diff --git a/application/controllers/mockup/process/resultentry-v20/9/Re_px.php b/application/controllers/mockup/process/resultentry-v20/9/Re_px.php index 08699539..e0631de5 100644 --- a/application/controllers/mockup/process/resultentry-v20/9/Re_px.php +++ b/application/controllers/mockup/process/resultentry-v20/9/Re_px.php @@ -1,2467 +1,2464 @@ -db_smartone = $this->load->database("onedev", true); - $this->load->helper(array('form', 'url')); - } - function getMethodeID($natTestID) { - $sql = "select M_MethodePriorityNat_MethodeID MethodeID, Nat_MethodeName - from - m_methode_priority - join nat_methode on Nat_MethodeID = M_MethodePriorityNat_MethodeID - and Nat_MethodeIsActive = 'Y' - join m_instrumentmethode on M_InstrumentMethodeNat_MethodeID = Nat_MethodeID and M_InstrumentMethodeIsActive = 'Y' - join nat_instrument on M_InstrumentMethodeNat_InstrumentID = Nat_InstrumentID - and Nat_InstrumentIsActive ='Y' - where M_MethodePriorityIsActive = 'Y' - and M_MethodePriorityNat_TestID = $natTestID - and M_MethodePriorityM_DayOfWeekID = dayofweek(now()) - order by M_MethodePriorityNumber desc - limit 0,1 "; - $qry = $this->db->query($sql); - if ($qry) { - $rows = $qry->result_array(); - if (count($rows) > 0 ) return array($rows[0]["MethodeID"],$rows[0]["Nat_MethodeName"]); - } - //2nd - $sql= "select - M_InstrumentMethodeNat_MethodeID MethodeID, Nat_MethodeName - from m_instrumentmethode - join nat_methode on M_InstrumentMethodeNat_MethodeID = Nat_MethodeID - and Nat_MethodeIsActive = 'Y' - join nat_instrument on M_InstrumentMethodeNat_InstrumentID = Nat_InstrumentID - and Nat_InstrumentIsActive ='Y' - where M_InstrumentMethodeNat_TestID = $natTestID - and M_InstrumentMethodeIsActive = 'Y' - order by M_InstrumentMethodePriority desc - limit 0,1"; - $qry = $this->db->query($sql); - if ($qry) { - $rows = $qry->result_array(); - if (count($rows) > 0 ) return array($rows[0]["MethodeID"],$rows[0]["Nat_MethodeName"]); - } - // - $sql = "select Nat_NormalValueNat_MethodeID MethodeID, Nat_MethodeName - from - nat_normalvalue - join nat_methode on Nat_NormalValueNat_MethodeID = Nat_MethodeID - and Nat_MethodeIsActive = 'Y' - where Nat_NormalValueNat_TestID = $natTestID - and Nat_NormalValueIsActive = 'Y' - order by Nat_NormalValueID - limit 0,1"; - $qry = $this->db->query($sql); - if ($qry) { - $rows = $qry->result_array(); - if (count($rows) > 0 ) return array($rows[0]["MethodeID"],$rows[0]["Nat_MethodeName"]); - } - return array(0,""); - } - function get_normal_value($methodeID, $natTestID, $sexID, $ageInDay ) { - $sql = "select fn_sampling_get_normal($methodeID, $natTestID, $sexID, $ageInDay) as normalValueID"; - $qry = $this->db->query($sql); - if ($qry) { - $rows = $qry->result_array(); - if (count($rows) > 0 ) return $rows[0]["normalValueID"]; - } - return 0; - } - function fn_fix_normal($order_id) { - $sql = "select - T_OrderDetailID, M_PatientM_SexID, fn_global_age_count_day(M_PatientDOB, date(T_OrderHeaderDate)) Dob , - T_TestNat_TestID - from t_orderheader - join m_patient on T_OrderHeaderID = $order_id and T_OrderHeaderM_PatientID = M_PatientID - join t_orderdetail on T_OrderDetailT_OrderHeaderID = T_OrderHeaderID - and T_OrderDetailIsACtive = 'Y' - and ( T_OrderDetailNat_NormalValueID is null or T_OrderDetailNat_NormalValueID = 0 ) - join t_test on T_OrderDetailT_TestID = T_TestID and T_TestIsResult = 'Y' "; - $qry = $this->db->query($sql); - if(! $qry) { - return; - } - $rows = $qry->result_array(); - if(count($rows) == 0 ) return; - $sql_u = "update t_orderdetail - join nat_normalvalue on T_OrderDetailID = ? and Nat_NormalValueID = ? - set - T_OrderDetailNat_NormalValueID = Nat_NormalValueID, - T_OrderDetailNormalValueNote = Nat_NormalValueNote, - T_OrderDetailNormalValueDescription = Nat_NormalValueDescription, - T_OrderDetailMinValue = Nat_NormalValueMinValue, - T_OrderDetailMaxValue = Nat_NormalValueMaxValue, - T_OrderDetailMinValueInclusive = Nat_NormalValueMinValueInclusive, - T_OrderDetailMaxValueInclusive = Nat_NormalValueMaxValueInclusive, - T_OrderDetailNat_MethodeID = ?, - T_OrderdetailNat_MethodeName =?"; - - foreach($rows as $r) { - $T_OrderDetailID = $r["T_OrderDetailID"]; - $sexID = $r["M_PatientM_SexID"]; - $ageInDay = $r["Dob"]; - $natTestID = $r["T_TestNat_TestID"]; - list($methodeID,$methodeName) = $this->getMethodeID($natTestID); - if ($methodeID == 0 ) continue; - $normalValueID = $this->get_normal_value($methodeID, $natTestID, $sexID, $ageInDay); - if ($normalValueID == 0) return; - $this->db->query($sql_u, array($T_OrderDetailID, $normalValueID, $methodeID, $methodeName)); - } - } - function update_order_sample($targetID, $sourceID) { - $sql = "update t_ordersample target - join t_ordersample source on - target.T_OrderSampleID = ? - and target.T_OrderSampleWorklistReceive = 'N' - and source.T_OrderSampleID = ? - set - target.T_OrderSampleSampling = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSampling, source.T_OrderSampleSampling), - target.T_OrderSampleSamplingDate = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingDate, source.T_OrderSampleSamplingDate), - target.T_OrderSampleSamplingTime = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingTime, source.T_OrderSampleSamplingTime), - target.T_OrderSampleSamplingUserID = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingUserID, source.T_OrderSampleSamplingUserID), - - target.T_OrderSampleReceive = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceive, source.T_OrderSampleReceive), - target.T_OrderSampleReceiveDate = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveDate, source.T_OrderSampleReceiveDate), - target.T_OrderSampleReceiveTime = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveTime, source.T_OrderSampleReceiveTime), - target.T_OrderSampleReceiveUserID = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveUserID, source.T_OrderSampleReceiveUserID), - - target.T_OrderSampleVerification = if(target.T_OrderSampleVerification='Y',target.T_OrderSampleVerification, source.T_OrderSampleVerification), - target.T_OrderSampleVerificationDate =if(target.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationDate, source.T_OrderSampleVerificationDate), - target.T_OrderSampleVerificationTime =if(source.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationTime, source.T_OrderSampleVerificationTime), - target.T_OrderSampleVerificationUserID =if(source.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationUserID, source.T_OrderSampleVerificationUserID), - - target.T_OrderSampleProcessing = if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessing, source.T_OrderSampleProcessing), - target.T_OrderSampleProcessingDate= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingDate, source.T_OrderSampleProcessingDate), - target.T_OrderSampleProcessingTime= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingTime, source.T_OrderSampleProcessingTime), - target.T_OrderSampleProcessingUserID= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingUserID, source.T_OrderSampleProcessingUserID), - - target.T_OrderSampleReceiveHandling =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandling, source.T_OrderSampleReceiveHandling ), - target.T_OrderSampleReceiveHandlingDate =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingDate, source.T_OrderSampleReceiveHandlingDate), - target.T_OrderSampleReceiveHandlingTime =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingTime, source.T_OrderSampleReceiveHandlingTime), - target.T_OrderSampleReceiveHandlingUserID =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingUserID, source.T_OrderSampleReceiveHandlingUserID), - - target.T_OrderSampleHandling = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandling, source.T_OrderSampleHandling), - target.T_OrderSampleHandlingDate = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingDate, source.T_OrderSampleHandlingDate), - target.T_OrderSampleHandlingTime = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingTime, source.T_OrderSampleHandlingTime), - target.T_OrderSampleHandlingUserID = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingUserID, source.T_OrderSampleHandlingUserID), - - target.T_OrderSampleWorklistReceive = source.T_OrderSampleWorklistReceive, - target.T_OrderSampleWorklistReceiveDatetime = source.T_OrderSampleWorklistReceiveDateTime, - target.T_OrderSampleWorklistReceiveUserID = source.T_OrderSampleWorklistReceiveUserID - "; - $qry = $this->db->query($sql,array($targetID,$sourceID)); - if(! $qry ) { - echo json_encode(array( "status" => "ERR" , "message" => print_r($this->db->error(),true))); - exit; - } - } - function fix_sample_serum($headerID) { - //cari t_ordersample yg belum worklist receive dengan code 017% - $sql = "select T_OrderSampleID - from t_ordersample - join t_sampletype on - T_OrderSampleT_OrderHeaderID = ? - and T_OrderSampleWorklistReceive = 'N' - and T_OrderSampleIsActive = 'Y' - and T_OrderSampleT_SampleTypeID = T_SampletypeID - and T_SampleTypeCode like '017%' - "; - $qry = $this->db->query($sql, array($headerID)); - if(!$qry) { - echo json_encode(array( "status" => "ERR" , "message" => print_r($this->db->error(),true))); - exit; - } - $rows = $qry->result_array(); - if (count($rows) == 0 ) return; - //cari T_OrderSample yang sudah di receive yg terakhir - $sql = "select T_OrderSampleID - from t_ordersample - join t_sampletype on - T_OrderSampleT_OrderHeaderID = ? - and T_OrderSampleWorklistReceive = 'Y' - and T_OrderSampleIsActive = 'Y' - and T_OrderSampleT_SampleTypeID = T_SampletypeID - and T_SampleTypeCode like '017%' - order by T_OrderSampleWorklistReceiveDatetime desc - limit 0,1 - "; - $qry = $this->db->query($sql, array($headerID)); - if(!$qry) { - echo json_encode(array( "status" => "ERR" , "message" => print_r($this->db->error(),true))); - exit; - } - $rcv_rows = $qry->result_array(); - if (count($rcv_rows) == 0 ) return; - - //print_r($rows); - //print_r($rcv_rows); - $rcv_T_OrderSampleID = $rcv_rows[0]["T_OrderSampleID"]; - //ada yg belum di receive - foreach($rows as $r) { - $T_OrderSampleID = $r["T_OrderSampleID"]; - $this->update_order_sample($T_OrderSampleID,$rcv_T_OrderSampleID); - } - } - public function search() - { - $prm = $this->sys_input; - $max_rst = 99; - - $id = $prm["order_id"]; - if ($id > 0 ) { - $this->fix_sample_serum($id); - $this->fn_fix_normal($id); - } - $lang = $this->lang_default_code; - $lang_id = isset($prm['lang_id']) ? $prm['lang_id'] : '0'; - - if ($lang_id != 0) - { - $l = $this->db_smartone->where("Nat_LangID", $lang_id)->get("nat_lang")->row(); - $lang = $l->Nat_LangCode; - } - - //tambahan fajri - $sql = " UPDATE t_orderdetail - JOIN t_test ON T_OrderDetailT_TestID = T_TestID - SET T_OrderDetailT_TestIsResult = T_TestIsResult - WHERE - T_OrderDetailT_OrderHeaderID = {$id} AND - T_OrderDetailT_TestIsResult = '' AND - T_OrderDetailIsActive = 'Y'"; - $this->db_smartone->query($sql); - - $tot_count = 0; - $lq = ""; - $group_id = 0; - if (isset($prm['group_id'])) - $group_id = $prm['group_id']; - - if ($group_id != 0) - { - $sql = "select distinct T_WorklistDetailNat_TestID Nat_TestID - from t_worklistdetailv2 - where T_WorklistDetailT_WorklistID = {$group_id}"; - $qry = $this->db_smartone->query($sql); - $rows = $qry->result_array(); - $nat_test_ids = "0"; - foreach($rows as $r) { - $nat_test_ids .= ", " . $r["Nat_TestID"]; - } - $q_group = " ( $nat_test_ids ) "; - - $sql = " - SELECT a1.*, cOUNT(a2.T_OrderDetailID) level - FROM ( - SELECT IFNULL(y.T_OrderDetailT_TestID, x.T_OrderDetailT_TestID) t_testid, - IFNULL(y.T_OrderDetailT_TestName, y.T_OrderDetailT_TestName) t_testname, - y.T_OrderDetailResult result, y.T_OrderDetailResult result_old, y.T_OrderDetailNote note, y.T_OrderDetailNote note_old, - y.T_OrderDetailID id, - y.T_OrderDetailT_TestIsResult is_result, a.T_TestIsQuantitative is_quantitative, - y.T_OrderDetailResultFlag result_flag, - y.T_OrderDetailNat_NormalValueID normal_id, - y.T_OrderDetailNormalValueNote normal_note, y.T_OrderDetailNat_UnitName unit_name, - y.T_OrderdetailNat_MethodeID methode_id, y.T_OrderdetailNat_MethodeName methode_name, - a.T_TestNat_TestID nattest_id, a.T_TestID tx_id, count(T_ResultInstrumentID) as result_instrument_n, - y.T_OrderDetailVerification, T_OrderSampleReceive sample_receive, - T_OrderSampleProcessing sample_processing, T_OrderSampleWorklistReceive sample_worklist_receive, - IF(T_OrderDetailAddOnPreAnalytic = 'Y', T_OrderDetailAddOnPreAnalytic, PreAnalyticIsOk) pre_analytic, - T_OrderDetailAddOnPreAnalytic, - T_OrderHeaderID order_id, y.T_OrderDetailT_TestSasCode test_sas_code, - tx.T_TestSasCode, - T_OrderDetailAddOnResample `resample`, T_OrderDetailAddOnResampleStatus resample_status, - T_OrderDetailAddOnRef ref, y.T_OrderDetailVerification verification, y.T_OrderDetailValidation validation, - T_OrderPromiseDateTime, Group_ResultName as ResultGroupName - FROM t_orderdetail x - left join t_orderpromise on x.T_OrderDetailT_OrderPromiseID = T_OrderPromiseID - JOIN t_test tx ON x.T_OrderDetailT_TestID = T_TestID - JOIN t_test tcheck on tcheck.T_TestNat_TestID in {$q_group} - and ( tx.T_TestID = tcheck.T_TestID or tx.T_TestSasCode like concat(tcheck.T_TestSasCode,'%')) - LEFT JOIN group_resultdetail ON Group_ResultDetailT_TestID = x.T_OrderDetailT_TestID AND Group_ResultDetailIsActive = 'Y' - LEFT JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND Group_ResultFlagNonLab = 'N' - LEFT JOIN t_orderdetail y ON x.T_OrderDetailT_TestSasCode LIKE CONCAT(y.T_OrderDetailT_TestSasCode, '%') - AND x.T_OrderDetailT_OrderHeaderID = y.T_OrderDetailT_OrderHeaderID - AND y.T_OrderDetailIsActive = 'Y' - LEFT JOIN t_orderdetailaddon ON x.T_OrderDetailID = T_OrderDetailAddOnT_OrderDetailID - JOIN t_orderheader ON y.T_OrderDetailT_OrderHeaderID = T_OrderHeaderID - LEFT JOIN t_test a ON y.T_OrderDetailT_TestID = a.T_TestID - AND a.T_TestIsNonLab = '' - LEFT JOIN (SELECT T_OrderSampleT_SampleTypeID, T_OrderSampleReceive, T_OrderSampleProcessing, T_OrderSampleWorklistReceive - FROM t_ordersample WHERE T_OrderSampleT_OrderHeaderID = {$id} - AND T_OrderSampleIsactive = 'Y' - GROUP BY T_OrderSampleT_SampleTypeID) os ON a.T_TestT_SampleTypeID = os.T_OrderSampleT_SampleTypeID - or os.T_OrderSampleT_SampleTypeID = fn_sampletype_from_local(a.T_TestNat_TestID) - - LEFT JOIN t_resultinstrument ON T_ResultInstrumentT_OrderDetailID = x.T_OrderDetailID - LEFT JOIN pre_analytic ON PreAnalyticNat_TestID = a.T_TestNat_TestID AND PreAnalyticDate = date(now()) and PreAnalyticIsActive = 'Y' - WHERE x.T_OrderDetailT_OrderHeaderID = {$id} - AND x.T_OrderDetailIsActive = 'Y' - GROUP BY y.T_OrderDetailT_TestID - ORDER BY y.T_OrderDetailT_TestSasCode ASC - ) a1 - - LEFT JOIN t_orderdetail a2 ON a2.T_OrderDetailT_OrderHeaderID = a1.order_id - AND a2.T_OrderDetailIsActive = 'Y' - AND a1.test_sas_code LIKE CONCAT(a2.T_OrderDetailT_testSasCode, '%') - GROUP BY a1.t_testid - order by a1.test_sas_code -"; - $query = $this->db_smartone->query($sql); - $lq = $this->db_smartone->last_query(); - } - else - { - $sql = " - SELECT a1.*, cOUNT(a2.T_OrderDetailID) level - FROM ( - SELECT IFNULL(y.T_OrderDetailT_TestID, x.T_OrderDetailT_TestID) t_testid, - IFNULL(y.T_OrderDetailT_TestName, y.T_OrderDetailT_TestName) t_testname, - y.T_OrderDetailResult result, y.T_OrderDetailResult result_old, y.T_OrderDetailNote note, y.T_OrderDetailNote note_old, - y.T_OrderDetailID id, - y.T_OrderDetailT_TestIsResult is_result, a.T_TestIsQuantitative is_quantitative, - y.T_OrderDetailResultFlag result_flag, - y.T_OrderDetailNat_NormalValueID normal_id, - y.T_OrderDetailNormalValueNote normal_note, y.T_OrderDetailNat_UnitName unit_name, - y.T_OrderdetailNat_MethodeID methode_id, y.T_OrderdetailNat_MethodeName methode_name, - a.T_TestNat_TestID nattest_id, a.T_TestID tx_id, count(T_ResultInstrumentID) as result_instrument_n, - y.T_OrderDetailVerification, T_OrderSampleReceive sample_receive, - T_OrderSampleProcessing sample_processing, T_OrderSampleWorklistReceive sample_worklist_receive, - IF(T_OrderDetailAddOnPreAnalytic = 'Y', T_OrderDetailAddOnPreAnalytic, PreAnalyticIsOk) pre_analytic, - T_OrderDetailAddOnPreAnalytic, - T_OrderHeaderID order_id, y.T_OrderDetailT_TestSasCode test_sas_code, - tx.T_TestSasCode, - T_OrderDetailAddOnResample `resample`, T_OrderDetailAddOnResampleStatus resample_status, - T_OrderDetailAddOnRef ref, y.T_OrderDetailVerification verification, y.T_OrderDetailValidation validation, - T_OrderPromiseDateTime , Group_ResultName as ResultGroupName - FROM t_orderdetail x - left join t_orderpromise on x.T_OrderDetailT_OrderPromiseID = T_OrderPromiseID - JOIN t_test tx ON x.T_OrderDetailT_TestID = T_TestID - LEFT JOIN group_resultdetail ON Group_ResultDetailT_TestID = x.T_OrderDetailT_TestID AND Group_ResultDetailIsActive = 'Y' - LEFT JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND Group_ResultFlagNonLab = 'N' - LEFT JOIN t_orderdetail y ON x.T_OrderDetailT_TestSasCode LIKE CONCAT(y.T_OrderDetailT_TestSasCode, '%') - AND x.T_OrderDetailT_OrderHeaderID = y.T_OrderDetailT_OrderHeaderID - AND y.T_OrderDetailIsActive = 'Y' - - LEFT JOIN t_orderdetailaddon ON x.T_OrderDetailID = T_OrderDetailAddOnT_OrderDetailID - - JOIN t_orderheader ON y.T_OrderDetailT_OrderHeaderID = T_OrderHeaderID - LEFT JOIN t_test a ON y.T_OrderDetailT_TestID = a.T_TestID - AND a.T_TestIsNonLab = '' - LEFT JOIN (SELECT T_OrderSampleT_SampleTypeID, T_OrderSampleReceive, T_OrderSampleProcessing, T_OrderSampleWorklistReceive - FROM t_ordersample WHERE T_OrderSampleT_OrderHeaderID = {$id} - AND T_OrderSampleIsactive = 'Y' - GROUP BY T_OrderSampleT_SampleTypeID) os ON a.T_TestT_SampleTypeID = os.T_OrderSampleT_SampleTypeID - or os.T_OrderSampleT_SampleTypeID = fn_sampletype_from_local(a.T_TestNat_TestID) - - LEFT JOIN t_resultinstrument ON T_ResultInstrumentT_OrderDetailID = x.T_OrderDetailID - LEFT JOIN pre_analytic ON PreAnalyticNat_TestID = a.T_TestNat_TestID AND PreAnalyticDate = date(now()) and PreAnalyticIsActive = 'Y' - WHERE x.T_OrderDetailT_OrderHeaderID = {$id} - AND x.T_OrderDetailIsActive = 'Y' - GROUP BY y.T_OrderDetailT_TestID - ORDER BY y.T_OrderDetailT_TestSasCode ASC - ) a1 - - LEFT JOIN t_orderdetail a2 ON a2.T_OrderDetailT_OrderHeaderID = a1.order_id - AND a2.T_OrderDetailIsActive = 'Y' - AND a1.test_sas_code LIKE CONCAT(a2.T_OrderDetailT_testSasCode, '%') - GROUP BY a1.t_testid - order by a1.test_sas_code -"; -//echo $sql; - $query = $this->db_smartone->query($sql); - $lq = $this->db_smartone->last_query(); - } - // file_put_contents("/xtmp/re-query.sql",$lq); - - if ($query) { - $rst = []; - $rows = $query->result_array(); - - foreach($rows as $k => $v) - { - - if ($v['is_result'] == "Y" && $v['is_quantitative'] == "N") - { - $v['template'] = []; - $x = $this->db_smartone->query("CALL sp_master_resulttemplate_get('{$v['t_testid']}')"); - $this->clean_mysqli_connection($this->db_smartone->conn_id); - if ($x) - $v['template'] = $x->result_array(); - } - - // IF Rujukan, by pas Pre Analytik - if ($v['ref'] == 'Y') - $v['pre_analytic'] = 'Y'; - if ($v["id"] == "885455" ) - { - //sipe workaround - //$v["sample_receive"] = "Y"; - $v["sample_worklist_receive"] = "Y"; - } - $rst[] = $v; - } - - $result = array("total" => $tot_count, "records" => $rst, "total_display" => sizeof($rows), "q" => $lq); - $this->sys_ok($result); - } - else { - $this->sys_error_db("RE Px rows", $this->db_smartone); - exit; - } - } - - public function save() - { - $prm = $this->sys_input; - $data = json_decode($prm["data"]); - $lang = $this->lang_default_code; - $lang_id = isset($prm['lang_id']) ? $prm['lang_id'] : '0'; - - if ($lang_id != 0) - { - $l = $this->db_smartone->where("Nat_LangID", $lang_id)->get("nat_lang")->row(); - $lang = $l->Nat_LangCode; - } - - $sql_norm = "select T_OrderDetailMinValue, T_OrderDetailMaxValue, - T_OrderDetailMinValueInclusive, T_OrderDetailMaxValueInclusive, - Nat_TestFlagLow, Nat_TestFlagHigh - from t_orderdetail - join t_test on T_OrderDetailT_TestID = T_TestID - join nat_test on T_TestNat_TestID = Nat_TestID and T_TestIsActive = 'Y' - where T_OrderDetailID = ? "; - - $ids = []; - foreach ($data as $k => $v) - { - if ( $v->resultInstrumentID > 0 ) { - $sql_i = "select T_ResultInstrumentNat_NormalValueID normalValueID - from t_resultinstrument - where T_ResultInstrumentID = ?"; - $qry_i = $this->db_smartone->query($sql_i, array($v->resultInstrumentID)); - if ($qry_i) { - $rows_i = $qry_i->result_array(); - - if (count($rows_i) > 0 ) { - $sql_iu = "update t_orderdetail, nat_normalvalue , nat_methode - set T_OrderDetailMinValue = Nat_NormalValueMinValue, - T_OrderDetailMinValueInclusive = Nat_NormalValueMinValueInclusive, - T_OrderDetailMaxValue = Nat_NormalValueMaxValue , - T_OrderDetailMaxValueInclusive = Nat_NormalValueMaxValueInclusive, - T_OrderDetailNormalValueNote = Nat_NormalValueNote, - T_OrderDetailNormalValueDescription = Nat_NormalValueDescription, - T_OrderDetailNat_NormalValueID = Nat_NormalValueID, - T_OrderDetailNat_MethodeID = Nat_NormalValueNat_MethodeID, - T_OrderDetailNat_MethodeName = Nat_MethodeName - where T_OrderDetailID = ? and Nat_NormalValueID = ? - and Nat_NormalValueNat_MethodeID = Nat_MethodeID - "; - $this->db_smartone->query($sql_iu, array($v->id, $rows_i[0]["normalValueID"])); - //file_put_contents("/xtmp/update-nilai-normal", $this->db_smartone->last_query() . "\n", FILE_APPEND); - } - } - } - $y = $this->db_smartone->query("SELECT fn_process_sample_handling_perfect('{$v->order_id}', '{$v->test_id}') c") - ->row(); - $req_status = $y->c; - $qry_norm = $this->db_smartone->query($sql_norm,$v->id); - $result_flag = ""; - if ($qry_norm) { - $rows_norm = $qry_norm->result_array(); - if (count($rows_norm) > 0 ) { - $r = $rows_norm[0]; - if (is_numeric($v->result)) { - - if ( $r["T_OrderDetailMinValueInclusive"] == "Y" && $v->result < $r["T_OrderDetailMinValue"] ) { - $result_flag = $r["Nat_TestFlagLow"]; - } - if ( $r["T_OrderDetailMinValueInclusive"] == "N" && $v->result <= $r["T_OrderDetailMinValue"] ) { - $result_flag = $r["Nat_TestFlagLow"]; - } - if ( $r["T_OrderDetailMaxValueInclusive"] == "Y" && $v->result > $r["T_OrderDetailMaxValue"] ) { - $result_flag = $r["Nat_TestFlagHigh"]; - } - if ( $r["T_OrderDetailMaxValueInclusive"] == "N" && $v->result >= $r["T_OrderDetailMaxValue"] ) { - $result_flag = $r["Nat_TestFlagHigh"]; - } - } - } - } - if ($lang == $this->lang_default_code) - { - $this->db_smartone->set('T_OrderDetailResult', $v->result) - ->set('T_OrderDetailResultFlag', $result_flag) - ->set('T_OrderDetailNote', $v->note) - ->set('T_OrderDetailReqStatus', $req_status) - ->where('T_OrderDetailID', $v->id) - ->update('t_orderdetail'); - } - else - { - $this->db_smartone->set('T_OrderDetailLangResult', $v->result) - ->set('T_OrderDetailLangNote', $v->note) - ->where('T_OrderDetailLangID', $v->id) - ->update('t_orderdetaillang'); - } - - $ids[] = $v->id; - } - - // LOG Process - $order = $this->db_smartone->select('T_OrderDetailT_OrderHeaderID id, T_OrderHeaderLabNumber lab_number', false) - ->join('t_orderheader', 'T_OrderHeaderID = T_OrderDetailT_OrderHeaderID') - ->where('T_OrderDetailID', $data[0]->id) - ->get('t_orderdetail') - ->row(); - - $dblog = $this->load->database("onelog", true); - $dblog->set('Log_ProcessCode', 'PROCESS.Result.Entry') - ->set('Log_ProcessOrderID', $order->id) - ->set('Log_ProcessOrderNumber', $order->lab_number) - ->set('Log_ProcessJson', json_encode($data)) - ->set('Log_ProcessUserID', $this->sys_user['M_UserID']) - ->insert('log_process'); - // END OF Log Process - //auto calculation - $this->load->library("Resultcalc"); - $rows = $this->resultcalc->auto($order->id); - - try { - foreach($ids as $id ) { - $this->db_smartone->query("call sp_set_normal_value_flag($id)"); - $this->clean_mysqli_connection($this->db_smartone->conn_id); - } - } catch(Exception $e) { - } - - $this->sys_ok($ids); - } - - public function save_template() - { - $prm = $this->sys_input; - - $n = $this->db_smartone->select("COUNT(T_ResultTemplateID) n") - ->where("T_ResultTemplateT_TestID", $prm['test_id']) - ->where("T_ResultTemplateIsActive", "Y") - ->where("T_ResultTemplateValue", $prm['value']) - ->get('t_resulttemplate') - ->row(); - if ($n->n > 0) - { - $this->sys_error_db("Insert Result Template", $this->db_smartone); - return; - } - - $r = $this->db_smartone->set("T_ResultTemplateT_TestID", $prm['test_id']) - ->set("T_ResultTemplateValue", $prm['value']) - ->insert('t_resulttemplate'); - if ($r) - { - $template = []; - $x = $this->db_smartone->query("CALL sp_master_resulttemplate_get('{$prm['test_id']}')"); - $this->clean_mysqli_connection($this->db_smartone->conn_id); - if ($x) - $template = $x->result_array(); - - $this->sys_ok($template); - } - } - - public function export() - { - $prm = $this->sys_input; - - $sql = "CALL sp_process_result_lang(?, ?, ?, ?)"; - $query = $this->db_smartone->query($sql, [$prm['order_id'], $prm['lang_id'], $prm['is_si'], $this->sys_user['M_UserID']]); - if ($query) - { - $r = $query->row(); - if ($r->status == "OK") - { - $this->sys_ok($r->data); - return; - } - - $this->sys_error_db("Message : " . $r->message, $this->db_smartone); - } - else - { - $this->sys_error_db("Lang Result", $this->db_smartone); - return; - } - } - - public function search_group() - { - $prm = $this->sys_input; - $max_rst = 100; - - // QUERY TOTAL - $sql = "select count(*) total - from t_worklist - where T_WorklistIsActive = 'Y' - order by T_WorklistName ASC"; - $query = $this->db_smartone->query($sql); - - if ($query) { - $tot_count = $query->result_array()[0]["total"]; - } - else { - $this->sys_error_db("worklist count", $this->db_smartone); - exit; - } - - $sql = "select T_WorklistID group_id, T_WorklistName group_name - from t_worklist - where T_WorklistIsActive = 'Y' - order by T_WorklistName ASC - limit 0, {$max_rst}"; - $query = $this->db_smartone->query($sql); - - if ($query) { - $rows = $query->result_array(); - foreach ($rows as $k => $v) - $rows[$k]['data'] = json_decode($v['data']); - $result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows), "q" => $this->db_smartone->last_query()); - $this->sys_ok($result); - } - else { - $this->sys_error_db("worklist rows", $this->db_smartone); - exit; - } - } - - public function search_rerun() - { - $prm = $this->sys_input; - $id = $prm["detail_id"]; - - $sql = "CALL sp_process_result_rerun(?)"; - $query = $this->db_smartone->query($sql, [$id]); - - if ($query) - { - $rows = $query->result_array(); - $this->sys_ok(["records"=>$rows]); - } - else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - - - function getdoctorsfna() - { - $prm = $this->sys_input; - // $id = $prm["id"]; - - $sql = " SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY M_DoctorName ASC"; - //echo $sql; - $query = $this->db_smartone->query($sql); - - if ($query) - { - $rows = $query->result_array(); - $this->sys_ok(["records"=>$rows]); - } - else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - function getfnaresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT Other_FNADetailsID as xid, - Other_FNAT_OrderDetailID as orderdetail_id, - Other_FNADetailsCode as code, - Other_FNADetailsLabel as label, - Other_FNADetailsResult as result, - IFNULL(Other_FNAM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_FNAM_DoctorID) OR Other_FNAM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_fna - JOIN other_fnadetails ON Other_FNADetailsOther_FNAID = Other_FNAID AND Other_FNADetailsIsActive = 'Y' - LEFT JOIN m_doctor ON Other_FNAM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_FNAT_OrderDetailID = {$id} AND Other_FNAIsActive = 'Y' - GROUP BY Other_FNADetailsID - ORDER BY Other_FNADetailsCode ASC"; - $query = $this->db_smartone->query($sql); - - if ($query) - { - $rows = $query->result_array(); - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $images = array(); - $sql = "SELECT So_ImageUploadID as xid, - CONCAT('/one-media/one-image-nonlab/',So_ImageUploadNewName) as image_url - FROM t_orderdetail - JOIN so_imageupload ON So_ImageUploadT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND - So_ImageUploadIsActive = 'Y' - WHERE - T_OrderDetailID = {$id} AND - T_OrderDetailIsActive = 'Y' - GROUP BY So_ImageUploadID"; - $images = $this->db_smartone->query($sql)->result_array(); - - $rst = array('doctors'=>$doctors,'results'=>$rows,'images'=>$images); - $this->sys_ok(["records"=>$rst]); - } - else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - - function uploadimage(){ - if (! $this->isLogin) { - $this->sys_error("Invalid Token"); - exit; - } - - $userid = $this->sys_user["M_UserID"]; - $data = []; - //print_r($_SERVER); - - $prm = $this->sys_input; - $orderid = $this->input->post('orderid'); - $labnumber = $this->input->post('labnumber'); - $sql = "UPDATE so_imageupload SET - So_ImageUploadIsActive = 'N', - So_ImageUploadUserID = {$userid} - WHERE - So_ImageUploadT_OrderHeaderID = {$orderid}"; - //echo $sql; - $this->db_onedev->query($sql); - //$config['upload_path'] = 'assets/'; - - $path = '/home/one/project/one/one-media/one-image-nonlab/'; - //echo $path; - $config['upload_path'] = $path; - $config['allowed_types'] = 'jpg|jpeg|png|gif'; - - $config['max_size'] = '10000'; - $count = count($_FILES['files']['name']); - //echo $count; - $this->load->library('upload',$config); - - $error = []; - for($i=0;$i<$count;$i++){ - - - if(!empty($_FILES['files']['name'][$i])){ - - - - $_FILES['file']['name'] = $_FILES['files']['name'][$i]; - - $_FILES['file']['type'] = $_FILES['files']['type'][$i]; - - $_FILES['file']['tmp_name'] = $_FILES['files']['tmp_name'][$i]; - - $_FILES['file']['error'] = $_FILES['files']['error'][$i]; - - $_FILES['file']['size'] = $_FILES['files']['size'][$i]; - - - - $namex = $orderid.'-'.$labnumber.'-'.$this->generateRandomString(5); - //echo $namex; - - $config['file_name'] = $namex; - $this->upload->initialize($config); - //echo $config['file_name'] ; - - - - - - if($this->upload->do_upload('file')){ - - $uploadData = $this->upload->data(); - - $filename = $uploadData['file_name']; - //echo $filename; - - - $sql = "INSERT INTO so_imageupload ( - So_ImageUploadT_OrderHeaderID, - So_ImageUploadT_OrderHeaderLabNumber, - So_ImageUploadT_SampleTypeID, - So_ImageUploadOldName, - So_ImageUploadNewName, - So_ImageUploadCreated, - So_ImageUploadUserID - ) - VALUES( - {$orderid}, - '{$labnumber}', - '150', - '{$_FILES['files']['name'][$i]}', - '{$filename}', - NOW(), - {$userid} - - )"; - //echo $sql; - $this->db_onedev->query($sql); - $xlast_id = $this->db_onedev->insert_id(); - $data['totalFiles'][] = array('xid' => $xlast_id ,'image_url' => '/one-media/one-image-nonlab/'.$filename); - - } - else{ - $error = array('error' => $this->upload->display_errors()); - } - - } - - - - } - - $result = array("total" =>count( $data['totalFiles']), "records" => $data['totalFiles'],'errors'=>$error); - $this->sys_ok($result); - } - - - function generateRandomString($length = 10) { - $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; - $charactersLength = strlen($characters); - $randomString = ''; - for ($i = 0; $i < $length; $i++) { - $randomString .= $characters[rand(0, $charactersLength - 1)]; - } - return $randomString; - } - - function getcytologiresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT Other_CytologiDetailsID as xid, - Other_CytologiT_OrderDetailID as orderdetail_id, - Other_CytologiDetailsCode as code, - Other_CytologiDetailsLabel as label, - Other_CytologiDetailsResult as result, - IFNULL(Other_CytologiM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_CytologiM_DoctorID) OR Other_CytologiM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_cytologi - JOIN other_cytologidetails ON Other_CytologiDetailsOther_CytologiID = Other_CytologiID AND Other_CytologiDetailsIsActive = 'Y' - LEFT JOIN m_doctor ON Other_CytologiM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_CytologiT_OrderDetailID = {$id} AND Other_CytologiIsActive = 'Y' - GROUP BY Other_CytologiDetailsID - ORDER BY Other_CytologiDetailsCode ASC"; - //echo $sql; - $query = $this->db_smartone->query($sql); - - if ($query) - { - $rows = $query->result_array(); - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $rst = array('doctors'=>$doctors,'results'=>$rows); - $this->sys_ok(["records"=>$rst]); - } - else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - function getmikroresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT - Other_MikroID as xid, - Other_MikroHasilBiakan as hasil_biakan, - Other_MikroSampleTypeName as sample_name, - Other_MikroT_OrderDetailID as orderdetail_id, - Other_MikroResult as result_value, - '' as result_other, - IFNULL(T_BacteriaID,0) as T_BacteriaID, - IFNULL(T_BacteriaName,'') as T_BacteriaName, - '' as details, - IFNULL(Other_MikroM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_MikroM_DoctorID) OR Other_MikroM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_mikro - LEFT JOIN t_bacteria ON Other_MikroT_BacteriaID = T_BacteriaID - LEFT JOIN m_doctor ON Other_MikroM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_MikroT_OrderDetailID = {$id} AND Other_MikroIsActive = 'Y' - GROUP BY Other_MikroID"; - //echo $sql; - $query = $this->db_smartone->query($sql); - - if ($query) - { - $row = $query->row_array(); - if($row){ - if($row['result_value'] != 'Positif' && $row['result_value'] != 'Negatif'){ - $row['result_other'] = $row['result_value']; - $row['result_value'] = 'other'; - } - $sql = "SELECT '' as xno, - Other_MikroDetailsID as xid, - Other_MikroDetailsValue as value, - IF(Other_MikroDetailsNote = 'R','Y','N') as chx_r, - IF(Other_MikroDetailsNote = 'I','Y','N') as chx_i, - IF(Other_MikroDetailsNote = 'S','Y','N') as chx_s, - Other_MikroDetailsNote as note, - t_antibiotic.* - FROM other_mikrodetails - LEFT JOIN t_antibiotic ON Other_MikroDetailsT_AntibioticID = T_AntibioticID - WHERE - Other_MikroDetailsOther_MikroID = {$row['xid']} AND Other_MikroDetailsIsActive = 'Y' - GROUP BY Other_MikroDetailsID - ORDER BY T_AntibioticName ASC"; - //echo $sql; - $details = $this->db_smartone->query($sql)->result_array(); - if(details){ - foreach($details as $k => $v){ - $details[$k]['xno'] = $k + 1; - } - } - $row['details'] = $details; - } - else{ - $row = array('xid'=>'0','hasil_biakan' => '','result_value'=>'Negatif','sample_name' => '','orderdetail_id'=>$id, 'T_BacteriaID'=>'0','T_BacteriaName'=>'0','details'=>array(),'doctor_id'=>'0','doctor_name'=>'0'); - } - } - else{ - $row = array('xid'=>'0','hasil_biakan' => '','result_value'=>'Negatif','sample_name' => '','orderdetail_id'=>$id, 'T_BacteriaID'=>'0','T_BacteriaName'=>'0','details'=>array(),'doctor_id'=>'0','doctor_name'=>'0'); - } - //print_r($row); - - - - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 7 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $sql = " - SELECT '0' as id, 'Belum memilih bakteria' as name - UNION - SELECT T_BacteriaID as id, T_BacteriaName as name - FROM t_bacteria - WHERE - T_BacteriaIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $bacteries = $this->db_smartone->query($sql)->result_array(); - $rst = array('doctors'=>$doctors,'bacteries'=>$bacteries,'results'=>$row); - $this->sys_ok(["records"=>$rst]); - } - function getantibiotics(){ - $prm = $this->sys_input; - $id = $prm["id"]; - $sql = " SELECT '' as xno, - 0 as xid, - '' as hasil_biakan, - '' as sample_name, - 0 as value, - 'Y' as chx_r, - 'N' as chx_i, - 'N' as chx_s, - 'R' as note, - t_antibiotic.* - FROM t_antibiotic - WHERE - T_AntibioticT_BacteriaID = {$prm['id']} AND T_AntibioticIsActive= 'Y' - ORDER BY T_AntibioticName ASC"; - //echo $sql; - $rows = $this->db_smartone->query($sql)->result_array(); - if(rows){ - foreach($rows as $k => $v){ - $rows[$k]['xno'] = $k + 1; - } - } - - $this->sys_ok(["records"=>$rows]); - } - function getlcprepresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - $sql = " SELECT Other_LcprepDetailsID as xid, - Other_LcprepID as header_id, - Other_LcprepT_orderDetailID as orderdetail_id, - Other_LcprepDetailsCode as code, - Other_LcprepDetailsLabel as label, - Other_LcprepDetailsResult as result, - IFNULL(Other_LcprepM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_LcprepM_DoctorID) OR Other_LcprepM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_lcprep - JOIN other_lcprepdetails ON Other_LcprepDetailsOther_LcprepID = Other_LcprepID AND Other_LcprepDetailsIsActive = 'Y' - LEFT JOIN m_doctor ON Other_LcprepM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_LcprepT_orderDetailID = {$id} AND Other_LcprepIsActive = 'Y' - GROUP BY Other_LcprepDetailsOther_LcprepID, Other_LcprepDetailsCode - ORDER BY Other_LcprepDetailsCode ASC"; - //echo $sql; - $rows = $this->db_smartone->query($sql)->result_array(); - if(!$rows){ - $rows = array( - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'A', - 'label' => 'DESKRIPSI', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ), - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'B', - 'label' => 'KESIMPULAN', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ) - ); - } - - $header_id = $rows[0]['header_id']; - $sql = "SELECT IFNULL(Other_LcprepAdekuasiID,0) as xid, - Lcprep_AdekuasiID as id, - Lcprep_AdekuasiLabel as name, - IF(ISNULL(Other_LcprepAdekuasiID),'N',Other_LcprepAdekuasiChex) as chex - FROM lcprep_adekuasi - LEFT JOIN other_lcprepadekuasi ON Other_LcprepAdekuasiLcprep_AdekuasiID = Lcprep_AdekuasiID AND - Other_LcprepAdekuasiOther_LcprepID = {$header_id} AND - Other_LcprepAdekuasiIsActive = 'Y' - WHERE - Lcprep_AdekuasiIsActive = 'Y' - GROUP BY Lcprep_AdekuasiID - ORDER BY Lcprep_AdekuasiOrder ASC - "; - //echo $sql; - $adeakuasi = $this->db_smartone->query($sql)->result_array(); - foreach($adeakuasi as $kc => $vc){ - $adeakuasi[$kc]['chex'] = $vc['chex'] == 'N'?false:true; - } - - $sql = "SELECT IFNULL(Other_LcprepKategoriUmumID,0) as xid, - Lcprep_KategoriUmumID as id, - Lcprep_KategoriUmumLabel as name, - IF(ISNULL(Other_LcprepKategoriUmumID),'N',Other_LcprepKategoriUmumChex) as chex - FROM lcprep_kategoriumum - LEFT JOIN other_lcprepkategoriumum ON Other_LcprepKategoriUmumLcprep_KategoriUmumID = Lcprep_KategoriUmumID AND - Other_LcprepKategoriUmumOther_LcprepID = {$header_id} AND - Other_LcprepKategoriUmumIsActive = 'Y' - WHERE - Lcprep_KategoriUmumIsActive = 'Y' - GROUP BY Lcprep_KategoriUmumID - "; - //echo $sql; - $kategoriumum = $this->db_smartone->query($sql)->result_array(); - foreach($kategoriumum as $kc => $vc){ - $kategoriumum[$kc]['chex'] = $vc['chex'] == 'N'?false:true; - } - - $sql = " - SELECT Lcprep_InterpretasiGroupID as group_id, - Lcprep_InterpretasiGroupName as group_name, - '' as subgroups - FROM lcprep_interpretasigroup - WHERE - Lcprep_InterpretasiGroupIsActive = 'Y' - "; - //echo $sql; - $interpretasi = $this->db_smartone->query($sql)->result_array(); - foreach($interpretasi as $k => $v){ - $subgroups = array(); - $sql = "SELECT Lcprep_InterpretasiSubgroupID as subgroup_id, - Lcprep_InterpretasiSubgroupName as subgroup_name, - '' as childs - FROM lcprep_interpretasisubgroup - WHERE - Lcprep_InterpretasiSubgroupLcprep_InterpretasiGroupID = {$v['group_id']} AND Lcprep_InterpretasiSubgroupIsActive = 'Y'"; - //echo $sql; - $subgroups = $this->db_smartone->query($sql)->result_array(); - if(count($subgroups) > 0){ - foreach($subgroups as $ki => $vi){ - $childs = array(); - $sql = "SELECT IFNULL(Other_LcprepInterpretasiID,0) as xid, - IFNULL(Other_LcprepInterpretasiChex,'N') as chex, - IFNULL(Other_LcprepInterpretasiValue,'') as value, - Lcprep_InterpretasiID as id, - Lcprep_InterpretasiLcprep_InterpretasiSubgroupID as subgroup_id, - Lcprep_InterpretasiCode as code, - Lcprep_InterpretasiName as name, - Lcprep_InterpretasiParentID as parent_id, - Lcprep_InterpretasiIsParent as is_parent, - Lcprep_InterpretasiHasResult as has_result, - Lcprep_InterpretasiTypeResult as type_result - FROM lcprep_interpretasi - LEFT JOIN other_lcprepinterpretasi ON Other_LcprepInterpretasiOther_LcprepID = {$header_id} AND - Other_LcprepInterpretasiLcprep_InterpretasiID = Lcprep_InterpretasiID AND - Other_LcprepInterpretasiIsActive = 'Y' - WHERE - Lcprep_InterpretasiLcprep_InterpretasiSubgroupID = {$vi['subgroup_id']} AND Lcprep_InterpretasiIsActive = 'Y' - GROUP BY Lcprep_InterpretasiID Order BY Lcprep_InterpretasiCode ASC"; - $childs = $this->db_smartone->query($sql)->result_array(); - if($childs){ - foreach($childs as $kc => $vc){ - $childs[$kc]['chex'] = $vc['chex'] == 'N'?false:true; - } - } - $subgroups[$ki]['childs'] = $childs; - } - } - - $interpretasi[$k]['subgroups'] = $subgroups; - } - - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $rst = array('doctors'=>$doctors,'results'=>$rows,'adekuasi'=>$adeakuasi,'kategoriumum'=>$kategoriumum,'interpretasi'=>$interpretasi); - $this->sys_ok(["records"=>$rst]); - } - - function getpapsmearresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT Other_PapSmearDetailsID as xid, - Other_PapSmearID as header_id, - Other_PapSmearT_OrderDetailID as orderdetail_id, - Other_PapSmearDetailsCode as code, - Other_PapSmearDetailsLabel as label, - Other_PapSmearDetailsResult as result, - IFNULL(Other_PapSmearM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_PapSmearM_DoctorID) OR Other_PapSmearM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_papsmear - JOIN other_papsmeardetails ON Other_PapSmearDetailsOther_PapSmearID = Other_PapSmearID AND Other_PapSmearDetailsIsActive = 'Y' - LEFT JOIN m_doctor ON Other_PapSmearM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_PapSmearT_OrderDetailID = {$id} AND Other_PapSmearIsActive = 'Y' - GROUP BY Other_PapSmearDetailsID - ORDER BY Other_PapSmearDetailsCode ASC"; - //echo $sql; - $rows = $this->db_smartone->query($sql)->result_array(); - if(!$rows){ - $rows = array( - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'A', - 'label' => 'Makroskopik', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ), - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'B', - 'label' => 'Mikroskopik', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ), - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'C', - 'label' => 'Kesimpulan', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ) - ); - } - - $header_id = $rows[0]['header_id']; - $sql = "SELECT Other_PapSmearMaturasiID as xid, - Other_PapSmearMaturasiValue as value - FROM other_papsmearmaturasi - WHERE - Other_PapSmearMaturasiOther_PapSmearID = {$header_id} AND - Other_PapSmearMaturasiIsActive = 'Y' - "; - //echo $sql; - $dt_maturasi = $this->db_smartone->query($sql)->row_array(); - if(!$dt_maturasi){ - $maturasi = array('xid'=>'0','value'=> array('','','')); - } - else{ - $value = explode('/',$dt_maturasi['value']); - $maturasi = array('xid'=>$dt_maturasi['xid'],'value'=> $value); - } - - $sql = "SELECT IFNULL(Other_PapSmearBahanID,0) as xid, - M_PapSmearBahanID as bahan_id, - M_PapSmearBahanName as name, - IF(ISNULL(Other_PapSmearBahanID),'N','Y') as selected - FROM m_papsmearbahan - LEFT JOIN other_papsmearbahan ON Other_PapSmearBahanM_PapSmearBahanID = M_PapSmearBahanID AND - Other_PapSmearBahanOther_PapSmearID = {$header_id} AND - Other_PapSmearBahanIsActive = 'Y' - WHERE - M_PapSmearBahanIsActive = 'Y' - ORDER BY M_PapSmearBahanID ASC - "; - //echo $sql; - $bahans = $this->db_smartone->query($sql)->result_array(); - - $sql = "SELECT IFNULL(Other_PapsmearCategoryID,0) as xid, - M_PapSmearCategoryID as category_id, - M_PapSmearCategoryName as name, - IF(ISNULL(Other_PapsmearCategoryID),'N','Y') as selected - FROM m_papsmearcategory - LEFT JOIN other_papsmearcategory ON Other_PapsmearCategoryM_PapSmearCategoryID = M_PapSmearCategoryID AND - Other_PapsmearCategoryOther_PapSmearID = {$header_id} AND - Other_PapsmearCategoryIsActive = 'Y' - WHERE - M_PapSmearCategoryIsActive = 'Y' - ORDER BY M_PapSmearCategoryID ASC - "; - //echo $sql; - $categories = $this->db_smartone->query($sql)->result_array(); - - $sql = "SELECT IFNULL(Other_PapSmearCheckID,0) as xid, - M_PapSmearCheckID as check_id, - M_PapSmearCheckLabel as name, - IF(ISNULL(Other_PapSmearCheckID),'N','Y') as selected, - Other_PapSmearCheckNote as note - FROM m_papsmearcheck - LEFT JOIN other_papsmearcheck ON Other_PapSmearCheckM_PapSmearCheckID = M_PapSmearCheckID AND - Other_PapSmearCheckOther_PapSmearID = {$header_id} AND - Other_PapSmearCheckIsActive = 'Y' - WHERE - M_PapSmearCheckIsActive = 'Y' - ORDER BY M_PapSmearCheckCode ASC - "; - $checks = $this->db_smartone->query($sql)->result_array(); - - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $rst = array('doctors'=>$doctors,'checks'=>$checks,'bahans'=>$bahans,'categories'=>$categories,'maturasi'=>$maturasi,'results'=>$rows); - $this->sys_ok(["records"=>$rst]); - - } - - function saveresult_lcprep() - { - $prm = $this->sys_input; - $detail_id = $prm['detail_id']; - $doctor_id = $prm['doctor']; - $adekuasi = $prm['adekuasi']; - $kategoriumum = $prm['kategoriumum']; - $interpretasi = $prm['interpretasi']; - $results = $prm['results']; - - $userid = $this->sys_user['M_UserID']; - - $header_id = 0; - $sql = "SELECT * FROM other_lcprep WHERE Other_LcprepT_orderDetailID = {$detail_id} AND Other_LcprepIsActive = 'Y'"; - $dt_header = $this->db_smartone->query($sql)->row_array(); - if($dt_header){ - $header_id = $dt_header['Other_LcprepID']; - } - if($header_id == 0){ - $sql = "INSERT INTO other_lcprep( - Other_LcprepT_orderDetailID, - Other_LcprepM_DoctorID, - Other_LcprepUserID, - Other_LcprepCreated - ) - VALUES( - {$detail_id}, - {$doctor_id}, - {$userid}, - NOW() - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - }else{ - $sql = "UPDATE other_lcprep SET Other_LcprepM_DoctorID = {$doctor_id}, Other_LcprepUserID = {$userid} WHERE Other_LcprepID = {$header_id}"; - $this->db_smartone->query($sql); - } - - if($adekuasi){ - foreach($adekuasi as $k =>$v){ - $selected = $v['chex']?'Y':'N'; - if(intval($v['xid'] == 0)){ - $sql = "UPDATE other_lcprepadekuasi SET Other_LcprepAdekuasiIsActive = 'N' - WHERE - Other_LcprepAdekuasiOther_LcprepID = {$header_id} AND - Other_LcprepAdekuasiIsActive = 'Y' AND - Other_LcprepAdekuasiLcprep_AdekuasiID = {$v['id']}"; - $this->db_smartone->query($sql); - $sql = "INSERT INTO other_lcprepadekuasi ( - Other_LcprepAdekuasiOther_LcprepID, - Other_LcprepAdekuasiLcprep_AdekuasiID, - Other_LcprepAdekuasiChex, - Other_LcprepAdekuasiUserID, - Other_LcprepAdekuasiCreated - ) - VALUES( - {$header_id}, - {$v['id']}, - '{$selected}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - //echo $sql; - } - if(intval($v['xid'] != 0)){ - - $sql = "UPDATE other_lcprepadekuasi SET - Other_LcprepAdekuasiChex = '{$selected}', - Other_LcprepAdekuasiUserID = {$userid} - WHERE - Other_LcprepAdekuasiID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - - //echo $sql; - } - } - - if($kategoriumum){ - foreach($kategoriumum as $k =>$v){ - $selected = $v['chex']?'Y':'N'; - if(intval($v['xid'] == 0)){ - $sql = "UPDATE other_lcprepkategoriumum SET Other_LcprepKategoriUmumIsActive = 'N' - WHERE - Other_LcprepKategoriUmumOther_LcprepID = {$header_id} AND - Other_LcprepKategoriUmumLcprep_KategoriUmumID = {$v['id']} AND - Other_LcprepKategoriUmumIsActive = 'Y' - "; - $this->db_smartone->query($sql); - $sql = "INSERT INTO other_lcprepkategoriumum ( - Other_LcprepKategoriUmumOther_LcprepID, - Other_LcprepKategoriUmumLcprep_KategoriUmumID, - Other_LcprepKategoriUmumChex, - Other_LcprepKategoriUmumUserID, - Other_LcprepKategoriUmumCreated - ) - VALUES( - {$header_id}, - {$v['id']}, - '{$selected}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if(intval($v['xid'] != 0)){ - $sql = "UPDATE other_lcprepkategoriumum SET - Other_LcprepKategoriUmumChex = '{$selected }', - Other_LcprepKategoriUmumUserID = {$userid} - WHERE - Other_LcprepKategoriUmumID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - - //echo $sql; - } - } - - if($results){ - foreach($results as $k =>$v){ - if(intval($v['xid'] == 0)){ - $sql = "UPDATE other_lcprepdetails SET Other_LcprepDetailsIsActive = 'N' - WHERE - Other_LcprepDetailsOther_LcprepID = {$header_id} AND - Other_LcprepDetailsCode = '{$v['code']}' AND - Other_LcprepDetailsIsActive = 'Y'"; - $this->db_smartone->query($sql); - $sql = "INSERT INTO other_lcprepdetails ( - Other_LcprepDetailsOther_LcprepID, - Other_LcprepDetailsCode, - Other_LcprepDetailsLabel, - Other_LcprepDetailsResult, - Other_LcprepDetailsUserID, - Other_LcprepDetailsCreated - ) - VALUES( - {$header_id}, - '{$v['code']}', - '{$v['label']}', - '{$v['result']}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if(intval($v['xid'] != 0)){ - $sql = "UPDATE other_lcprepdetails SET - Other_LcprepDetailsCode = '{$v['code']}', - Other_LcprepDetailsLabel = '{$v['label']}', - Other_LcprepDetailsResult = '{$v['result']}', - Other_LcprepDetailsUserID = {$userid} - WHERE - Other_LcprepDetailsID = {$v['xid']}"; - $this->db_smartone->query($sql); - - } - //echo $sql; - } - } - - if($interpretasi){ - foreach($interpretasi as $k =>$v){ - if(count($v['subgroups']) > 0){ - foreach($v['subgroups'] as $ik => $iv){ - if(count($iv['childs']) > 0){ - foreach($iv['childs'] as $iik => $iiv){ - if(intval($iiv['xid'] == 0)){ - $chex = $iiv['chex'] ? 'Y':'N'; - $sql = "UPDATE other_lcprepinterpretasi SET Other_LcprepInterpretasiIsActive = 'N' - WHERE - Other_LcprepInterpretasiOther_LcprepID = {$header_id} AND - Other_LcprepInterpretasiLcprep_InterpretasiID = '{$iiv['id']}' AND - Other_LcprepInterpretasiIsActive = 'Y'"; - $this->db_smartone->query($sql); - $sql = "INSERT INTO other_lcprepinterpretasi ( - Other_LcprepInterpretasiOther_LcprepID, - Other_LcprepInterpretasiLcprep_InterpretasiID, - Other_LcprepInterpretasiChex, - Other_LcprepInterpretasiValue, - Other_LcprepInterpretasiUserID, - Other_LcprepInterpretasiCreated - ) - VALUES( - {$header_id}, - '{$iiv['id']}', - '{$chex}', - '{$iiv['value']}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - - if(intval($iiv['xid'] != 0)){ - $chex = $iiv['chex'] ? 'Y':'N'; - $sql = "UPDATE other_lcprepinterpretasi SET - Other_LcprepInterpretasiChex = '{$chex}', - Other_LcprepInterpretasiValue = '{$iiv['value']}', - Other_LcprepInterpretasiUserID = {$userid} - WHERE - Other_LcprepInterpretasiID = {$iiv['xid']}"; - $this->db_smartone->query($sql); - //echo $sql; - - } - - } - } - } - } - //echo $sql; - } - } - - - $result = array("total" => 1, "records" => array(), "sql"=> ''); - $this->sys_ok($result); - exit; - } - - function saveresult_papsmear() - { - $prm = $this->sys_input; - $detail_id = $prm['detail_id']; - $doctor_id = $prm['doctor']; - $checks = $prm['checks']; - $maturasi = $prm['maturasi']; - $bahans = $prm['bahans']; - $categories = $prm['categories']; - $results = $prm['results']; - - $userid = $this->sys_user['M_UserID']; - - $header_id = 0; - $sql = "SELECT * FROM other_papsmear WHERE Other_PapSmearT_OrderDetailID = {$detail_id} AND Other_PapSmearIsActive = 'Y'"; - $dt_header = $this->db_smartone->query($sql)->row_array(); - if($dt_header){ - $header_id = $dt_header['Other_PapSmearID']; - } - if($header_id == 0){ - $sql = "INSERT INTO other_papsmear( - Other_PapSmearT_OrderDetailID, - Other_PapSmearM_DoctorID, - Other_PapSmearUserID, - Other_PapSmearCreated - ) - VALUES( - {$detail_id}, - {$doctor_id}, - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } - else{ - $sql = "UPDATE other_papsmear SET Other_PapSmearM_DoctorID = {$doctor_id}, Other_PapSmearUserID = {$userid} WHERE Other_PapSmearID = {$header_id}"; - $this->db_smartone->query($sql); - } - - if($checks){ - foreach($checks as $k =>$v){ - if(intval($v['xid']) == 0 && $v['selected'] === 'Y'){ - $sql = "INSERT INTO other_papsmearcheck ( - Other_PapSmearCheckOther_PapSmearID, - Other_PapSmearCheckM_PapSmearCheckID, - Other_PapSmearCheckNote, - Other_PapSmearCheckUserID, - Other_PapSmearCheckCreated - ) - VALUES( - {$header_id}, - {$v['check_id']}, - '{$v['note']}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if(intval($v['xid']) != 0 && $v['selected'] === 'N'){ - $sql = "UPDATE other_papsmearcheck SET - Other_PapSmearCheckIsActive = 'N', - Other_PapSmearCheckUserID = {$userid} - WHERE - Other_PapSmearCheckID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - if(intval($v['xid']) != 0 && $v['selected'] === 'Y'){ - $sql = "UPDATE other_papsmearcheck SET - Other_PapSmearCheckNote = '{$v['note']}', - Other_PapSmearCheckUserID = {$userid} - WHERE - Other_PapSmearCheckID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - //echo $sql; - } - } - - if($maturasi){ - if(intval($maturasi['xid']) == 0){ - $value = join("/",$maturasi['value']); - $sql = "INSERT INTO other_papsmearmaturasi ( - Other_PapSmearMaturasiOther_PapSmearID, - Other_PapSmearMaturasiValue, - Other_PapSmearMaturasiUserID, - Other_PapSmearMaturasiCreated - ) - VALUE( - {$header_id}, - '{$value}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - //echo $sql; - } - if(intval($maturasi['xid']) != 0){ - $value = join("/",$maturasi['value']); - $sql = "UPDATE other_papsmearmaturasi SET - Other_PapSmearMaturasiValue = '{$value}', - Other_PapSmearMaturasiUserID = {$userid} - WHERE - Other_PapSmearMaturasiID = {$maturasi['xid']}"; - // echo $sql; - $this->db_smartone->query($sql); - } - } - - if($bahans){ - foreach($bahans as $k =>$v){ - if(intval($v['xid']) == 0 && $v['selected'] === 'Y'){ - $sql = "INSERT INTO other_papsmearbahan ( - Other_PapSmearBahanOther_PapSmearID, - Other_PapSmearBahanM_PapSmearBahanID, - Other_PapSmearBahanUserID, - Other_PapSmearBahanCreated - ) - VALUES( - {$header_id}, - {$v['bahan_id']}, - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if(intval($v['xid']) != 0 && $v['selected'] === 'N'){ - $sql = "UPDATE other_papsmearbahan SET - Other_PapSmearBahanIsActive = 'N', - Other_PapsmearCategoryUserID = {$userid} - WHERE - Other_PapSmearBahanID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - if(intval($v['xid']) != 0 && $v['selected'] === 'Y'){ - $sql = "UPDATE other_papsmearbahan SET - Other_PapSmearBahanIsActive = 'Y', - Other_PapsmearCategoryUserID = {$userid} - WHERE - Other_PapSmearBahanID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - //echo $sql; - } - } - - if($categories){ - foreach($categories as $k =>$v){ - if(intval($v['xid']) == 0 && $v['selected'] === 'Y'){ - $sql = "INSERT INTO other_papsmearcategory ( - Other_PapsmearCategoryOther_PapSmearID, - Other_PapsmearCategoryM_PapSmearCategoryID, - Other_PapsmearCategoryUserID, - Other_PapsmearCategoryCreated - ) - VALUES( - {$header_id}, - {$v['category_id']}, - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if(intval($v['xid']) != 0 && $v['selected'] === 'N'){ - $sql = "UPDATE other_papsmearcategory SET - Other_PapsmearCategoryIsActive = 'N', - Other_PapsmearCategoryUserID = {$userid} - WHERE - Other_PapsmearCategoryID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - //echo $sql; - if(intval($v['xid']) != 0 && $v['selected'] === 'Y'){ - $sql = "UPDATE other_papsmearcategory SET - Other_PapsmearCategoryIsActive = 'Y', - Other_PapsmearCategoryUserID = {$userid} - WHERE - Other_PapsmearCategoryID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - } - } - - if($results){ - foreach($results as $k =>$v){ - if(intval($v['xid']) == 0){ - $sql = "INSERT INTO other_papsmeardetails ( - Other_PapSmearDetailsOther_PapSmearID, - Other_PapSmearDetailsCode, - Other_PapSmearDetailsLabel, - Other_PapSmearDetailsResult, - Other_PapSmearDetailsUserID, - Other_PapSmearDetailsCreated - ) - VALUES( - {$header_id}, - '{$v['code']}', - '{$v['label']}', - '{$v['result']}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if(intval($v['xid']) != 0){ - $sql = "UPDATE other_papsmeardetails SET - Other_PapSmearDetailsCode = '{$v['code']}', - Other_PapSmearDetailsLabel = '{$v['label']}', - Other_PapSmearDetailsResult = '{$v['result']}', - Other_PapSmearDetailsUserID = {$userid} - WHERE - Other_PapSmearDetailsID = {$v['xid']}"; - $this->db_smartone->query($sql); - - } - //echo $sql; - } - } - - $result = array("total" => 1, "records" => array(), "sql"=> ''); - $this->sys_ok($result); - exit; - } - - function saveresult_fna() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = $inp['doctor']; - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - if($prm[0]['xid'] == '0'){ - $sql = "INSERT INTO other_fna( - Other_FNAM_DoctorID, - Other_FNAT_OrderDetailID, - Other_FNAUserID, - Other_FNACreated - ) - VALUES( - {$doctor_id}, - {$prm[0]['orderdetail_id']}, - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } - else{ - $sql = "SELECT * FROM other_fna WHERE Other_FNAT_OrderDetailID = {$prm[0]['orderdetail_id']} AND Other_FNAIsActive = 'Y'"; - $data_header = $this->db_smartone->query($sql)->row_array(); - $header_id = $data_header['Other_FNAID']; - $sql = "UPDATE other_fna SET - Other_FNAM_DoctorID = {$doctor_id}, - Other_FNAUserID = {$userid} - WHERE - Other_FNAID = {$header_id}"; - $this->db_smartone->query($sql); - } - foreach($prm as $k => $v){ - if($v['xid'] == '0'){ - $results = str_replace("'", "\\'", $v['result']); - $sql = "INSERT INTO other_fnadetails( - Other_FNADetailsOther_FNAID , - Other_FNADetailsCode, - Other_FNADetailsLabel, - Other_FNADetailsResult, - Other_FNADetailsCreated, - Other_FNADetailsUserID - ) - VALUES( - {$header_id}, - '{$v['code']}', - '{$v['label']}', - '{$results}', - NOW(), - {$userid} - )"; - $query = $this->db_smartone->query($sql); - } - else{ - $results = str_replace("'", "\\'", $v['result']); - $sql = "UPDATE other_fnadetails SET - Other_FNADetailsResult = '{$results}', - Other_FNADetailsUserID = {$userid} - WHERE - Other_FNADetailsID = {$v['xid']}"; - $query = $this->db_smartone->query($sql); - } - } - - $result = array("total" => 1, "records" => array(), "sql"=> ''); - $this->sys_ok($result); - exit; - } - - function saveresult_cytologi() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = $inp['doctor']; - - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - if($prm[0]['xid'] == '0'){ - $sql = "INSERT INTO other_cytologi( - Other_CytologiT_OrderDetailID, - Other_CytologiM_DoctorID, - Other_CytologiUserID, - Other_CytologiCreated - ) - VALUES( - {$prm[0]['orderdetail_id']}, - {$doctor_id}, - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } - else{ - $sql = "SELECT * FROM other_cytologi WHERE Other_CytologiT_OrderDetailID = {$prm[0]['orderdetail_id']} AND Other_CytologiIsActive = 'Y'"; - $data_header = $this->db_smartone->query($sql)->row_array(); - $header_id = $data_header['Other_CytologiID']; - $sql = "UPDATE other_cytologi SET - Other_CytologiM_DoctorID = {$doctor_id}, - Other_CytologiUserID = {$userid} - WHERE - Other_CytologiID = {$header_id}"; - $this->db_smartone->query($sql); - } - foreach($prm as $k => $v){ - if($v['xid'] == '0'){ - $results = str_replace("'", "\\'", $v['result']); - $sql = "INSERT INTO other_cytologidetails( - Other_CytologiDetailsOther_CytologiID , - Other_CytologiDetailsCode, - Other_CytologiDetailsLabel, - Other_CytologiDetailsResult, - Other_CytologiDetailsCreated, - Other_CytologiDetailsUserID - ) - VALUES( - {$header_id}, - '{$v['code']}', - '{$v['label']}', - '{$results}', - NOW(), - {$userid} - )"; - $query = $this->db_smartone->query($sql); - } - else{ - $results = str_replace("'", "\\'", $v['result']); - $sql = "UPDATE other_cytologidetails SET - Other_CytologiDetailsResult = '{$results}', - Other_CytologiDetailsUserID = {$userid} - WHERE - Other_CytologiDetailsID = {$v['xid']}"; - $query = $this->db_smartone->query($sql); - } - } - - $result = array("total" => 1, "records" => array(), "sql"=> ''); - $this->sys_ok($result); - exit; - } - - function saveresult_mikro() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = $inp['doctor']; - $backteria_id = $inp['bacteria']; - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - - if($inp['result_value'] != 'Negatif' && $inp['result_value'] != 'Positif'){ - $prm['result_value'] = $prm['result_other']; - } - else{ - $prm['result_value'] = $inp['result_value']; - } - - if($prm['xid'] == '0'){ - $sql = "INSERT INTO other_mikro( - Other_MikroM_DoctorID, - Other_MikroResult, - Other_MikroT_BacteriaID, - Other_MikroT_OrderDetailID, - Other_MikroHasilBiakan, - Other_MikroSampleTypeName, - Other_MikroUserID, - Other_MikroCreated - ) - VALUES( - {$doctor_id}, - '{$prm['result_value']}', - {$backteria_id}, - {$prm['orderdetail_id']}, - '{$prm['hasil_biakan']}', - '{$prm['sample_name']}', - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } - else{ - $sql = "SELECT * FROM other_mikro WHERE Other_MikroT_OrderDetailID = {$prm['orderdetail_id']} AND Other_MikroIsActive = 'Y'"; - $data_header = $this->db_smartone->query($sql)->row_array(); - $header_id = $data_header['Other_MikroID']; - $sql = "UPDATE other_mikro SET - Other_MikroResult = '{$prm['result_value']}', - Other_MikroM_DoctorID = {$doctor_id}, - Other_MikroT_BacteriaID = {$backteria_id}, - Other_MikroHasilBiakan = '{$prm['hasil_biakan']}', - Other_MikroSampleTypeName = '{$prm['sample_name']}', - Other_MikroUserID = {$userid} - WHERE - Other_MikroID = {$header_id}"; - //echo $sql; - $this->db_smartone->query($sql); - } - - - - $sql = "UPDATE other_mikrodetails SET Other_MikroDetailsIsActive = 'N', Other_MikroDetailsUserID = 0 WHERE Other_MikroDetailsOther_MikroID = {$header_id}"; - $this->db_smartone->query($sql); - - $results = $prm['details']; - if($inp['result_value'] == 'Positif'){ - foreach($results as $k => $v){ - if($v['xid'] == '0'){ - $sql = "INSERT INTO other_mikrodetails( - Other_MikroDetailsOther_MikroID , - Other_MikroDetailsT_AntibioticID, - Other_MikroDetailsValue, - Other_MikroDetailsNote, - Other_MikroDetailsCreated, - Other_MikroDetailsUserID - ) - VALUES( - {$header_id}, - '{$v['T_AntibioticID']}', - '{$v['value']}', - '{$v['note']}', - NOW(), - {$userid} - )"; - $query = $this->db_smartone->query($sql); - } - else{ - $sql = "UPDATE other_mikrodetails SET - Other_MikroDetailsT_AntibioticID = '{$v['T_AntibioticID']}', - Other_MikroDetailsValue = '{$v['value']}', - Other_MikroDetailsNote = '{$v['note']}', - Other_MikroDetailsIsActive = 'Y', - Other_MikroDetailsUserID = {$userid} - WHERE - Other_MikroDetailsID = {$v['xid']}"; - //echo $sql; - $query = $this->db_smartone->query($sql); - } - } - } - - - $result = array("total" => 1, "records" => array(), "sql"=> ''); - $this->sys_ok($result); - exit; - } - - - function get_doctors_preparasi_sperma() - { - $prm = $this->sys_input; - // $id = $prm["id"]; - - $sql = " SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 10 AND - M_DoctorSOIsActive = 'Y' - ORDER BY M_DoctorName ASC"; - //echo $sql; - $query = $this->db_smartone->query($sql); - - if ($query) - { - $rows = $query->result_array(); - $this->sys_ok(["records"=>$rows]); - } - else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - - function getpreparasispermaresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT other_preparasisperma.*, - Other_PreparasiSpermaID as xid, - Other_PreparasiSpermaT_OrderDetailID as orderdetail_id, - IFNULL(Other_PreparasiSpermaM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_PreparasiSpermaM_DoctorID) OR Other_PreparasiSpermaM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_preparasisperma - LEFT JOIN m_doctor ON Other_PreparasiSpermaM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_PreparasiSpermaT_OrderDetailID = {$id} AND Other_PreparasiSpermaIsActive = 'Y' - GROUP BY Other_PreparasiSpermaID"; - $query = $this->db_smartone->query($sql); - - if ($query) - { - $rows = $query->row_array(); - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 10 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $images = array(); - $sql = "SELECT Other_PreparasiSpermaImgID as xid, - Other_PreparasiSpermaImgType as type, - CONCAT('/one-media/one-image-nonlab/',Other_PreparasiSpermaImgNewName) as image_url - FROM t_orderdetail - JOIN other_preparasisperma_img ON Other_PreparasiSpermaImgT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND - Other_PreparasiSpermaImgIsActive = 'Y' - WHERE - T_OrderDetailID = {$id} AND - T_OrderDetailIsActive = 'Y' - GROUP BY Other_PreparasiSpermaImgID"; - //echo $sql; - $images = $this->db_smartone->query($sql)->result_array(); - - $rst = array('doctors'=>$doctors,'results'=>$rows,'images'=>$images); - $this->sys_ok(["records"=>$rst]); - } - else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - - function uploadimage_preparasi_sperma(){ - if (! $this->isLogin) { - $this->sys_error("Invalid Token"); - exit; - } - - $userid = $this->sys_user["M_UserID"]; - $data = []; - //print_r($_SERVER); - - $prm = $this->sys_input; - $orderid = $this->input->post('orderid'); - $type = $this->input->post('type'); - $labnumber = $this->input->post('labnumber'); - $sql = "UPDATE other_preparasisperma_img SET - Other_PreparasiSpermaImgIsActive = 'N', - Other_PreparasiSpermaImgUserID = {$userid} - WHERE - Other_PreparasiSpermaImgT_OrderHeaderID = {$orderid} AND - Other_PreparasiSpermaImgType = '{$type}'"; - //echo $sql; - $this->db_onedev->query($sql); - //$config['upload_path'] = 'assets/'; - - $path = '/home/one/project/one/one-media/one-image-nonlab/'; - //echo $path; - $config['upload_path'] = $path; - $config['allowed_types'] = 'jpg|jpeg|png|gif'; - - $config['max_size'] = '10000'; - $count = count($_FILES['files']['name']); - //echo $count; - $this->load->library('upload',$config); - - $error = []; - for($i=0;$i<$count;$i++){ - - - if(!empty($_FILES['files']['name'][$i])){ - - - - $_FILES['file']['name'] = $_FILES['files']['name'][$i]; - - $_FILES['file']['type'] = $_FILES['files']['type'][$i]; - - $_FILES['file']['tmp_name'] = $_FILES['files']['tmp_name'][$i]; - - $_FILES['file']['error'] = $_FILES['files']['error'][$i]; - - $_FILES['file']['size'] = $_FILES['files']['size'][$i]; - - - - $namex = $orderid.'-'.$labnumber.'-'.$this->generateRandomString(5); - //echo $namex; - - $config['file_name'] = $namex; - $this->upload->initialize($config); - //echo $config['file_name'] ; - - - - - - if($this->upload->do_upload('file')){ - - $uploadData = $this->upload->data(); - - $filename = $uploadData['file_name']; - //echo $filename; - - - $sql = "INSERT INTO other_preparasisperma_img ( - Other_PreparasiSpermaImgT_OrderHeaderID, - Other_PreparasiSpermaImgType, - Other_PreparasiSpermaImgOldName, - Other_PreparasiSpermaImgNewName, - Other_PreparasiSpermaImgCreated, - Other_PreparasiSpermaImgUserID - ) - VALUES( - {$orderid}, - '{$type}', - '{$_FILES['files']['name'][$i]}', - '{$filename}', - NOW(), - {$userid} - - )"; - //echo $sql; - $this->db_onedev->query($sql); - $xlast_id = $this->db_onedev->insert_id(); - $data['totalFiles'][] = array('xid' => $xlast_id ,'type'=>$type,'image_url' => '/one-media/one-image-nonlab/'.$filename); - - } - else{ - $error = array('error' => $this->upload->display_errors()); - } - - } - - - - } - - $result = array("total" =>count( $data['totalFiles']), "records" => $data['totalFiles'],'errors'=>$error); - $this->sys_ok($result); - } - - - function saveresult_preparasi_sperma() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = $inp['doctor']; - $orderdetail_id = $inp['orderdetailid']; - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - if($prm['xid'] == '0'){ - $sql = "INSERT INTO other_preparasisperma( - Other_PreparasiSpermaM_DoctorID, - Other_PreparasiSpermaT_OrderDetailID, - Other_PreparasiSpermaPreMotilitasA, - Other_PreparasiSpermaPreMotilitasB, - Other_PreparasiSpermaPreMotilitasC, - Other_PreparasiSpermaPreKonsentrasi, - Other_PreparasiSpermaPreKontaminan, - Other_PreparasiSpermaPostMotilitasA, - Other_PreparasiSpermaPostMotilitasB, - Other_PreparasiSpermaPostMotilitasC, - Other_PreparasiSpermaPostKonsentrasi, - Other_PreparasiSpermaPostKontaminan, - Other_PreparasiSpermaNote, - Other_PreparasiSpermaUserID, - Other_PreparasiSpermaCreated - ) - VALUES( - {$doctor_id}, - {$orderdetail_id}, - '{$prm['Other_PreparasiSpermaPreMotilitasA']}', - '{$prm['Other_PreparasiSpermaPreMotilitasB']}', - '{$prm['Other_PreparasiSpermaPreMotilitasC']}', - '{$prm['Other_PreparasiSpermaPreKonsentrasi']}', - '{$prm['Other_PreparasiSpermaPreKontaminan']}', - '{$prm['Other_PreparasiSpermaPostMotilitasA']}', - '{$prm['Other_PreparasiSpermaPostMotilitasB']}', - '{$prm['Other_PreparasiSpermaPostMotilitasC']}', - '{$prm['Other_PreparasiSpermaPostKonsentrasi']}', - '{$prm['Other_PreparasiSpermaPostKontaminan']}', - '{$prm['Other_PreparasiSpermaNote']}', - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } - else{ - $sql = "SELECT * FROM other_preparasisperma WHERE Other_PreparasiSpermaT_OrderDetailID = {$orderdetail_id} AND Other_PreparasiSpermaIsActive = 'Y'"; - $data_header = $this->db_smartone->query($sql)->row_array(); - $header_id = $data_header['Other_PreparasiSpermaID']; - $sql = "UPDATE other_preparasisperma SET - Other_PreparasiSpermaM_DoctorID = {$doctor_id}, - Other_PreparasiSpermaPreMotilitasA = '{$prm['Other_PreparasiSpermaPreMotilitasA']}', - Other_PreparasiSpermaPreMotilitasB = '{$prm['Other_PreparasiSpermaPreMotilitasB']}', - Other_PreparasiSpermaPreMotilitasC = '{$prm['Other_PreparasiSpermaPreMotilitasC']}', - Other_PreparasiSpermaPreKonsentrasi = '{$prm['Other_PreparasiSpermaPreKonsentrasi']}', - Other_PreparasiSpermaPreKontaminan = '{$prm['Other_PreparasiSpermaPreKontaminan']}', - Other_PreparasiSpermaPostMotilitasA = '{$prm['Other_PreparasiSpermaPostMotilitasA']}', - Other_PreparasiSpermaPostMotilitasB = '{$prm['Other_PreparasiSpermaPostMotilitasB']}', - Other_PreparasiSpermaPostMotilitasC = '{$prm['Other_PreparasiSpermaPostMotilitasC']}', - Other_PreparasiSpermaPostKonsentrasi = '{$prm['Other_PreparasiSpermaPostKonsentrasi']}', - Other_PreparasiSpermaPostKontaminan = '{$prm['Other_PreparasiSpermaPostKontaminan']}', - Other_PreparasiSpermaNote = '{$prm['Other_PreparasiSpermaNote']}', - Other_PreparasiSpermaUserID = {$userid} - WHERE - Other_PreparasiSpermaID = {$header_id}"; - $this->db_smartone->query($sql); - } - - - $result = array("total" => 1, "records" => array(), "sql"=> ''); - $this->sys_ok($result); - exit; - } - - function getdnafragmentasiresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT other_dnafragmentasi.*, - Other_DnaFragmentasiID as xid, - Other_DnaFragmentasiT_OrderDetailID as orderdetail_id, - IFNULL(Other_DnaFragmentasiM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_DnaFragmentasiM_DoctorID) OR Other_DnaFragmentasiM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name, - IFNULL(Other_DnaFragmentasiOther_DnaFragmentasiMethodeID,0) as methode_id, - IFNULL(Other_DnaFragmentasiMethodeName,'') as methode_name, - Other_DnaFragmentasiHaloLuas as halo_luas, - Other_DnaFragmentasiHaloSedang as halo_sedang, - Other_DnaFragmentasiHaloSempit as halo_sempit, - Other_DnaFragmentasiTanpaHalo as tanpa_halo, - Other_DnaFragmentasiDFI as dfi, - Other_DnaFragmentasiKesimpulan as kesimpulan, - Other_DnaFragmentasiCatatan as catatan - FROM other_dnafragmentasi - LEFT JOIN m_doctor ON Other_DnaFragmentasiM_DoctorID = M_DoctorID - LEFT JOIN other_dnafragmentasimethode ON Other_DnaFragmentasiOther_DnaFragmentasiMethodeID = Other_DnaFragmentasiMethodeID - WHERE - Other_DnaFragmentasiT_OrderDetailID = {$id} AND Other_DnaFragmentasiIsActive = 'Y' - GROUP BY Other_DnaFragmentasiID - LIMIT 1"; - //echo $sql; - $query = $this->db_smartone->query($sql); - - if ($query) - { - $rows = $query->row_array(); - if(!$rows){ - $rows = array( - 'xid' => 0, - 'orderdetail_id' =>$id, - 'doctor_id' => 0, - 'doctor_name' => '', - 'methode_id' => 0, - 'methode_name' => '', - 'halo_luas' => '', - 'halo_sedang' => '', - 'tanpa_halo' => '', - 'dfi' => '', - 'kesimpulan' => '', - 'catatan' => '' - ); - } - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID - WHERE - M_DoctorSONat_SubGroupID = 4 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - - $sql = " - SELECT '0' as id, 'Belum memilih metode' as name - UNION - SELECT Other_DnaFragmentasiMethodeID as id, Other_DnaFragmentasiMethodeName as name - FROM other_dnafragmentasimethode - WHERE - Other_DnaFragmentasiMethodeIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $methodes = $this->db_smartone->query($sql)->result_array(); - - - $rst = array('doctors'=>$doctors,'methodes'=>$methodes,'results'=>$rows); - $this->sys_ok(["records"=>$rst]); - } - else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - function saveresult_dnafragmentasi() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = $inp['doctor']['id']; - $methode_id = $inp['methode']['id']; - $orderdetail_id = $inp['results']['orderdetail_id']; - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - if(intval($prm['xid']) == 0){ - $sql = "INSERT INTO other_dnafragmentasi( - Other_DnaFragmentasiT_OrderDetailID, - Other_DnaFragmentasiM_DoctorID, - Other_DnaFragmentasiOther_DnaFragmentasiMethodeID, - Other_DnaFragmentasiHaloLuas, - Other_DnaFragmentasiHaloSedang, - Other_DnaFragmentasiHaloSempit, - Other_DnaFragmentasiTanpaHalo, - Other_DnaFragmentasiDFI, - Other_DnaFragmentasiKesimpulan, - Other_DnaFragmentasiCatatan, - Other_DnaFragmentasiUserID, - Other_DnaFragmentasiLastUpdated - ) - VALUES( - {$orderdetail_id}, - {$doctor_id}, - {$methode_id}, - '{$prm['halo_luas']}', - '{$prm['halo_sedang']}', - '{$prm['halo_sempit']}', - '{$prm['tanpa_halo']}', - '{$prm['dfi']}', - '{$prm['kesimpulan']}', - '{$prm['catatan']}', - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } - else{ - $sql = "UPDATE other_dnafragmentasi SET - Other_DnaFragmentasiT_OrderDetailID = {$orderdetail_id}, - Other_DnaFragmentasiM_DoctorID = {$doctor_id}, - Other_DnaFragmentasiOther_DnaFragmentasiMethodeID = '{$methode_id}', - Other_DnaFragmentasiHaloLuas = '{$prm['halo_luas']}', - Other_DnaFragmentasiHaloSedang = '{$prm['halo_sedang']}', - Other_DnaFragmentasiHaloSempit = '{$prm['halo_sempit']}', - Other_DnaFragmentasiTanpaHalo = '{$prm['tanpa_halo']}', - Other_DnaFragmentasiDFI = '{$prm['dfi']}', - Other_DnaFragmentasiKesimpulan = '{$prm['kesimpulan']}', - Other_DnaFragmentasiCatatan = '{$prm['catatan']}', - Other_DnaFragmentasiLastUpdated = NOW(), - Other_DnaFragmentasiUserID = {$userid} - WHERE - Other_DnaFragmentasiID = {$prm['xid']}"; - //echo $sql; - $this->db_smartone->query($sql); - } - - - $result = array("total" => 1, "records" => array(), "sql"=> ''); - $this->sys_ok($result); - exit; - } - - -} - +db_smartone = $this->load->database("onedev", true); + $this->load->helper(array('form', 'url')); + } + function getMethodeID($natTestID) { + $sql = "select M_MethodePriorityNat_MethodeID MethodeID, Nat_MethodeName + from + m_methode_priority + join nat_methode on Nat_MethodeID = M_MethodePriorityNat_MethodeID + and Nat_MethodeIsActive = 'Y' + join m_instrumentmethode on M_InstrumentMethodeNat_MethodeID = Nat_MethodeID and M_InstrumentMethodeIsActive = 'Y' + join nat_instrument on M_InstrumentMethodeNat_InstrumentID = Nat_InstrumentID + and Nat_InstrumentIsActive ='Y' + where M_MethodePriorityIsActive = 'Y' + and M_MethodePriorityNat_TestID = $natTestID + and M_MethodePriorityM_DayOfWeekID = dayofweek(now()) + order by M_MethodePriorityNumber desc + limit 0,1 "; + $qry = $this->db->query($sql); + if ($qry) { + $rows = $qry->result_array(); + if (count($rows) > 0 ) return array($rows[0]["MethodeID"],$rows[0]["Nat_MethodeName"]); + } + //2nd + $sql= "select + M_InstrumentMethodeNat_MethodeID MethodeID, Nat_MethodeName + from m_instrumentmethode + join nat_methode on M_InstrumentMethodeNat_MethodeID = Nat_MethodeID + and Nat_MethodeIsActive = 'Y' + join nat_instrument on M_InstrumentMethodeNat_InstrumentID = Nat_InstrumentID + and Nat_InstrumentIsActive ='Y' + where M_InstrumentMethodeNat_TestID = $natTestID + and M_InstrumentMethodeIsActive = 'Y' + order by M_InstrumentMethodePriority desc + limit 0,1"; + $qry = $this->db->query($sql); + if ($qry) { + $rows = $qry->result_array(); + if (count($rows) > 0 ) return array($rows[0]["MethodeID"],$rows[0]["Nat_MethodeName"]); + } + // + $sql = "select Nat_NormalValueNat_MethodeID MethodeID, Nat_MethodeName + from + nat_normalvalue + join nat_methode on Nat_NormalValueNat_MethodeID = Nat_MethodeID + and Nat_MethodeIsActive = 'Y' + where Nat_NormalValueNat_TestID = $natTestID + and Nat_NormalValueIsActive = 'Y' + order by Nat_NormalValueID + limit 0,1"; + $qry = $this->db->query($sql); + if ($qry) { + $rows = $qry->result_array(); + if (count($rows) > 0 ) return array($rows[0]["MethodeID"],$rows[0]["Nat_MethodeName"]); + } + return array(0,""); + } + function get_normal_value($methodeID, $natTestID, $sexID, $ageInDay ) { + $this->load->library('ibl_sampling_normal'); + return $this->ibl_sampling_normal->get_normal_value_id($methodeID, $natTestID, $sexID, $ageInDay); + } + return 0; + } + function fn_fix_normal($order_id) { + $sql = "select + T_OrderDetailID, M_PatientM_SexID, fn_global_age_count_day(M_PatientDOB, date(T_OrderHeaderDate)) Dob , + T_TestNat_TestID + from t_orderheader + join m_patient on T_OrderHeaderID = $order_id and T_OrderHeaderM_PatientID = M_PatientID + join t_orderdetail on T_OrderDetailT_OrderHeaderID = T_OrderHeaderID + and T_OrderDetailIsACtive = 'Y' + and ( T_OrderDetailNat_NormalValueID is null or T_OrderDetailNat_NormalValueID = 0 ) + join t_test on T_OrderDetailT_TestID = T_TestID and T_TestIsResult = 'Y' "; + $qry = $this->db->query($sql); + if(! $qry) { + return; + } + $rows = $qry->result_array(); + if(count($rows) == 0 ) return; + $sql_u = "update t_orderdetail + join nat_normalvalue on T_OrderDetailID = ? and Nat_NormalValueID = ? + set + T_OrderDetailNat_NormalValueID = Nat_NormalValueID, + T_OrderDetailNormalValueNote = Nat_NormalValueNote, + T_OrderDetailNormalValueDescription = Nat_NormalValueDescription, + T_OrderDetailMinValue = Nat_NormalValueMinValue, + T_OrderDetailMaxValue = Nat_NormalValueMaxValue, + T_OrderDetailMinValueInclusive = Nat_NormalValueMinValueInclusive, + T_OrderDetailMaxValueInclusive = Nat_NormalValueMaxValueInclusive, + T_OrderDetailNat_MethodeID = ?, + T_OrderdetailNat_MethodeName =?"; + + foreach($rows as $r) { + $T_OrderDetailID = $r["T_OrderDetailID"]; + $sexID = $r["M_PatientM_SexID"]; + $ageInDay = $r["Dob"]; + $natTestID = $r["T_TestNat_TestID"]; + list($methodeID,$methodeName) = $this->getMethodeID($natTestID); + if ($methodeID == 0 ) continue; + $normalValueID = $this->get_normal_value($methodeID, $natTestID, $sexID, $ageInDay); + if ($normalValueID == 0) return; + $this->db->query($sql_u, array($T_OrderDetailID, $normalValueID, $methodeID, $methodeName)); + } + } + function update_order_sample($targetID, $sourceID) { + $sql = "update t_ordersample target + join t_ordersample source on + target.T_OrderSampleID = ? + and target.T_OrderSampleWorklistReceive = 'N' + and source.T_OrderSampleID = ? + set + target.T_OrderSampleSampling = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSampling, source.T_OrderSampleSampling), + target.T_OrderSampleSamplingDate = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingDate, source.T_OrderSampleSamplingDate), + target.T_OrderSampleSamplingTime = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingTime, source.T_OrderSampleSamplingTime), + target.T_OrderSampleSamplingUserID = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingUserID, source.T_OrderSampleSamplingUserID), + + target.T_OrderSampleReceive = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceive, source.T_OrderSampleReceive), + target.T_OrderSampleReceiveDate = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveDate, source.T_OrderSampleReceiveDate), + target.T_OrderSampleReceiveTime = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveTime, source.T_OrderSampleReceiveTime), + target.T_OrderSampleReceiveUserID = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveUserID, source.T_OrderSampleReceiveUserID), + + target.T_OrderSampleVerification = if(target.T_OrderSampleVerification='Y',target.T_OrderSampleVerification, source.T_OrderSampleVerification), + target.T_OrderSampleVerificationDate =if(target.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationDate, source.T_OrderSampleVerificationDate), + target.T_OrderSampleVerificationTime =if(source.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationTime, source.T_OrderSampleVerificationTime), + target.T_OrderSampleVerificationUserID =if(source.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationUserID, source.T_OrderSampleVerificationUserID), + + target.T_OrderSampleProcessing = if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessing, source.T_OrderSampleProcessing), + target.T_OrderSampleProcessingDate= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingDate, source.T_OrderSampleProcessingDate), + target.T_OrderSampleProcessingTime= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingTime, source.T_OrderSampleProcessingTime), + target.T_OrderSampleProcessingUserID= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingUserID, source.T_OrderSampleProcessingUserID), + + target.T_OrderSampleReceiveHandling =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandling, source.T_OrderSampleReceiveHandling ), + target.T_OrderSampleReceiveHandlingDate =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingDate, source.T_OrderSampleReceiveHandlingDate), + target.T_OrderSampleReceiveHandlingTime =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingTime, source.T_OrderSampleReceiveHandlingTime), + target.T_OrderSampleReceiveHandlingUserID =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingUserID, source.T_OrderSampleReceiveHandlingUserID), + + target.T_OrderSampleHandling = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandling, source.T_OrderSampleHandling), + target.T_OrderSampleHandlingDate = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingDate, source.T_OrderSampleHandlingDate), + target.T_OrderSampleHandlingTime = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingTime, source.T_OrderSampleHandlingTime), + target.T_OrderSampleHandlingUserID = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingUserID, source.T_OrderSampleHandlingUserID), + + target.T_OrderSampleWorklistReceive = source.T_OrderSampleWorklistReceive, + target.T_OrderSampleWorklistReceiveDatetime = source.T_OrderSampleWorklistReceiveDateTime, + target.T_OrderSampleWorklistReceiveUserID = source.T_OrderSampleWorklistReceiveUserID + "; + $qry = $this->db->query($sql,array($targetID,$sourceID)); + if(! $qry ) { + echo json_encode(array( "status" => "ERR" , "message" => print_r($this->db->error(),true))); + exit; + } + } + function fix_sample_serum($headerID) { + //cari t_ordersample yg belum worklist receive dengan code 017% + $sql = "select T_OrderSampleID + from t_ordersample + join t_sampletype on + T_OrderSampleT_OrderHeaderID = ? + and T_OrderSampleWorklistReceive = 'N' + and T_OrderSampleIsActive = 'Y' + and T_OrderSampleT_SampleTypeID = T_SampletypeID + and T_SampleTypeCode like '017%' + "; + $qry = $this->db->query($sql, array($headerID)); + if(!$qry) { + echo json_encode(array( "status" => "ERR" , "message" => print_r($this->db->error(),true))); + exit; + } + $rows = $qry->result_array(); + if (count($rows) == 0 ) return; + //cari T_OrderSample yang sudah di receive yg terakhir + $sql = "select T_OrderSampleID + from t_ordersample + join t_sampletype on + T_OrderSampleT_OrderHeaderID = ? + and T_OrderSampleWorklistReceive = 'Y' + and T_OrderSampleIsActive = 'Y' + and T_OrderSampleT_SampleTypeID = T_SampletypeID + and T_SampleTypeCode like '017%' + order by T_OrderSampleWorklistReceiveDatetime desc + limit 0,1 + "; + $qry = $this->db->query($sql, array($headerID)); + if(!$qry) { + echo json_encode(array( "status" => "ERR" , "message" => print_r($this->db->error(),true))); + exit; + } + $rcv_rows = $qry->result_array(); + if (count($rcv_rows) == 0 ) return; + + //print_r($rows); + //print_r($rcv_rows); + $rcv_T_OrderSampleID = $rcv_rows[0]["T_OrderSampleID"]; + //ada yg belum di receive + foreach($rows as $r) { + $T_OrderSampleID = $r["T_OrderSampleID"]; + $this->update_order_sample($T_OrderSampleID,$rcv_T_OrderSampleID); + } + } + public function search() + { + $prm = $this->sys_input; + $max_rst = 99; + + $id = $prm["order_id"]; + if ($id > 0 ) { + $this->fix_sample_serum($id); + $this->fn_fix_normal($id); + } + $lang = $this->lang_default_code; + $lang_id = isset($prm['lang_id']) ? $prm['lang_id'] : '0'; + + if ($lang_id != 0) + { + $l = $this->db_smartone->where("Nat_LangID", $lang_id)->get("nat_lang")->row(); + $lang = $l->Nat_LangCode; + } + + //tambahan fajri + $sql = " UPDATE t_orderdetail + JOIN t_test ON T_OrderDetailT_TestID = T_TestID + SET T_OrderDetailT_TestIsResult = T_TestIsResult + WHERE + T_OrderDetailT_OrderHeaderID = {$id} AND + T_OrderDetailT_TestIsResult = '' AND + T_OrderDetailIsActive = 'Y'"; + $this->db_smartone->query($sql); + + $tot_count = 0; + $lq = ""; + $group_id = 0; + if (isset($prm['group_id'])) + $group_id = $prm['group_id']; + + if ($group_id != 0) + { + $sql = "select distinct T_WorklistDetailNat_TestID Nat_TestID + from t_worklistdetailv2 + where T_WorklistDetailT_WorklistID = {$group_id}"; + $qry = $this->db_smartone->query($sql); + $rows = $qry->result_array(); + $nat_test_ids = "0"; + foreach($rows as $r) { + $nat_test_ids .= ", " . $r["Nat_TestID"]; + } + $q_group = " ( $nat_test_ids ) "; + + $sql = " + SELECT a1.*, cOUNT(a2.T_OrderDetailID) level + FROM ( + SELECT IFNULL(y.T_OrderDetailT_TestID, x.T_OrderDetailT_TestID) t_testid, + IFNULL(y.T_OrderDetailT_TestName, y.T_OrderDetailT_TestName) t_testname, + y.T_OrderDetailResult result, y.T_OrderDetailResult result_old, y.T_OrderDetailNote note, y.T_OrderDetailNote note_old, + y.T_OrderDetailID id, + y.T_OrderDetailT_TestIsResult is_result, a.T_TestIsQuantitative is_quantitative, + y.T_OrderDetailResultFlag result_flag, + y.T_OrderDetailNat_NormalValueID normal_id, + y.T_OrderDetailNormalValueNote normal_note, y.T_OrderDetailNat_UnitName unit_name, + y.T_OrderdetailNat_MethodeID methode_id, y.T_OrderdetailNat_MethodeName methode_name, + a.T_TestNat_TestID nattest_id, a.T_TestID tx_id, count(T_ResultInstrumentID) as result_instrument_n, + y.T_OrderDetailVerification, T_OrderSampleReceive sample_receive, + T_OrderSampleProcessing sample_processing, T_OrderSampleWorklistReceive sample_worklist_receive, + IF(T_OrderDetailAddOnPreAnalytic = 'Y', T_OrderDetailAddOnPreAnalytic, PreAnalyticIsOk) pre_analytic, + T_OrderDetailAddOnPreAnalytic, + T_OrderHeaderID order_id, y.T_OrderDetailT_TestSasCode test_sas_code, + tx.T_TestSasCode, + T_OrderDetailAddOnResample `resample`, T_OrderDetailAddOnResampleStatus resample_status, + T_OrderDetailAddOnRef ref, y.T_OrderDetailVerification verification, y.T_OrderDetailValidation validation, + T_OrderPromiseDateTime, Group_ResultName as ResultGroupName + FROM t_orderdetail x + left join t_orderpromise on x.T_OrderDetailT_OrderPromiseID = T_OrderPromiseID + JOIN t_test tx ON x.T_OrderDetailT_TestID = T_TestID + JOIN t_test tcheck on tcheck.T_TestNat_TestID in {$q_group} + and ( tx.T_TestID = tcheck.T_TestID or tx.T_TestSasCode like concat(tcheck.T_TestSasCode,'%')) + LEFT JOIN group_resultdetail ON Group_ResultDetailT_TestID = x.T_OrderDetailT_TestID AND Group_ResultDetailIsActive = 'Y' + LEFT JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND Group_ResultFlagNonLab = 'N' + LEFT JOIN t_orderdetail y ON x.T_OrderDetailT_TestSasCode LIKE CONCAT(y.T_OrderDetailT_TestSasCode, '%') + AND x.T_OrderDetailT_OrderHeaderID = y.T_OrderDetailT_OrderHeaderID + AND y.T_OrderDetailIsActive = 'Y' + LEFT JOIN t_orderdetailaddon ON x.T_OrderDetailID = T_OrderDetailAddOnT_OrderDetailID + JOIN t_orderheader ON y.T_OrderDetailT_OrderHeaderID = T_OrderHeaderID + LEFT JOIN t_test a ON y.T_OrderDetailT_TestID = a.T_TestID + AND a.T_TestIsNonLab = '' + LEFT JOIN (SELECT T_OrderSampleT_SampleTypeID, T_OrderSampleReceive, T_OrderSampleProcessing, T_OrderSampleWorklistReceive + FROM t_ordersample WHERE T_OrderSampleT_OrderHeaderID = {$id} + AND T_OrderSampleIsactive = 'Y' + GROUP BY T_OrderSampleT_SampleTypeID) os ON a.T_TestT_SampleTypeID = os.T_OrderSampleT_SampleTypeID + or os.T_OrderSampleT_SampleTypeID = fn_sampletype_from_local(a.T_TestNat_TestID) + + LEFT JOIN t_resultinstrument ON T_ResultInstrumentT_OrderDetailID = x.T_OrderDetailID + LEFT JOIN pre_analytic ON PreAnalyticNat_TestID = a.T_TestNat_TestID AND PreAnalyticDate = date(now()) and PreAnalyticIsActive = 'Y' + WHERE x.T_OrderDetailT_OrderHeaderID = {$id} + AND x.T_OrderDetailIsActive = 'Y' + GROUP BY y.T_OrderDetailT_TestID + ORDER BY y.T_OrderDetailT_TestSasCode ASC + ) a1 + + LEFT JOIN t_orderdetail a2 ON a2.T_OrderDetailT_OrderHeaderID = a1.order_id + AND a2.T_OrderDetailIsActive = 'Y' + AND a1.test_sas_code LIKE CONCAT(a2.T_OrderDetailT_testSasCode, '%') + GROUP BY a1.t_testid + order by a1.test_sas_code +"; + $query = $this->db_smartone->query($sql); + $lq = $this->db_smartone->last_query(); + } + else + { + $sql = " + SELECT a1.*, cOUNT(a2.T_OrderDetailID) level + FROM ( + SELECT IFNULL(y.T_OrderDetailT_TestID, x.T_OrderDetailT_TestID) t_testid, + IFNULL(y.T_OrderDetailT_TestName, y.T_OrderDetailT_TestName) t_testname, + y.T_OrderDetailResult result, y.T_OrderDetailResult result_old, y.T_OrderDetailNote note, y.T_OrderDetailNote note_old, + y.T_OrderDetailID id, + y.T_OrderDetailT_TestIsResult is_result, a.T_TestIsQuantitative is_quantitative, + y.T_OrderDetailResultFlag result_flag, + y.T_OrderDetailNat_NormalValueID normal_id, + y.T_OrderDetailNormalValueNote normal_note, y.T_OrderDetailNat_UnitName unit_name, + y.T_OrderdetailNat_MethodeID methode_id, y.T_OrderdetailNat_MethodeName methode_name, + a.T_TestNat_TestID nattest_id, a.T_TestID tx_id, count(T_ResultInstrumentID) as result_instrument_n, + y.T_OrderDetailVerification, T_OrderSampleReceive sample_receive, + T_OrderSampleProcessing sample_processing, T_OrderSampleWorklistReceive sample_worklist_receive, + IF(T_OrderDetailAddOnPreAnalytic = 'Y', T_OrderDetailAddOnPreAnalytic, PreAnalyticIsOk) pre_analytic, + T_OrderDetailAddOnPreAnalytic, + T_OrderHeaderID order_id, y.T_OrderDetailT_TestSasCode test_sas_code, + tx.T_TestSasCode, + T_OrderDetailAddOnResample `resample`, T_OrderDetailAddOnResampleStatus resample_status, + T_OrderDetailAddOnRef ref, y.T_OrderDetailVerification verification, y.T_OrderDetailValidation validation, + T_OrderPromiseDateTime , Group_ResultName as ResultGroupName + FROM t_orderdetail x + left join t_orderpromise on x.T_OrderDetailT_OrderPromiseID = T_OrderPromiseID + JOIN t_test tx ON x.T_OrderDetailT_TestID = T_TestID + LEFT JOIN group_resultdetail ON Group_ResultDetailT_TestID = x.T_OrderDetailT_TestID AND Group_ResultDetailIsActive = 'Y' + LEFT JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND Group_ResultFlagNonLab = 'N' + LEFT JOIN t_orderdetail y ON x.T_OrderDetailT_TestSasCode LIKE CONCAT(y.T_OrderDetailT_TestSasCode, '%') + AND x.T_OrderDetailT_OrderHeaderID = y.T_OrderDetailT_OrderHeaderID + AND y.T_OrderDetailIsActive = 'Y' + + LEFT JOIN t_orderdetailaddon ON x.T_OrderDetailID = T_OrderDetailAddOnT_OrderDetailID + + JOIN t_orderheader ON y.T_OrderDetailT_OrderHeaderID = T_OrderHeaderID + LEFT JOIN t_test a ON y.T_OrderDetailT_TestID = a.T_TestID + AND a.T_TestIsNonLab = '' + LEFT JOIN (SELECT T_OrderSampleT_SampleTypeID, T_OrderSampleReceive, T_OrderSampleProcessing, T_OrderSampleWorklistReceive + FROM t_ordersample WHERE T_OrderSampleT_OrderHeaderID = {$id} + AND T_OrderSampleIsactive = 'Y' + GROUP BY T_OrderSampleT_SampleTypeID) os ON a.T_TestT_SampleTypeID = os.T_OrderSampleT_SampleTypeID + or os.T_OrderSampleT_SampleTypeID = fn_sampletype_from_local(a.T_TestNat_TestID) + + LEFT JOIN t_resultinstrument ON T_ResultInstrumentT_OrderDetailID = x.T_OrderDetailID + LEFT JOIN pre_analytic ON PreAnalyticNat_TestID = a.T_TestNat_TestID AND PreAnalyticDate = date(now()) and PreAnalyticIsActive = 'Y' + WHERE x.T_OrderDetailT_OrderHeaderID = {$id} + AND x.T_OrderDetailIsActive = 'Y' + GROUP BY y.T_OrderDetailT_TestID + ORDER BY y.T_OrderDetailT_TestSasCode ASC + ) a1 + + LEFT JOIN t_orderdetail a2 ON a2.T_OrderDetailT_OrderHeaderID = a1.order_id + AND a2.T_OrderDetailIsActive = 'Y' + AND a1.test_sas_code LIKE CONCAT(a2.T_OrderDetailT_testSasCode, '%') + GROUP BY a1.t_testid + order by a1.test_sas_code +"; +//echo $sql; + $query = $this->db_smartone->query($sql); + $lq = $this->db_smartone->last_query(); + } + // file_put_contents("/xtmp/re-query.sql",$lq); + + if ($query) { + $rst = []; + $rows = $query->result_array(); + + foreach($rows as $k => $v) + { + + if ($v['is_result'] == "Y" && $v['is_quantitative'] == "N") + { + $v['template'] = []; + $x = $this->db_smartone->query("CALL sp_master_resulttemplate_get('{$v['t_testid']}')"); + $this->clean_mysqli_connection($this->db_smartone->conn_id); + if ($x) + $v['template'] = $x->result_array(); + } + + // IF Rujukan, by pas Pre Analytik + if ($v['ref'] == 'Y') + $v['pre_analytic'] = 'Y'; + if ($v["id"] == "885455" ) + { + //sipe workaround + //$v["sample_receive"] = "Y"; + $v["sample_worklist_receive"] = "Y"; + } + $rst[] = $v; + } + + $result = array("total" => $tot_count, "records" => $rst, "total_display" => sizeof($rows), "q" => $lq); + $this->sys_ok($result); + } + else { + $this->sys_error_db("RE Px rows", $this->db_smartone); + exit; + } + } + + public function save() + { + $prm = $this->sys_input; + $data = json_decode($prm["data"]); + $lang = $this->lang_default_code; + $lang_id = isset($prm['lang_id']) ? $prm['lang_id'] : '0'; + + if ($lang_id != 0) + { + $l = $this->db_smartone->where("Nat_LangID", $lang_id)->get("nat_lang")->row(); + $lang = $l->Nat_LangCode; + } + + $sql_norm = "select T_OrderDetailMinValue, T_OrderDetailMaxValue, + T_OrderDetailMinValueInclusive, T_OrderDetailMaxValueInclusive, + Nat_TestFlagLow, Nat_TestFlagHigh + from t_orderdetail + join t_test on T_OrderDetailT_TestID = T_TestID + join nat_test on T_TestNat_TestID = Nat_TestID and T_TestIsActive = 'Y' + where T_OrderDetailID = ? "; + + $ids = []; + foreach ($data as $k => $v) + { + if ( $v->resultInstrumentID > 0 ) { + $sql_i = "select T_ResultInstrumentNat_NormalValueID normalValueID + from t_resultinstrument + where T_ResultInstrumentID = ?"; + $qry_i = $this->db_smartone->query($sql_i, array($v->resultInstrumentID)); + if ($qry_i) { + $rows_i = $qry_i->result_array(); + + if (count($rows_i) > 0 ) { + $sql_iu = "update t_orderdetail, nat_normalvalue , nat_methode + set T_OrderDetailMinValue = Nat_NormalValueMinValue, + T_OrderDetailMinValueInclusive = Nat_NormalValueMinValueInclusive, + T_OrderDetailMaxValue = Nat_NormalValueMaxValue , + T_OrderDetailMaxValueInclusive = Nat_NormalValueMaxValueInclusive, + T_OrderDetailNormalValueNote = Nat_NormalValueNote, + T_OrderDetailNormalValueDescription = Nat_NormalValueDescription, + T_OrderDetailNat_NormalValueID = Nat_NormalValueID, + T_OrderDetailNat_MethodeID = Nat_NormalValueNat_MethodeID, + T_OrderDetailNat_MethodeName = Nat_MethodeName + where T_OrderDetailID = ? and Nat_NormalValueID = ? + and Nat_NormalValueNat_MethodeID = Nat_MethodeID + "; + $this->db_smartone->query($sql_iu, array($v->id, $rows_i[0]["normalValueID"])); + //file_put_contents("/xtmp/update-nilai-normal", $this->db_smartone->last_query() . "\n", FILE_APPEND); + } + } + } + $y = $this->db_smartone->query("SELECT fn_process_sample_handling_perfect('{$v->order_id}', '{$v->test_id}') c") + ->row(); + $req_status = $y->c; + $qry_norm = $this->db_smartone->query($sql_norm,$v->id); + $result_flag = ""; + if ($qry_norm) { + $rows_norm = $qry_norm->result_array(); + if (count($rows_norm) > 0 ) { + $r = $rows_norm[0]; + if (is_numeric($v->result)) { + + if ( $r["T_OrderDetailMinValueInclusive"] == "Y" && $v->result < $r["T_OrderDetailMinValue"] ) { + $result_flag = $r["Nat_TestFlagLow"]; + } + if ( $r["T_OrderDetailMinValueInclusive"] == "N" && $v->result <= $r["T_OrderDetailMinValue"] ) { + $result_flag = $r["Nat_TestFlagLow"]; + } + if ( $r["T_OrderDetailMaxValueInclusive"] == "Y" && $v->result > $r["T_OrderDetailMaxValue"] ) { + $result_flag = $r["Nat_TestFlagHigh"]; + } + if ( $r["T_OrderDetailMaxValueInclusive"] == "N" && $v->result >= $r["T_OrderDetailMaxValue"] ) { + $result_flag = $r["Nat_TestFlagHigh"]; + } + } + } + } + if ($lang == $this->lang_default_code) + { + $this->db_smartone->set('T_OrderDetailResult', $v->result) + ->set('T_OrderDetailResultFlag', $result_flag) + ->set('T_OrderDetailNote', $v->note) + ->set('T_OrderDetailReqStatus', $req_status) + ->where('T_OrderDetailID', $v->id) + ->update('t_orderdetail'); + } + else + { + $this->db_smartone->set('T_OrderDetailLangResult', $v->result) + ->set('T_OrderDetailLangNote', $v->note) + ->where('T_OrderDetailLangID', $v->id) + ->update('t_orderdetaillang'); + } + + $ids[] = $v->id; + } + + // LOG Process + $order = $this->db_smartone->select('T_OrderDetailT_OrderHeaderID id, T_OrderHeaderLabNumber lab_number', false) + ->join('t_orderheader', 'T_OrderHeaderID = T_OrderDetailT_OrderHeaderID') + ->where('T_OrderDetailID', $data[0]->id) + ->get('t_orderdetail') + ->row(); + + $dblog = $this->load->database("onelog", true); + $dblog->set('Log_ProcessCode', 'PROCESS.Result.Entry') + ->set('Log_ProcessOrderID', $order->id) + ->set('Log_ProcessOrderNumber', $order->lab_number) + ->set('Log_ProcessJson', json_encode($data)) + ->set('Log_ProcessUserID', $this->sys_user['M_UserID']) + ->insert('log_process'); + // END OF Log Process + //auto calculation + $this->load->library("Resultcalc"); + $rows = $this->resultcalc->auto($order->id); + + try { + foreach($ids as $id ) { + $this->db_smartone->query("call sp_set_normal_value_flag($id)"); + $this->clean_mysqli_connection($this->db_smartone->conn_id); + } + } catch(Exception $e) { + } + + $this->sys_ok($ids); + } + + public function save_template() + { + $prm = $this->sys_input; + + $n = $this->db_smartone->select("COUNT(T_ResultTemplateID) n") + ->where("T_ResultTemplateT_TestID", $prm['test_id']) + ->where("T_ResultTemplateIsActive", "Y") + ->where("T_ResultTemplateValue", $prm['value']) + ->get('t_resulttemplate') + ->row(); + if ($n->n > 0) + { + $this->sys_error_db("Insert Result Template", $this->db_smartone); + return; + } + + $r = $this->db_smartone->set("T_ResultTemplateT_TestID", $prm['test_id']) + ->set("T_ResultTemplateValue", $prm['value']) + ->insert('t_resulttemplate'); + if ($r) + { + $template = []; + $x = $this->db_smartone->query("CALL sp_master_resulttemplate_get('{$prm['test_id']}')"); + $this->clean_mysqli_connection($this->db_smartone->conn_id); + if ($x) + $template = $x->result_array(); + + $this->sys_ok($template); + } + } + + public function export() + { + $prm = $this->sys_input; + + $sql = "CALL sp_process_result_lang(?, ?, ?, ?)"; + $query = $this->db_smartone->query($sql, [$prm['order_id'], $prm['lang_id'], $prm['is_si'], $this->sys_user['M_UserID']]); + if ($query) + { + $r = $query->row(); + if ($r->status == "OK") + { + $this->sys_ok($r->data); + return; + } + + $this->sys_error_db("Message : " . $r->message, $this->db_smartone); + } + else + { + $this->sys_error_db("Lang Result", $this->db_smartone); + return; + } + } + + public function search_group() + { + $prm = $this->sys_input; + $max_rst = 100; + + // QUERY TOTAL + $sql = "select count(*) total + from t_worklist + where T_WorklistIsActive = 'Y' + order by T_WorklistName ASC"; + $query = $this->db_smartone->query($sql); + + if ($query) { + $tot_count = $query->result_array()[0]["total"]; + } + else { + $this->sys_error_db("worklist count", $this->db_smartone); + exit; + } + + $sql = "select T_WorklistID group_id, T_WorklistName group_name + from t_worklist + where T_WorklistIsActive = 'Y' + order by T_WorklistName ASC + limit 0, {$max_rst}"; + $query = $this->db_smartone->query($sql); + + if ($query) { + $rows = $query->result_array(); + foreach ($rows as $k => $v) + $rows[$k]['data'] = json_decode($v['data']); + $result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows), "q" => $this->db_smartone->last_query()); + $this->sys_ok($result); + } + else { + $this->sys_error_db("worklist rows", $this->db_smartone); + exit; + } + } + + public function search_rerun() + { + $prm = $this->sys_input; + $id = $prm["detail_id"]; + + $sql = "CALL sp_process_result_rerun(?)"; + $query = $this->db_smartone->query($sql, [$id]); + + if ($query) + { + $rows = $query->result_array(); + $this->sys_ok(["records"=>$rows]); + } + else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + + + function getdoctorsfna() + { + $prm = $this->sys_input; + // $id = $prm["id"]; + + $sql = " SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY M_DoctorName ASC"; + //echo $sql; + $query = $this->db_smartone->query($sql); + + if ($query) + { + $rows = $query->result_array(); + $this->sys_ok(["records"=>$rows]); + } + else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + function getfnaresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT Other_FNADetailsID as xid, + Other_FNAT_OrderDetailID as orderdetail_id, + Other_FNADetailsCode as code, + Other_FNADetailsLabel as label, + Other_FNADetailsResult as result, + IFNULL(Other_FNAM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_FNAM_DoctorID) OR Other_FNAM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_fna + JOIN other_fnadetails ON Other_FNADetailsOther_FNAID = Other_FNAID AND Other_FNADetailsIsActive = 'Y' + LEFT JOIN m_doctor ON Other_FNAM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_FNAT_OrderDetailID = {$id} AND Other_FNAIsActive = 'Y' + GROUP BY Other_FNADetailsID + ORDER BY Other_FNADetailsCode ASC"; + $query = $this->db_smartone->query($sql); + + if ($query) + { + $rows = $query->result_array(); + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $images = array(); + $sql = "SELECT So_ImageUploadID as xid, + CONCAT('/one-media/one-image-nonlab/',So_ImageUploadNewName) as image_url + FROM t_orderdetail + JOIN so_imageupload ON So_ImageUploadT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND + So_ImageUploadIsActive = 'Y' + WHERE + T_OrderDetailID = {$id} AND + T_OrderDetailIsActive = 'Y' + GROUP BY So_ImageUploadID"; + $images = $this->db_smartone->query($sql)->result_array(); + + $rst = array('doctors'=>$doctors,'results'=>$rows,'images'=>$images); + $this->sys_ok(["records"=>$rst]); + } + else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + + function uploadimage(){ + if (! $this->isLogin) { + $this->sys_error("Invalid Token"); + exit; + } + + $userid = $this->sys_user["M_UserID"]; + $data = []; + //print_r($_SERVER); + + $prm = $this->sys_input; + $orderid = $this->input->post('orderid'); + $labnumber = $this->input->post('labnumber'); + $sql = "UPDATE so_imageupload SET + So_ImageUploadIsActive = 'N', + So_ImageUploadUserID = {$userid} + WHERE + So_ImageUploadT_OrderHeaderID = {$orderid}"; + //echo $sql; + $this->db_onedev->query($sql); + //$config['upload_path'] = 'assets/'; + + $path = '/home/one/project/one/one-media/one-image-nonlab/'; + //echo $path; + $config['upload_path'] = $path; + $config['allowed_types'] = 'jpg|jpeg|png|gif'; + + $config['max_size'] = '10000'; + $count = count($_FILES['files']['name']); + //echo $count; + $this->load->library('upload',$config); + + $error = []; + for($i=0;$i<$count;$i++){ + + + if(!empty($_FILES['files']['name'][$i])){ + + + + $_FILES['file']['name'] = $_FILES['files']['name'][$i]; + + $_FILES['file']['type'] = $_FILES['files']['type'][$i]; + + $_FILES['file']['tmp_name'] = $_FILES['files']['tmp_name'][$i]; + + $_FILES['file']['error'] = $_FILES['files']['error'][$i]; + + $_FILES['file']['size'] = $_FILES['files']['size'][$i]; + + + + $namex = $orderid.'-'.$labnumber.'-'.$this->generateRandomString(5); + //echo $namex; + + $config['file_name'] = $namex; + $this->upload->initialize($config); + //echo $config['file_name'] ; + + + + + + if($this->upload->do_upload('file')){ + + $uploadData = $this->upload->data(); + + $filename = $uploadData['file_name']; + //echo $filename; + + + $sql = "INSERT INTO so_imageupload ( + So_ImageUploadT_OrderHeaderID, + So_ImageUploadT_OrderHeaderLabNumber, + So_ImageUploadT_SampleTypeID, + So_ImageUploadOldName, + So_ImageUploadNewName, + So_ImageUploadCreated, + So_ImageUploadUserID + ) + VALUES( + {$orderid}, + '{$labnumber}', + '150', + '{$_FILES['files']['name'][$i]}', + '{$filename}', + NOW(), + {$userid} + + )"; + //echo $sql; + $this->db_onedev->query($sql); + $xlast_id = $this->db_onedev->insert_id(); + $data['totalFiles'][] = array('xid' => $xlast_id ,'image_url' => '/one-media/one-image-nonlab/'.$filename); + + } + else{ + $error = array('error' => $this->upload->display_errors()); + } + + } + + + + } + + $result = array("total" =>count( $data['totalFiles']), "records" => $data['totalFiles'],'errors'=>$error); + $this->sys_ok($result); + } + + + function generateRandomString($length = 10) { + $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; + $charactersLength = strlen($characters); + $randomString = ''; + for ($i = 0; $i < $length; $i++) { + $randomString .= $characters[rand(0, $charactersLength - 1)]; + } + return $randomString; + } + + function getcytologiresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT Other_CytologiDetailsID as xid, + Other_CytologiT_OrderDetailID as orderdetail_id, + Other_CytologiDetailsCode as code, + Other_CytologiDetailsLabel as label, + Other_CytologiDetailsResult as result, + IFNULL(Other_CytologiM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_CytologiM_DoctorID) OR Other_CytologiM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_cytologi + JOIN other_cytologidetails ON Other_CytologiDetailsOther_CytologiID = Other_CytologiID AND Other_CytologiDetailsIsActive = 'Y' + LEFT JOIN m_doctor ON Other_CytologiM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_CytologiT_OrderDetailID = {$id} AND Other_CytologiIsActive = 'Y' + GROUP BY Other_CytologiDetailsID + ORDER BY Other_CytologiDetailsCode ASC"; + //echo $sql; + $query = $this->db_smartone->query($sql); + + if ($query) + { + $rows = $query->result_array(); + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $rst = array('doctors'=>$doctors,'results'=>$rows); + $this->sys_ok(["records"=>$rst]); + } + else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + function getmikroresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT + Other_MikroID as xid, + Other_MikroHasilBiakan as hasil_biakan, + Other_MikroSampleTypeName as sample_name, + Other_MikroT_OrderDetailID as orderdetail_id, + Other_MikroResult as result_value, + '' as result_other, + IFNULL(T_BacteriaID,0) as T_BacteriaID, + IFNULL(T_BacteriaName,'') as T_BacteriaName, + '' as details, + IFNULL(Other_MikroM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_MikroM_DoctorID) OR Other_MikroM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_mikro + LEFT JOIN t_bacteria ON Other_MikroT_BacteriaID = T_BacteriaID + LEFT JOIN m_doctor ON Other_MikroM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_MikroT_OrderDetailID = {$id} AND Other_MikroIsActive = 'Y' + GROUP BY Other_MikroID"; + //echo $sql; + $query = $this->db_smartone->query($sql); + + if ($query) + { + $row = $query->row_array(); + if($row){ + if($row['result_value'] != 'Positif' && $row['result_value'] != 'Negatif'){ + $row['result_other'] = $row['result_value']; + $row['result_value'] = 'other'; + } + $sql = "SELECT '' as xno, + Other_MikroDetailsID as xid, + Other_MikroDetailsValue as value, + IF(Other_MikroDetailsNote = 'R','Y','N') as chx_r, + IF(Other_MikroDetailsNote = 'I','Y','N') as chx_i, + IF(Other_MikroDetailsNote = 'S','Y','N') as chx_s, + Other_MikroDetailsNote as note, + t_antibiotic.* + FROM other_mikrodetails + LEFT JOIN t_antibiotic ON Other_MikroDetailsT_AntibioticID = T_AntibioticID + WHERE + Other_MikroDetailsOther_MikroID = {$row['xid']} AND Other_MikroDetailsIsActive = 'Y' + GROUP BY Other_MikroDetailsID + ORDER BY T_AntibioticName ASC"; + //echo $sql; + $details = $this->db_smartone->query($sql)->result_array(); + if(details){ + foreach($details as $k => $v){ + $details[$k]['xno'] = $k + 1; + } + } + $row['details'] = $details; + } + else{ + $row = array('xid'=>'0','hasil_biakan' => '','result_value'=>'Negatif','sample_name' => '','orderdetail_id'=>$id, 'T_BacteriaID'=>'0','T_BacteriaName'=>'0','details'=>array(),'doctor_id'=>'0','doctor_name'=>'0'); + } + } + else{ + $row = array('xid'=>'0','hasil_biakan' => '','result_value'=>'Negatif','sample_name' => '','orderdetail_id'=>$id, 'T_BacteriaID'=>'0','T_BacteriaName'=>'0','details'=>array(),'doctor_id'=>'0','doctor_name'=>'0'); + } + //print_r($row); + + + + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 7 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $sql = " + SELECT '0' as id, 'Belum memilih bakteria' as name + UNION + SELECT T_BacteriaID as id, T_BacteriaName as name + FROM t_bacteria + WHERE + T_BacteriaIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $bacteries = $this->db_smartone->query($sql)->result_array(); + $rst = array('doctors'=>$doctors,'bacteries'=>$bacteries,'results'=>$row); + $this->sys_ok(["records"=>$rst]); + } + function getantibiotics(){ + $prm = $this->sys_input; + $id = $prm["id"]; + $sql = " SELECT '' as xno, + 0 as xid, + '' as hasil_biakan, + '' as sample_name, + 0 as value, + 'Y' as chx_r, + 'N' as chx_i, + 'N' as chx_s, + 'R' as note, + t_antibiotic.* + FROM t_antibiotic + WHERE + T_AntibioticT_BacteriaID = {$prm['id']} AND T_AntibioticIsActive= 'Y' + ORDER BY T_AntibioticName ASC"; + //echo $sql; + $rows = $this->db_smartone->query($sql)->result_array(); + if(rows){ + foreach($rows as $k => $v){ + $rows[$k]['xno'] = $k + 1; + } + } + + $this->sys_ok(["records"=>$rows]); + } + function getlcprepresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + $sql = " SELECT Other_LcprepDetailsID as xid, + Other_LcprepID as header_id, + Other_LcprepT_orderDetailID as orderdetail_id, + Other_LcprepDetailsCode as code, + Other_LcprepDetailsLabel as label, + Other_LcprepDetailsResult as result, + IFNULL(Other_LcprepM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_LcprepM_DoctorID) OR Other_LcprepM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_lcprep + JOIN other_lcprepdetails ON Other_LcprepDetailsOther_LcprepID = Other_LcprepID AND Other_LcprepDetailsIsActive = 'Y' + LEFT JOIN m_doctor ON Other_LcprepM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_LcprepT_orderDetailID = {$id} AND Other_LcprepIsActive = 'Y' + GROUP BY Other_LcprepDetailsOther_LcprepID, Other_LcprepDetailsCode + ORDER BY Other_LcprepDetailsCode ASC"; + //echo $sql; + $rows = $this->db_smartone->query($sql)->result_array(); + if(!$rows){ + $rows = array( + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'A', + 'label' => 'DESKRIPSI', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ), + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'B', + 'label' => 'KESIMPULAN', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ) + ); + } + + $header_id = $rows[0]['header_id']; + $sql = "SELECT IFNULL(Other_LcprepAdekuasiID,0) as xid, + Lcprep_AdekuasiID as id, + Lcprep_AdekuasiLabel as name, + IF(ISNULL(Other_LcprepAdekuasiID),'N',Other_LcprepAdekuasiChex) as chex + FROM lcprep_adekuasi + LEFT JOIN other_lcprepadekuasi ON Other_LcprepAdekuasiLcprep_AdekuasiID = Lcprep_AdekuasiID AND + Other_LcprepAdekuasiOther_LcprepID = {$header_id} AND + Other_LcprepAdekuasiIsActive = 'Y' + WHERE + Lcprep_AdekuasiIsActive = 'Y' + GROUP BY Lcprep_AdekuasiID + ORDER BY Lcprep_AdekuasiOrder ASC + "; + //echo $sql; + $adeakuasi = $this->db_smartone->query($sql)->result_array(); + foreach($adeakuasi as $kc => $vc){ + $adeakuasi[$kc]['chex'] = $vc['chex'] == 'N'?false:true; + } + + $sql = "SELECT IFNULL(Other_LcprepKategoriUmumID,0) as xid, + Lcprep_KategoriUmumID as id, + Lcprep_KategoriUmumLabel as name, + IF(ISNULL(Other_LcprepKategoriUmumID),'N',Other_LcprepKategoriUmumChex) as chex + FROM lcprep_kategoriumum + LEFT JOIN other_lcprepkategoriumum ON Other_LcprepKategoriUmumLcprep_KategoriUmumID = Lcprep_KategoriUmumID AND + Other_LcprepKategoriUmumOther_LcprepID = {$header_id} AND + Other_LcprepKategoriUmumIsActive = 'Y' + WHERE + Lcprep_KategoriUmumIsActive = 'Y' + GROUP BY Lcprep_KategoriUmumID + "; + //echo $sql; + $kategoriumum = $this->db_smartone->query($sql)->result_array(); + foreach($kategoriumum as $kc => $vc){ + $kategoriumum[$kc]['chex'] = $vc['chex'] == 'N'?false:true; + } + + $sql = " + SELECT Lcprep_InterpretasiGroupID as group_id, + Lcprep_InterpretasiGroupName as group_name, + '' as subgroups + FROM lcprep_interpretasigroup + WHERE + Lcprep_InterpretasiGroupIsActive = 'Y' + "; + //echo $sql; + $interpretasi = $this->db_smartone->query($sql)->result_array(); + foreach($interpretasi as $k => $v){ + $subgroups = array(); + $sql = "SELECT Lcprep_InterpretasiSubgroupID as subgroup_id, + Lcprep_InterpretasiSubgroupName as subgroup_name, + '' as childs + FROM lcprep_interpretasisubgroup + WHERE + Lcprep_InterpretasiSubgroupLcprep_InterpretasiGroupID = {$v['group_id']} AND Lcprep_InterpretasiSubgroupIsActive = 'Y'"; + //echo $sql; + $subgroups = $this->db_smartone->query($sql)->result_array(); + if(count($subgroups) > 0){ + foreach($subgroups as $ki => $vi){ + $childs = array(); + $sql = "SELECT IFNULL(Other_LcprepInterpretasiID,0) as xid, + IFNULL(Other_LcprepInterpretasiChex,'N') as chex, + IFNULL(Other_LcprepInterpretasiValue,'') as value, + Lcprep_InterpretasiID as id, + Lcprep_InterpretasiLcprep_InterpretasiSubgroupID as subgroup_id, + Lcprep_InterpretasiCode as code, + Lcprep_InterpretasiName as name, + Lcprep_InterpretasiParentID as parent_id, + Lcprep_InterpretasiIsParent as is_parent, + Lcprep_InterpretasiHasResult as has_result, + Lcprep_InterpretasiTypeResult as type_result + FROM lcprep_interpretasi + LEFT JOIN other_lcprepinterpretasi ON Other_LcprepInterpretasiOther_LcprepID = {$header_id} AND + Other_LcprepInterpretasiLcprep_InterpretasiID = Lcprep_InterpretasiID AND + Other_LcprepInterpretasiIsActive = 'Y' + WHERE + Lcprep_InterpretasiLcprep_InterpretasiSubgroupID = {$vi['subgroup_id']} AND Lcprep_InterpretasiIsActive = 'Y' + GROUP BY Lcprep_InterpretasiID Order BY Lcprep_InterpretasiCode ASC"; + $childs = $this->db_smartone->query($sql)->result_array(); + if($childs){ + foreach($childs as $kc => $vc){ + $childs[$kc]['chex'] = $vc['chex'] == 'N'?false:true; + } + } + $subgroups[$ki]['childs'] = $childs; + } + } + + $interpretasi[$k]['subgroups'] = $subgroups; + } + + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $rst = array('doctors'=>$doctors,'results'=>$rows,'adekuasi'=>$adeakuasi,'kategoriumum'=>$kategoriumum,'interpretasi'=>$interpretasi); + $this->sys_ok(["records"=>$rst]); + } + + function getpapsmearresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT Other_PapSmearDetailsID as xid, + Other_PapSmearID as header_id, + Other_PapSmearT_OrderDetailID as orderdetail_id, + Other_PapSmearDetailsCode as code, + Other_PapSmearDetailsLabel as label, + Other_PapSmearDetailsResult as result, + IFNULL(Other_PapSmearM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_PapSmearM_DoctorID) OR Other_PapSmearM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_papsmear + JOIN other_papsmeardetails ON Other_PapSmearDetailsOther_PapSmearID = Other_PapSmearID AND Other_PapSmearDetailsIsActive = 'Y' + LEFT JOIN m_doctor ON Other_PapSmearM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_PapSmearT_OrderDetailID = {$id} AND Other_PapSmearIsActive = 'Y' + GROUP BY Other_PapSmearDetailsID + ORDER BY Other_PapSmearDetailsCode ASC"; + //echo $sql; + $rows = $this->db_smartone->query($sql)->result_array(); + if(!$rows){ + $rows = array( + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'A', + 'label' => 'Makroskopik', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ), + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'B', + 'label' => 'Mikroskopik', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ), + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'C', + 'label' => 'Kesimpulan', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ) + ); + } + + $header_id = $rows[0]['header_id']; + $sql = "SELECT Other_PapSmearMaturasiID as xid, + Other_PapSmearMaturasiValue as value + FROM other_papsmearmaturasi + WHERE + Other_PapSmearMaturasiOther_PapSmearID = {$header_id} AND + Other_PapSmearMaturasiIsActive = 'Y' + "; + //echo $sql; + $dt_maturasi = $this->db_smartone->query($sql)->row_array(); + if(!$dt_maturasi){ + $maturasi = array('xid'=>'0','value'=> array('','','')); + } + else{ + $value = explode('/',$dt_maturasi['value']); + $maturasi = array('xid'=>$dt_maturasi['xid'],'value'=> $value); + } + + $sql = "SELECT IFNULL(Other_PapSmearBahanID,0) as xid, + M_PapSmearBahanID as bahan_id, + M_PapSmearBahanName as name, + IF(ISNULL(Other_PapSmearBahanID),'N','Y') as selected + FROM m_papsmearbahan + LEFT JOIN other_papsmearbahan ON Other_PapSmearBahanM_PapSmearBahanID = M_PapSmearBahanID AND + Other_PapSmearBahanOther_PapSmearID = {$header_id} AND + Other_PapSmearBahanIsActive = 'Y' + WHERE + M_PapSmearBahanIsActive = 'Y' + ORDER BY M_PapSmearBahanID ASC + "; + //echo $sql; + $bahans = $this->db_smartone->query($sql)->result_array(); + + $sql = "SELECT IFNULL(Other_PapsmearCategoryID,0) as xid, + M_PapSmearCategoryID as category_id, + M_PapSmearCategoryName as name, + IF(ISNULL(Other_PapsmearCategoryID),'N','Y') as selected + FROM m_papsmearcategory + LEFT JOIN other_papsmearcategory ON Other_PapsmearCategoryM_PapSmearCategoryID = M_PapSmearCategoryID AND + Other_PapsmearCategoryOther_PapSmearID = {$header_id} AND + Other_PapsmearCategoryIsActive = 'Y' + WHERE + M_PapSmearCategoryIsActive = 'Y' + ORDER BY M_PapSmearCategoryID ASC + "; + //echo $sql; + $categories = $this->db_smartone->query($sql)->result_array(); + + $sql = "SELECT IFNULL(Other_PapSmearCheckID,0) as xid, + M_PapSmearCheckID as check_id, + M_PapSmearCheckLabel as name, + IF(ISNULL(Other_PapSmearCheckID),'N','Y') as selected, + Other_PapSmearCheckNote as note + FROM m_papsmearcheck + LEFT JOIN other_papsmearcheck ON Other_PapSmearCheckM_PapSmearCheckID = M_PapSmearCheckID AND + Other_PapSmearCheckOther_PapSmearID = {$header_id} AND + Other_PapSmearCheckIsActive = 'Y' + WHERE + M_PapSmearCheckIsActive = 'Y' + ORDER BY M_PapSmearCheckCode ASC + "; + $checks = $this->db_smartone->query($sql)->result_array(); + + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $rst = array('doctors'=>$doctors,'checks'=>$checks,'bahans'=>$bahans,'categories'=>$categories,'maturasi'=>$maturasi,'results'=>$rows); + $this->sys_ok(["records"=>$rst]); + + } + + function saveresult_lcprep() + { + $prm = $this->sys_input; + $detail_id = $prm['detail_id']; + $doctor_id = $prm['doctor']; + $adekuasi = $prm['adekuasi']; + $kategoriumum = $prm['kategoriumum']; + $interpretasi = $prm['interpretasi']; + $results = $prm['results']; + + $userid = $this->sys_user['M_UserID']; + + $header_id = 0; + $sql = "SELECT * FROM other_lcprep WHERE Other_LcprepT_orderDetailID = {$detail_id} AND Other_LcprepIsActive = 'Y'"; + $dt_header = $this->db_smartone->query($sql)->row_array(); + if($dt_header){ + $header_id = $dt_header['Other_LcprepID']; + } + if($header_id == 0){ + $sql = "INSERT INTO other_lcprep( + Other_LcprepT_orderDetailID, + Other_LcprepM_DoctorID, + Other_LcprepUserID, + Other_LcprepCreated + ) + VALUES( + {$detail_id}, + {$doctor_id}, + {$userid}, + NOW() + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + }else{ + $sql = "UPDATE other_lcprep SET Other_LcprepM_DoctorID = {$doctor_id}, Other_LcprepUserID = {$userid} WHERE Other_LcprepID = {$header_id}"; + $this->db_smartone->query($sql); + } + + if($adekuasi){ + foreach($adekuasi as $k =>$v){ + $selected = $v['chex']?'Y':'N'; + if(intval($v['xid'] == 0)){ + $sql = "UPDATE other_lcprepadekuasi SET Other_LcprepAdekuasiIsActive = 'N' + WHERE + Other_LcprepAdekuasiOther_LcprepID = {$header_id} AND + Other_LcprepAdekuasiIsActive = 'Y' AND + Other_LcprepAdekuasiLcprep_AdekuasiID = {$v['id']}"; + $this->db_smartone->query($sql); + $sql = "INSERT INTO other_lcprepadekuasi ( + Other_LcprepAdekuasiOther_LcprepID, + Other_LcprepAdekuasiLcprep_AdekuasiID, + Other_LcprepAdekuasiChex, + Other_LcprepAdekuasiUserID, + Other_LcprepAdekuasiCreated + ) + VALUES( + {$header_id}, + {$v['id']}, + '{$selected}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + //echo $sql; + } + if(intval($v['xid'] != 0)){ + + $sql = "UPDATE other_lcprepadekuasi SET + Other_LcprepAdekuasiChex = '{$selected}', + Other_LcprepAdekuasiUserID = {$userid} + WHERE + Other_LcprepAdekuasiID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + + //echo $sql; + } + } + + if($kategoriumum){ + foreach($kategoriumum as $k =>$v){ + $selected = $v['chex']?'Y':'N'; + if(intval($v['xid'] == 0)){ + $sql = "UPDATE other_lcprepkategoriumum SET Other_LcprepKategoriUmumIsActive = 'N' + WHERE + Other_LcprepKategoriUmumOther_LcprepID = {$header_id} AND + Other_LcprepKategoriUmumLcprep_KategoriUmumID = {$v['id']} AND + Other_LcprepKategoriUmumIsActive = 'Y' + "; + $this->db_smartone->query($sql); + $sql = "INSERT INTO other_lcprepkategoriumum ( + Other_LcprepKategoriUmumOther_LcprepID, + Other_LcprepKategoriUmumLcprep_KategoriUmumID, + Other_LcprepKategoriUmumChex, + Other_LcprepKategoriUmumUserID, + Other_LcprepKategoriUmumCreated + ) + VALUES( + {$header_id}, + {$v['id']}, + '{$selected}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if(intval($v['xid'] != 0)){ + $sql = "UPDATE other_lcprepkategoriumum SET + Other_LcprepKategoriUmumChex = '{$selected }', + Other_LcprepKategoriUmumUserID = {$userid} + WHERE + Other_LcprepKategoriUmumID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + + //echo $sql; + } + } + + if($results){ + foreach($results as $k =>$v){ + if(intval($v['xid'] == 0)){ + $sql = "UPDATE other_lcprepdetails SET Other_LcprepDetailsIsActive = 'N' + WHERE + Other_LcprepDetailsOther_LcprepID = {$header_id} AND + Other_LcprepDetailsCode = '{$v['code']}' AND + Other_LcprepDetailsIsActive = 'Y'"; + $this->db_smartone->query($sql); + $sql = "INSERT INTO other_lcprepdetails ( + Other_LcprepDetailsOther_LcprepID, + Other_LcprepDetailsCode, + Other_LcprepDetailsLabel, + Other_LcprepDetailsResult, + Other_LcprepDetailsUserID, + Other_LcprepDetailsCreated + ) + VALUES( + {$header_id}, + '{$v['code']}', + '{$v['label']}', + '{$v['result']}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if(intval($v['xid'] != 0)){ + $sql = "UPDATE other_lcprepdetails SET + Other_LcprepDetailsCode = '{$v['code']}', + Other_LcprepDetailsLabel = '{$v['label']}', + Other_LcprepDetailsResult = '{$v['result']}', + Other_LcprepDetailsUserID = {$userid} + WHERE + Other_LcprepDetailsID = {$v['xid']}"; + $this->db_smartone->query($sql); + + } + //echo $sql; + } + } + + if($interpretasi){ + foreach($interpretasi as $k =>$v){ + if(count($v['subgroups']) > 0){ + foreach($v['subgroups'] as $ik => $iv){ + if(count($iv['childs']) > 0){ + foreach($iv['childs'] as $iik => $iiv){ + if(intval($iiv['xid'] == 0)){ + $chex = $iiv['chex'] ? 'Y':'N'; + $sql = "UPDATE other_lcprepinterpretasi SET Other_LcprepInterpretasiIsActive = 'N' + WHERE + Other_LcprepInterpretasiOther_LcprepID = {$header_id} AND + Other_LcprepInterpretasiLcprep_InterpretasiID = '{$iiv['id']}' AND + Other_LcprepInterpretasiIsActive = 'Y'"; + $this->db_smartone->query($sql); + $sql = "INSERT INTO other_lcprepinterpretasi ( + Other_LcprepInterpretasiOther_LcprepID, + Other_LcprepInterpretasiLcprep_InterpretasiID, + Other_LcprepInterpretasiChex, + Other_LcprepInterpretasiValue, + Other_LcprepInterpretasiUserID, + Other_LcprepInterpretasiCreated + ) + VALUES( + {$header_id}, + '{$iiv['id']}', + '{$chex}', + '{$iiv['value']}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + + if(intval($iiv['xid'] != 0)){ + $chex = $iiv['chex'] ? 'Y':'N'; + $sql = "UPDATE other_lcprepinterpretasi SET + Other_LcprepInterpretasiChex = '{$chex}', + Other_LcprepInterpretasiValue = '{$iiv['value']}', + Other_LcprepInterpretasiUserID = {$userid} + WHERE + Other_LcprepInterpretasiID = {$iiv['xid']}"; + $this->db_smartone->query($sql); + //echo $sql; + + } + + } + } + } + } + //echo $sql; + } + } + + + $result = array("total" => 1, "records" => array(), "sql"=> ''); + $this->sys_ok($result); + exit; + } + + function saveresult_papsmear() + { + $prm = $this->sys_input; + $detail_id = $prm['detail_id']; + $doctor_id = $prm['doctor']; + $checks = $prm['checks']; + $maturasi = $prm['maturasi']; + $bahans = $prm['bahans']; + $categories = $prm['categories']; + $results = $prm['results']; + + $userid = $this->sys_user['M_UserID']; + + $header_id = 0; + $sql = "SELECT * FROM other_papsmear WHERE Other_PapSmearT_OrderDetailID = {$detail_id} AND Other_PapSmearIsActive = 'Y'"; + $dt_header = $this->db_smartone->query($sql)->row_array(); + if($dt_header){ + $header_id = $dt_header['Other_PapSmearID']; + } + if($header_id == 0){ + $sql = "INSERT INTO other_papsmear( + Other_PapSmearT_OrderDetailID, + Other_PapSmearM_DoctorID, + Other_PapSmearUserID, + Other_PapSmearCreated + ) + VALUES( + {$detail_id}, + {$doctor_id}, + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } + else{ + $sql = "UPDATE other_papsmear SET Other_PapSmearM_DoctorID = {$doctor_id}, Other_PapSmearUserID = {$userid} WHERE Other_PapSmearID = {$header_id}"; + $this->db_smartone->query($sql); + } + + if($checks){ + foreach($checks as $k =>$v){ + if(intval($v['xid']) == 0 && $v['selected'] === 'Y'){ + $sql = "INSERT INTO other_papsmearcheck ( + Other_PapSmearCheckOther_PapSmearID, + Other_PapSmearCheckM_PapSmearCheckID, + Other_PapSmearCheckNote, + Other_PapSmearCheckUserID, + Other_PapSmearCheckCreated + ) + VALUES( + {$header_id}, + {$v['check_id']}, + '{$v['note']}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if(intval($v['xid']) != 0 && $v['selected'] === 'N'){ + $sql = "UPDATE other_papsmearcheck SET + Other_PapSmearCheckIsActive = 'N', + Other_PapSmearCheckUserID = {$userid} + WHERE + Other_PapSmearCheckID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + if(intval($v['xid']) != 0 && $v['selected'] === 'Y'){ + $sql = "UPDATE other_papsmearcheck SET + Other_PapSmearCheckNote = '{$v['note']}', + Other_PapSmearCheckUserID = {$userid} + WHERE + Other_PapSmearCheckID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + //echo $sql; + } + } + + if($maturasi){ + if(intval($maturasi['xid']) == 0){ + $value = join("/",$maturasi['value']); + $sql = "INSERT INTO other_papsmearmaturasi ( + Other_PapSmearMaturasiOther_PapSmearID, + Other_PapSmearMaturasiValue, + Other_PapSmearMaturasiUserID, + Other_PapSmearMaturasiCreated + ) + VALUE( + {$header_id}, + '{$value}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + //echo $sql; + } + if(intval($maturasi['xid']) != 0){ + $value = join("/",$maturasi['value']); + $sql = "UPDATE other_papsmearmaturasi SET + Other_PapSmearMaturasiValue = '{$value}', + Other_PapSmearMaturasiUserID = {$userid} + WHERE + Other_PapSmearMaturasiID = {$maturasi['xid']}"; + // echo $sql; + $this->db_smartone->query($sql); + } + } + + if($bahans){ + foreach($bahans as $k =>$v){ + if(intval($v['xid']) == 0 && $v['selected'] === 'Y'){ + $sql = "INSERT INTO other_papsmearbahan ( + Other_PapSmearBahanOther_PapSmearID, + Other_PapSmearBahanM_PapSmearBahanID, + Other_PapSmearBahanUserID, + Other_PapSmearBahanCreated + ) + VALUES( + {$header_id}, + {$v['bahan_id']}, + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if(intval($v['xid']) != 0 && $v['selected'] === 'N'){ + $sql = "UPDATE other_papsmearbahan SET + Other_PapSmearBahanIsActive = 'N', + Other_PapsmearCategoryUserID = {$userid} + WHERE + Other_PapSmearBahanID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + if(intval($v['xid']) != 0 && $v['selected'] === 'Y'){ + $sql = "UPDATE other_papsmearbahan SET + Other_PapSmearBahanIsActive = 'Y', + Other_PapsmearCategoryUserID = {$userid} + WHERE + Other_PapSmearBahanID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + //echo $sql; + } + } + + if($categories){ + foreach($categories as $k =>$v){ + if(intval($v['xid']) == 0 && $v['selected'] === 'Y'){ + $sql = "INSERT INTO other_papsmearcategory ( + Other_PapsmearCategoryOther_PapSmearID, + Other_PapsmearCategoryM_PapSmearCategoryID, + Other_PapsmearCategoryUserID, + Other_PapsmearCategoryCreated + ) + VALUES( + {$header_id}, + {$v['category_id']}, + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if(intval($v['xid']) != 0 && $v['selected'] === 'N'){ + $sql = "UPDATE other_papsmearcategory SET + Other_PapsmearCategoryIsActive = 'N', + Other_PapsmearCategoryUserID = {$userid} + WHERE + Other_PapsmearCategoryID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + //echo $sql; + if(intval($v['xid']) != 0 && $v['selected'] === 'Y'){ + $sql = "UPDATE other_papsmearcategory SET + Other_PapsmearCategoryIsActive = 'Y', + Other_PapsmearCategoryUserID = {$userid} + WHERE + Other_PapsmearCategoryID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + } + } + + if($results){ + foreach($results as $k =>$v){ + if(intval($v['xid']) == 0){ + $sql = "INSERT INTO other_papsmeardetails ( + Other_PapSmearDetailsOther_PapSmearID, + Other_PapSmearDetailsCode, + Other_PapSmearDetailsLabel, + Other_PapSmearDetailsResult, + Other_PapSmearDetailsUserID, + Other_PapSmearDetailsCreated + ) + VALUES( + {$header_id}, + '{$v['code']}', + '{$v['label']}', + '{$v['result']}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if(intval($v['xid']) != 0){ + $sql = "UPDATE other_papsmeardetails SET + Other_PapSmearDetailsCode = '{$v['code']}', + Other_PapSmearDetailsLabel = '{$v['label']}', + Other_PapSmearDetailsResult = '{$v['result']}', + Other_PapSmearDetailsUserID = {$userid} + WHERE + Other_PapSmearDetailsID = {$v['xid']}"; + $this->db_smartone->query($sql); + + } + //echo $sql; + } + } + + $result = array("total" => 1, "records" => array(), "sql"=> ''); + $this->sys_ok($result); + exit; + } + + function saveresult_fna() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = $inp['doctor']; + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + if($prm[0]['xid'] == '0'){ + $sql = "INSERT INTO other_fna( + Other_FNAM_DoctorID, + Other_FNAT_OrderDetailID, + Other_FNAUserID, + Other_FNACreated + ) + VALUES( + {$doctor_id}, + {$prm[0]['orderdetail_id']}, + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } + else{ + $sql = "SELECT * FROM other_fna WHERE Other_FNAT_OrderDetailID = {$prm[0]['orderdetail_id']} AND Other_FNAIsActive = 'Y'"; + $data_header = $this->db_smartone->query($sql)->row_array(); + $header_id = $data_header['Other_FNAID']; + $sql = "UPDATE other_fna SET + Other_FNAM_DoctorID = {$doctor_id}, + Other_FNAUserID = {$userid} + WHERE + Other_FNAID = {$header_id}"; + $this->db_smartone->query($sql); + } + foreach($prm as $k => $v){ + if($v['xid'] == '0'){ + $results = str_replace("'", "\\'", $v['result']); + $sql = "INSERT INTO other_fnadetails( + Other_FNADetailsOther_FNAID , + Other_FNADetailsCode, + Other_FNADetailsLabel, + Other_FNADetailsResult, + Other_FNADetailsCreated, + Other_FNADetailsUserID + ) + VALUES( + {$header_id}, + '{$v['code']}', + '{$v['label']}', + '{$results}', + NOW(), + {$userid} + )"; + $query = $this->db_smartone->query($sql); + } + else{ + $results = str_replace("'", "\\'", $v['result']); + $sql = "UPDATE other_fnadetails SET + Other_FNADetailsResult = '{$results}', + Other_FNADetailsUserID = {$userid} + WHERE + Other_FNADetailsID = {$v['xid']}"; + $query = $this->db_smartone->query($sql); + } + } + + $result = array("total" => 1, "records" => array(), "sql"=> ''); + $this->sys_ok($result); + exit; + } + + function saveresult_cytologi() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = $inp['doctor']; + + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + if($prm[0]['xid'] == '0'){ + $sql = "INSERT INTO other_cytologi( + Other_CytologiT_OrderDetailID, + Other_CytologiM_DoctorID, + Other_CytologiUserID, + Other_CytologiCreated + ) + VALUES( + {$prm[0]['orderdetail_id']}, + {$doctor_id}, + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } + else{ + $sql = "SELECT * FROM other_cytologi WHERE Other_CytologiT_OrderDetailID = {$prm[0]['orderdetail_id']} AND Other_CytologiIsActive = 'Y'"; + $data_header = $this->db_smartone->query($sql)->row_array(); + $header_id = $data_header['Other_CytologiID']; + $sql = "UPDATE other_cytologi SET + Other_CytologiM_DoctorID = {$doctor_id}, + Other_CytologiUserID = {$userid} + WHERE + Other_CytologiID = {$header_id}"; + $this->db_smartone->query($sql); + } + foreach($prm as $k => $v){ + if($v['xid'] == '0'){ + $results = str_replace("'", "\\'", $v['result']); + $sql = "INSERT INTO other_cytologidetails( + Other_CytologiDetailsOther_CytologiID , + Other_CytologiDetailsCode, + Other_CytologiDetailsLabel, + Other_CytologiDetailsResult, + Other_CytologiDetailsCreated, + Other_CytologiDetailsUserID + ) + VALUES( + {$header_id}, + '{$v['code']}', + '{$v['label']}', + '{$results}', + NOW(), + {$userid} + )"; + $query = $this->db_smartone->query($sql); + } + else{ + $results = str_replace("'", "\\'", $v['result']); + $sql = "UPDATE other_cytologidetails SET + Other_CytologiDetailsResult = '{$results}', + Other_CytologiDetailsUserID = {$userid} + WHERE + Other_CytologiDetailsID = {$v['xid']}"; + $query = $this->db_smartone->query($sql); + } + } + + $result = array("total" => 1, "records" => array(), "sql"=> ''); + $this->sys_ok($result); + exit; + } + + function saveresult_mikro() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = $inp['doctor']; + $backteria_id = $inp['bacteria']; + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + + if($inp['result_value'] != 'Negatif' && $inp['result_value'] != 'Positif'){ + $prm['result_value'] = $prm['result_other']; + } + else{ + $prm['result_value'] = $inp['result_value']; + } + + if($prm['xid'] == '0'){ + $sql = "INSERT INTO other_mikro( + Other_MikroM_DoctorID, + Other_MikroResult, + Other_MikroT_BacteriaID, + Other_MikroT_OrderDetailID, + Other_MikroHasilBiakan, + Other_MikroSampleTypeName, + Other_MikroUserID, + Other_MikroCreated + ) + VALUES( + {$doctor_id}, + '{$prm['result_value']}', + {$backteria_id}, + {$prm['orderdetail_id']}, + '{$prm['hasil_biakan']}', + '{$prm['sample_name']}', + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } + else{ + $sql = "SELECT * FROM other_mikro WHERE Other_MikroT_OrderDetailID = {$prm['orderdetail_id']} AND Other_MikroIsActive = 'Y'"; + $data_header = $this->db_smartone->query($sql)->row_array(); + $header_id = $data_header['Other_MikroID']; + $sql = "UPDATE other_mikro SET + Other_MikroResult = '{$prm['result_value']}', + Other_MikroM_DoctorID = {$doctor_id}, + Other_MikroT_BacteriaID = {$backteria_id}, + Other_MikroHasilBiakan = '{$prm['hasil_biakan']}', + Other_MikroSampleTypeName = '{$prm['sample_name']}', + Other_MikroUserID = {$userid} + WHERE + Other_MikroID = {$header_id}"; + //echo $sql; + $this->db_smartone->query($sql); + } + + + + $sql = "UPDATE other_mikrodetails SET Other_MikroDetailsIsActive = 'N', Other_MikroDetailsUserID = 0 WHERE Other_MikroDetailsOther_MikroID = {$header_id}"; + $this->db_smartone->query($sql); + + $results = $prm['details']; + if($inp['result_value'] == 'Positif'){ + foreach($results as $k => $v){ + if($v['xid'] == '0'){ + $sql = "INSERT INTO other_mikrodetails( + Other_MikroDetailsOther_MikroID , + Other_MikroDetailsT_AntibioticID, + Other_MikroDetailsValue, + Other_MikroDetailsNote, + Other_MikroDetailsCreated, + Other_MikroDetailsUserID + ) + VALUES( + {$header_id}, + '{$v['T_AntibioticID']}', + '{$v['value']}', + '{$v['note']}', + NOW(), + {$userid} + )"; + $query = $this->db_smartone->query($sql); + } + else{ + $sql = "UPDATE other_mikrodetails SET + Other_MikroDetailsT_AntibioticID = '{$v['T_AntibioticID']}', + Other_MikroDetailsValue = '{$v['value']}', + Other_MikroDetailsNote = '{$v['note']}', + Other_MikroDetailsIsActive = 'Y', + Other_MikroDetailsUserID = {$userid} + WHERE + Other_MikroDetailsID = {$v['xid']}"; + //echo $sql; + $query = $this->db_smartone->query($sql); + } + } + } + + + $result = array("total" => 1, "records" => array(), "sql"=> ''); + $this->sys_ok($result); + exit; + } + + + function get_doctors_preparasi_sperma() + { + $prm = $this->sys_input; + // $id = $prm["id"]; + + $sql = " SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 10 AND + M_DoctorSOIsActive = 'Y' + ORDER BY M_DoctorName ASC"; + //echo $sql; + $query = $this->db_smartone->query($sql); + + if ($query) + { + $rows = $query->result_array(); + $this->sys_ok(["records"=>$rows]); + } + else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + + function getpreparasispermaresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT other_preparasisperma.*, + Other_PreparasiSpermaID as xid, + Other_PreparasiSpermaT_OrderDetailID as orderdetail_id, + IFNULL(Other_PreparasiSpermaM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_PreparasiSpermaM_DoctorID) OR Other_PreparasiSpermaM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_preparasisperma + LEFT JOIN m_doctor ON Other_PreparasiSpermaM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_PreparasiSpermaT_OrderDetailID = {$id} AND Other_PreparasiSpermaIsActive = 'Y' + GROUP BY Other_PreparasiSpermaID"; + $query = $this->db_smartone->query($sql); + + if ($query) + { + $rows = $query->row_array(); + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 10 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $images = array(); + $sql = "SELECT Other_PreparasiSpermaImgID as xid, + Other_PreparasiSpermaImgType as type, + CONCAT('/one-media/one-image-nonlab/',Other_PreparasiSpermaImgNewName) as image_url + FROM t_orderdetail + JOIN other_preparasisperma_img ON Other_PreparasiSpermaImgT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND + Other_PreparasiSpermaImgIsActive = 'Y' + WHERE + T_OrderDetailID = {$id} AND + T_OrderDetailIsActive = 'Y' + GROUP BY Other_PreparasiSpermaImgID"; + //echo $sql; + $images = $this->db_smartone->query($sql)->result_array(); + + $rst = array('doctors'=>$doctors,'results'=>$rows,'images'=>$images); + $this->sys_ok(["records"=>$rst]); + } + else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + + function uploadimage_preparasi_sperma(){ + if (! $this->isLogin) { + $this->sys_error("Invalid Token"); + exit; + } + + $userid = $this->sys_user["M_UserID"]; + $data = []; + //print_r($_SERVER); + + $prm = $this->sys_input; + $orderid = $this->input->post('orderid'); + $type = $this->input->post('type'); + $labnumber = $this->input->post('labnumber'); + $sql = "UPDATE other_preparasisperma_img SET + Other_PreparasiSpermaImgIsActive = 'N', + Other_PreparasiSpermaImgUserID = {$userid} + WHERE + Other_PreparasiSpermaImgT_OrderHeaderID = {$orderid} AND + Other_PreparasiSpermaImgType = '{$type}'"; + //echo $sql; + $this->db_onedev->query($sql); + //$config['upload_path'] = 'assets/'; + + $path = '/home/one/project/one/one-media/one-image-nonlab/'; + //echo $path; + $config['upload_path'] = $path; + $config['allowed_types'] = 'jpg|jpeg|png|gif'; + + $config['max_size'] = '10000'; + $count = count($_FILES['files']['name']); + //echo $count; + $this->load->library('upload',$config); + + $error = []; + for($i=0;$i<$count;$i++){ + + + if(!empty($_FILES['files']['name'][$i])){ + + + + $_FILES['file']['name'] = $_FILES['files']['name'][$i]; + + $_FILES['file']['type'] = $_FILES['files']['type'][$i]; + + $_FILES['file']['tmp_name'] = $_FILES['files']['tmp_name'][$i]; + + $_FILES['file']['error'] = $_FILES['files']['error'][$i]; + + $_FILES['file']['size'] = $_FILES['files']['size'][$i]; + + + + $namex = $orderid.'-'.$labnumber.'-'.$this->generateRandomString(5); + //echo $namex; + + $config['file_name'] = $namex; + $this->upload->initialize($config); + //echo $config['file_name'] ; + + + + + + if($this->upload->do_upload('file')){ + + $uploadData = $this->upload->data(); + + $filename = $uploadData['file_name']; + //echo $filename; + + + $sql = "INSERT INTO other_preparasisperma_img ( + Other_PreparasiSpermaImgT_OrderHeaderID, + Other_PreparasiSpermaImgType, + Other_PreparasiSpermaImgOldName, + Other_PreparasiSpermaImgNewName, + Other_PreparasiSpermaImgCreated, + Other_PreparasiSpermaImgUserID + ) + VALUES( + {$orderid}, + '{$type}', + '{$_FILES['files']['name'][$i]}', + '{$filename}', + NOW(), + {$userid} + + )"; + //echo $sql; + $this->db_onedev->query($sql); + $xlast_id = $this->db_onedev->insert_id(); + $data['totalFiles'][] = array('xid' => $xlast_id ,'type'=>$type,'image_url' => '/one-media/one-image-nonlab/'.$filename); + + } + else{ + $error = array('error' => $this->upload->display_errors()); + } + + } + + + + } + + $result = array("total" =>count( $data['totalFiles']), "records" => $data['totalFiles'],'errors'=>$error); + $this->sys_ok($result); + } + + + function saveresult_preparasi_sperma() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = $inp['doctor']; + $orderdetail_id = $inp['orderdetailid']; + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + if($prm['xid'] == '0'){ + $sql = "INSERT INTO other_preparasisperma( + Other_PreparasiSpermaM_DoctorID, + Other_PreparasiSpermaT_OrderDetailID, + Other_PreparasiSpermaPreMotilitasA, + Other_PreparasiSpermaPreMotilitasB, + Other_PreparasiSpermaPreMotilitasC, + Other_PreparasiSpermaPreKonsentrasi, + Other_PreparasiSpermaPreKontaminan, + Other_PreparasiSpermaPostMotilitasA, + Other_PreparasiSpermaPostMotilitasB, + Other_PreparasiSpermaPostMotilitasC, + Other_PreparasiSpermaPostKonsentrasi, + Other_PreparasiSpermaPostKontaminan, + Other_PreparasiSpermaNote, + Other_PreparasiSpermaUserID, + Other_PreparasiSpermaCreated + ) + VALUES( + {$doctor_id}, + {$orderdetail_id}, + '{$prm['Other_PreparasiSpermaPreMotilitasA']}', + '{$prm['Other_PreparasiSpermaPreMotilitasB']}', + '{$prm['Other_PreparasiSpermaPreMotilitasC']}', + '{$prm['Other_PreparasiSpermaPreKonsentrasi']}', + '{$prm['Other_PreparasiSpermaPreKontaminan']}', + '{$prm['Other_PreparasiSpermaPostMotilitasA']}', + '{$prm['Other_PreparasiSpermaPostMotilitasB']}', + '{$prm['Other_PreparasiSpermaPostMotilitasC']}', + '{$prm['Other_PreparasiSpermaPostKonsentrasi']}', + '{$prm['Other_PreparasiSpermaPostKontaminan']}', + '{$prm['Other_PreparasiSpermaNote']}', + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } + else{ + $sql = "SELECT * FROM other_preparasisperma WHERE Other_PreparasiSpermaT_OrderDetailID = {$orderdetail_id} AND Other_PreparasiSpermaIsActive = 'Y'"; + $data_header = $this->db_smartone->query($sql)->row_array(); + $header_id = $data_header['Other_PreparasiSpermaID']; + $sql = "UPDATE other_preparasisperma SET + Other_PreparasiSpermaM_DoctorID = {$doctor_id}, + Other_PreparasiSpermaPreMotilitasA = '{$prm['Other_PreparasiSpermaPreMotilitasA']}', + Other_PreparasiSpermaPreMotilitasB = '{$prm['Other_PreparasiSpermaPreMotilitasB']}', + Other_PreparasiSpermaPreMotilitasC = '{$prm['Other_PreparasiSpermaPreMotilitasC']}', + Other_PreparasiSpermaPreKonsentrasi = '{$prm['Other_PreparasiSpermaPreKonsentrasi']}', + Other_PreparasiSpermaPreKontaminan = '{$prm['Other_PreparasiSpermaPreKontaminan']}', + Other_PreparasiSpermaPostMotilitasA = '{$prm['Other_PreparasiSpermaPostMotilitasA']}', + Other_PreparasiSpermaPostMotilitasB = '{$prm['Other_PreparasiSpermaPostMotilitasB']}', + Other_PreparasiSpermaPostMotilitasC = '{$prm['Other_PreparasiSpermaPostMotilitasC']}', + Other_PreparasiSpermaPostKonsentrasi = '{$prm['Other_PreparasiSpermaPostKonsentrasi']}', + Other_PreparasiSpermaPostKontaminan = '{$prm['Other_PreparasiSpermaPostKontaminan']}', + Other_PreparasiSpermaNote = '{$prm['Other_PreparasiSpermaNote']}', + Other_PreparasiSpermaUserID = {$userid} + WHERE + Other_PreparasiSpermaID = {$header_id}"; + $this->db_smartone->query($sql); + } + + + $result = array("total" => 1, "records" => array(), "sql"=> ''); + $this->sys_ok($result); + exit; + } + + function getdnafragmentasiresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT other_dnafragmentasi.*, + Other_DnaFragmentasiID as xid, + Other_DnaFragmentasiT_OrderDetailID as orderdetail_id, + IFNULL(Other_DnaFragmentasiM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_DnaFragmentasiM_DoctorID) OR Other_DnaFragmentasiM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name, + IFNULL(Other_DnaFragmentasiOther_DnaFragmentasiMethodeID,0) as methode_id, + IFNULL(Other_DnaFragmentasiMethodeName,'') as methode_name, + Other_DnaFragmentasiHaloLuas as halo_luas, + Other_DnaFragmentasiHaloSedang as halo_sedang, + Other_DnaFragmentasiHaloSempit as halo_sempit, + Other_DnaFragmentasiTanpaHalo as tanpa_halo, + Other_DnaFragmentasiDFI as dfi, + Other_DnaFragmentasiKesimpulan as kesimpulan, + Other_DnaFragmentasiCatatan as catatan + FROM other_dnafragmentasi + LEFT JOIN m_doctor ON Other_DnaFragmentasiM_DoctorID = M_DoctorID + LEFT JOIN other_dnafragmentasimethode ON Other_DnaFragmentasiOther_DnaFragmentasiMethodeID = Other_DnaFragmentasiMethodeID + WHERE + Other_DnaFragmentasiT_OrderDetailID = {$id} AND Other_DnaFragmentasiIsActive = 'Y' + GROUP BY Other_DnaFragmentasiID + LIMIT 1"; + //echo $sql; + $query = $this->db_smartone->query($sql); + + if ($query) + { + $rows = $query->row_array(); + if(!$rows){ + $rows = array( + 'xid' => 0, + 'orderdetail_id' =>$id, + 'doctor_id' => 0, + 'doctor_name' => '', + 'methode_id' => 0, + 'methode_name' => '', + 'halo_luas' => '', + 'halo_sedang' => '', + 'tanpa_halo' => '', + 'dfi' => '', + 'kesimpulan' => '', + 'catatan' => '' + ); + } + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID + WHERE + M_DoctorSONat_SubGroupID = 4 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + + $sql = " + SELECT '0' as id, 'Belum memilih metode' as name + UNION + SELECT Other_DnaFragmentasiMethodeID as id, Other_DnaFragmentasiMethodeName as name + FROM other_dnafragmentasimethode + WHERE + Other_DnaFragmentasiMethodeIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $methodes = $this->db_smartone->query($sql)->result_array(); + + + $rst = array('doctors'=>$doctors,'methodes'=>$methodes,'results'=>$rows); + $this->sys_ok(["records"=>$rst]); + } + else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + function saveresult_dnafragmentasi() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = $inp['doctor']['id']; + $methode_id = $inp['methode']['id']; + $orderdetail_id = $inp['results']['orderdetail_id']; + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + if(intval($prm['xid']) == 0){ + $sql = "INSERT INTO other_dnafragmentasi( + Other_DnaFragmentasiT_OrderDetailID, + Other_DnaFragmentasiM_DoctorID, + Other_DnaFragmentasiOther_DnaFragmentasiMethodeID, + Other_DnaFragmentasiHaloLuas, + Other_DnaFragmentasiHaloSedang, + Other_DnaFragmentasiHaloSempit, + Other_DnaFragmentasiTanpaHalo, + Other_DnaFragmentasiDFI, + Other_DnaFragmentasiKesimpulan, + Other_DnaFragmentasiCatatan, + Other_DnaFragmentasiUserID, + Other_DnaFragmentasiLastUpdated + ) + VALUES( + {$orderdetail_id}, + {$doctor_id}, + {$methode_id}, + '{$prm['halo_luas']}', + '{$prm['halo_sedang']}', + '{$prm['halo_sempit']}', + '{$prm['tanpa_halo']}', + '{$prm['dfi']}', + '{$prm['kesimpulan']}', + '{$prm['catatan']}', + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } + else{ + $sql = "UPDATE other_dnafragmentasi SET + Other_DnaFragmentasiT_OrderDetailID = {$orderdetail_id}, + Other_DnaFragmentasiM_DoctorID = {$doctor_id}, + Other_DnaFragmentasiOther_DnaFragmentasiMethodeID = '{$methode_id}', + Other_DnaFragmentasiHaloLuas = '{$prm['halo_luas']}', + Other_DnaFragmentasiHaloSedang = '{$prm['halo_sedang']}', + Other_DnaFragmentasiHaloSempit = '{$prm['halo_sempit']}', + Other_DnaFragmentasiTanpaHalo = '{$prm['tanpa_halo']}', + Other_DnaFragmentasiDFI = '{$prm['dfi']}', + Other_DnaFragmentasiKesimpulan = '{$prm['kesimpulan']}', + Other_DnaFragmentasiCatatan = '{$prm['catatan']}', + Other_DnaFragmentasiLastUpdated = NOW(), + Other_DnaFragmentasiUserID = {$userid} + WHERE + Other_DnaFragmentasiID = {$prm['xid']}"; + //echo $sql; + $this->db_smartone->query($sql); + } + + + $result = array("total" => 1, "records" => array(), "sql"=> ''); + $this->sys_ok($result); + exit; + } + + +} + diff --git a/application/controllers/mockup/process/resultentry-v20/Re_px.php b/application/controllers/mockup/process/resultentry-v20/Re_px.php index 0438a3e1..9bab2c82 100644 --- a/application/controllers/mockup/process/resultentry-v20/Re_px.php +++ b/application/controllers/mockup/process/resultentry-v20/Re_px.php @@ -1,2496 +1,2493 @@ -db_smartone = $this->load->database("onedev", true); - $this->load->helper(array('form', 'url')); - } - function getMethodeID($natTestID) { - $sql = "select M_MethodePriorityNat_MethodeID MethodeID, Nat_MethodeName - from - m_methode_priority - join nat_methode on Nat_MethodeID = M_MethodePriorityNat_MethodeID - and Nat_MethodeIsActive = 'Y' - join m_instrumentmethode on M_InstrumentMethodeNat_MethodeID = Nat_MethodeID and M_InstrumentMethodeIsActive = 'Y' - join nat_instrument on M_InstrumentMethodeNat_InstrumentID = Nat_InstrumentID - and Nat_InstrumentIsActive ='Y' - where M_MethodePriorityIsActive = 'Y' - and M_MethodePriorityNat_TestID = $natTestID - and M_MethodePriorityM_DayOfWeekID = dayofweek(now()) - order by M_MethodePriorityNumber desc - limit 0,1 "; - $qry = $this->db->query($sql); - if ($qry) { - $rows = $qry->result_array(); - if (count($rows) > 0 ) return array($rows[0]["MethodeID"],$rows[0]["Nat_MethodeName"]); - } - //2nd - $sql= "select - M_InstrumentMethodeNat_MethodeID MethodeID, Nat_MethodeName - from m_instrumentmethode - join nat_methode on M_InstrumentMethodeNat_MethodeID = Nat_MethodeID - and Nat_MethodeIsActive = 'Y' - join nat_instrument on M_InstrumentMethodeNat_InstrumentID = Nat_InstrumentID - and Nat_InstrumentIsActive ='Y' - where M_InstrumentMethodeNat_TestID = $natTestID - and M_InstrumentMethodeIsActive = 'Y' - order by M_InstrumentMethodePriority desc - limit 0,1"; - $qry = $this->db->query($sql); - if ($qry) { - $rows = $qry->result_array(); - if (count($rows) > 0 ) return array($rows[0]["MethodeID"],$rows[0]["Nat_MethodeName"]); - } - // - $sql = "select Nat_NormalValueNat_MethodeID MethodeID, Nat_MethodeName - from - nat_normalvalue - join nat_methode on Nat_NormalValueNat_MethodeID = Nat_MethodeID - and Nat_MethodeIsActive = 'Y' - where Nat_NormalValueNat_TestID = $natTestID - and Nat_NormalValueIsActive = 'Y' - order by Nat_NormalValueID - limit 0,1"; - $qry = $this->db->query($sql); - if ($qry) { - $rows = $qry->result_array(); - if (count($rows) > 0 ) return array($rows[0]["MethodeID"],$rows[0]["Nat_MethodeName"]); - } - return array(0,""); - } - function get_normal_value($methodeID, $natTestID, $sexID, $ageInDay ) { - $sql = "select fn_sampling_get_normal($methodeID, $natTestID, $sexID, $ageInDay) as normalValueID"; - $qry = $this->db->query($sql); - if ($qry) { - $rows = $qry->result_array(); - if (count($rows) > 0 ) return $rows[0]["normalValueID"]; - } - return 0; - } - function fn_fix_normal($order_id) { - $sql = "select - T_OrderDetailID, M_PatientM_SexID, fn_global_age_count_day(M_PatientDOB, date(T_OrderHeaderDate)) Dob , - T_TestNat_TestID - from t_orderheader - join m_patient on T_OrderHeaderID = $order_id and T_OrderHeaderM_PatientID = M_PatientID - join t_orderdetail on T_OrderDetailT_OrderHeaderID = T_OrderHeaderID - and T_OrderDetailIsACtive = 'Y' - and ( T_OrderDetailNat_NormalValueID is null or T_OrderDetailNat_NormalValueID = 0 ) - join t_test on T_OrderDetailT_TestID = T_TestID and T_TestIsResult = 'Y' "; - $qry = $this->db->query($sql); - if(! $qry) { - return; - } - $rows = $qry->result_array(); - if(count($rows) == 0 ) return; - $sql_u = "update t_orderdetail - join nat_normalvalue on T_OrderDetailID = ? and Nat_NormalValueID = ? - set - T_OrderDetailNat_NormalValueID = Nat_NormalValueID, - T_OrderDetailNormalValueNote = Nat_NormalValueNote, - T_OrderDetailNormalValueDescription = Nat_NormalValueDescription, - T_OrderDetailMinValue = Nat_NormalValueMinValue, - T_OrderDetailMaxValue = Nat_NormalValueMaxValue, - T_OrderDetailMinValueInclusive = Nat_NormalValueMinValueInclusive, - T_OrderDetailMaxValueInclusive = Nat_NormalValueMaxValueInclusive, - T_OrderDetailNat_MethodeID = ?, - T_OrderdetailNat_MethodeName =?"; - - foreach($rows as $r) { - $T_OrderDetailID = $r["T_OrderDetailID"]; - $sexID = $r["M_PatientM_SexID"]; - $ageInDay = $r["Dob"]; - $natTestID = $r["T_TestNat_TestID"]; - list($methodeID,$methodeName) = $this->getMethodeID($natTestID); - if ($methodeID == 0 ) continue; - $normalValueID = $this->get_normal_value($methodeID, $natTestID, $sexID, $ageInDay); - if ($normalValueID == 0) return; - $this->db->query($sql_u, array($T_OrderDetailID, $normalValueID, $methodeID, $methodeName)); - } - } - function update_order_sample($targetID, $sourceID) { - $sql = "update t_ordersample target - join t_ordersample source on - target.T_OrderSampleID = ? - and target.T_OrderSampleWorklistReceive = 'N' - and source.T_OrderSampleID = ? - set - target.T_OrderSampleSampling = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSampling, source.T_OrderSampleSampling), - target.T_OrderSampleSamplingDate = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingDate, source.T_OrderSampleSamplingDate), - target.T_OrderSampleSamplingTime = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingTime, source.T_OrderSampleSamplingTime), - target.T_OrderSampleSamplingUserID = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingUserID, source.T_OrderSampleSamplingUserID), - - target.T_OrderSampleReceive = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceive, source.T_OrderSampleReceive), - target.T_OrderSampleReceiveDate = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveDate, source.T_OrderSampleReceiveDate), - target.T_OrderSampleReceiveTime = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveTime, source.T_OrderSampleReceiveTime), - target.T_OrderSampleReceiveUserID = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveUserID, source.T_OrderSampleReceiveUserID), - - target.T_OrderSampleVerification = if(target.T_OrderSampleVerification='Y',target.T_OrderSampleVerification, source.T_OrderSampleVerification), - target.T_OrderSampleVerificationDate =if(target.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationDate, source.T_OrderSampleVerificationDate), - target.T_OrderSampleVerificationTime =if(source.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationTime, source.T_OrderSampleVerificationTime), - target.T_OrderSampleVerificationUserID =if(source.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationUserID, source.T_OrderSampleVerificationUserID), - - target.T_OrderSampleProcessing = if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessing, source.T_OrderSampleProcessing), - target.T_OrderSampleProcessingDate= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingDate, source.T_OrderSampleProcessingDate), - target.T_OrderSampleProcessingTime= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingTime, source.T_OrderSampleProcessingTime), - target.T_OrderSampleProcessingUserID= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingUserID, source.T_OrderSampleProcessingUserID), - - target.T_OrderSampleReceiveHandling =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandling, source.T_OrderSampleReceiveHandling ), - target.T_OrderSampleReceiveHandlingDate =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingDate, source.T_OrderSampleReceiveHandlingDate), - target.T_OrderSampleReceiveHandlingTime =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingTime, source.T_OrderSampleReceiveHandlingTime), - target.T_OrderSampleReceiveHandlingUserID =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingUserID, source.T_OrderSampleReceiveHandlingUserID), - - target.T_OrderSampleHandling = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandling, source.T_OrderSampleHandling), - target.T_OrderSampleHandlingDate = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingDate, source.T_OrderSampleHandlingDate), - target.T_OrderSampleHandlingTime = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingTime, source.T_OrderSampleHandlingTime), - target.T_OrderSampleHandlingUserID = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingUserID, source.T_OrderSampleHandlingUserID), - - target.T_OrderSampleWorklistReceive = source.T_OrderSampleWorklistReceive, - target.T_OrderSampleWorklistReceiveDatetime = source.T_OrderSampleWorklistReceiveDateTime, - target.T_OrderSampleWorklistReceiveUserID = source.T_OrderSampleWorklistReceiveUserID - "; - $qry = $this->db->query($sql,array($targetID,$sourceID)); - if(! $qry ) { - echo json_encode(array( "status" => "ERR" , "message" => print_r($this->db->error(),true))); - exit; - } - } - function fix_sample_serum($headerID) { - //cari t_ordersample yg belum worklist receive dengan code 017% - $sql = "select T_OrderSampleID - from t_ordersample - join t_sampletype on - T_OrderSampleT_OrderHeaderID = ? - and T_OrderSampleWorklistReceive = 'N' - and T_OrderSampleIsActive = 'Y' - and T_OrderSampleT_SampleTypeID = T_SampletypeID - and T_SampleTypeCode like '017%' - "; - $qry = $this->db->query($sql, array($headerID)); - if(!$qry) { - echo json_encode(array( "status" => "ERR" , "message" => print_r($this->db->error(),true))); - exit; - } - $rows = $qry->result_array(); - if (count($rows) == 0 ) return; - //cari T_OrderSample yang sudah di receive yg terakhir - $sql = "select T_OrderSampleID - from t_ordersample - join t_sampletype on - T_OrderSampleT_OrderHeaderID = ? - and T_OrderSampleWorklistReceive = 'Y' - and T_OrderSampleIsActive = 'Y' - and T_OrderSampleT_SampleTypeID = T_SampletypeID - and T_SampleTypeCode like '017%' - order by T_OrderSampleWorklistReceiveDatetime desc - limit 0,1 - "; - $qry = $this->db->query($sql, array($headerID)); - if(!$qry) { - echo json_encode(array( "status" => "ERR" , "message" => print_r($this->db->error(),true))); - exit; - } - $rcv_rows = $qry->result_array(); - if (count($rcv_rows) == 0 ) return; - - //print_r($rows); - //print_r($rcv_rows); - $rcv_T_OrderSampleID = $rcv_rows[0]["T_OrderSampleID"]; - //ada yg belum di receive - foreach($rows as $r) { - $T_OrderSampleID = $r["T_OrderSampleID"]; - $this->update_order_sample($T_OrderSampleID,$rcv_T_OrderSampleID); - } - } - public function search() - { - $prm = $this->sys_input; - $max_rst = 99; - - $id = $prm["order_id"]; - if ($id > 0 ) { - $this->fix_sample_serum($id); - $this->fn_fix_normal($id); - } - $lang = $this->lang_default_code; - $lang_id = isset($prm['lang_id']) ? $prm['lang_id'] : '0'; - - if ($lang_id != 0) - { - $l = $this->db_smartone->where("Nat_LangID", $lang_id)->get("nat_lang")->row(); - $lang = $l->Nat_LangCode; - } - - //tambahan fajri - $sql = " UPDATE t_orderdetail - JOIN t_test ON T_OrderDetailT_TestID = T_TestID - SET T_OrderDetailT_TestIsResult = T_TestIsResult - WHERE - T_OrderDetailT_OrderHeaderID = {$id} AND - T_OrderDetailT_TestIsResult = '' AND - T_OrderDetailIsActive = 'Y'"; - $this->db_smartone->query($sql); - - $tot_count = 0; - $lq = ""; - $group_id = 0; - if (isset($prm['group_id'])) - $group_id = $prm['group_id']; - - if ($group_id != 0) - { - $sql = "select distinct T_WorklistDetailNat_TestID Nat_TestID - from t_worklistdetailv2 - where T_WorklistDetailT_WorklistID = {$group_id}"; - $qry = $this->db_smartone->query($sql); - $rows = $qry->result_array(); - $nat_test_ids = "0"; - foreach($rows as $r) { - $nat_test_ids .= ", " . $r["Nat_TestID"]; - } - $q_group = " ( $nat_test_ids ) "; - - $sql = " - SELECT a1.*, cOUNT(a2.T_OrderDetailID) level - FROM ( - SELECT IFNULL(y.T_OrderDetailT_TestID, x.T_OrderDetailT_TestID) t_testid, - IFNULL(y.T_OrderDetailT_TestName, y.T_OrderDetailT_TestName) t_testname, - y.T_OrderDetailResult result, y.T_OrderDetailResult result_old, y.T_OrderDetailNote note, y.T_OrderDetailNote note_old, - y.T_OrderDetailID id, - y.T_OrderDetailT_TestIsResult is_result, a.T_TestIsQuantitative is_quantitative, - y.T_OrderDetailResultFlag result_flag, - y.T_OrderDetailNat_NormalValueID normal_id, - y.T_OrderDetailNormalValueNote normal_note, y.T_OrderDetailNat_UnitName unit_name, - y.T_OrderdetailNat_MethodeID methode_id, y.T_OrderdetailNat_MethodeName methode_name, - a.T_TestNat_TestID nattest_id, a.T_TestID tx_id, count(T_ResultInstrumentID) as result_instrument_n, - y.T_OrderDetailVerification, T_OrderSampleReceive sample_receive, - T_OrderSampleProcessing sample_processing, T_OrderSampleWorklistReceive sample_worklist_receive, - IF(T_OrderDetailAddOnPreAnalytic = 'Y', T_OrderDetailAddOnPreAnalytic, PreAnalyticIsOk) pre_analytic, - T_OrderDetailAddOnPreAnalytic, - T_OrderHeaderID order_id, y.T_OrderDetailT_TestSasCode test_sas_code, - tx.T_TestSasCode, - T_OrderDetailAddOnResample `resample`, T_OrderDetailAddOnResampleStatus resample_status, - T_OrderDetailAddOnRef ref, y.T_OrderDetailVerification verification, y.T_OrderDetailValidation validation, - T_OrderPromiseDateTime, Group_ResultName as ResultGroupName - FROM t_orderdetail x - left join t_orderpromise on x.T_OrderDetailT_OrderPromiseID = T_OrderPromiseID - JOIN t_test tx ON x.T_OrderDetailT_TestID = T_TestID - JOIN t_test tcheck on tcheck.T_TestNat_TestID in {$q_group} - and ( tx.T_TestID = tcheck.T_TestID or tx.T_TestSasCode like concat(tcheck.T_TestSasCode,'%')) - LEFT JOIN group_resultdetail ON Group_ResultDetailT_TestID = x.T_OrderDetailT_TestID AND Group_ResultDetailIsActive = 'Y' - LEFT JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND Group_ResultFlagNonLab = 'N' - LEFT JOIN t_orderdetail y ON x.T_OrderDetailT_TestSasCode LIKE CONCAT(y.T_OrderDetailT_TestSasCode, '%') - AND x.T_OrderDetailT_OrderHeaderID = y.T_OrderDetailT_OrderHeaderID - AND y.T_OrderDetailIsActive = 'Y' - LEFT JOIN t_orderdetailaddon ON x.T_OrderDetailID = T_OrderDetailAddOnT_OrderDetailID - JOIN t_orderheader ON y.T_OrderDetailT_OrderHeaderID = T_OrderHeaderID - LEFT JOIN t_test a ON y.T_OrderDetailT_TestID = a.T_TestID - AND a.T_TestIsNonLab = '' - LEFT JOIN (SELECT T_OrderSampleT_SampleTypeID, T_OrderSampleReceive, T_OrderSampleProcessing, T_OrderSampleWorklistReceive - FROM t_ordersample WHERE T_OrderSampleT_OrderHeaderID = {$id} - AND T_OrderSampleIsactive = 'Y' - GROUP BY T_OrderSampleT_SampleTypeID) os ON a.T_TestT_SampleTypeID = os.T_OrderSampleT_SampleTypeID - or os.T_OrderSampleT_SampleTypeID = fn_sampletype_from_local(a.T_TestNat_TestID) - - LEFT JOIN t_resultinstrument ON T_ResultInstrumentT_OrderDetailID = x.T_OrderDetailID - LEFT JOIN pre_analytic ON PreAnalyticNat_TestID = a.T_TestNat_TestID AND PreAnalyticDate = date(now()) and PreAnalyticIsActive = 'Y' - WHERE x.T_OrderDetailT_OrderHeaderID = {$id} - AND x.T_OrderDetailIsActive = 'Y' - GROUP BY y.T_OrderDetailT_TestID - ORDER BY y.T_OrderDetailT_TestSasCode ASC - ) a1 - - LEFT JOIN t_orderdetail a2 ON a2.T_OrderDetailT_OrderHeaderID = a1.order_id - AND a2.T_OrderDetailIsActive = 'Y' - AND a1.test_sas_code LIKE CONCAT(a2.T_OrderDetailT_testSasCode, '%') - GROUP BY a1.t_testid - order by a1.test_sas_code -"; - $query = $this->db_smartone->query($sql); - $lq = $this->db_smartone->last_query(); - } - else - { - $sql = " - SELECT a1.*, cOUNT(a2.T_OrderDetailID) level - FROM ( - SELECT IFNULL(y.T_OrderDetailT_TestID, x.T_OrderDetailT_TestID) t_testid, - IFNULL(y.T_OrderDetailT_TestName, y.T_OrderDetailT_TestName) t_testname, - y.T_OrderDetailResult result, y.T_OrderDetailResult result_old, y.T_OrderDetailNote note, y.T_OrderDetailNote note_old, - y.T_OrderDetailID id, - y.T_OrderDetailT_TestIsResult is_result, a.T_TestIsQuantitative is_quantitative, - y.T_OrderDetailResultFlag result_flag, - y.T_OrderDetailNat_NormalValueID normal_id, - y.T_OrderDetailNormalValueNote normal_note, y.T_OrderDetailNat_UnitName unit_name, - y.T_OrderdetailNat_MethodeID methode_id, y.T_OrderdetailNat_MethodeName methode_name, - a.T_TestNat_TestID nattest_id, a.T_TestID tx_id, count(T_ResultInstrumentID) as result_instrument_n, - y.T_OrderDetailVerification, T_OrderSampleReceive sample_receive, - T_OrderSampleProcessing sample_processing, T_OrderSampleWorklistReceive sample_worklist_receive, - IF(T_OrderDetailAddOnPreAnalytic = 'Y', T_OrderDetailAddOnPreAnalytic, PreAnalyticIsOk) pre_analytic, - T_OrderDetailAddOnPreAnalytic, - T_OrderHeaderID order_id, y.T_OrderDetailT_TestSasCode test_sas_code, - tx.T_TestSasCode, - T_OrderDetailAddOnResample `resample`, T_OrderDetailAddOnResampleStatus resample_status, - T_OrderDetailAddOnRef ref, y.T_OrderDetailVerification verification, y.T_OrderDetailValidation validation, - T_OrderPromiseDateTime , Group_ResultName as ResultGroupName - FROM t_orderdetail x - left join t_orderpromise on x.T_OrderDetailT_OrderPromiseID = T_OrderPromiseID - JOIN t_test tx ON x.T_OrderDetailT_TestID = T_TestID - LEFT JOIN group_resultdetail ON Group_ResultDetailT_TestID = x.T_OrderDetailT_TestID AND Group_ResultDetailIsActive = 'Y' - LEFT JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND Group_ResultFlagNonLab = 'N' - LEFT JOIN t_orderdetail y ON x.T_OrderDetailT_TestSasCode LIKE CONCAT(y.T_OrderDetailT_TestSasCode, '%') - AND x.T_OrderDetailT_OrderHeaderID = y.T_OrderDetailT_OrderHeaderID - AND y.T_OrderDetailIsActive = 'Y' - - LEFT JOIN t_orderdetailaddon ON x.T_OrderDetailID = T_OrderDetailAddOnT_OrderDetailID - - JOIN t_orderheader ON y.T_OrderDetailT_OrderHeaderID = T_OrderHeaderID - LEFT JOIN t_test a ON y.T_OrderDetailT_TestID = a.T_TestID - AND a.T_TestIsNonLab = '' - LEFT JOIN (SELECT T_OrderSampleT_SampleTypeID, T_OrderSampleReceive, T_OrderSampleProcessing, T_OrderSampleWorklistReceive - FROM t_ordersample WHERE T_OrderSampleT_OrderHeaderID = {$id} - AND T_OrderSampleIsactive = 'Y' - GROUP BY T_OrderSampleT_SampleTypeID) os ON a.T_TestT_SampleTypeID = os.T_OrderSampleT_SampleTypeID - or os.T_OrderSampleT_SampleTypeID = fn_sampletype_from_local(a.T_TestNat_TestID) - - LEFT JOIN t_resultinstrument ON T_ResultInstrumentT_OrderDetailID = x.T_OrderDetailID - LEFT JOIN pre_analytic ON PreAnalyticNat_TestID = a.T_TestNat_TestID AND PreAnalyticDate = date(now()) and PreAnalyticIsActive = 'Y' - WHERE x.T_OrderDetailT_OrderHeaderID = {$id} - AND x.T_OrderDetailIsActive = 'Y' - GROUP BY y.T_OrderDetailT_TestID - ORDER BY y.T_OrderDetailT_TestSasCode ASC - ) a1 - - LEFT JOIN t_orderdetail a2 ON a2.T_OrderDetailT_OrderHeaderID = a1.order_id - AND a2.T_OrderDetailIsActive = 'Y' - AND a1.test_sas_code LIKE CONCAT(a2.T_OrderDetailT_testSasCode, '%') - GROUP BY a1.t_testid - order by a1.test_sas_code -"; -//echo $sql; - $query = $this->db_smartone->query($sql); - $lq = $this->db_smartone->last_query(); - } - // file_put_contents("/xtmp/re-query.sql",$lq); - - if ($query) { - $rst = []; - $rows = $query->result_array(); - - foreach($rows as $k => $v) - { - - if ($v['is_result'] == "Y" && $v['is_quantitative'] == "N") - { - $v['template'] = []; - $x = $this->db_smartone->query("CALL sp_master_resulttemplate_get('{$v['t_testid']}')"); - $this->clean_mysqli_connection($this->db_smartone->conn_id); - if ($x) - $v['template'] = $x->result_array(); - } - - // IF Rujukan, by pas Pre Analytik - if ($v['ref'] == 'Y') - $v['pre_analytic'] = 'Y'; - if ($v["id"] == "885455" ) - { - //sipe workaround - //$v["sample_receive"] = "Y"; - $v["sample_worklist_receive"] = "Y"; - } - $rst[] = $v; - } - - $result = array("total" => $tot_count, "records" => $rst, "total_display" => sizeof($rows), "q" => $lq); - $this->sys_ok($result); - } - else { - $this->sys_error_db("RE Px rows", $this->db_smartone); - exit; - } - } - - public function save() - { - $prm = $this->sys_input; - $data = json_decode($prm["data"]); - $lang = $this->lang_default_code; - $lang_id = isset($prm['lang_id']) ? $prm['lang_id'] : '0'; - - if ($lang_id != 0) - { - $l = $this->db_smartone->where("Nat_LangID", $lang_id)->get("nat_lang")->row(); - $lang = $l->Nat_LangCode; - } - - $sql_norm = "select T_OrderDetailMinValue, T_OrderDetailMaxValue, - T_OrderDetailMinValueInclusive, T_OrderDetailMaxValueInclusive, - Nat_TestFlagLow, Nat_TestFlagHigh - from t_orderdetail - join t_test on T_OrderDetailT_TestID = T_TestID - join nat_test on T_TestNat_TestID = Nat_TestID and T_TestIsActive = 'Y' - where T_OrderDetailID = ? "; - - $ids = []; - foreach ($data as $k => $v) - { - if ( $v->resultInstrumentID > 0 ) { - $sql_i = "select T_ResultInstrumentNat_NormalValueID normalValueID - from t_resultinstrument - where T_ResultInstrumentID = ?"; - $qry_i = $this->db_smartone->query($sql_i, array($v->resultInstrumentID)); - if ($qry_i) { - $rows_i = $qry_i->result_array(); - - if (count($rows_i) > 0 ) { - $sql_iu = "update t_orderdetail, nat_normalvalue , nat_methode - set T_OrderDetailMinValue = Nat_NormalValueMinValue, - T_OrderDetailMinValueInclusive = Nat_NormalValueMinValueInclusive, - T_OrderDetailMaxValue = Nat_NormalValueMaxValue , - T_OrderDetailMaxValueInclusive = Nat_NormalValueMaxValueInclusive, - T_OrderDetailNormalValueNote = Nat_NormalValueNote, - T_OrderDetailNormalValueDescription = Nat_NormalValueDescription, - T_OrderDetailNat_NormalValueID = Nat_NormalValueID, - T_OrderDetailNat_MethodeID = Nat_NormalValueNat_MethodeID, - T_OrderDetailNat_MethodeName = Nat_MethodeName - where T_OrderDetailID = ? and Nat_NormalValueID = ? - and Nat_NormalValueNat_MethodeID = Nat_MethodeID - "; - $this->db_smartone->query($sql_iu, array($v->id, $rows_i[0]["normalValueID"])); - //file_put_contents("/xtmp/update-nilai-normal", $this->db_smartone->last_query() . "\n", FILE_APPEND); - } - } - } - $y = $this->db_smartone->query("SELECT fn_process_sample_handling_perfect('{$v->order_id}', '{$v->test_id}') c") - ->row(); - $req_status = $y->c; - $qry_norm = $this->db_smartone->query($sql_norm,$v->id); - $result_flag = ""; - if ($qry_norm) { - $rows_norm = $qry_norm->result_array(); - if (count($rows_norm) > 0 ) { - $r = $rows_norm[0]; - if (is_numeric($v->result)) { - - if ( $r["T_OrderDetailMinValueInclusive"] == "Y" && $v->result < $r["T_OrderDetailMinValue"] ) { - $result_flag = $r["Nat_TestFlagLow"]; - } - if ( $r["T_OrderDetailMinValueInclusive"] == "N" && $v->result <= $r["T_OrderDetailMinValue"] ) { - $result_flag = $r["Nat_TestFlagLow"]; - } - if ( $r["T_OrderDetailMaxValueInclusive"] == "Y" && $v->result > $r["T_OrderDetailMaxValue"] ) { - $result_flag = $r["Nat_TestFlagHigh"]; - } - if ( $r["T_OrderDetailMaxValueInclusive"] == "N" && $v->result >= $r["T_OrderDetailMaxValue"] ) { - $result_flag = $r["Nat_TestFlagHigh"]; - } - } - } - } - if ($lang == $this->lang_default_code) - { - $this->db_smartone->set('T_OrderDetailResult', $v->result) - ->set('T_OrderDetailResultFlag', $result_flag) - ->set('T_OrderDetailNote', $v->note) - ->set('T_OrderDetailReqStatus', $req_status) - ->where('T_OrderDetailID', $v->id) - ->update('t_orderdetail'); - } - else - { - $this->db_smartone->set('T_OrderDetailLangResult', $v->result) - ->set('T_OrderDetailLangNote', $v->note) - ->where('T_OrderDetailLangID', $v->id) - ->update('t_orderdetaillang'); - } - - $ids[] = $v->id; - } - - // LOG Process - $order = $this->db_smartone->select('T_OrderDetailT_OrderHeaderID id, T_OrderHeaderLabNumber lab_number', false) - ->join('t_orderheader', 'T_OrderHeaderID = T_OrderDetailT_OrderHeaderID') - ->where('T_OrderDetailID', $data[0]->id) - ->get('t_orderdetail') - ->row(); - - $dblog = $this->load->database("onelog", true); - $dblog->set('Log_ProcessCode', 'PROCESS.Result.Entry') - ->set('Log_ProcessOrderID', $order->id) - ->set('Log_ProcessOrderNumber', $order->lab_number) - ->set('Log_ProcessJson', json_encode($data)) - ->set('Log_ProcessUserID', $this->sys_user['M_UserID']) - ->insert('log_process'); - // END OF Log Process - //auto calculation - $this->load->library("Resultcalc"); - $rows = $this->resultcalc->auto($order->id); - - try { - foreach($ids as $id ) { - $this->db_smartone->query("call sp_set_normal_value_flag($id)"); - $this->clean_mysqli_connection($this->db_smartone->conn_id); - } - } catch(Exception $e) { - } - - $this->sys_ok($ids); - } - - public function save_template() - { - $prm = $this->sys_input; - - $n = $this->db_smartone->select("COUNT(T_ResultTemplateID) n") - ->where("T_ResultTemplateT_TestID", $prm['test_id']) - ->where("T_ResultTemplateIsActive", "Y") - ->where("T_ResultTemplateValue", $prm['value']) - ->get('t_resulttemplate') - ->row(); - if ($n->n > 0) - { - $this->sys_error_db("Insert Result Template", $this->db_smartone); - return; - } - - $r = $this->db_smartone->set("T_ResultTemplateT_TestID", $prm['test_id']) - ->set("T_ResultTemplateValue", $prm['value']) - ->insert('t_resulttemplate'); - if ($r) - { - $template = []; - $x = $this->db_smartone->query("CALL sp_master_resulttemplate_get('{$prm['test_id']}')"); - $this->clean_mysqli_connection($this->db_smartone->conn_id); - if ($x) - $template = $x->result_array(); - - $this->sys_ok($template); - } - } - - public function export() - { - $prm = $this->sys_input; - - $sql = "CALL sp_process_result_lang(?, ?, ?, ?)"; - $query = $this->db_smartone->query($sql, [$prm['order_id'], $prm['lang_id'], $prm['is_si'], $this->sys_user['M_UserID']]); - if ($query) - { - $r = $query->row(); - if ($r->status == "OK") - { - $this->sys_ok($r->data); - return; - } - - $this->sys_error_db("Message : " . $r->message, $this->db_smartone); - } - else - { - $this->sys_error_db("Lang Result", $this->db_smartone); - return; - } - } - - public function search_group() - { - $prm = $this->sys_input; - $max_rst = 100; - - // QUERY TOTAL - $sql = "select count(*) total - from t_worklist - where T_WorklistIsActive = 'Y' - order by T_WorklistName ASC"; - $query = $this->db_smartone->query($sql); - - if ($query) { - $tot_count = $query->result_array()[0]["total"]; - } - else { - $this->sys_error_db("worklist count", $this->db_smartone); - exit; - } - - $sql = "select T_WorklistID group_id, T_WorklistName group_name - from t_worklist - where T_WorklistIsActive = 'Y' - order by T_WorklistName ASC - limit 0, {$max_rst}"; - $query = $this->db_smartone->query($sql); - - if ($query) { - $rows = $query->result_array(); - foreach ($rows as $k => $v) - $rows[$k]['data'] = json_decode($v['data']); - $result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows), "q" => $this->db_smartone->last_query()); - $this->sys_ok($result); - } - else { - $this->sys_error_db("worklist rows", $this->db_smartone); - exit; - } - } - - public function search_rerun() - { - $prm = $this->sys_input; - $id = $prm["detail_id"]; - - $sql = "CALL sp_process_result_rerun(?)"; - $query = $this->db_smartone->query($sql, [$id]); - - if ($query) - { - $rows = $query->result_array(); - $this->sys_ok(["records"=>$rows]); - } - else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - - - function getdoctorsfna() - { - $prm = $this->sys_input; - // $id = $prm["id"]; - - $sql = " SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY M_DoctorName ASC"; - //echo $sql; - $query = $this->db_smartone->query($sql); - - if ($query) - { - $rows = $query->result_array(); - $this->sys_ok(["records"=>$rows]); - } - else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - function getfnaresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT Other_FNADetailsID as xid, - Other_FNAT_OrderDetailID as orderdetail_id, - Other_FNADetailsCode as code, - Other_FNADetailsLabel as label, - Other_FNADetailsResult as result, - IFNULL(Other_FNAM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_FNAM_DoctorID) OR Other_FNAM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_fna - JOIN other_fnadetails ON Other_FNADetailsOther_FNAID = Other_FNAID AND Other_FNADetailsIsActive = 'Y' - LEFT JOIN m_doctor ON Other_FNAM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_FNAT_OrderDetailID = {$id} AND Other_FNAIsActive = 'Y' - GROUP BY Other_FNADetailsID - ORDER BY Other_FNADetailsCode ASC"; - $query = $this->db_smartone->query($sql); - - if ($query) - { - $rows = $query->result_array(); - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $images = array(); - $sql = "SELECT So_ImageUploadID as xid, - CONCAT('/one-media/one-image-nonlab/',So_ImageUploadNewName) as image_url - FROM t_orderdetail - JOIN so_imageupload ON So_ImageUploadT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND - So_ImageUploadIsActive = 'Y' - WHERE - T_OrderDetailID = {$id} AND - T_OrderDetailIsActive = 'Y' - GROUP BY So_ImageUploadID"; - $images = $this->db_smartone->query($sql)->result_array(); - - $rst = array('doctors'=>$doctors,'results'=>$rows,'images'=>$images); - $this->sys_ok(["records"=>$rst]); - } - else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - - function uploadimage(){ - if (! $this->isLogin) { - $this->sys_error("Invalid Token"); - exit; - } - - $userid = $this->sys_user["M_UserID"]; - $data = []; - //print_r($_SERVER); - - $prm = $this->sys_input; - $orderid = $this->input->post('orderid'); - $labnumber = $this->input->post('labnumber'); - $sql = "UPDATE so_imageupload SET - So_ImageUploadIsActive = 'N', - So_ImageUploadUserID = {$userid} - WHERE - So_ImageUploadT_OrderHeaderID = {$orderid}"; - //echo $sql; - $this->db_onedev->query($sql); - //$config['upload_path'] = 'assets/'; - - $path = '/home/one/project/one/one-media/one-image-nonlab/'; - //echo $path; - $config['upload_path'] = $path; - $config['allowed_types'] = 'jpg|jpeg|png|gif'; - - $config['max_size'] = '10000'; - $count = count($_FILES['files']['name']); - //echo $count; - $this->load->library('upload',$config); - - $error = []; - for($i=0;$i<$count;$i++){ - - - if(!empty($_FILES['files']['name'][$i])){ - - - - $_FILES['file']['name'] = $_FILES['files']['name'][$i]; - - $_FILES['file']['type'] = $_FILES['files']['type'][$i]; - - $_FILES['file']['tmp_name'] = $_FILES['files']['tmp_name'][$i]; - - $_FILES['file']['error'] = $_FILES['files']['error'][$i]; - - $_FILES['file']['size'] = $_FILES['files']['size'][$i]; - - - - $namex = $orderid.'-'.$labnumber.'-'.$this->generateRandomString(5); - //echo $namex; - - $config['file_name'] = $namex; - $this->upload->initialize($config); - //echo $config['file_name'] ; - - - - - - if($this->upload->do_upload('file')){ - - $uploadData = $this->upload->data(); - - $filename = $uploadData['file_name']; - //echo $filename; - - - $sql = "INSERT INTO so_imageupload ( - So_ImageUploadT_OrderHeaderID, - So_ImageUploadT_OrderHeaderLabNumber, - So_ImageUploadT_SampleTypeID, - So_ImageUploadOldName, - So_ImageUploadNewName, - So_ImageUploadCreated, - So_ImageUploadUserID - ) - VALUES( - {$orderid}, - '{$labnumber}', - '150', - '{$_FILES['files']['name'][$i]}', - '{$filename}', - NOW(), - {$userid} - - )"; - //echo $sql; - $this->db_onedev->query($sql); - $xlast_id = $this->db_onedev->insert_id(); - $data['totalFiles'][] = array('xid' => $xlast_id ,'image_url' => '/one-media/one-image-nonlab/'.$filename); - - } - else{ - $error = array('error' => $this->upload->display_errors()); - } - - } - - - - } - - $result = array("total" =>count( $data['totalFiles']), "records" => $data['totalFiles'],'errors'=>$error); - $this->sys_ok($result); - } - - - function generateRandomString($length = 10) { - $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; - $charactersLength = strlen($characters); - $randomString = ''; - for ($i = 0; $i < $length; $i++) { - $randomString .= $characters[rand(0, $charactersLength - 1)]; - } - return $randomString; - } - - function getcytologiresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT Other_CytologiDetailsID as xid, - Other_CytologiT_OrderDetailID as orderdetail_id, - Other_CytologiDetailsCode as code, - Other_CytologiDetailsLabel as label, - Other_CytologiDetailsResult as result, - IFNULL(Other_CytologiM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_CytologiM_DoctorID) OR Other_CytologiM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_cytologi - JOIN other_cytologidetails ON Other_CytologiDetailsOther_CytologiID = Other_CytologiID AND Other_CytologiDetailsIsActive = 'Y' - LEFT JOIN m_doctor ON Other_CytologiM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_CytologiT_OrderDetailID = {$id} AND Other_CytologiIsActive = 'Y' - GROUP BY Other_CytologiDetailsID - ORDER BY Other_CytologiDetailsCode ASC"; - //echo $sql; - $query = $this->db_smartone->query($sql); - - if ($query) - { - $rows = $query->result_array(); - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $rst = array('doctors'=>$doctors,'results'=>$rows); - $this->sys_ok(["records"=>$rst]); - } - else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - function getmikroresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT - Other_MikroID as xid, - Other_MikroHasilBiakan as hasil_biakan, - Other_MikroSampleTypeName as sample_name, - Other_MikroT_OrderDetailID as orderdetail_id, - Other_MikroResult as result_value, - '' as result_other, - IFNULL(T_BacteriaID,0) as T_BacteriaID, - IFNULL(T_BacteriaName,'') as T_BacteriaName, - '' as details, - IFNULL(Other_MikroM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_MikroM_DoctorID) OR Other_MikroM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_mikro - LEFT JOIN t_bacteria ON Other_MikroT_BacteriaID = T_BacteriaID - LEFT JOIN m_doctor ON Other_MikroM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_MikroT_OrderDetailID = {$id} AND Other_MikroIsActive = 'Y' - GROUP BY Other_MikroID"; - //echo $sql; - $query = $this->db_smartone->query($sql); - - if ($query) - { - $row = $query->row_array(); - if($row){ - if($row['result_value'] != 'Positif' && $row['result_value'] != 'Negatif'){ - $row['result_other'] = $row['result_value']; - $row['result_value'] = 'other'; - } - $sql = "SELECT '' as xno, - Other_MikroDetailsID as xid, - Other_MikroDetailsValue as value, - IF(Other_MikroDetailsNote = 'R','Y','N') as chx_r, - IF(Other_MikroDetailsNote = 'I','Y','N') as chx_i, - IF(Other_MikroDetailsNote = 'S','Y','N') as chx_s, - Other_MikroDetailsNote as note, - t_antibiotic.* - FROM other_mikrodetails - LEFT JOIN t_antibiotic ON Other_MikroDetailsT_AntibioticID = T_AntibioticID - WHERE - Other_MikroDetailsOther_MikroID = {$row['xid']} AND Other_MikroDetailsIsActive = 'Y' - GROUP BY Other_MikroDetailsID - ORDER BY T_AntibioticName ASC"; - //echo $sql; - $details = $this->db_smartone->query($sql)->result_array(); - if($details){ - foreach($details as $k => $v){ - $details[$k]['xno'] = $k + 1; - } - } - $row['details'] = $details; - } - else{ - $row = array('xid'=>'0','hasil_biakan' => '','result_value'=>'Negatif','sample_name' => '','orderdetail_id'=>$id, 'T_BacteriaID'=>'0','T_BacteriaName'=>'0','details'=>array(),'doctor_id'=>'0','doctor_name'=>'0'); - } - } - else{ - $row = array('xid'=>'0','hasil_biakan' => '','result_value'=>'Negatif','sample_name' => '','orderdetail_id'=>$id, 'T_BacteriaID'=>'0','T_BacteriaName'=>'0','details'=>array(),'doctor_id'=>'0','doctor_name'=>'0'); - } - //print_r($row); - - - - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 7 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $sql = " - SELECT '0' as id, 'Belum memilih bakteria' as name - UNION - SELECT T_BacteriaID as id, T_BacteriaName as name - FROM t_bacteria - WHERE - T_BacteriaIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $bacteries = $this->db_smartone->query($sql)->result_array(); - $rst = array('doctors'=>$doctors,'bacteries'=>$bacteries,'results'=>$row); - $this->sys_ok(["records"=>$rst]); - } - function getantibiotics(){ - $prm = $this->sys_input; - $id = $prm["id"]; - $sql = " SELECT '' as xno, - 0 as xid, - '' as hasil_biakan, - '' as sample_name, - 0 as value, - 'Y' as chx_r, - 'N' as chx_i, - 'N' as chx_s, - 'R' as note, - t_antibiotic.* - FROM t_antibiotic - WHERE - T_AntibioticT_BacteriaID = {$prm['id']} AND T_AntibioticIsActive= 'Y' - ORDER BY T_AntibioticName ASC"; - //echo $sql; - $rows = $this->db_smartone->query($sql)->result_array(); - if(rows){ - foreach($rows as $k => $v){ - $rows[$k]['xno'] = $k + 1; - } - } - - $this->sys_ok(["records"=>$rows]); - } - function getlcprepresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - $sql = " SELECT Other_LcprepDetailsID as xid, - Other_LcprepID as header_id, - Other_LcprepT_orderDetailID as orderdetail_id, - Other_LcprepDetailsCode as code, - Other_LcprepDetailsLabel as label, - Other_LcprepDetailsResult as result, - IFNULL(Other_LcprepM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_LcprepM_DoctorID) OR Other_LcprepM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_lcprep - JOIN other_lcprepdetails ON Other_LcprepDetailsOther_LcprepID = Other_LcprepID AND Other_LcprepDetailsIsActive = 'Y' - LEFT JOIN m_doctor ON Other_LcprepM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_LcprepT_orderDetailID = {$id} AND Other_LcprepIsActive = 'Y' - GROUP BY Other_LcprepDetailsOther_LcprepID, Other_LcprepDetailsCode - ORDER BY Other_LcprepDetailsCode ASC"; - //echo $sql; - $rows = $this->db_smartone->query($sql)->result_array(); - if(!$rows){ - $rows = array( - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'A', - 'label' => 'DESKRIPSI', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ), - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'B', - 'label' => 'KESIMPULAN', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ) - ); - } - - $header_id = $rows[0]['header_id']; - $sql = "SELECT IFNULL(Other_LcprepAdekuasiID,0) as xid, - Lcprep_AdekuasiID as id, - Lcprep_AdekuasiLabel as name, - IF(ISNULL(Other_LcprepAdekuasiID),'N',Other_LcprepAdekuasiChex) as chex - FROM lcprep_adekuasi - LEFT JOIN other_lcprepadekuasi ON Other_LcprepAdekuasiLcprep_AdekuasiID = Lcprep_AdekuasiID AND - Other_LcprepAdekuasiOther_LcprepID = {$header_id} AND - Other_LcprepAdekuasiIsActive = 'Y' - WHERE - Lcprep_AdekuasiIsActive = 'Y' - GROUP BY Lcprep_AdekuasiID - ORDER BY Lcprep_AdekuasiOrder ASC - "; - //echo $sql; - $adeakuasi = $this->db_smartone->query($sql)->result_array(); - foreach($adeakuasi as $kc => $vc){ - $adeakuasi[$kc]['chex'] = $vc['chex'] == 'N'?false:true; - } - - $sql = "SELECT IFNULL(Other_LcprepKategoriUmumID,0) as xid, - Lcprep_KategoriUmumID as id, - Lcprep_KategoriUmumLabel as name, - IF(ISNULL(Other_LcprepKategoriUmumID),'N',Other_LcprepKategoriUmumChex) as chex - FROM lcprep_kategoriumum - LEFT JOIN other_lcprepkategoriumum ON Other_LcprepKategoriUmumLcprep_KategoriUmumID = Lcprep_KategoriUmumID AND - Other_LcprepKategoriUmumOther_LcprepID = {$header_id} AND - Other_LcprepKategoriUmumIsActive = 'Y' - WHERE - Lcprep_KategoriUmumIsActive = 'Y' - GROUP BY Lcprep_KategoriUmumID - "; - //echo $sql; - $kategoriumum = $this->db_smartone->query($sql)->result_array(); - foreach($kategoriumum as $kc => $vc){ - $kategoriumum[$kc]['chex'] = $vc['chex'] == 'N'?false:true; - } - - $sql = " - SELECT Lcprep_InterpretasiGroupID as group_id, - Lcprep_InterpretasiGroupName as group_name, - '' as subgroups - FROM lcprep_interpretasigroup - WHERE - Lcprep_InterpretasiGroupIsActive = 'Y' - "; - //echo $sql; - $interpretasi = $this->db_smartone->query($sql)->result_array(); - foreach($interpretasi as $k => $v){ - $subgroups = array(); - $sql = "SELECT Lcprep_InterpretasiSubgroupID as subgroup_id, - Lcprep_InterpretasiSubgroupName as subgroup_name, - '' as childs - FROM lcprep_interpretasisubgroup - WHERE - Lcprep_InterpretasiSubgroupLcprep_InterpretasiGroupID = {$v['group_id']} AND Lcprep_InterpretasiSubgroupIsActive = 'Y'"; - //echo $sql; - $subgroups = $this->db_smartone->query($sql)->result_array(); - if(count($subgroups) > 0){ - foreach($subgroups as $ki => $vi){ - $childs = array(); - $sql = "SELECT IFNULL(Other_LcprepInterpretasiID,0) as xid, - IFNULL(Other_LcprepInterpretasiChex,'N') as chex, - IFNULL(Other_LcprepInterpretasiValue,'') as value, - Lcprep_InterpretasiID as id, - Lcprep_InterpretasiLcprep_InterpretasiSubgroupID as subgroup_id, - Lcprep_InterpretasiCode as code, - Lcprep_InterpretasiName as name, - Lcprep_InterpretasiParentID as parent_id, - Lcprep_InterpretasiIsParent as is_parent, - Lcprep_InterpretasiHasResult as has_result, - Lcprep_InterpretasiTypeResult as type_result - FROM lcprep_interpretasi - LEFT JOIN other_lcprepinterpretasi ON Other_LcprepInterpretasiOther_LcprepID = {$header_id} AND - Other_LcprepInterpretasiLcprep_InterpretasiID = Lcprep_InterpretasiID AND - Other_LcprepInterpretasiIsActive = 'Y' - WHERE - Lcprep_InterpretasiLcprep_InterpretasiSubgroupID = {$vi['subgroup_id']} AND Lcprep_InterpretasiIsActive = 'Y' - GROUP BY Lcprep_InterpretasiID Order BY Lcprep_InterpretasiCode ASC"; - $childs = $this->db_smartone->query($sql)->result_array(); - if($childs){ - foreach($childs as $kc => $vc){ - $childs[$kc]['chex'] = $vc['chex'] == 'N'?false:true; - } - } - $subgroups[$ki]['childs'] = $childs; - } - } - - $interpretasi[$k]['subgroups'] = $subgroups; - } - - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $rst = array('doctors'=>$doctors,'results'=>$rows,'adekuasi'=>$adeakuasi,'kategoriumum'=>$kategoriumum,'interpretasi'=>$interpretasi); - $this->sys_ok(["records"=>$rst]); - } - - function getpapsmearresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT Other_PapSmearDetailsID as xid, - Other_PapSmearID as header_id, - Other_PapSmearT_OrderDetailID as orderdetail_id, - Other_PapSmearDetailsCode as code, - Other_PapSmearDetailsLabel as label, - Other_PapSmearDetailsResult as result, - IFNULL(Other_PapSmearM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_PapSmearM_DoctorID) OR Other_PapSmearM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_papsmear - JOIN other_papsmeardetails ON Other_PapSmearDetailsOther_PapSmearID = Other_PapSmearID AND Other_PapSmearDetailsIsActive = 'Y' - LEFT JOIN m_doctor ON Other_PapSmearM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_PapSmearT_OrderDetailID = {$id} AND Other_PapSmearIsActive = 'Y' - GROUP BY Other_PapSmearDetailsID - ORDER BY Other_PapSmearDetailsCode ASC"; - //echo $sql; - $rows = $this->db_smartone->query($sql)->result_array(); - if(!$rows){ - $rows = array( - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'A', - 'label' => 'Makroskopik', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ), - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'B', - 'label' => 'Mikroskopik', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ), - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'C', - 'label' => 'Kesimpulan', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ) - ); - } - - $header_id = $rows[0]['header_id']; - $sql = "SELECT Other_PapSmearMaturasiID as xid, - Other_PapSmearMaturasiValue as value - FROM other_papsmearmaturasi - WHERE - Other_PapSmearMaturasiOther_PapSmearID = {$header_id} AND - Other_PapSmearMaturasiIsActive = 'Y' - "; - //echo $sql; - $dt_maturasi = $this->db_smartone->query($sql)->row_array(); - if(!$dt_maturasi){ - $maturasi = array('xid'=>'0','value'=> array('','','')); - } - else{ - $value = explode('/',$dt_maturasi['value']); - $maturasi = array('xid'=>$dt_maturasi['xid'],'value'=> $value); - } - - $sql = "SELECT IFNULL(Other_PapSmearBahanID,0) as xid, - M_PapSmearBahanID as bahan_id, - M_PapSmearBahanName as name, - IF(ISNULL(Other_PapSmearBahanID),'N','Y') as selected - FROM m_papsmearbahan - LEFT JOIN other_papsmearbahan ON Other_PapSmearBahanM_PapSmearBahanID = M_PapSmearBahanID AND - Other_PapSmearBahanOther_PapSmearID = {$header_id} AND - Other_PapSmearBahanIsActive = 'Y' - WHERE - M_PapSmearBahanIsActive = 'Y' - ORDER BY M_PapSmearBahanID ASC - "; - //echo $sql; - $bahans = $this->db_smartone->query($sql)->result_array(); - - $sql = "SELECT IFNULL(Other_PapsmearCategoryID,0) as xid, - M_PapSmearCategoryID as category_id, - M_PapSmearCategoryName as name, - IF(ISNULL(Other_PapsmearCategoryID),'N','Y') as selected - FROM m_papsmearcategory - LEFT JOIN other_papsmearcategory ON Other_PapsmearCategoryM_PapSmearCategoryID = M_PapSmearCategoryID AND - Other_PapsmearCategoryOther_PapSmearID = {$header_id} AND - Other_PapsmearCategoryIsActive = 'Y' - WHERE - M_PapSmearCategoryIsActive = 'Y' - ORDER BY M_PapSmearCategoryID ASC - "; - //echo $sql; - $categories = $this->db_smartone->query($sql)->result_array(); - - $sql = "SELECT IFNULL(Other_PapSmearCheckID,0) as xid, - M_PapSmearCheckID as check_id, - M_PapSmearCheckLabel as name, - IF(ISNULL(Other_PapSmearCheckID),'N','Y') as selected, - Other_PapSmearCheckNote as note - FROM m_papsmearcheck - LEFT JOIN other_papsmearcheck ON Other_PapSmearCheckM_PapSmearCheckID = M_PapSmearCheckID AND - Other_PapSmearCheckOther_PapSmearID = {$header_id} AND - Other_PapSmearCheckIsActive = 'Y' - WHERE - M_PapSmearCheckIsActive = 'Y' - ORDER BY M_PapSmearCheckCode ASC - "; - $checks = $this->db_smartone->query($sql)->result_array(); - - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $rst = array('doctors'=>$doctors,'checks'=>$checks,'bahans'=>$bahans,'categories'=>$categories,'maturasi'=>$maturasi,'results'=>$rows); - $this->sys_ok(["records"=>$rst]); - - } - - function saveresult_lcprep() - { - $prm = $this->sys_input; - $detail_id = $prm['detail_id']; - $doctor_id = $prm['doctor']; - $adekuasi = $prm['adekuasi']; - $kategoriumum = $prm['kategoriumum']; - $interpretasi = $prm['interpretasi']; - $results = $prm['results']; - - $userid = $this->sys_user['M_UserID']; - - $header_id = 0; - $sql = "SELECT * FROM other_lcprep WHERE Other_LcprepT_orderDetailID = {$detail_id} AND Other_LcprepIsActive = 'Y'"; - $dt_header = $this->db_smartone->query($sql)->row_array(); - if($dt_header){ - $header_id = $dt_header['Other_LcprepID']; - } - if($header_id == 0){ - $sql = "INSERT INTO other_lcprep( - Other_LcprepT_orderDetailID, - Other_LcprepM_DoctorID, - Other_LcprepUserID, - Other_LcprepCreated - ) - VALUES( - {$detail_id}, - {$doctor_id}, - {$userid}, - NOW() - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - }else{ - $sql = "UPDATE other_lcprep SET Other_LcprepM_DoctorID = {$doctor_id}, Other_LcprepUserID = {$userid} WHERE Other_LcprepID = {$header_id}"; - $this->db_smartone->query($sql); - } - - if($adekuasi){ - foreach($adekuasi as $k =>$v){ - $selected = $v['chex']?'Y':'N'; - if(intval($v['xid'] == 0)){ - $sql = "UPDATE other_lcprepadekuasi SET Other_LcprepAdekuasiIsActive = 'N' - WHERE - Other_LcprepAdekuasiOther_LcprepID = {$header_id} AND - Other_LcprepAdekuasiIsActive = 'Y' AND - Other_LcprepAdekuasiLcprep_AdekuasiID = {$v['id']}"; - $this->db_smartone->query($sql); - $sql = "INSERT INTO other_lcprepadekuasi ( - Other_LcprepAdekuasiOther_LcprepID, - Other_LcprepAdekuasiLcprep_AdekuasiID, - Other_LcprepAdekuasiChex, - Other_LcprepAdekuasiUserID, - Other_LcprepAdekuasiCreated - ) - VALUES( - {$header_id}, - {$v['id']}, - '{$selected}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - //echo $sql; - } - if(intval($v['xid'] != 0)){ - - $sql = "UPDATE other_lcprepadekuasi SET - Other_LcprepAdekuasiChex = '{$selected}', - Other_LcprepAdekuasiUserID = {$userid} - WHERE - Other_LcprepAdekuasiID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - - //echo $sql; - } - } - - if($kategoriumum){ - foreach($kategoriumum as $k =>$v){ - $selected = $v['chex']?'Y':'N'; - if(intval($v['xid'] == 0)){ - $sql = "UPDATE other_lcprepkategoriumum SET Other_LcprepKategoriUmumIsActive = 'N' - WHERE - Other_LcprepKategoriUmumOther_LcprepID = {$header_id} AND - Other_LcprepKategoriUmumLcprep_KategoriUmumID = {$v['id']} AND - Other_LcprepKategoriUmumIsActive = 'Y' - "; - $this->db_smartone->query($sql); - $sql = "INSERT INTO other_lcprepkategoriumum ( - Other_LcprepKategoriUmumOther_LcprepID, - Other_LcprepKategoriUmumLcprep_KategoriUmumID, - Other_LcprepKategoriUmumChex, - Other_LcprepKategoriUmumUserID, - Other_LcprepKategoriUmumCreated - ) - VALUES( - {$header_id}, - {$v['id']}, - '{$selected}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if(intval($v['xid'] != 0)){ - $sql = "UPDATE other_lcprepkategoriumum SET - Other_LcprepKategoriUmumChex = '{$selected }', - Other_LcprepKategoriUmumUserID = {$userid} - WHERE - Other_LcprepKategoriUmumID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - - //echo $sql; - } - } - - if($results){ - foreach($results as $k =>$v){ - if(intval($v['xid'] == 0)){ - $sql = "UPDATE other_lcprepdetails SET Other_LcprepDetailsIsActive = 'N' - WHERE - Other_LcprepDetailsOther_LcprepID = {$header_id} AND - Other_LcprepDetailsCode = '{$v['code']}' AND - Other_LcprepDetailsIsActive = 'Y'"; - $this->db_smartone->query($sql); - $sql = "INSERT INTO other_lcprepdetails ( - Other_LcprepDetailsOther_LcprepID, - Other_LcprepDetailsCode, - Other_LcprepDetailsLabel, - Other_LcprepDetailsResult, - Other_LcprepDetailsUserID, - Other_LcprepDetailsCreated - ) - VALUES( - {$header_id}, - '{$v['code']}', - '{$v['label']}', - '{$v['result']}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if(intval($v['xid'] != 0)){ - $sql = "UPDATE other_lcprepdetails SET - Other_LcprepDetailsCode = '{$v['code']}', - Other_LcprepDetailsLabel = '{$v['label']}', - Other_LcprepDetailsResult = '{$v['result']}', - Other_LcprepDetailsUserID = {$userid} - WHERE - Other_LcprepDetailsID = {$v['xid']}"; - $this->db_smartone->query($sql); - - } - //echo $sql; - } - } - - if($interpretasi){ - foreach($interpretasi as $k =>$v){ - if(count($v['subgroups']) > 0){ - foreach($v['subgroups'] as $ik => $iv){ - if(count($iv['childs']) > 0){ - foreach($iv['childs'] as $iik => $iiv){ - if(intval($iiv['xid'] == 0)){ - $chex = $iiv['chex'] ? 'Y':'N'; - $sql = "UPDATE other_lcprepinterpretasi SET Other_LcprepInterpretasiIsActive = 'N' - WHERE - Other_LcprepInterpretasiOther_LcprepID = {$header_id} AND - Other_LcprepInterpretasiLcprep_InterpretasiID = '{$iiv['id']}' AND - Other_LcprepInterpretasiIsActive = 'Y'"; - $this->db_smartone->query($sql); - $sql = "INSERT INTO other_lcprepinterpretasi ( - Other_LcprepInterpretasiOther_LcprepID, - Other_LcprepInterpretasiLcprep_InterpretasiID, - Other_LcprepInterpretasiChex, - Other_LcprepInterpretasiValue, - Other_LcprepInterpretasiUserID, - Other_LcprepInterpretasiCreated - ) - VALUES( - {$header_id}, - '{$iiv['id']}', - '{$chex}', - '{$iiv['value']}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - - if(intval($iiv['xid'] != 0)){ - $chex = $iiv['chex'] ? 'Y':'N'; - $sql = "UPDATE other_lcprepinterpretasi SET - Other_LcprepInterpretasiChex = '{$chex}', - Other_LcprepInterpretasiValue = '{$iiv['value']}', - Other_LcprepInterpretasiUserID = {$userid} - WHERE - Other_LcprepInterpretasiID = {$iiv['xid']}"; - $this->db_smartone->query($sql); - //echo $sql; - - } - - } - } - } - } - //echo $sql; - } - } - - - $result = array("total" => 1, "records" => array(), "sql"=> ''); - $this->sys_ok($result); - exit; - } - - function saveresult_papsmear() - { - $prm = $this->sys_input; - $detail_id = $prm['detail_id']; - $doctor_id = $prm['doctor']; - $checks = $prm['checks']; - $maturasi = $prm['maturasi']; - $bahans = $prm['bahans']; - $categories = $prm['categories']; - $results = $prm['results']; - - $userid = $this->sys_user['M_UserID']; - - $header_id = 0; - $sql = "SELECT * FROM other_papsmear WHERE Other_PapSmearT_OrderDetailID = {$detail_id} AND Other_PapSmearIsActive = 'Y'"; - $dt_header = $this->db_smartone->query($sql)->row_array(); - if($dt_header){ - $header_id = $dt_header['Other_PapSmearID']; - } - if($header_id == 0){ - $sql = "INSERT INTO other_papsmear( - Other_PapSmearT_OrderDetailID, - Other_PapSmearM_DoctorID, - Other_PapSmearUserID, - Other_PapSmearCreated - ) - VALUES( - {$detail_id}, - {$doctor_id}, - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } - else{ - $sql = "UPDATE other_papsmear SET Other_PapSmearM_DoctorID = {$doctor_id}, Other_PapSmearUserID = {$userid} WHERE Other_PapSmearID = {$header_id}"; - $this->db_smartone->query($sql); - } - - if($checks){ - foreach($checks as $k =>$v){ - if(intval($v['xid']) == 0 && $v['selected'] === 'Y'){ - $sql = "INSERT INTO other_papsmearcheck ( - Other_PapSmearCheckOther_PapSmearID, - Other_PapSmearCheckM_PapSmearCheckID, - Other_PapSmearCheckNote, - Other_PapSmearCheckUserID, - Other_PapSmearCheckCreated - ) - VALUES( - {$header_id}, - {$v['check_id']}, - '{$v['note']}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if(intval($v['xid']) != 0 && $v['selected'] === 'N'){ - $sql = "UPDATE other_papsmearcheck SET - Other_PapSmearCheckIsActive = 'N', - Other_PapSmearCheckUserID = {$userid} - WHERE - Other_PapSmearCheckID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - if(intval($v['xid']) != 0 && $v['selected'] === 'Y'){ - $sql = "UPDATE other_papsmearcheck SET - Other_PapSmearCheckNote = '{$v['note']}', - Other_PapSmearCheckUserID = {$userid} - WHERE - Other_PapSmearCheckID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - //echo $sql; - } - } - - if($maturasi){ - if(intval($maturasi['xid']) == 0){ - $value = join("/",$maturasi['value']); - $sql = "INSERT INTO other_papsmearmaturasi ( - Other_PapSmearMaturasiOther_PapSmearID, - Other_PapSmearMaturasiValue, - Other_PapSmearMaturasiUserID, - Other_PapSmearMaturasiCreated - ) - VALUE( - {$header_id}, - '{$value}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - //echo $sql; - } - if(intval($maturasi['xid']) != 0){ - $value = join("/",$maturasi['value']); - $sql = "UPDATE other_papsmearmaturasi SET - Other_PapSmearMaturasiValue = '{$value}', - Other_PapSmearMaturasiUserID = {$userid} - WHERE - Other_PapSmearMaturasiID = {$maturasi['xid']}"; - // echo $sql; - $this->db_smartone->query($sql); - } - } - - if($bahans){ - foreach($bahans as $k =>$v){ - if(intval($v['xid']) == 0 && $v['selected'] === 'Y'){ - $sql = "INSERT INTO other_papsmearbahan ( - Other_PapSmearBahanOther_PapSmearID, - Other_PapSmearBahanM_PapSmearBahanID, - Other_PapSmearBahanUserID, - Other_PapSmearBahanCreated - ) - VALUES( - {$header_id}, - {$v['bahan_id']}, - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if(intval($v['xid']) != 0 && $v['selected'] === 'N'){ - $sql = "UPDATE other_papsmearbahan SET - Other_PapSmearBahanIsActive = 'N', - Other_PapsmearCategoryUserID = {$userid} - WHERE - Other_PapSmearBahanID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - if(intval($v['xid']) != 0 && $v['selected'] === 'Y'){ - $sql = "UPDATE other_papsmearbahan SET - Other_PapSmearBahanIsActive = 'Y', - Other_PapsmearCategoryUserID = {$userid} - WHERE - Other_PapSmearBahanID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - //echo $sql; - } - } - - if($categories){ - foreach($categories as $k =>$v){ - if(intval($v['xid']) == 0 && $v['selected'] === 'Y'){ - $sql = "INSERT INTO other_papsmearcategory ( - Other_PapsmearCategoryOther_PapSmearID, - Other_PapsmearCategoryM_PapSmearCategoryID, - Other_PapsmearCategoryUserID, - Other_PapsmearCategoryCreated - ) - VALUES( - {$header_id}, - {$v['category_id']}, - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if(intval($v['xid']) != 0 && $v['selected'] === 'N'){ - $sql = "UPDATE other_papsmearcategory SET - Other_PapsmearCategoryIsActive = 'N', - Other_PapsmearCategoryUserID = {$userid} - WHERE - Other_PapsmearCategoryID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - //echo $sql; - if(intval($v['xid']) != 0 && $v['selected'] === 'Y'){ - $sql = "UPDATE other_papsmearcategory SET - Other_PapsmearCategoryIsActive = 'Y', - Other_PapsmearCategoryUserID = {$userid} - WHERE - Other_PapsmearCategoryID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - } - } - - if($results){ - foreach($results as $k =>$v){ - if(intval($v['xid']) == 0){ - $sql = "INSERT INTO other_papsmeardetails ( - Other_PapSmearDetailsOther_PapSmearID, - Other_PapSmearDetailsCode, - Other_PapSmearDetailsLabel, - Other_PapSmearDetailsResult, - Other_PapSmearDetailsUserID, - Other_PapSmearDetailsCreated - ) - VALUES( - {$header_id}, - '{$v['code']}', - '{$v['label']}', - '{$v['result']}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if(intval($v['xid']) != 0){ - $sql = "UPDATE other_papsmeardetails SET - Other_PapSmearDetailsCode = '{$v['code']}', - Other_PapSmearDetailsLabel = '{$v['label']}', - Other_PapSmearDetailsResult = '{$v['result']}', - Other_PapSmearDetailsUserID = {$userid} - WHERE - Other_PapSmearDetailsID = {$v['xid']}"; - $this->db_smartone->query($sql); - - } - //echo $sql; - } - } - - $result = array("total" => 1, "records" => array(), "sql"=> ''); - $this->sys_ok($result); - exit; - } - - function saveresult_fna() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = $inp['doctor']; - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - if($prm[0]['xid'] == '0'){ - $sql = "INSERT INTO other_fna( - Other_FNAM_DoctorID, - Other_FNAT_OrderDetailID, - Other_FNAUserID, - Other_FNACreated - ) - VALUES( - {$doctor_id}, - {$prm[0]['orderdetail_id']}, - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } - else{ - $sql = "SELECT * FROM other_fna WHERE Other_FNAT_OrderDetailID = {$prm[0]['orderdetail_id']} AND Other_FNAIsActive = 'Y'"; - $data_header = $this->db_smartone->query($sql)->row_array(); - $header_id = $data_header['Other_FNAID']; - $sql = "UPDATE other_fna SET - Other_FNAM_DoctorID = {$doctor_id}, - Other_FNAUserID = {$userid} - WHERE - Other_FNAID = {$header_id}"; - $this->db_smartone->query($sql); - } - foreach($prm as $k => $v){ - if($v['xid'] == '0'){ - $results = str_replace("'", "\\'", $v['result']); - $sql = "INSERT INTO other_fnadetails( - Other_FNADetailsOther_FNAID , - Other_FNADetailsCode, - Other_FNADetailsLabel, - Other_FNADetailsResult, - Other_FNADetailsCreated, - Other_FNADetailsUserID - ) - VALUES( - {$header_id}, - '{$v['code']}', - '{$v['label']}', - '{$results}', - NOW(), - {$userid} - )"; - $query = $this->db_smartone->query($sql); - } - else{ - $results = str_replace("'", "\\'", $v['result']); - $sql = "UPDATE other_fnadetails SET - Other_FNADetailsResult = '{$results}', - Other_FNADetailsUserID = {$userid} - WHERE - Other_FNADetailsID = {$v['xid']}"; - $query = $this->db_smartone->query($sql); - } - } - - $result = array("total" => 1, "records" => array(), "sql"=> ''); - $this->sys_ok($result); - exit; - } - - function saveresult_cytologi() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = $inp['doctor']; - - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - if($prm[0]['xid'] == '0'){ - $sql = "INSERT INTO other_cytologi( - Other_CytologiT_OrderDetailID, - Other_CytologiM_DoctorID, - Other_CytologiUserID, - Other_CytologiCreated - ) - VALUES( - {$prm[0]['orderdetail_id']}, - {$doctor_id}, - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } - else{ - $sql = "SELECT * FROM other_cytologi WHERE Other_CytologiT_OrderDetailID = {$prm[0]['orderdetail_id']} AND Other_CytologiIsActive = 'Y'"; - $data_header = $this->db_smartone->query($sql)->row_array(); - $header_id = $data_header['Other_CytologiID']; - $sql = "UPDATE other_cytologi SET - Other_CytologiM_DoctorID = {$doctor_id}, - Other_CytologiUserID = {$userid} - WHERE - Other_CytologiID = {$header_id}"; - $this->db_smartone->query($sql); - } - foreach($prm as $k => $v){ - if($v['xid'] == '0'){ - $results = str_replace("'", "\\'", $v['result']); - $sql = "INSERT INTO other_cytologidetails( - Other_CytologiDetailsOther_CytologiID , - Other_CytologiDetailsCode, - Other_CytologiDetailsLabel, - Other_CytologiDetailsResult, - Other_CytologiDetailsCreated, - Other_CytologiDetailsUserID - ) - VALUES( - {$header_id}, - '{$v['code']}', - '{$v['label']}', - '{$results}', - NOW(), - {$userid} - )"; - $query = $this->db_smartone->query($sql); - } - else{ - $results = str_replace("'", "\\'", $v['result']); - $sql = "UPDATE other_cytologidetails SET - Other_CytologiDetailsResult = '{$results}', - Other_CytologiDetailsUserID = {$userid} - WHERE - Other_CytologiDetailsID = {$v['xid']}"; - $query = $this->db_smartone->query($sql); - } - } - - $result = array("total" => 1, "records" => array(), "sql"=> ''); - $this->sys_ok($result); - exit; - } - - function saveresult_mikro() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = $inp['doctor']; - $backteria_id = $inp['bacteria']; - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - - if($inp['result_value'] != 'Negatif' && $inp['result_value'] != 'Positif'){ - $prm['result_value'] = $prm['result_other']; - } - else{ - $prm['result_value'] = $inp['result_value']; - } - - if($prm['xid'] == '0'){ - $sql = "INSERT INTO other_mikro( - Other_MikroM_DoctorID, - Other_MikroResult, - Other_MikroT_BacteriaID, - Other_MikroT_OrderDetailID, - Other_MikroHasilBiakan, - Other_MikroSampleTypeName, - Other_MikroUserID, - Other_MikroCreated - ) - VALUES( - {$doctor_id}, - '{$prm['result_value']}', - {$backteria_id}, - {$prm['orderdetail_id']}, - '{$prm['hasil_biakan']}', - '{$prm['sample_name']}', - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } - else{ - $sql = "SELECT * FROM other_mikro WHERE Other_MikroT_OrderDetailID = {$prm['orderdetail_id']} AND Other_MikroIsActive = 'Y'"; - $data_header = $this->db_smartone->query($sql)->row_array(); - $header_id = $data_header['Other_MikroID']; - $sql = "UPDATE other_mikro SET - Other_MikroResult = '{$prm['result_value']}', - Other_MikroM_DoctorID = {$doctor_id}, - Other_MikroT_BacteriaID = {$backteria_id}, - Other_MikroHasilBiakan = '{$prm['hasil_biakan']}', - Other_MikroSampleTypeName = '{$prm['sample_name']}', - Other_MikroUserID = {$userid} - WHERE - Other_MikroID = {$header_id}"; - //echo $sql; - $this->db_smartone->query($sql); - } - - - - $sql = "UPDATE other_mikrodetails SET Other_MikroDetailsIsActive = 'N', Other_MikroDetailsUserID = 0 WHERE Other_MikroDetailsOther_MikroID = {$header_id}"; - $this->db_smartone->query($sql); - - $results = $prm['details']; - if($inp['result_value'] == 'Positif'){ - foreach($results as $k => $v){ - if($v['xid'] == '0'){ - $sql = "INSERT INTO other_mikrodetails( - Other_MikroDetailsOther_MikroID , - Other_MikroDetailsT_AntibioticID, - Other_MikroDetailsValue, - Other_MikroDetailsNote, - Other_MikroDetailsCreated, - Other_MikroDetailsUserID - ) - VALUES( - {$header_id}, - '{$v['T_AntibioticID']}', - '{$v['value']}', - '{$v['note']}', - NOW(), - {$userid} - )"; - $query = $this->db_smartone->query($sql); - } - else{ - $sql = "UPDATE other_mikrodetails SET - Other_MikroDetailsT_AntibioticID = '{$v['T_AntibioticID']}', - Other_MikroDetailsValue = '{$v['value']}', - Other_MikroDetailsNote = '{$v['note']}', - Other_MikroDetailsIsActive = 'Y', - Other_MikroDetailsUserID = {$userid} - WHERE - Other_MikroDetailsID = {$v['xid']}"; - //echo $sql; - $query = $this->db_smartone->query($sql); - } - } - } - - - $result = array("total" => 1, "records" => array(), "sql"=> ''); - $this->sys_ok($result); - exit; - } - - - function get_doctors_preparasi_sperma() - { - $prm = $this->sys_input; - // $id = $prm["id"]; - - $sql = " SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 10 AND - M_DoctorSOIsActive = 'Y' - ORDER BY M_DoctorName ASC"; - //echo $sql; - $query = $this->db_smartone->query($sql); - $rows = $query->result_array(); - $sql = " - SELECT '0' as id, 'Belum memilih metode' as name - UNION - SELECT M_MethodeSpermaID as id, M_MethodeSpermaName as name - FROM m_methodesperma - WHERE - M_MethodeSpermaIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $methodes = $this->db_smartone->query($sql)->result_array(); - - - $this->sys_ok(["records"=>$rows,"methodes"=>$methodes]); - - } - - - function getpreparasispermaresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT other_preparasisperma.*, - Other_PreparasiSpermaID as xid, - Other_PreparasiSpermaT_OrderDetailID as orderdetail_id, - IFNULL(Other_PreparasiSpermaM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_PreparasiSpermaM_DoctorID) OR Other_PreparasiSpermaM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name, - IFNULL(M_MethodeSpermaID,0) as methode_id, - IFNULL(M_MethodeSpermaName,'') as methode_name - FROM other_preparasisperma - LEFT JOIN m_doctor ON Other_PreparasiSpermaM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - LEFT JOIN m_methodesperma ON Other_PreparasiSpermaM_MethodeSpermaID = M_MethodeSpermaID AND - M_MethodeSpermaIsActive = 'Y' - WHERE - Other_PreparasiSpermaT_OrderDetailID = {$id} AND Other_PreparasiSpermaIsActive = 'Y' - GROUP BY Other_PreparasiSpermaID"; - $query = $this->db_smartone->query($sql); - - if ($query) - { - $rows = $query->row_array(); - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 10 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $sql = " - SELECT '0' as id, 'Belum memilih metode' as name - UNION - SELECT M_MethodeSpermaID as id, M_MethodeSpermaName as name - FROM m_methodesperma - WHERE - M_MethodeSpermaIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $methodes = $this->db_smartone->query($sql)->result_array(); - $images = array(); - $sql = "SELECT Other_PreparasiSpermaImgID as xid, - Other_PreparasiSpermaImgType as type, - CONCAT('/one-media/one-image-nonlab/',Other_PreparasiSpermaImgNewName) as image_url - FROM t_orderdetail - JOIN other_preparasisperma_img ON Other_PreparasiSpermaImgT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND - Other_PreparasiSpermaImgIsActive = 'Y' - WHERE - T_OrderDetailID = {$id} AND - T_OrderDetailIsActive = 'Y' - GROUP BY Other_PreparasiSpermaImgID"; - //echo $sql; - $images = $this->db_smartone->query($sql)->result_array(); - - $rst = array('doctors'=>$doctors,'methodes'=>$methodes,'results'=>$rows,'images'=>$images); - $this->sys_ok(["records"=>$rst]); - } - else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - - function uploadimage_preparasi_sperma(){ - if (! $this->isLogin) { - $this->sys_error("Invalid Token"); - exit; - } - - $userid = $this->sys_user["M_UserID"]; - $data = []; - //print_r($_SERVER); - - $prm = $this->sys_input; - $orderid = $this->input->post('orderid'); - $type = $this->input->post('type'); - $labnumber = $this->input->post('labnumber'); - $sql = "UPDATE other_preparasisperma_img SET - Other_PreparasiSpermaImgIsActive = 'N', - Other_PreparasiSpermaImgUserID = {$userid} - WHERE - Other_PreparasiSpermaImgT_OrderHeaderID = {$orderid} AND - Other_PreparasiSpermaImgType = '{$type}'"; - //echo $sql; - $this->db_onedev->query($sql); - //$config['upload_path'] = 'assets/'; - - $path = '/home/one/project/one/one-media/one-image-nonlab/'; - //echo $path; - $config['upload_path'] = $path; - $config['allowed_types'] = 'jpg|jpeg|png|gif'; - - $config['max_size'] = '10000'; - $count = count($_FILES['files']['name']); - //echo $count; - $this->load->library('upload',$config); - - $error = []; - for($i=0;$i<$count;$i++){ - - - if(!empty($_FILES['files']['name'][$i])){ - - - - $_FILES['file']['name'] = $_FILES['files']['name'][$i]; - - $_FILES['file']['type'] = $_FILES['files']['type'][$i]; - - $_FILES['file']['tmp_name'] = $_FILES['files']['tmp_name'][$i]; - - $_FILES['file']['error'] = $_FILES['files']['error'][$i]; - - $_FILES['file']['size'] = $_FILES['files']['size'][$i]; - - - - $namex = $orderid.'-'.$labnumber.'-'.$this->generateRandomString(5); - //echo $namex; - - $config['file_name'] = $namex; - $this->upload->initialize($config); - //echo $config['file_name'] ; - - - - - - if($this->upload->do_upload('file')){ - - $uploadData = $this->upload->data(); - - $filename = $uploadData['file_name']; - //echo $filename; - - - $sql = "INSERT INTO other_preparasisperma_img ( - Other_PreparasiSpermaImgT_OrderHeaderID, - Other_PreparasiSpermaImgType, - Other_PreparasiSpermaImgOldName, - Other_PreparasiSpermaImgNewName, - Other_PreparasiSpermaImgCreated, - Other_PreparasiSpermaImgUserID - ) - VALUES( - {$orderid}, - '{$type}', - '{$_FILES['files']['name'][$i]}', - '{$filename}', - NOW(), - {$userid} - - )"; - //echo $sql; - $this->db_onedev->query($sql); - $xlast_id = $this->db_onedev->insert_id(); - $data['totalFiles'][] = array('xid' => $xlast_id ,'type'=>$type,'image_url' => '/one-media/one-image-nonlab/'.$filename); - - } - else{ - $error = array('error' => $this->upload->display_errors()); - } - - } - - - - } - - $result = array("total" =>count( $data['totalFiles']), "records" => $data['totalFiles'],'errors'=>$error); - $this->sys_ok($result); - } - - - function saveresult_preparasi_sperma() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = isset($inp['doctor'])?$inp['doctor']:0; - $methode_id = isset($inp['methode'])?$inp['methode']:0; - $orderdetail_id = $inp['orderdetailid']; - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - if($prm['xid'] == '0'){ - $sql = "INSERT INTO other_preparasisperma( - Other_PreparasiSpermaM_DoctorID, - Other_PreparasiSpermaT_OrderDetailID, - Other_PreparasiSpermaPreMotilitasA, - Other_PreparasiSpermaPreMotilitasB, - Other_PreparasiSpermaPreMotilitasC, - Other_PreparasiSpermaPreKonsentrasi, - Other_PreparasiSpermaPreKontaminan, - Other_PreparasiSpermaPostMotilitasA, - Other_PreparasiSpermaPostMotilitasB, - Other_PreparasiSpermaPostMotilitasC, - Other_PreparasiSpermaPostKonsentrasi, - Other_PreparasiSpermaPostKontaminan, - Other_PreparasiSpermaPreVolume, - Other_PreparasiSpermaPostVolume, - Other_PreparasiSpermaM_MethodeSpermaID, - Other_PreparasiSpermaNote, - Other_PreparasiSpermaUserID, - Other_PreparasiSpermaCreated - ) - VALUES( - {$doctor_id}, - {$orderdetail_id}, - '{$prm['Other_PreparasiSpermaPreMotilitasA']}', - '{$prm['Other_PreparasiSpermaPreMotilitasB']}', - '{$prm['Other_PreparasiSpermaPreMotilitasC']}', - '{$prm['Other_PreparasiSpermaPreKonsentrasi']}', - '{$prm['Other_PreparasiSpermaPreKontaminan']}', - '{$prm['Other_PreparasiSpermaPostMotilitasA']}', - '{$prm['Other_PreparasiSpermaPostMotilitasB']}', - '{$prm['Other_PreparasiSpermaPostMotilitasC']}', - '{$prm['Other_PreparasiSpermaPostKonsentrasi']}', - '{$prm['Other_PreparasiSpermaPostKontaminan']}', - '{$prm['Other_PreparasiSpermaPreVolume']}', - '{$prm['Other_PreparasiSpermaPostVolume']}', - '{$methode_id}', - '{$prm['Other_PreparasiSpermaNote']}', - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } - else{ - $sql = "SELECT * FROM other_preparasisperma WHERE Other_PreparasiSpermaT_OrderDetailID = {$orderdetail_id} AND Other_PreparasiSpermaIsActive = 'Y'"; - $data_header = $this->db_smartone->query($sql)->row_array(); - $header_id = $data_header['Other_PreparasiSpermaID']; - $sql = "UPDATE other_preparasisperma SET - Other_PreparasiSpermaM_DoctorID = {$doctor_id}, - Other_PreparasiSpermaPreMotilitasA = '{$prm['Other_PreparasiSpermaPreMotilitasA']}', - Other_PreparasiSpermaPreMotilitasB = '{$prm['Other_PreparasiSpermaPreMotilitasB']}', - Other_PreparasiSpermaPreMotilitasC = '{$prm['Other_PreparasiSpermaPreMotilitasC']}', - Other_PreparasiSpermaPreKonsentrasi = '{$prm['Other_PreparasiSpermaPreKonsentrasi']}', - Other_PreparasiSpermaPreKontaminan = '{$prm['Other_PreparasiSpermaPreKontaminan']}', - Other_PreparasiSpermaPostMotilitasA = '{$prm['Other_PreparasiSpermaPostMotilitasA']}', - Other_PreparasiSpermaPostMotilitasB = '{$prm['Other_PreparasiSpermaPostMotilitasB']}', - Other_PreparasiSpermaPostMotilitasC = '{$prm['Other_PreparasiSpermaPostMotilitasC']}', - Other_PreparasiSpermaPostKonsentrasi = '{$prm['Other_PreparasiSpermaPostKonsentrasi']}', - Other_PreparasiSpermaPostKontaminan = '{$prm['Other_PreparasiSpermaPostKontaminan']}', - Other_PreparasiSpermaPreVolume = '{$prm['Other_PreparasiSpermaPreVolume']}', - Other_PreparasiSpermaPostVolume = '{$prm['Other_PreparasiSpermaPostVolume']}', - Other_PreparasiSpermaM_MethodeSpermaID = '{$methode_id}', - Other_PreparasiSpermaNote = '{$prm['Other_PreparasiSpermaNote']}', - Other_PreparasiSpermaUserID = {$userid} - WHERE - Other_PreparasiSpermaID = {$header_id}"; - $this->db_smartone->query($sql); - } - - - $result = array("total" => 1, "records" => array(), "sql"=> ''); - $this->sys_ok($result); - exit; - } - - function getdnafragmentasiresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT other_dnafragmentasi.*, - Other_DnaFragmentasiID as xid, - Other_DnaFragmentasiT_OrderDetailID as orderdetail_id, - IFNULL(Other_DnaFragmentasiM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_DnaFragmentasiM_DoctorID) OR Other_DnaFragmentasiM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name, - IFNULL(Other_DnaFragmentasiOther_DnaFragmentasiMethodeID,0) as methode_id, - IFNULL(Other_DnaFragmentasiMethodeName,'') as methode_name, - Other_DnaFragmentasiHaloLuas as halo_luas, - Other_DnaFragmentasiHaloSedang as halo_sedang, - Other_DnaFragmentasiHaloSempit as halo_sempit, - Other_DnaFragmentasiTanpaHalo as tanpa_halo, - Other_DnaFragmentasiDFI as dfi, - Other_DnaFragmentasiKesimpulan as kesimpulan, - Other_DnaFragmentasiCatatan as catatan - FROM other_dnafragmentasi - LEFT JOIN m_doctor ON Other_DnaFragmentasiM_DoctorID = M_DoctorID - LEFT JOIN other_dnafragmentasimethode ON Other_DnaFragmentasiOther_DnaFragmentasiMethodeID = Other_DnaFragmentasiMethodeID - WHERE - Other_DnaFragmentasiT_OrderDetailID = {$id} AND Other_DnaFragmentasiIsActive = 'Y' - GROUP BY Other_DnaFragmentasiID - LIMIT 1"; - //echo $sql; - $query = $this->db_smartone->query($sql); - - if ($query) - { - $rows = $query->row_array(); - if(!$rows){ - $rows = array( - 'xid' => 0, - 'orderdetail_id' =>$id, - 'doctor_id' => 0, - 'doctor_name' => '', - 'methode_id' => 0, - 'methode_name' => '', - 'halo_luas' => '', - 'halo_sedang' => '', - 'tanpa_halo' => '', - 'dfi' => '', - 'kesimpulan' => '', - 'catatan' => '' - ); - } - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID - WHERE - M_DoctorSONat_SubGroupID = 4 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - - $sql = " - SELECT '0' as id, 'Belum memilih metode' as name - UNION - SELECT Other_DnaFragmentasiMethodeID as id, Other_DnaFragmentasiMethodeName as name - FROM other_dnafragmentasimethode - WHERE - Other_DnaFragmentasiMethodeIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $methodes = $this->db_smartone->query($sql)->result_array(); - - - $rst = array('doctors'=>$doctors,'methodes'=>$methodes,'results'=>$rows); - $this->sys_ok(["records"=>$rst]); - } - else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - function saveresult_dnafragmentasi() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = $inp['doctor']['id']; - $methode_id = $inp['methode']['id']; - $orderdetail_id = $inp['results']['orderdetail_id']; - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - if(intval($prm['xid']) == 0){ - $sql = "INSERT INTO other_dnafragmentasi( - Other_DnaFragmentasiT_OrderDetailID, - Other_DnaFragmentasiM_DoctorID, - Other_DnaFragmentasiOther_DnaFragmentasiMethodeID, - Other_DnaFragmentasiHaloLuas, - Other_DnaFragmentasiHaloSedang, - Other_DnaFragmentasiHaloSempit, - Other_DnaFragmentasiTanpaHalo, - Other_DnaFragmentasiDFI, - Other_DnaFragmentasiKesimpulan, - Other_DnaFragmentasiCatatan, - Other_DnaFragmentasiUserID, - Other_DnaFragmentasiLastUpdated - ) - VALUES( - {$orderdetail_id}, - {$doctor_id}, - {$methode_id}, - '{$prm['halo_luas']}', - '{$prm['halo_sedang']}', - '{$prm['halo_sempit']}', - '{$prm['tanpa_halo']}', - '{$prm['dfi']}', - '{$prm['kesimpulan']}', - '{$prm['catatan']}', - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } - else{ - $sql = "UPDATE other_dnafragmentasi SET - Other_DnaFragmentasiT_OrderDetailID = {$orderdetail_id}, - Other_DnaFragmentasiM_DoctorID = {$doctor_id}, - Other_DnaFragmentasiOther_DnaFragmentasiMethodeID = '{$methode_id}', - Other_DnaFragmentasiHaloLuas = '{$prm['halo_luas']}', - Other_DnaFragmentasiHaloSedang = '{$prm['halo_sedang']}', - Other_DnaFragmentasiHaloSempit = '{$prm['halo_sempit']}', - Other_DnaFragmentasiTanpaHalo = '{$prm['tanpa_halo']}', - Other_DnaFragmentasiDFI = '{$prm['dfi']}', - Other_DnaFragmentasiKesimpulan = '{$prm['kesimpulan']}', - Other_DnaFragmentasiCatatan = '{$prm['catatan']}', - Other_DnaFragmentasiLastUpdated = NOW(), - Other_DnaFragmentasiUserID = {$userid} - WHERE - Other_DnaFragmentasiID = {$prm['xid']}"; - //echo $sql; - $this->db_smartone->query($sql); - } - - - $result = array("total" => 1, "records" => array(), "sql"=> ''); - $this->sys_ok($result); - exit; - } - - -} - +db_smartone = $this->load->database("onedev", true); + $this->load->helper(array('form', 'url')); + } + function getMethodeID($natTestID) { + $sql = "select M_MethodePriorityNat_MethodeID MethodeID, Nat_MethodeName + from + m_methode_priority + join nat_methode on Nat_MethodeID = M_MethodePriorityNat_MethodeID + and Nat_MethodeIsActive = 'Y' + join m_instrumentmethode on M_InstrumentMethodeNat_MethodeID = Nat_MethodeID and M_InstrumentMethodeIsActive = 'Y' + join nat_instrument on M_InstrumentMethodeNat_InstrumentID = Nat_InstrumentID + and Nat_InstrumentIsActive ='Y' + where M_MethodePriorityIsActive = 'Y' + and M_MethodePriorityNat_TestID = $natTestID + and M_MethodePriorityM_DayOfWeekID = dayofweek(now()) + order by M_MethodePriorityNumber desc + limit 0,1 "; + $qry = $this->db->query($sql); + if ($qry) { + $rows = $qry->result_array(); + if (count($rows) > 0 ) return array($rows[0]["MethodeID"],$rows[0]["Nat_MethodeName"]); + } + //2nd + $sql= "select + M_InstrumentMethodeNat_MethodeID MethodeID, Nat_MethodeName + from m_instrumentmethode + join nat_methode on M_InstrumentMethodeNat_MethodeID = Nat_MethodeID + and Nat_MethodeIsActive = 'Y' + join nat_instrument on M_InstrumentMethodeNat_InstrumentID = Nat_InstrumentID + and Nat_InstrumentIsActive ='Y' + where M_InstrumentMethodeNat_TestID = $natTestID + and M_InstrumentMethodeIsActive = 'Y' + order by M_InstrumentMethodePriority desc + limit 0,1"; + $qry = $this->db->query($sql); + if ($qry) { + $rows = $qry->result_array(); + if (count($rows) > 0 ) return array($rows[0]["MethodeID"],$rows[0]["Nat_MethodeName"]); + } + // + $sql = "select Nat_NormalValueNat_MethodeID MethodeID, Nat_MethodeName + from + nat_normalvalue + join nat_methode on Nat_NormalValueNat_MethodeID = Nat_MethodeID + and Nat_MethodeIsActive = 'Y' + where Nat_NormalValueNat_TestID = $natTestID + and Nat_NormalValueIsActive = 'Y' + order by Nat_NormalValueID + limit 0,1"; + $qry = $this->db->query($sql); + if ($qry) { + $rows = $qry->result_array(); + if (count($rows) > 0 ) return array($rows[0]["MethodeID"],$rows[0]["Nat_MethodeName"]); + } + return array(0,""); + } + function get_normal_value($methodeID, $natTestID, $sexID, $ageInDay ) { + $this->load->library('ibl_sampling_normal'); + return $this->ibl_sampling_normal->get_normal_value_id($methodeID, $natTestID, $sexID, $ageInDay); + } + return 0; + } + function fn_fix_normal($order_id) { + $sql = "select + T_OrderDetailID, M_PatientM_SexID, fn_global_age_count_day(M_PatientDOB, date(T_OrderHeaderDate)) Dob , + T_TestNat_TestID + from t_orderheader + join m_patient on T_OrderHeaderID = $order_id and T_OrderHeaderM_PatientID = M_PatientID + join t_orderdetail on T_OrderDetailT_OrderHeaderID = T_OrderHeaderID + and T_OrderDetailIsACtive = 'Y' + and ( T_OrderDetailNat_NormalValueID is null or T_OrderDetailNat_NormalValueID = 0 ) + join t_test on T_OrderDetailT_TestID = T_TestID and T_TestIsResult = 'Y' "; + $qry = $this->db->query($sql); + if(! $qry) { + return; + } + $rows = $qry->result_array(); + if(count($rows) == 0 ) return; + $sql_u = "update t_orderdetail + join nat_normalvalue on T_OrderDetailID = ? and Nat_NormalValueID = ? + set + T_OrderDetailNat_NormalValueID = Nat_NormalValueID, + T_OrderDetailNormalValueNote = Nat_NormalValueNote, + T_OrderDetailNormalValueDescription = Nat_NormalValueDescription, + T_OrderDetailMinValue = Nat_NormalValueMinValue, + T_OrderDetailMaxValue = Nat_NormalValueMaxValue, + T_OrderDetailMinValueInclusive = Nat_NormalValueMinValueInclusive, + T_OrderDetailMaxValueInclusive = Nat_NormalValueMaxValueInclusive, + T_OrderDetailNat_MethodeID = ?, + T_OrderdetailNat_MethodeName =?"; + + foreach($rows as $r) { + $T_OrderDetailID = $r["T_OrderDetailID"]; + $sexID = $r["M_PatientM_SexID"]; + $ageInDay = $r["Dob"]; + $natTestID = $r["T_TestNat_TestID"]; + list($methodeID,$methodeName) = $this->getMethodeID($natTestID); + if ($methodeID == 0 ) continue; + $normalValueID = $this->get_normal_value($methodeID, $natTestID, $sexID, $ageInDay); + if ($normalValueID == 0) return; + $this->db->query($sql_u, array($T_OrderDetailID, $normalValueID, $methodeID, $methodeName)); + } + } + function update_order_sample($targetID, $sourceID) { + $sql = "update t_ordersample target + join t_ordersample source on + target.T_OrderSampleID = ? + and target.T_OrderSampleWorklistReceive = 'N' + and source.T_OrderSampleID = ? + set + target.T_OrderSampleSampling = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSampling, source.T_OrderSampleSampling), + target.T_OrderSampleSamplingDate = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingDate, source.T_OrderSampleSamplingDate), + target.T_OrderSampleSamplingTime = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingTime, source.T_OrderSampleSamplingTime), + target.T_OrderSampleSamplingUserID = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingUserID, source.T_OrderSampleSamplingUserID), + + target.T_OrderSampleReceive = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceive, source.T_OrderSampleReceive), + target.T_OrderSampleReceiveDate = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveDate, source.T_OrderSampleReceiveDate), + target.T_OrderSampleReceiveTime = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveTime, source.T_OrderSampleReceiveTime), + target.T_OrderSampleReceiveUserID = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveUserID, source.T_OrderSampleReceiveUserID), + + target.T_OrderSampleVerification = if(target.T_OrderSampleVerification='Y',target.T_OrderSampleVerification, source.T_OrderSampleVerification), + target.T_OrderSampleVerificationDate =if(target.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationDate, source.T_OrderSampleVerificationDate), + target.T_OrderSampleVerificationTime =if(source.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationTime, source.T_OrderSampleVerificationTime), + target.T_OrderSampleVerificationUserID =if(source.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationUserID, source.T_OrderSampleVerificationUserID), + + target.T_OrderSampleProcessing = if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessing, source.T_OrderSampleProcessing), + target.T_OrderSampleProcessingDate= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingDate, source.T_OrderSampleProcessingDate), + target.T_OrderSampleProcessingTime= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingTime, source.T_OrderSampleProcessingTime), + target.T_OrderSampleProcessingUserID= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingUserID, source.T_OrderSampleProcessingUserID), + + target.T_OrderSampleReceiveHandling =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandling, source.T_OrderSampleReceiveHandling ), + target.T_OrderSampleReceiveHandlingDate =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingDate, source.T_OrderSampleReceiveHandlingDate), + target.T_OrderSampleReceiveHandlingTime =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingTime, source.T_OrderSampleReceiveHandlingTime), + target.T_OrderSampleReceiveHandlingUserID =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingUserID, source.T_OrderSampleReceiveHandlingUserID), + + target.T_OrderSampleHandling = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandling, source.T_OrderSampleHandling), + target.T_OrderSampleHandlingDate = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingDate, source.T_OrderSampleHandlingDate), + target.T_OrderSampleHandlingTime = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingTime, source.T_OrderSampleHandlingTime), + target.T_OrderSampleHandlingUserID = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingUserID, source.T_OrderSampleHandlingUserID), + + target.T_OrderSampleWorklistReceive = source.T_OrderSampleWorklistReceive, + target.T_OrderSampleWorklistReceiveDatetime = source.T_OrderSampleWorklistReceiveDateTime, + target.T_OrderSampleWorklistReceiveUserID = source.T_OrderSampleWorklistReceiveUserID + "; + $qry = $this->db->query($sql,array($targetID,$sourceID)); + if(! $qry ) { + echo json_encode(array( "status" => "ERR" , "message" => print_r($this->db->error(),true))); + exit; + } + } + function fix_sample_serum($headerID) { + //cari t_ordersample yg belum worklist receive dengan code 017% + $sql = "select T_OrderSampleID + from t_ordersample + join t_sampletype on + T_OrderSampleT_OrderHeaderID = ? + and T_OrderSampleWorklistReceive = 'N' + and T_OrderSampleIsActive = 'Y' + and T_OrderSampleT_SampleTypeID = T_SampletypeID + and T_SampleTypeCode like '017%' + "; + $qry = $this->db->query($sql, array($headerID)); + if(!$qry) { + echo json_encode(array( "status" => "ERR" , "message" => print_r($this->db->error(),true))); + exit; + } + $rows = $qry->result_array(); + if (count($rows) == 0 ) return; + //cari T_OrderSample yang sudah di receive yg terakhir + $sql = "select T_OrderSampleID + from t_ordersample + join t_sampletype on + T_OrderSampleT_OrderHeaderID = ? + and T_OrderSampleWorklistReceive = 'Y' + and T_OrderSampleIsActive = 'Y' + and T_OrderSampleT_SampleTypeID = T_SampletypeID + and T_SampleTypeCode like '017%' + order by T_OrderSampleWorklistReceiveDatetime desc + limit 0,1 + "; + $qry = $this->db->query($sql, array($headerID)); + if(!$qry) { + echo json_encode(array( "status" => "ERR" , "message" => print_r($this->db->error(),true))); + exit; + } + $rcv_rows = $qry->result_array(); + if (count($rcv_rows) == 0 ) return; + + //print_r($rows); + //print_r($rcv_rows); + $rcv_T_OrderSampleID = $rcv_rows[0]["T_OrderSampleID"]; + //ada yg belum di receive + foreach($rows as $r) { + $T_OrderSampleID = $r["T_OrderSampleID"]; + $this->update_order_sample($T_OrderSampleID,$rcv_T_OrderSampleID); + } + } + public function search() + { + $prm = $this->sys_input; + $max_rst = 99; + + $id = $prm["order_id"]; + if ($id > 0 ) { + $this->fix_sample_serum($id); + $this->fn_fix_normal($id); + } + $lang = $this->lang_default_code; + $lang_id = isset($prm['lang_id']) ? $prm['lang_id'] : '0'; + + if ($lang_id != 0) + { + $l = $this->db_smartone->where("Nat_LangID", $lang_id)->get("nat_lang")->row(); + $lang = $l->Nat_LangCode; + } + + //tambahan fajri + $sql = " UPDATE t_orderdetail + JOIN t_test ON T_OrderDetailT_TestID = T_TestID + SET T_OrderDetailT_TestIsResult = T_TestIsResult + WHERE + T_OrderDetailT_OrderHeaderID = {$id} AND + T_OrderDetailT_TestIsResult = '' AND + T_OrderDetailIsActive = 'Y'"; + $this->db_smartone->query($sql); + + $tot_count = 0; + $lq = ""; + $group_id = 0; + if (isset($prm['group_id'])) + $group_id = $prm['group_id']; + + if ($group_id != 0) + { + $sql = "select distinct T_WorklistDetailNat_TestID Nat_TestID + from t_worklistdetailv2 + where T_WorklistDetailT_WorklistID = {$group_id}"; + $qry = $this->db_smartone->query($sql); + $rows = $qry->result_array(); + $nat_test_ids = "0"; + foreach($rows as $r) { + $nat_test_ids .= ", " . $r["Nat_TestID"]; + } + $q_group = " ( $nat_test_ids ) "; + + $sql = " + SELECT a1.*, cOUNT(a2.T_OrderDetailID) level + FROM ( + SELECT IFNULL(y.T_OrderDetailT_TestID, x.T_OrderDetailT_TestID) t_testid, + IFNULL(y.T_OrderDetailT_TestName, y.T_OrderDetailT_TestName) t_testname, + y.T_OrderDetailResult result, y.T_OrderDetailResult result_old, y.T_OrderDetailNote note, y.T_OrderDetailNote note_old, + y.T_OrderDetailID id, + y.T_OrderDetailT_TestIsResult is_result, a.T_TestIsQuantitative is_quantitative, + y.T_OrderDetailResultFlag result_flag, + y.T_OrderDetailNat_NormalValueID normal_id, + y.T_OrderDetailNormalValueNote normal_note, y.T_OrderDetailNat_UnitName unit_name, + y.T_OrderdetailNat_MethodeID methode_id, y.T_OrderdetailNat_MethodeName methode_name, + a.T_TestNat_TestID nattest_id, a.T_TestID tx_id, count(T_ResultInstrumentID) as result_instrument_n, + y.T_OrderDetailVerification, T_OrderSampleReceive sample_receive, + T_OrderSampleProcessing sample_processing, T_OrderSampleWorklistReceive sample_worklist_receive, + IF(T_OrderDetailAddOnPreAnalytic = 'Y', T_OrderDetailAddOnPreAnalytic, PreAnalyticIsOk) pre_analytic, + T_OrderDetailAddOnPreAnalytic, + T_OrderHeaderID order_id, y.T_OrderDetailT_TestSasCode test_sas_code, + tx.T_TestSasCode, + T_OrderDetailAddOnResample `resample`, T_OrderDetailAddOnResampleStatus resample_status, + T_OrderDetailAddOnRef ref, y.T_OrderDetailVerification verification, y.T_OrderDetailValidation validation, + T_OrderPromiseDateTime, Group_ResultName as ResultGroupName + FROM t_orderdetail x + left join t_orderpromise on x.T_OrderDetailT_OrderPromiseID = T_OrderPromiseID + JOIN t_test tx ON x.T_OrderDetailT_TestID = T_TestID + JOIN t_test tcheck on tcheck.T_TestNat_TestID in {$q_group} + and ( tx.T_TestID = tcheck.T_TestID or tx.T_TestSasCode like concat(tcheck.T_TestSasCode,'%')) + LEFT JOIN group_resultdetail ON Group_ResultDetailT_TestID = x.T_OrderDetailT_TestID AND Group_ResultDetailIsActive = 'Y' + LEFT JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND Group_ResultFlagNonLab = 'N' + LEFT JOIN t_orderdetail y ON x.T_OrderDetailT_TestSasCode LIKE CONCAT(y.T_OrderDetailT_TestSasCode, '%') + AND x.T_OrderDetailT_OrderHeaderID = y.T_OrderDetailT_OrderHeaderID + AND y.T_OrderDetailIsActive = 'Y' + LEFT JOIN t_orderdetailaddon ON x.T_OrderDetailID = T_OrderDetailAddOnT_OrderDetailID + JOIN t_orderheader ON y.T_OrderDetailT_OrderHeaderID = T_OrderHeaderID + LEFT JOIN t_test a ON y.T_OrderDetailT_TestID = a.T_TestID + AND a.T_TestIsNonLab = '' + LEFT JOIN (SELECT T_OrderSampleT_SampleTypeID, T_OrderSampleReceive, T_OrderSampleProcessing, T_OrderSampleWorklistReceive + FROM t_ordersample WHERE T_OrderSampleT_OrderHeaderID = {$id} + AND T_OrderSampleIsactive = 'Y' + GROUP BY T_OrderSampleT_SampleTypeID) os ON a.T_TestT_SampleTypeID = os.T_OrderSampleT_SampleTypeID + or os.T_OrderSampleT_SampleTypeID = fn_sampletype_from_local(a.T_TestNat_TestID) + + LEFT JOIN t_resultinstrument ON T_ResultInstrumentT_OrderDetailID = x.T_OrderDetailID + LEFT JOIN pre_analytic ON PreAnalyticNat_TestID = a.T_TestNat_TestID AND PreAnalyticDate = date(now()) and PreAnalyticIsActive = 'Y' + WHERE x.T_OrderDetailT_OrderHeaderID = {$id} + AND x.T_OrderDetailIsActive = 'Y' + GROUP BY y.T_OrderDetailT_TestID + ORDER BY y.T_OrderDetailT_TestSasCode ASC + ) a1 + + LEFT JOIN t_orderdetail a2 ON a2.T_OrderDetailT_OrderHeaderID = a1.order_id + AND a2.T_OrderDetailIsActive = 'Y' + AND a1.test_sas_code LIKE CONCAT(a2.T_OrderDetailT_testSasCode, '%') + GROUP BY a1.t_testid + order by a1.test_sas_code +"; + $query = $this->db_smartone->query($sql); + $lq = $this->db_smartone->last_query(); + } + else + { + $sql = " + SELECT a1.*, cOUNT(a2.T_OrderDetailID) level + FROM ( + SELECT IFNULL(y.T_OrderDetailT_TestID, x.T_OrderDetailT_TestID) t_testid, + IFNULL(y.T_OrderDetailT_TestName, y.T_OrderDetailT_TestName) t_testname, + y.T_OrderDetailResult result, y.T_OrderDetailResult result_old, y.T_OrderDetailNote note, y.T_OrderDetailNote note_old, + y.T_OrderDetailID id, + y.T_OrderDetailT_TestIsResult is_result, a.T_TestIsQuantitative is_quantitative, + y.T_OrderDetailResultFlag result_flag, + y.T_OrderDetailNat_NormalValueID normal_id, + y.T_OrderDetailNormalValueNote normal_note, y.T_OrderDetailNat_UnitName unit_name, + y.T_OrderdetailNat_MethodeID methode_id, y.T_OrderdetailNat_MethodeName methode_name, + a.T_TestNat_TestID nattest_id, a.T_TestID tx_id, count(T_ResultInstrumentID) as result_instrument_n, + y.T_OrderDetailVerification, T_OrderSampleReceive sample_receive, + T_OrderSampleProcessing sample_processing, T_OrderSampleWorklistReceive sample_worklist_receive, + IF(T_OrderDetailAddOnPreAnalytic = 'Y', T_OrderDetailAddOnPreAnalytic, PreAnalyticIsOk) pre_analytic, + T_OrderDetailAddOnPreAnalytic, + T_OrderHeaderID order_id, y.T_OrderDetailT_TestSasCode test_sas_code, + tx.T_TestSasCode, + T_OrderDetailAddOnResample `resample`, T_OrderDetailAddOnResampleStatus resample_status, + T_OrderDetailAddOnRef ref, y.T_OrderDetailVerification verification, y.T_OrderDetailValidation validation, + T_OrderPromiseDateTime , Group_ResultName as ResultGroupName + FROM t_orderdetail x + left join t_orderpromise on x.T_OrderDetailT_OrderPromiseID = T_OrderPromiseID + JOIN t_test tx ON x.T_OrderDetailT_TestID = T_TestID + LEFT JOIN group_resultdetail ON Group_ResultDetailT_TestID = x.T_OrderDetailT_TestID AND Group_ResultDetailIsActive = 'Y' + LEFT JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND Group_ResultFlagNonLab = 'N' + LEFT JOIN t_orderdetail y ON x.T_OrderDetailT_TestSasCode LIKE CONCAT(y.T_OrderDetailT_TestSasCode, '%') + AND x.T_OrderDetailT_OrderHeaderID = y.T_OrderDetailT_OrderHeaderID + AND y.T_OrderDetailIsActive = 'Y' + + LEFT JOIN t_orderdetailaddon ON x.T_OrderDetailID = T_OrderDetailAddOnT_OrderDetailID + + JOIN t_orderheader ON y.T_OrderDetailT_OrderHeaderID = T_OrderHeaderID + LEFT JOIN t_test a ON y.T_OrderDetailT_TestID = a.T_TestID + AND a.T_TestIsNonLab = '' + LEFT JOIN (SELECT T_OrderSampleT_SampleTypeID, T_OrderSampleReceive, T_OrderSampleProcessing, T_OrderSampleWorklistReceive + FROM t_ordersample WHERE T_OrderSampleT_OrderHeaderID = {$id} + AND T_OrderSampleIsactive = 'Y' + GROUP BY T_OrderSampleT_SampleTypeID) os ON a.T_TestT_SampleTypeID = os.T_OrderSampleT_SampleTypeID + or os.T_OrderSampleT_SampleTypeID = fn_sampletype_from_local(a.T_TestNat_TestID) + + LEFT JOIN t_resultinstrument ON T_ResultInstrumentT_OrderDetailID = x.T_OrderDetailID + LEFT JOIN pre_analytic ON PreAnalyticNat_TestID = a.T_TestNat_TestID AND PreAnalyticDate = date(now()) and PreAnalyticIsActive = 'Y' + WHERE x.T_OrderDetailT_OrderHeaderID = {$id} + AND x.T_OrderDetailIsActive = 'Y' + GROUP BY y.T_OrderDetailT_TestID + ORDER BY y.T_OrderDetailT_TestSasCode ASC + ) a1 + + LEFT JOIN t_orderdetail a2 ON a2.T_OrderDetailT_OrderHeaderID = a1.order_id + AND a2.T_OrderDetailIsActive = 'Y' + AND a1.test_sas_code LIKE CONCAT(a2.T_OrderDetailT_testSasCode, '%') + GROUP BY a1.t_testid + order by a1.test_sas_code +"; +//echo $sql; + $query = $this->db_smartone->query($sql); + $lq = $this->db_smartone->last_query(); + } + // file_put_contents("/xtmp/re-query.sql",$lq); + + if ($query) { + $rst = []; + $rows = $query->result_array(); + + foreach($rows as $k => $v) + { + + if ($v['is_result'] == "Y" && $v['is_quantitative'] == "N") + { + $v['template'] = []; + $x = $this->db_smartone->query("CALL sp_master_resulttemplate_get('{$v['t_testid']}')"); + $this->clean_mysqli_connection($this->db_smartone->conn_id); + if ($x) + $v['template'] = $x->result_array(); + } + + // IF Rujukan, by pas Pre Analytik + if ($v['ref'] == 'Y') + $v['pre_analytic'] = 'Y'; + if ($v["id"] == "885455" ) + { + //sipe workaround + //$v["sample_receive"] = "Y"; + $v["sample_worklist_receive"] = "Y"; + } + $rst[] = $v; + } + + $result = array("total" => $tot_count, "records" => $rst, "total_display" => sizeof($rows), "q" => $lq); + $this->sys_ok($result); + } + else { + $this->sys_error_db("RE Px rows", $this->db_smartone); + exit; + } + } + + public function save() + { + $prm = $this->sys_input; + $data = json_decode($prm["data"]); + $lang = $this->lang_default_code; + $lang_id = isset($prm['lang_id']) ? $prm['lang_id'] : '0'; + + if ($lang_id != 0) + { + $l = $this->db_smartone->where("Nat_LangID", $lang_id)->get("nat_lang")->row(); + $lang = $l->Nat_LangCode; + } + + $sql_norm = "select T_OrderDetailMinValue, T_OrderDetailMaxValue, + T_OrderDetailMinValueInclusive, T_OrderDetailMaxValueInclusive, + Nat_TestFlagLow, Nat_TestFlagHigh + from t_orderdetail + join t_test on T_OrderDetailT_TestID = T_TestID + join nat_test on T_TestNat_TestID = Nat_TestID and T_TestIsActive = 'Y' + where T_OrderDetailID = ? "; + + $ids = []; + foreach ($data as $k => $v) + { + if ( $v->resultInstrumentID > 0 ) { + $sql_i = "select T_ResultInstrumentNat_NormalValueID normalValueID + from t_resultinstrument + where T_ResultInstrumentID = ?"; + $qry_i = $this->db_smartone->query($sql_i, array($v->resultInstrumentID)); + if ($qry_i) { + $rows_i = $qry_i->result_array(); + + if (count($rows_i) > 0 ) { + $sql_iu = "update t_orderdetail, nat_normalvalue , nat_methode + set T_OrderDetailMinValue = Nat_NormalValueMinValue, + T_OrderDetailMinValueInclusive = Nat_NormalValueMinValueInclusive, + T_OrderDetailMaxValue = Nat_NormalValueMaxValue , + T_OrderDetailMaxValueInclusive = Nat_NormalValueMaxValueInclusive, + T_OrderDetailNormalValueNote = Nat_NormalValueNote, + T_OrderDetailNormalValueDescription = Nat_NormalValueDescription, + T_OrderDetailNat_NormalValueID = Nat_NormalValueID, + T_OrderDetailNat_MethodeID = Nat_NormalValueNat_MethodeID, + T_OrderDetailNat_MethodeName = Nat_MethodeName + where T_OrderDetailID = ? and Nat_NormalValueID = ? + and Nat_NormalValueNat_MethodeID = Nat_MethodeID + "; + $this->db_smartone->query($sql_iu, array($v->id, $rows_i[0]["normalValueID"])); + //file_put_contents("/xtmp/update-nilai-normal", $this->db_smartone->last_query() . "\n", FILE_APPEND); + } + } + } + $y = $this->db_smartone->query("SELECT fn_process_sample_handling_perfect('{$v->order_id}', '{$v->test_id}') c") + ->row(); + $req_status = $y->c; + $qry_norm = $this->db_smartone->query($sql_norm,$v->id); + $result_flag = ""; + if ($qry_norm) { + $rows_norm = $qry_norm->result_array(); + if (count($rows_norm) > 0 ) { + $r = $rows_norm[0]; + if (is_numeric($v->result)) { + + if ( $r["T_OrderDetailMinValueInclusive"] == "Y" && $v->result < $r["T_OrderDetailMinValue"] ) { + $result_flag = $r["Nat_TestFlagLow"]; + } + if ( $r["T_OrderDetailMinValueInclusive"] == "N" && $v->result <= $r["T_OrderDetailMinValue"] ) { + $result_flag = $r["Nat_TestFlagLow"]; + } + if ( $r["T_OrderDetailMaxValueInclusive"] == "Y" && $v->result > $r["T_OrderDetailMaxValue"] ) { + $result_flag = $r["Nat_TestFlagHigh"]; + } + if ( $r["T_OrderDetailMaxValueInclusive"] == "N" && $v->result >= $r["T_OrderDetailMaxValue"] ) { + $result_flag = $r["Nat_TestFlagHigh"]; + } + } + } + } + if ($lang == $this->lang_default_code) + { + $this->db_smartone->set('T_OrderDetailResult', $v->result) + ->set('T_OrderDetailResultFlag', $result_flag) + ->set('T_OrderDetailNote', $v->note) + ->set('T_OrderDetailReqStatus', $req_status) + ->where('T_OrderDetailID', $v->id) + ->update('t_orderdetail'); + } + else + { + $this->db_smartone->set('T_OrderDetailLangResult', $v->result) + ->set('T_OrderDetailLangNote', $v->note) + ->where('T_OrderDetailLangID', $v->id) + ->update('t_orderdetaillang'); + } + + $ids[] = $v->id; + } + + // LOG Process + $order = $this->db_smartone->select('T_OrderDetailT_OrderHeaderID id, T_OrderHeaderLabNumber lab_number', false) + ->join('t_orderheader', 'T_OrderHeaderID = T_OrderDetailT_OrderHeaderID') + ->where('T_OrderDetailID', $data[0]->id) + ->get('t_orderdetail') + ->row(); + + $dblog = $this->load->database("onelog", true); + $dblog->set('Log_ProcessCode', 'PROCESS.Result.Entry') + ->set('Log_ProcessOrderID', $order->id) + ->set('Log_ProcessOrderNumber', $order->lab_number) + ->set('Log_ProcessJson', json_encode($data)) + ->set('Log_ProcessUserID', $this->sys_user['M_UserID']) + ->insert('log_process'); + // END OF Log Process + //auto calculation + $this->load->library("Resultcalc"); + $rows = $this->resultcalc->auto($order->id); + + try { + foreach($ids as $id ) { + $this->db_smartone->query("call sp_set_normal_value_flag($id)"); + $this->clean_mysqli_connection($this->db_smartone->conn_id); + } + } catch(Exception $e) { + } + + $this->sys_ok($ids); + } + + public function save_template() + { + $prm = $this->sys_input; + + $n = $this->db_smartone->select("COUNT(T_ResultTemplateID) n") + ->where("T_ResultTemplateT_TestID", $prm['test_id']) + ->where("T_ResultTemplateIsActive", "Y") + ->where("T_ResultTemplateValue", $prm['value']) + ->get('t_resulttemplate') + ->row(); + if ($n->n > 0) + { + $this->sys_error_db("Insert Result Template", $this->db_smartone); + return; + } + + $r = $this->db_smartone->set("T_ResultTemplateT_TestID", $prm['test_id']) + ->set("T_ResultTemplateValue", $prm['value']) + ->insert('t_resulttemplate'); + if ($r) + { + $template = []; + $x = $this->db_smartone->query("CALL sp_master_resulttemplate_get('{$prm['test_id']}')"); + $this->clean_mysqli_connection($this->db_smartone->conn_id); + if ($x) + $template = $x->result_array(); + + $this->sys_ok($template); + } + } + + public function export() + { + $prm = $this->sys_input; + + $sql = "CALL sp_process_result_lang(?, ?, ?, ?)"; + $query = $this->db_smartone->query($sql, [$prm['order_id'], $prm['lang_id'], $prm['is_si'], $this->sys_user['M_UserID']]); + if ($query) + { + $r = $query->row(); + if ($r->status == "OK") + { + $this->sys_ok($r->data); + return; + } + + $this->sys_error_db("Message : " . $r->message, $this->db_smartone); + } + else + { + $this->sys_error_db("Lang Result", $this->db_smartone); + return; + } + } + + public function search_group() + { + $prm = $this->sys_input; + $max_rst = 100; + + // QUERY TOTAL + $sql = "select count(*) total + from t_worklist + where T_WorklistIsActive = 'Y' + order by T_WorklistName ASC"; + $query = $this->db_smartone->query($sql); + + if ($query) { + $tot_count = $query->result_array()[0]["total"]; + } + else { + $this->sys_error_db("worklist count", $this->db_smartone); + exit; + } + + $sql = "select T_WorklistID group_id, T_WorklistName group_name + from t_worklist + where T_WorklistIsActive = 'Y' + order by T_WorklistName ASC + limit 0, {$max_rst}"; + $query = $this->db_smartone->query($sql); + + if ($query) { + $rows = $query->result_array(); + foreach ($rows as $k => $v) + $rows[$k]['data'] = json_decode($v['data']); + $result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows), "q" => $this->db_smartone->last_query()); + $this->sys_ok($result); + } + else { + $this->sys_error_db("worklist rows", $this->db_smartone); + exit; + } + } + + public function search_rerun() + { + $prm = $this->sys_input; + $id = $prm["detail_id"]; + + $sql = "CALL sp_process_result_rerun(?)"; + $query = $this->db_smartone->query($sql, [$id]); + + if ($query) + { + $rows = $query->result_array(); + $this->sys_ok(["records"=>$rows]); + } + else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + + + function getdoctorsfna() + { + $prm = $this->sys_input; + // $id = $prm["id"]; + + $sql = " SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY M_DoctorName ASC"; + //echo $sql; + $query = $this->db_smartone->query($sql); + + if ($query) + { + $rows = $query->result_array(); + $this->sys_ok(["records"=>$rows]); + } + else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + function getfnaresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT Other_FNADetailsID as xid, + Other_FNAT_OrderDetailID as orderdetail_id, + Other_FNADetailsCode as code, + Other_FNADetailsLabel as label, + Other_FNADetailsResult as result, + IFNULL(Other_FNAM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_FNAM_DoctorID) OR Other_FNAM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_fna + JOIN other_fnadetails ON Other_FNADetailsOther_FNAID = Other_FNAID AND Other_FNADetailsIsActive = 'Y' + LEFT JOIN m_doctor ON Other_FNAM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_FNAT_OrderDetailID = {$id} AND Other_FNAIsActive = 'Y' + GROUP BY Other_FNADetailsID + ORDER BY Other_FNADetailsCode ASC"; + $query = $this->db_smartone->query($sql); + + if ($query) + { + $rows = $query->result_array(); + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $images = array(); + $sql = "SELECT So_ImageUploadID as xid, + CONCAT('/one-media/one-image-nonlab/',So_ImageUploadNewName) as image_url + FROM t_orderdetail + JOIN so_imageupload ON So_ImageUploadT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND + So_ImageUploadIsActive = 'Y' + WHERE + T_OrderDetailID = {$id} AND + T_OrderDetailIsActive = 'Y' + GROUP BY So_ImageUploadID"; + $images = $this->db_smartone->query($sql)->result_array(); + + $rst = array('doctors'=>$doctors,'results'=>$rows,'images'=>$images); + $this->sys_ok(["records"=>$rst]); + } + else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + + function uploadimage(){ + if (! $this->isLogin) { + $this->sys_error("Invalid Token"); + exit; + } + + $userid = $this->sys_user["M_UserID"]; + $data = []; + //print_r($_SERVER); + + $prm = $this->sys_input; + $orderid = $this->input->post('orderid'); + $labnumber = $this->input->post('labnumber'); + $sql = "UPDATE so_imageupload SET + So_ImageUploadIsActive = 'N', + So_ImageUploadUserID = {$userid} + WHERE + So_ImageUploadT_OrderHeaderID = {$orderid}"; + //echo $sql; + $this->db_onedev->query($sql); + //$config['upload_path'] = 'assets/'; + + $path = '/home/one/project/one/one-media/one-image-nonlab/'; + //echo $path; + $config['upload_path'] = $path; + $config['allowed_types'] = 'jpg|jpeg|png|gif'; + + $config['max_size'] = '10000'; + $count = count($_FILES['files']['name']); + //echo $count; + $this->load->library('upload',$config); + + $error = []; + for($i=0;$i<$count;$i++){ + + + if(!empty($_FILES['files']['name'][$i])){ + + + + $_FILES['file']['name'] = $_FILES['files']['name'][$i]; + + $_FILES['file']['type'] = $_FILES['files']['type'][$i]; + + $_FILES['file']['tmp_name'] = $_FILES['files']['tmp_name'][$i]; + + $_FILES['file']['error'] = $_FILES['files']['error'][$i]; + + $_FILES['file']['size'] = $_FILES['files']['size'][$i]; + + + + $namex = $orderid.'-'.$labnumber.'-'.$this->generateRandomString(5); + //echo $namex; + + $config['file_name'] = $namex; + $this->upload->initialize($config); + //echo $config['file_name'] ; + + + + + + if($this->upload->do_upload('file')){ + + $uploadData = $this->upload->data(); + + $filename = $uploadData['file_name']; + //echo $filename; + + + $sql = "INSERT INTO so_imageupload ( + So_ImageUploadT_OrderHeaderID, + So_ImageUploadT_OrderHeaderLabNumber, + So_ImageUploadT_SampleTypeID, + So_ImageUploadOldName, + So_ImageUploadNewName, + So_ImageUploadCreated, + So_ImageUploadUserID + ) + VALUES( + {$orderid}, + '{$labnumber}', + '150', + '{$_FILES['files']['name'][$i]}', + '{$filename}', + NOW(), + {$userid} + + )"; + //echo $sql; + $this->db_onedev->query($sql); + $xlast_id = $this->db_onedev->insert_id(); + $data['totalFiles'][] = array('xid' => $xlast_id ,'image_url' => '/one-media/one-image-nonlab/'.$filename); + + } + else{ + $error = array('error' => $this->upload->display_errors()); + } + + } + + + + } + + $result = array("total" =>count( $data['totalFiles']), "records" => $data['totalFiles'],'errors'=>$error); + $this->sys_ok($result); + } + + + function generateRandomString($length = 10) { + $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; + $charactersLength = strlen($characters); + $randomString = ''; + for ($i = 0; $i < $length; $i++) { + $randomString .= $characters[rand(0, $charactersLength - 1)]; + } + return $randomString; + } + + function getcytologiresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT Other_CytologiDetailsID as xid, + Other_CytologiT_OrderDetailID as orderdetail_id, + Other_CytologiDetailsCode as code, + Other_CytologiDetailsLabel as label, + Other_CytologiDetailsResult as result, + IFNULL(Other_CytologiM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_CytologiM_DoctorID) OR Other_CytologiM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_cytologi + JOIN other_cytologidetails ON Other_CytologiDetailsOther_CytologiID = Other_CytologiID AND Other_CytologiDetailsIsActive = 'Y' + LEFT JOIN m_doctor ON Other_CytologiM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_CytologiT_OrderDetailID = {$id} AND Other_CytologiIsActive = 'Y' + GROUP BY Other_CytologiDetailsID + ORDER BY Other_CytologiDetailsCode ASC"; + //echo $sql; + $query = $this->db_smartone->query($sql); + + if ($query) + { + $rows = $query->result_array(); + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $rst = array('doctors'=>$doctors,'results'=>$rows); + $this->sys_ok(["records"=>$rst]); + } + else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + function getmikroresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT + Other_MikroID as xid, + Other_MikroHasilBiakan as hasil_biakan, + Other_MikroSampleTypeName as sample_name, + Other_MikroT_OrderDetailID as orderdetail_id, + Other_MikroResult as result_value, + '' as result_other, + IFNULL(T_BacteriaID,0) as T_BacteriaID, + IFNULL(T_BacteriaName,'') as T_BacteriaName, + '' as details, + IFNULL(Other_MikroM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_MikroM_DoctorID) OR Other_MikroM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_mikro + LEFT JOIN t_bacteria ON Other_MikroT_BacteriaID = T_BacteriaID + LEFT JOIN m_doctor ON Other_MikroM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_MikroT_OrderDetailID = {$id} AND Other_MikroIsActive = 'Y' + GROUP BY Other_MikroID"; + //echo $sql; + $query = $this->db_smartone->query($sql); + + if ($query) + { + $row = $query->row_array(); + if($row){ + if($row['result_value'] != 'Positif' && $row['result_value'] != 'Negatif'){ + $row['result_other'] = $row['result_value']; + $row['result_value'] = 'other'; + } + $sql = "SELECT '' as xno, + Other_MikroDetailsID as xid, + Other_MikroDetailsValue as value, + IF(Other_MikroDetailsNote = 'R','Y','N') as chx_r, + IF(Other_MikroDetailsNote = 'I','Y','N') as chx_i, + IF(Other_MikroDetailsNote = 'S','Y','N') as chx_s, + Other_MikroDetailsNote as note, + t_antibiotic.* + FROM other_mikrodetails + LEFT JOIN t_antibiotic ON Other_MikroDetailsT_AntibioticID = T_AntibioticID + WHERE + Other_MikroDetailsOther_MikroID = {$row['xid']} AND Other_MikroDetailsIsActive = 'Y' + GROUP BY Other_MikroDetailsID + ORDER BY T_AntibioticName ASC"; + //echo $sql; + $details = $this->db_smartone->query($sql)->result_array(); + if($details){ + foreach($details as $k => $v){ + $details[$k]['xno'] = $k + 1; + } + } + $row['details'] = $details; + } + else{ + $row = array('xid'=>'0','hasil_biakan' => '','result_value'=>'Negatif','sample_name' => '','orderdetail_id'=>$id, 'T_BacteriaID'=>'0','T_BacteriaName'=>'0','details'=>array(),'doctor_id'=>'0','doctor_name'=>'0'); + } + } + else{ + $row = array('xid'=>'0','hasil_biakan' => '','result_value'=>'Negatif','sample_name' => '','orderdetail_id'=>$id, 'T_BacteriaID'=>'0','T_BacteriaName'=>'0','details'=>array(),'doctor_id'=>'0','doctor_name'=>'0'); + } + //print_r($row); + + + + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 7 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $sql = " + SELECT '0' as id, 'Belum memilih bakteria' as name + UNION + SELECT T_BacteriaID as id, T_BacteriaName as name + FROM t_bacteria + WHERE + T_BacteriaIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $bacteries = $this->db_smartone->query($sql)->result_array(); + $rst = array('doctors'=>$doctors,'bacteries'=>$bacteries,'results'=>$row); + $this->sys_ok(["records"=>$rst]); + } + function getantibiotics(){ + $prm = $this->sys_input; + $id = $prm["id"]; + $sql = " SELECT '' as xno, + 0 as xid, + '' as hasil_biakan, + '' as sample_name, + 0 as value, + 'Y' as chx_r, + 'N' as chx_i, + 'N' as chx_s, + 'R' as note, + t_antibiotic.* + FROM t_antibiotic + WHERE + T_AntibioticT_BacteriaID = {$prm['id']} AND T_AntibioticIsActive= 'Y' + ORDER BY T_AntibioticName ASC"; + //echo $sql; + $rows = $this->db_smartone->query($sql)->result_array(); + if(rows){ + foreach($rows as $k => $v){ + $rows[$k]['xno'] = $k + 1; + } + } + + $this->sys_ok(["records"=>$rows]); + } + function getlcprepresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + $sql = " SELECT Other_LcprepDetailsID as xid, + Other_LcprepID as header_id, + Other_LcprepT_orderDetailID as orderdetail_id, + Other_LcprepDetailsCode as code, + Other_LcprepDetailsLabel as label, + Other_LcprepDetailsResult as result, + IFNULL(Other_LcprepM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_LcprepM_DoctorID) OR Other_LcprepM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_lcprep + JOIN other_lcprepdetails ON Other_LcprepDetailsOther_LcprepID = Other_LcprepID AND Other_LcprepDetailsIsActive = 'Y' + LEFT JOIN m_doctor ON Other_LcprepM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_LcprepT_orderDetailID = {$id} AND Other_LcprepIsActive = 'Y' + GROUP BY Other_LcprepDetailsOther_LcprepID, Other_LcprepDetailsCode + ORDER BY Other_LcprepDetailsCode ASC"; + //echo $sql; + $rows = $this->db_smartone->query($sql)->result_array(); + if(!$rows){ + $rows = array( + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'A', + 'label' => 'DESKRIPSI', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ), + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'B', + 'label' => 'KESIMPULAN', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ) + ); + } + + $header_id = $rows[0]['header_id']; + $sql = "SELECT IFNULL(Other_LcprepAdekuasiID,0) as xid, + Lcprep_AdekuasiID as id, + Lcprep_AdekuasiLabel as name, + IF(ISNULL(Other_LcprepAdekuasiID),'N',Other_LcprepAdekuasiChex) as chex + FROM lcprep_adekuasi + LEFT JOIN other_lcprepadekuasi ON Other_LcprepAdekuasiLcprep_AdekuasiID = Lcprep_AdekuasiID AND + Other_LcprepAdekuasiOther_LcprepID = {$header_id} AND + Other_LcprepAdekuasiIsActive = 'Y' + WHERE + Lcprep_AdekuasiIsActive = 'Y' + GROUP BY Lcprep_AdekuasiID + ORDER BY Lcprep_AdekuasiOrder ASC + "; + //echo $sql; + $adeakuasi = $this->db_smartone->query($sql)->result_array(); + foreach($adeakuasi as $kc => $vc){ + $adeakuasi[$kc]['chex'] = $vc['chex'] == 'N'?false:true; + } + + $sql = "SELECT IFNULL(Other_LcprepKategoriUmumID,0) as xid, + Lcprep_KategoriUmumID as id, + Lcprep_KategoriUmumLabel as name, + IF(ISNULL(Other_LcprepKategoriUmumID),'N',Other_LcprepKategoriUmumChex) as chex + FROM lcprep_kategoriumum + LEFT JOIN other_lcprepkategoriumum ON Other_LcprepKategoriUmumLcprep_KategoriUmumID = Lcprep_KategoriUmumID AND + Other_LcprepKategoriUmumOther_LcprepID = {$header_id} AND + Other_LcprepKategoriUmumIsActive = 'Y' + WHERE + Lcprep_KategoriUmumIsActive = 'Y' + GROUP BY Lcprep_KategoriUmumID + "; + //echo $sql; + $kategoriumum = $this->db_smartone->query($sql)->result_array(); + foreach($kategoriumum as $kc => $vc){ + $kategoriumum[$kc]['chex'] = $vc['chex'] == 'N'?false:true; + } + + $sql = " + SELECT Lcprep_InterpretasiGroupID as group_id, + Lcprep_InterpretasiGroupName as group_name, + '' as subgroups + FROM lcprep_interpretasigroup + WHERE + Lcprep_InterpretasiGroupIsActive = 'Y' + "; + //echo $sql; + $interpretasi = $this->db_smartone->query($sql)->result_array(); + foreach($interpretasi as $k => $v){ + $subgroups = array(); + $sql = "SELECT Lcprep_InterpretasiSubgroupID as subgroup_id, + Lcprep_InterpretasiSubgroupName as subgroup_name, + '' as childs + FROM lcprep_interpretasisubgroup + WHERE + Lcprep_InterpretasiSubgroupLcprep_InterpretasiGroupID = {$v['group_id']} AND Lcprep_InterpretasiSubgroupIsActive = 'Y'"; + //echo $sql; + $subgroups = $this->db_smartone->query($sql)->result_array(); + if(count($subgroups) > 0){ + foreach($subgroups as $ki => $vi){ + $childs = array(); + $sql = "SELECT IFNULL(Other_LcprepInterpretasiID,0) as xid, + IFNULL(Other_LcprepInterpretasiChex,'N') as chex, + IFNULL(Other_LcprepInterpretasiValue,'') as value, + Lcprep_InterpretasiID as id, + Lcprep_InterpretasiLcprep_InterpretasiSubgroupID as subgroup_id, + Lcprep_InterpretasiCode as code, + Lcprep_InterpretasiName as name, + Lcprep_InterpretasiParentID as parent_id, + Lcprep_InterpretasiIsParent as is_parent, + Lcprep_InterpretasiHasResult as has_result, + Lcprep_InterpretasiTypeResult as type_result + FROM lcprep_interpretasi + LEFT JOIN other_lcprepinterpretasi ON Other_LcprepInterpretasiOther_LcprepID = {$header_id} AND + Other_LcprepInterpretasiLcprep_InterpretasiID = Lcprep_InterpretasiID AND + Other_LcprepInterpretasiIsActive = 'Y' + WHERE + Lcprep_InterpretasiLcprep_InterpretasiSubgroupID = {$vi['subgroup_id']} AND Lcprep_InterpretasiIsActive = 'Y' + GROUP BY Lcprep_InterpretasiID Order BY Lcprep_InterpretasiCode ASC"; + $childs = $this->db_smartone->query($sql)->result_array(); + if($childs){ + foreach($childs as $kc => $vc){ + $childs[$kc]['chex'] = $vc['chex'] == 'N'?false:true; + } + } + $subgroups[$ki]['childs'] = $childs; + } + } + + $interpretasi[$k]['subgroups'] = $subgroups; + } + + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $rst = array('doctors'=>$doctors,'results'=>$rows,'adekuasi'=>$adeakuasi,'kategoriumum'=>$kategoriumum,'interpretasi'=>$interpretasi); + $this->sys_ok(["records"=>$rst]); + } + + function getpapsmearresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT Other_PapSmearDetailsID as xid, + Other_PapSmearID as header_id, + Other_PapSmearT_OrderDetailID as orderdetail_id, + Other_PapSmearDetailsCode as code, + Other_PapSmearDetailsLabel as label, + Other_PapSmearDetailsResult as result, + IFNULL(Other_PapSmearM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_PapSmearM_DoctorID) OR Other_PapSmearM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_papsmear + JOIN other_papsmeardetails ON Other_PapSmearDetailsOther_PapSmearID = Other_PapSmearID AND Other_PapSmearDetailsIsActive = 'Y' + LEFT JOIN m_doctor ON Other_PapSmearM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_PapSmearT_OrderDetailID = {$id} AND Other_PapSmearIsActive = 'Y' + GROUP BY Other_PapSmearDetailsID + ORDER BY Other_PapSmearDetailsCode ASC"; + //echo $sql; + $rows = $this->db_smartone->query($sql)->result_array(); + if(!$rows){ + $rows = array( + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'A', + 'label' => 'Makroskopik', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ), + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'B', + 'label' => 'Mikroskopik', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ), + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'C', + 'label' => 'Kesimpulan', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ) + ); + } + + $header_id = $rows[0]['header_id']; + $sql = "SELECT Other_PapSmearMaturasiID as xid, + Other_PapSmearMaturasiValue as value + FROM other_papsmearmaturasi + WHERE + Other_PapSmearMaturasiOther_PapSmearID = {$header_id} AND + Other_PapSmearMaturasiIsActive = 'Y' + "; + //echo $sql; + $dt_maturasi = $this->db_smartone->query($sql)->row_array(); + if(!$dt_maturasi){ + $maturasi = array('xid'=>'0','value'=> array('','','')); + } + else{ + $value = explode('/',$dt_maturasi['value']); + $maturasi = array('xid'=>$dt_maturasi['xid'],'value'=> $value); + } + + $sql = "SELECT IFNULL(Other_PapSmearBahanID,0) as xid, + M_PapSmearBahanID as bahan_id, + M_PapSmearBahanName as name, + IF(ISNULL(Other_PapSmearBahanID),'N','Y') as selected + FROM m_papsmearbahan + LEFT JOIN other_papsmearbahan ON Other_PapSmearBahanM_PapSmearBahanID = M_PapSmearBahanID AND + Other_PapSmearBahanOther_PapSmearID = {$header_id} AND + Other_PapSmearBahanIsActive = 'Y' + WHERE + M_PapSmearBahanIsActive = 'Y' + ORDER BY M_PapSmearBahanID ASC + "; + //echo $sql; + $bahans = $this->db_smartone->query($sql)->result_array(); + + $sql = "SELECT IFNULL(Other_PapsmearCategoryID,0) as xid, + M_PapSmearCategoryID as category_id, + M_PapSmearCategoryName as name, + IF(ISNULL(Other_PapsmearCategoryID),'N','Y') as selected + FROM m_papsmearcategory + LEFT JOIN other_papsmearcategory ON Other_PapsmearCategoryM_PapSmearCategoryID = M_PapSmearCategoryID AND + Other_PapsmearCategoryOther_PapSmearID = {$header_id} AND + Other_PapsmearCategoryIsActive = 'Y' + WHERE + M_PapSmearCategoryIsActive = 'Y' + ORDER BY M_PapSmearCategoryID ASC + "; + //echo $sql; + $categories = $this->db_smartone->query($sql)->result_array(); + + $sql = "SELECT IFNULL(Other_PapSmearCheckID,0) as xid, + M_PapSmearCheckID as check_id, + M_PapSmearCheckLabel as name, + IF(ISNULL(Other_PapSmearCheckID),'N','Y') as selected, + Other_PapSmearCheckNote as note + FROM m_papsmearcheck + LEFT JOIN other_papsmearcheck ON Other_PapSmearCheckM_PapSmearCheckID = M_PapSmearCheckID AND + Other_PapSmearCheckOther_PapSmearID = {$header_id} AND + Other_PapSmearCheckIsActive = 'Y' + WHERE + M_PapSmearCheckIsActive = 'Y' + ORDER BY M_PapSmearCheckCode ASC + "; + $checks = $this->db_smartone->query($sql)->result_array(); + + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $rst = array('doctors'=>$doctors,'checks'=>$checks,'bahans'=>$bahans,'categories'=>$categories,'maturasi'=>$maturasi,'results'=>$rows); + $this->sys_ok(["records"=>$rst]); + + } + + function saveresult_lcprep() + { + $prm = $this->sys_input; + $detail_id = $prm['detail_id']; + $doctor_id = $prm['doctor']; + $adekuasi = $prm['adekuasi']; + $kategoriumum = $prm['kategoriumum']; + $interpretasi = $prm['interpretasi']; + $results = $prm['results']; + + $userid = $this->sys_user['M_UserID']; + + $header_id = 0; + $sql = "SELECT * FROM other_lcprep WHERE Other_LcprepT_orderDetailID = {$detail_id} AND Other_LcprepIsActive = 'Y'"; + $dt_header = $this->db_smartone->query($sql)->row_array(); + if($dt_header){ + $header_id = $dt_header['Other_LcprepID']; + } + if($header_id == 0){ + $sql = "INSERT INTO other_lcprep( + Other_LcprepT_orderDetailID, + Other_LcprepM_DoctorID, + Other_LcprepUserID, + Other_LcprepCreated + ) + VALUES( + {$detail_id}, + {$doctor_id}, + {$userid}, + NOW() + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + }else{ + $sql = "UPDATE other_lcprep SET Other_LcprepM_DoctorID = {$doctor_id}, Other_LcprepUserID = {$userid} WHERE Other_LcprepID = {$header_id}"; + $this->db_smartone->query($sql); + } + + if($adekuasi){ + foreach($adekuasi as $k =>$v){ + $selected = $v['chex']?'Y':'N'; + if(intval($v['xid'] == 0)){ + $sql = "UPDATE other_lcprepadekuasi SET Other_LcprepAdekuasiIsActive = 'N' + WHERE + Other_LcprepAdekuasiOther_LcprepID = {$header_id} AND + Other_LcprepAdekuasiIsActive = 'Y' AND + Other_LcprepAdekuasiLcprep_AdekuasiID = {$v['id']}"; + $this->db_smartone->query($sql); + $sql = "INSERT INTO other_lcprepadekuasi ( + Other_LcprepAdekuasiOther_LcprepID, + Other_LcprepAdekuasiLcprep_AdekuasiID, + Other_LcprepAdekuasiChex, + Other_LcprepAdekuasiUserID, + Other_LcprepAdekuasiCreated + ) + VALUES( + {$header_id}, + {$v['id']}, + '{$selected}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + //echo $sql; + } + if(intval($v['xid'] != 0)){ + + $sql = "UPDATE other_lcprepadekuasi SET + Other_LcprepAdekuasiChex = '{$selected}', + Other_LcprepAdekuasiUserID = {$userid} + WHERE + Other_LcprepAdekuasiID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + + //echo $sql; + } + } + + if($kategoriumum){ + foreach($kategoriumum as $k =>$v){ + $selected = $v['chex']?'Y':'N'; + if(intval($v['xid'] == 0)){ + $sql = "UPDATE other_lcprepkategoriumum SET Other_LcprepKategoriUmumIsActive = 'N' + WHERE + Other_LcprepKategoriUmumOther_LcprepID = {$header_id} AND + Other_LcprepKategoriUmumLcprep_KategoriUmumID = {$v['id']} AND + Other_LcprepKategoriUmumIsActive = 'Y' + "; + $this->db_smartone->query($sql); + $sql = "INSERT INTO other_lcprepkategoriumum ( + Other_LcprepKategoriUmumOther_LcprepID, + Other_LcprepKategoriUmumLcprep_KategoriUmumID, + Other_LcprepKategoriUmumChex, + Other_LcprepKategoriUmumUserID, + Other_LcprepKategoriUmumCreated + ) + VALUES( + {$header_id}, + {$v['id']}, + '{$selected}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if(intval($v['xid'] != 0)){ + $sql = "UPDATE other_lcprepkategoriumum SET + Other_LcprepKategoriUmumChex = '{$selected }', + Other_LcprepKategoriUmumUserID = {$userid} + WHERE + Other_LcprepKategoriUmumID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + + //echo $sql; + } + } + + if($results){ + foreach($results as $k =>$v){ + if(intval($v['xid'] == 0)){ + $sql = "UPDATE other_lcprepdetails SET Other_LcprepDetailsIsActive = 'N' + WHERE + Other_LcprepDetailsOther_LcprepID = {$header_id} AND + Other_LcprepDetailsCode = '{$v['code']}' AND + Other_LcprepDetailsIsActive = 'Y'"; + $this->db_smartone->query($sql); + $sql = "INSERT INTO other_lcprepdetails ( + Other_LcprepDetailsOther_LcprepID, + Other_LcprepDetailsCode, + Other_LcprepDetailsLabel, + Other_LcprepDetailsResult, + Other_LcprepDetailsUserID, + Other_LcprepDetailsCreated + ) + VALUES( + {$header_id}, + '{$v['code']}', + '{$v['label']}', + '{$v['result']}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if(intval($v['xid'] != 0)){ + $sql = "UPDATE other_lcprepdetails SET + Other_LcprepDetailsCode = '{$v['code']}', + Other_LcprepDetailsLabel = '{$v['label']}', + Other_LcprepDetailsResult = '{$v['result']}', + Other_LcprepDetailsUserID = {$userid} + WHERE + Other_LcprepDetailsID = {$v['xid']}"; + $this->db_smartone->query($sql); + + } + //echo $sql; + } + } + + if($interpretasi){ + foreach($interpretasi as $k =>$v){ + if(count($v['subgroups']) > 0){ + foreach($v['subgroups'] as $ik => $iv){ + if(count($iv['childs']) > 0){ + foreach($iv['childs'] as $iik => $iiv){ + if(intval($iiv['xid'] == 0)){ + $chex = $iiv['chex'] ? 'Y':'N'; + $sql = "UPDATE other_lcprepinterpretasi SET Other_LcprepInterpretasiIsActive = 'N' + WHERE + Other_LcprepInterpretasiOther_LcprepID = {$header_id} AND + Other_LcprepInterpretasiLcprep_InterpretasiID = '{$iiv['id']}' AND + Other_LcprepInterpretasiIsActive = 'Y'"; + $this->db_smartone->query($sql); + $sql = "INSERT INTO other_lcprepinterpretasi ( + Other_LcprepInterpretasiOther_LcprepID, + Other_LcprepInterpretasiLcprep_InterpretasiID, + Other_LcprepInterpretasiChex, + Other_LcprepInterpretasiValue, + Other_LcprepInterpretasiUserID, + Other_LcprepInterpretasiCreated + ) + VALUES( + {$header_id}, + '{$iiv['id']}', + '{$chex}', + '{$iiv['value']}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + + if(intval($iiv['xid'] != 0)){ + $chex = $iiv['chex'] ? 'Y':'N'; + $sql = "UPDATE other_lcprepinterpretasi SET + Other_LcprepInterpretasiChex = '{$chex}', + Other_LcprepInterpretasiValue = '{$iiv['value']}', + Other_LcprepInterpretasiUserID = {$userid} + WHERE + Other_LcprepInterpretasiID = {$iiv['xid']}"; + $this->db_smartone->query($sql); + //echo $sql; + + } + + } + } + } + } + //echo $sql; + } + } + + + $result = array("total" => 1, "records" => array(), "sql"=> ''); + $this->sys_ok($result); + exit; + } + + function saveresult_papsmear() + { + $prm = $this->sys_input; + $detail_id = $prm['detail_id']; + $doctor_id = $prm['doctor']; + $checks = $prm['checks']; + $maturasi = $prm['maturasi']; + $bahans = $prm['bahans']; + $categories = $prm['categories']; + $results = $prm['results']; + + $userid = $this->sys_user['M_UserID']; + + $header_id = 0; + $sql = "SELECT * FROM other_papsmear WHERE Other_PapSmearT_OrderDetailID = {$detail_id} AND Other_PapSmearIsActive = 'Y'"; + $dt_header = $this->db_smartone->query($sql)->row_array(); + if($dt_header){ + $header_id = $dt_header['Other_PapSmearID']; + } + if($header_id == 0){ + $sql = "INSERT INTO other_papsmear( + Other_PapSmearT_OrderDetailID, + Other_PapSmearM_DoctorID, + Other_PapSmearUserID, + Other_PapSmearCreated + ) + VALUES( + {$detail_id}, + {$doctor_id}, + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } + else{ + $sql = "UPDATE other_papsmear SET Other_PapSmearM_DoctorID = {$doctor_id}, Other_PapSmearUserID = {$userid} WHERE Other_PapSmearID = {$header_id}"; + $this->db_smartone->query($sql); + } + + if($checks){ + foreach($checks as $k =>$v){ + if(intval($v['xid']) == 0 && $v['selected'] === 'Y'){ + $sql = "INSERT INTO other_papsmearcheck ( + Other_PapSmearCheckOther_PapSmearID, + Other_PapSmearCheckM_PapSmearCheckID, + Other_PapSmearCheckNote, + Other_PapSmearCheckUserID, + Other_PapSmearCheckCreated + ) + VALUES( + {$header_id}, + {$v['check_id']}, + '{$v['note']}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if(intval($v['xid']) != 0 && $v['selected'] === 'N'){ + $sql = "UPDATE other_papsmearcheck SET + Other_PapSmearCheckIsActive = 'N', + Other_PapSmearCheckUserID = {$userid} + WHERE + Other_PapSmearCheckID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + if(intval($v['xid']) != 0 && $v['selected'] === 'Y'){ + $sql = "UPDATE other_papsmearcheck SET + Other_PapSmearCheckNote = '{$v['note']}', + Other_PapSmearCheckUserID = {$userid} + WHERE + Other_PapSmearCheckID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + //echo $sql; + } + } + + if($maturasi){ + if(intval($maturasi['xid']) == 0){ + $value = join("/",$maturasi['value']); + $sql = "INSERT INTO other_papsmearmaturasi ( + Other_PapSmearMaturasiOther_PapSmearID, + Other_PapSmearMaturasiValue, + Other_PapSmearMaturasiUserID, + Other_PapSmearMaturasiCreated + ) + VALUE( + {$header_id}, + '{$value}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + //echo $sql; + } + if(intval($maturasi['xid']) != 0){ + $value = join("/",$maturasi['value']); + $sql = "UPDATE other_papsmearmaturasi SET + Other_PapSmearMaturasiValue = '{$value}', + Other_PapSmearMaturasiUserID = {$userid} + WHERE + Other_PapSmearMaturasiID = {$maturasi['xid']}"; + // echo $sql; + $this->db_smartone->query($sql); + } + } + + if($bahans){ + foreach($bahans as $k =>$v){ + if(intval($v['xid']) == 0 && $v['selected'] === 'Y'){ + $sql = "INSERT INTO other_papsmearbahan ( + Other_PapSmearBahanOther_PapSmearID, + Other_PapSmearBahanM_PapSmearBahanID, + Other_PapSmearBahanUserID, + Other_PapSmearBahanCreated + ) + VALUES( + {$header_id}, + {$v['bahan_id']}, + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if(intval($v['xid']) != 0 && $v['selected'] === 'N'){ + $sql = "UPDATE other_papsmearbahan SET + Other_PapSmearBahanIsActive = 'N', + Other_PapsmearCategoryUserID = {$userid} + WHERE + Other_PapSmearBahanID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + if(intval($v['xid']) != 0 && $v['selected'] === 'Y'){ + $sql = "UPDATE other_papsmearbahan SET + Other_PapSmearBahanIsActive = 'Y', + Other_PapsmearCategoryUserID = {$userid} + WHERE + Other_PapSmearBahanID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + //echo $sql; + } + } + + if($categories){ + foreach($categories as $k =>$v){ + if(intval($v['xid']) == 0 && $v['selected'] === 'Y'){ + $sql = "INSERT INTO other_papsmearcategory ( + Other_PapsmearCategoryOther_PapSmearID, + Other_PapsmearCategoryM_PapSmearCategoryID, + Other_PapsmearCategoryUserID, + Other_PapsmearCategoryCreated + ) + VALUES( + {$header_id}, + {$v['category_id']}, + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if(intval($v['xid']) != 0 && $v['selected'] === 'N'){ + $sql = "UPDATE other_papsmearcategory SET + Other_PapsmearCategoryIsActive = 'N', + Other_PapsmearCategoryUserID = {$userid} + WHERE + Other_PapsmearCategoryID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + //echo $sql; + if(intval($v['xid']) != 0 && $v['selected'] === 'Y'){ + $sql = "UPDATE other_papsmearcategory SET + Other_PapsmearCategoryIsActive = 'Y', + Other_PapsmearCategoryUserID = {$userid} + WHERE + Other_PapsmearCategoryID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + } + } + + if($results){ + foreach($results as $k =>$v){ + if(intval($v['xid']) == 0){ + $sql = "INSERT INTO other_papsmeardetails ( + Other_PapSmearDetailsOther_PapSmearID, + Other_PapSmearDetailsCode, + Other_PapSmearDetailsLabel, + Other_PapSmearDetailsResult, + Other_PapSmearDetailsUserID, + Other_PapSmearDetailsCreated + ) + VALUES( + {$header_id}, + '{$v['code']}', + '{$v['label']}', + '{$v['result']}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if(intval($v['xid']) != 0){ + $sql = "UPDATE other_papsmeardetails SET + Other_PapSmearDetailsCode = '{$v['code']}', + Other_PapSmearDetailsLabel = '{$v['label']}', + Other_PapSmearDetailsResult = '{$v['result']}', + Other_PapSmearDetailsUserID = {$userid} + WHERE + Other_PapSmearDetailsID = {$v['xid']}"; + $this->db_smartone->query($sql); + + } + //echo $sql; + } + } + + $result = array("total" => 1, "records" => array(), "sql"=> ''); + $this->sys_ok($result); + exit; + } + + function saveresult_fna() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = $inp['doctor']; + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + if($prm[0]['xid'] == '0'){ + $sql = "INSERT INTO other_fna( + Other_FNAM_DoctorID, + Other_FNAT_OrderDetailID, + Other_FNAUserID, + Other_FNACreated + ) + VALUES( + {$doctor_id}, + {$prm[0]['orderdetail_id']}, + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } + else{ + $sql = "SELECT * FROM other_fna WHERE Other_FNAT_OrderDetailID = {$prm[0]['orderdetail_id']} AND Other_FNAIsActive = 'Y'"; + $data_header = $this->db_smartone->query($sql)->row_array(); + $header_id = $data_header['Other_FNAID']; + $sql = "UPDATE other_fna SET + Other_FNAM_DoctorID = {$doctor_id}, + Other_FNAUserID = {$userid} + WHERE + Other_FNAID = {$header_id}"; + $this->db_smartone->query($sql); + } + foreach($prm as $k => $v){ + if($v['xid'] == '0'){ + $results = str_replace("'", "\\'", $v['result']); + $sql = "INSERT INTO other_fnadetails( + Other_FNADetailsOther_FNAID , + Other_FNADetailsCode, + Other_FNADetailsLabel, + Other_FNADetailsResult, + Other_FNADetailsCreated, + Other_FNADetailsUserID + ) + VALUES( + {$header_id}, + '{$v['code']}', + '{$v['label']}', + '{$results}', + NOW(), + {$userid} + )"; + $query = $this->db_smartone->query($sql); + } + else{ + $results = str_replace("'", "\\'", $v['result']); + $sql = "UPDATE other_fnadetails SET + Other_FNADetailsResult = '{$results}', + Other_FNADetailsUserID = {$userid} + WHERE + Other_FNADetailsID = {$v['xid']}"; + $query = $this->db_smartone->query($sql); + } + } + + $result = array("total" => 1, "records" => array(), "sql"=> ''); + $this->sys_ok($result); + exit; + } + + function saveresult_cytologi() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = $inp['doctor']; + + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + if($prm[0]['xid'] == '0'){ + $sql = "INSERT INTO other_cytologi( + Other_CytologiT_OrderDetailID, + Other_CytologiM_DoctorID, + Other_CytologiUserID, + Other_CytologiCreated + ) + VALUES( + {$prm[0]['orderdetail_id']}, + {$doctor_id}, + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } + else{ + $sql = "SELECT * FROM other_cytologi WHERE Other_CytologiT_OrderDetailID = {$prm[0]['orderdetail_id']} AND Other_CytologiIsActive = 'Y'"; + $data_header = $this->db_smartone->query($sql)->row_array(); + $header_id = $data_header['Other_CytologiID']; + $sql = "UPDATE other_cytologi SET + Other_CytologiM_DoctorID = {$doctor_id}, + Other_CytologiUserID = {$userid} + WHERE + Other_CytologiID = {$header_id}"; + $this->db_smartone->query($sql); + } + foreach($prm as $k => $v){ + if($v['xid'] == '0'){ + $results = str_replace("'", "\\'", $v['result']); + $sql = "INSERT INTO other_cytologidetails( + Other_CytologiDetailsOther_CytologiID , + Other_CytologiDetailsCode, + Other_CytologiDetailsLabel, + Other_CytologiDetailsResult, + Other_CytologiDetailsCreated, + Other_CytologiDetailsUserID + ) + VALUES( + {$header_id}, + '{$v['code']}', + '{$v['label']}', + '{$results}', + NOW(), + {$userid} + )"; + $query = $this->db_smartone->query($sql); + } + else{ + $results = str_replace("'", "\\'", $v['result']); + $sql = "UPDATE other_cytologidetails SET + Other_CytologiDetailsResult = '{$results}', + Other_CytologiDetailsUserID = {$userid} + WHERE + Other_CytologiDetailsID = {$v['xid']}"; + $query = $this->db_smartone->query($sql); + } + } + + $result = array("total" => 1, "records" => array(), "sql"=> ''); + $this->sys_ok($result); + exit; + } + + function saveresult_mikro() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = $inp['doctor']; + $backteria_id = $inp['bacteria']; + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + + if($inp['result_value'] != 'Negatif' && $inp['result_value'] != 'Positif'){ + $prm['result_value'] = $prm['result_other']; + } + else{ + $prm['result_value'] = $inp['result_value']; + } + + if($prm['xid'] == '0'){ + $sql = "INSERT INTO other_mikro( + Other_MikroM_DoctorID, + Other_MikroResult, + Other_MikroT_BacteriaID, + Other_MikroT_OrderDetailID, + Other_MikroHasilBiakan, + Other_MikroSampleTypeName, + Other_MikroUserID, + Other_MikroCreated + ) + VALUES( + {$doctor_id}, + '{$prm['result_value']}', + {$backteria_id}, + {$prm['orderdetail_id']}, + '{$prm['hasil_biakan']}', + '{$prm['sample_name']}', + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } + else{ + $sql = "SELECT * FROM other_mikro WHERE Other_MikroT_OrderDetailID = {$prm['orderdetail_id']} AND Other_MikroIsActive = 'Y'"; + $data_header = $this->db_smartone->query($sql)->row_array(); + $header_id = $data_header['Other_MikroID']; + $sql = "UPDATE other_mikro SET + Other_MikroResult = '{$prm['result_value']}', + Other_MikroM_DoctorID = {$doctor_id}, + Other_MikroT_BacteriaID = {$backteria_id}, + Other_MikroHasilBiakan = '{$prm['hasil_biakan']}', + Other_MikroSampleTypeName = '{$prm['sample_name']}', + Other_MikroUserID = {$userid} + WHERE + Other_MikroID = {$header_id}"; + //echo $sql; + $this->db_smartone->query($sql); + } + + + + $sql = "UPDATE other_mikrodetails SET Other_MikroDetailsIsActive = 'N', Other_MikroDetailsUserID = 0 WHERE Other_MikroDetailsOther_MikroID = {$header_id}"; + $this->db_smartone->query($sql); + + $results = $prm['details']; + if($inp['result_value'] == 'Positif'){ + foreach($results as $k => $v){ + if($v['xid'] == '0'){ + $sql = "INSERT INTO other_mikrodetails( + Other_MikroDetailsOther_MikroID , + Other_MikroDetailsT_AntibioticID, + Other_MikroDetailsValue, + Other_MikroDetailsNote, + Other_MikroDetailsCreated, + Other_MikroDetailsUserID + ) + VALUES( + {$header_id}, + '{$v['T_AntibioticID']}', + '{$v['value']}', + '{$v['note']}', + NOW(), + {$userid} + )"; + $query = $this->db_smartone->query($sql); + } + else{ + $sql = "UPDATE other_mikrodetails SET + Other_MikroDetailsT_AntibioticID = '{$v['T_AntibioticID']}', + Other_MikroDetailsValue = '{$v['value']}', + Other_MikroDetailsNote = '{$v['note']}', + Other_MikroDetailsIsActive = 'Y', + Other_MikroDetailsUserID = {$userid} + WHERE + Other_MikroDetailsID = {$v['xid']}"; + //echo $sql; + $query = $this->db_smartone->query($sql); + } + } + } + + + $result = array("total" => 1, "records" => array(), "sql"=> ''); + $this->sys_ok($result); + exit; + } + + + function get_doctors_preparasi_sperma() + { + $prm = $this->sys_input; + // $id = $prm["id"]; + + $sql = " SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 10 AND + M_DoctorSOIsActive = 'Y' + ORDER BY M_DoctorName ASC"; + //echo $sql; + $query = $this->db_smartone->query($sql); + $rows = $query->result_array(); + $sql = " + SELECT '0' as id, 'Belum memilih metode' as name + UNION + SELECT M_MethodeSpermaID as id, M_MethodeSpermaName as name + FROM m_methodesperma + WHERE + M_MethodeSpermaIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $methodes = $this->db_smartone->query($sql)->result_array(); + + + $this->sys_ok(["records"=>$rows,"methodes"=>$methodes]); + + } + + + function getpreparasispermaresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT other_preparasisperma.*, + Other_PreparasiSpermaID as xid, + Other_PreparasiSpermaT_OrderDetailID as orderdetail_id, + IFNULL(Other_PreparasiSpermaM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_PreparasiSpermaM_DoctorID) OR Other_PreparasiSpermaM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name, + IFNULL(M_MethodeSpermaID,0) as methode_id, + IFNULL(M_MethodeSpermaName,'') as methode_name + FROM other_preparasisperma + LEFT JOIN m_doctor ON Other_PreparasiSpermaM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + LEFT JOIN m_methodesperma ON Other_PreparasiSpermaM_MethodeSpermaID = M_MethodeSpermaID AND + M_MethodeSpermaIsActive = 'Y' + WHERE + Other_PreparasiSpermaT_OrderDetailID = {$id} AND Other_PreparasiSpermaIsActive = 'Y' + GROUP BY Other_PreparasiSpermaID"; + $query = $this->db_smartone->query($sql); + + if ($query) + { + $rows = $query->row_array(); + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 10 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $sql = " + SELECT '0' as id, 'Belum memilih metode' as name + UNION + SELECT M_MethodeSpermaID as id, M_MethodeSpermaName as name + FROM m_methodesperma + WHERE + M_MethodeSpermaIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $methodes = $this->db_smartone->query($sql)->result_array(); + $images = array(); + $sql = "SELECT Other_PreparasiSpermaImgID as xid, + Other_PreparasiSpermaImgType as type, + CONCAT('/one-media/one-image-nonlab/',Other_PreparasiSpermaImgNewName) as image_url + FROM t_orderdetail + JOIN other_preparasisperma_img ON Other_PreparasiSpermaImgT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND + Other_PreparasiSpermaImgIsActive = 'Y' + WHERE + T_OrderDetailID = {$id} AND + T_OrderDetailIsActive = 'Y' + GROUP BY Other_PreparasiSpermaImgID"; + //echo $sql; + $images = $this->db_smartone->query($sql)->result_array(); + + $rst = array('doctors'=>$doctors,'methodes'=>$methodes,'results'=>$rows,'images'=>$images); + $this->sys_ok(["records"=>$rst]); + } + else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + + function uploadimage_preparasi_sperma(){ + if (! $this->isLogin) { + $this->sys_error("Invalid Token"); + exit; + } + + $userid = $this->sys_user["M_UserID"]; + $data = []; + //print_r($_SERVER); + + $prm = $this->sys_input; + $orderid = $this->input->post('orderid'); + $type = $this->input->post('type'); + $labnumber = $this->input->post('labnumber'); + $sql = "UPDATE other_preparasisperma_img SET + Other_PreparasiSpermaImgIsActive = 'N', + Other_PreparasiSpermaImgUserID = {$userid} + WHERE + Other_PreparasiSpermaImgT_OrderHeaderID = {$orderid} AND + Other_PreparasiSpermaImgType = '{$type}'"; + //echo $sql; + $this->db_onedev->query($sql); + //$config['upload_path'] = 'assets/'; + + $path = '/home/one/project/one/one-media/one-image-nonlab/'; + //echo $path; + $config['upload_path'] = $path; + $config['allowed_types'] = 'jpg|jpeg|png|gif'; + + $config['max_size'] = '10000'; + $count = count($_FILES['files']['name']); + //echo $count; + $this->load->library('upload',$config); + + $error = []; + for($i=0;$i<$count;$i++){ + + + if(!empty($_FILES['files']['name'][$i])){ + + + + $_FILES['file']['name'] = $_FILES['files']['name'][$i]; + + $_FILES['file']['type'] = $_FILES['files']['type'][$i]; + + $_FILES['file']['tmp_name'] = $_FILES['files']['tmp_name'][$i]; + + $_FILES['file']['error'] = $_FILES['files']['error'][$i]; + + $_FILES['file']['size'] = $_FILES['files']['size'][$i]; + + + + $namex = $orderid.'-'.$labnumber.'-'.$this->generateRandomString(5); + //echo $namex; + + $config['file_name'] = $namex; + $this->upload->initialize($config); + //echo $config['file_name'] ; + + + + + + if($this->upload->do_upload('file')){ + + $uploadData = $this->upload->data(); + + $filename = $uploadData['file_name']; + //echo $filename; + + + $sql = "INSERT INTO other_preparasisperma_img ( + Other_PreparasiSpermaImgT_OrderHeaderID, + Other_PreparasiSpermaImgType, + Other_PreparasiSpermaImgOldName, + Other_PreparasiSpermaImgNewName, + Other_PreparasiSpermaImgCreated, + Other_PreparasiSpermaImgUserID + ) + VALUES( + {$orderid}, + '{$type}', + '{$_FILES['files']['name'][$i]}', + '{$filename}', + NOW(), + {$userid} + + )"; + //echo $sql; + $this->db_onedev->query($sql); + $xlast_id = $this->db_onedev->insert_id(); + $data['totalFiles'][] = array('xid' => $xlast_id ,'type'=>$type,'image_url' => '/one-media/one-image-nonlab/'.$filename); + + } + else{ + $error = array('error' => $this->upload->display_errors()); + } + + } + + + + } + + $result = array("total" =>count( $data['totalFiles']), "records" => $data['totalFiles'],'errors'=>$error); + $this->sys_ok($result); + } + + + function saveresult_preparasi_sperma() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = isset($inp['doctor'])?$inp['doctor']:0; + $methode_id = isset($inp['methode'])?$inp['methode']:0; + $orderdetail_id = $inp['orderdetailid']; + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + if($prm['xid'] == '0'){ + $sql = "INSERT INTO other_preparasisperma( + Other_PreparasiSpermaM_DoctorID, + Other_PreparasiSpermaT_OrderDetailID, + Other_PreparasiSpermaPreMotilitasA, + Other_PreparasiSpermaPreMotilitasB, + Other_PreparasiSpermaPreMotilitasC, + Other_PreparasiSpermaPreKonsentrasi, + Other_PreparasiSpermaPreKontaminan, + Other_PreparasiSpermaPostMotilitasA, + Other_PreparasiSpermaPostMotilitasB, + Other_PreparasiSpermaPostMotilitasC, + Other_PreparasiSpermaPostKonsentrasi, + Other_PreparasiSpermaPostKontaminan, + Other_PreparasiSpermaPreVolume, + Other_PreparasiSpermaPostVolume, + Other_PreparasiSpermaM_MethodeSpermaID, + Other_PreparasiSpermaNote, + Other_PreparasiSpermaUserID, + Other_PreparasiSpermaCreated + ) + VALUES( + {$doctor_id}, + {$orderdetail_id}, + '{$prm['Other_PreparasiSpermaPreMotilitasA']}', + '{$prm['Other_PreparasiSpermaPreMotilitasB']}', + '{$prm['Other_PreparasiSpermaPreMotilitasC']}', + '{$prm['Other_PreparasiSpermaPreKonsentrasi']}', + '{$prm['Other_PreparasiSpermaPreKontaminan']}', + '{$prm['Other_PreparasiSpermaPostMotilitasA']}', + '{$prm['Other_PreparasiSpermaPostMotilitasB']}', + '{$prm['Other_PreparasiSpermaPostMotilitasC']}', + '{$prm['Other_PreparasiSpermaPostKonsentrasi']}', + '{$prm['Other_PreparasiSpermaPostKontaminan']}', + '{$prm['Other_PreparasiSpermaPreVolume']}', + '{$prm['Other_PreparasiSpermaPostVolume']}', + '{$methode_id}', + '{$prm['Other_PreparasiSpermaNote']}', + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } + else{ + $sql = "SELECT * FROM other_preparasisperma WHERE Other_PreparasiSpermaT_OrderDetailID = {$orderdetail_id} AND Other_PreparasiSpermaIsActive = 'Y'"; + $data_header = $this->db_smartone->query($sql)->row_array(); + $header_id = $data_header['Other_PreparasiSpermaID']; + $sql = "UPDATE other_preparasisperma SET + Other_PreparasiSpermaM_DoctorID = {$doctor_id}, + Other_PreparasiSpermaPreMotilitasA = '{$prm['Other_PreparasiSpermaPreMotilitasA']}', + Other_PreparasiSpermaPreMotilitasB = '{$prm['Other_PreparasiSpermaPreMotilitasB']}', + Other_PreparasiSpermaPreMotilitasC = '{$prm['Other_PreparasiSpermaPreMotilitasC']}', + Other_PreparasiSpermaPreKonsentrasi = '{$prm['Other_PreparasiSpermaPreKonsentrasi']}', + Other_PreparasiSpermaPreKontaminan = '{$prm['Other_PreparasiSpermaPreKontaminan']}', + Other_PreparasiSpermaPostMotilitasA = '{$prm['Other_PreparasiSpermaPostMotilitasA']}', + Other_PreparasiSpermaPostMotilitasB = '{$prm['Other_PreparasiSpermaPostMotilitasB']}', + Other_PreparasiSpermaPostMotilitasC = '{$prm['Other_PreparasiSpermaPostMotilitasC']}', + Other_PreparasiSpermaPostKonsentrasi = '{$prm['Other_PreparasiSpermaPostKonsentrasi']}', + Other_PreparasiSpermaPostKontaminan = '{$prm['Other_PreparasiSpermaPostKontaminan']}', + Other_PreparasiSpermaPreVolume = '{$prm['Other_PreparasiSpermaPreVolume']}', + Other_PreparasiSpermaPostVolume = '{$prm['Other_PreparasiSpermaPostVolume']}', + Other_PreparasiSpermaM_MethodeSpermaID = '{$methode_id}', + Other_PreparasiSpermaNote = '{$prm['Other_PreparasiSpermaNote']}', + Other_PreparasiSpermaUserID = {$userid} + WHERE + Other_PreparasiSpermaID = {$header_id}"; + $this->db_smartone->query($sql); + } + + + $result = array("total" => 1, "records" => array(), "sql"=> ''); + $this->sys_ok($result); + exit; + } + + function getdnafragmentasiresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT other_dnafragmentasi.*, + Other_DnaFragmentasiID as xid, + Other_DnaFragmentasiT_OrderDetailID as orderdetail_id, + IFNULL(Other_DnaFragmentasiM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_DnaFragmentasiM_DoctorID) OR Other_DnaFragmentasiM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name, + IFNULL(Other_DnaFragmentasiOther_DnaFragmentasiMethodeID,0) as methode_id, + IFNULL(Other_DnaFragmentasiMethodeName,'') as methode_name, + Other_DnaFragmentasiHaloLuas as halo_luas, + Other_DnaFragmentasiHaloSedang as halo_sedang, + Other_DnaFragmentasiHaloSempit as halo_sempit, + Other_DnaFragmentasiTanpaHalo as tanpa_halo, + Other_DnaFragmentasiDFI as dfi, + Other_DnaFragmentasiKesimpulan as kesimpulan, + Other_DnaFragmentasiCatatan as catatan + FROM other_dnafragmentasi + LEFT JOIN m_doctor ON Other_DnaFragmentasiM_DoctorID = M_DoctorID + LEFT JOIN other_dnafragmentasimethode ON Other_DnaFragmentasiOther_DnaFragmentasiMethodeID = Other_DnaFragmentasiMethodeID + WHERE + Other_DnaFragmentasiT_OrderDetailID = {$id} AND Other_DnaFragmentasiIsActive = 'Y' + GROUP BY Other_DnaFragmentasiID + LIMIT 1"; + //echo $sql; + $query = $this->db_smartone->query($sql); + + if ($query) + { + $rows = $query->row_array(); + if(!$rows){ + $rows = array( + 'xid' => 0, + 'orderdetail_id' =>$id, + 'doctor_id' => 0, + 'doctor_name' => '', + 'methode_id' => 0, + 'methode_name' => '', + 'halo_luas' => '', + 'halo_sedang' => '', + 'tanpa_halo' => '', + 'dfi' => '', + 'kesimpulan' => '', + 'catatan' => '' + ); + } + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID + WHERE + M_DoctorSONat_SubGroupID = 4 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + + $sql = " + SELECT '0' as id, 'Belum memilih metode' as name + UNION + SELECT Other_DnaFragmentasiMethodeID as id, Other_DnaFragmentasiMethodeName as name + FROM other_dnafragmentasimethode + WHERE + Other_DnaFragmentasiMethodeIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $methodes = $this->db_smartone->query($sql)->result_array(); + + + $rst = array('doctors'=>$doctors,'methodes'=>$methodes,'results'=>$rows); + $this->sys_ok(["records"=>$rst]); + } + else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + function saveresult_dnafragmentasi() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = $inp['doctor']['id']; + $methode_id = $inp['methode']['id']; + $orderdetail_id = $inp['results']['orderdetail_id']; + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + if(intval($prm['xid']) == 0){ + $sql = "INSERT INTO other_dnafragmentasi( + Other_DnaFragmentasiT_OrderDetailID, + Other_DnaFragmentasiM_DoctorID, + Other_DnaFragmentasiOther_DnaFragmentasiMethodeID, + Other_DnaFragmentasiHaloLuas, + Other_DnaFragmentasiHaloSedang, + Other_DnaFragmentasiHaloSempit, + Other_DnaFragmentasiTanpaHalo, + Other_DnaFragmentasiDFI, + Other_DnaFragmentasiKesimpulan, + Other_DnaFragmentasiCatatan, + Other_DnaFragmentasiUserID, + Other_DnaFragmentasiLastUpdated + ) + VALUES( + {$orderdetail_id}, + {$doctor_id}, + {$methode_id}, + '{$prm['halo_luas']}', + '{$prm['halo_sedang']}', + '{$prm['halo_sempit']}', + '{$prm['tanpa_halo']}', + '{$prm['dfi']}', + '{$prm['kesimpulan']}', + '{$prm['catatan']}', + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } + else{ + $sql = "UPDATE other_dnafragmentasi SET + Other_DnaFragmentasiT_OrderDetailID = {$orderdetail_id}, + Other_DnaFragmentasiM_DoctorID = {$doctor_id}, + Other_DnaFragmentasiOther_DnaFragmentasiMethodeID = '{$methode_id}', + Other_DnaFragmentasiHaloLuas = '{$prm['halo_luas']}', + Other_DnaFragmentasiHaloSedang = '{$prm['halo_sedang']}', + Other_DnaFragmentasiHaloSempit = '{$prm['halo_sempit']}', + Other_DnaFragmentasiTanpaHalo = '{$prm['tanpa_halo']}', + Other_DnaFragmentasiDFI = '{$prm['dfi']}', + Other_DnaFragmentasiKesimpulan = '{$prm['kesimpulan']}', + Other_DnaFragmentasiCatatan = '{$prm['catatan']}', + Other_DnaFragmentasiLastUpdated = NOW(), + Other_DnaFragmentasiUserID = {$userid} + WHERE + Other_DnaFragmentasiID = {$prm['xid']}"; + //echo $sql; + $this->db_smartone->query($sql); + } + + + $result = array("total" => 1, "records" => array(), "sql"=> ''); + $this->sys_ok($result); + exit; + } + + +} + diff --git a/application/controllers/mockup/process/resultentry-v21/9/Re_px.php b/application/controllers/mockup/process/resultentry-v21/9/Re_px.php index 08699539..e0631de5 100644 --- a/application/controllers/mockup/process/resultentry-v21/9/Re_px.php +++ b/application/controllers/mockup/process/resultentry-v21/9/Re_px.php @@ -1,2467 +1,2464 @@ -db_smartone = $this->load->database("onedev", true); - $this->load->helper(array('form', 'url')); - } - function getMethodeID($natTestID) { - $sql = "select M_MethodePriorityNat_MethodeID MethodeID, Nat_MethodeName - from - m_methode_priority - join nat_methode on Nat_MethodeID = M_MethodePriorityNat_MethodeID - and Nat_MethodeIsActive = 'Y' - join m_instrumentmethode on M_InstrumentMethodeNat_MethodeID = Nat_MethodeID and M_InstrumentMethodeIsActive = 'Y' - join nat_instrument on M_InstrumentMethodeNat_InstrumentID = Nat_InstrumentID - and Nat_InstrumentIsActive ='Y' - where M_MethodePriorityIsActive = 'Y' - and M_MethodePriorityNat_TestID = $natTestID - and M_MethodePriorityM_DayOfWeekID = dayofweek(now()) - order by M_MethodePriorityNumber desc - limit 0,1 "; - $qry = $this->db->query($sql); - if ($qry) { - $rows = $qry->result_array(); - if (count($rows) > 0 ) return array($rows[0]["MethodeID"],$rows[0]["Nat_MethodeName"]); - } - //2nd - $sql= "select - M_InstrumentMethodeNat_MethodeID MethodeID, Nat_MethodeName - from m_instrumentmethode - join nat_methode on M_InstrumentMethodeNat_MethodeID = Nat_MethodeID - and Nat_MethodeIsActive = 'Y' - join nat_instrument on M_InstrumentMethodeNat_InstrumentID = Nat_InstrumentID - and Nat_InstrumentIsActive ='Y' - where M_InstrumentMethodeNat_TestID = $natTestID - and M_InstrumentMethodeIsActive = 'Y' - order by M_InstrumentMethodePriority desc - limit 0,1"; - $qry = $this->db->query($sql); - if ($qry) { - $rows = $qry->result_array(); - if (count($rows) > 0 ) return array($rows[0]["MethodeID"],$rows[0]["Nat_MethodeName"]); - } - // - $sql = "select Nat_NormalValueNat_MethodeID MethodeID, Nat_MethodeName - from - nat_normalvalue - join nat_methode on Nat_NormalValueNat_MethodeID = Nat_MethodeID - and Nat_MethodeIsActive = 'Y' - where Nat_NormalValueNat_TestID = $natTestID - and Nat_NormalValueIsActive = 'Y' - order by Nat_NormalValueID - limit 0,1"; - $qry = $this->db->query($sql); - if ($qry) { - $rows = $qry->result_array(); - if (count($rows) > 0 ) return array($rows[0]["MethodeID"],$rows[0]["Nat_MethodeName"]); - } - return array(0,""); - } - function get_normal_value($methodeID, $natTestID, $sexID, $ageInDay ) { - $sql = "select fn_sampling_get_normal($methodeID, $natTestID, $sexID, $ageInDay) as normalValueID"; - $qry = $this->db->query($sql); - if ($qry) { - $rows = $qry->result_array(); - if (count($rows) > 0 ) return $rows[0]["normalValueID"]; - } - return 0; - } - function fn_fix_normal($order_id) { - $sql = "select - T_OrderDetailID, M_PatientM_SexID, fn_global_age_count_day(M_PatientDOB, date(T_OrderHeaderDate)) Dob , - T_TestNat_TestID - from t_orderheader - join m_patient on T_OrderHeaderID = $order_id and T_OrderHeaderM_PatientID = M_PatientID - join t_orderdetail on T_OrderDetailT_OrderHeaderID = T_OrderHeaderID - and T_OrderDetailIsACtive = 'Y' - and ( T_OrderDetailNat_NormalValueID is null or T_OrderDetailNat_NormalValueID = 0 ) - join t_test on T_OrderDetailT_TestID = T_TestID and T_TestIsResult = 'Y' "; - $qry = $this->db->query($sql); - if(! $qry) { - return; - } - $rows = $qry->result_array(); - if(count($rows) == 0 ) return; - $sql_u = "update t_orderdetail - join nat_normalvalue on T_OrderDetailID = ? and Nat_NormalValueID = ? - set - T_OrderDetailNat_NormalValueID = Nat_NormalValueID, - T_OrderDetailNormalValueNote = Nat_NormalValueNote, - T_OrderDetailNormalValueDescription = Nat_NormalValueDescription, - T_OrderDetailMinValue = Nat_NormalValueMinValue, - T_OrderDetailMaxValue = Nat_NormalValueMaxValue, - T_OrderDetailMinValueInclusive = Nat_NormalValueMinValueInclusive, - T_OrderDetailMaxValueInclusive = Nat_NormalValueMaxValueInclusive, - T_OrderDetailNat_MethodeID = ?, - T_OrderdetailNat_MethodeName =?"; - - foreach($rows as $r) { - $T_OrderDetailID = $r["T_OrderDetailID"]; - $sexID = $r["M_PatientM_SexID"]; - $ageInDay = $r["Dob"]; - $natTestID = $r["T_TestNat_TestID"]; - list($methodeID,$methodeName) = $this->getMethodeID($natTestID); - if ($methodeID == 0 ) continue; - $normalValueID = $this->get_normal_value($methodeID, $natTestID, $sexID, $ageInDay); - if ($normalValueID == 0) return; - $this->db->query($sql_u, array($T_OrderDetailID, $normalValueID, $methodeID, $methodeName)); - } - } - function update_order_sample($targetID, $sourceID) { - $sql = "update t_ordersample target - join t_ordersample source on - target.T_OrderSampleID = ? - and target.T_OrderSampleWorklistReceive = 'N' - and source.T_OrderSampleID = ? - set - target.T_OrderSampleSampling = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSampling, source.T_OrderSampleSampling), - target.T_OrderSampleSamplingDate = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingDate, source.T_OrderSampleSamplingDate), - target.T_OrderSampleSamplingTime = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingTime, source.T_OrderSampleSamplingTime), - target.T_OrderSampleSamplingUserID = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingUserID, source.T_OrderSampleSamplingUserID), - - target.T_OrderSampleReceive = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceive, source.T_OrderSampleReceive), - target.T_OrderSampleReceiveDate = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveDate, source.T_OrderSampleReceiveDate), - target.T_OrderSampleReceiveTime = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveTime, source.T_OrderSampleReceiveTime), - target.T_OrderSampleReceiveUserID = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveUserID, source.T_OrderSampleReceiveUserID), - - target.T_OrderSampleVerification = if(target.T_OrderSampleVerification='Y',target.T_OrderSampleVerification, source.T_OrderSampleVerification), - target.T_OrderSampleVerificationDate =if(target.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationDate, source.T_OrderSampleVerificationDate), - target.T_OrderSampleVerificationTime =if(source.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationTime, source.T_OrderSampleVerificationTime), - target.T_OrderSampleVerificationUserID =if(source.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationUserID, source.T_OrderSampleVerificationUserID), - - target.T_OrderSampleProcessing = if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessing, source.T_OrderSampleProcessing), - target.T_OrderSampleProcessingDate= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingDate, source.T_OrderSampleProcessingDate), - target.T_OrderSampleProcessingTime= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingTime, source.T_OrderSampleProcessingTime), - target.T_OrderSampleProcessingUserID= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingUserID, source.T_OrderSampleProcessingUserID), - - target.T_OrderSampleReceiveHandling =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandling, source.T_OrderSampleReceiveHandling ), - target.T_OrderSampleReceiveHandlingDate =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingDate, source.T_OrderSampleReceiveHandlingDate), - target.T_OrderSampleReceiveHandlingTime =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingTime, source.T_OrderSampleReceiveHandlingTime), - target.T_OrderSampleReceiveHandlingUserID =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingUserID, source.T_OrderSampleReceiveHandlingUserID), - - target.T_OrderSampleHandling = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandling, source.T_OrderSampleHandling), - target.T_OrderSampleHandlingDate = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingDate, source.T_OrderSampleHandlingDate), - target.T_OrderSampleHandlingTime = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingTime, source.T_OrderSampleHandlingTime), - target.T_OrderSampleHandlingUserID = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingUserID, source.T_OrderSampleHandlingUserID), - - target.T_OrderSampleWorklistReceive = source.T_OrderSampleWorklistReceive, - target.T_OrderSampleWorklistReceiveDatetime = source.T_OrderSampleWorklistReceiveDateTime, - target.T_OrderSampleWorklistReceiveUserID = source.T_OrderSampleWorklistReceiveUserID - "; - $qry = $this->db->query($sql,array($targetID,$sourceID)); - if(! $qry ) { - echo json_encode(array( "status" => "ERR" , "message" => print_r($this->db->error(),true))); - exit; - } - } - function fix_sample_serum($headerID) { - //cari t_ordersample yg belum worklist receive dengan code 017% - $sql = "select T_OrderSampleID - from t_ordersample - join t_sampletype on - T_OrderSampleT_OrderHeaderID = ? - and T_OrderSampleWorklistReceive = 'N' - and T_OrderSampleIsActive = 'Y' - and T_OrderSampleT_SampleTypeID = T_SampletypeID - and T_SampleTypeCode like '017%' - "; - $qry = $this->db->query($sql, array($headerID)); - if(!$qry) { - echo json_encode(array( "status" => "ERR" , "message" => print_r($this->db->error(),true))); - exit; - } - $rows = $qry->result_array(); - if (count($rows) == 0 ) return; - //cari T_OrderSample yang sudah di receive yg terakhir - $sql = "select T_OrderSampleID - from t_ordersample - join t_sampletype on - T_OrderSampleT_OrderHeaderID = ? - and T_OrderSampleWorklistReceive = 'Y' - and T_OrderSampleIsActive = 'Y' - and T_OrderSampleT_SampleTypeID = T_SampletypeID - and T_SampleTypeCode like '017%' - order by T_OrderSampleWorklistReceiveDatetime desc - limit 0,1 - "; - $qry = $this->db->query($sql, array($headerID)); - if(!$qry) { - echo json_encode(array( "status" => "ERR" , "message" => print_r($this->db->error(),true))); - exit; - } - $rcv_rows = $qry->result_array(); - if (count($rcv_rows) == 0 ) return; - - //print_r($rows); - //print_r($rcv_rows); - $rcv_T_OrderSampleID = $rcv_rows[0]["T_OrderSampleID"]; - //ada yg belum di receive - foreach($rows as $r) { - $T_OrderSampleID = $r["T_OrderSampleID"]; - $this->update_order_sample($T_OrderSampleID,$rcv_T_OrderSampleID); - } - } - public function search() - { - $prm = $this->sys_input; - $max_rst = 99; - - $id = $prm["order_id"]; - if ($id > 0 ) { - $this->fix_sample_serum($id); - $this->fn_fix_normal($id); - } - $lang = $this->lang_default_code; - $lang_id = isset($prm['lang_id']) ? $prm['lang_id'] : '0'; - - if ($lang_id != 0) - { - $l = $this->db_smartone->where("Nat_LangID", $lang_id)->get("nat_lang")->row(); - $lang = $l->Nat_LangCode; - } - - //tambahan fajri - $sql = " UPDATE t_orderdetail - JOIN t_test ON T_OrderDetailT_TestID = T_TestID - SET T_OrderDetailT_TestIsResult = T_TestIsResult - WHERE - T_OrderDetailT_OrderHeaderID = {$id} AND - T_OrderDetailT_TestIsResult = '' AND - T_OrderDetailIsActive = 'Y'"; - $this->db_smartone->query($sql); - - $tot_count = 0; - $lq = ""; - $group_id = 0; - if (isset($prm['group_id'])) - $group_id = $prm['group_id']; - - if ($group_id != 0) - { - $sql = "select distinct T_WorklistDetailNat_TestID Nat_TestID - from t_worklistdetailv2 - where T_WorklistDetailT_WorklistID = {$group_id}"; - $qry = $this->db_smartone->query($sql); - $rows = $qry->result_array(); - $nat_test_ids = "0"; - foreach($rows as $r) { - $nat_test_ids .= ", " . $r["Nat_TestID"]; - } - $q_group = " ( $nat_test_ids ) "; - - $sql = " - SELECT a1.*, cOUNT(a2.T_OrderDetailID) level - FROM ( - SELECT IFNULL(y.T_OrderDetailT_TestID, x.T_OrderDetailT_TestID) t_testid, - IFNULL(y.T_OrderDetailT_TestName, y.T_OrderDetailT_TestName) t_testname, - y.T_OrderDetailResult result, y.T_OrderDetailResult result_old, y.T_OrderDetailNote note, y.T_OrderDetailNote note_old, - y.T_OrderDetailID id, - y.T_OrderDetailT_TestIsResult is_result, a.T_TestIsQuantitative is_quantitative, - y.T_OrderDetailResultFlag result_flag, - y.T_OrderDetailNat_NormalValueID normal_id, - y.T_OrderDetailNormalValueNote normal_note, y.T_OrderDetailNat_UnitName unit_name, - y.T_OrderdetailNat_MethodeID methode_id, y.T_OrderdetailNat_MethodeName methode_name, - a.T_TestNat_TestID nattest_id, a.T_TestID tx_id, count(T_ResultInstrumentID) as result_instrument_n, - y.T_OrderDetailVerification, T_OrderSampleReceive sample_receive, - T_OrderSampleProcessing sample_processing, T_OrderSampleWorklistReceive sample_worklist_receive, - IF(T_OrderDetailAddOnPreAnalytic = 'Y', T_OrderDetailAddOnPreAnalytic, PreAnalyticIsOk) pre_analytic, - T_OrderDetailAddOnPreAnalytic, - T_OrderHeaderID order_id, y.T_OrderDetailT_TestSasCode test_sas_code, - tx.T_TestSasCode, - T_OrderDetailAddOnResample `resample`, T_OrderDetailAddOnResampleStatus resample_status, - T_OrderDetailAddOnRef ref, y.T_OrderDetailVerification verification, y.T_OrderDetailValidation validation, - T_OrderPromiseDateTime, Group_ResultName as ResultGroupName - FROM t_orderdetail x - left join t_orderpromise on x.T_OrderDetailT_OrderPromiseID = T_OrderPromiseID - JOIN t_test tx ON x.T_OrderDetailT_TestID = T_TestID - JOIN t_test tcheck on tcheck.T_TestNat_TestID in {$q_group} - and ( tx.T_TestID = tcheck.T_TestID or tx.T_TestSasCode like concat(tcheck.T_TestSasCode,'%')) - LEFT JOIN group_resultdetail ON Group_ResultDetailT_TestID = x.T_OrderDetailT_TestID AND Group_ResultDetailIsActive = 'Y' - LEFT JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND Group_ResultFlagNonLab = 'N' - LEFT JOIN t_orderdetail y ON x.T_OrderDetailT_TestSasCode LIKE CONCAT(y.T_OrderDetailT_TestSasCode, '%') - AND x.T_OrderDetailT_OrderHeaderID = y.T_OrderDetailT_OrderHeaderID - AND y.T_OrderDetailIsActive = 'Y' - LEFT JOIN t_orderdetailaddon ON x.T_OrderDetailID = T_OrderDetailAddOnT_OrderDetailID - JOIN t_orderheader ON y.T_OrderDetailT_OrderHeaderID = T_OrderHeaderID - LEFT JOIN t_test a ON y.T_OrderDetailT_TestID = a.T_TestID - AND a.T_TestIsNonLab = '' - LEFT JOIN (SELECT T_OrderSampleT_SampleTypeID, T_OrderSampleReceive, T_OrderSampleProcessing, T_OrderSampleWorklistReceive - FROM t_ordersample WHERE T_OrderSampleT_OrderHeaderID = {$id} - AND T_OrderSampleIsactive = 'Y' - GROUP BY T_OrderSampleT_SampleTypeID) os ON a.T_TestT_SampleTypeID = os.T_OrderSampleT_SampleTypeID - or os.T_OrderSampleT_SampleTypeID = fn_sampletype_from_local(a.T_TestNat_TestID) - - LEFT JOIN t_resultinstrument ON T_ResultInstrumentT_OrderDetailID = x.T_OrderDetailID - LEFT JOIN pre_analytic ON PreAnalyticNat_TestID = a.T_TestNat_TestID AND PreAnalyticDate = date(now()) and PreAnalyticIsActive = 'Y' - WHERE x.T_OrderDetailT_OrderHeaderID = {$id} - AND x.T_OrderDetailIsActive = 'Y' - GROUP BY y.T_OrderDetailT_TestID - ORDER BY y.T_OrderDetailT_TestSasCode ASC - ) a1 - - LEFT JOIN t_orderdetail a2 ON a2.T_OrderDetailT_OrderHeaderID = a1.order_id - AND a2.T_OrderDetailIsActive = 'Y' - AND a1.test_sas_code LIKE CONCAT(a2.T_OrderDetailT_testSasCode, '%') - GROUP BY a1.t_testid - order by a1.test_sas_code -"; - $query = $this->db_smartone->query($sql); - $lq = $this->db_smartone->last_query(); - } - else - { - $sql = " - SELECT a1.*, cOUNT(a2.T_OrderDetailID) level - FROM ( - SELECT IFNULL(y.T_OrderDetailT_TestID, x.T_OrderDetailT_TestID) t_testid, - IFNULL(y.T_OrderDetailT_TestName, y.T_OrderDetailT_TestName) t_testname, - y.T_OrderDetailResult result, y.T_OrderDetailResult result_old, y.T_OrderDetailNote note, y.T_OrderDetailNote note_old, - y.T_OrderDetailID id, - y.T_OrderDetailT_TestIsResult is_result, a.T_TestIsQuantitative is_quantitative, - y.T_OrderDetailResultFlag result_flag, - y.T_OrderDetailNat_NormalValueID normal_id, - y.T_OrderDetailNormalValueNote normal_note, y.T_OrderDetailNat_UnitName unit_name, - y.T_OrderdetailNat_MethodeID methode_id, y.T_OrderdetailNat_MethodeName methode_name, - a.T_TestNat_TestID nattest_id, a.T_TestID tx_id, count(T_ResultInstrumentID) as result_instrument_n, - y.T_OrderDetailVerification, T_OrderSampleReceive sample_receive, - T_OrderSampleProcessing sample_processing, T_OrderSampleWorklistReceive sample_worklist_receive, - IF(T_OrderDetailAddOnPreAnalytic = 'Y', T_OrderDetailAddOnPreAnalytic, PreAnalyticIsOk) pre_analytic, - T_OrderDetailAddOnPreAnalytic, - T_OrderHeaderID order_id, y.T_OrderDetailT_TestSasCode test_sas_code, - tx.T_TestSasCode, - T_OrderDetailAddOnResample `resample`, T_OrderDetailAddOnResampleStatus resample_status, - T_OrderDetailAddOnRef ref, y.T_OrderDetailVerification verification, y.T_OrderDetailValidation validation, - T_OrderPromiseDateTime , Group_ResultName as ResultGroupName - FROM t_orderdetail x - left join t_orderpromise on x.T_OrderDetailT_OrderPromiseID = T_OrderPromiseID - JOIN t_test tx ON x.T_OrderDetailT_TestID = T_TestID - LEFT JOIN group_resultdetail ON Group_ResultDetailT_TestID = x.T_OrderDetailT_TestID AND Group_ResultDetailIsActive = 'Y' - LEFT JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND Group_ResultFlagNonLab = 'N' - LEFT JOIN t_orderdetail y ON x.T_OrderDetailT_TestSasCode LIKE CONCAT(y.T_OrderDetailT_TestSasCode, '%') - AND x.T_OrderDetailT_OrderHeaderID = y.T_OrderDetailT_OrderHeaderID - AND y.T_OrderDetailIsActive = 'Y' - - LEFT JOIN t_orderdetailaddon ON x.T_OrderDetailID = T_OrderDetailAddOnT_OrderDetailID - - JOIN t_orderheader ON y.T_OrderDetailT_OrderHeaderID = T_OrderHeaderID - LEFT JOIN t_test a ON y.T_OrderDetailT_TestID = a.T_TestID - AND a.T_TestIsNonLab = '' - LEFT JOIN (SELECT T_OrderSampleT_SampleTypeID, T_OrderSampleReceive, T_OrderSampleProcessing, T_OrderSampleWorklistReceive - FROM t_ordersample WHERE T_OrderSampleT_OrderHeaderID = {$id} - AND T_OrderSampleIsactive = 'Y' - GROUP BY T_OrderSampleT_SampleTypeID) os ON a.T_TestT_SampleTypeID = os.T_OrderSampleT_SampleTypeID - or os.T_OrderSampleT_SampleTypeID = fn_sampletype_from_local(a.T_TestNat_TestID) - - LEFT JOIN t_resultinstrument ON T_ResultInstrumentT_OrderDetailID = x.T_OrderDetailID - LEFT JOIN pre_analytic ON PreAnalyticNat_TestID = a.T_TestNat_TestID AND PreAnalyticDate = date(now()) and PreAnalyticIsActive = 'Y' - WHERE x.T_OrderDetailT_OrderHeaderID = {$id} - AND x.T_OrderDetailIsActive = 'Y' - GROUP BY y.T_OrderDetailT_TestID - ORDER BY y.T_OrderDetailT_TestSasCode ASC - ) a1 - - LEFT JOIN t_orderdetail a2 ON a2.T_OrderDetailT_OrderHeaderID = a1.order_id - AND a2.T_OrderDetailIsActive = 'Y' - AND a1.test_sas_code LIKE CONCAT(a2.T_OrderDetailT_testSasCode, '%') - GROUP BY a1.t_testid - order by a1.test_sas_code -"; -//echo $sql; - $query = $this->db_smartone->query($sql); - $lq = $this->db_smartone->last_query(); - } - // file_put_contents("/xtmp/re-query.sql",$lq); - - if ($query) { - $rst = []; - $rows = $query->result_array(); - - foreach($rows as $k => $v) - { - - if ($v['is_result'] == "Y" && $v['is_quantitative'] == "N") - { - $v['template'] = []; - $x = $this->db_smartone->query("CALL sp_master_resulttemplate_get('{$v['t_testid']}')"); - $this->clean_mysqli_connection($this->db_smartone->conn_id); - if ($x) - $v['template'] = $x->result_array(); - } - - // IF Rujukan, by pas Pre Analytik - if ($v['ref'] == 'Y') - $v['pre_analytic'] = 'Y'; - if ($v["id"] == "885455" ) - { - //sipe workaround - //$v["sample_receive"] = "Y"; - $v["sample_worklist_receive"] = "Y"; - } - $rst[] = $v; - } - - $result = array("total" => $tot_count, "records" => $rst, "total_display" => sizeof($rows), "q" => $lq); - $this->sys_ok($result); - } - else { - $this->sys_error_db("RE Px rows", $this->db_smartone); - exit; - } - } - - public function save() - { - $prm = $this->sys_input; - $data = json_decode($prm["data"]); - $lang = $this->lang_default_code; - $lang_id = isset($prm['lang_id']) ? $prm['lang_id'] : '0'; - - if ($lang_id != 0) - { - $l = $this->db_smartone->where("Nat_LangID", $lang_id)->get("nat_lang")->row(); - $lang = $l->Nat_LangCode; - } - - $sql_norm = "select T_OrderDetailMinValue, T_OrderDetailMaxValue, - T_OrderDetailMinValueInclusive, T_OrderDetailMaxValueInclusive, - Nat_TestFlagLow, Nat_TestFlagHigh - from t_orderdetail - join t_test on T_OrderDetailT_TestID = T_TestID - join nat_test on T_TestNat_TestID = Nat_TestID and T_TestIsActive = 'Y' - where T_OrderDetailID = ? "; - - $ids = []; - foreach ($data as $k => $v) - { - if ( $v->resultInstrumentID > 0 ) { - $sql_i = "select T_ResultInstrumentNat_NormalValueID normalValueID - from t_resultinstrument - where T_ResultInstrumentID = ?"; - $qry_i = $this->db_smartone->query($sql_i, array($v->resultInstrumentID)); - if ($qry_i) { - $rows_i = $qry_i->result_array(); - - if (count($rows_i) > 0 ) { - $sql_iu = "update t_orderdetail, nat_normalvalue , nat_methode - set T_OrderDetailMinValue = Nat_NormalValueMinValue, - T_OrderDetailMinValueInclusive = Nat_NormalValueMinValueInclusive, - T_OrderDetailMaxValue = Nat_NormalValueMaxValue , - T_OrderDetailMaxValueInclusive = Nat_NormalValueMaxValueInclusive, - T_OrderDetailNormalValueNote = Nat_NormalValueNote, - T_OrderDetailNormalValueDescription = Nat_NormalValueDescription, - T_OrderDetailNat_NormalValueID = Nat_NormalValueID, - T_OrderDetailNat_MethodeID = Nat_NormalValueNat_MethodeID, - T_OrderDetailNat_MethodeName = Nat_MethodeName - where T_OrderDetailID = ? and Nat_NormalValueID = ? - and Nat_NormalValueNat_MethodeID = Nat_MethodeID - "; - $this->db_smartone->query($sql_iu, array($v->id, $rows_i[0]["normalValueID"])); - //file_put_contents("/xtmp/update-nilai-normal", $this->db_smartone->last_query() . "\n", FILE_APPEND); - } - } - } - $y = $this->db_smartone->query("SELECT fn_process_sample_handling_perfect('{$v->order_id}', '{$v->test_id}') c") - ->row(); - $req_status = $y->c; - $qry_norm = $this->db_smartone->query($sql_norm,$v->id); - $result_flag = ""; - if ($qry_norm) { - $rows_norm = $qry_norm->result_array(); - if (count($rows_norm) > 0 ) { - $r = $rows_norm[0]; - if (is_numeric($v->result)) { - - if ( $r["T_OrderDetailMinValueInclusive"] == "Y" && $v->result < $r["T_OrderDetailMinValue"] ) { - $result_flag = $r["Nat_TestFlagLow"]; - } - if ( $r["T_OrderDetailMinValueInclusive"] == "N" && $v->result <= $r["T_OrderDetailMinValue"] ) { - $result_flag = $r["Nat_TestFlagLow"]; - } - if ( $r["T_OrderDetailMaxValueInclusive"] == "Y" && $v->result > $r["T_OrderDetailMaxValue"] ) { - $result_flag = $r["Nat_TestFlagHigh"]; - } - if ( $r["T_OrderDetailMaxValueInclusive"] == "N" && $v->result >= $r["T_OrderDetailMaxValue"] ) { - $result_flag = $r["Nat_TestFlagHigh"]; - } - } - } - } - if ($lang == $this->lang_default_code) - { - $this->db_smartone->set('T_OrderDetailResult', $v->result) - ->set('T_OrderDetailResultFlag', $result_flag) - ->set('T_OrderDetailNote', $v->note) - ->set('T_OrderDetailReqStatus', $req_status) - ->where('T_OrderDetailID', $v->id) - ->update('t_orderdetail'); - } - else - { - $this->db_smartone->set('T_OrderDetailLangResult', $v->result) - ->set('T_OrderDetailLangNote', $v->note) - ->where('T_OrderDetailLangID', $v->id) - ->update('t_orderdetaillang'); - } - - $ids[] = $v->id; - } - - // LOG Process - $order = $this->db_smartone->select('T_OrderDetailT_OrderHeaderID id, T_OrderHeaderLabNumber lab_number', false) - ->join('t_orderheader', 'T_OrderHeaderID = T_OrderDetailT_OrderHeaderID') - ->where('T_OrderDetailID', $data[0]->id) - ->get('t_orderdetail') - ->row(); - - $dblog = $this->load->database("onelog", true); - $dblog->set('Log_ProcessCode', 'PROCESS.Result.Entry') - ->set('Log_ProcessOrderID', $order->id) - ->set('Log_ProcessOrderNumber', $order->lab_number) - ->set('Log_ProcessJson', json_encode($data)) - ->set('Log_ProcessUserID', $this->sys_user['M_UserID']) - ->insert('log_process'); - // END OF Log Process - //auto calculation - $this->load->library("Resultcalc"); - $rows = $this->resultcalc->auto($order->id); - - try { - foreach($ids as $id ) { - $this->db_smartone->query("call sp_set_normal_value_flag($id)"); - $this->clean_mysqli_connection($this->db_smartone->conn_id); - } - } catch(Exception $e) { - } - - $this->sys_ok($ids); - } - - public function save_template() - { - $prm = $this->sys_input; - - $n = $this->db_smartone->select("COUNT(T_ResultTemplateID) n") - ->where("T_ResultTemplateT_TestID", $prm['test_id']) - ->where("T_ResultTemplateIsActive", "Y") - ->where("T_ResultTemplateValue", $prm['value']) - ->get('t_resulttemplate') - ->row(); - if ($n->n > 0) - { - $this->sys_error_db("Insert Result Template", $this->db_smartone); - return; - } - - $r = $this->db_smartone->set("T_ResultTemplateT_TestID", $prm['test_id']) - ->set("T_ResultTemplateValue", $prm['value']) - ->insert('t_resulttemplate'); - if ($r) - { - $template = []; - $x = $this->db_smartone->query("CALL sp_master_resulttemplate_get('{$prm['test_id']}')"); - $this->clean_mysqli_connection($this->db_smartone->conn_id); - if ($x) - $template = $x->result_array(); - - $this->sys_ok($template); - } - } - - public function export() - { - $prm = $this->sys_input; - - $sql = "CALL sp_process_result_lang(?, ?, ?, ?)"; - $query = $this->db_smartone->query($sql, [$prm['order_id'], $prm['lang_id'], $prm['is_si'], $this->sys_user['M_UserID']]); - if ($query) - { - $r = $query->row(); - if ($r->status == "OK") - { - $this->sys_ok($r->data); - return; - } - - $this->sys_error_db("Message : " . $r->message, $this->db_smartone); - } - else - { - $this->sys_error_db("Lang Result", $this->db_smartone); - return; - } - } - - public function search_group() - { - $prm = $this->sys_input; - $max_rst = 100; - - // QUERY TOTAL - $sql = "select count(*) total - from t_worklist - where T_WorklistIsActive = 'Y' - order by T_WorklistName ASC"; - $query = $this->db_smartone->query($sql); - - if ($query) { - $tot_count = $query->result_array()[0]["total"]; - } - else { - $this->sys_error_db("worklist count", $this->db_smartone); - exit; - } - - $sql = "select T_WorklistID group_id, T_WorklistName group_name - from t_worklist - where T_WorklistIsActive = 'Y' - order by T_WorklistName ASC - limit 0, {$max_rst}"; - $query = $this->db_smartone->query($sql); - - if ($query) { - $rows = $query->result_array(); - foreach ($rows as $k => $v) - $rows[$k]['data'] = json_decode($v['data']); - $result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows), "q" => $this->db_smartone->last_query()); - $this->sys_ok($result); - } - else { - $this->sys_error_db("worklist rows", $this->db_smartone); - exit; - } - } - - public function search_rerun() - { - $prm = $this->sys_input; - $id = $prm["detail_id"]; - - $sql = "CALL sp_process_result_rerun(?)"; - $query = $this->db_smartone->query($sql, [$id]); - - if ($query) - { - $rows = $query->result_array(); - $this->sys_ok(["records"=>$rows]); - } - else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - - - function getdoctorsfna() - { - $prm = $this->sys_input; - // $id = $prm["id"]; - - $sql = " SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY M_DoctorName ASC"; - //echo $sql; - $query = $this->db_smartone->query($sql); - - if ($query) - { - $rows = $query->result_array(); - $this->sys_ok(["records"=>$rows]); - } - else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - function getfnaresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT Other_FNADetailsID as xid, - Other_FNAT_OrderDetailID as orderdetail_id, - Other_FNADetailsCode as code, - Other_FNADetailsLabel as label, - Other_FNADetailsResult as result, - IFNULL(Other_FNAM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_FNAM_DoctorID) OR Other_FNAM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_fna - JOIN other_fnadetails ON Other_FNADetailsOther_FNAID = Other_FNAID AND Other_FNADetailsIsActive = 'Y' - LEFT JOIN m_doctor ON Other_FNAM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_FNAT_OrderDetailID = {$id} AND Other_FNAIsActive = 'Y' - GROUP BY Other_FNADetailsID - ORDER BY Other_FNADetailsCode ASC"; - $query = $this->db_smartone->query($sql); - - if ($query) - { - $rows = $query->result_array(); - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $images = array(); - $sql = "SELECT So_ImageUploadID as xid, - CONCAT('/one-media/one-image-nonlab/',So_ImageUploadNewName) as image_url - FROM t_orderdetail - JOIN so_imageupload ON So_ImageUploadT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND - So_ImageUploadIsActive = 'Y' - WHERE - T_OrderDetailID = {$id} AND - T_OrderDetailIsActive = 'Y' - GROUP BY So_ImageUploadID"; - $images = $this->db_smartone->query($sql)->result_array(); - - $rst = array('doctors'=>$doctors,'results'=>$rows,'images'=>$images); - $this->sys_ok(["records"=>$rst]); - } - else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - - function uploadimage(){ - if (! $this->isLogin) { - $this->sys_error("Invalid Token"); - exit; - } - - $userid = $this->sys_user["M_UserID"]; - $data = []; - //print_r($_SERVER); - - $prm = $this->sys_input; - $orderid = $this->input->post('orderid'); - $labnumber = $this->input->post('labnumber'); - $sql = "UPDATE so_imageupload SET - So_ImageUploadIsActive = 'N', - So_ImageUploadUserID = {$userid} - WHERE - So_ImageUploadT_OrderHeaderID = {$orderid}"; - //echo $sql; - $this->db_onedev->query($sql); - //$config['upload_path'] = 'assets/'; - - $path = '/home/one/project/one/one-media/one-image-nonlab/'; - //echo $path; - $config['upload_path'] = $path; - $config['allowed_types'] = 'jpg|jpeg|png|gif'; - - $config['max_size'] = '10000'; - $count = count($_FILES['files']['name']); - //echo $count; - $this->load->library('upload',$config); - - $error = []; - for($i=0;$i<$count;$i++){ - - - if(!empty($_FILES['files']['name'][$i])){ - - - - $_FILES['file']['name'] = $_FILES['files']['name'][$i]; - - $_FILES['file']['type'] = $_FILES['files']['type'][$i]; - - $_FILES['file']['tmp_name'] = $_FILES['files']['tmp_name'][$i]; - - $_FILES['file']['error'] = $_FILES['files']['error'][$i]; - - $_FILES['file']['size'] = $_FILES['files']['size'][$i]; - - - - $namex = $orderid.'-'.$labnumber.'-'.$this->generateRandomString(5); - //echo $namex; - - $config['file_name'] = $namex; - $this->upload->initialize($config); - //echo $config['file_name'] ; - - - - - - if($this->upload->do_upload('file')){ - - $uploadData = $this->upload->data(); - - $filename = $uploadData['file_name']; - //echo $filename; - - - $sql = "INSERT INTO so_imageupload ( - So_ImageUploadT_OrderHeaderID, - So_ImageUploadT_OrderHeaderLabNumber, - So_ImageUploadT_SampleTypeID, - So_ImageUploadOldName, - So_ImageUploadNewName, - So_ImageUploadCreated, - So_ImageUploadUserID - ) - VALUES( - {$orderid}, - '{$labnumber}', - '150', - '{$_FILES['files']['name'][$i]}', - '{$filename}', - NOW(), - {$userid} - - )"; - //echo $sql; - $this->db_onedev->query($sql); - $xlast_id = $this->db_onedev->insert_id(); - $data['totalFiles'][] = array('xid' => $xlast_id ,'image_url' => '/one-media/one-image-nonlab/'.$filename); - - } - else{ - $error = array('error' => $this->upload->display_errors()); - } - - } - - - - } - - $result = array("total" =>count( $data['totalFiles']), "records" => $data['totalFiles'],'errors'=>$error); - $this->sys_ok($result); - } - - - function generateRandomString($length = 10) { - $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; - $charactersLength = strlen($characters); - $randomString = ''; - for ($i = 0; $i < $length; $i++) { - $randomString .= $characters[rand(0, $charactersLength - 1)]; - } - return $randomString; - } - - function getcytologiresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT Other_CytologiDetailsID as xid, - Other_CytologiT_OrderDetailID as orderdetail_id, - Other_CytologiDetailsCode as code, - Other_CytologiDetailsLabel as label, - Other_CytologiDetailsResult as result, - IFNULL(Other_CytologiM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_CytologiM_DoctorID) OR Other_CytologiM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_cytologi - JOIN other_cytologidetails ON Other_CytologiDetailsOther_CytologiID = Other_CytologiID AND Other_CytologiDetailsIsActive = 'Y' - LEFT JOIN m_doctor ON Other_CytologiM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_CytologiT_OrderDetailID = {$id} AND Other_CytologiIsActive = 'Y' - GROUP BY Other_CytologiDetailsID - ORDER BY Other_CytologiDetailsCode ASC"; - //echo $sql; - $query = $this->db_smartone->query($sql); - - if ($query) - { - $rows = $query->result_array(); - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $rst = array('doctors'=>$doctors,'results'=>$rows); - $this->sys_ok(["records"=>$rst]); - } - else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - function getmikroresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT - Other_MikroID as xid, - Other_MikroHasilBiakan as hasil_biakan, - Other_MikroSampleTypeName as sample_name, - Other_MikroT_OrderDetailID as orderdetail_id, - Other_MikroResult as result_value, - '' as result_other, - IFNULL(T_BacteriaID,0) as T_BacteriaID, - IFNULL(T_BacteriaName,'') as T_BacteriaName, - '' as details, - IFNULL(Other_MikroM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_MikroM_DoctorID) OR Other_MikroM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_mikro - LEFT JOIN t_bacteria ON Other_MikroT_BacteriaID = T_BacteriaID - LEFT JOIN m_doctor ON Other_MikroM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_MikroT_OrderDetailID = {$id} AND Other_MikroIsActive = 'Y' - GROUP BY Other_MikroID"; - //echo $sql; - $query = $this->db_smartone->query($sql); - - if ($query) - { - $row = $query->row_array(); - if($row){ - if($row['result_value'] != 'Positif' && $row['result_value'] != 'Negatif'){ - $row['result_other'] = $row['result_value']; - $row['result_value'] = 'other'; - } - $sql = "SELECT '' as xno, - Other_MikroDetailsID as xid, - Other_MikroDetailsValue as value, - IF(Other_MikroDetailsNote = 'R','Y','N') as chx_r, - IF(Other_MikroDetailsNote = 'I','Y','N') as chx_i, - IF(Other_MikroDetailsNote = 'S','Y','N') as chx_s, - Other_MikroDetailsNote as note, - t_antibiotic.* - FROM other_mikrodetails - LEFT JOIN t_antibiotic ON Other_MikroDetailsT_AntibioticID = T_AntibioticID - WHERE - Other_MikroDetailsOther_MikroID = {$row['xid']} AND Other_MikroDetailsIsActive = 'Y' - GROUP BY Other_MikroDetailsID - ORDER BY T_AntibioticName ASC"; - //echo $sql; - $details = $this->db_smartone->query($sql)->result_array(); - if(details){ - foreach($details as $k => $v){ - $details[$k]['xno'] = $k + 1; - } - } - $row['details'] = $details; - } - else{ - $row = array('xid'=>'0','hasil_biakan' => '','result_value'=>'Negatif','sample_name' => '','orderdetail_id'=>$id, 'T_BacteriaID'=>'0','T_BacteriaName'=>'0','details'=>array(),'doctor_id'=>'0','doctor_name'=>'0'); - } - } - else{ - $row = array('xid'=>'0','hasil_biakan' => '','result_value'=>'Negatif','sample_name' => '','orderdetail_id'=>$id, 'T_BacteriaID'=>'0','T_BacteriaName'=>'0','details'=>array(),'doctor_id'=>'0','doctor_name'=>'0'); - } - //print_r($row); - - - - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 7 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $sql = " - SELECT '0' as id, 'Belum memilih bakteria' as name - UNION - SELECT T_BacteriaID as id, T_BacteriaName as name - FROM t_bacteria - WHERE - T_BacteriaIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $bacteries = $this->db_smartone->query($sql)->result_array(); - $rst = array('doctors'=>$doctors,'bacteries'=>$bacteries,'results'=>$row); - $this->sys_ok(["records"=>$rst]); - } - function getantibiotics(){ - $prm = $this->sys_input; - $id = $prm["id"]; - $sql = " SELECT '' as xno, - 0 as xid, - '' as hasil_biakan, - '' as sample_name, - 0 as value, - 'Y' as chx_r, - 'N' as chx_i, - 'N' as chx_s, - 'R' as note, - t_antibiotic.* - FROM t_antibiotic - WHERE - T_AntibioticT_BacteriaID = {$prm['id']} AND T_AntibioticIsActive= 'Y' - ORDER BY T_AntibioticName ASC"; - //echo $sql; - $rows = $this->db_smartone->query($sql)->result_array(); - if(rows){ - foreach($rows as $k => $v){ - $rows[$k]['xno'] = $k + 1; - } - } - - $this->sys_ok(["records"=>$rows]); - } - function getlcprepresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - $sql = " SELECT Other_LcprepDetailsID as xid, - Other_LcprepID as header_id, - Other_LcprepT_orderDetailID as orderdetail_id, - Other_LcprepDetailsCode as code, - Other_LcprepDetailsLabel as label, - Other_LcprepDetailsResult as result, - IFNULL(Other_LcprepM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_LcprepM_DoctorID) OR Other_LcprepM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_lcprep - JOIN other_lcprepdetails ON Other_LcprepDetailsOther_LcprepID = Other_LcprepID AND Other_LcprepDetailsIsActive = 'Y' - LEFT JOIN m_doctor ON Other_LcprepM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_LcprepT_orderDetailID = {$id} AND Other_LcprepIsActive = 'Y' - GROUP BY Other_LcprepDetailsOther_LcprepID, Other_LcprepDetailsCode - ORDER BY Other_LcprepDetailsCode ASC"; - //echo $sql; - $rows = $this->db_smartone->query($sql)->result_array(); - if(!$rows){ - $rows = array( - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'A', - 'label' => 'DESKRIPSI', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ), - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'B', - 'label' => 'KESIMPULAN', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ) - ); - } - - $header_id = $rows[0]['header_id']; - $sql = "SELECT IFNULL(Other_LcprepAdekuasiID,0) as xid, - Lcprep_AdekuasiID as id, - Lcprep_AdekuasiLabel as name, - IF(ISNULL(Other_LcprepAdekuasiID),'N',Other_LcprepAdekuasiChex) as chex - FROM lcprep_adekuasi - LEFT JOIN other_lcprepadekuasi ON Other_LcprepAdekuasiLcprep_AdekuasiID = Lcprep_AdekuasiID AND - Other_LcprepAdekuasiOther_LcprepID = {$header_id} AND - Other_LcprepAdekuasiIsActive = 'Y' - WHERE - Lcprep_AdekuasiIsActive = 'Y' - GROUP BY Lcprep_AdekuasiID - ORDER BY Lcprep_AdekuasiOrder ASC - "; - //echo $sql; - $adeakuasi = $this->db_smartone->query($sql)->result_array(); - foreach($adeakuasi as $kc => $vc){ - $adeakuasi[$kc]['chex'] = $vc['chex'] == 'N'?false:true; - } - - $sql = "SELECT IFNULL(Other_LcprepKategoriUmumID,0) as xid, - Lcprep_KategoriUmumID as id, - Lcprep_KategoriUmumLabel as name, - IF(ISNULL(Other_LcprepKategoriUmumID),'N',Other_LcprepKategoriUmumChex) as chex - FROM lcprep_kategoriumum - LEFT JOIN other_lcprepkategoriumum ON Other_LcprepKategoriUmumLcprep_KategoriUmumID = Lcprep_KategoriUmumID AND - Other_LcprepKategoriUmumOther_LcprepID = {$header_id} AND - Other_LcprepKategoriUmumIsActive = 'Y' - WHERE - Lcprep_KategoriUmumIsActive = 'Y' - GROUP BY Lcprep_KategoriUmumID - "; - //echo $sql; - $kategoriumum = $this->db_smartone->query($sql)->result_array(); - foreach($kategoriumum as $kc => $vc){ - $kategoriumum[$kc]['chex'] = $vc['chex'] == 'N'?false:true; - } - - $sql = " - SELECT Lcprep_InterpretasiGroupID as group_id, - Lcprep_InterpretasiGroupName as group_name, - '' as subgroups - FROM lcprep_interpretasigroup - WHERE - Lcprep_InterpretasiGroupIsActive = 'Y' - "; - //echo $sql; - $interpretasi = $this->db_smartone->query($sql)->result_array(); - foreach($interpretasi as $k => $v){ - $subgroups = array(); - $sql = "SELECT Lcprep_InterpretasiSubgroupID as subgroup_id, - Lcprep_InterpretasiSubgroupName as subgroup_name, - '' as childs - FROM lcprep_interpretasisubgroup - WHERE - Lcprep_InterpretasiSubgroupLcprep_InterpretasiGroupID = {$v['group_id']} AND Lcprep_InterpretasiSubgroupIsActive = 'Y'"; - //echo $sql; - $subgroups = $this->db_smartone->query($sql)->result_array(); - if(count($subgroups) > 0){ - foreach($subgroups as $ki => $vi){ - $childs = array(); - $sql = "SELECT IFNULL(Other_LcprepInterpretasiID,0) as xid, - IFNULL(Other_LcprepInterpretasiChex,'N') as chex, - IFNULL(Other_LcprepInterpretasiValue,'') as value, - Lcprep_InterpretasiID as id, - Lcprep_InterpretasiLcprep_InterpretasiSubgroupID as subgroup_id, - Lcprep_InterpretasiCode as code, - Lcprep_InterpretasiName as name, - Lcprep_InterpretasiParentID as parent_id, - Lcprep_InterpretasiIsParent as is_parent, - Lcprep_InterpretasiHasResult as has_result, - Lcprep_InterpretasiTypeResult as type_result - FROM lcprep_interpretasi - LEFT JOIN other_lcprepinterpretasi ON Other_LcprepInterpretasiOther_LcprepID = {$header_id} AND - Other_LcprepInterpretasiLcprep_InterpretasiID = Lcprep_InterpretasiID AND - Other_LcprepInterpretasiIsActive = 'Y' - WHERE - Lcprep_InterpretasiLcprep_InterpretasiSubgroupID = {$vi['subgroup_id']} AND Lcprep_InterpretasiIsActive = 'Y' - GROUP BY Lcprep_InterpretasiID Order BY Lcprep_InterpretasiCode ASC"; - $childs = $this->db_smartone->query($sql)->result_array(); - if($childs){ - foreach($childs as $kc => $vc){ - $childs[$kc]['chex'] = $vc['chex'] == 'N'?false:true; - } - } - $subgroups[$ki]['childs'] = $childs; - } - } - - $interpretasi[$k]['subgroups'] = $subgroups; - } - - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $rst = array('doctors'=>$doctors,'results'=>$rows,'adekuasi'=>$adeakuasi,'kategoriumum'=>$kategoriumum,'interpretasi'=>$interpretasi); - $this->sys_ok(["records"=>$rst]); - } - - function getpapsmearresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT Other_PapSmearDetailsID as xid, - Other_PapSmearID as header_id, - Other_PapSmearT_OrderDetailID as orderdetail_id, - Other_PapSmearDetailsCode as code, - Other_PapSmearDetailsLabel as label, - Other_PapSmearDetailsResult as result, - IFNULL(Other_PapSmearM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_PapSmearM_DoctorID) OR Other_PapSmearM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_papsmear - JOIN other_papsmeardetails ON Other_PapSmearDetailsOther_PapSmearID = Other_PapSmearID AND Other_PapSmearDetailsIsActive = 'Y' - LEFT JOIN m_doctor ON Other_PapSmearM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_PapSmearT_OrderDetailID = {$id} AND Other_PapSmearIsActive = 'Y' - GROUP BY Other_PapSmearDetailsID - ORDER BY Other_PapSmearDetailsCode ASC"; - //echo $sql; - $rows = $this->db_smartone->query($sql)->result_array(); - if(!$rows){ - $rows = array( - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'A', - 'label' => 'Makroskopik', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ), - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'B', - 'label' => 'Mikroskopik', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ), - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'C', - 'label' => 'Kesimpulan', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ) - ); - } - - $header_id = $rows[0]['header_id']; - $sql = "SELECT Other_PapSmearMaturasiID as xid, - Other_PapSmearMaturasiValue as value - FROM other_papsmearmaturasi - WHERE - Other_PapSmearMaturasiOther_PapSmearID = {$header_id} AND - Other_PapSmearMaturasiIsActive = 'Y' - "; - //echo $sql; - $dt_maturasi = $this->db_smartone->query($sql)->row_array(); - if(!$dt_maturasi){ - $maturasi = array('xid'=>'0','value'=> array('','','')); - } - else{ - $value = explode('/',$dt_maturasi['value']); - $maturasi = array('xid'=>$dt_maturasi['xid'],'value'=> $value); - } - - $sql = "SELECT IFNULL(Other_PapSmearBahanID,0) as xid, - M_PapSmearBahanID as bahan_id, - M_PapSmearBahanName as name, - IF(ISNULL(Other_PapSmearBahanID),'N','Y') as selected - FROM m_papsmearbahan - LEFT JOIN other_papsmearbahan ON Other_PapSmearBahanM_PapSmearBahanID = M_PapSmearBahanID AND - Other_PapSmearBahanOther_PapSmearID = {$header_id} AND - Other_PapSmearBahanIsActive = 'Y' - WHERE - M_PapSmearBahanIsActive = 'Y' - ORDER BY M_PapSmearBahanID ASC - "; - //echo $sql; - $bahans = $this->db_smartone->query($sql)->result_array(); - - $sql = "SELECT IFNULL(Other_PapsmearCategoryID,0) as xid, - M_PapSmearCategoryID as category_id, - M_PapSmearCategoryName as name, - IF(ISNULL(Other_PapsmearCategoryID),'N','Y') as selected - FROM m_papsmearcategory - LEFT JOIN other_papsmearcategory ON Other_PapsmearCategoryM_PapSmearCategoryID = M_PapSmearCategoryID AND - Other_PapsmearCategoryOther_PapSmearID = {$header_id} AND - Other_PapsmearCategoryIsActive = 'Y' - WHERE - M_PapSmearCategoryIsActive = 'Y' - ORDER BY M_PapSmearCategoryID ASC - "; - //echo $sql; - $categories = $this->db_smartone->query($sql)->result_array(); - - $sql = "SELECT IFNULL(Other_PapSmearCheckID,0) as xid, - M_PapSmearCheckID as check_id, - M_PapSmearCheckLabel as name, - IF(ISNULL(Other_PapSmearCheckID),'N','Y') as selected, - Other_PapSmearCheckNote as note - FROM m_papsmearcheck - LEFT JOIN other_papsmearcheck ON Other_PapSmearCheckM_PapSmearCheckID = M_PapSmearCheckID AND - Other_PapSmearCheckOther_PapSmearID = {$header_id} AND - Other_PapSmearCheckIsActive = 'Y' - WHERE - M_PapSmearCheckIsActive = 'Y' - ORDER BY M_PapSmearCheckCode ASC - "; - $checks = $this->db_smartone->query($sql)->result_array(); - - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $rst = array('doctors'=>$doctors,'checks'=>$checks,'bahans'=>$bahans,'categories'=>$categories,'maturasi'=>$maturasi,'results'=>$rows); - $this->sys_ok(["records"=>$rst]); - - } - - function saveresult_lcprep() - { - $prm = $this->sys_input; - $detail_id = $prm['detail_id']; - $doctor_id = $prm['doctor']; - $adekuasi = $prm['adekuasi']; - $kategoriumum = $prm['kategoriumum']; - $interpretasi = $prm['interpretasi']; - $results = $prm['results']; - - $userid = $this->sys_user['M_UserID']; - - $header_id = 0; - $sql = "SELECT * FROM other_lcprep WHERE Other_LcprepT_orderDetailID = {$detail_id} AND Other_LcprepIsActive = 'Y'"; - $dt_header = $this->db_smartone->query($sql)->row_array(); - if($dt_header){ - $header_id = $dt_header['Other_LcprepID']; - } - if($header_id == 0){ - $sql = "INSERT INTO other_lcprep( - Other_LcprepT_orderDetailID, - Other_LcprepM_DoctorID, - Other_LcprepUserID, - Other_LcprepCreated - ) - VALUES( - {$detail_id}, - {$doctor_id}, - {$userid}, - NOW() - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - }else{ - $sql = "UPDATE other_lcprep SET Other_LcprepM_DoctorID = {$doctor_id}, Other_LcprepUserID = {$userid} WHERE Other_LcprepID = {$header_id}"; - $this->db_smartone->query($sql); - } - - if($adekuasi){ - foreach($adekuasi as $k =>$v){ - $selected = $v['chex']?'Y':'N'; - if(intval($v['xid'] == 0)){ - $sql = "UPDATE other_lcprepadekuasi SET Other_LcprepAdekuasiIsActive = 'N' - WHERE - Other_LcprepAdekuasiOther_LcprepID = {$header_id} AND - Other_LcprepAdekuasiIsActive = 'Y' AND - Other_LcprepAdekuasiLcprep_AdekuasiID = {$v['id']}"; - $this->db_smartone->query($sql); - $sql = "INSERT INTO other_lcprepadekuasi ( - Other_LcprepAdekuasiOther_LcprepID, - Other_LcprepAdekuasiLcprep_AdekuasiID, - Other_LcprepAdekuasiChex, - Other_LcprepAdekuasiUserID, - Other_LcprepAdekuasiCreated - ) - VALUES( - {$header_id}, - {$v['id']}, - '{$selected}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - //echo $sql; - } - if(intval($v['xid'] != 0)){ - - $sql = "UPDATE other_lcprepadekuasi SET - Other_LcprepAdekuasiChex = '{$selected}', - Other_LcprepAdekuasiUserID = {$userid} - WHERE - Other_LcprepAdekuasiID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - - //echo $sql; - } - } - - if($kategoriumum){ - foreach($kategoriumum as $k =>$v){ - $selected = $v['chex']?'Y':'N'; - if(intval($v['xid'] == 0)){ - $sql = "UPDATE other_lcprepkategoriumum SET Other_LcprepKategoriUmumIsActive = 'N' - WHERE - Other_LcprepKategoriUmumOther_LcprepID = {$header_id} AND - Other_LcprepKategoriUmumLcprep_KategoriUmumID = {$v['id']} AND - Other_LcprepKategoriUmumIsActive = 'Y' - "; - $this->db_smartone->query($sql); - $sql = "INSERT INTO other_lcprepkategoriumum ( - Other_LcprepKategoriUmumOther_LcprepID, - Other_LcprepKategoriUmumLcprep_KategoriUmumID, - Other_LcprepKategoriUmumChex, - Other_LcprepKategoriUmumUserID, - Other_LcprepKategoriUmumCreated - ) - VALUES( - {$header_id}, - {$v['id']}, - '{$selected}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if(intval($v['xid'] != 0)){ - $sql = "UPDATE other_lcprepkategoriumum SET - Other_LcprepKategoriUmumChex = '{$selected }', - Other_LcprepKategoriUmumUserID = {$userid} - WHERE - Other_LcprepKategoriUmumID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - - //echo $sql; - } - } - - if($results){ - foreach($results as $k =>$v){ - if(intval($v['xid'] == 0)){ - $sql = "UPDATE other_lcprepdetails SET Other_LcprepDetailsIsActive = 'N' - WHERE - Other_LcprepDetailsOther_LcprepID = {$header_id} AND - Other_LcprepDetailsCode = '{$v['code']}' AND - Other_LcprepDetailsIsActive = 'Y'"; - $this->db_smartone->query($sql); - $sql = "INSERT INTO other_lcprepdetails ( - Other_LcprepDetailsOther_LcprepID, - Other_LcprepDetailsCode, - Other_LcprepDetailsLabel, - Other_LcprepDetailsResult, - Other_LcprepDetailsUserID, - Other_LcprepDetailsCreated - ) - VALUES( - {$header_id}, - '{$v['code']}', - '{$v['label']}', - '{$v['result']}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if(intval($v['xid'] != 0)){ - $sql = "UPDATE other_lcprepdetails SET - Other_LcprepDetailsCode = '{$v['code']}', - Other_LcprepDetailsLabel = '{$v['label']}', - Other_LcprepDetailsResult = '{$v['result']}', - Other_LcprepDetailsUserID = {$userid} - WHERE - Other_LcprepDetailsID = {$v['xid']}"; - $this->db_smartone->query($sql); - - } - //echo $sql; - } - } - - if($interpretasi){ - foreach($interpretasi as $k =>$v){ - if(count($v['subgroups']) > 0){ - foreach($v['subgroups'] as $ik => $iv){ - if(count($iv['childs']) > 0){ - foreach($iv['childs'] as $iik => $iiv){ - if(intval($iiv['xid'] == 0)){ - $chex = $iiv['chex'] ? 'Y':'N'; - $sql = "UPDATE other_lcprepinterpretasi SET Other_LcprepInterpretasiIsActive = 'N' - WHERE - Other_LcprepInterpretasiOther_LcprepID = {$header_id} AND - Other_LcprepInterpretasiLcprep_InterpretasiID = '{$iiv['id']}' AND - Other_LcprepInterpretasiIsActive = 'Y'"; - $this->db_smartone->query($sql); - $sql = "INSERT INTO other_lcprepinterpretasi ( - Other_LcprepInterpretasiOther_LcprepID, - Other_LcprepInterpretasiLcprep_InterpretasiID, - Other_LcprepInterpretasiChex, - Other_LcprepInterpretasiValue, - Other_LcprepInterpretasiUserID, - Other_LcprepInterpretasiCreated - ) - VALUES( - {$header_id}, - '{$iiv['id']}', - '{$chex}', - '{$iiv['value']}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - - if(intval($iiv['xid'] != 0)){ - $chex = $iiv['chex'] ? 'Y':'N'; - $sql = "UPDATE other_lcprepinterpretasi SET - Other_LcprepInterpretasiChex = '{$chex}', - Other_LcprepInterpretasiValue = '{$iiv['value']}', - Other_LcprepInterpretasiUserID = {$userid} - WHERE - Other_LcprepInterpretasiID = {$iiv['xid']}"; - $this->db_smartone->query($sql); - //echo $sql; - - } - - } - } - } - } - //echo $sql; - } - } - - - $result = array("total" => 1, "records" => array(), "sql"=> ''); - $this->sys_ok($result); - exit; - } - - function saveresult_papsmear() - { - $prm = $this->sys_input; - $detail_id = $prm['detail_id']; - $doctor_id = $prm['doctor']; - $checks = $prm['checks']; - $maturasi = $prm['maturasi']; - $bahans = $prm['bahans']; - $categories = $prm['categories']; - $results = $prm['results']; - - $userid = $this->sys_user['M_UserID']; - - $header_id = 0; - $sql = "SELECT * FROM other_papsmear WHERE Other_PapSmearT_OrderDetailID = {$detail_id} AND Other_PapSmearIsActive = 'Y'"; - $dt_header = $this->db_smartone->query($sql)->row_array(); - if($dt_header){ - $header_id = $dt_header['Other_PapSmearID']; - } - if($header_id == 0){ - $sql = "INSERT INTO other_papsmear( - Other_PapSmearT_OrderDetailID, - Other_PapSmearM_DoctorID, - Other_PapSmearUserID, - Other_PapSmearCreated - ) - VALUES( - {$detail_id}, - {$doctor_id}, - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } - else{ - $sql = "UPDATE other_papsmear SET Other_PapSmearM_DoctorID = {$doctor_id}, Other_PapSmearUserID = {$userid} WHERE Other_PapSmearID = {$header_id}"; - $this->db_smartone->query($sql); - } - - if($checks){ - foreach($checks as $k =>$v){ - if(intval($v['xid']) == 0 && $v['selected'] === 'Y'){ - $sql = "INSERT INTO other_papsmearcheck ( - Other_PapSmearCheckOther_PapSmearID, - Other_PapSmearCheckM_PapSmearCheckID, - Other_PapSmearCheckNote, - Other_PapSmearCheckUserID, - Other_PapSmearCheckCreated - ) - VALUES( - {$header_id}, - {$v['check_id']}, - '{$v['note']}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if(intval($v['xid']) != 0 && $v['selected'] === 'N'){ - $sql = "UPDATE other_papsmearcheck SET - Other_PapSmearCheckIsActive = 'N', - Other_PapSmearCheckUserID = {$userid} - WHERE - Other_PapSmearCheckID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - if(intval($v['xid']) != 0 && $v['selected'] === 'Y'){ - $sql = "UPDATE other_papsmearcheck SET - Other_PapSmearCheckNote = '{$v['note']}', - Other_PapSmearCheckUserID = {$userid} - WHERE - Other_PapSmearCheckID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - //echo $sql; - } - } - - if($maturasi){ - if(intval($maturasi['xid']) == 0){ - $value = join("/",$maturasi['value']); - $sql = "INSERT INTO other_papsmearmaturasi ( - Other_PapSmearMaturasiOther_PapSmearID, - Other_PapSmearMaturasiValue, - Other_PapSmearMaturasiUserID, - Other_PapSmearMaturasiCreated - ) - VALUE( - {$header_id}, - '{$value}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - //echo $sql; - } - if(intval($maturasi['xid']) != 0){ - $value = join("/",$maturasi['value']); - $sql = "UPDATE other_papsmearmaturasi SET - Other_PapSmearMaturasiValue = '{$value}', - Other_PapSmearMaturasiUserID = {$userid} - WHERE - Other_PapSmearMaturasiID = {$maturasi['xid']}"; - // echo $sql; - $this->db_smartone->query($sql); - } - } - - if($bahans){ - foreach($bahans as $k =>$v){ - if(intval($v['xid']) == 0 && $v['selected'] === 'Y'){ - $sql = "INSERT INTO other_papsmearbahan ( - Other_PapSmearBahanOther_PapSmearID, - Other_PapSmearBahanM_PapSmearBahanID, - Other_PapSmearBahanUserID, - Other_PapSmearBahanCreated - ) - VALUES( - {$header_id}, - {$v['bahan_id']}, - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if(intval($v['xid']) != 0 && $v['selected'] === 'N'){ - $sql = "UPDATE other_papsmearbahan SET - Other_PapSmearBahanIsActive = 'N', - Other_PapsmearCategoryUserID = {$userid} - WHERE - Other_PapSmearBahanID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - if(intval($v['xid']) != 0 && $v['selected'] === 'Y'){ - $sql = "UPDATE other_papsmearbahan SET - Other_PapSmearBahanIsActive = 'Y', - Other_PapsmearCategoryUserID = {$userid} - WHERE - Other_PapSmearBahanID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - //echo $sql; - } - } - - if($categories){ - foreach($categories as $k =>$v){ - if(intval($v['xid']) == 0 && $v['selected'] === 'Y'){ - $sql = "INSERT INTO other_papsmearcategory ( - Other_PapsmearCategoryOther_PapSmearID, - Other_PapsmearCategoryM_PapSmearCategoryID, - Other_PapsmearCategoryUserID, - Other_PapsmearCategoryCreated - ) - VALUES( - {$header_id}, - {$v['category_id']}, - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if(intval($v['xid']) != 0 && $v['selected'] === 'N'){ - $sql = "UPDATE other_papsmearcategory SET - Other_PapsmearCategoryIsActive = 'N', - Other_PapsmearCategoryUserID = {$userid} - WHERE - Other_PapsmearCategoryID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - //echo $sql; - if(intval($v['xid']) != 0 && $v['selected'] === 'Y'){ - $sql = "UPDATE other_papsmearcategory SET - Other_PapsmearCategoryIsActive = 'Y', - Other_PapsmearCategoryUserID = {$userid} - WHERE - Other_PapsmearCategoryID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - } - } - - if($results){ - foreach($results as $k =>$v){ - if(intval($v['xid']) == 0){ - $sql = "INSERT INTO other_papsmeardetails ( - Other_PapSmearDetailsOther_PapSmearID, - Other_PapSmearDetailsCode, - Other_PapSmearDetailsLabel, - Other_PapSmearDetailsResult, - Other_PapSmearDetailsUserID, - Other_PapSmearDetailsCreated - ) - VALUES( - {$header_id}, - '{$v['code']}', - '{$v['label']}', - '{$v['result']}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if(intval($v['xid']) != 0){ - $sql = "UPDATE other_papsmeardetails SET - Other_PapSmearDetailsCode = '{$v['code']}', - Other_PapSmearDetailsLabel = '{$v['label']}', - Other_PapSmearDetailsResult = '{$v['result']}', - Other_PapSmearDetailsUserID = {$userid} - WHERE - Other_PapSmearDetailsID = {$v['xid']}"; - $this->db_smartone->query($sql); - - } - //echo $sql; - } - } - - $result = array("total" => 1, "records" => array(), "sql"=> ''); - $this->sys_ok($result); - exit; - } - - function saveresult_fna() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = $inp['doctor']; - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - if($prm[0]['xid'] == '0'){ - $sql = "INSERT INTO other_fna( - Other_FNAM_DoctorID, - Other_FNAT_OrderDetailID, - Other_FNAUserID, - Other_FNACreated - ) - VALUES( - {$doctor_id}, - {$prm[0]['orderdetail_id']}, - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } - else{ - $sql = "SELECT * FROM other_fna WHERE Other_FNAT_OrderDetailID = {$prm[0]['orderdetail_id']} AND Other_FNAIsActive = 'Y'"; - $data_header = $this->db_smartone->query($sql)->row_array(); - $header_id = $data_header['Other_FNAID']; - $sql = "UPDATE other_fna SET - Other_FNAM_DoctorID = {$doctor_id}, - Other_FNAUserID = {$userid} - WHERE - Other_FNAID = {$header_id}"; - $this->db_smartone->query($sql); - } - foreach($prm as $k => $v){ - if($v['xid'] == '0'){ - $results = str_replace("'", "\\'", $v['result']); - $sql = "INSERT INTO other_fnadetails( - Other_FNADetailsOther_FNAID , - Other_FNADetailsCode, - Other_FNADetailsLabel, - Other_FNADetailsResult, - Other_FNADetailsCreated, - Other_FNADetailsUserID - ) - VALUES( - {$header_id}, - '{$v['code']}', - '{$v['label']}', - '{$results}', - NOW(), - {$userid} - )"; - $query = $this->db_smartone->query($sql); - } - else{ - $results = str_replace("'", "\\'", $v['result']); - $sql = "UPDATE other_fnadetails SET - Other_FNADetailsResult = '{$results}', - Other_FNADetailsUserID = {$userid} - WHERE - Other_FNADetailsID = {$v['xid']}"; - $query = $this->db_smartone->query($sql); - } - } - - $result = array("total" => 1, "records" => array(), "sql"=> ''); - $this->sys_ok($result); - exit; - } - - function saveresult_cytologi() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = $inp['doctor']; - - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - if($prm[0]['xid'] == '0'){ - $sql = "INSERT INTO other_cytologi( - Other_CytologiT_OrderDetailID, - Other_CytologiM_DoctorID, - Other_CytologiUserID, - Other_CytologiCreated - ) - VALUES( - {$prm[0]['orderdetail_id']}, - {$doctor_id}, - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } - else{ - $sql = "SELECT * FROM other_cytologi WHERE Other_CytologiT_OrderDetailID = {$prm[0]['orderdetail_id']} AND Other_CytologiIsActive = 'Y'"; - $data_header = $this->db_smartone->query($sql)->row_array(); - $header_id = $data_header['Other_CytologiID']; - $sql = "UPDATE other_cytologi SET - Other_CytologiM_DoctorID = {$doctor_id}, - Other_CytologiUserID = {$userid} - WHERE - Other_CytologiID = {$header_id}"; - $this->db_smartone->query($sql); - } - foreach($prm as $k => $v){ - if($v['xid'] == '0'){ - $results = str_replace("'", "\\'", $v['result']); - $sql = "INSERT INTO other_cytologidetails( - Other_CytologiDetailsOther_CytologiID , - Other_CytologiDetailsCode, - Other_CytologiDetailsLabel, - Other_CytologiDetailsResult, - Other_CytologiDetailsCreated, - Other_CytologiDetailsUserID - ) - VALUES( - {$header_id}, - '{$v['code']}', - '{$v['label']}', - '{$results}', - NOW(), - {$userid} - )"; - $query = $this->db_smartone->query($sql); - } - else{ - $results = str_replace("'", "\\'", $v['result']); - $sql = "UPDATE other_cytologidetails SET - Other_CytologiDetailsResult = '{$results}', - Other_CytologiDetailsUserID = {$userid} - WHERE - Other_CytologiDetailsID = {$v['xid']}"; - $query = $this->db_smartone->query($sql); - } - } - - $result = array("total" => 1, "records" => array(), "sql"=> ''); - $this->sys_ok($result); - exit; - } - - function saveresult_mikro() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = $inp['doctor']; - $backteria_id = $inp['bacteria']; - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - - if($inp['result_value'] != 'Negatif' && $inp['result_value'] != 'Positif'){ - $prm['result_value'] = $prm['result_other']; - } - else{ - $prm['result_value'] = $inp['result_value']; - } - - if($prm['xid'] == '0'){ - $sql = "INSERT INTO other_mikro( - Other_MikroM_DoctorID, - Other_MikroResult, - Other_MikroT_BacteriaID, - Other_MikroT_OrderDetailID, - Other_MikroHasilBiakan, - Other_MikroSampleTypeName, - Other_MikroUserID, - Other_MikroCreated - ) - VALUES( - {$doctor_id}, - '{$prm['result_value']}', - {$backteria_id}, - {$prm['orderdetail_id']}, - '{$prm['hasil_biakan']}', - '{$prm['sample_name']}', - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } - else{ - $sql = "SELECT * FROM other_mikro WHERE Other_MikroT_OrderDetailID = {$prm['orderdetail_id']} AND Other_MikroIsActive = 'Y'"; - $data_header = $this->db_smartone->query($sql)->row_array(); - $header_id = $data_header['Other_MikroID']; - $sql = "UPDATE other_mikro SET - Other_MikroResult = '{$prm['result_value']}', - Other_MikroM_DoctorID = {$doctor_id}, - Other_MikroT_BacteriaID = {$backteria_id}, - Other_MikroHasilBiakan = '{$prm['hasil_biakan']}', - Other_MikroSampleTypeName = '{$prm['sample_name']}', - Other_MikroUserID = {$userid} - WHERE - Other_MikroID = {$header_id}"; - //echo $sql; - $this->db_smartone->query($sql); - } - - - - $sql = "UPDATE other_mikrodetails SET Other_MikroDetailsIsActive = 'N', Other_MikroDetailsUserID = 0 WHERE Other_MikroDetailsOther_MikroID = {$header_id}"; - $this->db_smartone->query($sql); - - $results = $prm['details']; - if($inp['result_value'] == 'Positif'){ - foreach($results as $k => $v){ - if($v['xid'] == '0'){ - $sql = "INSERT INTO other_mikrodetails( - Other_MikroDetailsOther_MikroID , - Other_MikroDetailsT_AntibioticID, - Other_MikroDetailsValue, - Other_MikroDetailsNote, - Other_MikroDetailsCreated, - Other_MikroDetailsUserID - ) - VALUES( - {$header_id}, - '{$v['T_AntibioticID']}', - '{$v['value']}', - '{$v['note']}', - NOW(), - {$userid} - )"; - $query = $this->db_smartone->query($sql); - } - else{ - $sql = "UPDATE other_mikrodetails SET - Other_MikroDetailsT_AntibioticID = '{$v['T_AntibioticID']}', - Other_MikroDetailsValue = '{$v['value']}', - Other_MikroDetailsNote = '{$v['note']}', - Other_MikroDetailsIsActive = 'Y', - Other_MikroDetailsUserID = {$userid} - WHERE - Other_MikroDetailsID = {$v['xid']}"; - //echo $sql; - $query = $this->db_smartone->query($sql); - } - } - } - - - $result = array("total" => 1, "records" => array(), "sql"=> ''); - $this->sys_ok($result); - exit; - } - - - function get_doctors_preparasi_sperma() - { - $prm = $this->sys_input; - // $id = $prm["id"]; - - $sql = " SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 10 AND - M_DoctorSOIsActive = 'Y' - ORDER BY M_DoctorName ASC"; - //echo $sql; - $query = $this->db_smartone->query($sql); - - if ($query) - { - $rows = $query->result_array(); - $this->sys_ok(["records"=>$rows]); - } - else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - - function getpreparasispermaresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT other_preparasisperma.*, - Other_PreparasiSpermaID as xid, - Other_PreparasiSpermaT_OrderDetailID as orderdetail_id, - IFNULL(Other_PreparasiSpermaM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_PreparasiSpermaM_DoctorID) OR Other_PreparasiSpermaM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_preparasisperma - LEFT JOIN m_doctor ON Other_PreparasiSpermaM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_PreparasiSpermaT_OrderDetailID = {$id} AND Other_PreparasiSpermaIsActive = 'Y' - GROUP BY Other_PreparasiSpermaID"; - $query = $this->db_smartone->query($sql); - - if ($query) - { - $rows = $query->row_array(); - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 10 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $images = array(); - $sql = "SELECT Other_PreparasiSpermaImgID as xid, - Other_PreparasiSpermaImgType as type, - CONCAT('/one-media/one-image-nonlab/',Other_PreparasiSpermaImgNewName) as image_url - FROM t_orderdetail - JOIN other_preparasisperma_img ON Other_PreparasiSpermaImgT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND - Other_PreparasiSpermaImgIsActive = 'Y' - WHERE - T_OrderDetailID = {$id} AND - T_OrderDetailIsActive = 'Y' - GROUP BY Other_PreparasiSpermaImgID"; - //echo $sql; - $images = $this->db_smartone->query($sql)->result_array(); - - $rst = array('doctors'=>$doctors,'results'=>$rows,'images'=>$images); - $this->sys_ok(["records"=>$rst]); - } - else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - - function uploadimage_preparasi_sperma(){ - if (! $this->isLogin) { - $this->sys_error("Invalid Token"); - exit; - } - - $userid = $this->sys_user["M_UserID"]; - $data = []; - //print_r($_SERVER); - - $prm = $this->sys_input; - $orderid = $this->input->post('orderid'); - $type = $this->input->post('type'); - $labnumber = $this->input->post('labnumber'); - $sql = "UPDATE other_preparasisperma_img SET - Other_PreparasiSpermaImgIsActive = 'N', - Other_PreparasiSpermaImgUserID = {$userid} - WHERE - Other_PreparasiSpermaImgT_OrderHeaderID = {$orderid} AND - Other_PreparasiSpermaImgType = '{$type}'"; - //echo $sql; - $this->db_onedev->query($sql); - //$config['upload_path'] = 'assets/'; - - $path = '/home/one/project/one/one-media/one-image-nonlab/'; - //echo $path; - $config['upload_path'] = $path; - $config['allowed_types'] = 'jpg|jpeg|png|gif'; - - $config['max_size'] = '10000'; - $count = count($_FILES['files']['name']); - //echo $count; - $this->load->library('upload',$config); - - $error = []; - for($i=0;$i<$count;$i++){ - - - if(!empty($_FILES['files']['name'][$i])){ - - - - $_FILES['file']['name'] = $_FILES['files']['name'][$i]; - - $_FILES['file']['type'] = $_FILES['files']['type'][$i]; - - $_FILES['file']['tmp_name'] = $_FILES['files']['tmp_name'][$i]; - - $_FILES['file']['error'] = $_FILES['files']['error'][$i]; - - $_FILES['file']['size'] = $_FILES['files']['size'][$i]; - - - - $namex = $orderid.'-'.$labnumber.'-'.$this->generateRandomString(5); - //echo $namex; - - $config['file_name'] = $namex; - $this->upload->initialize($config); - //echo $config['file_name'] ; - - - - - - if($this->upload->do_upload('file')){ - - $uploadData = $this->upload->data(); - - $filename = $uploadData['file_name']; - //echo $filename; - - - $sql = "INSERT INTO other_preparasisperma_img ( - Other_PreparasiSpermaImgT_OrderHeaderID, - Other_PreparasiSpermaImgType, - Other_PreparasiSpermaImgOldName, - Other_PreparasiSpermaImgNewName, - Other_PreparasiSpermaImgCreated, - Other_PreparasiSpermaImgUserID - ) - VALUES( - {$orderid}, - '{$type}', - '{$_FILES['files']['name'][$i]}', - '{$filename}', - NOW(), - {$userid} - - )"; - //echo $sql; - $this->db_onedev->query($sql); - $xlast_id = $this->db_onedev->insert_id(); - $data['totalFiles'][] = array('xid' => $xlast_id ,'type'=>$type,'image_url' => '/one-media/one-image-nonlab/'.$filename); - - } - else{ - $error = array('error' => $this->upload->display_errors()); - } - - } - - - - } - - $result = array("total" =>count( $data['totalFiles']), "records" => $data['totalFiles'],'errors'=>$error); - $this->sys_ok($result); - } - - - function saveresult_preparasi_sperma() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = $inp['doctor']; - $orderdetail_id = $inp['orderdetailid']; - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - if($prm['xid'] == '0'){ - $sql = "INSERT INTO other_preparasisperma( - Other_PreparasiSpermaM_DoctorID, - Other_PreparasiSpermaT_OrderDetailID, - Other_PreparasiSpermaPreMotilitasA, - Other_PreparasiSpermaPreMotilitasB, - Other_PreparasiSpermaPreMotilitasC, - Other_PreparasiSpermaPreKonsentrasi, - Other_PreparasiSpermaPreKontaminan, - Other_PreparasiSpermaPostMotilitasA, - Other_PreparasiSpermaPostMotilitasB, - Other_PreparasiSpermaPostMotilitasC, - Other_PreparasiSpermaPostKonsentrasi, - Other_PreparasiSpermaPostKontaminan, - Other_PreparasiSpermaNote, - Other_PreparasiSpermaUserID, - Other_PreparasiSpermaCreated - ) - VALUES( - {$doctor_id}, - {$orderdetail_id}, - '{$prm['Other_PreparasiSpermaPreMotilitasA']}', - '{$prm['Other_PreparasiSpermaPreMotilitasB']}', - '{$prm['Other_PreparasiSpermaPreMotilitasC']}', - '{$prm['Other_PreparasiSpermaPreKonsentrasi']}', - '{$prm['Other_PreparasiSpermaPreKontaminan']}', - '{$prm['Other_PreparasiSpermaPostMotilitasA']}', - '{$prm['Other_PreparasiSpermaPostMotilitasB']}', - '{$prm['Other_PreparasiSpermaPostMotilitasC']}', - '{$prm['Other_PreparasiSpermaPostKonsentrasi']}', - '{$prm['Other_PreparasiSpermaPostKontaminan']}', - '{$prm['Other_PreparasiSpermaNote']}', - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } - else{ - $sql = "SELECT * FROM other_preparasisperma WHERE Other_PreparasiSpermaT_OrderDetailID = {$orderdetail_id} AND Other_PreparasiSpermaIsActive = 'Y'"; - $data_header = $this->db_smartone->query($sql)->row_array(); - $header_id = $data_header['Other_PreparasiSpermaID']; - $sql = "UPDATE other_preparasisperma SET - Other_PreparasiSpermaM_DoctorID = {$doctor_id}, - Other_PreparasiSpermaPreMotilitasA = '{$prm['Other_PreparasiSpermaPreMotilitasA']}', - Other_PreparasiSpermaPreMotilitasB = '{$prm['Other_PreparasiSpermaPreMotilitasB']}', - Other_PreparasiSpermaPreMotilitasC = '{$prm['Other_PreparasiSpermaPreMotilitasC']}', - Other_PreparasiSpermaPreKonsentrasi = '{$prm['Other_PreparasiSpermaPreKonsentrasi']}', - Other_PreparasiSpermaPreKontaminan = '{$prm['Other_PreparasiSpermaPreKontaminan']}', - Other_PreparasiSpermaPostMotilitasA = '{$prm['Other_PreparasiSpermaPostMotilitasA']}', - Other_PreparasiSpermaPostMotilitasB = '{$prm['Other_PreparasiSpermaPostMotilitasB']}', - Other_PreparasiSpermaPostMotilitasC = '{$prm['Other_PreparasiSpermaPostMotilitasC']}', - Other_PreparasiSpermaPostKonsentrasi = '{$prm['Other_PreparasiSpermaPostKonsentrasi']}', - Other_PreparasiSpermaPostKontaminan = '{$prm['Other_PreparasiSpermaPostKontaminan']}', - Other_PreparasiSpermaNote = '{$prm['Other_PreparasiSpermaNote']}', - Other_PreparasiSpermaUserID = {$userid} - WHERE - Other_PreparasiSpermaID = {$header_id}"; - $this->db_smartone->query($sql); - } - - - $result = array("total" => 1, "records" => array(), "sql"=> ''); - $this->sys_ok($result); - exit; - } - - function getdnafragmentasiresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT other_dnafragmentasi.*, - Other_DnaFragmentasiID as xid, - Other_DnaFragmentasiT_OrderDetailID as orderdetail_id, - IFNULL(Other_DnaFragmentasiM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_DnaFragmentasiM_DoctorID) OR Other_DnaFragmentasiM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name, - IFNULL(Other_DnaFragmentasiOther_DnaFragmentasiMethodeID,0) as methode_id, - IFNULL(Other_DnaFragmentasiMethodeName,'') as methode_name, - Other_DnaFragmentasiHaloLuas as halo_luas, - Other_DnaFragmentasiHaloSedang as halo_sedang, - Other_DnaFragmentasiHaloSempit as halo_sempit, - Other_DnaFragmentasiTanpaHalo as tanpa_halo, - Other_DnaFragmentasiDFI as dfi, - Other_DnaFragmentasiKesimpulan as kesimpulan, - Other_DnaFragmentasiCatatan as catatan - FROM other_dnafragmentasi - LEFT JOIN m_doctor ON Other_DnaFragmentasiM_DoctorID = M_DoctorID - LEFT JOIN other_dnafragmentasimethode ON Other_DnaFragmentasiOther_DnaFragmentasiMethodeID = Other_DnaFragmentasiMethodeID - WHERE - Other_DnaFragmentasiT_OrderDetailID = {$id} AND Other_DnaFragmentasiIsActive = 'Y' - GROUP BY Other_DnaFragmentasiID - LIMIT 1"; - //echo $sql; - $query = $this->db_smartone->query($sql); - - if ($query) - { - $rows = $query->row_array(); - if(!$rows){ - $rows = array( - 'xid' => 0, - 'orderdetail_id' =>$id, - 'doctor_id' => 0, - 'doctor_name' => '', - 'methode_id' => 0, - 'methode_name' => '', - 'halo_luas' => '', - 'halo_sedang' => '', - 'tanpa_halo' => '', - 'dfi' => '', - 'kesimpulan' => '', - 'catatan' => '' - ); - } - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID - WHERE - M_DoctorSONat_SubGroupID = 4 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - - $sql = " - SELECT '0' as id, 'Belum memilih metode' as name - UNION - SELECT Other_DnaFragmentasiMethodeID as id, Other_DnaFragmentasiMethodeName as name - FROM other_dnafragmentasimethode - WHERE - Other_DnaFragmentasiMethodeIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $methodes = $this->db_smartone->query($sql)->result_array(); - - - $rst = array('doctors'=>$doctors,'methodes'=>$methodes,'results'=>$rows); - $this->sys_ok(["records"=>$rst]); - } - else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - function saveresult_dnafragmentasi() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = $inp['doctor']['id']; - $methode_id = $inp['methode']['id']; - $orderdetail_id = $inp['results']['orderdetail_id']; - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - if(intval($prm['xid']) == 0){ - $sql = "INSERT INTO other_dnafragmentasi( - Other_DnaFragmentasiT_OrderDetailID, - Other_DnaFragmentasiM_DoctorID, - Other_DnaFragmentasiOther_DnaFragmentasiMethodeID, - Other_DnaFragmentasiHaloLuas, - Other_DnaFragmentasiHaloSedang, - Other_DnaFragmentasiHaloSempit, - Other_DnaFragmentasiTanpaHalo, - Other_DnaFragmentasiDFI, - Other_DnaFragmentasiKesimpulan, - Other_DnaFragmentasiCatatan, - Other_DnaFragmentasiUserID, - Other_DnaFragmentasiLastUpdated - ) - VALUES( - {$orderdetail_id}, - {$doctor_id}, - {$methode_id}, - '{$prm['halo_luas']}', - '{$prm['halo_sedang']}', - '{$prm['halo_sempit']}', - '{$prm['tanpa_halo']}', - '{$prm['dfi']}', - '{$prm['kesimpulan']}', - '{$prm['catatan']}', - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } - else{ - $sql = "UPDATE other_dnafragmentasi SET - Other_DnaFragmentasiT_OrderDetailID = {$orderdetail_id}, - Other_DnaFragmentasiM_DoctorID = {$doctor_id}, - Other_DnaFragmentasiOther_DnaFragmentasiMethodeID = '{$methode_id}', - Other_DnaFragmentasiHaloLuas = '{$prm['halo_luas']}', - Other_DnaFragmentasiHaloSedang = '{$prm['halo_sedang']}', - Other_DnaFragmentasiHaloSempit = '{$prm['halo_sempit']}', - Other_DnaFragmentasiTanpaHalo = '{$prm['tanpa_halo']}', - Other_DnaFragmentasiDFI = '{$prm['dfi']}', - Other_DnaFragmentasiKesimpulan = '{$prm['kesimpulan']}', - Other_DnaFragmentasiCatatan = '{$prm['catatan']}', - Other_DnaFragmentasiLastUpdated = NOW(), - Other_DnaFragmentasiUserID = {$userid} - WHERE - Other_DnaFragmentasiID = {$prm['xid']}"; - //echo $sql; - $this->db_smartone->query($sql); - } - - - $result = array("total" => 1, "records" => array(), "sql"=> ''); - $this->sys_ok($result); - exit; - } - - -} - +db_smartone = $this->load->database("onedev", true); + $this->load->helper(array('form', 'url')); + } + function getMethodeID($natTestID) { + $sql = "select M_MethodePriorityNat_MethodeID MethodeID, Nat_MethodeName + from + m_methode_priority + join nat_methode on Nat_MethodeID = M_MethodePriorityNat_MethodeID + and Nat_MethodeIsActive = 'Y' + join m_instrumentmethode on M_InstrumentMethodeNat_MethodeID = Nat_MethodeID and M_InstrumentMethodeIsActive = 'Y' + join nat_instrument on M_InstrumentMethodeNat_InstrumentID = Nat_InstrumentID + and Nat_InstrumentIsActive ='Y' + where M_MethodePriorityIsActive = 'Y' + and M_MethodePriorityNat_TestID = $natTestID + and M_MethodePriorityM_DayOfWeekID = dayofweek(now()) + order by M_MethodePriorityNumber desc + limit 0,1 "; + $qry = $this->db->query($sql); + if ($qry) { + $rows = $qry->result_array(); + if (count($rows) > 0 ) return array($rows[0]["MethodeID"],$rows[0]["Nat_MethodeName"]); + } + //2nd + $sql= "select + M_InstrumentMethodeNat_MethodeID MethodeID, Nat_MethodeName + from m_instrumentmethode + join nat_methode on M_InstrumentMethodeNat_MethodeID = Nat_MethodeID + and Nat_MethodeIsActive = 'Y' + join nat_instrument on M_InstrumentMethodeNat_InstrumentID = Nat_InstrumentID + and Nat_InstrumentIsActive ='Y' + where M_InstrumentMethodeNat_TestID = $natTestID + and M_InstrumentMethodeIsActive = 'Y' + order by M_InstrumentMethodePriority desc + limit 0,1"; + $qry = $this->db->query($sql); + if ($qry) { + $rows = $qry->result_array(); + if (count($rows) > 0 ) return array($rows[0]["MethodeID"],$rows[0]["Nat_MethodeName"]); + } + // + $sql = "select Nat_NormalValueNat_MethodeID MethodeID, Nat_MethodeName + from + nat_normalvalue + join nat_methode on Nat_NormalValueNat_MethodeID = Nat_MethodeID + and Nat_MethodeIsActive = 'Y' + where Nat_NormalValueNat_TestID = $natTestID + and Nat_NormalValueIsActive = 'Y' + order by Nat_NormalValueID + limit 0,1"; + $qry = $this->db->query($sql); + if ($qry) { + $rows = $qry->result_array(); + if (count($rows) > 0 ) return array($rows[0]["MethodeID"],$rows[0]["Nat_MethodeName"]); + } + return array(0,""); + } + function get_normal_value($methodeID, $natTestID, $sexID, $ageInDay ) { + $this->load->library('ibl_sampling_normal'); + return $this->ibl_sampling_normal->get_normal_value_id($methodeID, $natTestID, $sexID, $ageInDay); + } + return 0; + } + function fn_fix_normal($order_id) { + $sql = "select + T_OrderDetailID, M_PatientM_SexID, fn_global_age_count_day(M_PatientDOB, date(T_OrderHeaderDate)) Dob , + T_TestNat_TestID + from t_orderheader + join m_patient on T_OrderHeaderID = $order_id and T_OrderHeaderM_PatientID = M_PatientID + join t_orderdetail on T_OrderDetailT_OrderHeaderID = T_OrderHeaderID + and T_OrderDetailIsACtive = 'Y' + and ( T_OrderDetailNat_NormalValueID is null or T_OrderDetailNat_NormalValueID = 0 ) + join t_test on T_OrderDetailT_TestID = T_TestID and T_TestIsResult = 'Y' "; + $qry = $this->db->query($sql); + if(! $qry) { + return; + } + $rows = $qry->result_array(); + if(count($rows) == 0 ) return; + $sql_u = "update t_orderdetail + join nat_normalvalue on T_OrderDetailID = ? and Nat_NormalValueID = ? + set + T_OrderDetailNat_NormalValueID = Nat_NormalValueID, + T_OrderDetailNormalValueNote = Nat_NormalValueNote, + T_OrderDetailNormalValueDescription = Nat_NormalValueDescription, + T_OrderDetailMinValue = Nat_NormalValueMinValue, + T_OrderDetailMaxValue = Nat_NormalValueMaxValue, + T_OrderDetailMinValueInclusive = Nat_NormalValueMinValueInclusive, + T_OrderDetailMaxValueInclusive = Nat_NormalValueMaxValueInclusive, + T_OrderDetailNat_MethodeID = ?, + T_OrderdetailNat_MethodeName =?"; + + foreach($rows as $r) { + $T_OrderDetailID = $r["T_OrderDetailID"]; + $sexID = $r["M_PatientM_SexID"]; + $ageInDay = $r["Dob"]; + $natTestID = $r["T_TestNat_TestID"]; + list($methodeID,$methodeName) = $this->getMethodeID($natTestID); + if ($methodeID == 0 ) continue; + $normalValueID = $this->get_normal_value($methodeID, $natTestID, $sexID, $ageInDay); + if ($normalValueID == 0) return; + $this->db->query($sql_u, array($T_OrderDetailID, $normalValueID, $methodeID, $methodeName)); + } + } + function update_order_sample($targetID, $sourceID) { + $sql = "update t_ordersample target + join t_ordersample source on + target.T_OrderSampleID = ? + and target.T_OrderSampleWorklistReceive = 'N' + and source.T_OrderSampleID = ? + set + target.T_OrderSampleSampling = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSampling, source.T_OrderSampleSampling), + target.T_OrderSampleSamplingDate = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingDate, source.T_OrderSampleSamplingDate), + target.T_OrderSampleSamplingTime = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingTime, source.T_OrderSampleSamplingTime), + target.T_OrderSampleSamplingUserID = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingUserID, source.T_OrderSampleSamplingUserID), + + target.T_OrderSampleReceive = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceive, source.T_OrderSampleReceive), + target.T_OrderSampleReceiveDate = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveDate, source.T_OrderSampleReceiveDate), + target.T_OrderSampleReceiveTime = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveTime, source.T_OrderSampleReceiveTime), + target.T_OrderSampleReceiveUserID = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveUserID, source.T_OrderSampleReceiveUserID), + + target.T_OrderSampleVerification = if(target.T_OrderSampleVerification='Y',target.T_OrderSampleVerification, source.T_OrderSampleVerification), + target.T_OrderSampleVerificationDate =if(target.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationDate, source.T_OrderSampleVerificationDate), + target.T_OrderSampleVerificationTime =if(source.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationTime, source.T_OrderSampleVerificationTime), + target.T_OrderSampleVerificationUserID =if(source.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationUserID, source.T_OrderSampleVerificationUserID), + + target.T_OrderSampleProcessing = if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessing, source.T_OrderSampleProcessing), + target.T_OrderSampleProcessingDate= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingDate, source.T_OrderSampleProcessingDate), + target.T_OrderSampleProcessingTime= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingTime, source.T_OrderSampleProcessingTime), + target.T_OrderSampleProcessingUserID= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingUserID, source.T_OrderSampleProcessingUserID), + + target.T_OrderSampleReceiveHandling =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandling, source.T_OrderSampleReceiveHandling ), + target.T_OrderSampleReceiveHandlingDate =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingDate, source.T_OrderSampleReceiveHandlingDate), + target.T_OrderSampleReceiveHandlingTime =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingTime, source.T_OrderSampleReceiveHandlingTime), + target.T_OrderSampleReceiveHandlingUserID =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingUserID, source.T_OrderSampleReceiveHandlingUserID), + + target.T_OrderSampleHandling = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandling, source.T_OrderSampleHandling), + target.T_OrderSampleHandlingDate = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingDate, source.T_OrderSampleHandlingDate), + target.T_OrderSampleHandlingTime = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingTime, source.T_OrderSampleHandlingTime), + target.T_OrderSampleHandlingUserID = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingUserID, source.T_OrderSampleHandlingUserID), + + target.T_OrderSampleWorklistReceive = source.T_OrderSampleWorklistReceive, + target.T_OrderSampleWorklistReceiveDatetime = source.T_OrderSampleWorklistReceiveDateTime, + target.T_OrderSampleWorklistReceiveUserID = source.T_OrderSampleWorklistReceiveUserID + "; + $qry = $this->db->query($sql,array($targetID,$sourceID)); + if(! $qry ) { + echo json_encode(array( "status" => "ERR" , "message" => print_r($this->db->error(),true))); + exit; + } + } + function fix_sample_serum($headerID) { + //cari t_ordersample yg belum worklist receive dengan code 017% + $sql = "select T_OrderSampleID + from t_ordersample + join t_sampletype on + T_OrderSampleT_OrderHeaderID = ? + and T_OrderSampleWorklistReceive = 'N' + and T_OrderSampleIsActive = 'Y' + and T_OrderSampleT_SampleTypeID = T_SampletypeID + and T_SampleTypeCode like '017%' + "; + $qry = $this->db->query($sql, array($headerID)); + if(!$qry) { + echo json_encode(array( "status" => "ERR" , "message" => print_r($this->db->error(),true))); + exit; + } + $rows = $qry->result_array(); + if (count($rows) == 0 ) return; + //cari T_OrderSample yang sudah di receive yg terakhir + $sql = "select T_OrderSampleID + from t_ordersample + join t_sampletype on + T_OrderSampleT_OrderHeaderID = ? + and T_OrderSampleWorklistReceive = 'Y' + and T_OrderSampleIsActive = 'Y' + and T_OrderSampleT_SampleTypeID = T_SampletypeID + and T_SampleTypeCode like '017%' + order by T_OrderSampleWorklistReceiveDatetime desc + limit 0,1 + "; + $qry = $this->db->query($sql, array($headerID)); + if(!$qry) { + echo json_encode(array( "status" => "ERR" , "message" => print_r($this->db->error(),true))); + exit; + } + $rcv_rows = $qry->result_array(); + if (count($rcv_rows) == 0 ) return; + + //print_r($rows); + //print_r($rcv_rows); + $rcv_T_OrderSampleID = $rcv_rows[0]["T_OrderSampleID"]; + //ada yg belum di receive + foreach($rows as $r) { + $T_OrderSampleID = $r["T_OrderSampleID"]; + $this->update_order_sample($T_OrderSampleID,$rcv_T_OrderSampleID); + } + } + public function search() + { + $prm = $this->sys_input; + $max_rst = 99; + + $id = $prm["order_id"]; + if ($id > 0 ) { + $this->fix_sample_serum($id); + $this->fn_fix_normal($id); + } + $lang = $this->lang_default_code; + $lang_id = isset($prm['lang_id']) ? $prm['lang_id'] : '0'; + + if ($lang_id != 0) + { + $l = $this->db_smartone->where("Nat_LangID", $lang_id)->get("nat_lang")->row(); + $lang = $l->Nat_LangCode; + } + + //tambahan fajri + $sql = " UPDATE t_orderdetail + JOIN t_test ON T_OrderDetailT_TestID = T_TestID + SET T_OrderDetailT_TestIsResult = T_TestIsResult + WHERE + T_OrderDetailT_OrderHeaderID = {$id} AND + T_OrderDetailT_TestIsResult = '' AND + T_OrderDetailIsActive = 'Y'"; + $this->db_smartone->query($sql); + + $tot_count = 0; + $lq = ""; + $group_id = 0; + if (isset($prm['group_id'])) + $group_id = $prm['group_id']; + + if ($group_id != 0) + { + $sql = "select distinct T_WorklistDetailNat_TestID Nat_TestID + from t_worklistdetailv2 + where T_WorklistDetailT_WorklistID = {$group_id}"; + $qry = $this->db_smartone->query($sql); + $rows = $qry->result_array(); + $nat_test_ids = "0"; + foreach($rows as $r) { + $nat_test_ids .= ", " . $r["Nat_TestID"]; + } + $q_group = " ( $nat_test_ids ) "; + + $sql = " + SELECT a1.*, cOUNT(a2.T_OrderDetailID) level + FROM ( + SELECT IFNULL(y.T_OrderDetailT_TestID, x.T_OrderDetailT_TestID) t_testid, + IFNULL(y.T_OrderDetailT_TestName, y.T_OrderDetailT_TestName) t_testname, + y.T_OrderDetailResult result, y.T_OrderDetailResult result_old, y.T_OrderDetailNote note, y.T_OrderDetailNote note_old, + y.T_OrderDetailID id, + y.T_OrderDetailT_TestIsResult is_result, a.T_TestIsQuantitative is_quantitative, + y.T_OrderDetailResultFlag result_flag, + y.T_OrderDetailNat_NormalValueID normal_id, + y.T_OrderDetailNormalValueNote normal_note, y.T_OrderDetailNat_UnitName unit_name, + y.T_OrderdetailNat_MethodeID methode_id, y.T_OrderdetailNat_MethodeName methode_name, + a.T_TestNat_TestID nattest_id, a.T_TestID tx_id, count(T_ResultInstrumentID) as result_instrument_n, + y.T_OrderDetailVerification, T_OrderSampleReceive sample_receive, + T_OrderSampleProcessing sample_processing, T_OrderSampleWorklistReceive sample_worklist_receive, + IF(T_OrderDetailAddOnPreAnalytic = 'Y', T_OrderDetailAddOnPreAnalytic, PreAnalyticIsOk) pre_analytic, + T_OrderDetailAddOnPreAnalytic, + T_OrderHeaderID order_id, y.T_OrderDetailT_TestSasCode test_sas_code, + tx.T_TestSasCode, + T_OrderDetailAddOnResample `resample`, T_OrderDetailAddOnResampleStatus resample_status, + T_OrderDetailAddOnRef ref, y.T_OrderDetailVerification verification, y.T_OrderDetailValidation validation, + T_OrderPromiseDateTime, Group_ResultName as ResultGroupName + FROM t_orderdetail x + left join t_orderpromise on x.T_OrderDetailT_OrderPromiseID = T_OrderPromiseID + JOIN t_test tx ON x.T_OrderDetailT_TestID = T_TestID + JOIN t_test tcheck on tcheck.T_TestNat_TestID in {$q_group} + and ( tx.T_TestID = tcheck.T_TestID or tx.T_TestSasCode like concat(tcheck.T_TestSasCode,'%')) + LEFT JOIN group_resultdetail ON Group_ResultDetailT_TestID = x.T_OrderDetailT_TestID AND Group_ResultDetailIsActive = 'Y' + LEFT JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND Group_ResultFlagNonLab = 'N' + LEFT JOIN t_orderdetail y ON x.T_OrderDetailT_TestSasCode LIKE CONCAT(y.T_OrderDetailT_TestSasCode, '%') + AND x.T_OrderDetailT_OrderHeaderID = y.T_OrderDetailT_OrderHeaderID + AND y.T_OrderDetailIsActive = 'Y' + LEFT JOIN t_orderdetailaddon ON x.T_OrderDetailID = T_OrderDetailAddOnT_OrderDetailID + JOIN t_orderheader ON y.T_OrderDetailT_OrderHeaderID = T_OrderHeaderID + LEFT JOIN t_test a ON y.T_OrderDetailT_TestID = a.T_TestID + AND a.T_TestIsNonLab = '' + LEFT JOIN (SELECT T_OrderSampleT_SampleTypeID, T_OrderSampleReceive, T_OrderSampleProcessing, T_OrderSampleWorklistReceive + FROM t_ordersample WHERE T_OrderSampleT_OrderHeaderID = {$id} + AND T_OrderSampleIsactive = 'Y' + GROUP BY T_OrderSampleT_SampleTypeID) os ON a.T_TestT_SampleTypeID = os.T_OrderSampleT_SampleTypeID + or os.T_OrderSampleT_SampleTypeID = fn_sampletype_from_local(a.T_TestNat_TestID) + + LEFT JOIN t_resultinstrument ON T_ResultInstrumentT_OrderDetailID = x.T_OrderDetailID + LEFT JOIN pre_analytic ON PreAnalyticNat_TestID = a.T_TestNat_TestID AND PreAnalyticDate = date(now()) and PreAnalyticIsActive = 'Y' + WHERE x.T_OrderDetailT_OrderHeaderID = {$id} + AND x.T_OrderDetailIsActive = 'Y' + GROUP BY y.T_OrderDetailT_TestID + ORDER BY y.T_OrderDetailT_TestSasCode ASC + ) a1 + + LEFT JOIN t_orderdetail a2 ON a2.T_OrderDetailT_OrderHeaderID = a1.order_id + AND a2.T_OrderDetailIsActive = 'Y' + AND a1.test_sas_code LIKE CONCAT(a2.T_OrderDetailT_testSasCode, '%') + GROUP BY a1.t_testid + order by a1.test_sas_code +"; + $query = $this->db_smartone->query($sql); + $lq = $this->db_smartone->last_query(); + } + else + { + $sql = " + SELECT a1.*, cOUNT(a2.T_OrderDetailID) level + FROM ( + SELECT IFNULL(y.T_OrderDetailT_TestID, x.T_OrderDetailT_TestID) t_testid, + IFNULL(y.T_OrderDetailT_TestName, y.T_OrderDetailT_TestName) t_testname, + y.T_OrderDetailResult result, y.T_OrderDetailResult result_old, y.T_OrderDetailNote note, y.T_OrderDetailNote note_old, + y.T_OrderDetailID id, + y.T_OrderDetailT_TestIsResult is_result, a.T_TestIsQuantitative is_quantitative, + y.T_OrderDetailResultFlag result_flag, + y.T_OrderDetailNat_NormalValueID normal_id, + y.T_OrderDetailNormalValueNote normal_note, y.T_OrderDetailNat_UnitName unit_name, + y.T_OrderdetailNat_MethodeID methode_id, y.T_OrderdetailNat_MethodeName methode_name, + a.T_TestNat_TestID nattest_id, a.T_TestID tx_id, count(T_ResultInstrumentID) as result_instrument_n, + y.T_OrderDetailVerification, T_OrderSampleReceive sample_receive, + T_OrderSampleProcessing sample_processing, T_OrderSampleWorklistReceive sample_worklist_receive, + IF(T_OrderDetailAddOnPreAnalytic = 'Y', T_OrderDetailAddOnPreAnalytic, PreAnalyticIsOk) pre_analytic, + T_OrderDetailAddOnPreAnalytic, + T_OrderHeaderID order_id, y.T_OrderDetailT_TestSasCode test_sas_code, + tx.T_TestSasCode, + T_OrderDetailAddOnResample `resample`, T_OrderDetailAddOnResampleStatus resample_status, + T_OrderDetailAddOnRef ref, y.T_OrderDetailVerification verification, y.T_OrderDetailValidation validation, + T_OrderPromiseDateTime , Group_ResultName as ResultGroupName + FROM t_orderdetail x + left join t_orderpromise on x.T_OrderDetailT_OrderPromiseID = T_OrderPromiseID + JOIN t_test tx ON x.T_OrderDetailT_TestID = T_TestID + LEFT JOIN group_resultdetail ON Group_ResultDetailT_TestID = x.T_OrderDetailT_TestID AND Group_ResultDetailIsActive = 'Y' + LEFT JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND Group_ResultFlagNonLab = 'N' + LEFT JOIN t_orderdetail y ON x.T_OrderDetailT_TestSasCode LIKE CONCAT(y.T_OrderDetailT_TestSasCode, '%') + AND x.T_OrderDetailT_OrderHeaderID = y.T_OrderDetailT_OrderHeaderID + AND y.T_OrderDetailIsActive = 'Y' + + LEFT JOIN t_orderdetailaddon ON x.T_OrderDetailID = T_OrderDetailAddOnT_OrderDetailID + + JOIN t_orderheader ON y.T_OrderDetailT_OrderHeaderID = T_OrderHeaderID + LEFT JOIN t_test a ON y.T_OrderDetailT_TestID = a.T_TestID + AND a.T_TestIsNonLab = '' + LEFT JOIN (SELECT T_OrderSampleT_SampleTypeID, T_OrderSampleReceive, T_OrderSampleProcessing, T_OrderSampleWorklistReceive + FROM t_ordersample WHERE T_OrderSampleT_OrderHeaderID = {$id} + AND T_OrderSampleIsactive = 'Y' + GROUP BY T_OrderSampleT_SampleTypeID) os ON a.T_TestT_SampleTypeID = os.T_OrderSampleT_SampleTypeID + or os.T_OrderSampleT_SampleTypeID = fn_sampletype_from_local(a.T_TestNat_TestID) + + LEFT JOIN t_resultinstrument ON T_ResultInstrumentT_OrderDetailID = x.T_OrderDetailID + LEFT JOIN pre_analytic ON PreAnalyticNat_TestID = a.T_TestNat_TestID AND PreAnalyticDate = date(now()) and PreAnalyticIsActive = 'Y' + WHERE x.T_OrderDetailT_OrderHeaderID = {$id} + AND x.T_OrderDetailIsActive = 'Y' + GROUP BY y.T_OrderDetailT_TestID + ORDER BY y.T_OrderDetailT_TestSasCode ASC + ) a1 + + LEFT JOIN t_orderdetail a2 ON a2.T_OrderDetailT_OrderHeaderID = a1.order_id + AND a2.T_OrderDetailIsActive = 'Y' + AND a1.test_sas_code LIKE CONCAT(a2.T_OrderDetailT_testSasCode, '%') + GROUP BY a1.t_testid + order by a1.test_sas_code +"; +//echo $sql; + $query = $this->db_smartone->query($sql); + $lq = $this->db_smartone->last_query(); + } + // file_put_contents("/xtmp/re-query.sql",$lq); + + if ($query) { + $rst = []; + $rows = $query->result_array(); + + foreach($rows as $k => $v) + { + + if ($v['is_result'] == "Y" && $v['is_quantitative'] == "N") + { + $v['template'] = []; + $x = $this->db_smartone->query("CALL sp_master_resulttemplate_get('{$v['t_testid']}')"); + $this->clean_mysqli_connection($this->db_smartone->conn_id); + if ($x) + $v['template'] = $x->result_array(); + } + + // IF Rujukan, by pas Pre Analytik + if ($v['ref'] == 'Y') + $v['pre_analytic'] = 'Y'; + if ($v["id"] == "885455" ) + { + //sipe workaround + //$v["sample_receive"] = "Y"; + $v["sample_worklist_receive"] = "Y"; + } + $rst[] = $v; + } + + $result = array("total" => $tot_count, "records" => $rst, "total_display" => sizeof($rows), "q" => $lq); + $this->sys_ok($result); + } + else { + $this->sys_error_db("RE Px rows", $this->db_smartone); + exit; + } + } + + public function save() + { + $prm = $this->sys_input; + $data = json_decode($prm["data"]); + $lang = $this->lang_default_code; + $lang_id = isset($prm['lang_id']) ? $prm['lang_id'] : '0'; + + if ($lang_id != 0) + { + $l = $this->db_smartone->where("Nat_LangID", $lang_id)->get("nat_lang")->row(); + $lang = $l->Nat_LangCode; + } + + $sql_norm = "select T_OrderDetailMinValue, T_OrderDetailMaxValue, + T_OrderDetailMinValueInclusive, T_OrderDetailMaxValueInclusive, + Nat_TestFlagLow, Nat_TestFlagHigh + from t_orderdetail + join t_test on T_OrderDetailT_TestID = T_TestID + join nat_test on T_TestNat_TestID = Nat_TestID and T_TestIsActive = 'Y' + where T_OrderDetailID = ? "; + + $ids = []; + foreach ($data as $k => $v) + { + if ( $v->resultInstrumentID > 0 ) { + $sql_i = "select T_ResultInstrumentNat_NormalValueID normalValueID + from t_resultinstrument + where T_ResultInstrumentID = ?"; + $qry_i = $this->db_smartone->query($sql_i, array($v->resultInstrumentID)); + if ($qry_i) { + $rows_i = $qry_i->result_array(); + + if (count($rows_i) > 0 ) { + $sql_iu = "update t_orderdetail, nat_normalvalue , nat_methode + set T_OrderDetailMinValue = Nat_NormalValueMinValue, + T_OrderDetailMinValueInclusive = Nat_NormalValueMinValueInclusive, + T_OrderDetailMaxValue = Nat_NormalValueMaxValue , + T_OrderDetailMaxValueInclusive = Nat_NormalValueMaxValueInclusive, + T_OrderDetailNormalValueNote = Nat_NormalValueNote, + T_OrderDetailNormalValueDescription = Nat_NormalValueDescription, + T_OrderDetailNat_NormalValueID = Nat_NormalValueID, + T_OrderDetailNat_MethodeID = Nat_NormalValueNat_MethodeID, + T_OrderDetailNat_MethodeName = Nat_MethodeName + where T_OrderDetailID = ? and Nat_NormalValueID = ? + and Nat_NormalValueNat_MethodeID = Nat_MethodeID + "; + $this->db_smartone->query($sql_iu, array($v->id, $rows_i[0]["normalValueID"])); + //file_put_contents("/xtmp/update-nilai-normal", $this->db_smartone->last_query() . "\n", FILE_APPEND); + } + } + } + $y = $this->db_smartone->query("SELECT fn_process_sample_handling_perfect('{$v->order_id}', '{$v->test_id}') c") + ->row(); + $req_status = $y->c; + $qry_norm = $this->db_smartone->query($sql_norm,$v->id); + $result_flag = ""; + if ($qry_norm) { + $rows_norm = $qry_norm->result_array(); + if (count($rows_norm) > 0 ) { + $r = $rows_norm[0]; + if (is_numeric($v->result)) { + + if ( $r["T_OrderDetailMinValueInclusive"] == "Y" && $v->result < $r["T_OrderDetailMinValue"] ) { + $result_flag = $r["Nat_TestFlagLow"]; + } + if ( $r["T_OrderDetailMinValueInclusive"] == "N" && $v->result <= $r["T_OrderDetailMinValue"] ) { + $result_flag = $r["Nat_TestFlagLow"]; + } + if ( $r["T_OrderDetailMaxValueInclusive"] == "Y" && $v->result > $r["T_OrderDetailMaxValue"] ) { + $result_flag = $r["Nat_TestFlagHigh"]; + } + if ( $r["T_OrderDetailMaxValueInclusive"] == "N" && $v->result >= $r["T_OrderDetailMaxValue"] ) { + $result_flag = $r["Nat_TestFlagHigh"]; + } + } + } + } + if ($lang == $this->lang_default_code) + { + $this->db_smartone->set('T_OrderDetailResult', $v->result) + ->set('T_OrderDetailResultFlag', $result_flag) + ->set('T_OrderDetailNote', $v->note) + ->set('T_OrderDetailReqStatus', $req_status) + ->where('T_OrderDetailID', $v->id) + ->update('t_orderdetail'); + } + else + { + $this->db_smartone->set('T_OrderDetailLangResult', $v->result) + ->set('T_OrderDetailLangNote', $v->note) + ->where('T_OrderDetailLangID', $v->id) + ->update('t_orderdetaillang'); + } + + $ids[] = $v->id; + } + + // LOG Process + $order = $this->db_smartone->select('T_OrderDetailT_OrderHeaderID id, T_OrderHeaderLabNumber lab_number', false) + ->join('t_orderheader', 'T_OrderHeaderID = T_OrderDetailT_OrderHeaderID') + ->where('T_OrderDetailID', $data[0]->id) + ->get('t_orderdetail') + ->row(); + + $dblog = $this->load->database("onelog", true); + $dblog->set('Log_ProcessCode', 'PROCESS.Result.Entry') + ->set('Log_ProcessOrderID', $order->id) + ->set('Log_ProcessOrderNumber', $order->lab_number) + ->set('Log_ProcessJson', json_encode($data)) + ->set('Log_ProcessUserID', $this->sys_user['M_UserID']) + ->insert('log_process'); + // END OF Log Process + //auto calculation + $this->load->library("Resultcalc"); + $rows = $this->resultcalc->auto($order->id); + + try { + foreach($ids as $id ) { + $this->db_smartone->query("call sp_set_normal_value_flag($id)"); + $this->clean_mysqli_connection($this->db_smartone->conn_id); + } + } catch(Exception $e) { + } + + $this->sys_ok($ids); + } + + public function save_template() + { + $prm = $this->sys_input; + + $n = $this->db_smartone->select("COUNT(T_ResultTemplateID) n") + ->where("T_ResultTemplateT_TestID", $prm['test_id']) + ->where("T_ResultTemplateIsActive", "Y") + ->where("T_ResultTemplateValue", $prm['value']) + ->get('t_resulttemplate') + ->row(); + if ($n->n > 0) + { + $this->sys_error_db("Insert Result Template", $this->db_smartone); + return; + } + + $r = $this->db_smartone->set("T_ResultTemplateT_TestID", $prm['test_id']) + ->set("T_ResultTemplateValue", $prm['value']) + ->insert('t_resulttemplate'); + if ($r) + { + $template = []; + $x = $this->db_smartone->query("CALL sp_master_resulttemplate_get('{$prm['test_id']}')"); + $this->clean_mysqli_connection($this->db_smartone->conn_id); + if ($x) + $template = $x->result_array(); + + $this->sys_ok($template); + } + } + + public function export() + { + $prm = $this->sys_input; + + $sql = "CALL sp_process_result_lang(?, ?, ?, ?)"; + $query = $this->db_smartone->query($sql, [$prm['order_id'], $prm['lang_id'], $prm['is_si'], $this->sys_user['M_UserID']]); + if ($query) + { + $r = $query->row(); + if ($r->status == "OK") + { + $this->sys_ok($r->data); + return; + } + + $this->sys_error_db("Message : " . $r->message, $this->db_smartone); + } + else + { + $this->sys_error_db("Lang Result", $this->db_smartone); + return; + } + } + + public function search_group() + { + $prm = $this->sys_input; + $max_rst = 100; + + // QUERY TOTAL + $sql = "select count(*) total + from t_worklist + where T_WorklistIsActive = 'Y' + order by T_WorklistName ASC"; + $query = $this->db_smartone->query($sql); + + if ($query) { + $tot_count = $query->result_array()[0]["total"]; + } + else { + $this->sys_error_db("worklist count", $this->db_smartone); + exit; + } + + $sql = "select T_WorklistID group_id, T_WorklistName group_name + from t_worklist + where T_WorklistIsActive = 'Y' + order by T_WorklistName ASC + limit 0, {$max_rst}"; + $query = $this->db_smartone->query($sql); + + if ($query) { + $rows = $query->result_array(); + foreach ($rows as $k => $v) + $rows[$k]['data'] = json_decode($v['data']); + $result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows), "q" => $this->db_smartone->last_query()); + $this->sys_ok($result); + } + else { + $this->sys_error_db("worklist rows", $this->db_smartone); + exit; + } + } + + public function search_rerun() + { + $prm = $this->sys_input; + $id = $prm["detail_id"]; + + $sql = "CALL sp_process_result_rerun(?)"; + $query = $this->db_smartone->query($sql, [$id]); + + if ($query) + { + $rows = $query->result_array(); + $this->sys_ok(["records"=>$rows]); + } + else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + + + function getdoctorsfna() + { + $prm = $this->sys_input; + // $id = $prm["id"]; + + $sql = " SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY M_DoctorName ASC"; + //echo $sql; + $query = $this->db_smartone->query($sql); + + if ($query) + { + $rows = $query->result_array(); + $this->sys_ok(["records"=>$rows]); + } + else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + function getfnaresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT Other_FNADetailsID as xid, + Other_FNAT_OrderDetailID as orderdetail_id, + Other_FNADetailsCode as code, + Other_FNADetailsLabel as label, + Other_FNADetailsResult as result, + IFNULL(Other_FNAM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_FNAM_DoctorID) OR Other_FNAM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_fna + JOIN other_fnadetails ON Other_FNADetailsOther_FNAID = Other_FNAID AND Other_FNADetailsIsActive = 'Y' + LEFT JOIN m_doctor ON Other_FNAM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_FNAT_OrderDetailID = {$id} AND Other_FNAIsActive = 'Y' + GROUP BY Other_FNADetailsID + ORDER BY Other_FNADetailsCode ASC"; + $query = $this->db_smartone->query($sql); + + if ($query) + { + $rows = $query->result_array(); + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $images = array(); + $sql = "SELECT So_ImageUploadID as xid, + CONCAT('/one-media/one-image-nonlab/',So_ImageUploadNewName) as image_url + FROM t_orderdetail + JOIN so_imageupload ON So_ImageUploadT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND + So_ImageUploadIsActive = 'Y' + WHERE + T_OrderDetailID = {$id} AND + T_OrderDetailIsActive = 'Y' + GROUP BY So_ImageUploadID"; + $images = $this->db_smartone->query($sql)->result_array(); + + $rst = array('doctors'=>$doctors,'results'=>$rows,'images'=>$images); + $this->sys_ok(["records"=>$rst]); + } + else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + + function uploadimage(){ + if (! $this->isLogin) { + $this->sys_error("Invalid Token"); + exit; + } + + $userid = $this->sys_user["M_UserID"]; + $data = []; + //print_r($_SERVER); + + $prm = $this->sys_input; + $orderid = $this->input->post('orderid'); + $labnumber = $this->input->post('labnumber'); + $sql = "UPDATE so_imageupload SET + So_ImageUploadIsActive = 'N', + So_ImageUploadUserID = {$userid} + WHERE + So_ImageUploadT_OrderHeaderID = {$orderid}"; + //echo $sql; + $this->db_onedev->query($sql); + //$config['upload_path'] = 'assets/'; + + $path = '/home/one/project/one/one-media/one-image-nonlab/'; + //echo $path; + $config['upload_path'] = $path; + $config['allowed_types'] = 'jpg|jpeg|png|gif'; + + $config['max_size'] = '10000'; + $count = count($_FILES['files']['name']); + //echo $count; + $this->load->library('upload',$config); + + $error = []; + for($i=0;$i<$count;$i++){ + + + if(!empty($_FILES['files']['name'][$i])){ + + + + $_FILES['file']['name'] = $_FILES['files']['name'][$i]; + + $_FILES['file']['type'] = $_FILES['files']['type'][$i]; + + $_FILES['file']['tmp_name'] = $_FILES['files']['tmp_name'][$i]; + + $_FILES['file']['error'] = $_FILES['files']['error'][$i]; + + $_FILES['file']['size'] = $_FILES['files']['size'][$i]; + + + + $namex = $orderid.'-'.$labnumber.'-'.$this->generateRandomString(5); + //echo $namex; + + $config['file_name'] = $namex; + $this->upload->initialize($config); + //echo $config['file_name'] ; + + + + + + if($this->upload->do_upload('file')){ + + $uploadData = $this->upload->data(); + + $filename = $uploadData['file_name']; + //echo $filename; + + + $sql = "INSERT INTO so_imageupload ( + So_ImageUploadT_OrderHeaderID, + So_ImageUploadT_OrderHeaderLabNumber, + So_ImageUploadT_SampleTypeID, + So_ImageUploadOldName, + So_ImageUploadNewName, + So_ImageUploadCreated, + So_ImageUploadUserID + ) + VALUES( + {$orderid}, + '{$labnumber}', + '150', + '{$_FILES['files']['name'][$i]}', + '{$filename}', + NOW(), + {$userid} + + )"; + //echo $sql; + $this->db_onedev->query($sql); + $xlast_id = $this->db_onedev->insert_id(); + $data['totalFiles'][] = array('xid' => $xlast_id ,'image_url' => '/one-media/one-image-nonlab/'.$filename); + + } + else{ + $error = array('error' => $this->upload->display_errors()); + } + + } + + + + } + + $result = array("total" =>count( $data['totalFiles']), "records" => $data['totalFiles'],'errors'=>$error); + $this->sys_ok($result); + } + + + function generateRandomString($length = 10) { + $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; + $charactersLength = strlen($characters); + $randomString = ''; + for ($i = 0; $i < $length; $i++) { + $randomString .= $characters[rand(0, $charactersLength - 1)]; + } + return $randomString; + } + + function getcytologiresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT Other_CytologiDetailsID as xid, + Other_CytologiT_OrderDetailID as orderdetail_id, + Other_CytologiDetailsCode as code, + Other_CytologiDetailsLabel as label, + Other_CytologiDetailsResult as result, + IFNULL(Other_CytologiM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_CytologiM_DoctorID) OR Other_CytologiM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_cytologi + JOIN other_cytologidetails ON Other_CytologiDetailsOther_CytologiID = Other_CytologiID AND Other_CytologiDetailsIsActive = 'Y' + LEFT JOIN m_doctor ON Other_CytologiM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_CytologiT_OrderDetailID = {$id} AND Other_CytologiIsActive = 'Y' + GROUP BY Other_CytologiDetailsID + ORDER BY Other_CytologiDetailsCode ASC"; + //echo $sql; + $query = $this->db_smartone->query($sql); + + if ($query) + { + $rows = $query->result_array(); + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $rst = array('doctors'=>$doctors,'results'=>$rows); + $this->sys_ok(["records"=>$rst]); + } + else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + function getmikroresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT + Other_MikroID as xid, + Other_MikroHasilBiakan as hasil_biakan, + Other_MikroSampleTypeName as sample_name, + Other_MikroT_OrderDetailID as orderdetail_id, + Other_MikroResult as result_value, + '' as result_other, + IFNULL(T_BacteriaID,0) as T_BacteriaID, + IFNULL(T_BacteriaName,'') as T_BacteriaName, + '' as details, + IFNULL(Other_MikroM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_MikroM_DoctorID) OR Other_MikroM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_mikro + LEFT JOIN t_bacteria ON Other_MikroT_BacteriaID = T_BacteriaID + LEFT JOIN m_doctor ON Other_MikroM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_MikroT_OrderDetailID = {$id} AND Other_MikroIsActive = 'Y' + GROUP BY Other_MikroID"; + //echo $sql; + $query = $this->db_smartone->query($sql); + + if ($query) + { + $row = $query->row_array(); + if($row){ + if($row['result_value'] != 'Positif' && $row['result_value'] != 'Negatif'){ + $row['result_other'] = $row['result_value']; + $row['result_value'] = 'other'; + } + $sql = "SELECT '' as xno, + Other_MikroDetailsID as xid, + Other_MikroDetailsValue as value, + IF(Other_MikroDetailsNote = 'R','Y','N') as chx_r, + IF(Other_MikroDetailsNote = 'I','Y','N') as chx_i, + IF(Other_MikroDetailsNote = 'S','Y','N') as chx_s, + Other_MikroDetailsNote as note, + t_antibiotic.* + FROM other_mikrodetails + LEFT JOIN t_antibiotic ON Other_MikroDetailsT_AntibioticID = T_AntibioticID + WHERE + Other_MikroDetailsOther_MikroID = {$row['xid']} AND Other_MikroDetailsIsActive = 'Y' + GROUP BY Other_MikroDetailsID + ORDER BY T_AntibioticName ASC"; + //echo $sql; + $details = $this->db_smartone->query($sql)->result_array(); + if(details){ + foreach($details as $k => $v){ + $details[$k]['xno'] = $k + 1; + } + } + $row['details'] = $details; + } + else{ + $row = array('xid'=>'0','hasil_biakan' => '','result_value'=>'Negatif','sample_name' => '','orderdetail_id'=>$id, 'T_BacteriaID'=>'0','T_BacteriaName'=>'0','details'=>array(),'doctor_id'=>'0','doctor_name'=>'0'); + } + } + else{ + $row = array('xid'=>'0','hasil_biakan' => '','result_value'=>'Negatif','sample_name' => '','orderdetail_id'=>$id, 'T_BacteriaID'=>'0','T_BacteriaName'=>'0','details'=>array(),'doctor_id'=>'0','doctor_name'=>'0'); + } + //print_r($row); + + + + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 7 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $sql = " + SELECT '0' as id, 'Belum memilih bakteria' as name + UNION + SELECT T_BacteriaID as id, T_BacteriaName as name + FROM t_bacteria + WHERE + T_BacteriaIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $bacteries = $this->db_smartone->query($sql)->result_array(); + $rst = array('doctors'=>$doctors,'bacteries'=>$bacteries,'results'=>$row); + $this->sys_ok(["records"=>$rst]); + } + function getantibiotics(){ + $prm = $this->sys_input; + $id = $prm["id"]; + $sql = " SELECT '' as xno, + 0 as xid, + '' as hasil_biakan, + '' as sample_name, + 0 as value, + 'Y' as chx_r, + 'N' as chx_i, + 'N' as chx_s, + 'R' as note, + t_antibiotic.* + FROM t_antibiotic + WHERE + T_AntibioticT_BacteriaID = {$prm['id']} AND T_AntibioticIsActive= 'Y' + ORDER BY T_AntibioticName ASC"; + //echo $sql; + $rows = $this->db_smartone->query($sql)->result_array(); + if(rows){ + foreach($rows as $k => $v){ + $rows[$k]['xno'] = $k + 1; + } + } + + $this->sys_ok(["records"=>$rows]); + } + function getlcprepresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + $sql = " SELECT Other_LcprepDetailsID as xid, + Other_LcprepID as header_id, + Other_LcprepT_orderDetailID as orderdetail_id, + Other_LcprepDetailsCode as code, + Other_LcprepDetailsLabel as label, + Other_LcprepDetailsResult as result, + IFNULL(Other_LcprepM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_LcprepM_DoctorID) OR Other_LcprepM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_lcprep + JOIN other_lcprepdetails ON Other_LcprepDetailsOther_LcprepID = Other_LcprepID AND Other_LcprepDetailsIsActive = 'Y' + LEFT JOIN m_doctor ON Other_LcprepM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_LcprepT_orderDetailID = {$id} AND Other_LcprepIsActive = 'Y' + GROUP BY Other_LcprepDetailsOther_LcprepID, Other_LcprepDetailsCode + ORDER BY Other_LcprepDetailsCode ASC"; + //echo $sql; + $rows = $this->db_smartone->query($sql)->result_array(); + if(!$rows){ + $rows = array( + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'A', + 'label' => 'DESKRIPSI', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ), + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'B', + 'label' => 'KESIMPULAN', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ) + ); + } + + $header_id = $rows[0]['header_id']; + $sql = "SELECT IFNULL(Other_LcprepAdekuasiID,0) as xid, + Lcprep_AdekuasiID as id, + Lcprep_AdekuasiLabel as name, + IF(ISNULL(Other_LcprepAdekuasiID),'N',Other_LcprepAdekuasiChex) as chex + FROM lcprep_adekuasi + LEFT JOIN other_lcprepadekuasi ON Other_LcprepAdekuasiLcprep_AdekuasiID = Lcprep_AdekuasiID AND + Other_LcprepAdekuasiOther_LcprepID = {$header_id} AND + Other_LcprepAdekuasiIsActive = 'Y' + WHERE + Lcprep_AdekuasiIsActive = 'Y' + GROUP BY Lcprep_AdekuasiID + ORDER BY Lcprep_AdekuasiOrder ASC + "; + //echo $sql; + $adeakuasi = $this->db_smartone->query($sql)->result_array(); + foreach($adeakuasi as $kc => $vc){ + $adeakuasi[$kc]['chex'] = $vc['chex'] == 'N'?false:true; + } + + $sql = "SELECT IFNULL(Other_LcprepKategoriUmumID,0) as xid, + Lcprep_KategoriUmumID as id, + Lcprep_KategoriUmumLabel as name, + IF(ISNULL(Other_LcprepKategoriUmumID),'N',Other_LcprepKategoriUmumChex) as chex + FROM lcprep_kategoriumum + LEFT JOIN other_lcprepkategoriumum ON Other_LcprepKategoriUmumLcprep_KategoriUmumID = Lcprep_KategoriUmumID AND + Other_LcprepKategoriUmumOther_LcprepID = {$header_id} AND + Other_LcprepKategoriUmumIsActive = 'Y' + WHERE + Lcprep_KategoriUmumIsActive = 'Y' + GROUP BY Lcprep_KategoriUmumID + "; + //echo $sql; + $kategoriumum = $this->db_smartone->query($sql)->result_array(); + foreach($kategoriumum as $kc => $vc){ + $kategoriumum[$kc]['chex'] = $vc['chex'] == 'N'?false:true; + } + + $sql = " + SELECT Lcprep_InterpretasiGroupID as group_id, + Lcprep_InterpretasiGroupName as group_name, + '' as subgroups + FROM lcprep_interpretasigroup + WHERE + Lcprep_InterpretasiGroupIsActive = 'Y' + "; + //echo $sql; + $interpretasi = $this->db_smartone->query($sql)->result_array(); + foreach($interpretasi as $k => $v){ + $subgroups = array(); + $sql = "SELECT Lcprep_InterpretasiSubgroupID as subgroup_id, + Lcprep_InterpretasiSubgroupName as subgroup_name, + '' as childs + FROM lcprep_interpretasisubgroup + WHERE + Lcprep_InterpretasiSubgroupLcprep_InterpretasiGroupID = {$v['group_id']} AND Lcprep_InterpretasiSubgroupIsActive = 'Y'"; + //echo $sql; + $subgroups = $this->db_smartone->query($sql)->result_array(); + if(count($subgroups) > 0){ + foreach($subgroups as $ki => $vi){ + $childs = array(); + $sql = "SELECT IFNULL(Other_LcprepInterpretasiID,0) as xid, + IFNULL(Other_LcprepInterpretasiChex,'N') as chex, + IFNULL(Other_LcprepInterpretasiValue,'') as value, + Lcprep_InterpretasiID as id, + Lcprep_InterpretasiLcprep_InterpretasiSubgroupID as subgroup_id, + Lcprep_InterpretasiCode as code, + Lcprep_InterpretasiName as name, + Lcprep_InterpretasiParentID as parent_id, + Lcprep_InterpretasiIsParent as is_parent, + Lcprep_InterpretasiHasResult as has_result, + Lcprep_InterpretasiTypeResult as type_result + FROM lcprep_interpretasi + LEFT JOIN other_lcprepinterpretasi ON Other_LcprepInterpretasiOther_LcprepID = {$header_id} AND + Other_LcprepInterpretasiLcprep_InterpretasiID = Lcprep_InterpretasiID AND + Other_LcprepInterpretasiIsActive = 'Y' + WHERE + Lcprep_InterpretasiLcprep_InterpretasiSubgroupID = {$vi['subgroup_id']} AND Lcprep_InterpretasiIsActive = 'Y' + GROUP BY Lcprep_InterpretasiID Order BY Lcprep_InterpretasiCode ASC"; + $childs = $this->db_smartone->query($sql)->result_array(); + if($childs){ + foreach($childs as $kc => $vc){ + $childs[$kc]['chex'] = $vc['chex'] == 'N'?false:true; + } + } + $subgroups[$ki]['childs'] = $childs; + } + } + + $interpretasi[$k]['subgroups'] = $subgroups; + } + + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $rst = array('doctors'=>$doctors,'results'=>$rows,'adekuasi'=>$adeakuasi,'kategoriumum'=>$kategoriumum,'interpretasi'=>$interpretasi); + $this->sys_ok(["records"=>$rst]); + } + + function getpapsmearresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT Other_PapSmearDetailsID as xid, + Other_PapSmearID as header_id, + Other_PapSmearT_OrderDetailID as orderdetail_id, + Other_PapSmearDetailsCode as code, + Other_PapSmearDetailsLabel as label, + Other_PapSmearDetailsResult as result, + IFNULL(Other_PapSmearM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_PapSmearM_DoctorID) OR Other_PapSmearM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_papsmear + JOIN other_papsmeardetails ON Other_PapSmearDetailsOther_PapSmearID = Other_PapSmearID AND Other_PapSmearDetailsIsActive = 'Y' + LEFT JOIN m_doctor ON Other_PapSmearM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_PapSmearT_OrderDetailID = {$id} AND Other_PapSmearIsActive = 'Y' + GROUP BY Other_PapSmearDetailsID + ORDER BY Other_PapSmearDetailsCode ASC"; + //echo $sql; + $rows = $this->db_smartone->query($sql)->result_array(); + if(!$rows){ + $rows = array( + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'A', + 'label' => 'Makroskopik', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ), + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'B', + 'label' => 'Mikroskopik', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ), + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'C', + 'label' => 'Kesimpulan', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ) + ); + } + + $header_id = $rows[0]['header_id']; + $sql = "SELECT Other_PapSmearMaturasiID as xid, + Other_PapSmearMaturasiValue as value + FROM other_papsmearmaturasi + WHERE + Other_PapSmearMaturasiOther_PapSmearID = {$header_id} AND + Other_PapSmearMaturasiIsActive = 'Y' + "; + //echo $sql; + $dt_maturasi = $this->db_smartone->query($sql)->row_array(); + if(!$dt_maturasi){ + $maturasi = array('xid'=>'0','value'=> array('','','')); + } + else{ + $value = explode('/',$dt_maturasi['value']); + $maturasi = array('xid'=>$dt_maturasi['xid'],'value'=> $value); + } + + $sql = "SELECT IFNULL(Other_PapSmearBahanID,0) as xid, + M_PapSmearBahanID as bahan_id, + M_PapSmearBahanName as name, + IF(ISNULL(Other_PapSmearBahanID),'N','Y') as selected + FROM m_papsmearbahan + LEFT JOIN other_papsmearbahan ON Other_PapSmearBahanM_PapSmearBahanID = M_PapSmearBahanID AND + Other_PapSmearBahanOther_PapSmearID = {$header_id} AND + Other_PapSmearBahanIsActive = 'Y' + WHERE + M_PapSmearBahanIsActive = 'Y' + ORDER BY M_PapSmearBahanID ASC + "; + //echo $sql; + $bahans = $this->db_smartone->query($sql)->result_array(); + + $sql = "SELECT IFNULL(Other_PapsmearCategoryID,0) as xid, + M_PapSmearCategoryID as category_id, + M_PapSmearCategoryName as name, + IF(ISNULL(Other_PapsmearCategoryID),'N','Y') as selected + FROM m_papsmearcategory + LEFT JOIN other_papsmearcategory ON Other_PapsmearCategoryM_PapSmearCategoryID = M_PapSmearCategoryID AND + Other_PapsmearCategoryOther_PapSmearID = {$header_id} AND + Other_PapsmearCategoryIsActive = 'Y' + WHERE + M_PapSmearCategoryIsActive = 'Y' + ORDER BY M_PapSmearCategoryID ASC + "; + //echo $sql; + $categories = $this->db_smartone->query($sql)->result_array(); + + $sql = "SELECT IFNULL(Other_PapSmearCheckID,0) as xid, + M_PapSmearCheckID as check_id, + M_PapSmearCheckLabel as name, + IF(ISNULL(Other_PapSmearCheckID),'N','Y') as selected, + Other_PapSmearCheckNote as note + FROM m_papsmearcheck + LEFT JOIN other_papsmearcheck ON Other_PapSmearCheckM_PapSmearCheckID = M_PapSmearCheckID AND + Other_PapSmearCheckOther_PapSmearID = {$header_id} AND + Other_PapSmearCheckIsActive = 'Y' + WHERE + M_PapSmearCheckIsActive = 'Y' + ORDER BY M_PapSmearCheckCode ASC + "; + $checks = $this->db_smartone->query($sql)->result_array(); + + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $rst = array('doctors'=>$doctors,'checks'=>$checks,'bahans'=>$bahans,'categories'=>$categories,'maturasi'=>$maturasi,'results'=>$rows); + $this->sys_ok(["records"=>$rst]); + + } + + function saveresult_lcprep() + { + $prm = $this->sys_input; + $detail_id = $prm['detail_id']; + $doctor_id = $prm['doctor']; + $adekuasi = $prm['adekuasi']; + $kategoriumum = $prm['kategoriumum']; + $interpretasi = $prm['interpretasi']; + $results = $prm['results']; + + $userid = $this->sys_user['M_UserID']; + + $header_id = 0; + $sql = "SELECT * FROM other_lcprep WHERE Other_LcprepT_orderDetailID = {$detail_id} AND Other_LcprepIsActive = 'Y'"; + $dt_header = $this->db_smartone->query($sql)->row_array(); + if($dt_header){ + $header_id = $dt_header['Other_LcprepID']; + } + if($header_id == 0){ + $sql = "INSERT INTO other_lcprep( + Other_LcprepT_orderDetailID, + Other_LcprepM_DoctorID, + Other_LcprepUserID, + Other_LcprepCreated + ) + VALUES( + {$detail_id}, + {$doctor_id}, + {$userid}, + NOW() + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + }else{ + $sql = "UPDATE other_lcprep SET Other_LcprepM_DoctorID = {$doctor_id}, Other_LcprepUserID = {$userid} WHERE Other_LcprepID = {$header_id}"; + $this->db_smartone->query($sql); + } + + if($adekuasi){ + foreach($adekuasi as $k =>$v){ + $selected = $v['chex']?'Y':'N'; + if(intval($v['xid'] == 0)){ + $sql = "UPDATE other_lcprepadekuasi SET Other_LcprepAdekuasiIsActive = 'N' + WHERE + Other_LcprepAdekuasiOther_LcprepID = {$header_id} AND + Other_LcprepAdekuasiIsActive = 'Y' AND + Other_LcprepAdekuasiLcprep_AdekuasiID = {$v['id']}"; + $this->db_smartone->query($sql); + $sql = "INSERT INTO other_lcprepadekuasi ( + Other_LcprepAdekuasiOther_LcprepID, + Other_LcprepAdekuasiLcprep_AdekuasiID, + Other_LcprepAdekuasiChex, + Other_LcprepAdekuasiUserID, + Other_LcprepAdekuasiCreated + ) + VALUES( + {$header_id}, + {$v['id']}, + '{$selected}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + //echo $sql; + } + if(intval($v['xid'] != 0)){ + + $sql = "UPDATE other_lcprepadekuasi SET + Other_LcprepAdekuasiChex = '{$selected}', + Other_LcprepAdekuasiUserID = {$userid} + WHERE + Other_LcprepAdekuasiID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + + //echo $sql; + } + } + + if($kategoriumum){ + foreach($kategoriumum as $k =>$v){ + $selected = $v['chex']?'Y':'N'; + if(intval($v['xid'] == 0)){ + $sql = "UPDATE other_lcprepkategoriumum SET Other_LcprepKategoriUmumIsActive = 'N' + WHERE + Other_LcprepKategoriUmumOther_LcprepID = {$header_id} AND + Other_LcprepKategoriUmumLcprep_KategoriUmumID = {$v['id']} AND + Other_LcprepKategoriUmumIsActive = 'Y' + "; + $this->db_smartone->query($sql); + $sql = "INSERT INTO other_lcprepkategoriumum ( + Other_LcprepKategoriUmumOther_LcprepID, + Other_LcprepKategoriUmumLcprep_KategoriUmumID, + Other_LcprepKategoriUmumChex, + Other_LcprepKategoriUmumUserID, + Other_LcprepKategoriUmumCreated + ) + VALUES( + {$header_id}, + {$v['id']}, + '{$selected}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if(intval($v['xid'] != 0)){ + $sql = "UPDATE other_lcprepkategoriumum SET + Other_LcprepKategoriUmumChex = '{$selected }', + Other_LcprepKategoriUmumUserID = {$userid} + WHERE + Other_LcprepKategoriUmumID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + + //echo $sql; + } + } + + if($results){ + foreach($results as $k =>$v){ + if(intval($v['xid'] == 0)){ + $sql = "UPDATE other_lcprepdetails SET Other_LcprepDetailsIsActive = 'N' + WHERE + Other_LcprepDetailsOther_LcprepID = {$header_id} AND + Other_LcprepDetailsCode = '{$v['code']}' AND + Other_LcprepDetailsIsActive = 'Y'"; + $this->db_smartone->query($sql); + $sql = "INSERT INTO other_lcprepdetails ( + Other_LcprepDetailsOther_LcprepID, + Other_LcprepDetailsCode, + Other_LcprepDetailsLabel, + Other_LcprepDetailsResult, + Other_LcprepDetailsUserID, + Other_LcprepDetailsCreated + ) + VALUES( + {$header_id}, + '{$v['code']}', + '{$v['label']}', + '{$v['result']}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if(intval($v['xid'] != 0)){ + $sql = "UPDATE other_lcprepdetails SET + Other_LcprepDetailsCode = '{$v['code']}', + Other_LcprepDetailsLabel = '{$v['label']}', + Other_LcprepDetailsResult = '{$v['result']}', + Other_LcprepDetailsUserID = {$userid} + WHERE + Other_LcprepDetailsID = {$v['xid']}"; + $this->db_smartone->query($sql); + + } + //echo $sql; + } + } + + if($interpretasi){ + foreach($interpretasi as $k =>$v){ + if(count($v['subgroups']) > 0){ + foreach($v['subgroups'] as $ik => $iv){ + if(count($iv['childs']) > 0){ + foreach($iv['childs'] as $iik => $iiv){ + if(intval($iiv['xid'] == 0)){ + $chex = $iiv['chex'] ? 'Y':'N'; + $sql = "UPDATE other_lcprepinterpretasi SET Other_LcprepInterpretasiIsActive = 'N' + WHERE + Other_LcprepInterpretasiOther_LcprepID = {$header_id} AND + Other_LcprepInterpretasiLcprep_InterpretasiID = '{$iiv['id']}' AND + Other_LcprepInterpretasiIsActive = 'Y'"; + $this->db_smartone->query($sql); + $sql = "INSERT INTO other_lcprepinterpretasi ( + Other_LcprepInterpretasiOther_LcprepID, + Other_LcprepInterpretasiLcprep_InterpretasiID, + Other_LcprepInterpretasiChex, + Other_LcprepInterpretasiValue, + Other_LcprepInterpretasiUserID, + Other_LcprepInterpretasiCreated + ) + VALUES( + {$header_id}, + '{$iiv['id']}', + '{$chex}', + '{$iiv['value']}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + + if(intval($iiv['xid'] != 0)){ + $chex = $iiv['chex'] ? 'Y':'N'; + $sql = "UPDATE other_lcprepinterpretasi SET + Other_LcprepInterpretasiChex = '{$chex}', + Other_LcprepInterpretasiValue = '{$iiv['value']}', + Other_LcprepInterpretasiUserID = {$userid} + WHERE + Other_LcprepInterpretasiID = {$iiv['xid']}"; + $this->db_smartone->query($sql); + //echo $sql; + + } + + } + } + } + } + //echo $sql; + } + } + + + $result = array("total" => 1, "records" => array(), "sql"=> ''); + $this->sys_ok($result); + exit; + } + + function saveresult_papsmear() + { + $prm = $this->sys_input; + $detail_id = $prm['detail_id']; + $doctor_id = $prm['doctor']; + $checks = $prm['checks']; + $maturasi = $prm['maturasi']; + $bahans = $prm['bahans']; + $categories = $prm['categories']; + $results = $prm['results']; + + $userid = $this->sys_user['M_UserID']; + + $header_id = 0; + $sql = "SELECT * FROM other_papsmear WHERE Other_PapSmearT_OrderDetailID = {$detail_id} AND Other_PapSmearIsActive = 'Y'"; + $dt_header = $this->db_smartone->query($sql)->row_array(); + if($dt_header){ + $header_id = $dt_header['Other_PapSmearID']; + } + if($header_id == 0){ + $sql = "INSERT INTO other_papsmear( + Other_PapSmearT_OrderDetailID, + Other_PapSmearM_DoctorID, + Other_PapSmearUserID, + Other_PapSmearCreated + ) + VALUES( + {$detail_id}, + {$doctor_id}, + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } + else{ + $sql = "UPDATE other_papsmear SET Other_PapSmearM_DoctorID = {$doctor_id}, Other_PapSmearUserID = {$userid} WHERE Other_PapSmearID = {$header_id}"; + $this->db_smartone->query($sql); + } + + if($checks){ + foreach($checks as $k =>$v){ + if(intval($v['xid']) == 0 && $v['selected'] === 'Y'){ + $sql = "INSERT INTO other_papsmearcheck ( + Other_PapSmearCheckOther_PapSmearID, + Other_PapSmearCheckM_PapSmearCheckID, + Other_PapSmearCheckNote, + Other_PapSmearCheckUserID, + Other_PapSmearCheckCreated + ) + VALUES( + {$header_id}, + {$v['check_id']}, + '{$v['note']}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if(intval($v['xid']) != 0 && $v['selected'] === 'N'){ + $sql = "UPDATE other_papsmearcheck SET + Other_PapSmearCheckIsActive = 'N', + Other_PapSmearCheckUserID = {$userid} + WHERE + Other_PapSmearCheckID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + if(intval($v['xid']) != 0 && $v['selected'] === 'Y'){ + $sql = "UPDATE other_papsmearcheck SET + Other_PapSmearCheckNote = '{$v['note']}', + Other_PapSmearCheckUserID = {$userid} + WHERE + Other_PapSmearCheckID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + //echo $sql; + } + } + + if($maturasi){ + if(intval($maturasi['xid']) == 0){ + $value = join("/",$maturasi['value']); + $sql = "INSERT INTO other_papsmearmaturasi ( + Other_PapSmearMaturasiOther_PapSmearID, + Other_PapSmearMaturasiValue, + Other_PapSmearMaturasiUserID, + Other_PapSmearMaturasiCreated + ) + VALUE( + {$header_id}, + '{$value}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + //echo $sql; + } + if(intval($maturasi['xid']) != 0){ + $value = join("/",$maturasi['value']); + $sql = "UPDATE other_papsmearmaturasi SET + Other_PapSmearMaturasiValue = '{$value}', + Other_PapSmearMaturasiUserID = {$userid} + WHERE + Other_PapSmearMaturasiID = {$maturasi['xid']}"; + // echo $sql; + $this->db_smartone->query($sql); + } + } + + if($bahans){ + foreach($bahans as $k =>$v){ + if(intval($v['xid']) == 0 && $v['selected'] === 'Y'){ + $sql = "INSERT INTO other_papsmearbahan ( + Other_PapSmearBahanOther_PapSmearID, + Other_PapSmearBahanM_PapSmearBahanID, + Other_PapSmearBahanUserID, + Other_PapSmearBahanCreated + ) + VALUES( + {$header_id}, + {$v['bahan_id']}, + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if(intval($v['xid']) != 0 && $v['selected'] === 'N'){ + $sql = "UPDATE other_papsmearbahan SET + Other_PapSmearBahanIsActive = 'N', + Other_PapsmearCategoryUserID = {$userid} + WHERE + Other_PapSmearBahanID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + if(intval($v['xid']) != 0 && $v['selected'] === 'Y'){ + $sql = "UPDATE other_papsmearbahan SET + Other_PapSmearBahanIsActive = 'Y', + Other_PapsmearCategoryUserID = {$userid} + WHERE + Other_PapSmearBahanID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + //echo $sql; + } + } + + if($categories){ + foreach($categories as $k =>$v){ + if(intval($v['xid']) == 0 && $v['selected'] === 'Y'){ + $sql = "INSERT INTO other_papsmearcategory ( + Other_PapsmearCategoryOther_PapSmearID, + Other_PapsmearCategoryM_PapSmearCategoryID, + Other_PapsmearCategoryUserID, + Other_PapsmearCategoryCreated + ) + VALUES( + {$header_id}, + {$v['category_id']}, + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if(intval($v['xid']) != 0 && $v['selected'] === 'N'){ + $sql = "UPDATE other_papsmearcategory SET + Other_PapsmearCategoryIsActive = 'N', + Other_PapsmearCategoryUserID = {$userid} + WHERE + Other_PapsmearCategoryID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + //echo $sql; + if(intval($v['xid']) != 0 && $v['selected'] === 'Y'){ + $sql = "UPDATE other_papsmearcategory SET + Other_PapsmearCategoryIsActive = 'Y', + Other_PapsmearCategoryUserID = {$userid} + WHERE + Other_PapsmearCategoryID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + } + } + + if($results){ + foreach($results as $k =>$v){ + if(intval($v['xid']) == 0){ + $sql = "INSERT INTO other_papsmeardetails ( + Other_PapSmearDetailsOther_PapSmearID, + Other_PapSmearDetailsCode, + Other_PapSmearDetailsLabel, + Other_PapSmearDetailsResult, + Other_PapSmearDetailsUserID, + Other_PapSmearDetailsCreated + ) + VALUES( + {$header_id}, + '{$v['code']}', + '{$v['label']}', + '{$v['result']}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if(intval($v['xid']) != 0){ + $sql = "UPDATE other_papsmeardetails SET + Other_PapSmearDetailsCode = '{$v['code']}', + Other_PapSmearDetailsLabel = '{$v['label']}', + Other_PapSmearDetailsResult = '{$v['result']}', + Other_PapSmearDetailsUserID = {$userid} + WHERE + Other_PapSmearDetailsID = {$v['xid']}"; + $this->db_smartone->query($sql); + + } + //echo $sql; + } + } + + $result = array("total" => 1, "records" => array(), "sql"=> ''); + $this->sys_ok($result); + exit; + } + + function saveresult_fna() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = $inp['doctor']; + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + if($prm[0]['xid'] == '0'){ + $sql = "INSERT INTO other_fna( + Other_FNAM_DoctorID, + Other_FNAT_OrderDetailID, + Other_FNAUserID, + Other_FNACreated + ) + VALUES( + {$doctor_id}, + {$prm[0]['orderdetail_id']}, + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } + else{ + $sql = "SELECT * FROM other_fna WHERE Other_FNAT_OrderDetailID = {$prm[0]['orderdetail_id']} AND Other_FNAIsActive = 'Y'"; + $data_header = $this->db_smartone->query($sql)->row_array(); + $header_id = $data_header['Other_FNAID']; + $sql = "UPDATE other_fna SET + Other_FNAM_DoctorID = {$doctor_id}, + Other_FNAUserID = {$userid} + WHERE + Other_FNAID = {$header_id}"; + $this->db_smartone->query($sql); + } + foreach($prm as $k => $v){ + if($v['xid'] == '0'){ + $results = str_replace("'", "\\'", $v['result']); + $sql = "INSERT INTO other_fnadetails( + Other_FNADetailsOther_FNAID , + Other_FNADetailsCode, + Other_FNADetailsLabel, + Other_FNADetailsResult, + Other_FNADetailsCreated, + Other_FNADetailsUserID + ) + VALUES( + {$header_id}, + '{$v['code']}', + '{$v['label']}', + '{$results}', + NOW(), + {$userid} + )"; + $query = $this->db_smartone->query($sql); + } + else{ + $results = str_replace("'", "\\'", $v['result']); + $sql = "UPDATE other_fnadetails SET + Other_FNADetailsResult = '{$results}', + Other_FNADetailsUserID = {$userid} + WHERE + Other_FNADetailsID = {$v['xid']}"; + $query = $this->db_smartone->query($sql); + } + } + + $result = array("total" => 1, "records" => array(), "sql"=> ''); + $this->sys_ok($result); + exit; + } + + function saveresult_cytologi() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = $inp['doctor']; + + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + if($prm[0]['xid'] == '0'){ + $sql = "INSERT INTO other_cytologi( + Other_CytologiT_OrderDetailID, + Other_CytologiM_DoctorID, + Other_CytologiUserID, + Other_CytologiCreated + ) + VALUES( + {$prm[0]['orderdetail_id']}, + {$doctor_id}, + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } + else{ + $sql = "SELECT * FROM other_cytologi WHERE Other_CytologiT_OrderDetailID = {$prm[0]['orderdetail_id']} AND Other_CytologiIsActive = 'Y'"; + $data_header = $this->db_smartone->query($sql)->row_array(); + $header_id = $data_header['Other_CytologiID']; + $sql = "UPDATE other_cytologi SET + Other_CytologiM_DoctorID = {$doctor_id}, + Other_CytologiUserID = {$userid} + WHERE + Other_CytologiID = {$header_id}"; + $this->db_smartone->query($sql); + } + foreach($prm as $k => $v){ + if($v['xid'] == '0'){ + $results = str_replace("'", "\\'", $v['result']); + $sql = "INSERT INTO other_cytologidetails( + Other_CytologiDetailsOther_CytologiID , + Other_CytologiDetailsCode, + Other_CytologiDetailsLabel, + Other_CytologiDetailsResult, + Other_CytologiDetailsCreated, + Other_CytologiDetailsUserID + ) + VALUES( + {$header_id}, + '{$v['code']}', + '{$v['label']}', + '{$results}', + NOW(), + {$userid} + )"; + $query = $this->db_smartone->query($sql); + } + else{ + $results = str_replace("'", "\\'", $v['result']); + $sql = "UPDATE other_cytologidetails SET + Other_CytologiDetailsResult = '{$results}', + Other_CytologiDetailsUserID = {$userid} + WHERE + Other_CytologiDetailsID = {$v['xid']}"; + $query = $this->db_smartone->query($sql); + } + } + + $result = array("total" => 1, "records" => array(), "sql"=> ''); + $this->sys_ok($result); + exit; + } + + function saveresult_mikro() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = $inp['doctor']; + $backteria_id = $inp['bacteria']; + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + + if($inp['result_value'] != 'Negatif' && $inp['result_value'] != 'Positif'){ + $prm['result_value'] = $prm['result_other']; + } + else{ + $prm['result_value'] = $inp['result_value']; + } + + if($prm['xid'] == '0'){ + $sql = "INSERT INTO other_mikro( + Other_MikroM_DoctorID, + Other_MikroResult, + Other_MikroT_BacteriaID, + Other_MikroT_OrderDetailID, + Other_MikroHasilBiakan, + Other_MikroSampleTypeName, + Other_MikroUserID, + Other_MikroCreated + ) + VALUES( + {$doctor_id}, + '{$prm['result_value']}', + {$backteria_id}, + {$prm['orderdetail_id']}, + '{$prm['hasil_biakan']}', + '{$prm['sample_name']}', + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } + else{ + $sql = "SELECT * FROM other_mikro WHERE Other_MikroT_OrderDetailID = {$prm['orderdetail_id']} AND Other_MikroIsActive = 'Y'"; + $data_header = $this->db_smartone->query($sql)->row_array(); + $header_id = $data_header['Other_MikroID']; + $sql = "UPDATE other_mikro SET + Other_MikroResult = '{$prm['result_value']}', + Other_MikroM_DoctorID = {$doctor_id}, + Other_MikroT_BacteriaID = {$backteria_id}, + Other_MikroHasilBiakan = '{$prm['hasil_biakan']}', + Other_MikroSampleTypeName = '{$prm['sample_name']}', + Other_MikroUserID = {$userid} + WHERE + Other_MikroID = {$header_id}"; + //echo $sql; + $this->db_smartone->query($sql); + } + + + + $sql = "UPDATE other_mikrodetails SET Other_MikroDetailsIsActive = 'N', Other_MikroDetailsUserID = 0 WHERE Other_MikroDetailsOther_MikroID = {$header_id}"; + $this->db_smartone->query($sql); + + $results = $prm['details']; + if($inp['result_value'] == 'Positif'){ + foreach($results as $k => $v){ + if($v['xid'] == '0'){ + $sql = "INSERT INTO other_mikrodetails( + Other_MikroDetailsOther_MikroID , + Other_MikroDetailsT_AntibioticID, + Other_MikroDetailsValue, + Other_MikroDetailsNote, + Other_MikroDetailsCreated, + Other_MikroDetailsUserID + ) + VALUES( + {$header_id}, + '{$v['T_AntibioticID']}', + '{$v['value']}', + '{$v['note']}', + NOW(), + {$userid} + )"; + $query = $this->db_smartone->query($sql); + } + else{ + $sql = "UPDATE other_mikrodetails SET + Other_MikroDetailsT_AntibioticID = '{$v['T_AntibioticID']}', + Other_MikroDetailsValue = '{$v['value']}', + Other_MikroDetailsNote = '{$v['note']}', + Other_MikroDetailsIsActive = 'Y', + Other_MikroDetailsUserID = {$userid} + WHERE + Other_MikroDetailsID = {$v['xid']}"; + //echo $sql; + $query = $this->db_smartone->query($sql); + } + } + } + + + $result = array("total" => 1, "records" => array(), "sql"=> ''); + $this->sys_ok($result); + exit; + } + + + function get_doctors_preparasi_sperma() + { + $prm = $this->sys_input; + // $id = $prm["id"]; + + $sql = " SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 10 AND + M_DoctorSOIsActive = 'Y' + ORDER BY M_DoctorName ASC"; + //echo $sql; + $query = $this->db_smartone->query($sql); + + if ($query) + { + $rows = $query->result_array(); + $this->sys_ok(["records"=>$rows]); + } + else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + + function getpreparasispermaresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT other_preparasisperma.*, + Other_PreparasiSpermaID as xid, + Other_PreparasiSpermaT_OrderDetailID as orderdetail_id, + IFNULL(Other_PreparasiSpermaM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_PreparasiSpermaM_DoctorID) OR Other_PreparasiSpermaM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_preparasisperma + LEFT JOIN m_doctor ON Other_PreparasiSpermaM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_PreparasiSpermaT_OrderDetailID = {$id} AND Other_PreparasiSpermaIsActive = 'Y' + GROUP BY Other_PreparasiSpermaID"; + $query = $this->db_smartone->query($sql); + + if ($query) + { + $rows = $query->row_array(); + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 10 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $images = array(); + $sql = "SELECT Other_PreparasiSpermaImgID as xid, + Other_PreparasiSpermaImgType as type, + CONCAT('/one-media/one-image-nonlab/',Other_PreparasiSpermaImgNewName) as image_url + FROM t_orderdetail + JOIN other_preparasisperma_img ON Other_PreparasiSpermaImgT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND + Other_PreparasiSpermaImgIsActive = 'Y' + WHERE + T_OrderDetailID = {$id} AND + T_OrderDetailIsActive = 'Y' + GROUP BY Other_PreparasiSpermaImgID"; + //echo $sql; + $images = $this->db_smartone->query($sql)->result_array(); + + $rst = array('doctors'=>$doctors,'results'=>$rows,'images'=>$images); + $this->sys_ok(["records"=>$rst]); + } + else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + + function uploadimage_preparasi_sperma(){ + if (! $this->isLogin) { + $this->sys_error("Invalid Token"); + exit; + } + + $userid = $this->sys_user["M_UserID"]; + $data = []; + //print_r($_SERVER); + + $prm = $this->sys_input; + $orderid = $this->input->post('orderid'); + $type = $this->input->post('type'); + $labnumber = $this->input->post('labnumber'); + $sql = "UPDATE other_preparasisperma_img SET + Other_PreparasiSpermaImgIsActive = 'N', + Other_PreparasiSpermaImgUserID = {$userid} + WHERE + Other_PreparasiSpermaImgT_OrderHeaderID = {$orderid} AND + Other_PreparasiSpermaImgType = '{$type}'"; + //echo $sql; + $this->db_onedev->query($sql); + //$config['upload_path'] = 'assets/'; + + $path = '/home/one/project/one/one-media/one-image-nonlab/'; + //echo $path; + $config['upload_path'] = $path; + $config['allowed_types'] = 'jpg|jpeg|png|gif'; + + $config['max_size'] = '10000'; + $count = count($_FILES['files']['name']); + //echo $count; + $this->load->library('upload',$config); + + $error = []; + for($i=0;$i<$count;$i++){ + + + if(!empty($_FILES['files']['name'][$i])){ + + + + $_FILES['file']['name'] = $_FILES['files']['name'][$i]; + + $_FILES['file']['type'] = $_FILES['files']['type'][$i]; + + $_FILES['file']['tmp_name'] = $_FILES['files']['tmp_name'][$i]; + + $_FILES['file']['error'] = $_FILES['files']['error'][$i]; + + $_FILES['file']['size'] = $_FILES['files']['size'][$i]; + + + + $namex = $orderid.'-'.$labnumber.'-'.$this->generateRandomString(5); + //echo $namex; + + $config['file_name'] = $namex; + $this->upload->initialize($config); + //echo $config['file_name'] ; + + + + + + if($this->upload->do_upload('file')){ + + $uploadData = $this->upload->data(); + + $filename = $uploadData['file_name']; + //echo $filename; + + + $sql = "INSERT INTO other_preparasisperma_img ( + Other_PreparasiSpermaImgT_OrderHeaderID, + Other_PreparasiSpermaImgType, + Other_PreparasiSpermaImgOldName, + Other_PreparasiSpermaImgNewName, + Other_PreparasiSpermaImgCreated, + Other_PreparasiSpermaImgUserID + ) + VALUES( + {$orderid}, + '{$type}', + '{$_FILES['files']['name'][$i]}', + '{$filename}', + NOW(), + {$userid} + + )"; + //echo $sql; + $this->db_onedev->query($sql); + $xlast_id = $this->db_onedev->insert_id(); + $data['totalFiles'][] = array('xid' => $xlast_id ,'type'=>$type,'image_url' => '/one-media/one-image-nonlab/'.$filename); + + } + else{ + $error = array('error' => $this->upload->display_errors()); + } + + } + + + + } + + $result = array("total" =>count( $data['totalFiles']), "records" => $data['totalFiles'],'errors'=>$error); + $this->sys_ok($result); + } + + + function saveresult_preparasi_sperma() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = $inp['doctor']; + $orderdetail_id = $inp['orderdetailid']; + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + if($prm['xid'] == '0'){ + $sql = "INSERT INTO other_preparasisperma( + Other_PreparasiSpermaM_DoctorID, + Other_PreparasiSpermaT_OrderDetailID, + Other_PreparasiSpermaPreMotilitasA, + Other_PreparasiSpermaPreMotilitasB, + Other_PreparasiSpermaPreMotilitasC, + Other_PreparasiSpermaPreKonsentrasi, + Other_PreparasiSpermaPreKontaminan, + Other_PreparasiSpermaPostMotilitasA, + Other_PreparasiSpermaPostMotilitasB, + Other_PreparasiSpermaPostMotilitasC, + Other_PreparasiSpermaPostKonsentrasi, + Other_PreparasiSpermaPostKontaminan, + Other_PreparasiSpermaNote, + Other_PreparasiSpermaUserID, + Other_PreparasiSpermaCreated + ) + VALUES( + {$doctor_id}, + {$orderdetail_id}, + '{$prm['Other_PreparasiSpermaPreMotilitasA']}', + '{$prm['Other_PreparasiSpermaPreMotilitasB']}', + '{$prm['Other_PreparasiSpermaPreMotilitasC']}', + '{$prm['Other_PreparasiSpermaPreKonsentrasi']}', + '{$prm['Other_PreparasiSpermaPreKontaminan']}', + '{$prm['Other_PreparasiSpermaPostMotilitasA']}', + '{$prm['Other_PreparasiSpermaPostMotilitasB']}', + '{$prm['Other_PreparasiSpermaPostMotilitasC']}', + '{$prm['Other_PreparasiSpermaPostKonsentrasi']}', + '{$prm['Other_PreparasiSpermaPostKontaminan']}', + '{$prm['Other_PreparasiSpermaNote']}', + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } + else{ + $sql = "SELECT * FROM other_preparasisperma WHERE Other_PreparasiSpermaT_OrderDetailID = {$orderdetail_id} AND Other_PreparasiSpermaIsActive = 'Y'"; + $data_header = $this->db_smartone->query($sql)->row_array(); + $header_id = $data_header['Other_PreparasiSpermaID']; + $sql = "UPDATE other_preparasisperma SET + Other_PreparasiSpermaM_DoctorID = {$doctor_id}, + Other_PreparasiSpermaPreMotilitasA = '{$prm['Other_PreparasiSpermaPreMotilitasA']}', + Other_PreparasiSpermaPreMotilitasB = '{$prm['Other_PreparasiSpermaPreMotilitasB']}', + Other_PreparasiSpermaPreMotilitasC = '{$prm['Other_PreparasiSpermaPreMotilitasC']}', + Other_PreparasiSpermaPreKonsentrasi = '{$prm['Other_PreparasiSpermaPreKonsentrasi']}', + Other_PreparasiSpermaPreKontaminan = '{$prm['Other_PreparasiSpermaPreKontaminan']}', + Other_PreparasiSpermaPostMotilitasA = '{$prm['Other_PreparasiSpermaPostMotilitasA']}', + Other_PreparasiSpermaPostMotilitasB = '{$prm['Other_PreparasiSpermaPostMotilitasB']}', + Other_PreparasiSpermaPostMotilitasC = '{$prm['Other_PreparasiSpermaPostMotilitasC']}', + Other_PreparasiSpermaPostKonsentrasi = '{$prm['Other_PreparasiSpermaPostKonsentrasi']}', + Other_PreparasiSpermaPostKontaminan = '{$prm['Other_PreparasiSpermaPostKontaminan']}', + Other_PreparasiSpermaNote = '{$prm['Other_PreparasiSpermaNote']}', + Other_PreparasiSpermaUserID = {$userid} + WHERE + Other_PreparasiSpermaID = {$header_id}"; + $this->db_smartone->query($sql); + } + + + $result = array("total" => 1, "records" => array(), "sql"=> ''); + $this->sys_ok($result); + exit; + } + + function getdnafragmentasiresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT other_dnafragmentasi.*, + Other_DnaFragmentasiID as xid, + Other_DnaFragmentasiT_OrderDetailID as orderdetail_id, + IFNULL(Other_DnaFragmentasiM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_DnaFragmentasiM_DoctorID) OR Other_DnaFragmentasiM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name, + IFNULL(Other_DnaFragmentasiOther_DnaFragmentasiMethodeID,0) as methode_id, + IFNULL(Other_DnaFragmentasiMethodeName,'') as methode_name, + Other_DnaFragmentasiHaloLuas as halo_luas, + Other_DnaFragmentasiHaloSedang as halo_sedang, + Other_DnaFragmentasiHaloSempit as halo_sempit, + Other_DnaFragmentasiTanpaHalo as tanpa_halo, + Other_DnaFragmentasiDFI as dfi, + Other_DnaFragmentasiKesimpulan as kesimpulan, + Other_DnaFragmentasiCatatan as catatan + FROM other_dnafragmentasi + LEFT JOIN m_doctor ON Other_DnaFragmentasiM_DoctorID = M_DoctorID + LEFT JOIN other_dnafragmentasimethode ON Other_DnaFragmentasiOther_DnaFragmentasiMethodeID = Other_DnaFragmentasiMethodeID + WHERE + Other_DnaFragmentasiT_OrderDetailID = {$id} AND Other_DnaFragmentasiIsActive = 'Y' + GROUP BY Other_DnaFragmentasiID + LIMIT 1"; + //echo $sql; + $query = $this->db_smartone->query($sql); + + if ($query) + { + $rows = $query->row_array(); + if(!$rows){ + $rows = array( + 'xid' => 0, + 'orderdetail_id' =>$id, + 'doctor_id' => 0, + 'doctor_name' => '', + 'methode_id' => 0, + 'methode_name' => '', + 'halo_luas' => '', + 'halo_sedang' => '', + 'tanpa_halo' => '', + 'dfi' => '', + 'kesimpulan' => '', + 'catatan' => '' + ); + } + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID + WHERE + M_DoctorSONat_SubGroupID = 4 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + + $sql = " + SELECT '0' as id, 'Belum memilih metode' as name + UNION + SELECT Other_DnaFragmentasiMethodeID as id, Other_DnaFragmentasiMethodeName as name + FROM other_dnafragmentasimethode + WHERE + Other_DnaFragmentasiMethodeIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $methodes = $this->db_smartone->query($sql)->result_array(); + + + $rst = array('doctors'=>$doctors,'methodes'=>$methodes,'results'=>$rows); + $this->sys_ok(["records"=>$rst]); + } + else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + function saveresult_dnafragmentasi() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = $inp['doctor']['id']; + $methode_id = $inp['methode']['id']; + $orderdetail_id = $inp['results']['orderdetail_id']; + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + if(intval($prm['xid']) == 0){ + $sql = "INSERT INTO other_dnafragmentasi( + Other_DnaFragmentasiT_OrderDetailID, + Other_DnaFragmentasiM_DoctorID, + Other_DnaFragmentasiOther_DnaFragmentasiMethodeID, + Other_DnaFragmentasiHaloLuas, + Other_DnaFragmentasiHaloSedang, + Other_DnaFragmentasiHaloSempit, + Other_DnaFragmentasiTanpaHalo, + Other_DnaFragmentasiDFI, + Other_DnaFragmentasiKesimpulan, + Other_DnaFragmentasiCatatan, + Other_DnaFragmentasiUserID, + Other_DnaFragmentasiLastUpdated + ) + VALUES( + {$orderdetail_id}, + {$doctor_id}, + {$methode_id}, + '{$prm['halo_luas']}', + '{$prm['halo_sedang']}', + '{$prm['halo_sempit']}', + '{$prm['tanpa_halo']}', + '{$prm['dfi']}', + '{$prm['kesimpulan']}', + '{$prm['catatan']}', + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } + else{ + $sql = "UPDATE other_dnafragmentasi SET + Other_DnaFragmentasiT_OrderDetailID = {$orderdetail_id}, + Other_DnaFragmentasiM_DoctorID = {$doctor_id}, + Other_DnaFragmentasiOther_DnaFragmentasiMethodeID = '{$methode_id}', + Other_DnaFragmentasiHaloLuas = '{$prm['halo_luas']}', + Other_DnaFragmentasiHaloSedang = '{$prm['halo_sedang']}', + Other_DnaFragmentasiHaloSempit = '{$prm['halo_sempit']}', + Other_DnaFragmentasiTanpaHalo = '{$prm['tanpa_halo']}', + Other_DnaFragmentasiDFI = '{$prm['dfi']}', + Other_DnaFragmentasiKesimpulan = '{$prm['kesimpulan']}', + Other_DnaFragmentasiCatatan = '{$prm['catatan']}', + Other_DnaFragmentasiLastUpdated = NOW(), + Other_DnaFragmentasiUserID = {$userid} + WHERE + Other_DnaFragmentasiID = {$prm['xid']}"; + //echo $sql; + $this->db_smartone->query($sql); + } + + + $result = array("total" => 1, "records" => array(), "sql"=> ''); + $this->sys_ok($result); + exit; + } + + +} + diff --git a/application/controllers/mockup/process/resultentry-v21/Re_px.php b/application/controllers/mockup/process/resultentry-v21/Re_px.php index c9ca8c48..ee9d2eaa 100644 --- a/application/controllers/mockup/process/resultentry-v21/Re_px.php +++ b/application/controllers/mockup/process/resultentry-v21/Re_px.php @@ -69,13 +69,8 @@ class Re_px extends MY_Controller return array(0,""); } function get_normal_value($methodeID, $natTestID, $sexID, $ageInDay ) { - $sql = "select fn_sampling_get_normal($methodeID, $natTestID, $sexID, $ageInDay) as normalValueID"; - $qry = $this->db->query($sql); - if ($qry) { - $rows = $qry->result_array(); - if (count($rows) > 0 ) return $rows[0]["normalValueID"]; - } - return 0; + $this->load->library('ibl_sampling_normal'); + return $this->ibl_sampling_normal->get_normal_value_id($methodeID, $natTestID, $sexID, $ageInDay); } function fn_fix_normal($order_id) { diff --git a/application/controllers/mockup/process/resultentry-v22/9/Re_px.php b/application/controllers/mockup/process/resultentry-v22/9/Re_px.php index 08699539..885cc9a6 100644 --- a/application/controllers/mockup/process/resultentry-v22/9/Re_px.php +++ b/application/controllers/mockup/process/resultentry-v22/9/Re_px.php @@ -69,13 +69,8 @@ class Re_px extends MY_Controller return array(0,""); } function get_normal_value($methodeID, $natTestID, $sexID, $ageInDay ) { - $sql = "select fn_sampling_get_normal($methodeID, $natTestID, $sexID, $ageInDay) as normalValueID"; - $qry = $this->db->query($sql); - if ($qry) { - $rows = $qry->result_array(); - if (count($rows) > 0 ) return $rows[0]["normalValueID"]; - } - return 0; + $this->load->library('ibl_sampling_normal'); + return $this->ibl_sampling_normal->get_normal_value_id($methodeID, $natTestID, $sexID, $ageInDay); } function fn_fix_normal($order_id) { $sql = "select diff --git a/application/controllers/mockup/process/resultentry-v22/Re_px.php b/application/controllers/mockup/process/resultentry-v22/Re_px.php index ae3abcaf..cf16ddfb 100644 --- a/application/controllers/mockup/process/resultentry-v22/Re_px.php +++ b/application/controllers/mockup/process/resultentry-v22/Re_px.php @@ -1,2986 +1,2983 @@ -db_smartone = $this->load->database("onedev", true); - $this->db_lab = $this->load->database('one_lab_log', TRUE); - $this->load->helper(array('form', 'url')); - } - function getMethodeID($natTestID) - { - $sql = "select M_MethodePriorityNat_MethodeID MethodeID, Nat_MethodeName - from - m_methode_priority - join nat_methode on Nat_MethodeID = M_MethodePriorityNat_MethodeID - and Nat_MethodeIsActive = 'Y' - join m_instrumentmethode on M_InstrumentMethodeNat_MethodeID = Nat_MethodeID and M_InstrumentMethodeIsActive = 'Y' - join nat_instrument on M_InstrumentMethodeNat_InstrumentID = Nat_InstrumentID - and Nat_InstrumentIsActive ='Y' - where M_MethodePriorityIsActive = 'Y' - and M_MethodePriorityNat_TestID = $natTestID - and M_MethodePriorityM_DayOfWeekID = dayofweek(now()) - order by M_MethodePriorityNumber desc - limit 0,1 "; - $qry = $this->db->query($sql); - if ($qry) { - $rows = $qry->result_array(); - if (count($rows) > 0) return array($rows[0]["MethodeID"], $rows[0]["Nat_MethodeName"]); - } - //2nd - $sql = "select - M_InstrumentMethodeNat_MethodeID MethodeID, Nat_MethodeName - from m_instrumentmethode - join nat_methode on M_InstrumentMethodeNat_MethodeID = Nat_MethodeID - and Nat_MethodeIsActive = 'Y' - join nat_instrument on M_InstrumentMethodeNat_InstrumentID = Nat_InstrumentID - and Nat_InstrumentIsActive ='Y' - where M_InstrumentMethodeNat_TestID = $natTestID - and M_InstrumentMethodeIsActive = 'Y' - order by M_InstrumentMethodePriority desc - limit 0,1"; - $qry = $this->db->query($sql); - if ($qry) { - $rows = $qry->result_array(); - if (count($rows) > 0) return array($rows[0]["MethodeID"], $rows[0]["Nat_MethodeName"]); - } - // - $sql = "select Nat_NormalValueNat_MethodeID MethodeID, Nat_MethodeName - from - nat_normalvalue - join nat_methode on Nat_NormalValueNat_MethodeID = Nat_MethodeID - and Nat_MethodeIsActive = 'Y' - where Nat_NormalValueNat_TestID = $natTestID - and Nat_NormalValueIsActive = 'Y' - order by Nat_NormalValueID - limit 0,1"; - $qry = $this->db->query($sql); - if ($qry) { - $rows = $qry->result_array(); - if (count($rows) > 0) return array($rows[0]["MethodeID"], $rows[0]["Nat_MethodeName"]); - } - return array(0, ""); - } - function get_normal_value($methodeID, $natTestID, $sexID, $ageInDay) - { - $sql = "select fn_sampling_get_normal($methodeID, $natTestID, $sexID, $ageInDay) as normalValueID"; - $qry = $this->db->query($sql); - if ($qry) { - $rows = $qry->result_array(); - if (count($rows) > 0) return $rows[0]["normalValueID"]; - } - return 0; - } - function fn_fix_normal($order_id) - { - $sql = "select - T_OrderDetailID, M_PatientM_SexID, fn_global_age_count_day(M_PatientDOB, date(T_OrderHeaderDate)) Dob , - T_TestNat_TestID - from t_orderheader - join m_patient on T_OrderHeaderID = $order_id and T_OrderHeaderM_PatientID = M_PatientID - join t_orderdetail on T_OrderDetailT_OrderHeaderID = T_OrderHeaderID - and T_OrderDetailIsACtive = 'Y' - and ( T_OrderDetailNat_NormalValueID is null or T_OrderDetailNat_NormalValueID = 0 ) - join t_test on T_OrderDetailT_TestID = T_TestID and T_TestIsResult = 'Y' "; - $qry = $this->db->query($sql); - if (! $qry) { - return; - } - $rows = $qry->result_array(); - if (count($rows) == 0) return; - $sql_u = "update t_orderdetail - join nat_normalvalue on T_OrderDetailID = ? and Nat_NormalValueID = ? - set - T_OrderDetailNat_NormalValueID = Nat_NormalValueID, - T_OrderDetailNormalValueNote = Nat_NormalValueNote, - T_OrderDetailNormalValueDescription = Nat_NormalValueDescription, - T_OrderDetailMinValue = Nat_NormalValueMinValue, - T_OrderDetailMaxValue = Nat_NormalValueMaxValue, - T_OrderDetailMinValueInclusive = Nat_NormalValueMinValueInclusive, - T_OrderDetailMaxValueInclusive = Nat_NormalValueMaxValueInclusive, - T_OrderDetailNat_MethodeID = ?, - T_OrderdetailNat_MethodeName =?"; - - foreach ($rows as $r) { - $T_OrderDetailID = $r["T_OrderDetailID"]; - $sexID = $r["M_PatientM_SexID"]; - $ageInDay = $r["Dob"]; - $natTestID = $r["T_TestNat_TestID"]; - list($methodeID, $methodeName) = $this->getMethodeID($natTestID); - if ($methodeID == 0) continue; - $normalValueID = $this->get_normal_value($methodeID, $natTestID, $sexID, $ageInDay); - if ($normalValueID == 0) return; - $this->db->query($sql_u, array($T_OrderDetailID, $normalValueID, $methodeID, $methodeName)); - } - } - function update_order_sample($targetID, $sourceID) - { - $sql = "update t_ordersample target - join t_ordersample source on - target.T_OrderSampleID = ? - and target.T_OrderSampleWorklistReceive = 'N' - and source.T_OrderSampleID = ? - set - target.T_OrderSampleSampling = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSampling, source.T_OrderSampleSampling), - target.T_OrderSampleSamplingDate = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingDate, source.T_OrderSampleSamplingDate), - target.T_OrderSampleSamplingTime = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingTime, source.T_OrderSampleSamplingTime), - target.T_OrderSampleSamplingUserID = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingUserID, source.T_OrderSampleSamplingUserID), - - target.T_OrderSampleReceive = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceive, source.T_OrderSampleReceive), - target.T_OrderSampleReceiveDate = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveDate, source.T_OrderSampleReceiveDate), - target.T_OrderSampleReceiveTime = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveTime, source.T_OrderSampleReceiveTime), - target.T_OrderSampleReceiveUserID = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveUserID, source.T_OrderSampleReceiveUserID), - - target.T_OrderSampleVerification = if(target.T_OrderSampleVerification='Y',target.T_OrderSampleVerification, source.T_OrderSampleVerification), - target.T_OrderSampleVerificationDate =if(target.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationDate, source.T_OrderSampleVerificationDate), - target.T_OrderSampleVerificationTime =if(source.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationTime, source.T_OrderSampleVerificationTime), - target.T_OrderSampleVerificationUserID =if(source.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationUserID, source.T_OrderSampleVerificationUserID), - - target.T_OrderSampleProcessing = if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessing, source.T_OrderSampleProcessing), - target.T_OrderSampleProcessingDate= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingDate, source.T_OrderSampleProcessingDate), - target.T_OrderSampleProcessingTime= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingTime, source.T_OrderSampleProcessingTime), - target.T_OrderSampleProcessingUserID= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingUserID, source.T_OrderSampleProcessingUserID), - - target.T_OrderSampleReceiveHandling =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandling, source.T_OrderSampleReceiveHandling ), - target.T_OrderSampleReceiveHandlingDate =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingDate, source.T_OrderSampleReceiveHandlingDate), - target.T_OrderSampleReceiveHandlingTime =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingTime, source.T_OrderSampleReceiveHandlingTime), - target.T_OrderSampleReceiveHandlingUserID =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingUserID, source.T_OrderSampleReceiveHandlingUserID), - - target.T_OrderSampleHandling = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandling, source.T_OrderSampleHandling), - target.T_OrderSampleHandlingDate = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingDate, source.T_OrderSampleHandlingDate), - target.T_OrderSampleHandlingTime = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingTime, source.T_OrderSampleHandlingTime), - target.T_OrderSampleHandlingUserID = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingUserID, source.T_OrderSampleHandlingUserID), - - target.T_OrderSampleWorklistReceive = source.T_OrderSampleWorklistReceive, - target.T_OrderSampleWorklistReceiveDatetime = source.T_OrderSampleWorklistReceiveDateTime, - target.T_OrderSampleWorklistReceiveUserID = source.T_OrderSampleWorklistReceiveUserID - "; - $qry = $this->db->query($sql, array($targetID, $sourceID)); - if (! $qry) { - echo json_encode(array("status" => "ERR", "message" => print_r($this->db->error(), true))); - exit; - } - } - function fix_sample_serum($headerID) - { - //cari t_ordersample yg belum worklist receive dengan code 017% - $sql = "select T_OrderSampleID - from t_ordersample - join t_sampletype on - T_OrderSampleT_OrderHeaderID = ? - and T_OrderSampleWorklistReceive = 'N' - and T_OrderSampleIsActive = 'Y' - and T_OrderSampleT_SampleTypeID = T_SampletypeID - and T_SampleTypeCode like '017%' - "; - $qry = $this->db->query($sql, array($headerID)); - if (!$qry) { - echo json_encode(array("status" => "ERR", "message" => print_r($this->db->error(), true))); - exit; - } - $rows = $qry->result_array(); - if (count($rows) == 0) return; - //cari T_OrderSample yang sudah di receive yg terakhir - $sql = "select T_OrderSampleID - from t_ordersample - join t_sampletype on - T_OrderSampleT_OrderHeaderID = ? - and T_OrderSampleWorklistReceive = 'Y' - and T_OrderSampleIsActive = 'Y' - and T_OrderSampleT_SampleTypeID = T_SampletypeID - and T_SampleTypeCode like '017%' - order by T_OrderSampleWorklistReceiveDatetime desc - limit 0,1 - "; - $qry = $this->db->query($sql, array($headerID)); - if (!$qry) { - echo json_encode(array("status" => "ERR", "message" => print_r($this->db->error(), true))); - exit; - } - $rcv_rows = $qry->result_array(); - if (count($rcv_rows) == 0) return; - - //print_r($rows); - //print_r($rcv_rows); - $rcv_T_OrderSampleID = $rcv_rows[0]["T_OrderSampleID"]; - //ada yg belum di receive - foreach ($rows as $r) { - $T_OrderSampleID = $r["T_OrderSampleID"]; - $this->update_order_sample($T_OrderSampleID, $rcv_T_OrderSampleID); - } - } - public function search() - { - $prm = $this->sys_input; - $max_rst = 99; - - $id = $prm["order_id"]; - if ($id > 0) { - $this->fix_sample_serum($id); - $this->fn_fix_normal($id); - } - $lang = $this->lang_default_code; - $lang_id = isset($prm['lang_id']) ? $prm['lang_id'] : '0'; - - if ($lang_id != 0) { - $l = $this->db_smartone->where("Nat_LangID", $lang_id)->get("nat_lang")->row(); - $lang = $l->Nat_LangCode; - } - - //tambahan fajri - $sql = " UPDATE t_orderdetail - JOIN t_test ON T_OrderDetailT_TestID = T_TestID - SET T_OrderDetailT_TestIsResult = T_TestIsResult - WHERE - T_OrderDetailT_OrderHeaderID = {$id} AND - T_OrderDetailT_TestIsResult = '' AND - T_OrderDetailIsActive = 'Y'"; - $this->db_smartone->query($sql); - - $tot_count = 0; - $lq = ""; - $group_id = 0; - if (isset($prm['group_id'])) - $group_id = $prm['group_id']; - - if ($group_id != 0) { - $sql = "select distinct T_WorklistDetailNat_TestID Nat_TestID - from t_worklistdetailv2 - where T_WorklistDetailT_WorklistID = {$group_id}"; - $qry = $this->db_smartone->query($sql); - $rows = $qry->result_array(); - $nat_test_ids = "0"; - foreach ($rows as $r) { - $nat_test_ids .= ", " . $r["Nat_TestID"]; - } - $q_group = " ( $nat_test_ids ) "; - - $sql = " - SELECT a1.*, cOUNT(a2.T_OrderDetailID) level - FROM ( - SELECT IFNULL(y.T_OrderDetailT_TestID, x.T_OrderDetailT_TestID) t_testid, - IFNULL(y.T_OrderDetailT_TestName, y.T_OrderDetailT_TestName) t_testname, - y.T_OrderDetailResult result, y.T_OrderDetailResult result_old, y.T_OrderDetailNote note, y.T_OrderDetailNote note_old, - y.T_OrderDetailID id, - y.T_OrderDetailT_TestIsResult is_result, a.T_TestIsQuantitative is_quantitative, - y.T_OrderDetailResultFlag result_flag, - y.T_OrderDetailNat_NormalValueID normal_id, - y.T_OrderDetailNormalValueNote normal_note, y.T_OrderDetailNat_UnitName unit_name, - y.T_OrderdetailNat_MethodeID methode_id, y.T_OrderdetailNat_MethodeName methode_name, - a.T_TestNat_TestID nattest_id, a.T_TestID tx_id, count(T_ResultInstrumentID) as result_instrument_n, - y.T_OrderDetailVerification, T_OrderSampleReceive sample_receive, - T_OrderSampleProcessing sample_processing, T_OrderSampleWorklistReceive sample_worklist_receive, - IF(T_OrderDetailAddOnPreAnalytic = 'Y', T_OrderDetailAddOnPreAnalytic, PreAnalyticIsOk) pre_analytic, - T_OrderDetailAddOnPreAnalytic, - T_OrderHeaderID order_id, y.T_OrderDetailT_TestSasCode test_sas_code, - tx.T_TestSasCode, - T_OrderDetailAddOnResample `resample`, T_OrderDetailAddOnResampleStatus resample_status, - T_OrderDetailAddOnRef ref, y.T_OrderDetailVerification verification, y.T_OrderDetailValidation validation, - T_OrderPromiseDateTime, Group_ResultName as ResultGroupName - FROM t_orderdetail x - left join t_orderpromise on x.T_OrderDetailT_OrderPromiseID = T_OrderPromiseID - JOIN t_test tx ON x.T_OrderDetailT_TestID = T_TestID - JOIN t_test tcheck on tcheck.T_TestNat_TestID in {$q_group} - and ( tx.T_TestID = tcheck.T_TestID or tx.T_TestSasCode like concat(tcheck.T_TestSasCode,'%')) - JOIN group_resultdetail ON Group_ResultDetailT_TestID = x.T_OrderDetailT_TestID AND Group_ResultDetailIsActive = 'Y' - JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND Group_ResultResumeMcu = 'LAB' - LEFT JOIN t_orderdetail y ON x.T_OrderDetailT_TestSasCode LIKE CONCAT(y.T_OrderDetailT_TestSasCode, '%') - AND x.T_OrderDetailT_OrderHeaderID = y.T_OrderDetailT_OrderHeaderID - AND y.T_OrderDetailIsActive = 'Y' - LEFT JOIN t_orderdetailaddon ON x.T_OrderDetailID = T_OrderDetailAddOnT_OrderDetailID - JOIN t_orderheader ON y.T_OrderDetailT_OrderHeaderID = T_OrderHeaderID - LEFT JOIN t_test a ON y.T_OrderDetailT_TestID = a.T_TestID - AND a.T_TestIsNonLab = '' - LEFT JOIN (SELECT T_OrderSampleT_SampleTypeID, T_OrderSampleReceive, T_OrderSampleProcessing, T_OrderSampleWorklistReceive - FROM t_ordersample WHERE T_OrderSampleT_OrderHeaderID = {$id} - AND T_OrderSampleIsactive = 'Y' - GROUP BY T_OrderSampleT_SampleTypeID) os ON a.T_TestT_SampleTypeID = os.T_OrderSampleT_SampleTypeID - or os.T_OrderSampleT_SampleTypeID = fn_sampletype_from_local(a.T_TestNat_TestID) - - LEFT JOIN t_resultinstrument ON T_ResultInstrumentT_OrderDetailID = x.T_OrderDetailID - LEFT JOIN pre_analytic ON PreAnalyticNat_TestID = a.T_TestNat_TestID AND PreAnalyticDate = date(now()) and PreAnalyticIsActive = 'Y' - WHERE x.T_OrderDetailT_OrderHeaderID = {$id} - AND x.T_OrderDetailIsActive = 'Y' - GROUP BY y.T_OrderDetailT_TestID - ORDER BY y.T_OrderDetailT_TestSasCode ASC - ) a1 - - LEFT JOIN t_orderdetail a2 ON a2.T_OrderDetailT_OrderHeaderID = a1.order_id - AND a2.T_OrderDetailIsActive = 'Y' - AND a1.test_sas_code LIKE CONCAT(a2.T_OrderDetailT_testSasCode, '%') - GROUP BY a1.t_testid - order by a1.test_sas_code -"; - $query = $this->db_smartone->query($sql); - $lq = $this->db_smartone->last_query(); - } else { - $sql = " - SELECT a1.*, cOUNT(a2.T_OrderDetailID) level - FROM ( - SELECT IFNULL(y.T_OrderDetailT_TestID, x.T_OrderDetailT_TestID) t_testid, - IFNULL(y.T_OrderDetailT_TestName, y.T_OrderDetailT_TestName) t_testname, - y.T_OrderDetailResult result, y.T_OrderDetailResult result_old, y.T_OrderDetailNote note, y.T_OrderDetailNote note_old, - y.T_OrderDetailID id, - y.T_OrderDetailT_TestIsResult is_result, a.T_TestIsQuantitative is_quantitative, - y.T_OrderDetailResultFlag result_flag, - y.T_OrderDetailNat_NormalValueID normal_id, - y.T_OrderDetailNormalValueNote normal_note, y.T_OrderDetailNat_UnitName unit_name, - y.T_OrderdetailNat_MethodeID methode_id, y.T_OrderdetailNat_MethodeName methode_name, - a.T_TestNat_TestID nattest_id, a.T_TestID tx_id, count(T_ResultInstrumentID) as result_instrument_n, - y.T_OrderDetailVerification, T_OrderSampleReceive sample_receive, - T_OrderSampleProcessing sample_processing, T_OrderSampleWorklistReceive sample_worklist_receive, - IF(T_OrderDetailAddOnPreAnalytic = 'Y', T_OrderDetailAddOnPreAnalytic, PreAnalyticIsOk) pre_analytic, - T_OrderDetailAddOnPreAnalytic, - T_OrderHeaderID order_id, y.T_OrderDetailT_TestSasCode test_sas_code, - tx.T_TestSasCode, - T_OrderDetailAddOnResample `resample`, T_OrderDetailAddOnResampleStatus resample_status, - T_OrderDetailAddOnRef ref, y.T_OrderDetailVerification verification, y.T_OrderDetailValidation validation, - T_OrderPromiseDateTime , Group_ResultName as ResultGroupName - FROM t_orderdetail x - left join t_orderpromise on x.T_OrderDetailT_OrderPromiseID = T_OrderPromiseID - JOIN t_test tx ON x.T_OrderDetailT_TestID = T_TestID - JOIN group_resultdetail ON Group_ResultDetailT_TestID = x.T_OrderDetailT_TestID AND Group_ResultDetailIsActive = 'Y' - JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND Group_ResultResumeMcu = 'LAB' - LEFT JOIN t_orderdetail y ON x.T_OrderDetailT_TestSasCode LIKE CONCAT(y.T_OrderDetailT_TestSasCode, '%') - AND x.T_OrderDetailT_OrderHeaderID = y.T_OrderDetailT_OrderHeaderID - AND y.T_OrderDetailIsActive = 'Y' - - LEFT JOIN t_orderdetailaddon ON x.T_OrderDetailID = T_OrderDetailAddOnT_OrderDetailID - - JOIN t_orderheader ON y.T_OrderDetailT_OrderHeaderID = T_OrderHeaderID - LEFT JOIN t_test a ON y.T_OrderDetailT_TestID = a.T_TestID - AND a.T_TestIsNonLab = '' - LEFT JOIN (SELECT T_OrderSampleT_SampleTypeID, T_OrderSampleReceive, T_OrderSampleProcessing, T_OrderSampleWorklistReceive - FROM t_ordersample WHERE T_OrderSampleT_OrderHeaderID = {$id} - AND T_OrderSampleIsactive = 'Y' - GROUP BY T_OrderSampleT_SampleTypeID) os ON a.T_TestT_SampleTypeID = os.T_OrderSampleT_SampleTypeID - or os.T_OrderSampleT_SampleTypeID = fn_sampletype_from_local(a.T_TestNat_TestID) - - LEFT JOIN t_resultinstrument ON T_ResultInstrumentT_OrderDetailID = x.T_OrderDetailID - LEFT JOIN pre_analytic ON PreAnalyticNat_TestID = a.T_TestNat_TestID AND PreAnalyticDate = date(now()) and PreAnalyticIsActive = 'Y' - WHERE x.T_OrderDetailT_OrderHeaderID = {$id} - AND x.T_OrderDetailIsActive = 'Y' - GROUP BY y.T_OrderDetailT_TestID - ORDER BY y.T_OrderDetailT_TestSasCode ASC - ) a1 - - LEFT JOIN t_orderdetail a2 ON a2.T_OrderDetailT_OrderHeaderID = a1.order_id - AND a2.T_OrderDetailIsActive = 'Y' - AND a1.test_sas_code LIKE CONCAT(a2.T_OrderDetailT_testSasCode, '%') - GROUP BY a1.t_testid - order by a1.test_sas_code -"; - //echo $sql; - $query = $this->db_smartone->query($sql); - $lq = $this->db_smartone->last_query(); - } - // file_put_contents("/xtmp/re-query.sql",$lq); - - if ($query) { - $rst = []; - $rows = $query->result_array(); - - foreach ($rows as $k => $v) { - - if ($v['is_result'] == "Y" && $v['is_quantitative'] == "N") { - $v['template'] = []; - $x = $this->db_smartone->query("CALL sp_master_resulttemplate_get('{$v['t_testid']}')"); - $this->clean_mysqli_connection($this->db_smartone->conn_id); - if ($x) - $v['template'] = $x->result_array(); - } - - // IF Rujukan, by pas Pre Analytik - if ($v['ref'] == 'Y') - $v['pre_analytic'] = 'Y'; - if ($v["id"] == "885455") { - //sipe workaround - //$v["sample_receive"] = "Y"; - $v["sample_worklist_receive"] = "Y"; - } - $rst[] = $v; - } - - $result = array("total" => $tot_count, "records" => $rst, "total_display" => sizeof($rows), "q" => $lq); - $this->sys_ok($result); - } else { - $this->sys_error_db("RE Px rows", $this->db_smartone); - exit; - } - } - - public function save() - { - $prm = $this->sys_input; - $data = json_decode($prm["data"]); - $lang = $this->lang_default_code; - $lang_id = isset($prm['lang_id']) ? $prm['lang_id'] : '0'; - - if ($lang_id != 0) { - $l = $this->db_smartone->where("Nat_LangID", $lang_id)->get("nat_lang")->row(); - $lang = $l->Nat_LangCode; - } - - $sql_norm = "select T_OrderDetailMinValue, T_OrderDetailMaxValue, - T_OrderDetailMinValueInclusive, T_OrderDetailMaxValueInclusive, - Nat_TestFlagLow, Nat_TestFlagHigh - from t_orderdetail - join t_test on T_OrderDetailT_TestID = T_TestID - join nat_test on T_TestNat_TestID = Nat_TestID and T_TestIsActive = 'Y' - where T_OrderDetailID = ? "; - - $ids = []; - foreach ($data as $k => $v) { - if ($v->resultInstrumentID > 0) { - $sql_i = "select T_ResultInstrumentNat_NormalValueID normalValueID - from t_resultinstrument - where T_ResultInstrumentID = ?"; - $qry_i = $this->db_smartone->query($sql_i, array($v->resultInstrumentID)); - if ($qry_i) { - $rows_i = $qry_i->result_array(); - - if (count($rows_i) > 0) { - $sql_iu = "update t_orderdetail, nat_normalvalue , nat_methode - set T_OrderDetailMinValue = Nat_NormalValueMinValue, - T_OrderDetailMinValueInclusive = Nat_NormalValueMinValueInclusive, - T_OrderDetailMaxValue = Nat_NormalValueMaxValue , - T_OrderDetailMaxValueInclusive = Nat_NormalValueMaxValueInclusive, - T_OrderDetailNormalValueNote = Nat_NormalValueNote, - T_OrderDetailNormalValueDescription = Nat_NormalValueDescription, - T_OrderDetailNat_NormalValueID = Nat_NormalValueID, - T_OrderDetailNat_MethodeID = Nat_NormalValueNat_MethodeID, - T_OrderDetailNat_MethodeName = Nat_MethodeName - where T_OrderDetailID = ? and Nat_NormalValueID = ? - and Nat_NormalValueNat_MethodeID = Nat_MethodeID - "; - $this->db_smartone->query($sql_iu, array($v->id, $rows_i[0]["normalValueID"])); - //file_put_contents("/xtmp/update-nilai-normal", $this->db_smartone->last_query() . "\n", FILE_APPEND); - } - } - } - $y = $this->db_smartone->query("SELECT fn_process_sample_handling_perfect('{$v->order_id}', '{$v->test_id}') c") - ->row(); - $req_status = $y->c; - $qry_norm = $this->db_smartone->query($sql_norm, $v->id); - $result_flag = ""; - if ($qry_norm) { - $rows_norm = $qry_norm->result_array(); - if (count($rows_norm) > 0) { - $r = $rows_norm[0]; - if (is_numeric($v->result)) { - - if ($r["T_OrderDetailMinValueInclusive"] == "Y" && $v->result < $r["T_OrderDetailMinValue"]) { - $result_flag = $r["Nat_TestFlagLow"]; - } - if ($r["T_OrderDetailMinValueInclusive"] == "N" && $v->result <= $r["T_OrderDetailMinValue"]) { - $result_flag = $r["Nat_TestFlagLow"]; - } - if ($r["T_OrderDetailMaxValueInclusive"] == "Y" && $v->result > $r["T_OrderDetailMaxValue"]) { - $result_flag = $r["Nat_TestFlagHigh"]; - } - if ($r["T_OrderDetailMaxValueInclusive"] == "N" && $v->result >= $r["T_OrderDetailMaxValue"]) { - $result_flag = $r["Nat_TestFlagHigh"]; - } - } - } - } - if ($lang == $this->lang_default_code) { - $this->db_smartone->set('T_OrderDetailResult', $v->result) - ->set('T_OrderDetailResultFlag', $result_flag) - ->set('T_OrderDetailNote', $v->note) - ->set('T_OrderDetailReqStatus', $req_status) - ->where('T_OrderDetailID', $v->id) - ->update('t_orderdetail'); - } else { - $this->db_smartone->set('T_OrderDetailLangResult', $v->result) - ->set('T_OrderDetailLangNote', $v->note) - ->where('T_OrderDetailLangID', $v->id) - ->update('t_orderdetaillang'); - } - - - - $ids[] = $v->id; - - //log detail - - $sql = "SELECT COUNT(*) n FROM log_orderdetail WHERE Log_OrderDetailT_OrderDetailID = ? AND Log_OrderDetailResult = ? ORDER BY Log_OrderDetailID DESC LIMIT 1"; - $qry = $this->db_lab->query($sql, [$v->id, $v->result]); - if ($qry) { - $n = $qry->row(); - - if ($n->n == 0) { - $sql = "SELECT * FROM t_orderdetail WHERE T_OrderDetailID = ?"; - $qry_order = $this->db_smartone->query($sql, [$v->id]); - $dt_orderdetail = $qry_order->row(); - $dt_detail_log = json_encode($dt_orderdetail); - - $sql = "INSERT INTO log_orderdetail ( - Log_OrderDetailStatus, - Log_OrderDetailT_OrderDetailID, - Log_OrderDetailResult, - Log_OrderDetailJSON, - Log_OrderDetailCreated, - Log_OrderDetailUserID - ) - VALUES (?,?, ?, ?, NOW(), ?)"; - $this->db_lab->query($sql, ['RESULTENTRY',$v->id, $v->result, $dt_detail_log, $this->sys_user['M_UserID']]); - //echo $this->db_lab->last_query(); - //exit(); - } - } - } - - // LOG Process - $order = $this->db_smartone->select('T_OrderDetailT_OrderHeaderID id, T_OrderHeaderLabNumber lab_number', false) - ->join('t_orderheader', 'T_OrderHeaderID = T_OrderDetailT_OrderHeaderID') - ->where('T_OrderDetailID', $data[0]->id) - ->get('t_orderdetail') - ->row(); - - $dblog = $this->db_lab; - $dblog->set('Log_ProcessCode', 'PROCESS.Result.Entry') - ->set('Log_ProcessOrderID', $order->id) - ->set('Log_ProcessOrderNumber', $order->lab_number) - ->set('Log_ProcessJson', json_encode($data)) - ->set('Log_ProcessUserID', $this->sys_user['M_UserID']) - ->insert('log_process'); - // END OF Log Process - //auto calculation - $this->load->library("Resultcalc"); - $rows = $this->resultcalc->auto($order->id); - - try { - foreach ($ids as $id) { - $this->db_smartone->query("call sp_set_normal_value_flag($id)"); - $this->clean_mysqli_connection($this->db_smartone->conn_id); - } - } catch (Exception $e) { - } - - $this->sys_ok($ids); - } - - public function save_template() - { - $prm = $this->sys_input; - - $n = $this->db_smartone->select("COUNT(T_ResultTemplateID) n") - ->where("T_ResultTemplateT_TestID", $prm['test_id']) - ->where("T_ResultTemplateIsActive", "Y") - ->where("T_ResultTemplateValue", $prm['value']) - ->get('t_resulttemplate') - ->row(); - if ($n->n > 0) { - $this->sys_error_db("Insert Result Template", $this->db_smartone); - return; - } - - $r = $this->db_smartone->set("T_ResultTemplateT_TestID", $prm['test_id']) - ->set("T_ResultTemplateValue", $prm['value']) - ->insert('t_resulttemplate'); - if ($r) { - $template = []; - $x = $this->db_smartone->query("CALL sp_master_resulttemplate_get('{$prm['test_id']}')"); - $this->clean_mysqli_connection($this->db_smartone->conn_id); - if ($x) - $template = $x->result_array(); - - $this->sys_ok($template); - } - } - - public function export() - { - $prm = $this->sys_input; - - $sql = "CALL sp_process_result_lang(?, ?, ?, ?)"; - $query = $this->db_smartone->query($sql, [$prm['order_id'], $prm['lang_id'], $prm['is_si'], $this->sys_user['M_UserID']]); - if ($query) { - $r = $query->row(); - if ($r->status == "OK") { - $this->sys_ok($r->data); - return; - } - - $this->sys_error_db("Message : " . $r->message, $this->db_smartone); - } else { - $this->sys_error_db("Lang Result", $this->db_smartone); - return; - } - } - - public function search_group() - { - $prm = $this->sys_input; - $max_rst = 100; - - // QUERY TOTAL - $sql = "select count(*) total - from t_worklist - where T_WorklistIsActive = 'Y' - order by T_WorklistName ASC"; - $query = $this->db_smartone->query($sql); - - if ($query) { - $tot_count = $query->result_array()[0]["total"]; - } else { - $this->sys_error_db("worklist count", $this->db_smartone); - exit; - } - - $sql = "select T_WorklistID group_id, T_WorklistName group_name - from t_worklist - where T_WorklistIsActive = 'Y' - order by T_WorklistName ASC - limit 0, {$max_rst}"; - $query = $this->db_smartone->query($sql); - - if ($query) { - $rows = $query->result_array(); - foreach ($rows as $k => $v) - $rows[$k]['data'] = json_decode($v['data']); - $result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows), "q" => $this->db_smartone->last_query()); - $this->sys_ok($result); - } else { - $this->sys_error_db("worklist rows", $this->db_smartone); - exit; - } - } - - public function search_rerun() - { - $prm = $this->sys_input; - $id = $prm["detail_id"]; - - $sql = "CALL sp_process_result_rerun(?)"; - $query = $this->db_smartone->query($sql, [$id]); - - if ($query) { - $rows = $query->result_array(); - $this->sys_ok(["records" => $rows]); - } else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - - - function getdoctorsfna() - { - $prm = $this->sys_input; - // $id = $prm["id"]; - - $sql = " SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY M_DoctorName ASC"; - //echo $sql; - $query = $this->db_smartone->query($sql); - - if ($query) { - $rows = $query->result_array(); - $this->sys_ok(["records" => $rows]); - } else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - function getfnaresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT Other_FNADetailsID as xid, - Other_FNAT_OrderDetailID as orderdetail_id, - Other_FNADetailsCode as code, - Other_FNADetailsLabel as label, - Other_FNADetailsResult as result, - IFNULL(Other_FNAM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_FNAM_DoctorID) OR Other_FNAM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_fna - JOIN other_fnadetails ON Other_FNADetailsOther_FNAID = Other_FNAID AND Other_FNADetailsIsActive = 'Y' - LEFT JOIN m_doctor ON Other_FNAM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_FNAT_OrderDetailID = {$id} AND Other_FNAIsActive = 'Y' - GROUP BY Other_FNADetailsID - ORDER BY Other_FNADetailsCode ASC"; - $query = $this->db_smartone->query($sql); - - if ($query) { - $rows = $query->result_array(); - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $images = array(); - $sql = "SELECT So_ImageUploadID as xid, - CONCAT('/one-media/one-image-nonlab/',So_ImageUploadNewName) as image_url - FROM t_orderdetail - JOIN so_imageupload ON So_ImageUploadT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND - So_ImageUploadIsActive = 'Y' - WHERE - T_OrderDetailID = {$id} AND - T_OrderDetailIsActive = 'Y' - GROUP BY So_ImageUploadID"; - $images = $this->db_smartone->query($sql)->result_array(); - - $rst = array('doctors' => $doctors, 'results' => $rows, 'images' => $images); - $this->sys_ok(["records" => $rst]); - } else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - function getpatologianatomyresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT Other_PatologiAnatomyID as xid, - Other_PatologiAnatomyT_OrderDetailID as orderdetail_id, - Other_PatologiAnatomyNoSediaan as no_sediaan, - Other_PatologiAnatomyDiagnosaKlinis as diagnosa, - Other_PatologiAnatomyKeteranganKlinis as klinis, - Other_PatologiAnatomyLokasiOrgan as lokasi, - Other_PatologiAnatomyMakroskopik as makroskopik, - Other_PatologiAnatomyMikroskopik as mikroskopik, - Other_PatologiAnatomyKesimpulan as kesimpulan, - IFNULL(Other_PatologiAnatomyM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_PatologiAnatomyM_DoctorID) OR Other_PatologiAnatomyM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_patologi_anatomy - LEFT JOIN m_doctor ON Other_PatologiAnatomyM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_PatologiAnatomyT_OrderDetailID = {$id} AND Other_PatologiAnatomyIsActive = 'Y' - GROUP BY Other_PatologiAnatomyID - ORDER BY Other_PatologiAnatomyID ASC - LIMIT 1"; - $query = $this->db_smartone->query($sql); - - if ($query) { - $rows = $query->row_array(); - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - - $sql = "SELECT So_ImageUploadPatologyAnatomyID as xid, - CONCAT('/one-media/one-image-nonlab/',So_ImageUploadPatologyAnatomyNewName) as image_url, - So_ImageUploadPatologyAnatomyType as type - FROM t_orderdetail - JOIN so_imageupload_patology_anatomy ON So_ImageUploadPatologyAnatomyT_OrderHeaderID= T_OrderDetailT_OrderHeaderID AND - So_ImageUploadPatologyAnatomyIsActive= 'Y' - WHERE - T_OrderDetailID = {$id} AND - T_OrderDetailIsActive = 'Y' - GROUP BY So_ImageUploadPatologyAnatomyID"; - $images = $this->db_smartone->query($sql)->result_array(); - $mikro = []; - $makro = []; - - foreach ($images as $key => $value) { - - if ($value['type'] == 'mikro') { - $mikro[] = $value; - } - if ($value['type'] == 'makro') { - $makro[] = $value; - } - } - - $rst = array('doctors' => $doctors, 'result' => $rows, "mikro" => $mikro, "makro" => $makro); - $this->sys_ok(["records" => $rst]); - } else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - - - - function uploadimage() - { - if (! $this->isLogin) { - $this->sys_error("Invalid Token"); - exit; - } - - $userid = $this->sys_user["M_UserID"]; - $data = []; - //print_r($_SERVER); - - $prm = $this->sys_input; - $orderid = $this->input->post('orderid'); - $labnumber = $this->input->post('labnumber'); - $sql = "UPDATE so_imageupload SET - So_ImageUploadIsActive = 'N', - So_ImageUploadUserID = {$userid} - WHERE - So_ImageUploadT_OrderHeaderID = {$orderid}"; - //echo $sql; - $this->db_onedev->query($sql); - //$config['upload_path'] = 'assets/'; - - $path = '/home/one/project/one/one-media/one-image-nonlab/'; - //echo $path; - $config['upload_path'] = $path; - $config['allowed_types'] = 'jpg|jpeg|png|gif'; - - $config['max_size'] = '10000'; - $count = count($_FILES['files']['name']); - //echo $count; - $this->load->library('upload', $config); - - $error = []; - for ($i = 0; $i < $count; $i++) { - - - if (!empty($_FILES['files']['name'][$i])) { - - - - $_FILES['file']['name'] = $_FILES['files']['name'][$i]; - - $_FILES['file']['type'] = $_FILES['files']['type'][$i]; - - $_FILES['file']['tmp_name'] = $_FILES['files']['tmp_name'][$i]; - - $_FILES['file']['error'] = $_FILES['files']['error'][$i]; - - $_FILES['file']['size'] = $_FILES['files']['size'][$i]; - - - - $namex = $orderid . '-' . $labnumber . '-' . $this->generateRandomString(5); - //echo $namex; - - $config['file_name'] = $namex; - $this->upload->initialize($config); - //echo $config['file_name'] ; - - - - - - if ($this->upload->do_upload('file')) { - - $uploadData = $this->upload->data(); - - $filename = $uploadData['file_name']; - //echo $filename; - - - $sql = "INSERT INTO so_imageupload ( - So_ImageUploadT_OrderHeaderID, - So_ImageUploadT_OrderHeaderLabNumber, - So_ImageUploadT_SampleTypeID, - So_ImageUploadOldName, - So_ImageUploadNewName, - So_ImageUploadCreated, - So_ImageUploadUserID - ) - VALUES( - {$orderid}, - '{$labnumber}', - '150', - '{$_FILES['files']['name'][$i]}', - '{$filename}', - NOW(), - {$userid} - - )"; - //echo $sql; - $this->db_onedev->query($sql); - $xlast_id = $this->db_onedev->insert_id(); - $data['totalFiles'][] = array('xid' => $xlast_id, 'image_url' => '/one-media/one-image-nonlab/' . $filename); - } else { - $error = array('error' => $this->upload->display_errors()); - } - } - } - - $result = array("total" => count($data['totalFiles']), "records" => $data['totalFiles'], 'errors' => $error); - $this->sys_ok($result); - } - function uploadimagePatologiAnatomi() - { - if (! $this->isLogin) { - $this->sys_error("Invalid Token"); - exit; - } - - $userid = $this->sys_user["M_UserID"]; - $data = []; - //print_r($_SERVER); - - $prm = $this->sys_input; - $orderid = $this->input->post('orderid'); - $type = $this->input->post('type'); - $labnumber = $this->input->post('labnumber'); - $sql = "UPDATE so_imageupload_patology_anatomy SET - So_ImageUploadPatologyAnatomyIsActive = 'N', - So_ImageUploadPatologyAnatomyUserID = {$userid} - WHERE - So_ImageUploadPatologyAnatomyT_OrderHeaderID = {$orderid} - AND So_ImageUploadPatologyAnatomyType = '{$type}'"; - //echo $sql; - $qry = $this->db_onedev->query($sql); - $last_qry = $this->db_onedev->last_query(); - if (!$qry) { - $message = $this->db_onedev->error(); - $message['last_qry'] = $last_qry; - $this->sys_error_db($message); - exit; - } - //$config['upload_path'] = 'assets/'; - - $path = '/home/one/project/one/one-media/one-image-nonlab/'; - //echo $path; - $config['upload_path'] = $path; - $config['allowed_types'] = 'jpg|jpeg|png|gif'; - - $config['max_size'] = '10000'; - $count = count($_FILES['files']['name']); - //echo $count; - $this->load->library('upload', $config); - - $error = []; - for ($i = 0; $i < $count; $i++) { - - - if (!empty($_FILES['files']['name'][$i])) { - - - - $_FILES['file']['name'] = $_FILES['files']['name'][$i]; - - $_FILES['file']['type'] = $_FILES['files']['type'][$i]; - - $_FILES['file']['tmp_name'] = $_FILES['files']['tmp_name'][$i]; - - $_FILES['file']['error'] = $_FILES['files']['error'][$i]; - - $_FILES['file']['size'] = $_FILES['files']['size'][$i]; - - - - $namex = $orderid . '-' . $labnumber . '-' . $this->generateRandomString(5); - //echo $namex; - - $config['file_name'] = $namex; - $this->upload->initialize($config); - //echo $config['file_name'] ; - - - - - - if ($this->upload->do_upload('file')) { - - $uploadData = $this->upload->data(); - - $filename = $uploadData['file_name']; - //echo $filename; - - - $sql = "INSERT INTO so_imageupload_patology_anatomy ( - So_ImageUploadPatologyAnatomyT_OrderHeaderID, - So_ImageUploadPatologyAnatomyT_OrderHeaderLabNumber, - So_ImageUploadPatologyAnatomyT_SampleTypeID, - So_ImageUploadPatologyAnatomyOldName, - So_ImageUploadPatologyAnatomyNewName, - So_ImageUploadPatologyAnatomyCreated, - So_ImageUploadPatologyAnatomyUserID, - So_ImageUploadPatologyAnatomyType - ) - VALUES( - {$orderid}, - '{$labnumber}', - '145', - '{$_FILES['files']['name'][$i]}', - '{$filename}', - NOW(), - {$userid}, - '{$type}' - - )"; - //echo $sql; - $qry = $this->db_onedev->query($sql); - $last_qry = $this->db_onedev->last_query(); - if (!$qry) { - $message = $this->db_onedev->error(); - $message['last_qry'] = $last_qry; - $this->sys_error_db($message); - exit; - } - $xlast_id = $this->db_onedev->insert_id(); - $data['totalFiles'][] = array('xid' => $xlast_id, 'image_url' => '/one-media/one-image-nonlab/' . $filename); - } else { - $error = array('error' => $this->upload->display_errors()); - } - } - } - - $result = array("total" => count($data['totalFiles']), "records" => $data['totalFiles'], 'errors' => $error); - $this->sys_ok($result); - } - - - function generateRandomString($length = 10) - { - $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; - $charactersLength = strlen($characters); - $randomString = ''; - for ($i = 0; $i < $length; $i++) { - $randomString .= $characters[rand(0, $charactersLength - 1)]; - } - return $randomString; - } - - function getcytologiresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT Other_CytologiDetailsID as xid, - Other_CytologiT_OrderDetailID as orderdetail_id, - Other_CytologiDetailsCode as code, - Other_CytologiDetailsLabel as label, - Other_CytologiDetailsResult as result, - IFNULL(Other_CytologiM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_CytologiM_DoctorID) OR Other_CytologiM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_cytologi - JOIN other_cytologidetails ON Other_CytologiDetailsOther_CytologiID = Other_CytologiID AND Other_CytologiDetailsIsActive = 'Y' - LEFT JOIN m_doctor ON Other_CytologiM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_CytologiT_OrderDetailID = {$id} AND Other_CytologiIsActive = 'Y' - GROUP BY Other_CytologiDetailsID - ORDER BY Other_CytologiDetailsCode ASC"; - //echo $sql; - $query = $this->db_smartone->query($sql); - - if ($query) { - $rows = $query->result_array(); - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $rst = array('doctors' => $doctors, 'results' => $rows); - $this->sys_ok(["records" => $rst]); - } else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - function getmikroresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT - Other_MikroID as xid, - Other_MikroHasilBiakan as hasil_biakan, - Other_MikroSampleTypeName as sample_name, - Other_MikroT_OrderDetailID as orderdetail_id, - Other_MikroResult as result_value, - '' as result_other, - IFNULL(T_BacteriaID,0) as T_BacteriaID, - IFNULL(T_BacteriaName,'') as T_BacteriaName, - '' as details, - IFNULL(Other_MikroM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_MikroM_DoctorID) OR Other_MikroM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_mikro - LEFT JOIN t_bacteria ON Other_MikroT_BacteriaID = T_BacteriaID - LEFT JOIN m_doctor ON Other_MikroM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_MikroT_OrderDetailID = {$id} AND Other_MikroIsActive = 'Y' - GROUP BY Other_MikroID"; - //echo $sql; - $query = $this->db_smartone->query($sql); - - if ($query) { - $row = $query->row_array(); - if ($row) { - if ($row['result_value'] != 'Positif' && $row['result_value'] != 'Negatif') { - $row['result_other'] = $row['result_value']; - $row['result_value'] = 'other'; - } - $sql = "SELECT '' as xno, - Other_MikroDetailsID as xid, - Other_MikroDetailsValue as value, - IF(Other_MikroDetailsNote = 'R','Y','N') as chx_r, - IF(Other_MikroDetailsNote = 'I','Y','N') as chx_i, - IF(Other_MikroDetailsNote = 'S','Y','N') as chx_s, - Other_MikroDetailsNote as note, - t_antibiotic.* - FROM other_mikrodetails - LEFT JOIN t_antibiotic ON Other_MikroDetailsT_AntibioticID = T_AntibioticID - WHERE - Other_MikroDetailsOther_MikroID = {$row['xid']} AND Other_MikroDetailsIsActive = 'Y' - GROUP BY Other_MikroDetailsID - ORDER BY T_AntibioticName ASC"; - //echo $sql; - $details = $this->db_smartone->query($sql)->result_array(); - if ($details) { - foreach ($details as $k => $v) { - $details[$k]['xno'] = $k + 1; - } - } - $row['details'] = $details; - } else { - $row = array('xid' => '0', 'hasil_biakan' => '', 'result_value' => 'Negatif', 'sample_name' => '', 'orderdetail_id' => $id, 'T_BacteriaID' => '0', 'T_BacteriaName' => '0', 'details' => array(), 'doctor_id' => '0', 'doctor_name' => '0'); - } - } else { - $row = array('xid' => '0', 'hasil_biakan' => '', 'result_value' => 'Negatif', 'sample_name' => '', 'orderdetail_id' => $id, 'T_BacteriaID' => '0', 'T_BacteriaName' => '0', 'details' => array(), 'doctor_id' => '0', 'doctor_name' => '0'); - } - //print_r($row); - - - - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 7 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $sql = " - SELECT '0' as id, 'Belum memilih bakteria' as name - UNION - SELECT T_BacteriaID as id, T_BacteriaName as name - FROM t_bacteria - WHERE - T_BacteriaIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $bacteries = $this->db_smartone->query($sql)->result_array(); - $rst = array('doctors' => $doctors, 'bacteries' => $bacteries, 'results' => $row); - $this->sys_ok(["records" => $rst]); - } - function getantibiotics() - { - $prm = $this->sys_input; - $id = $prm["id"]; - $sql = " SELECT '' as xno, - 0 as xid, - '' as hasil_biakan, - '' as sample_name, - 0 as value, - 'Y' as chx_r, - 'N' as chx_i, - 'N' as chx_s, - 'R' as note, - t_antibiotic.* - FROM t_antibiotic - WHERE - T_AntibioticT_BacteriaID = {$prm['id']} AND T_AntibioticIsActive= 'Y' - ORDER BY T_AntibioticName ASC"; - //echo $sql; - $rows = $this->db_smartone->query($sql)->result_array(); - if (rows) { - foreach ($rows as $k => $v) { - $rows[$k]['xno'] = $k + 1; - } - } - - $this->sys_ok(["records" => $rows]); - } - function getlcprepresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = "SELECT T_OrderDetailVerification as verification, T_OrderDetailValidation as validation FROM t_orderdetail WHERE T_OrderDetailID = ?"; - $order = $this->db_smartone->query($sql, array($id))->row_array(); - - - $sql = " SELECT Other_LcprepDetailsID as xid, - Other_LcprepID as header_id, - Other_LcprepT_orderDetailID as orderdetail_id, - Other_LcprepDetailsCode as code, - Other_LcprepDetailsLabel as label, - Other_LcprepDetailsResult as result, - IFNULL(Other_LcprepM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_LcprepM_DoctorID) OR Other_LcprepM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_lcprep - JOIN other_lcprepdetails ON Other_LcprepDetailsOther_LcprepID = Other_LcprepID AND Other_LcprepDetailsIsActive = 'Y' - LEFT JOIN m_doctor ON Other_LcprepM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_LcprepT_orderDetailID = ? AND Other_LcprepIsActive = 'Y' - GROUP BY Other_LcprepDetailsOther_LcprepID, Other_LcprepDetailsCode - ORDER BY Other_LcprepDetailsCode ASC"; - //echo $sql; - $rows = $this->db_smartone->query($sql, array($id))->result_array(); - if (count($rows) == 0) { - $rows = array( - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'A', - 'label' => 'DESKRIPSI', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ), - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'B', - 'label' => 'KESIMPULAN', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ) - ); - } - - $other_rows = array(); - $langs = array(array('id' => 1, 'name' => 'Bahasa Indonesia')); - $selected_lang = array(array('id' => 1, 'name' => 'Bahasa Indonesia')); - $sql = "SELECT T_OrderHeaderAddOnSecondM_LangID as lang_id, - M_LangName as lang_name - FROM t_orderdetail - JOIN t_orderheader ON T_OrderDetailT_OrderHeaderID = T_OrderHeaderID AND T_OrderHeaderIsActive = 'Y' - JOIN t_orderheaderaddon ON T_OrderHeaderAddonT_OrderHeaderID = T_OrderHeaderID AND T_OrderHeaderAddonIsActive = 'Y' - JOIN m_lang ON T_OrderHeaderAddOnSecondM_LangID = M_LangID AND M_LangIsActive = 'Y' - WHERE T_OrderDetailID = {$id} AND T_OrderDetailIsActive = 'Y'"; - - $other_lang = $this->db_smartone->query($sql)->result_array(); - if (count($other_lang) > 0) { - $langs[] = array('id' => $other_lang[0]['lang_id'], 'name' => $other_lang[0]['lang_name']); - $selected_lang = array('id' => $other_lang[0]['lang_id'], 'name' => $other_lang[0]['lang_name']); - - - $sql = " SELECT Other_LcprepDetailsLangsID as xid, - Other_LcprepID as header_id, - Other_LcprepT_orderDetailID as orderdetail_id, - Other_LcprepDetailsLangsCode as code, - Other_LcprepDetailsLangsLabel as label, - Other_LcprepDetailsLangsResult as result, - IFNULL(Other_LcprepM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_LcprepM_DoctorID) OR Other_LcprepM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_lcprep - JOIN other_lcprepdetails_lang ON Other_LcprepDetailsLangsOther_LcprepID = Other_LcprepID AND Other_LcprepDetailsLangsIsActive = 'Y' - LEFT JOIN m_doctor ON Other_LcprepM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_LcprepT_orderDetailID = {$id} AND Other_LcprepDetailsLangsIsActive = 'Y' - GROUP BY Other_LcprepDetailsLangsOther_LcprepID, Other_LcprepDetailsLangsCode - ORDER BY Other_LcprepDetailsLangsCode ASC"; - // echo $sql; - $other_rows = $this->db_smartone->query($sql)->result_array(); - if (count($other_rows) == 0) { - $other_rows = array( - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'AA', - 'label' => 'DESCRIPTION', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ), - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'BB', - 'label' => 'CONCLUSION', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ) - ); - } - } - - $header_id = $rows[0]['header_id']; - $sql = "SELECT IFNULL(Other_LcprepAdekuasiID,0) as xid, - Lcprep_AdekuasiID as id, - Lcprep_AdekuasiLabel as name, - Lcprep_AdekuasiLabel as name_en, - IF(ISNULL(Other_LcprepAdekuasiID),'N',Other_LcprepAdekuasiChex) as chex - FROM lcprep_adekuasi - LEFT JOIN other_lcprepadekuasi ON Other_LcprepAdekuasiLcprep_AdekuasiID = Lcprep_AdekuasiID AND - Other_LcprepAdekuasiOther_LcprepID = {$header_id} AND - Other_LcprepAdekuasiIsActive = 'Y' - WHERE - Lcprep_AdekuasiIsActive = 'Y' - GROUP BY Lcprep_AdekuasiID - ORDER BY Lcprep_AdekuasiOrder ASC - "; - //echo $sql; - $adeakuasi = $this->db_smartone->query($sql)->result_array(); - foreach ($adeakuasi as $kc => $vc) { - $adeakuasi[$kc]['chex'] = $vc['chex'] == 'N' ? false : true; - $adeakuasi[$kc]['name_en'] = $this->translate_word($vc['name']); - } - - $sql = "SELECT IFNULL(Other_LcprepKategoriUmumID,0) as xid, - Lcprep_KategoriUmumID as id, - Lcprep_KategoriUmumLabel as name, - Lcprep_KategoriUmumLabel as name_en, - IF(ISNULL(Other_LcprepKategoriUmumID),'N',Other_LcprepKategoriUmumChex) as chex - FROM lcprep_kategoriumum - LEFT JOIN other_lcprepkategoriumum ON Other_LcprepKategoriUmumLcprep_KategoriUmumID = Lcprep_KategoriUmumID AND - Other_LcprepKategoriUmumOther_LcprepID = {$header_id} AND - Other_LcprepKategoriUmumIsActive = 'Y' - WHERE - Lcprep_KategoriUmumIsActive = 'Y' - GROUP BY Lcprep_KategoriUmumID - "; - //echo $sql; - $kategoriumum = $this->db_smartone->query($sql)->result_array(); - foreach ($kategoriumum as $kc => $vc) { - $kategoriumum[$kc]['chex'] = $vc['chex'] == 'N' ? false : true; - $kategoriumum[$kc]['name_en'] = $this->translate_word($vc['name']); - } - - $sql = " - SELECT Lcprep_InterpretasiGroupID as group_id, - Lcprep_InterpretasiGroupName as group_name, - Lcprep_InterpretasiGroupName as group_name_en, - '' as subgroups - FROM lcprep_interpretasigroup - WHERE - Lcprep_InterpretasiGroupIsActive = 'Y' - "; - //echo $sql; - $interpretasi = $this->db_smartone->query($sql)->result_array(); - foreach ($interpretasi as $k => $v) { - $interpretasi[$k]['group_name_en'] = $this->translate_word($v['group_name']); - $subgroups = array(); - $sql = "SELECT Lcprep_InterpretasiSubgroupID as subgroup_id, - Lcprep_InterpretasiSubgroupName as subgroup_name, - Lcprep_InterpretasiSubgroupName as subgroup_name_en, - '' as childs - FROM lcprep_interpretasisubgroup - WHERE - Lcprep_InterpretasiSubgroupLcprep_InterpretasiGroupID = {$v['group_id']} AND Lcprep_InterpretasiSubgroupIsActive = 'Y'"; - //echo $sql; - $subgroups = $this->db_smartone->query($sql)->result_array(); - if (count($subgroups) > 0) { - foreach ($subgroups as $ki => $vi) { - $subgroups[$ki]['subgroup_name_en'] = $this->translate_word($vi['subgroup_name']); - $childs = array(); - - $sql = "SELECT IFNULL(Other_LcprepInterpretasiID,0) as xid, - IFNULL(Other_LcprepInterpretasiChex,'N') as chex, - IFNULL(Other_LcprepInterpretasiValue,'') as value, - IFNULL(Other_LcprepInterpretasiValueEng,'') as value_en, - Lcprep_InterpretasiID as id, - Lcprep_InterpretasiLcprep_InterpretasiSubgroupID as subgroup_id, - Lcprep_InterpretasiCode as code, - Lcprep_InterpretasiName as name, - Lcprep_InterpretasiName as name_en, - Lcprep_InterpretasiParentID as parent_id, - Lcprep_InterpretasiIsParent as is_parent, - Lcprep_InterpretasiHasResult as has_result, - Lcprep_InterpretasiTypeResult as type_result - FROM lcprep_interpretasi - LEFT JOIN other_lcprepinterpretasi ON Other_LcprepInterpretasiOther_LcprepID = {$header_id} AND - Other_LcprepInterpretasiLcprep_InterpretasiID = Lcprep_InterpretasiID AND - Other_LcprepInterpretasiIsActive = 'Y' - WHERE - Lcprep_InterpretasiLcprep_InterpretasiSubgroupID = {$vi['subgroup_id']} AND Lcprep_InterpretasiIsActive = 'Y' - GROUP BY Lcprep_InterpretasiID Order BY Lcprep_InterpretasiCode ASC"; - $childs = $this->db_smartone->query($sql)->result_array(); - if ($childs) { - foreach ($childs as $kc => $vc) { - $childs[$kc]['chex'] = $vc['chex'] == 'N' ? false : true; - $childs[$kc]['name_en'] = $this->translate_word($vc['name']); - } - } - $subgroups[$ki]['childs'] = $childs; - } - } - - $interpretasi[$k]['subgroups'] = $subgroups; - } - - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - - - - $rst = array('order' => $order, 'langs' => $langs, 'selected_lang' => $selected_lang, 'doctors' => $doctors, 'results' => $rows, 'other_results' => $other_rows, 'adekuasi' => $adeakuasi, 'kategoriumum' => $kategoriumum, 'interpretasi' => $interpretasi); - $this->sys_ok(["records" => $rst]); - } - - function translate_word($word) - { - $sql = "SELECT * - FROM translate_word - WHERE Translate_WordNat_LangID = '2' AND - BINARY Translate_WordFrom = '{$word}' AND - Translate_WordIsActive = 'Y' - LIMIT 1"; - $dt = $this->db_smartone->query($sql)->result_array(); - if (count($dt) > 0) { - return $dt[0]['Translate_WordTo']; - } else { - return $word; - } - } - - function getpapsmearresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT Other_PapSmearDetailsID as xid, - Other_PapSmearID as header_id, - Other_PapSmearT_OrderDetailID as orderdetail_id, - Other_PapSmearDetailsCode as code, - Other_PapSmearDetailsLabel as label, - Other_PapSmearDetailsResult as result, - IFNULL(Other_PapSmearM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_PapSmearM_DoctorID) OR Other_PapSmearM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_papsmear - JOIN other_papsmeardetails ON Other_PapSmearDetailsOther_PapSmearID = Other_PapSmearID AND Other_PapSmearDetailsIsActive = 'Y' - LEFT JOIN m_doctor ON Other_PapSmearM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_PapSmearT_OrderDetailID = {$id} AND Other_PapSmearIsActive = 'Y' - GROUP BY Other_PapSmearDetailsID - ORDER BY Other_PapSmearDetailsCode ASC"; - //echo $sql; - $rows = $this->db_smartone->query($sql)->result_array(); - if (!$rows) { - $rows = array( - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'A', - 'label' => 'Makroskopik', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ), - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'B', - 'label' => 'Mikroskopik', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ), - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'C', - 'label' => 'Kesimpulan', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ) - ); - } - - $header_id = $rows[0]['header_id']; - $sql = "SELECT Other_PapSmearMaturasiID as xid, - Other_PapSmearMaturasiValue as value - FROM other_papsmearmaturasi - WHERE - Other_PapSmearMaturasiOther_PapSmearID = {$header_id} AND - Other_PapSmearMaturasiIsActive = 'Y' - "; - //echo $sql; - $dt_maturasi = $this->db_smartone->query($sql)->row_array(); - if (!$dt_maturasi) { - $maturasi = array('xid' => '0', 'value' => array('', '', '')); - } else { - $value = explode('/', $dt_maturasi['value']); - $maturasi = array('xid' => $dt_maturasi['xid'], 'value' => $value); - } - - $sql = "SELECT IFNULL(Other_PapSmearBahanID,0) as xid, - M_PapSmearBahanID as bahan_id, - M_PapSmearBahanName as name, - IF(ISNULL(Other_PapSmearBahanID),'N','Y') as selected - FROM m_papsmearbahan - LEFT JOIN other_papsmearbahan ON Other_PapSmearBahanM_PapSmearBahanID = M_PapSmearBahanID AND - Other_PapSmearBahanOther_PapSmearID = {$header_id} AND - Other_PapSmearBahanIsActive = 'Y' - WHERE - M_PapSmearBahanIsActive = 'Y' - ORDER BY M_PapSmearBahanID ASC - "; - //echo $sql; - $bahans = $this->db_smartone->query($sql)->result_array(); - - $sql = "SELECT IFNULL(Other_PapsmearCategoryID,0) as xid, - M_PapSmearCategoryID as category_id, - M_PapSmearCategoryName as name, - IF(ISNULL(Other_PapsmearCategoryID),'N','Y') as selected - FROM m_papsmearcategory - LEFT JOIN other_papsmearcategory ON Other_PapsmearCategoryM_PapSmearCategoryID = M_PapSmearCategoryID AND - Other_PapsmearCategoryOther_PapSmearID = {$header_id} AND - Other_PapsmearCategoryIsActive = 'Y' - WHERE - M_PapSmearCategoryIsActive = 'Y' - ORDER BY M_PapSmearCategoryID ASC - "; - //echo $sql; - $categories = $this->db_smartone->query($sql)->result_array(); - - $sql = "SELECT IFNULL(Other_PapSmearCheckID,0) as xid, - M_PapSmearCheckID as check_id, - M_PapSmearCheckLabel as name, - IF(ISNULL(Other_PapSmearCheckID),'N','Y') as selected, - Other_PapSmearCheckNote as note - FROM m_papsmearcheck - LEFT JOIN other_papsmearcheck ON Other_PapSmearCheckM_PapSmearCheckID = M_PapSmearCheckID AND - Other_PapSmearCheckOther_PapSmearID = {$header_id} AND - Other_PapSmearCheckIsActive = 'Y' - WHERE - M_PapSmearCheckIsActive = 'Y' - ORDER BY M_PapSmearCheckCode ASC - "; - $checks = $this->db_smartone->query($sql)->result_array(); - - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $rst = array('doctors' => $doctors, 'checks' => $checks, 'bahans' => $bahans, 'categories' => $categories, 'maturasi' => $maturasi, 'results' => $rows); - $this->sys_ok(["records" => $rst]); - } - - function saveresult_lcprep() - { - $prm = $this->sys_input; - $detail_id = $prm['detail_id']; - $doctor_id = $prm['doctor']; - $adekuasi = $prm['adekuasi']; - $kategoriumum = $prm['kategoriumum']; - $interpretasi = $prm['interpretasi']; - $results = $prm['results']; - $selected_lang = $prm['selected_lang']; - $other_results = $prm['other_results']; - - $userid = $this->sys_user['M_UserID']; - - $header_id = 0; - $sql = "SELECT * FROM other_lcprep WHERE Other_LcprepT_orderDetailID = ? AND Other_LcprepIsActive = 'Y'"; - $dt_header = $this->db_smartone->query($sql, array($detail_id))->row_array(); - if ($dt_header) { - $header_id = $dt_header['Other_LcprepID']; - } - if ($header_id == 0) { - $sql = "INSERT INTO other_lcprep( - Other_LcprepT_orderDetailID, - Other_LcprepM_DoctorID, - Other_LcprepUserID, - Other_LcprepCreated - ) - VALUES( - ?, - ?, - ?, - NOW() - )"; - //echo $sql; - $query = $this->db_smartone->query($sql, array($detail_id, $doctor_id, $userid)); - if(!$query){ - echo $this->db_smartone->last_query(); - exit; - } - $header_id = $this->db_smartone->insert_id(); - } else { - $sql = "UPDATE other_lcprep SET Other_LcprepM_DoctorID = ?, Other_LcprepUserID = ? WHERE Other_LcprepID = ?"; - $query = $this->db_smartone->query($sql, array($doctor_id, $userid, $header_id)); - if(!$query){ - echo $this->db_smartone->last_query(); - exit; - } - } - - - - if ($adekuasi) { - foreach ($adekuasi as $k => $v) { - $selected = $v['chex'] ? 'Y' : 'N'; - if (intval($v['xid'] == 0)) { - $sql = "UPDATE other_lcprepadekuasi SET Other_LcprepAdekuasiIsActive = 'N' - WHERE - Other_LcprepAdekuasiOther_LcprepID = ? AND - Other_LcprepAdekuasiIsActive = 'Y' AND - Other_LcprepAdekuasiLcprep_AdekuasiID = ?"; - $query = $this->db_smartone->query($sql, array($header_id, $v['id'])); - if(!$query){ - echo $this->db_smartone->last_query(); - exit; - } - $sql = "INSERT INTO other_lcprepadekuasi ( - Other_LcprepAdekuasiOther_LcprepID, - Other_LcprepAdekuasiLcprep_AdekuasiID, - Other_LcprepAdekuasiChex, - Other_LcprepAdekuasiUserID, - Other_LcprepAdekuasiCreated - ) - VALUES( - ?, - ?, - ?, - ?, - NOW() - )"; - $query = $this->db_smartone->query($sql, array($header_id, $v['id'], $selected, $userid)); - if(!$query){ - echo $this->db_smartone->last_query(); - exit; - } - //echo $sql; - } - if (intval($v['xid'] != 0)) { - - $sql = "UPDATE other_lcprepadekuasi SET - Other_LcprepAdekuasiChex = ?, - Other_LcprepAdekuasiUserID = ? - WHERE - Other_LcprepAdekuasiID = ? - "; - $query = $this->db_smartone->query($sql, array($selected, $userid, $v['xid'])); - if(!$query){ - echo $this->db_smartone->last_query(); - exit; - } - } - - //echo $sql; - } - } - - if ($kategoriumum) { - foreach ($kategoriumum as $k => $v) { - $selected = $v['chex'] ? 'Y' : 'N'; - if (intval($v['xid'] == 0)) { - $sql = "UPDATE other_lcprepkategoriumum SET Other_LcprepKategoriUmumIsActive = 'N' - WHERE - Other_LcprepKategoriUmumOther_LcprepID = ? AND - Other_LcprepKategoriUmumLcprep_KategoriUmumID = ? AND - Other_LcprepKategoriUmumIsActive = 'Y' - "; - $query = $this->db_smartone->query($sql, array($header_id, $v['id'])); - if(!$query){ - echo $this->db_smartone->last_query(); - exit; - } - $sql = "INSERT INTO other_lcprepkategoriumum ( - Other_LcprepKategoriUmumOther_LcprepID, - Other_LcprepKategoriUmumLcprep_KategoriUmumID, - Other_LcprepKategoriUmumChex, - Other_LcprepKategoriUmumUserID, - Other_LcprepKategoriUmumCreated - ) - VALUES( - ?, - ?, - ?, - ?, - NOW() - )"; - $query = $this->db_smartone->query($sql, array($header_id, $v['id'], $selected, $userid)); - if(!$query){ - echo $this->db_smartone->last_query(); - exit; - } - } - if (intval($v['xid'] != 0)) { - $sql = "UPDATE other_lcprepkategoriumum SET - Other_LcprepKategoriUmumChex = ?, - Other_LcprepKategoriUmumUserID = ? - WHERE - Other_LcprepKategoriUmumID = ? - "; - $query = $this->db_smartone->query($sql, array($selected, $userid, $v['xid'])); - if(!$query){ - echo $this->db_smartone->last_query(); - exit; - } - } - - //echo $sql; - } - } - - if (count($results) > 0 && intval($selected_lang) == 1) { - foreach ($results as $k => $v) { - if (intval($v['xid'] == 0)) { - $sql = "UPDATE other_lcprepdetails SET Other_LcprepDetailsIsActive = 'N' - WHERE - Other_LcprepDetailsOther_LcprepID = ? AND - Other_LcprepDetailsCode = ? AND - Other_LcprepDetailsIsActive = 'Y'"; - $query = $this->db_smartone->query($sql, array($header_id, $v['code'])); - if(!$query){ - echo $this->db_smartone->last_query(); - exit; - } - $sql = "INSERT INTO other_lcprepdetails ( - Other_LcprepDetailsOther_LcprepID, - Other_LcprepDetailsCode, - Other_LcprepDetailsLabel, - Other_LcprepDetailsResult, - Other_LcprepDetailsUserID, - Other_LcprepDetailsCreated - ) - VALUES( - ?, - ?, - ?, - ?, - ?, - NOW() - )"; - $query = $this->db_smartone->query($sql, array($header_id, $v['code'], $v['label'], $v['result'], $userid)); - if(!$query){ - echo $this->db_smartone->last_query(); - exit; - } - } - if (intval($v['xid'] != 0)) { - $sql = "UPDATE other_lcprepdetails SET - Other_LcprepDetailsCode = ?, - Other_LcprepDetailsLabel = ?, - Other_LcprepDetailsResult = ?, - Other_LcprepDetailsUserID = ? - WHERE - Other_LcprepDetailsID = ? - "; - $query = $this->db_smartone->query($sql, array($v['code'], $v['label'], $v['result'], $userid, $v['xid'])); - if(!$query){ - echo $this->db_smartone->last_query(); - exit; - } - } - //echo $sql; - } - } - - if (count($other_results) > 0 && intval($selected_lang) == 2) { - foreach ($other_results as $k => $v) { - if (intval($v['xid'] == 0)) { - $sql = "UPDATE other_lcprepdetails_lang SET Other_LcprepDetailsLangsIsActive = 'N' - WHERE - Other_LcprepDetailsLangsOther_LcprepID = ? AND - Other_LcprepDetailsLangsCode = ? AND - Other_LcprepDetailsLangsIsActive = 'Y'"; - $query = $this->db_smartone->query($sql, array($header_id, $v['code'])); - if(!$query){ - echo $this->db_smartone->last_query(); - exit; - } - //echo $this->db_smartone->last_query(); - $sql = "INSERT INTO other_lcprepdetails_lang ( - Other_LcprepDetailsLangsOther_LcprepID, - Other_LcprepDetailsLangsCode, - Other_LcprepDetailsLangsLabel, - Other_LcprepDetailsLangsResult, - Other_LcprepDetailsLangsCreatedUserID, - Other_LcprepDetailsLangsCreated - ) - VALUES( - ?, - ?, - ?, - ?, - ?, - NOW() - )"; - $query = $this->db_smartone->query($sql, array($header_id, $v['code'], $v['label'], $v['result'], $userid)); - if(!$query){ - echo $this->db_smartone->last_query(); - exit; - } - //echo $this->db_smartone->last_query(); - } - if (intval($v['xid'] != 0)) { - $sql = "UPDATE other_lcprepdetails_lang SET - Other_LcprepDetailsLangsCode = ?, - Other_LcprepDetailsLangsLabel = ?, - Other_LcprepDetailsLangsResult = ?, - Other_LcprepDetailsLangsUpdatedUserID = ?, - Other_LcprepDetailsLangsUpdated = NOW() - WHERE - Other_LcprepDetailsLangsID = ? - "; - $query = $this->db_smartone->query($sql, array($v['code'], $v['label'], $v['result'], $userid, $v['xid'])); - if(!$query){ - echo $this->db_smartone->last_query(); - exit; - } - } - //echo $sql; - } - } - - if ($interpretasi) { - foreach ($interpretasi as $k => $v) { - if (count($v['subgroups']) > 0) { - foreach ($v['subgroups'] as $ik => $iv) { - if (count($iv['childs']) > 0) { - foreach ($iv['childs'] as $iik => $iiv) { - if (intval($iiv['xid'] == 0)) { - $chex = $iiv['chex'] ? 'Y' : 'N'; - $sql = "UPDATE other_lcprepinterpretasi SET Other_LcprepInterpretasiIsActive = 'N' - WHERE - Other_LcprepInterpretasiOther_LcprepID = ? AND - Other_LcprepInterpretasiLcprep_InterpretasiID = ? AND - Other_LcprepInterpretasiIsActive = 'Y'"; - $query = $this->db_smartone->query($sql, array($header_id, $iiv['id'])); - if(!$query){ - echo $this->db_smartone->last_query(); - exit; - } - $sql = "INSERT INTO other_lcprepinterpretasi ( - Other_LcprepInterpretasiOther_LcprepID, - Other_LcprepInterpretasiLcprep_InterpretasiID, - Other_LcprepInterpretasiChex, - Other_LcprepInterpretasiValue, - Other_LcprepInterpretasiValueEng, - Other_LcprepInterpretasiUserID, - Other_LcprepInterpretasiCreated - ) - VALUES( - ?, - ?, - ?, - ?, - ?, - ?, - NOW() - )"; - $query = $this->db_smartone->query($sql, array($header_id, $iiv['id'], $chex, $iiv['value'], $iiv['value_en'], $userid)); - if(!$query){ - echo $this->db_smartone->last_query(); - exit; - } - } - - if (intval($iiv['xid'] != 0)) { - $chex = $iiv['chex'] ? 'Y' : 'N'; - $sql = "UPDATE other_lcprepinterpretasi SET - Other_LcprepInterpretasiChex = ?, - Other_LcprepInterpretasiValue = ?, - Other_LcprepInterpretasiValueEng = ?, - Other_LcprepInterpretasiUserID = ? - WHERE - Other_LcprepInterpretasiID = ? - "; - $query = $this->db_smartone->query($sql, array($chex, $iiv['value'], $iiv['value_en'], $userid, $iiv['xid'])); - if(!$query){ - echo $this->db_smartone->last_query(); - exit; - } - //echo $sql; - - } - } - } - } - } - //echo $sql; - } - } - - - $result = array("total" => 1, "records" => array(), "sql" => ''); - $this->sys_ok($result); - exit; - } - - function saveresult_papsmear() - { - $prm = $this->sys_input; - $detail_id = $prm['detail_id']; - $doctor_id = $prm['doctor']; - $checks = $prm['checks']; - $maturasi = $prm['maturasi']; - $bahans = $prm['bahans']; - $categories = $prm['categories']; - $results = $prm['results']; - - $userid = $this->sys_user['M_UserID']; - - $header_id = 0; - $sql = "SELECT * FROM other_papsmear WHERE Other_PapSmearT_OrderDetailID = {$detail_id} AND Other_PapSmearIsActive = 'Y'"; - $dt_header = $this->db_smartone->query($sql)->row_array(); - if ($dt_header) { - $header_id = $dt_header['Other_PapSmearID']; - } - if ($header_id == 0) { - $sql = "INSERT INTO other_papsmear( - Other_PapSmearT_OrderDetailID, - Other_PapSmearM_DoctorID, - Other_PapSmearUserID, - Other_PapSmearCreated - ) - VALUES( - {$detail_id}, - {$doctor_id}, - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } else { - $sql = "UPDATE other_papsmear SET Other_PapSmearM_DoctorID = {$doctor_id}, Other_PapSmearUserID = {$userid} WHERE Other_PapSmearID = {$header_id}"; - $this->db_smartone->query($sql); - } - - if ($checks) { - foreach ($checks as $k => $v) { - if (intval($v['xid']) == 0 && $v['selected'] === 'Y') { - $sql = "INSERT INTO other_papsmearcheck ( - Other_PapSmearCheckOther_PapSmearID, - Other_PapSmearCheckM_PapSmearCheckID, - Other_PapSmearCheckNote, - Other_PapSmearCheckUserID, - Other_PapSmearCheckCreated - ) - VALUES( - {$header_id}, - {$v['check_id']}, - '{$v['note']}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if (intval($v['xid']) != 0 && $v['selected'] === 'N') { - $sql = "UPDATE other_papsmearcheck SET - Other_PapSmearCheckIsActive = 'N', - Other_PapSmearCheckUserID = {$userid} - WHERE - Other_PapSmearCheckID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - if (intval($v['xid']) != 0 && $v['selected'] === 'Y') { - $sql = "UPDATE other_papsmearcheck SET - Other_PapSmearCheckNote = '{$v['note']}', - Other_PapSmearCheckUserID = {$userid} - WHERE - Other_PapSmearCheckID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - //echo $sql; - } - } - - if ($maturasi) { - if (intval($maturasi['xid']) == 0) { - $value = join("/", $maturasi['value']); - $sql = "INSERT INTO other_papsmearmaturasi ( - Other_PapSmearMaturasiOther_PapSmearID, - Other_PapSmearMaturasiValue, - Other_PapSmearMaturasiUserID, - Other_PapSmearMaturasiCreated - ) - VALUE( - {$header_id}, - '{$value}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - //echo $sql; - } - if (intval($maturasi['xid']) != 0) { - $value = join("/", $maturasi['value']); - $sql = "UPDATE other_papsmearmaturasi SET - Other_PapSmearMaturasiValue = '{$value}', - Other_PapSmearMaturasiUserID = {$userid} - WHERE - Other_PapSmearMaturasiID = {$maturasi['xid']}"; - // echo $sql; - $this->db_smartone->query($sql); - } - } - - if ($bahans) { - foreach ($bahans as $k => $v) { - if (intval($v['xid']) == 0 && $v['selected'] === 'Y') { - $sql = "INSERT INTO other_papsmearbahan ( - Other_PapSmearBahanOther_PapSmearID, - Other_PapSmearBahanM_PapSmearBahanID, - Other_PapSmearBahanUserID, - Other_PapSmearBahanCreated - ) - VALUES( - {$header_id}, - {$v['bahan_id']}, - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if (intval($v['xid']) != 0 && $v['selected'] === 'N') { - $sql = "UPDATE other_papsmearbahan SET - Other_PapSmearBahanIsActive = 'N', - Other_PapsmearCategoryUserID = {$userid} - WHERE - Other_PapSmearBahanID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - if (intval($v['xid']) != 0 && $v['selected'] === 'Y') { - $sql = "UPDATE other_papsmearbahan SET - Other_PapSmearBahanIsActive = 'Y', - Other_PapsmearCategoryUserID = {$userid} - WHERE - Other_PapSmearBahanID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - //echo $sql; - } - } - - if ($categories) { - foreach ($categories as $k => $v) { - if (intval($v['xid']) == 0 && $v['selected'] === 'Y') { - $sql = "INSERT INTO other_papsmearcategory ( - Other_PapsmearCategoryOther_PapSmearID, - Other_PapsmearCategoryM_PapSmearCategoryID, - Other_PapsmearCategoryUserID, - Other_PapsmearCategoryCreated - ) - VALUES( - {$header_id}, - {$v['category_id']}, - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if (intval($v['xid']) != 0 && $v['selected'] === 'N') { - $sql = "UPDATE other_papsmearcategory SET - Other_PapsmearCategoryIsActive = 'N', - Other_PapsmearCategoryUserID = {$userid} - WHERE - Other_PapsmearCategoryID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - //echo $sql; - if (intval($v['xid']) != 0 && $v['selected'] === 'Y') { - $sql = "UPDATE other_papsmearcategory SET - Other_PapsmearCategoryIsActive = 'Y', - Other_PapsmearCategoryUserID = {$userid} - WHERE - Other_PapsmearCategoryID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - } - } - - if ($results) { - foreach ($results as $k => $v) { - if (intval($v['xid']) == 0) { - $sql = "INSERT INTO other_papsmeardetails ( - Other_PapSmearDetailsOther_PapSmearID, - Other_PapSmearDetailsCode, - Other_PapSmearDetailsLabel, - Other_PapSmearDetailsResult, - Other_PapSmearDetailsUserID, - Other_PapSmearDetailsCreated - ) - VALUES( - {$header_id}, - '{$v['code']}', - '{$v['label']}', - '{$v['result']}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if (intval($v['xid']) != 0) { - $sql = "UPDATE other_papsmeardetails SET - Other_PapSmearDetailsCode = '{$v['code']}', - Other_PapSmearDetailsLabel = '{$v['label']}', - Other_PapSmearDetailsResult = '{$v['result']}', - Other_PapSmearDetailsUserID = {$userid} - WHERE - Other_PapSmearDetailsID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - //echo $sql; - } - } - - $result = array("total" => 1, "records" => array(), "sql" => ''); - $this->sys_ok($result); - exit; - } - - function saveresult_fna() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = $inp['doctor']; - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - if ($prm[0]['xid'] == '0') { - $sql = "INSERT INTO other_fna( - Other_FNAM_DoctorID, - Other_FNAT_OrderDetailID, - Other_FNAUserID, - Other_FNACreated - ) - VALUES( - {$doctor_id}, - {$prm[0]['orderdetail_id']}, - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } else { - $sql = "SELECT * FROM other_fna WHERE Other_FNAT_OrderDetailID = {$prm[0]['orderdetail_id']} AND Other_FNAIsActive = 'Y'"; - $data_header = $this->db_smartone->query($sql)->row_array(); - $header_id = $data_header['Other_FNAID']; - $sql = "UPDATE other_fna SET - Other_FNAM_DoctorID = {$doctor_id}, - Other_FNAUserID = {$userid} - WHERE - Other_FNAID = {$header_id}"; - $this->db_smartone->query($sql); - } - foreach ($prm as $k => $v) { - if ($v['xid'] == '0') { - $results = str_replace("'", "\\'", $v['result']); - $sql = "INSERT INTO other_fnadetails( - Other_FNADetailsOther_FNAID , - Other_FNADetailsCode, - Other_FNADetailsLabel, - Other_FNADetailsResult, - Other_FNADetailsCreated, - Other_FNADetailsUserID - ) - VALUES( - {$header_id}, - '{$v['code']}', - '{$v['label']}', - '{$results}', - NOW(), - {$userid} - )"; - $query = $this->db_smartone->query($sql); - } else { - $results = str_replace("'", "\\'", $v['result']); - $sql = "UPDATE other_fnadetails SET - Other_FNADetailsResult = '{$results}', - Other_FNADetailsUserID = {$userid} - WHERE - Other_FNADetailsID = {$v['xid']}"; - $query = $this->db_smartone->query($sql); - } - } - - $result = array("total" => 1, "records" => array(), "sql" => ''); - $this->sys_ok($result); - exit; - } - - function saveresult_patologianatomy() - { - - $inp = $this->sys_input; - $doctor_id = $inp['doctor']; - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - if ($inp['xid'] == '0') { - $sql = "INSERT INTO other_patologi_anatomy( - Other_PatologiAnatomyT_OrderDetailID, - Other_PatologiAnatomyM_DoctorID, - Other_PatologiAnatomyNoSediaan, - Other_PatologiAnatomyDiagnosaKlinis, - Other_PatologiAnatomyKeteranganKlinis, - Other_PatologiAnatomyLokasiOrgan, - Other_PatologiAnatomyMakroskopik, - Other_PatologiAnatomyMikroskopik, - Other_PatologiAnatomyKesimpulan, - Other_PatologiAnatomyUserID, - Other_PatologiAnatomyCreated - ) - VALUES( - {$inp['detail_id']}, - {$doctor_id}, - '{$inp['no_sediaan']}', - '{$inp['diagnosa']}', - '{$inp['klinis']}', - '{$inp['lokasi']}', - '{$inp['makroskopik']}', - '{$inp['mikroskopik']}', - '{$inp['kesimpulan']}', - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } else { - $sql = "UPDATE other_patologi_anatomy SET - Other_PatologiAnatomyM_DoctorID = ?, - Other_PatologiAnatomyNoSediaan = ?, - Other_PatologiAnatomyKeteranganKlinis = ?, - Other_PatologiAnatomyDiagnosaKlinis = ?, - Other_PatologiAnatomyLokasiOrgan = ?, - Other_PatologiAnatomyMakroskopik = ?, - Other_PatologiAnatomyMikroskopik = ?, - Other_PatologiAnatomyKesimpulan = ?, - Other_PatologiAnatomyUserID = ? - WHERE - Other_PatologiAnatomyT_OrderDetailID = ? AND Other_PatologiAnatomyIsActive = 'Y'"; - $this->db_smartone->query($sql, array( - $doctor_id, - $inp['no_sediaan'], - $inp['klinis'], - $inp['diagnosa'], - $inp['lokasi'], - $inp['makroskopik'], - $inp['mikroskopik'], - $inp['kesimpulan'], - $userid, - $inp['detail_id'] - )); - //echo $this->db_smartone->last_query(); - - } - - $inp_rst = array( - 'doctor_id' => $doctor_id, - 'no_sediaan' => $inp['no_sediaan'], - 'klinis' => $inp['klinis'], - 'diagnosa' => $inp['diagnosa'], - 'lokasi' => $inp['lokasi'], - 'makroskopik' => $inp['makroskopik'], - 'mikroskopik' => $inp['mikroskopik'], - 'kesimpulan' => $inp['kesimpulan'] - ); - $log_json = json_encode($inp_rst); - - $sql = "INSERT INTO log_other_patologianatomy ( - Log_OtherPatologiAnatomyT_OrderDetailID, - Log_OtherPatologiAnatomyDateTime, - Log_OtherPatologiAnatomySON, - Log_OtherPatologiAnatomyUserID - )VALUE( - {$inp['detail_id']}, - NOW(), - '{$log_json}', - {$userid} - )"; - $this->db_smartone->query($sql); - //echo $this->db_smartone->last_query(); - - $result = array("total" => 1, "records" => array(), "sql" => ''); - $this->sys_ok($result); - exit; - } - - function saveresult_cytologi() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = $inp['doctor']; - - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - if ($prm[0]['xid'] == '0') { - $sql = "INSERT INTO other_cytologi( - Other_CytologiT_OrderDetailID, - Other_CytologiM_DoctorID, - Other_CytologiUserID, - Other_CytologiCreated - ) - VALUES( - {$prm[0]['orderdetail_id']}, - {$doctor_id}, - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } else { - $sql = "SELECT * FROM other_cytologi WHERE Other_CytologiT_OrderDetailID = {$prm[0]['orderdetail_id']} AND Other_CytologiIsActive = 'Y'"; - $data_header = $this->db_smartone->query($sql)->row_array(); - $header_id = $data_header['Other_CytologiID']; - $sql = "UPDATE other_cytologi SET - Other_CytologiM_DoctorID = {$doctor_id}, - Other_CytologiUserID = {$userid} - WHERE - Other_CytologiID = {$header_id}"; - $this->db_smartone->query($sql); - } - foreach ($prm as $k => $v) { - if ($v['xid'] == '0') { - $results = str_replace("'", "\\'", $v['result']); - $sql = "INSERT INTO other_cytologidetails( - Other_CytologiDetailsOther_CytologiID , - Other_CytologiDetailsCode, - Other_CytologiDetailsLabel, - Other_CytologiDetailsResult, - Other_CytologiDetailsCreated, - Other_CytologiDetailsUserID - ) - VALUES( - {$header_id}, - '{$v['code']}', - '{$v['label']}', - '{$results}', - NOW(), - {$userid} - )"; - $query = $this->db_smartone->query($sql); - } else { - $results = str_replace("'", "\\'", $v['result']); - $sql = "UPDATE other_cytologidetails SET - Other_CytologiDetailsResult = '{$results}', - Other_CytologiDetailsUserID = {$userid} - WHERE - Other_CytologiDetailsID = {$v['xid']}"; - $query = $this->db_smartone->query($sql); - } - } - - $result = array("total" => 1, "records" => array(), "sql" => ''); - $this->sys_ok($result); - exit; - } - - function saveresult_mikro() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = $inp['doctor']; - $backteria_id = $inp['bacteria']; - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - - if ($inp['result_value'] != 'Negatif' && $inp['result_value'] != 'Positif') { - $prm['result_value'] = $prm['result_other']; - } else { - $prm['result_value'] = $inp['result_value']; - } - - if ($prm['xid'] == '0') { - $sql = "INSERT INTO other_mikro( - Other_MikroM_DoctorID, - Other_MikroResult, - Other_MikroT_BacteriaID, - Other_MikroT_OrderDetailID, - Other_MikroHasilBiakan, - Other_MikroSampleTypeName, - Other_MikroUserID, - Other_MikroCreated - ) - VALUES( - {$doctor_id}, - '{$prm['result_value']}', - {$backteria_id}, - {$prm['orderdetail_id']}, - '{$prm['hasil_biakan']}', - '{$prm['sample_name']}', - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } else { - $sql = "SELECT * FROM other_mikro WHERE Other_MikroT_OrderDetailID = {$prm['orderdetail_id']} AND Other_MikroIsActive = 'Y'"; - $data_header = $this->db_smartone->query($sql)->row_array(); - $header_id = $data_header['Other_MikroID']; - $sql = "UPDATE other_mikro SET - Other_MikroResult = '{$prm['result_value']}', - Other_MikroM_DoctorID = {$doctor_id}, - Other_MikroT_BacteriaID = {$backteria_id}, - Other_MikroHasilBiakan = '{$prm['hasil_biakan']}', - Other_MikroSampleTypeName = '{$prm['sample_name']}', - Other_MikroUserID = {$userid} - WHERE - Other_MikroID = {$header_id}"; - //echo $sql; - $this->db_smartone->query($sql); - } - - - - $sql = "UPDATE other_mikrodetails SET Other_MikroDetailsIsActive = 'N', Other_MikroDetailsUserID = 0 WHERE Other_MikroDetailsOther_MikroID = {$header_id}"; - $this->db_smartone->query($sql); - - $results = $prm['details']; - if ($inp['result_value'] == 'Positif') { - foreach ($results as $k => $v) { - if ($v['xid'] == '0') { - $sql = "INSERT INTO other_mikrodetails( - Other_MikroDetailsOther_MikroID , - Other_MikroDetailsT_AntibioticID, - Other_MikroDetailsValue, - Other_MikroDetailsNote, - Other_MikroDetailsCreated, - Other_MikroDetailsUserID - ) - VALUES( - {$header_id}, - '{$v['T_AntibioticID']}', - '{$v['value']}', - '{$v['note']}', - NOW(), - {$userid} - )"; - $query = $this->db_smartone->query($sql); - } else { - $sql = "UPDATE other_mikrodetails SET - Other_MikroDetailsT_AntibioticID = '{$v['T_AntibioticID']}', - Other_MikroDetailsValue = '{$v['value']}', - Other_MikroDetailsNote = '{$v['note']}', - Other_MikroDetailsIsActive = 'Y', - Other_MikroDetailsUserID = {$userid} - WHERE - Other_MikroDetailsID = {$v['xid']}"; - //echo $sql; - $query = $this->db_smartone->query($sql); - } - } - } - - - $result = array("total" => 1, "records" => array(), "sql" => ''); - $this->sys_ok($result); - exit; - } - - - function get_doctors_preparasi_sperma() - { - $prm = $this->sys_input; - // $id = $prm["id"]; - - $sql = " SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 10 AND - M_DoctorSOIsActive = 'Y' - ORDER BY M_DoctorName ASC"; - //echo $sql; - $query = $this->db_smartone->query($sql); - $rows = $query->result_array(); - $sql = " - SELECT '0' as id, 'Belum memilih metode' as name - UNION - SELECT M_MethodeSpermaID as id, M_MethodeSpermaName as name - FROM m_methodesperma - WHERE - M_MethodeSpermaIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $methodes = $this->db_smartone->query($sql)->result_array(); - - - $this->sys_ok(["records" => $rows, "methodes" => $methodes]); - } - - - function getpreparasispermaresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT other_preparasisperma.*, - Other_PreparasiSpermaID as xid, - Other_PreparasiSpermaT_OrderDetailID as orderdetail_id, - IFNULL(Other_PreparasiSpermaM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_PreparasiSpermaM_DoctorID) OR Other_PreparasiSpermaM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name, - IFNULL(M_MethodeSpermaID,0) as methode_id, - IFNULL(M_MethodeSpermaName,'') as methode_name - FROM other_preparasisperma - LEFT JOIN m_doctor ON Other_PreparasiSpermaM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - LEFT JOIN m_methodesperma ON Other_PreparasiSpermaM_MethodeSpermaID = M_MethodeSpermaID AND - M_MethodeSpermaIsActive = 'Y' - WHERE - Other_PreparasiSpermaT_OrderDetailID = {$id} AND Other_PreparasiSpermaIsActive = 'Y' - GROUP BY Other_PreparasiSpermaID"; - $query = $this->db_smartone->query($sql); - - if ($query) { - $rows = $query->row_array(); - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 10 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $sql = " - SELECT '0' as id, 'Belum memilih metode' as name - UNION - SELECT M_MethodeSpermaID as id, M_MethodeSpermaName as name - FROM m_methodesperma - WHERE - M_MethodeSpermaIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $methodes = $this->db_smartone->query($sql)->result_array(); - $images = array(); - $sql = "SELECT Other_PreparasiSpermaImgID as xid, - Other_PreparasiSpermaImgType as type, - CONCAT('/one-media/one-image-nonlab/',Other_PreparasiSpermaImgNewName) as image_url - FROM t_orderdetail - JOIN other_preparasisperma_img ON Other_PreparasiSpermaImgT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND - Other_PreparasiSpermaImgIsActive = 'Y' - WHERE - T_OrderDetailID = {$id} AND - T_OrderDetailIsActive = 'Y' - GROUP BY Other_PreparasiSpermaImgID"; - //echo $sql; - $images = $this->db_smartone->query($sql)->result_array(); - - $rst = array('doctors' => $doctors, 'methodes' => $methodes, 'results' => $rows, 'images' => $images); - $this->sys_ok(["records" => $rst]); - } else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - - function uploadimage_preparasi_sperma() - { - if (! $this->isLogin) { - $this->sys_error("Invalid Token"); - exit; - } - - $userid = $this->sys_user["M_UserID"]; - $data = []; - //print_r($_SERVER); - - $prm = $this->sys_input; - $orderid = $this->input->post('orderid'); - $type = $this->input->post('type'); - $labnumber = $this->input->post('labnumber'); - $sql = "UPDATE other_preparasisperma_img SET - Other_PreparasiSpermaImgIsActive = 'N', - Other_PreparasiSpermaImgUserID = {$userid} - WHERE - Other_PreparasiSpermaImgT_OrderHeaderID = {$orderid} AND - Other_PreparasiSpermaImgType = '{$type}'"; - //echo $sql; - $this->db_onedev->query($sql); - //$config['upload_path'] = 'assets/'; - - $path = '/home/one/project/one/one-media/one-image-nonlab/'; - //echo $path; - $config['upload_path'] = $path; - $config['allowed_types'] = 'jpg|jpeg|png|gif'; - - $config['max_size'] = '10000'; - $count = count($_FILES['files']['name']); - //echo $count; - $this->load->library('upload', $config); - - $error = []; - for ($i = 0; $i < $count; $i++) { - - - if (!empty($_FILES['files']['name'][$i])) { - - - - $_FILES['file']['name'] = $_FILES['files']['name'][$i]; - - $_FILES['file']['type'] = $_FILES['files']['type'][$i]; - - $_FILES['file']['tmp_name'] = $_FILES['files']['tmp_name'][$i]; - - $_FILES['file']['error'] = $_FILES['files']['error'][$i]; - - $_FILES['file']['size'] = $_FILES['files']['size'][$i]; - - - - $namex = $orderid . '-' . $labnumber . '-' . $this->generateRandomString(5); - //echo $namex; - - $config['file_name'] = $namex; - $this->upload->initialize($config); - //echo $config['file_name'] ; - - - - - - if ($this->upload->do_upload('file')) { - - $uploadData = $this->upload->data(); - - $filename = $uploadData['file_name']; - //echo $filename; - - - $sql = "INSERT INTO other_preparasisperma_img ( - Other_PreparasiSpermaImgT_OrderHeaderID, - Other_PreparasiSpermaImgType, - Other_PreparasiSpermaImgOldName, - Other_PreparasiSpermaImgNewName, - Other_PreparasiSpermaImgCreated, - Other_PreparasiSpermaImgUserID - ) - VALUES( - {$orderid}, - '{$type}', - '{$_FILES['files']['name'][$i]}', - '{$filename}', - NOW(), - {$userid} - - )"; - //echo $sql; - $this->db_onedev->query($sql); - $xlast_id = $this->db_onedev->insert_id(); - $data['totalFiles'][] = array('xid' => $xlast_id, 'type' => $type, 'image_url' => '/one-media/one-image-nonlab/' . $filename); - } else { - $error = array('error' => $this->upload->display_errors()); - } - } - } - - $result = array("total" => count($data['totalFiles']), "records" => $data['totalFiles'], 'errors' => $error); - $this->sys_ok($result); - } - - - function saveresult_preparasi_sperma() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = isset($inp['doctor']) ? $inp['doctor'] : 0; - $methode_id = isset($inp['methode']) ? $inp['methode'] : 0; - $orderdetail_id = $inp['orderdetailid']; - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - if ($prm['xid'] == '0') { - $sql = "INSERT INTO other_preparasisperma( - Other_PreparasiSpermaM_DoctorID, - Other_PreparasiSpermaT_OrderDetailID, - Other_PreparasiSpermaPreMotilitasA, - Other_PreparasiSpermaPreMotilitasB, - Other_PreparasiSpermaPreMotilitasC, - Other_PreparasiSpermaPreKonsentrasi, - Other_PreparasiSpermaPreKontaminan, - Other_PreparasiSpermaPostMotilitasA, - Other_PreparasiSpermaPostMotilitasB, - Other_PreparasiSpermaPostMotilitasC, - Other_PreparasiSpermaPostKonsentrasi, - Other_PreparasiSpermaPostKontaminan, - Other_PreparasiSpermaPreVolume, - Other_PreparasiSpermaPostVolume, - Other_PreparasiSpermaM_MethodeSpermaID, - Other_PreparasiSpermaNote, - Other_PreparasiSpermaUserID, - Other_PreparasiSpermaCreated - ) - VALUES( - {$doctor_id}, - {$orderdetail_id}, - '{$prm['Other_PreparasiSpermaPreMotilitasA']}', - '{$prm['Other_PreparasiSpermaPreMotilitasB']}', - '{$prm['Other_PreparasiSpermaPreMotilitasC']}', - '{$prm['Other_PreparasiSpermaPreKonsentrasi']}', - '{$prm['Other_PreparasiSpermaPreKontaminan']}', - '{$prm['Other_PreparasiSpermaPostMotilitasA']}', - '{$prm['Other_PreparasiSpermaPostMotilitasB']}', - '{$prm['Other_PreparasiSpermaPostMotilitasC']}', - '{$prm['Other_PreparasiSpermaPostKonsentrasi']}', - '{$prm['Other_PreparasiSpermaPostKontaminan']}', - '{$prm['Other_PreparasiSpermaPreVolume']}', - '{$prm['Other_PreparasiSpermaPostVolume']}', - '{$methode_id}', - '{$prm['Other_PreparasiSpermaNote']}', - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } else { - $sql = "SELECT * FROM other_preparasisperma WHERE Other_PreparasiSpermaT_OrderDetailID = {$orderdetail_id} AND Other_PreparasiSpermaIsActive = 'Y'"; - $data_header = $this->db_smartone->query($sql)->row_array(); - $header_id = $data_header['Other_PreparasiSpermaID']; - $sql = "UPDATE other_preparasisperma SET - Other_PreparasiSpermaM_DoctorID = {$doctor_id}, - Other_PreparasiSpermaPreMotilitasA = '{$prm['Other_PreparasiSpermaPreMotilitasA']}', - Other_PreparasiSpermaPreMotilitasB = '{$prm['Other_PreparasiSpermaPreMotilitasB']}', - Other_PreparasiSpermaPreMotilitasC = '{$prm['Other_PreparasiSpermaPreMotilitasC']}', - Other_PreparasiSpermaPreKonsentrasi = '{$prm['Other_PreparasiSpermaPreKonsentrasi']}', - Other_PreparasiSpermaPreKontaminan = '{$prm['Other_PreparasiSpermaPreKontaminan']}', - Other_PreparasiSpermaPostMotilitasA = '{$prm['Other_PreparasiSpermaPostMotilitasA']}', - Other_PreparasiSpermaPostMotilitasB = '{$prm['Other_PreparasiSpermaPostMotilitasB']}', - Other_PreparasiSpermaPostMotilitasC = '{$prm['Other_PreparasiSpermaPostMotilitasC']}', - Other_PreparasiSpermaPostKonsentrasi = '{$prm['Other_PreparasiSpermaPostKonsentrasi']}', - Other_PreparasiSpermaPostKontaminan = '{$prm['Other_PreparasiSpermaPostKontaminan']}', - Other_PreparasiSpermaPreVolume = '{$prm['Other_PreparasiSpermaPreVolume']}', - Other_PreparasiSpermaPostVolume = '{$prm['Other_PreparasiSpermaPostVolume']}', - Other_PreparasiSpermaM_MethodeSpermaID = '{$methode_id}', - Other_PreparasiSpermaNote = '{$prm['Other_PreparasiSpermaNote']}', - Other_PreparasiSpermaUserID = {$userid} - WHERE - Other_PreparasiSpermaID = {$header_id}"; - $this->db_smartone->query($sql); - } - - - $result = array("total" => 1, "records" => array(), "sql" => ''); - $this->sys_ok($result); - exit; - } - - function getdnafragmentasiresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT other_dnafragmentasi.*, - Other_DnaFragmentasiID as xid, - Other_DnaFragmentasiT_OrderDetailID as orderdetail_id, - IFNULL(Other_DnaFragmentasiM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_DnaFragmentasiM_DoctorID) OR Other_DnaFragmentasiM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name, - IFNULL(Other_DnaFragmentasiOther_DnaFragmentasiMethodeID,0) as methode_id, - IFNULL(Other_DnaFragmentasiMethodeName,'') as methode_name, - Other_DnaFragmentasiHaloLuas as halo_luas, - Other_DnaFragmentasiHaloSedang as halo_sedang, - Other_DnaFragmentasiHaloSempit as halo_sempit, - Other_DnaFragmentasiTanpaHalo as tanpa_halo, - Other_DnaFragmentasiDFI as dfi, - Other_DnaFragmentasiKesimpulan as kesimpulan, - Other_DnaFragmentasiCatatan as catatan - FROM other_dnafragmentasi - LEFT JOIN m_doctor ON Other_DnaFragmentasiM_DoctorID = M_DoctorID - LEFT JOIN other_dnafragmentasimethode ON Other_DnaFragmentasiOther_DnaFragmentasiMethodeID = Other_DnaFragmentasiMethodeID - WHERE - Other_DnaFragmentasiT_OrderDetailID = {$id} AND Other_DnaFragmentasiIsActive = 'Y' - GROUP BY Other_DnaFragmentasiID - LIMIT 1"; - //echo $sql; - $query = $this->db_smartone->query($sql); - - if ($query) { - $rows = $query->row_array(); - if (!$rows) { - $rows = array( - 'xid' => 0, - 'orderdetail_id' => $id, - 'doctor_id' => 0, - 'doctor_name' => '', - 'methode_id' => 0, - 'methode_name' => '', - 'halo_luas' => '', - 'halo_sedang' => '', - 'tanpa_halo' => '', - 'dfi' => '', - 'kesimpulan' => '', - 'catatan' => '' - ); - } - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID - WHERE - M_DoctorSONat_SubGroupID = 4 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - - $sql = " - SELECT '0' as id, 'Belum memilih metode' as name - UNION - SELECT Other_DnaFragmentasiMethodeID as id, Other_DnaFragmentasiMethodeName as name - FROM other_dnafragmentasimethode - WHERE - Other_DnaFragmentasiMethodeIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $methodes = $this->db_smartone->query($sql)->result_array(); - - - $rst = array('doctors' => $doctors, 'methodes' => $methodes, 'results' => $rows); - $this->sys_ok(["records" => $rst]); - } else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - function saveresult_dnafragmentasi() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = $inp['doctor']['id']; - $methode_id = $inp['methode']['id']; - $orderdetail_id = $inp['results']['orderdetail_id']; - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - if (intval($prm['xid']) == 0) { - $sql = "INSERT INTO other_dnafragmentasi( - Other_DnaFragmentasiT_OrderDetailID, - Other_DnaFragmentasiM_DoctorID, - Other_DnaFragmentasiOther_DnaFragmentasiMethodeID, - Other_DnaFragmentasiHaloLuas, - Other_DnaFragmentasiHaloSedang, - Other_DnaFragmentasiHaloSempit, - Other_DnaFragmentasiTanpaHalo, - Other_DnaFragmentasiDFI, - Other_DnaFragmentasiKesimpulan, - Other_DnaFragmentasiCatatan, - Other_DnaFragmentasiUserID, - Other_DnaFragmentasiLastUpdated - ) - VALUES( - {$orderdetail_id}, - {$doctor_id}, - {$methode_id}, - '{$prm['halo_luas']}', - '{$prm['halo_sedang']}', - '{$prm['halo_sempit']}', - '{$prm['tanpa_halo']}', - '{$prm['dfi']}', - '{$prm['kesimpulan']}', - '{$prm['catatan']}', - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } else { - $sql = "UPDATE other_dnafragmentasi SET - Other_DnaFragmentasiT_OrderDetailID = {$orderdetail_id}, - Other_DnaFragmentasiM_DoctorID = {$doctor_id}, - Other_DnaFragmentasiOther_DnaFragmentasiMethodeID = '{$methode_id}', - Other_DnaFragmentasiHaloLuas = '{$prm['halo_luas']}', - Other_DnaFragmentasiHaloSedang = '{$prm['halo_sedang']}', - Other_DnaFragmentasiHaloSempit = '{$prm['halo_sempit']}', - Other_DnaFragmentasiTanpaHalo = '{$prm['tanpa_halo']}', - Other_DnaFragmentasiDFI = '{$prm['dfi']}', - Other_DnaFragmentasiKesimpulan = '{$prm['kesimpulan']}', - Other_DnaFragmentasiCatatan = '{$prm['catatan']}', - Other_DnaFragmentasiLastUpdated = NOW(), - Other_DnaFragmentasiUserID = {$userid} - WHERE - Other_DnaFragmentasiID = {$prm['xid']}"; - //echo $sql; - $this->db_smartone->query($sql); - } - - - $result = array("total" => 1, "records" => array(), "sql" => ''); - $this->sys_ok($result); - exit; - } -} +db_smartone = $this->load->database("onedev", true); + $this->db_lab = $this->load->database('one_lab_log', TRUE); + $this->load->helper(array('form', 'url')); + } + function getMethodeID($natTestID) + { + $sql = "select M_MethodePriorityNat_MethodeID MethodeID, Nat_MethodeName + from + m_methode_priority + join nat_methode on Nat_MethodeID = M_MethodePriorityNat_MethodeID + and Nat_MethodeIsActive = 'Y' + join m_instrumentmethode on M_InstrumentMethodeNat_MethodeID = Nat_MethodeID and M_InstrumentMethodeIsActive = 'Y' + join nat_instrument on M_InstrumentMethodeNat_InstrumentID = Nat_InstrumentID + and Nat_InstrumentIsActive ='Y' + where M_MethodePriorityIsActive = 'Y' + and M_MethodePriorityNat_TestID = $natTestID + and M_MethodePriorityM_DayOfWeekID = dayofweek(now()) + order by M_MethodePriorityNumber desc + limit 0,1 "; + $qry = $this->db->query($sql); + if ($qry) { + $rows = $qry->result_array(); + if (count($rows) > 0) return array($rows[0]["MethodeID"], $rows[0]["Nat_MethodeName"]); + } + //2nd + $sql = "select + M_InstrumentMethodeNat_MethodeID MethodeID, Nat_MethodeName + from m_instrumentmethode + join nat_methode on M_InstrumentMethodeNat_MethodeID = Nat_MethodeID + and Nat_MethodeIsActive = 'Y' + join nat_instrument on M_InstrumentMethodeNat_InstrumentID = Nat_InstrumentID + and Nat_InstrumentIsActive ='Y' + where M_InstrumentMethodeNat_TestID = $natTestID + and M_InstrumentMethodeIsActive = 'Y' + order by M_InstrumentMethodePriority desc + limit 0,1"; + $qry = $this->db->query($sql); + if ($qry) { + $rows = $qry->result_array(); + if (count($rows) > 0) return array($rows[0]["MethodeID"], $rows[0]["Nat_MethodeName"]); + } + // + $sql = "select Nat_NormalValueNat_MethodeID MethodeID, Nat_MethodeName + from + nat_normalvalue + join nat_methode on Nat_NormalValueNat_MethodeID = Nat_MethodeID + and Nat_MethodeIsActive = 'Y' + where Nat_NormalValueNat_TestID = $natTestID + and Nat_NormalValueIsActive = 'Y' + order by Nat_NormalValueID + limit 0,1"; + $qry = $this->db->query($sql); + if ($qry) { + $rows = $qry->result_array(); + if (count($rows) > 0) return array($rows[0]["MethodeID"], $rows[0]["Nat_MethodeName"]); + } + return array(0, ""); + } + function get_normal_value($methodeID, $natTestID, $sexID, $ageInDay) + { + $this->load->library('ibl_sampling_normal'); + return $this->ibl_sampling_normal->get_normal_value_id($methodeID, $natTestID, $sexID, $ageInDay); + } + return 0; + } + function fn_fix_normal($order_id) + { + $sql = "select + T_OrderDetailID, M_PatientM_SexID, fn_global_age_count_day(M_PatientDOB, date(T_OrderHeaderDate)) Dob , + T_TestNat_TestID + from t_orderheader + join m_patient on T_OrderHeaderID = $order_id and T_OrderHeaderM_PatientID = M_PatientID + join t_orderdetail on T_OrderDetailT_OrderHeaderID = T_OrderHeaderID + and T_OrderDetailIsACtive = 'Y' + and ( T_OrderDetailNat_NormalValueID is null or T_OrderDetailNat_NormalValueID = 0 ) + join t_test on T_OrderDetailT_TestID = T_TestID and T_TestIsResult = 'Y' "; + $qry = $this->db->query($sql); + if (! $qry) { + return; + } + $rows = $qry->result_array(); + if (count($rows) == 0) return; + $sql_u = "update t_orderdetail + join nat_normalvalue on T_OrderDetailID = ? and Nat_NormalValueID = ? + set + T_OrderDetailNat_NormalValueID = Nat_NormalValueID, + T_OrderDetailNormalValueNote = Nat_NormalValueNote, + T_OrderDetailNormalValueDescription = Nat_NormalValueDescription, + T_OrderDetailMinValue = Nat_NormalValueMinValue, + T_OrderDetailMaxValue = Nat_NormalValueMaxValue, + T_OrderDetailMinValueInclusive = Nat_NormalValueMinValueInclusive, + T_OrderDetailMaxValueInclusive = Nat_NormalValueMaxValueInclusive, + T_OrderDetailNat_MethodeID = ?, + T_OrderdetailNat_MethodeName =?"; + + foreach ($rows as $r) { + $T_OrderDetailID = $r["T_OrderDetailID"]; + $sexID = $r["M_PatientM_SexID"]; + $ageInDay = $r["Dob"]; + $natTestID = $r["T_TestNat_TestID"]; + list($methodeID, $methodeName) = $this->getMethodeID($natTestID); + if ($methodeID == 0) continue; + $normalValueID = $this->get_normal_value($methodeID, $natTestID, $sexID, $ageInDay); + if ($normalValueID == 0) return; + $this->db->query($sql_u, array($T_OrderDetailID, $normalValueID, $methodeID, $methodeName)); + } + } + function update_order_sample($targetID, $sourceID) + { + $sql = "update t_ordersample target + join t_ordersample source on + target.T_OrderSampleID = ? + and target.T_OrderSampleWorklistReceive = 'N' + and source.T_OrderSampleID = ? + set + target.T_OrderSampleSampling = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSampling, source.T_OrderSampleSampling), + target.T_OrderSampleSamplingDate = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingDate, source.T_OrderSampleSamplingDate), + target.T_OrderSampleSamplingTime = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingTime, source.T_OrderSampleSamplingTime), + target.T_OrderSampleSamplingUserID = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingUserID, source.T_OrderSampleSamplingUserID), + + target.T_OrderSampleReceive = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceive, source.T_OrderSampleReceive), + target.T_OrderSampleReceiveDate = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveDate, source.T_OrderSampleReceiveDate), + target.T_OrderSampleReceiveTime = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveTime, source.T_OrderSampleReceiveTime), + target.T_OrderSampleReceiveUserID = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveUserID, source.T_OrderSampleReceiveUserID), + + target.T_OrderSampleVerification = if(target.T_OrderSampleVerification='Y',target.T_OrderSampleVerification, source.T_OrderSampleVerification), + target.T_OrderSampleVerificationDate =if(target.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationDate, source.T_OrderSampleVerificationDate), + target.T_OrderSampleVerificationTime =if(source.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationTime, source.T_OrderSampleVerificationTime), + target.T_OrderSampleVerificationUserID =if(source.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationUserID, source.T_OrderSampleVerificationUserID), + + target.T_OrderSampleProcessing = if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessing, source.T_OrderSampleProcessing), + target.T_OrderSampleProcessingDate= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingDate, source.T_OrderSampleProcessingDate), + target.T_OrderSampleProcessingTime= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingTime, source.T_OrderSampleProcessingTime), + target.T_OrderSampleProcessingUserID= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingUserID, source.T_OrderSampleProcessingUserID), + + target.T_OrderSampleReceiveHandling =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandling, source.T_OrderSampleReceiveHandling ), + target.T_OrderSampleReceiveHandlingDate =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingDate, source.T_OrderSampleReceiveHandlingDate), + target.T_OrderSampleReceiveHandlingTime =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingTime, source.T_OrderSampleReceiveHandlingTime), + target.T_OrderSampleReceiveHandlingUserID =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingUserID, source.T_OrderSampleReceiveHandlingUserID), + + target.T_OrderSampleHandling = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandling, source.T_OrderSampleHandling), + target.T_OrderSampleHandlingDate = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingDate, source.T_OrderSampleHandlingDate), + target.T_OrderSampleHandlingTime = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingTime, source.T_OrderSampleHandlingTime), + target.T_OrderSampleHandlingUserID = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingUserID, source.T_OrderSampleHandlingUserID), + + target.T_OrderSampleWorklistReceive = source.T_OrderSampleWorklistReceive, + target.T_OrderSampleWorklistReceiveDatetime = source.T_OrderSampleWorklistReceiveDateTime, + target.T_OrderSampleWorklistReceiveUserID = source.T_OrderSampleWorklistReceiveUserID + "; + $qry = $this->db->query($sql, array($targetID, $sourceID)); + if (! $qry) { + echo json_encode(array("status" => "ERR", "message" => print_r($this->db->error(), true))); + exit; + } + } + function fix_sample_serum($headerID) + { + //cari t_ordersample yg belum worklist receive dengan code 017% + $sql = "select T_OrderSampleID + from t_ordersample + join t_sampletype on + T_OrderSampleT_OrderHeaderID = ? + and T_OrderSampleWorklistReceive = 'N' + and T_OrderSampleIsActive = 'Y' + and T_OrderSampleT_SampleTypeID = T_SampletypeID + and T_SampleTypeCode like '017%' + "; + $qry = $this->db->query($sql, array($headerID)); + if (!$qry) { + echo json_encode(array("status" => "ERR", "message" => print_r($this->db->error(), true))); + exit; + } + $rows = $qry->result_array(); + if (count($rows) == 0) return; + //cari T_OrderSample yang sudah di receive yg terakhir + $sql = "select T_OrderSampleID + from t_ordersample + join t_sampletype on + T_OrderSampleT_OrderHeaderID = ? + and T_OrderSampleWorklistReceive = 'Y' + and T_OrderSampleIsActive = 'Y' + and T_OrderSampleT_SampleTypeID = T_SampletypeID + and T_SampleTypeCode like '017%' + order by T_OrderSampleWorklistReceiveDatetime desc + limit 0,1 + "; + $qry = $this->db->query($sql, array($headerID)); + if (!$qry) { + echo json_encode(array("status" => "ERR", "message" => print_r($this->db->error(), true))); + exit; + } + $rcv_rows = $qry->result_array(); + if (count($rcv_rows) == 0) return; + + //print_r($rows); + //print_r($rcv_rows); + $rcv_T_OrderSampleID = $rcv_rows[0]["T_OrderSampleID"]; + //ada yg belum di receive + foreach ($rows as $r) { + $T_OrderSampleID = $r["T_OrderSampleID"]; + $this->update_order_sample($T_OrderSampleID, $rcv_T_OrderSampleID); + } + } + public function search() + { + $prm = $this->sys_input; + $max_rst = 99; + + $id = $prm["order_id"]; + if ($id > 0) { + $this->fix_sample_serum($id); + $this->fn_fix_normal($id); + } + $lang = $this->lang_default_code; + $lang_id = isset($prm['lang_id']) ? $prm['lang_id'] : '0'; + + if ($lang_id != 0) { + $l = $this->db_smartone->where("Nat_LangID", $lang_id)->get("nat_lang")->row(); + $lang = $l->Nat_LangCode; + } + + //tambahan fajri + $sql = " UPDATE t_orderdetail + JOIN t_test ON T_OrderDetailT_TestID = T_TestID + SET T_OrderDetailT_TestIsResult = T_TestIsResult + WHERE + T_OrderDetailT_OrderHeaderID = {$id} AND + T_OrderDetailT_TestIsResult = '' AND + T_OrderDetailIsActive = 'Y'"; + $this->db_smartone->query($sql); + + $tot_count = 0; + $lq = ""; + $group_id = 0; + if (isset($prm['group_id'])) + $group_id = $prm['group_id']; + + if ($group_id != 0) { + $sql = "select distinct T_WorklistDetailNat_TestID Nat_TestID + from t_worklistdetailv2 + where T_WorklistDetailT_WorklistID = {$group_id}"; + $qry = $this->db_smartone->query($sql); + $rows = $qry->result_array(); + $nat_test_ids = "0"; + foreach ($rows as $r) { + $nat_test_ids .= ", " . $r["Nat_TestID"]; + } + $q_group = " ( $nat_test_ids ) "; + + $sql = " + SELECT a1.*, cOUNT(a2.T_OrderDetailID) level + FROM ( + SELECT IFNULL(y.T_OrderDetailT_TestID, x.T_OrderDetailT_TestID) t_testid, + IFNULL(y.T_OrderDetailT_TestName, y.T_OrderDetailT_TestName) t_testname, + y.T_OrderDetailResult result, y.T_OrderDetailResult result_old, y.T_OrderDetailNote note, y.T_OrderDetailNote note_old, + y.T_OrderDetailID id, + y.T_OrderDetailT_TestIsResult is_result, a.T_TestIsQuantitative is_quantitative, + y.T_OrderDetailResultFlag result_flag, + y.T_OrderDetailNat_NormalValueID normal_id, + y.T_OrderDetailNormalValueNote normal_note, y.T_OrderDetailNat_UnitName unit_name, + y.T_OrderdetailNat_MethodeID methode_id, y.T_OrderdetailNat_MethodeName methode_name, + a.T_TestNat_TestID nattest_id, a.T_TestID tx_id, count(T_ResultInstrumentID) as result_instrument_n, + y.T_OrderDetailVerification, T_OrderSampleReceive sample_receive, + T_OrderSampleProcessing sample_processing, T_OrderSampleWorklistReceive sample_worklist_receive, + IF(T_OrderDetailAddOnPreAnalytic = 'Y', T_OrderDetailAddOnPreAnalytic, PreAnalyticIsOk) pre_analytic, + T_OrderDetailAddOnPreAnalytic, + T_OrderHeaderID order_id, y.T_OrderDetailT_TestSasCode test_sas_code, + tx.T_TestSasCode, + T_OrderDetailAddOnResample `resample`, T_OrderDetailAddOnResampleStatus resample_status, + T_OrderDetailAddOnRef ref, y.T_OrderDetailVerification verification, y.T_OrderDetailValidation validation, + T_OrderPromiseDateTime, Group_ResultName as ResultGroupName + FROM t_orderdetail x + left join t_orderpromise on x.T_OrderDetailT_OrderPromiseID = T_OrderPromiseID + JOIN t_test tx ON x.T_OrderDetailT_TestID = T_TestID + JOIN t_test tcheck on tcheck.T_TestNat_TestID in {$q_group} + and ( tx.T_TestID = tcheck.T_TestID or tx.T_TestSasCode like concat(tcheck.T_TestSasCode,'%')) + JOIN group_resultdetail ON Group_ResultDetailT_TestID = x.T_OrderDetailT_TestID AND Group_ResultDetailIsActive = 'Y' + JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND Group_ResultResumeMcu = 'LAB' + LEFT JOIN t_orderdetail y ON x.T_OrderDetailT_TestSasCode LIKE CONCAT(y.T_OrderDetailT_TestSasCode, '%') + AND x.T_OrderDetailT_OrderHeaderID = y.T_OrderDetailT_OrderHeaderID + AND y.T_OrderDetailIsActive = 'Y' + LEFT JOIN t_orderdetailaddon ON x.T_OrderDetailID = T_OrderDetailAddOnT_OrderDetailID + JOIN t_orderheader ON y.T_OrderDetailT_OrderHeaderID = T_OrderHeaderID + LEFT JOIN t_test a ON y.T_OrderDetailT_TestID = a.T_TestID + AND a.T_TestIsNonLab = '' + LEFT JOIN (SELECT T_OrderSampleT_SampleTypeID, T_OrderSampleReceive, T_OrderSampleProcessing, T_OrderSampleWorklistReceive + FROM t_ordersample WHERE T_OrderSampleT_OrderHeaderID = {$id} + AND T_OrderSampleIsactive = 'Y' + GROUP BY T_OrderSampleT_SampleTypeID) os ON a.T_TestT_SampleTypeID = os.T_OrderSampleT_SampleTypeID + or os.T_OrderSampleT_SampleTypeID = fn_sampletype_from_local(a.T_TestNat_TestID) + + LEFT JOIN t_resultinstrument ON T_ResultInstrumentT_OrderDetailID = x.T_OrderDetailID + LEFT JOIN pre_analytic ON PreAnalyticNat_TestID = a.T_TestNat_TestID AND PreAnalyticDate = date(now()) and PreAnalyticIsActive = 'Y' + WHERE x.T_OrderDetailT_OrderHeaderID = {$id} + AND x.T_OrderDetailIsActive = 'Y' + GROUP BY y.T_OrderDetailT_TestID + ORDER BY y.T_OrderDetailT_TestSasCode ASC + ) a1 + + LEFT JOIN t_orderdetail a2 ON a2.T_OrderDetailT_OrderHeaderID = a1.order_id + AND a2.T_OrderDetailIsActive = 'Y' + AND a1.test_sas_code LIKE CONCAT(a2.T_OrderDetailT_testSasCode, '%') + GROUP BY a1.t_testid + order by a1.test_sas_code +"; + $query = $this->db_smartone->query($sql); + $lq = $this->db_smartone->last_query(); + } else { + $sql = " + SELECT a1.*, cOUNT(a2.T_OrderDetailID) level + FROM ( + SELECT IFNULL(y.T_OrderDetailT_TestID, x.T_OrderDetailT_TestID) t_testid, + IFNULL(y.T_OrderDetailT_TestName, y.T_OrderDetailT_TestName) t_testname, + y.T_OrderDetailResult result, y.T_OrderDetailResult result_old, y.T_OrderDetailNote note, y.T_OrderDetailNote note_old, + y.T_OrderDetailID id, + y.T_OrderDetailT_TestIsResult is_result, a.T_TestIsQuantitative is_quantitative, + y.T_OrderDetailResultFlag result_flag, + y.T_OrderDetailNat_NormalValueID normal_id, + y.T_OrderDetailNormalValueNote normal_note, y.T_OrderDetailNat_UnitName unit_name, + y.T_OrderdetailNat_MethodeID methode_id, y.T_OrderdetailNat_MethodeName methode_name, + a.T_TestNat_TestID nattest_id, a.T_TestID tx_id, count(T_ResultInstrumentID) as result_instrument_n, + y.T_OrderDetailVerification, T_OrderSampleReceive sample_receive, + T_OrderSampleProcessing sample_processing, T_OrderSampleWorklistReceive sample_worklist_receive, + IF(T_OrderDetailAddOnPreAnalytic = 'Y', T_OrderDetailAddOnPreAnalytic, PreAnalyticIsOk) pre_analytic, + T_OrderDetailAddOnPreAnalytic, + T_OrderHeaderID order_id, y.T_OrderDetailT_TestSasCode test_sas_code, + tx.T_TestSasCode, + T_OrderDetailAddOnResample `resample`, T_OrderDetailAddOnResampleStatus resample_status, + T_OrderDetailAddOnRef ref, y.T_OrderDetailVerification verification, y.T_OrderDetailValidation validation, + T_OrderPromiseDateTime , Group_ResultName as ResultGroupName + FROM t_orderdetail x + left join t_orderpromise on x.T_OrderDetailT_OrderPromiseID = T_OrderPromiseID + JOIN t_test tx ON x.T_OrderDetailT_TestID = T_TestID + JOIN group_resultdetail ON Group_ResultDetailT_TestID = x.T_OrderDetailT_TestID AND Group_ResultDetailIsActive = 'Y' + JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND Group_ResultResumeMcu = 'LAB' + LEFT JOIN t_orderdetail y ON x.T_OrderDetailT_TestSasCode LIKE CONCAT(y.T_OrderDetailT_TestSasCode, '%') + AND x.T_OrderDetailT_OrderHeaderID = y.T_OrderDetailT_OrderHeaderID + AND y.T_OrderDetailIsActive = 'Y' + + LEFT JOIN t_orderdetailaddon ON x.T_OrderDetailID = T_OrderDetailAddOnT_OrderDetailID + + JOIN t_orderheader ON y.T_OrderDetailT_OrderHeaderID = T_OrderHeaderID + LEFT JOIN t_test a ON y.T_OrderDetailT_TestID = a.T_TestID + AND a.T_TestIsNonLab = '' + LEFT JOIN (SELECT T_OrderSampleT_SampleTypeID, T_OrderSampleReceive, T_OrderSampleProcessing, T_OrderSampleWorklistReceive + FROM t_ordersample WHERE T_OrderSampleT_OrderHeaderID = {$id} + AND T_OrderSampleIsactive = 'Y' + GROUP BY T_OrderSampleT_SampleTypeID) os ON a.T_TestT_SampleTypeID = os.T_OrderSampleT_SampleTypeID + or os.T_OrderSampleT_SampleTypeID = fn_sampletype_from_local(a.T_TestNat_TestID) + + LEFT JOIN t_resultinstrument ON T_ResultInstrumentT_OrderDetailID = x.T_OrderDetailID + LEFT JOIN pre_analytic ON PreAnalyticNat_TestID = a.T_TestNat_TestID AND PreAnalyticDate = date(now()) and PreAnalyticIsActive = 'Y' + WHERE x.T_OrderDetailT_OrderHeaderID = {$id} + AND x.T_OrderDetailIsActive = 'Y' + GROUP BY y.T_OrderDetailT_TestID + ORDER BY y.T_OrderDetailT_TestSasCode ASC + ) a1 + + LEFT JOIN t_orderdetail a2 ON a2.T_OrderDetailT_OrderHeaderID = a1.order_id + AND a2.T_OrderDetailIsActive = 'Y' + AND a1.test_sas_code LIKE CONCAT(a2.T_OrderDetailT_testSasCode, '%') + GROUP BY a1.t_testid + order by a1.test_sas_code +"; + //echo $sql; + $query = $this->db_smartone->query($sql); + $lq = $this->db_smartone->last_query(); + } + // file_put_contents("/xtmp/re-query.sql",$lq); + + if ($query) { + $rst = []; + $rows = $query->result_array(); + + foreach ($rows as $k => $v) { + + if ($v['is_result'] == "Y" && $v['is_quantitative'] == "N") { + $v['template'] = []; + $x = $this->db_smartone->query("CALL sp_master_resulttemplate_get('{$v['t_testid']}')"); + $this->clean_mysqli_connection($this->db_smartone->conn_id); + if ($x) + $v['template'] = $x->result_array(); + } + + // IF Rujukan, by pas Pre Analytik + if ($v['ref'] == 'Y') + $v['pre_analytic'] = 'Y'; + if ($v["id"] == "885455") { + //sipe workaround + //$v["sample_receive"] = "Y"; + $v["sample_worklist_receive"] = "Y"; + } + $rst[] = $v; + } + + $result = array("total" => $tot_count, "records" => $rst, "total_display" => sizeof($rows), "q" => $lq); + $this->sys_ok($result); + } else { + $this->sys_error_db("RE Px rows", $this->db_smartone); + exit; + } + } + + public function save() + { + $prm = $this->sys_input; + $data = json_decode($prm["data"]); + $lang = $this->lang_default_code; + $lang_id = isset($prm['lang_id']) ? $prm['lang_id'] : '0'; + + if ($lang_id != 0) { + $l = $this->db_smartone->where("Nat_LangID", $lang_id)->get("nat_lang")->row(); + $lang = $l->Nat_LangCode; + } + + $sql_norm = "select T_OrderDetailMinValue, T_OrderDetailMaxValue, + T_OrderDetailMinValueInclusive, T_OrderDetailMaxValueInclusive, + Nat_TestFlagLow, Nat_TestFlagHigh + from t_orderdetail + join t_test on T_OrderDetailT_TestID = T_TestID + join nat_test on T_TestNat_TestID = Nat_TestID and T_TestIsActive = 'Y' + where T_OrderDetailID = ? "; + + $ids = []; + foreach ($data as $k => $v) { + if ($v->resultInstrumentID > 0) { + $sql_i = "select T_ResultInstrumentNat_NormalValueID normalValueID + from t_resultinstrument + where T_ResultInstrumentID = ?"; + $qry_i = $this->db_smartone->query($sql_i, array($v->resultInstrumentID)); + if ($qry_i) { + $rows_i = $qry_i->result_array(); + + if (count($rows_i) > 0) { + $sql_iu = "update t_orderdetail, nat_normalvalue , nat_methode + set T_OrderDetailMinValue = Nat_NormalValueMinValue, + T_OrderDetailMinValueInclusive = Nat_NormalValueMinValueInclusive, + T_OrderDetailMaxValue = Nat_NormalValueMaxValue , + T_OrderDetailMaxValueInclusive = Nat_NormalValueMaxValueInclusive, + T_OrderDetailNormalValueNote = Nat_NormalValueNote, + T_OrderDetailNormalValueDescription = Nat_NormalValueDescription, + T_OrderDetailNat_NormalValueID = Nat_NormalValueID, + T_OrderDetailNat_MethodeID = Nat_NormalValueNat_MethodeID, + T_OrderDetailNat_MethodeName = Nat_MethodeName + where T_OrderDetailID = ? and Nat_NormalValueID = ? + and Nat_NormalValueNat_MethodeID = Nat_MethodeID + "; + $this->db_smartone->query($sql_iu, array($v->id, $rows_i[0]["normalValueID"])); + //file_put_contents("/xtmp/update-nilai-normal", $this->db_smartone->last_query() . "\n", FILE_APPEND); + } + } + } + $y = $this->db_smartone->query("SELECT fn_process_sample_handling_perfect('{$v->order_id}', '{$v->test_id}') c") + ->row(); + $req_status = $y->c; + $qry_norm = $this->db_smartone->query($sql_norm, $v->id); + $result_flag = ""; + if ($qry_norm) { + $rows_norm = $qry_norm->result_array(); + if (count($rows_norm) > 0) { + $r = $rows_norm[0]; + if (is_numeric($v->result)) { + + if ($r["T_OrderDetailMinValueInclusive"] == "Y" && $v->result < $r["T_OrderDetailMinValue"]) { + $result_flag = $r["Nat_TestFlagLow"]; + } + if ($r["T_OrderDetailMinValueInclusive"] == "N" && $v->result <= $r["T_OrderDetailMinValue"]) { + $result_flag = $r["Nat_TestFlagLow"]; + } + if ($r["T_OrderDetailMaxValueInclusive"] == "Y" && $v->result > $r["T_OrderDetailMaxValue"]) { + $result_flag = $r["Nat_TestFlagHigh"]; + } + if ($r["T_OrderDetailMaxValueInclusive"] == "N" && $v->result >= $r["T_OrderDetailMaxValue"]) { + $result_flag = $r["Nat_TestFlagHigh"]; + } + } + } + } + if ($lang == $this->lang_default_code) { + $this->db_smartone->set('T_OrderDetailResult', $v->result) + ->set('T_OrderDetailResultFlag', $result_flag) + ->set('T_OrderDetailNote', $v->note) + ->set('T_OrderDetailReqStatus', $req_status) + ->where('T_OrderDetailID', $v->id) + ->update('t_orderdetail'); + } else { + $this->db_smartone->set('T_OrderDetailLangResult', $v->result) + ->set('T_OrderDetailLangNote', $v->note) + ->where('T_OrderDetailLangID', $v->id) + ->update('t_orderdetaillang'); + } + + + + $ids[] = $v->id; + + //log detail + + $sql = "SELECT COUNT(*) n FROM log_orderdetail WHERE Log_OrderDetailT_OrderDetailID = ? AND Log_OrderDetailResult = ? ORDER BY Log_OrderDetailID DESC LIMIT 1"; + $qry = $this->db_lab->query($sql, [$v->id, $v->result]); + if ($qry) { + $n = $qry->row(); + + if ($n->n == 0) { + $sql = "SELECT * FROM t_orderdetail WHERE T_OrderDetailID = ?"; + $qry_order = $this->db_smartone->query($sql, [$v->id]); + $dt_orderdetail = $qry_order->row(); + $dt_detail_log = json_encode($dt_orderdetail); + + $sql = "INSERT INTO log_orderdetail ( + Log_OrderDetailStatus, + Log_OrderDetailT_OrderDetailID, + Log_OrderDetailResult, + Log_OrderDetailJSON, + Log_OrderDetailCreated, + Log_OrderDetailUserID + ) + VALUES (?,?, ?, ?, NOW(), ?)"; + $this->db_lab->query($sql, ['RESULTENTRY',$v->id, $v->result, $dt_detail_log, $this->sys_user['M_UserID']]); + //echo $this->db_lab->last_query(); + //exit(); + } + } + } + + // LOG Process + $order = $this->db_smartone->select('T_OrderDetailT_OrderHeaderID id, T_OrderHeaderLabNumber lab_number', false) + ->join('t_orderheader', 'T_OrderHeaderID = T_OrderDetailT_OrderHeaderID') + ->where('T_OrderDetailID', $data[0]->id) + ->get('t_orderdetail') + ->row(); + + $dblog = $this->db_lab; + $dblog->set('Log_ProcessCode', 'PROCESS.Result.Entry') + ->set('Log_ProcessOrderID', $order->id) + ->set('Log_ProcessOrderNumber', $order->lab_number) + ->set('Log_ProcessJson', json_encode($data)) + ->set('Log_ProcessUserID', $this->sys_user['M_UserID']) + ->insert('log_process'); + // END OF Log Process + //auto calculation + $this->load->library("Resultcalc"); + $rows = $this->resultcalc->auto($order->id); + + try { + foreach ($ids as $id) { + $this->db_smartone->query("call sp_set_normal_value_flag($id)"); + $this->clean_mysqli_connection($this->db_smartone->conn_id); + } + } catch (Exception $e) { + } + + $this->sys_ok($ids); + } + + public function save_template() + { + $prm = $this->sys_input; + + $n = $this->db_smartone->select("COUNT(T_ResultTemplateID) n") + ->where("T_ResultTemplateT_TestID", $prm['test_id']) + ->where("T_ResultTemplateIsActive", "Y") + ->where("T_ResultTemplateValue", $prm['value']) + ->get('t_resulttemplate') + ->row(); + if ($n->n > 0) { + $this->sys_error_db("Insert Result Template", $this->db_smartone); + return; + } + + $r = $this->db_smartone->set("T_ResultTemplateT_TestID", $prm['test_id']) + ->set("T_ResultTemplateValue", $prm['value']) + ->insert('t_resulttemplate'); + if ($r) { + $template = []; + $x = $this->db_smartone->query("CALL sp_master_resulttemplate_get('{$prm['test_id']}')"); + $this->clean_mysqli_connection($this->db_smartone->conn_id); + if ($x) + $template = $x->result_array(); + + $this->sys_ok($template); + } + } + + public function export() + { + $prm = $this->sys_input; + + $sql = "CALL sp_process_result_lang(?, ?, ?, ?)"; + $query = $this->db_smartone->query($sql, [$prm['order_id'], $prm['lang_id'], $prm['is_si'], $this->sys_user['M_UserID']]); + if ($query) { + $r = $query->row(); + if ($r->status == "OK") { + $this->sys_ok($r->data); + return; + } + + $this->sys_error_db("Message : " . $r->message, $this->db_smartone); + } else { + $this->sys_error_db("Lang Result", $this->db_smartone); + return; + } + } + + public function search_group() + { + $prm = $this->sys_input; + $max_rst = 100; + + // QUERY TOTAL + $sql = "select count(*) total + from t_worklist + where T_WorklistIsActive = 'Y' + order by T_WorklistName ASC"; + $query = $this->db_smartone->query($sql); + + if ($query) { + $tot_count = $query->result_array()[0]["total"]; + } else { + $this->sys_error_db("worklist count", $this->db_smartone); + exit; + } + + $sql = "select T_WorklistID group_id, T_WorklistName group_name + from t_worklist + where T_WorklistIsActive = 'Y' + order by T_WorklistName ASC + limit 0, {$max_rst}"; + $query = $this->db_smartone->query($sql); + + if ($query) { + $rows = $query->result_array(); + foreach ($rows as $k => $v) + $rows[$k]['data'] = json_decode($v['data']); + $result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows), "q" => $this->db_smartone->last_query()); + $this->sys_ok($result); + } else { + $this->sys_error_db("worklist rows", $this->db_smartone); + exit; + } + } + + public function search_rerun() + { + $prm = $this->sys_input; + $id = $prm["detail_id"]; + + $sql = "CALL sp_process_result_rerun(?)"; + $query = $this->db_smartone->query($sql, [$id]); + + if ($query) { + $rows = $query->result_array(); + $this->sys_ok(["records" => $rows]); + } else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + + + function getdoctorsfna() + { + $prm = $this->sys_input; + // $id = $prm["id"]; + + $sql = " SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY M_DoctorName ASC"; + //echo $sql; + $query = $this->db_smartone->query($sql); + + if ($query) { + $rows = $query->result_array(); + $this->sys_ok(["records" => $rows]); + } else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + function getfnaresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT Other_FNADetailsID as xid, + Other_FNAT_OrderDetailID as orderdetail_id, + Other_FNADetailsCode as code, + Other_FNADetailsLabel as label, + Other_FNADetailsResult as result, + IFNULL(Other_FNAM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_FNAM_DoctorID) OR Other_FNAM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_fna + JOIN other_fnadetails ON Other_FNADetailsOther_FNAID = Other_FNAID AND Other_FNADetailsIsActive = 'Y' + LEFT JOIN m_doctor ON Other_FNAM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_FNAT_OrderDetailID = {$id} AND Other_FNAIsActive = 'Y' + GROUP BY Other_FNADetailsID + ORDER BY Other_FNADetailsCode ASC"; + $query = $this->db_smartone->query($sql); + + if ($query) { + $rows = $query->result_array(); + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $images = array(); + $sql = "SELECT So_ImageUploadID as xid, + CONCAT('/one-media/one-image-nonlab/',So_ImageUploadNewName) as image_url + FROM t_orderdetail + JOIN so_imageupload ON So_ImageUploadT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND + So_ImageUploadIsActive = 'Y' + WHERE + T_OrderDetailID = {$id} AND + T_OrderDetailIsActive = 'Y' + GROUP BY So_ImageUploadID"; + $images = $this->db_smartone->query($sql)->result_array(); + + $rst = array('doctors' => $doctors, 'results' => $rows, 'images' => $images); + $this->sys_ok(["records" => $rst]); + } else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + function getpatologianatomyresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT Other_PatologiAnatomyID as xid, + Other_PatologiAnatomyT_OrderDetailID as orderdetail_id, + Other_PatologiAnatomyNoSediaan as no_sediaan, + Other_PatologiAnatomyDiagnosaKlinis as diagnosa, + Other_PatologiAnatomyKeteranganKlinis as klinis, + Other_PatologiAnatomyLokasiOrgan as lokasi, + Other_PatologiAnatomyMakroskopik as makroskopik, + Other_PatologiAnatomyMikroskopik as mikroskopik, + Other_PatologiAnatomyKesimpulan as kesimpulan, + IFNULL(Other_PatologiAnatomyM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_PatologiAnatomyM_DoctorID) OR Other_PatologiAnatomyM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_patologi_anatomy + LEFT JOIN m_doctor ON Other_PatologiAnatomyM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_PatologiAnatomyT_OrderDetailID = {$id} AND Other_PatologiAnatomyIsActive = 'Y' + GROUP BY Other_PatologiAnatomyID + ORDER BY Other_PatologiAnatomyID ASC + LIMIT 1"; + $query = $this->db_smartone->query($sql); + + if ($query) { + $rows = $query->row_array(); + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + + $sql = "SELECT So_ImageUploadPatologyAnatomyID as xid, + CONCAT('/one-media/one-image-nonlab/',So_ImageUploadPatologyAnatomyNewName) as image_url, + So_ImageUploadPatologyAnatomyType as type + FROM t_orderdetail + JOIN so_imageupload_patology_anatomy ON So_ImageUploadPatologyAnatomyT_OrderHeaderID= T_OrderDetailT_OrderHeaderID AND + So_ImageUploadPatologyAnatomyIsActive= 'Y' + WHERE + T_OrderDetailID = {$id} AND + T_OrderDetailIsActive = 'Y' + GROUP BY So_ImageUploadPatologyAnatomyID"; + $images = $this->db_smartone->query($sql)->result_array(); + $mikro = []; + $makro = []; + + foreach ($images as $key => $value) { + + if ($value['type'] == 'mikro') { + $mikro[] = $value; + } + if ($value['type'] == 'makro') { + $makro[] = $value; + } + } + + $rst = array('doctors' => $doctors, 'result' => $rows, "mikro" => $mikro, "makro" => $makro); + $this->sys_ok(["records" => $rst]); + } else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + + + + function uploadimage() + { + if (! $this->isLogin) { + $this->sys_error("Invalid Token"); + exit; + } + + $userid = $this->sys_user["M_UserID"]; + $data = []; + //print_r($_SERVER); + + $prm = $this->sys_input; + $orderid = $this->input->post('orderid'); + $labnumber = $this->input->post('labnumber'); + $sql = "UPDATE so_imageupload SET + So_ImageUploadIsActive = 'N', + So_ImageUploadUserID = {$userid} + WHERE + So_ImageUploadT_OrderHeaderID = {$orderid}"; + //echo $sql; + $this->db_onedev->query($sql); + //$config['upload_path'] = 'assets/'; + + $path = '/home/one/project/one/one-media/one-image-nonlab/'; + //echo $path; + $config['upload_path'] = $path; + $config['allowed_types'] = 'jpg|jpeg|png|gif'; + + $config['max_size'] = '10000'; + $count = count($_FILES['files']['name']); + //echo $count; + $this->load->library('upload', $config); + + $error = []; + for ($i = 0; $i < $count; $i++) { + + + if (!empty($_FILES['files']['name'][$i])) { + + + + $_FILES['file']['name'] = $_FILES['files']['name'][$i]; + + $_FILES['file']['type'] = $_FILES['files']['type'][$i]; + + $_FILES['file']['tmp_name'] = $_FILES['files']['tmp_name'][$i]; + + $_FILES['file']['error'] = $_FILES['files']['error'][$i]; + + $_FILES['file']['size'] = $_FILES['files']['size'][$i]; + + + + $namex = $orderid . '-' . $labnumber . '-' . $this->generateRandomString(5); + //echo $namex; + + $config['file_name'] = $namex; + $this->upload->initialize($config); + //echo $config['file_name'] ; + + + + + + if ($this->upload->do_upload('file')) { + + $uploadData = $this->upload->data(); + + $filename = $uploadData['file_name']; + //echo $filename; + + + $sql = "INSERT INTO so_imageupload ( + So_ImageUploadT_OrderHeaderID, + So_ImageUploadT_OrderHeaderLabNumber, + So_ImageUploadT_SampleTypeID, + So_ImageUploadOldName, + So_ImageUploadNewName, + So_ImageUploadCreated, + So_ImageUploadUserID + ) + VALUES( + {$orderid}, + '{$labnumber}', + '150', + '{$_FILES['files']['name'][$i]}', + '{$filename}', + NOW(), + {$userid} + + )"; + //echo $sql; + $this->db_onedev->query($sql); + $xlast_id = $this->db_onedev->insert_id(); + $data['totalFiles'][] = array('xid' => $xlast_id, 'image_url' => '/one-media/one-image-nonlab/' . $filename); + } else { + $error = array('error' => $this->upload->display_errors()); + } + } + } + + $result = array("total" => count($data['totalFiles']), "records" => $data['totalFiles'], 'errors' => $error); + $this->sys_ok($result); + } + function uploadimagePatologiAnatomi() + { + if (! $this->isLogin) { + $this->sys_error("Invalid Token"); + exit; + } + + $userid = $this->sys_user["M_UserID"]; + $data = []; + //print_r($_SERVER); + + $prm = $this->sys_input; + $orderid = $this->input->post('orderid'); + $type = $this->input->post('type'); + $labnumber = $this->input->post('labnumber'); + $sql = "UPDATE so_imageupload_patology_anatomy SET + So_ImageUploadPatologyAnatomyIsActive = 'N', + So_ImageUploadPatologyAnatomyUserID = {$userid} + WHERE + So_ImageUploadPatologyAnatomyT_OrderHeaderID = {$orderid} + AND So_ImageUploadPatologyAnatomyType = '{$type}'"; + //echo $sql; + $qry = $this->db_onedev->query($sql); + $last_qry = $this->db_onedev->last_query(); + if (!$qry) { + $message = $this->db_onedev->error(); + $message['last_qry'] = $last_qry; + $this->sys_error_db($message); + exit; + } + //$config['upload_path'] = 'assets/'; + + $path = '/home/one/project/one/one-media/one-image-nonlab/'; + //echo $path; + $config['upload_path'] = $path; + $config['allowed_types'] = 'jpg|jpeg|png|gif'; + + $config['max_size'] = '10000'; + $count = count($_FILES['files']['name']); + //echo $count; + $this->load->library('upload', $config); + + $error = []; + for ($i = 0; $i < $count; $i++) { + + + if (!empty($_FILES['files']['name'][$i])) { + + + + $_FILES['file']['name'] = $_FILES['files']['name'][$i]; + + $_FILES['file']['type'] = $_FILES['files']['type'][$i]; + + $_FILES['file']['tmp_name'] = $_FILES['files']['tmp_name'][$i]; + + $_FILES['file']['error'] = $_FILES['files']['error'][$i]; + + $_FILES['file']['size'] = $_FILES['files']['size'][$i]; + + + + $namex = $orderid . '-' . $labnumber . '-' . $this->generateRandomString(5); + //echo $namex; + + $config['file_name'] = $namex; + $this->upload->initialize($config); + //echo $config['file_name'] ; + + + + + + if ($this->upload->do_upload('file')) { + + $uploadData = $this->upload->data(); + + $filename = $uploadData['file_name']; + //echo $filename; + + + $sql = "INSERT INTO so_imageupload_patology_anatomy ( + So_ImageUploadPatologyAnatomyT_OrderHeaderID, + So_ImageUploadPatologyAnatomyT_OrderHeaderLabNumber, + So_ImageUploadPatologyAnatomyT_SampleTypeID, + So_ImageUploadPatologyAnatomyOldName, + So_ImageUploadPatologyAnatomyNewName, + So_ImageUploadPatologyAnatomyCreated, + So_ImageUploadPatologyAnatomyUserID, + So_ImageUploadPatologyAnatomyType + ) + VALUES( + {$orderid}, + '{$labnumber}', + '145', + '{$_FILES['files']['name'][$i]}', + '{$filename}', + NOW(), + {$userid}, + '{$type}' + + )"; + //echo $sql; + $qry = $this->db_onedev->query($sql); + $last_qry = $this->db_onedev->last_query(); + if (!$qry) { + $message = $this->db_onedev->error(); + $message['last_qry'] = $last_qry; + $this->sys_error_db($message); + exit; + } + $xlast_id = $this->db_onedev->insert_id(); + $data['totalFiles'][] = array('xid' => $xlast_id, 'image_url' => '/one-media/one-image-nonlab/' . $filename); + } else { + $error = array('error' => $this->upload->display_errors()); + } + } + } + + $result = array("total" => count($data['totalFiles']), "records" => $data['totalFiles'], 'errors' => $error); + $this->sys_ok($result); + } + + + function generateRandomString($length = 10) + { + $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; + $charactersLength = strlen($characters); + $randomString = ''; + for ($i = 0; $i < $length; $i++) { + $randomString .= $characters[rand(0, $charactersLength - 1)]; + } + return $randomString; + } + + function getcytologiresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT Other_CytologiDetailsID as xid, + Other_CytologiT_OrderDetailID as orderdetail_id, + Other_CytologiDetailsCode as code, + Other_CytologiDetailsLabel as label, + Other_CytologiDetailsResult as result, + IFNULL(Other_CytologiM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_CytologiM_DoctorID) OR Other_CytologiM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_cytologi + JOIN other_cytologidetails ON Other_CytologiDetailsOther_CytologiID = Other_CytologiID AND Other_CytologiDetailsIsActive = 'Y' + LEFT JOIN m_doctor ON Other_CytologiM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_CytologiT_OrderDetailID = {$id} AND Other_CytologiIsActive = 'Y' + GROUP BY Other_CytologiDetailsID + ORDER BY Other_CytologiDetailsCode ASC"; + //echo $sql; + $query = $this->db_smartone->query($sql); + + if ($query) { + $rows = $query->result_array(); + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $rst = array('doctors' => $doctors, 'results' => $rows); + $this->sys_ok(["records" => $rst]); + } else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + function getmikroresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT + Other_MikroID as xid, + Other_MikroHasilBiakan as hasil_biakan, + Other_MikroSampleTypeName as sample_name, + Other_MikroT_OrderDetailID as orderdetail_id, + Other_MikroResult as result_value, + '' as result_other, + IFNULL(T_BacteriaID,0) as T_BacteriaID, + IFNULL(T_BacteriaName,'') as T_BacteriaName, + '' as details, + IFNULL(Other_MikroM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_MikroM_DoctorID) OR Other_MikroM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_mikro + LEFT JOIN t_bacteria ON Other_MikroT_BacteriaID = T_BacteriaID + LEFT JOIN m_doctor ON Other_MikroM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_MikroT_OrderDetailID = {$id} AND Other_MikroIsActive = 'Y' + GROUP BY Other_MikroID"; + //echo $sql; + $query = $this->db_smartone->query($sql); + + if ($query) { + $row = $query->row_array(); + if ($row) { + if ($row['result_value'] != 'Positif' && $row['result_value'] != 'Negatif') { + $row['result_other'] = $row['result_value']; + $row['result_value'] = 'other'; + } + $sql = "SELECT '' as xno, + Other_MikroDetailsID as xid, + Other_MikroDetailsValue as value, + IF(Other_MikroDetailsNote = 'R','Y','N') as chx_r, + IF(Other_MikroDetailsNote = 'I','Y','N') as chx_i, + IF(Other_MikroDetailsNote = 'S','Y','N') as chx_s, + Other_MikroDetailsNote as note, + t_antibiotic.* + FROM other_mikrodetails + LEFT JOIN t_antibiotic ON Other_MikroDetailsT_AntibioticID = T_AntibioticID + WHERE + Other_MikroDetailsOther_MikroID = {$row['xid']} AND Other_MikroDetailsIsActive = 'Y' + GROUP BY Other_MikroDetailsID + ORDER BY T_AntibioticName ASC"; + //echo $sql; + $details = $this->db_smartone->query($sql)->result_array(); + if ($details) { + foreach ($details as $k => $v) { + $details[$k]['xno'] = $k + 1; + } + } + $row['details'] = $details; + } else { + $row = array('xid' => '0', 'hasil_biakan' => '', 'result_value' => 'Negatif', 'sample_name' => '', 'orderdetail_id' => $id, 'T_BacteriaID' => '0', 'T_BacteriaName' => '0', 'details' => array(), 'doctor_id' => '0', 'doctor_name' => '0'); + } + } else { + $row = array('xid' => '0', 'hasil_biakan' => '', 'result_value' => 'Negatif', 'sample_name' => '', 'orderdetail_id' => $id, 'T_BacteriaID' => '0', 'T_BacteriaName' => '0', 'details' => array(), 'doctor_id' => '0', 'doctor_name' => '0'); + } + //print_r($row); + + + + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 7 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $sql = " + SELECT '0' as id, 'Belum memilih bakteria' as name + UNION + SELECT T_BacteriaID as id, T_BacteriaName as name + FROM t_bacteria + WHERE + T_BacteriaIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $bacteries = $this->db_smartone->query($sql)->result_array(); + $rst = array('doctors' => $doctors, 'bacteries' => $bacteries, 'results' => $row); + $this->sys_ok(["records" => $rst]); + } + function getantibiotics() + { + $prm = $this->sys_input; + $id = $prm["id"]; + $sql = " SELECT '' as xno, + 0 as xid, + '' as hasil_biakan, + '' as sample_name, + 0 as value, + 'Y' as chx_r, + 'N' as chx_i, + 'N' as chx_s, + 'R' as note, + t_antibiotic.* + FROM t_antibiotic + WHERE + T_AntibioticT_BacteriaID = {$prm['id']} AND T_AntibioticIsActive= 'Y' + ORDER BY T_AntibioticName ASC"; + //echo $sql; + $rows = $this->db_smartone->query($sql)->result_array(); + if (rows) { + foreach ($rows as $k => $v) { + $rows[$k]['xno'] = $k + 1; + } + } + + $this->sys_ok(["records" => $rows]); + } + function getlcprepresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = "SELECT T_OrderDetailVerification as verification, T_OrderDetailValidation as validation FROM t_orderdetail WHERE T_OrderDetailID = ?"; + $order = $this->db_smartone->query($sql, array($id))->row_array(); + + + $sql = " SELECT Other_LcprepDetailsID as xid, + Other_LcprepID as header_id, + Other_LcprepT_orderDetailID as orderdetail_id, + Other_LcprepDetailsCode as code, + Other_LcprepDetailsLabel as label, + Other_LcprepDetailsResult as result, + IFNULL(Other_LcprepM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_LcprepM_DoctorID) OR Other_LcprepM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_lcprep + JOIN other_lcprepdetails ON Other_LcprepDetailsOther_LcprepID = Other_LcprepID AND Other_LcprepDetailsIsActive = 'Y' + LEFT JOIN m_doctor ON Other_LcprepM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_LcprepT_orderDetailID = ? AND Other_LcprepIsActive = 'Y' + GROUP BY Other_LcprepDetailsOther_LcprepID, Other_LcprepDetailsCode + ORDER BY Other_LcprepDetailsCode ASC"; + //echo $sql; + $rows = $this->db_smartone->query($sql, array($id))->result_array(); + if (count($rows) == 0) { + $rows = array( + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'A', + 'label' => 'DESKRIPSI', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ), + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'B', + 'label' => 'KESIMPULAN', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ) + ); + } + + $other_rows = array(); + $langs = array(array('id' => 1, 'name' => 'Bahasa Indonesia')); + $selected_lang = array(array('id' => 1, 'name' => 'Bahasa Indonesia')); + $sql = "SELECT T_OrderHeaderAddOnSecondM_LangID as lang_id, + M_LangName as lang_name + FROM t_orderdetail + JOIN t_orderheader ON T_OrderDetailT_OrderHeaderID = T_OrderHeaderID AND T_OrderHeaderIsActive = 'Y' + JOIN t_orderheaderaddon ON T_OrderHeaderAddonT_OrderHeaderID = T_OrderHeaderID AND T_OrderHeaderAddonIsActive = 'Y' + JOIN m_lang ON T_OrderHeaderAddOnSecondM_LangID = M_LangID AND M_LangIsActive = 'Y' + WHERE T_OrderDetailID = {$id} AND T_OrderDetailIsActive = 'Y'"; + + $other_lang = $this->db_smartone->query($sql)->result_array(); + if (count($other_lang) > 0) { + $langs[] = array('id' => $other_lang[0]['lang_id'], 'name' => $other_lang[0]['lang_name']); + $selected_lang = array('id' => $other_lang[0]['lang_id'], 'name' => $other_lang[0]['lang_name']); + + + $sql = " SELECT Other_LcprepDetailsLangsID as xid, + Other_LcprepID as header_id, + Other_LcprepT_orderDetailID as orderdetail_id, + Other_LcprepDetailsLangsCode as code, + Other_LcprepDetailsLangsLabel as label, + Other_LcprepDetailsLangsResult as result, + IFNULL(Other_LcprepM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_LcprepM_DoctorID) OR Other_LcprepM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_lcprep + JOIN other_lcprepdetails_lang ON Other_LcprepDetailsLangsOther_LcprepID = Other_LcprepID AND Other_LcprepDetailsLangsIsActive = 'Y' + LEFT JOIN m_doctor ON Other_LcprepM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_LcprepT_orderDetailID = {$id} AND Other_LcprepDetailsLangsIsActive = 'Y' + GROUP BY Other_LcprepDetailsLangsOther_LcprepID, Other_LcprepDetailsLangsCode + ORDER BY Other_LcprepDetailsLangsCode ASC"; + // echo $sql; + $other_rows = $this->db_smartone->query($sql)->result_array(); + if (count($other_rows) == 0) { + $other_rows = array( + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'AA', + 'label' => 'DESCRIPTION', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ), + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'BB', + 'label' => 'CONCLUSION', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ) + ); + } + } + + $header_id = $rows[0]['header_id']; + $sql = "SELECT IFNULL(Other_LcprepAdekuasiID,0) as xid, + Lcprep_AdekuasiID as id, + Lcprep_AdekuasiLabel as name, + Lcprep_AdekuasiLabel as name_en, + IF(ISNULL(Other_LcprepAdekuasiID),'N',Other_LcprepAdekuasiChex) as chex + FROM lcprep_adekuasi + LEFT JOIN other_lcprepadekuasi ON Other_LcprepAdekuasiLcprep_AdekuasiID = Lcprep_AdekuasiID AND + Other_LcprepAdekuasiOther_LcprepID = {$header_id} AND + Other_LcprepAdekuasiIsActive = 'Y' + WHERE + Lcprep_AdekuasiIsActive = 'Y' + GROUP BY Lcprep_AdekuasiID + ORDER BY Lcprep_AdekuasiOrder ASC + "; + //echo $sql; + $adeakuasi = $this->db_smartone->query($sql)->result_array(); + foreach ($adeakuasi as $kc => $vc) { + $adeakuasi[$kc]['chex'] = $vc['chex'] == 'N' ? false : true; + $adeakuasi[$kc]['name_en'] = $this->translate_word($vc['name']); + } + + $sql = "SELECT IFNULL(Other_LcprepKategoriUmumID,0) as xid, + Lcprep_KategoriUmumID as id, + Lcprep_KategoriUmumLabel as name, + Lcprep_KategoriUmumLabel as name_en, + IF(ISNULL(Other_LcprepKategoriUmumID),'N',Other_LcprepKategoriUmumChex) as chex + FROM lcprep_kategoriumum + LEFT JOIN other_lcprepkategoriumum ON Other_LcprepKategoriUmumLcprep_KategoriUmumID = Lcprep_KategoriUmumID AND + Other_LcprepKategoriUmumOther_LcprepID = {$header_id} AND + Other_LcprepKategoriUmumIsActive = 'Y' + WHERE + Lcprep_KategoriUmumIsActive = 'Y' + GROUP BY Lcprep_KategoriUmumID + "; + //echo $sql; + $kategoriumum = $this->db_smartone->query($sql)->result_array(); + foreach ($kategoriumum as $kc => $vc) { + $kategoriumum[$kc]['chex'] = $vc['chex'] == 'N' ? false : true; + $kategoriumum[$kc]['name_en'] = $this->translate_word($vc['name']); + } + + $sql = " + SELECT Lcprep_InterpretasiGroupID as group_id, + Lcprep_InterpretasiGroupName as group_name, + Lcprep_InterpretasiGroupName as group_name_en, + '' as subgroups + FROM lcprep_interpretasigroup + WHERE + Lcprep_InterpretasiGroupIsActive = 'Y' + "; + //echo $sql; + $interpretasi = $this->db_smartone->query($sql)->result_array(); + foreach ($interpretasi as $k => $v) { + $interpretasi[$k]['group_name_en'] = $this->translate_word($v['group_name']); + $subgroups = array(); + $sql = "SELECT Lcprep_InterpretasiSubgroupID as subgroup_id, + Lcprep_InterpretasiSubgroupName as subgroup_name, + Lcprep_InterpretasiSubgroupName as subgroup_name_en, + '' as childs + FROM lcprep_interpretasisubgroup + WHERE + Lcprep_InterpretasiSubgroupLcprep_InterpretasiGroupID = {$v['group_id']} AND Lcprep_InterpretasiSubgroupIsActive = 'Y'"; + //echo $sql; + $subgroups = $this->db_smartone->query($sql)->result_array(); + if (count($subgroups) > 0) { + foreach ($subgroups as $ki => $vi) { + $subgroups[$ki]['subgroup_name_en'] = $this->translate_word($vi['subgroup_name']); + $childs = array(); + + $sql = "SELECT IFNULL(Other_LcprepInterpretasiID,0) as xid, + IFNULL(Other_LcprepInterpretasiChex,'N') as chex, + IFNULL(Other_LcprepInterpretasiValue,'') as value, + IFNULL(Other_LcprepInterpretasiValueEng,'') as value_en, + Lcprep_InterpretasiID as id, + Lcprep_InterpretasiLcprep_InterpretasiSubgroupID as subgroup_id, + Lcprep_InterpretasiCode as code, + Lcprep_InterpretasiName as name, + Lcprep_InterpretasiName as name_en, + Lcprep_InterpretasiParentID as parent_id, + Lcprep_InterpretasiIsParent as is_parent, + Lcprep_InterpretasiHasResult as has_result, + Lcprep_InterpretasiTypeResult as type_result + FROM lcprep_interpretasi + LEFT JOIN other_lcprepinterpretasi ON Other_LcprepInterpretasiOther_LcprepID = {$header_id} AND + Other_LcprepInterpretasiLcprep_InterpretasiID = Lcprep_InterpretasiID AND + Other_LcprepInterpretasiIsActive = 'Y' + WHERE + Lcprep_InterpretasiLcprep_InterpretasiSubgroupID = {$vi['subgroup_id']} AND Lcprep_InterpretasiIsActive = 'Y' + GROUP BY Lcprep_InterpretasiID Order BY Lcprep_InterpretasiCode ASC"; + $childs = $this->db_smartone->query($sql)->result_array(); + if ($childs) { + foreach ($childs as $kc => $vc) { + $childs[$kc]['chex'] = $vc['chex'] == 'N' ? false : true; + $childs[$kc]['name_en'] = $this->translate_word($vc['name']); + } + } + $subgroups[$ki]['childs'] = $childs; + } + } + + $interpretasi[$k]['subgroups'] = $subgroups; + } + + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + + + + $rst = array('order' => $order, 'langs' => $langs, 'selected_lang' => $selected_lang, 'doctors' => $doctors, 'results' => $rows, 'other_results' => $other_rows, 'adekuasi' => $adeakuasi, 'kategoriumum' => $kategoriumum, 'interpretasi' => $interpretasi); + $this->sys_ok(["records" => $rst]); + } + + function translate_word($word) + { + $sql = "SELECT * + FROM translate_word + WHERE Translate_WordNat_LangID = '2' AND + BINARY Translate_WordFrom = '{$word}' AND + Translate_WordIsActive = 'Y' + LIMIT 1"; + $dt = $this->db_smartone->query($sql)->result_array(); + if (count($dt) > 0) { + return $dt[0]['Translate_WordTo']; + } else { + return $word; + } + } + + function getpapsmearresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT Other_PapSmearDetailsID as xid, + Other_PapSmearID as header_id, + Other_PapSmearT_OrderDetailID as orderdetail_id, + Other_PapSmearDetailsCode as code, + Other_PapSmearDetailsLabel as label, + Other_PapSmearDetailsResult as result, + IFNULL(Other_PapSmearM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_PapSmearM_DoctorID) OR Other_PapSmearM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_papsmear + JOIN other_papsmeardetails ON Other_PapSmearDetailsOther_PapSmearID = Other_PapSmearID AND Other_PapSmearDetailsIsActive = 'Y' + LEFT JOIN m_doctor ON Other_PapSmearM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_PapSmearT_OrderDetailID = {$id} AND Other_PapSmearIsActive = 'Y' + GROUP BY Other_PapSmearDetailsID + ORDER BY Other_PapSmearDetailsCode ASC"; + //echo $sql; + $rows = $this->db_smartone->query($sql)->result_array(); + if (!$rows) { + $rows = array( + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'A', + 'label' => 'Makroskopik', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ), + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'B', + 'label' => 'Mikroskopik', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ), + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'C', + 'label' => 'Kesimpulan', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ) + ); + } + + $header_id = $rows[0]['header_id']; + $sql = "SELECT Other_PapSmearMaturasiID as xid, + Other_PapSmearMaturasiValue as value + FROM other_papsmearmaturasi + WHERE + Other_PapSmearMaturasiOther_PapSmearID = {$header_id} AND + Other_PapSmearMaturasiIsActive = 'Y' + "; + //echo $sql; + $dt_maturasi = $this->db_smartone->query($sql)->row_array(); + if (!$dt_maturasi) { + $maturasi = array('xid' => '0', 'value' => array('', '', '')); + } else { + $value = explode('/', $dt_maturasi['value']); + $maturasi = array('xid' => $dt_maturasi['xid'], 'value' => $value); + } + + $sql = "SELECT IFNULL(Other_PapSmearBahanID,0) as xid, + M_PapSmearBahanID as bahan_id, + M_PapSmearBahanName as name, + IF(ISNULL(Other_PapSmearBahanID),'N','Y') as selected + FROM m_papsmearbahan + LEFT JOIN other_papsmearbahan ON Other_PapSmearBahanM_PapSmearBahanID = M_PapSmearBahanID AND + Other_PapSmearBahanOther_PapSmearID = {$header_id} AND + Other_PapSmearBahanIsActive = 'Y' + WHERE + M_PapSmearBahanIsActive = 'Y' + ORDER BY M_PapSmearBahanID ASC + "; + //echo $sql; + $bahans = $this->db_smartone->query($sql)->result_array(); + + $sql = "SELECT IFNULL(Other_PapsmearCategoryID,0) as xid, + M_PapSmearCategoryID as category_id, + M_PapSmearCategoryName as name, + IF(ISNULL(Other_PapsmearCategoryID),'N','Y') as selected + FROM m_papsmearcategory + LEFT JOIN other_papsmearcategory ON Other_PapsmearCategoryM_PapSmearCategoryID = M_PapSmearCategoryID AND + Other_PapsmearCategoryOther_PapSmearID = {$header_id} AND + Other_PapsmearCategoryIsActive = 'Y' + WHERE + M_PapSmearCategoryIsActive = 'Y' + ORDER BY M_PapSmearCategoryID ASC + "; + //echo $sql; + $categories = $this->db_smartone->query($sql)->result_array(); + + $sql = "SELECT IFNULL(Other_PapSmearCheckID,0) as xid, + M_PapSmearCheckID as check_id, + M_PapSmearCheckLabel as name, + IF(ISNULL(Other_PapSmearCheckID),'N','Y') as selected, + Other_PapSmearCheckNote as note + FROM m_papsmearcheck + LEFT JOIN other_papsmearcheck ON Other_PapSmearCheckM_PapSmearCheckID = M_PapSmearCheckID AND + Other_PapSmearCheckOther_PapSmearID = {$header_id} AND + Other_PapSmearCheckIsActive = 'Y' + WHERE + M_PapSmearCheckIsActive = 'Y' + ORDER BY M_PapSmearCheckCode ASC + "; + $checks = $this->db_smartone->query($sql)->result_array(); + + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $rst = array('doctors' => $doctors, 'checks' => $checks, 'bahans' => $bahans, 'categories' => $categories, 'maturasi' => $maturasi, 'results' => $rows); + $this->sys_ok(["records" => $rst]); + } + + function saveresult_lcprep() + { + $prm = $this->sys_input; + $detail_id = $prm['detail_id']; + $doctor_id = $prm['doctor']; + $adekuasi = $prm['adekuasi']; + $kategoriumum = $prm['kategoriumum']; + $interpretasi = $prm['interpretasi']; + $results = $prm['results']; + $selected_lang = $prm['selected_lang']; + $other_results = $prm['other_results']; + + $userid = $this->sys_user['M_UserID']; + + $header_id = 0; + $sql = "SELECT * FROM other_lcprep WHERE Other_LcprepT_orderDetailID = ? AND Other_LcprepIsActive = 'Y'"; + $dt_header = $this->db_smartone->query($sql, array($detail_id))->row_array(); + if ($dt_header) { + $header_id = $dt_header['Other_LcprepID']; + } + if ($header_id == 0) { + $sql = "INSERT INTO other_lcprep( + Other_LcprepT_orderDetailID, + Other_LcprepM_DoctorID, + Other_LcprepUserID, + Other_LcprepCreated + ) + VALUES( + ?, + ?, + ?, + NOW() + )"; + //echo $sql; + $query = $this->db_smartone->query($sql, array($detail_id, $doctor_id, $userid)); + if(!$query){ + echo $this->db_smartone->last_query(); + exit; + } + $header_id = $this->db_smartone->insert_id(); + } else { + $sql = "UPDATE other_lcprep SET Other_LcprepM_DoctorID = ?, Other_LcprepUserID = ? WHERE Other_LcprepID = ?"; + $query = $this->db_smartone->query($sql, array($doctor_id, $userid, $header_id)); + if(!$query){ + echo $this->db_smartone->last_query(); + exit; + } + } + + + + if ($adekuasi) { + foreach ($adekuasi as $k => $v) { + $selected = $v['chex'] ? 'Y' : 'N'; + if (intval($v['xid'] == 0)) { + $sql = "UPDATE other_lcprepadekuasi SET Other_LcprepAdekuasiIsActive = 'N' + WHERE + Other_LcprepAdekuasiOther_LcprepID = ? AND + Other_LcprepAdekuasiIsActive = 'Y' AND + Other_LcprepAdekuasiLcprep_AdekuasiID = ?"; + $query = $this->db_smartone->query($sql, array($header_id, $v['id'])); + if(!$query){ + echo $this->db_smartone->last_query(); + exit; + } + $sql = "INSERT INTO other_lcprepadekuasi ( + Other_LcprepAdekuasiOther_LcprepID, + Other_LcprepAdekuasiLcprep_AdekuasiID, + Other_LcprepAdekuasiChex, + Other_LcprepAdekuasiUserID, + Other_LcprepAdekuasiCreated + ) + VALUES( + ?, + ?, + ?, + ?, + NOW() + )"; + $query = $this->db_smartone->query($sql, array($header_id, $v['id'], $selected, $userid)); + if(!$query){ + echo $this->db_smartone->last_query(); + exit; + } + //echo $sql; + } + if (intval($v['xid'] != 0)) { + + $sql = "UPDATE other_lcprepadekuasi SET + Other_LcprepAdekuasiChex = ?, + Other_LcprepAdekuasiUserID = ? + WHERE + Other_LcprepAdekuasiID = ? + "; + $query = $this->db_smartone->query($sql, array($selected, $userid, $v['xid'])); + if(!$query){ + echo $this->db_smartone->last_query(); + exit; + } + } + + //echo $sql; + } + } + + if ($kategoriumum) { + foreach ($kategoriumum as $k => $v) { + $selected = $v['chex'] ? 'Y' : 'N'; + if (intval($v['xid'] == 0)) { + $sql = "UPDATE other_lcprepkategoriumum SET Other_LcprepKategoriUmumIsActive = 'N' + WHERE + Other_LcprepKategoriUmumOther_LcprepID = ? AND + Other_LcprepKategoriUmumLcprep_KategoriUmumID = ? AND + Other_LcprepKategoriUmumIsActive = 'Y' + "; + $query = $this->db_smartone->query($sql, array($header_id, $v['id'])); + if(!$query){ + echo $this->db_smartone->last_query(); + exit; + } + $sql = "INSERT INTO other_lcprepkategoriumum ( + Other_LcprepKategoriUmumOther_LcprepID, + Other_LcprepKategoriUmumLcprep_KategoriUmumID, + Other_LcprepKategoriUmumChex, + Other_LcprepKategoriUmumUserID, + Other_LcprepKategoriUmumCreated + ) + VALUES( + ?, + ?, + ?, + ?, + NOW() + )"; + $query = $this->db_smartone->query($sql, array($header_id, $v['id'], $selected, $userid)); + if(!$query){ + echo $this->db_smartone->last_query(); + exit; + } + } + if (intval($v['xid'] != 0)) { + $sql = "UPDATE other_lcprepkategoriumum SET + Other_LcprepKategoriUmumChex = ?, + Other_LcprepKategoriUmumUserID = ? + WHERE + Other_LcprepKategoriUmumID = ? + "; + $query = $this->db_smartone->query($sql, array($selected, $userid, $v['xid'])); + if(!$query){ + echo $this->db_smartone->last_query(); + exit; + } + } + + //echo $sql; + } + } + + if (count($results) > 0 && intval($selected_lang) == 1) { + foreach ($results as $k => $v) { + if (intval($v['xid'] == 0)) { + $sql = "UPDATE other_lcprepdetails SET Other_LcprepDetailsIsActive = 'N' + WHERE + Other_LcprepDetailsOther_LcprepID = ? AND + Other_LcprepDetailsCode = ? AND + Other_LcprepDetailsIsActive = 'Y'"; + $query = $this->db_smartone->query($sql, array($header_id, $v['code'])); + if(!$query){ + echo $this->db_smartone->last_query(); + exit; + } + $sql = "INSERT INTO other_lcprepdetails ( + Other_LcprepDetailsOther_LcprepID, + Other_LcprepDetailsCode, + Other_LcprepDetailsLabel, + Other_LcprepDetailsResult, + Other_LcprepDetailsUserID, + Other_LcprepDetailsCreated + ) + VALUES( + ?, + ?, + ?, + ?, + ?, + NOW() + )"; + $query = $this->db_smartone->query($sql, array($header_id, $v['code'], $v['label'], $v['result'], $userid)); + if(!$query){ + echo $this->db_smartone->last_query(); + exit; + } + } + if (intval($v['xid'] != 0)) { + $sql = "UPDATE other_lcprepdetails SET + Other_LcprepDetailsCode = ?, + Other_LcprepDetailsLabel = ?, + Other_LcprepDetailsResult = ?, + Other_LcprepDetailsUserID = ? + WHERE + Other_LcprepDetailsID = ? + "; + $query = $this->db_smartone->query($sql, array($v['code'], $v['label'], $v['result'], $userid, $v['xid'])); + if(!$query){ + echo $this->db_smartone->last_query(); + exit; + } + } + //echo $sql; + } + } + + if (count($other_results) > 0 && intval($selected_lang) == 2) { + foreach ($other_results as $k => $v) { + if (intval($v['xid'] == 0)) { + $sql = "UPDATE other_lcprepdetails_lang SET Other_LcprepDetailsLangsIsActive = 'N' + WHERE + Other_LcprepDetailsLangsOther_LcprepID = ? AND + Other_LcprepDetailsLangsCode = ? AND + Other_LcprepDetailsLangsIsActive = 'Y'"; + $query = $this->db_smartone->query($sql, array($header_id, $v['code'])); + if(!$query){ + echo $this->db_smartone->last_query(); + exit; + } + //echo $this->db_smartone->last_query(); + $sql = "INSERT INTO other_lcprepdetails_lang ( + Other_LcprepDetailsLangsOther_LcprepID, + Other_LcprepDetailsLangsCode, + Other_LcprepDetailsLangsLabel, + Other_LcprepDetailsLangsResult, + Other_LcprepDetailsLangsCreatedUserID, + Other_LcprepDetailsLangsCreated + ) + VALUES( + ?, + ?, + ?, + ?, + ?, + NOW() + )"; + $query = $this->db_smartone->query($sql, array($header_id, $v['code'], $v['label'], $v['result'], $userid)); + if(!$query){ + echo $this->db_smartone->last_query(); + exit; + } + //echo $this->db_smartone->last_query(); + } + if (intval($v['xid'] != 0)) { + $sql = "UPDATE other_lcprepdetails_lang SET + Other_LcprepDetailsLangsCode = ?, + Other_LcprepDetailsLangsLabel = ?, + Other_LcprepDetailsLangsResult = ?, + Other_LcprepDetailsLangsUpdatedUserID = ?, + Other_LcprepDetailsLangsUpdated = NOW() + WHERE + Other_LcprepDetailsLangsID = ? + "; + $query = $this->db_smartone->query($sql, array($v['code'], $v['label'], $v['result'], $userid, $v['xid'])); + if(!$query){ + echo $this->db_smartone->last_query(); + exit; + } + } + //echo $sql; + } + } + + if ($interpretasi) { + foreach ($interpretasi as $k => $v) { + if (count($v['subgroups']) > 0) { + foreach ($v['subgroups'] as $ik => $iv) { + if (count($iv['childs']) > 0) { + foreach ($iv['childs'] as $iik => $iiv) { + if (intval($iiv['xid'] == 0)) { + $chex = $iiv['chex'] ? 'Y' : 'N'; + $sql = "UPDATE other_lcprepinterpretasi SET Other_LcprepInterpretasiIsActive = 'N' + WHERE + Other_LcprepInterpretasiOther_LcprepID = ? AND + Other_LcprepInterpretasiLcprep_InterpretasiID = ? AND + Other_LcprepInterpretasiIsActive = 'Y'"; + $query = $this->db_smartone->query($sql, array($header_id, $iiv['id'])); + if(!$query){ + echo $this->db_smartone->last_query(); + exit; + } + $sql = "INSERT INTO other_lcprepinterpretasi ( + Other_LcprepInterpretasiOther_LcprepID, + Other_LcprepInterpretasiLcprep_InterpretasiID, + Other_LcprepInterpretasiChex, + Other_LcprepInterpretasiValue, + Other_LcprepInterpretasiValueEng, + Other_LcprepInterpretasiUserID, + Other_LcprepInterpretasiCreated + ) + VALUES( + ?, + ?, + ?, + ?, + ?, + ?, + NOW() + )"; + $query = $this->db_smartone->query($sql, array($header_id, $iiv['id'], $chex, $iiv['value'], $iiv['value_en'], $userid)); + if(!$query){ + echo $this->db_smartone->last_query(); + exit; + } + } + + if (intval($iiv['xid'] != 0)) { + $chex = $iiv['chex'] ? 'Y' : 'N'; + $sql = "UPDATE other_lcprepinterpretasi SET + Other_LcprepInterpretasiChex = ?, + Other_LcprepInterpretasiValue = ?, + Other_LcprepInterpretasiValueEng = ?, + Other_LcprepInterpretasiUserID = ? + WHERE + Other_LcprepInterpretasiID = ? + "; + $query = $this->db_smartone->query($sql, array($chex, $iiv['value'], $iiv['value_en'], $userid, $iiv['xid'])); + if(!$query){ + echo $this->db_smartone->last_query(); + exit; + } + //echo $sql; + + } + } + } + } + } + //echo $sql; + } + } + + + $result = array("total" => 1, "records" => array(), "sql" => ''); + $this->sys_ok($result); + exit; + } + + function saveresult_papsmear() + { + $prm = $this->sys_input; + $detail_id = $prm['detail_id']; + $doctor_id = $prm['doctor']; + $checks = $prm['checks']; + $maturasi = $prm['maturasi']; + $bahans = $prm['bahans']; + $categories = $prm['categories']; + $results = $prm['results']; + + $userid = $this->sys_user['M_UserID']; + + $header_id = 0; + $sql = "SELECT * FROM other_papsmear WHERE Other_PapSmearT_OrderDetailID = {$detail_id} AND Other_PapSmearIsActive = 'Y'"; + $dt_header = $this->db_smartone->query($sql)->row_array(); + if ($dt_header) { + $header_id = $dt_header['Other_PapSmearID']; + } + if ($header_id == 0) { + $sql = "INSERT INTO other_papsmear( + Other_PapSmearT_OrderDetailID, + Other_PapSmearM_DoctorID, + Other_PapSmearUserID, + Other_PapSmearCreated + ) + VALUES( + {$detail_id}, + {$doctor_id}, + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } else { + $sql = "UPDATE other_papsmear SET Other_PapSmearM_DoctorID = {$doctor_id}, Other_PapSmearUserID = {$userid} WHERE Other_PapSmearID = {$header_id}"; + $this->db_smartone->query($sql); + } + + if ($checks) { + foreach ($checks as $k => $v) { + if (intval($v['xid']) == 0 && $v['selected'] === 'Y') { + $sql = "INSERT INTO other_papsmearcheck ( + Other_PapSmearCheckOther_PapSmearID, + Other_PapSmearCheckM_PapSmearCheckID, + Other_PapSmearCheckNote, + Other_PapSmearCheckUserID, + Other_PapSmearCheckCreated + ) + VALUES( + {$header_id}, + {$v['check_id']}, + '{$v['note']}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if (intval($v['xid']) != 0 && $v['selected'] === 'N') { + $sql = "UPDATE other_papsmearcheck SET + Other_PapSmearCheckIsActive = 'N', + Other_PapSmearCheckUserID = {$userid} + WHERE + Other_PapSmearCheckID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + if (intval($v['xid']) != 0 && $v['selected'] === 'Y') { + $sql = "UPDATE other_papsmearcheck SET + Other_PapSmearCheckNote = '{$v['note']}', + Other_PapSmearCheckUserID = {$userid} + WHERE + Other_PapSmearCheckID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + //echo $sql; + } + } + + if ($maturasi) { + if (intval($maturasi['xid']) == 0) { + $value = join("/", $maturasi['value']); + $sql = "INSERT INTO other_papsmearmaturasi ( + Other_PapSmearMaturasiOther_PapSmearID, + Other_PapSmearMaturasiValue, + Other_PapSmearMaturasiUserID, + Other_PapSmearMaturasiCreated + ) + VALUE( + {$header_id}, + '{$value}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + //echo $sql; + } + if (intval($maturasi['xid']) != 0) { + $value = join("/", $maturasi['value']); + $sql = "UPDATE other_papsmearmaturasi SET + Other_PapSmearMaturasiValue = '{$value}', + Other_PapSmearMaturasiUserID = {$userid} + WHERE + Other_PapSmearMaturasiID = {$maturasi['xid']}"; + // echo $sql; + $this->db_smartone->query($sql); + } + } + + if ($bahans) { + foreach ($bahans as $k => $v) { + if (intval($v['xid']) == 0 && $v['selected'] === 'Y') { + $sql = "INSERT INTO other_papsmearbahan ( + Other_PapSmearBahanOther_PapSmearID, + Other_PapSmearBahanM_PapSmearBahanID, + Other_PapSmearBahanUserID, + Other_PapSmearBahanCreated + ) + VALUES( + {$header_id}, + {$v['bahan_id']}, + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if (intval($v['xid']) != 0 && $v['selected'] === 'N') { + $sql = "UPDATE other_papsmearbahan SET + Other_PapSmearBahanIsActive = 'N', + Other_PapsmearCategoryUserID = {$userid} + WHERE + Other_PapSmearBahanID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + if (intval($v['xid']) != 0 && $v['selected'] === 'Y') { + $sql = "UPDATE other_papsmearbahan SET + Other_PapSmearBahanIsActive = 'Y', + Other_PapsmearCategoryUserID = {$userid} + WHERE + Other_PapSmearBahanID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + //echo $sql; + } + } + + if ($categories) { + foreach ($categories as $k => $v) { + if (intval($v['xid']) == 0 && $v['selected'] === 'Y') { + $sql = "INSERT INTO other_papsmearcategory ( + Other_PapsmearCategoryOther_PapSmearID, + Other_PapsmearCategoryM_PapSmearCategoryID, + Other_PapsmearCategoryUserID, + Other_PapsmearCategoryCreated + ) + VALUES( + {$header_id}, + {$v['category_id']}, + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if (intval($v['xid']) != 0 && $v['selected'] === 'N') { + $sql = "UPDATE other_papsmearcategory SET + Other_PapsmearCategoryIsActive = 'N', + Other_PapsmearCategoryUserID = {$userid} + WHERE + Other_PapsmearCategoryID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + //echo $sql; + if (intval($v['xid']) != 0 && $v['selected'] === 'Y') { + $sql = "UPDATE other_papsmearcategory SET + Other_PapsmearCategoryIsActive = 'Y', + Other_PapsmearCategoryUserID = {$userid} + WHERE + Other_PapsmearCategoryID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + } + } + + if ($results) { + foreach ($results as $k => $v) { + if (intval($v['xid']) == 0) { + $sql = "INSERT INTO other_papsmeardetails ( + Other_PapSmearDetailsOther_PapSmearID, + Other_PapSmearDetailsCode, + Other_PapSmearDetailsLabel, + Other_PapSmearDetailsResult, + Other_PapSmearDetailsUserID, + Other_PapSmearDetailsCreated + ) + VALUES( + {$header_id}, + '{$v['code']}', + '{$v['label']}', + '{$v['result']}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if (intval($v['xid']) != 0) { + $sql = "UPDATE other_papsmeardetails SET + Other_PapSmearDetailsCode = '{$v['code']}', + Other_PapSmearDetailsLabel = '{$v['label']}', + Other_PapSmearDetailsResult = '{$v['result']}', + Other_PapSmearDetailsUserID = {$userid} + WHERE + Other_PapSmearDetailsID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + //echo $sql; + } + } + + $result = array("total" => 1, "records" => array(), "sql" => ''); + $this->sys_ok($result); + exit; + } + + function saveresult_fna() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = $inp['doctor']; + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + if ($prm[0]['xid'] == '0') { + $sql = "INSERT INTO other_fna( + Other_FNAM_DoctorID, + Other_FNAT_OrderDetailID, + Other_FNAUserID, + Other_FNACreated + ) + VALUES( + {$doctor_id}, + {$prm[0]['orderdetail_id']}, + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } else { + $sql = "SELECT * FROM other_fna WHERE Other_FNAT_OrderDetailID = {$prm[0]['orderdetail_id']} AND Other_FNAIsActive = 'Y'"; + $data_header = $this->db_smartone->query($sql)->row_array(); + $header_id = $data_header['Other_FNAID']; + $sql = "UPDATE other_fna SET + Other_FNAM_DoctorID = {$doctor_id}, + Other_FNAUserID = {$userid} + WHERE + Other_FNAID = {$header_id}"; + $this->db_smartone->query($sql); + } + foreach ($prm as $k => $v) { + if ($v['xid'] == '0') { + $results = str_replace("'", "\\'", $v['result']); + $sql = "INSERT INTO other_fnadetails( + Other_FNADetailsOther_FNAID , + Other_FNADetailsCode, + Other_FNADetailsLabel, + Other_FNADetailsResult, + Other_FNADetailsCreated, + Other_FNADetailsUserID + ) + VALUES( + {$header_id}, + '{$v['code']}', + '{$v['label']}', + '{$results}', + NOW(), + {$userid} + )"; + $query = $this->db_smartone->query($sql); + } else { + $results = str_replace("'", "\\'", $v['result']); + $sql = "UPDATE other_fnadetails SET + Other_FNADetailsResult = '{$results}', + Other_FNADetailsUserID = {$userid} + WHERE + Other_FNADetailsID = {$v['xid']}"; + $query = $this->db_smartone->query($sql); + } + } + + $result = array("total" => 1, "records" => array(), "sql" => ''); + $this->sys_ok($result); + exit; + } + + function saveresult_patologianatomy() + { + + $inp = $this->sys_input; + $doctor_id = $inp['doctor']; + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + if ($inp['xid'] == '0') { + $sql = "INSERT INTO other_patologi_anatomy( + Other_PatologiAnatomyT_OrderDetailID, + Other_PatologiAnatomyM_DoctorID, + Other_PatologiAnatomyNoSediaan, + Other_PatologiAnatomyDiagnosaKlinis, + Other_PatologiAnatomyKeteranganKlinis, + Other_PatologiAnatomyLokasiOrgan, + Other_PatologiAnatomyMakroskopik, + Other_PatologiAnatomyMikroskopik, + Other_PatologiAnatomyKesimpulan, + Other_PatologiAnatomyUserID, + Other_PatologiAnatomyCreated + ) + VALUES( + {$inp['detail_id']}, + {$doctor_id}, + '{$inp['no_sediaan']}', + '{$inp['diagnosa']}', + '{$inp['klinis']}', + '{$inp['lokasi']}', + '{$inp['makroskopik']}', + '{$inp['mikroskopik']}', + '{$inp['kesimpulan']}', + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } else { + $sql = "UPDATE other_patologi_anatomy SET + Other_PatologiAnatomyM_DoctorID = ?, + Other_PatologiAnatomyNoSediaan = ?, + Other_PatologiAnatomyKeteranganKlinis = ?, + Other_PatologiAnatomyDiagnosaKlinis = ?, + Other_PatologiAnatomyLokasiOrgan = ?, + Other_PatologiAnatomyMakroskopik = ?, + Other_PatologiAnatomyMikroskopik = ?, + Other_PatologiAnatomyKesimpulan = ?, + Other_PatologiAnatomyUserID = ? + WHERE + Other_PatologiAnatomyT_OrderDetailID = ? AND Other_PatologiAnatomyIsActive = 'Y'"; + $this->db_smartone->query($sql, array( + $doctor_id, + $inp['no_sediaan'], + $inp['klinis'], + $inp['diagnosa'], + $inp['lokasi'], + $inp['makroskopik'], + $inp['mikroskopik'], + $inp['kesimpulan'], + $userid, + $inp['detail_id'] + )); + //echo $this->db_smartone->last_query(); + + } + + $inp_rst = array( + 'doctor_id' => $doctor_id, + 'no_sediaan' => $inp['no_sediaan'], + 'klinis' => $inp['klinis'], + 'diagnosa' => $inp['diagnosa'], + 'lokasi' => $inp['lokasi'], + 'makroskopik' => $inp['makroskopik'], + 'mikroskopik' => $inp['mikroskopik'], + 'kesimpulan' => $inp['kesimpulan'] + ); + $log_json = json_encode($inp_rst); + + $sql = "INSERT INTO log_other_patologianatomy ( + Log_OtherPatologiAnatomyT_OrderDetailID, + Log_OtherPatologiAnatomyDateTime, + Log_OtherPatologiAnatomySON, + Log_OtherPatologiAnatomyUserID + )VALUE( + {$inp['detail_id']}, + NOW(), + '{$log_json}', + {$userid} + )"; + $this->db_smartone->query($sql); + //echo $this->db_smartone->last_query(); + + $result = array("total" => 1, "records" => array(), "sql" => ''); + $this->sys_ok($result); + exit; + } + + function saveresult_cytologi() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = $inp['doctor']; + + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + if ($prm[0]['xid'] == '0') { + $sql = "INSERT INTO other_cytologi( + Other_CytologiT_OrderDetailID, + Other_CytologiM_DoctorID, + Other_CytologiUserID, + Other_CytologiCreated + ) + VALUES( + {$prm[0]['orderdetail_id']}, + {$doctor_id}, + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } else { + $sql = "SELECT * FROM other_cytologi WHERE Other_CytologiT_OrderDetailID = {$prm[0]['orderdetail_id']} AND Other_CytologiIsActive = 'Y'"; + $data_header = $this->db_smartone->query($sql)->row_array(); + $header_id = $data_header['Other_CytologiID']; + $sql = "UPDATE other_cytologi SET + Other_CytologiM_DoctorID = {$doctor_id}, + Other_CytologiUserID = {$userid} + WHERE + Other_CytologiID = {$header_id}"; + $this->db_smartone->query($sql); + } + foreach ($prm as $k => $v) { + if ($v['xid'] == '0') { + $results = str_replace("'", "\\'", $v['result']); + $sql = "INSERT INTO other_cytologidetails( + Other_CytologiDetailsOther_CytologiID , + Other_CytologiDetailsCode, + Other_CytologiDetailsLabel, + Other_CytologiDetailsResult, + Other_CytologiDetailsCreated, + Other_CytologiDetailsUserID + ) + VALUES( + {$header_id}, + '{$v['code']}', + '{$v['label']}', + '{$results}', + NOW(), + {$userid} + )"; + $query = $this->db_smartone->query($sql); + } else { + $results = str_replace("'", "\\'", $v['result']); + $sql = "UPDATE other_cytologidetails SET + Other_CytologiDetailsResult = '{$results}', + Other_CytologiDetailsUserID = {$userid} + WHERE + Other_CytologiDetailsID = {$v['xid']}"; + $query = $this->db_smartone->query($sql); + } + } + + $result = array("total" => 1, "records" => array(), "sql" => ''); + $this->sys_ok($result); + exit; + } + + function saveresult_mikro() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = $inp['doctor']; + $backteria_id = $inp['bacteria']; + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + + if ($inp['result_value'] != 'Negatif' && $inp['result_value'] != 'Positif') { + $prm['result_value'] = $prm['result_other']; + } else { + $prm['result_value'] = $inp['result_value']; + } + + if ($prm['xid'] == '0') { + $sql = "INSERT INTO other_mikro( + Other_MikroM_DoctorID, + Other_MikroResult, + Other_MikroT_BacteriaID, + Other_MikroT_OrderDetailID, + Other_MikroHasilBiakan, + Other_MikroSampleTypeName, + Other_MikroUserID, + Other_MikroCreated + ) + VALUES( + {$doctor_id}, + '{$prm['result_value']}', + {$backteria_id}, + {$prm['orderdetail_id']}, + '{$prm['hasil_biakan']}', + '{$prm['sample_name']}', + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } else { + $sql = "SELECT * FROM other_mikro WHERE Other_MikroT_OrderDetailID = {$prm['orderdetail_id']} AND Other_MikroIsActive = 'Y'"; + $data_header = $this->db_smartone->query($sql)->row_array(); + $header_id = $data_header['Other_MikroID']; + $sql = "UPDATE other_mikro SET + Other_MikroResult = '{$prm['result_value']}', + Other_MikroM_DoctorID = {$doctor_id}, + Other_MikroT_BacteriaID = {$backteria_id}, + Other_MikroHasilBiakan = '{$prm['hasil_biakan']}', + Other_MikroSampleTypeName = '{$prm['sample_name']}', + Other_MikroUserID = {$userid} + WHERE + Other_MikroID = {$header_id}"; + //echo $sql; + $this->db_smartone->query($sql); + } + + + + $sql = "UPDATE other_mikrodetails SET Other_MikroDetailsIsActive = 'N', Other_MikroDetailsUserID = 0 WHERE Other_MikroDetailsOther_MikroID = {$header_id}"; + $this->db_smartone->query($sql); + + $results = $prm['details']; + if ($inp['result_value'] == 'Positif') { + foreach ($results as $k => $v) { + if ($v['xid'] == '0') { + $sql = "INSERT INTO other_mikrodetails( + Other_MikroDetailsOther_MikroID , + Other_MikroDetailsT_AntibioticID, + Other_MikroDetailsValue, + Other_MikroDetailsNote, + Other_MikroDetailsCreated, + Other_MikroDetailsUserID + ) + VALUES( + {$header_id}, + '{$v['T_AntibioticID']}', + '{$v['value']}', + '{$v['note']}', + NOW(), + {$userid} + )"; + $query = $this->db_smartone->query($sql); + } else { + $sql = "UPDATE other_mikrodetails SET + Other_MikroDetailsT_AntibioticID = '{$v['T_AntibioticID']}', + Other_MikroDetailsValue = '{$v['value']}', + Other_MikroDetailsNote = '{$v['note']}', + Other_MikroDetailsIsActive = 'Y', + Other_MikroDetailsUserID = {$userid} + WHERE + Other_MikroDetailsID = {$v['xid']}"; + //echo $sql; + $query = $this->db_smartone->query($sql); + } + } + } + + + $result = array("total" => 1, "records" => array(), "sql" => ''); + $this->sys_ok($result); + exit; + } + + + function get_doctors_preparasi_sperma() + { + $prm = $this->sys_input; + // $id = $prm["id"]; + + $sql = " SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 10 AND + M_DoctorSOIsActive = 'Y' + ORDER BY M_DoctorName ASC"; + //echo $sql; + $query = $this->db_smartone->query($sql); + $rows = $query->result_array(); + $sql = " + SELECT '0' as id, 'Belum memilih metode' as name + UNION + SELECT M_MethodeSpermaID as id, M_MethodeSpermaName as name + FROM m_methodesperma + WHERE + M_MethodeSpermaIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $methodes = $this->db_smartone->query($sql)->result_array(); + + + $this->sys_ok(["records" => $rows, "methodes" => $methodes]); + } + + + function getpreparasispermaresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT other_preparasisperma.*, + Other_PreparasiSpermaID as xid, + Other_PreparasiSpermaT_OrderDetailID as orderdetail_id, + IFNULL(Other_PreparasiSpermaM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_PreparasiSpermaM_DoctorID) OR Other_PreparasiSpermaM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name, + IFNULL(M_MethodeSpermaID,0) as methode_id, + IFNULL(M_MethodeSpermaName,'') as methode_name + FROM other_preparasisperma + LEFT JOIN m_doctor ON Other_PreparasiSpermaM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + LEFT JOIN m_methodesperma ON Other_PreparasiSpermaM_MethodeSpermaID = M_MethodeSpermaID AND + M_MethodeSpermaIsActive = 'Y' + WHERE + Other_PreparasiSpermaT_OrderDetailID = {$id} AND Other_PreparasiSpermaIsActive = 'Y' + GROUP BY Other_PreparasiSpermaID"; + $query = $this->db_smartone->query($sql); + + if ($query) { + $rows = $query->row_array(); + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 10 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $sql = " + SELECT '0' as id, 'Belum memilih metode' as name + UNION + SELECT M_MethodeSpermaID as id, M_MethodeSpermaName as name + FROM m_methodesperma + WHERE + M_MethodeSpermaIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $methodes = $this->db_smartone->query($sql)->result_array(); + $images = array(); + $sql = "SELECT Other_PreparasiSpermaImgID as xid, + Other_PreparasiSpermaImgType as type, + CONCAT('/one-media/one-image-nonlab/',Other_PreparasiSpermaImgNewName) as image_url + FROM t_orderdetail + JOIN other_preparasisperma_img ON Other_PreparasiSpermaImgT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND + Other_PreparasiSpermaImgIsActive = 'Y' + WHERE + T_OrderDetailID = {$id} AND + T_OrderDetailIsActive = 'Y' + GROUP BY Other_PreparasiSpermaImgID"; + //echo $sql; + $images = $this->db_smartone->query($sql)->result_array(); + + $rst = array('doctors' => $doctors, 'methodes' => $methodes, 'results' => $rows, 'images' => $images); + $this->sys_ok(["records" => $rst]); + } else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + + function uploadimage_preparasi_sperma() + { + if (! $this->isLogin) { + $this->sys_error("Invalid Token"); + exit; + } + + $userid = $this->sys_user["M_UserID"]; + $data = []; + //print_r($_SERVER); + + $prm = $this->sys_input; + $orderid = $this->input->post('orderid'); + $type = $this->input->post('type'); + $labnumber = $this->input->post('labnumber'); + $sql = "UPDATE other_preparasisperma_img SET + Other_PreparasiSpermaImgIsActive = 'N', + Other_PreparasiSpermaImgUserID = {$userid} + WHERE + Other_PreparasiSpermaImgT_OrderHeaderID = {$orderid} AND + Other_PreparasiSpermaImgType = '{$type}'"; + //echo $sql; + $this->db_onedev->query($sql); + //$config['upload_path'] = 'assets/'; + + $path = '/home/one/project/one/one-media/one-image-nonlab/'; + //echo $path; + $config['upload_path'] = $path; + $config['allowed_types'] = 'jpg|jpeg|png|gif'; + + $config['max_size'] = '10000'; + $count = count($_FILES['files']['name']); + //echo $count; + $this->load->library('upload', $config); + + $error = []; + for ($i = 0; $i < $count; $i++) { + + + if (!empty($_FILES['files']['name'][$i])) { + + + + $_FILES['file']['name'] = $_FILES['files']['name'][$i]; + + $_FILES['file']['type'] = $_FILES['files']['type'][$i]; + + $_FILES['file']['tmp_name'] = $_FILES['files']['tmp_name'][$i]; + + $_FILES['file']['error'] = $_FILES['files']['error'][$i]; + + $_FILES['file']['size'] = $_FILES['files']['size'][$i]; + + + + $namex = $orderid . '-' . $labnumber . '-' . $this->generateRandomString(5); + //echo $namex; + + $config['file_name'] = $namex; + $this->upload->initialize($config); + //echo $config['file_name'] ; + + + + + + if ($this->upload->do_upload('file')) { + + $uploadData = $this->upload->data(); + + $filename = $uploadData['file_name']; + //echo $filename; + + + $sql = "INSERT INTO other_preparasisperma_img ( + Other_PreparasiSpermaImgT_OrderHeaderID, + Other_PreparasiSpermaImgType, + Other_PreparasiSpermaImgOldName, + Other_PreparasiSpermaImgNewName, + Other_PreparasiSpermaImgCreated, + Other_PreparasiSpermaImgUserID + ) + VALUES( + {$orderid}, + '{$type}', + '{$_FILES['files']['name'][$i]}', + '{$filename}', + NOW(), + {$userid} + + )"; + //echo $sql; + $this->db_onedev->query($sql); + $xlast_id = $this->db_onedev->insert_id(); + $data['totalFiles'][] = array('xid' => $xlast_id, 'type' => $type, 'image_url' => '/one-media/one-image-nonlab/' . $filename); + } else { + $error = array('error' => $this->upload->display_errors()); + } + } + } + + $result = array("total" => count($data['totalFiles']), "records" => $data['totalFiles'], 'errors' => $error); + $this->sys_ok($result); + } + + + function saveresult_preparasi_sperma() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = isset($inp['doctor']) ? $inp['doctor'] : 0; + $methode_id = isset($inp['methode']) ? $inp['methode'] : 0; + $orderdetail_id = $inp['orderdetailid']; + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + if ($prm['xid'] == '0') { + $sql = "INSERT INTO other_preparasisperma( + Other_PreparasiSpermaM_DoctorID, + Other_PreparasiSpermaT_OrderDetailID, + Other_PreparasiSpermaPreMotilitasA, + Other_PreparasiSpermaPreMotilitasB, + Other_PreparasiSpermaPreMotilitasC, + Other_PreparasiSpermaPreKonsentrasi, + Other_PreparasiSpermaPreKontaminan, + Other_PreparasiSpermaPostMotilitasA, + Other_PreparasiSpermaPostMotilitasB, + Other_PreparasiSpermaPostMotilitasC, + Other_PreparasiSpermaPostKonsentrasi, + Other_PreparasiSpermaPostKontaminan, + Other_PreparasiSpermaPreVolume, + Other_PreparasiSpermaPostVolume, + Other_PreparasiSpermaM_MethodeSpermaID, + Other_PreparasiSpermaNote, + Other_PreparasiSpermaUserID, + Other_PreparasiSpermaCreated + ) + VALUES( + {$doctor_id}, + {$orderdetail_id}, + '{$prm['Other_PreparasiSpermaPreMotilitasA']}', + '{$prm['Other_PreparasiSpermaPreMotilitasB']}', + '{$prm['Other_PreparasiSpermaPreMotilitasC']}', + '{$prm['Other_PreparasiSpermaPreKonsentrasi']}', + '{$prm['Other_PreparasiSpermaPreKontaminan']}', + '{$prm['Other_PreparasiSpermaPostMotilitasA']}', + '{$prm['Other_PreparasiSpermaPostMotilitasB']}', + '{$prm['Other_PreparasiSpermaPostMotilitasC']}', + '{$prm['Other_PreparasiSpermaPostKonsentrasi']}', + '{$prm['Other_PreparasiSpermaPostKontaminan']}', + '{$prm['Other_PreparasiSpermaPreVolume']}', + '{$prm['Other_PreparasiSpermaPostVolume']}', + '{$methode_id}', + '{$prm['Other_PreparasiSpermaNote']}', + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } else { + $sql = "SELECT * FROM other_preparasisperma WHERE Other_PreparasiSpermaT_OrderDetailID = {$orderdetail_id} AND Other_PreparasiSpermaIsActive = 'Y'"; + $data_header = $this->db_smartone->query($sql)->row_array(); + $header_id = $data_header['Other_PreparasiSpermaID']; + $sql = "UPDATE other_preparasisperma SET + Other_PreparasiSpermaM_DoctorID = {$doctor_id}, + Other_PreparasiSpermaPreMotilitasA = '{$prm['Other_PreparasiSpermaPreMotilitasA']}', + Other_PreparasiSpermaPreMotilitasB = '{$prm['Other_PreparasiSpermaPreMotilitasB']}', + Other_PreparasiSpermaPreMotilitasC = '{$prm['Other_PreparasiSpermaPreMotilitasC']}', + Other_PreparasiSpermaPreKonsentrasi = '{$prm['Other_PreparasiSpermaPreKonsentrasi']}', + Other_PreparasiSpermaPreKontaminan = '{$prm['Other_PreparasiSpermaPreKontaminan']}', + Other_PreparasiSpermaPostMotilitasA = '{$prm['Other_PreparasiSpermaPostMotilitasA']}', + Other_PreparasiSpermaPostMotilitasB = '{$prm['Other_PreparasiSpermaPostMotilitasB']}', + Other_PreparasiSpermaPostMotilitasC = '{$prm['Other_PreparasiSpermaPostMotilitasC']}', + Other_PreparasiSpermaPostKonsentrasi = '{$prm['Other_PreparasiSpermaPostKonsentrasi']}', + Other_PreparasiSpermaPostKontaminan = '{$prm['Other_PreparasiSpermaPostKontaminan']}', + Other_PreparasiSpermaPreVolume = '{$prm['Other_PreparasiSpermaPreVolume']}', + Other_PreparasiSpermaPostVolume = '{$prm['Other_PreparasiSpermaPostVolume']}', + Other_PreparasiSpermaM_MethodeSpermaID = '{$methode_id}', + Other_PreparasiSpermaNote = '{$prm['Other_PreparasiSpermaNote']}', + Other_PreparasiSpermaUserID = {$userid} + WHERE + Other_PreparasiSpermaID = {$header_id}"; + $this->db_smartone->query($sql); + } + + + $result = array("total" => 1, "records" => array(), "sql" => ''); + $this->sys_ok($result); + exit; + } + + function getdnafragmentasiresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT other_dnafragmentasi.*, + Other_DnaFragmentasiID as xid, + Other_DnaFragmentasiT_OrderDetailID as orderdetail_id, + IFNULL(Other_DnaFragmentasiM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_DnaFragmentasiM_DoctorID) OR Other_DnaFragmentasiM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name, + IFNULL(Other_DnaFragmentasiOther_DnaFragmentasiMethodeID,0) as methode_id, + IFNULL(Other_DnaFragmentasiMethodeName,'') as methode_name, + Other_DnaFragmentasiHaloLuas as halo_luas, + Other_DnaFragmentasiHaloSedang as halo_sedang, + Other_DnaFragmentasiHaloSempit as halo_sempit, + Other_DnaFragmentasiTanpaHalo as tanpa_halo, + Other_DnaFragmentasiDFI as dfi, + Other_DnaFragmentasiKesimpulan as kesimpulan, + Other_DnaFragmentasiCatatan as catatan + FROM other_dnafragmentasi + LEFT JOIN m_doctor ON Other_DnaFragmentasiM_DoctorID = M_DoctorID + LEFT JOIN other_dnafragmentasimethode ON Other_DnaFragmentasiOther_DnaFragmentasiMethodeID = Other_DnaFragmentasiMethodeID + WHERE + Other_DnaFragmentasiT_OrderDetailID = {$id} AND Other_DnaFragmentasiIsActive = 'Y' + GROUP BY Other_DnaFragmentasiID + LIMIT 1"; + //echo $sql; + $query = $this->db_smartone->query($sql); + + if ($query) { + $rows = $query->row_array(); + if (!$rows) { + $rows = array( + 'xid' => 0, + 'orderdetail_id' => $id, + 'doctor_id' => 0, + 'doctor_name' => '', + 'methode_id' => 0, + 'methode_name' => '', + 'halo_luas' => '', + 'halo_sedang' => '', + 'tanpa_halo' => '', + 'dfi' => '', + 'kesimpulan' => '', + 'catatan' => '' + ); + } + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID + WHERE + M_DoctorSONat_SubGroupID = 4 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + + $sql = " + SELECT '0' as id, 'Belum memilih metode' as name + UNION + SELECT Other_DnaFragmentasiMethodeID as id, Other_DnaFragmentasiMethodeName as name + FROM other_dnafragmentasimethode + WHERE + Other_DnaFragmentasiMethodeIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $methodes = $this->db_smartone->query($sql)->result_array(); + + + $rst = array('doctors' => $doctors, 'methodes' => $methodes, 'results' => $rows); + $this->sys_ok(["records" => $rst]); + } else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + function saveresult_dnafragmentasi() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = $inp['doctor']['id']; + $methode_id = $inp['methode']['id']; + $orderdetail_id = $inp['results']['orderdetail_id']; + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + if (intval($prm['xid']) == 0) { + $sql = "INSERT INTO other_dnafragmentasi( + Other_DnaFragmentasiT_OrderDetailID, + Other_DnaFragmentasiM_DoctorID, + Other_DnaFragmentasiOther_DnaFragmentasiMethodeID, + Other_DnaFragmentasiHaloLuas, + Other_DnaFragmentasiHaloSedang, + Other_DnaFragmentasiHaloSempit, + Other_DnaFragmentasiTanpaHalo, + Other_DnaFragmentasiDFI, + Other_DnaFragmentasiKesimpulan, + Other_DnaFragmentasiCatatan, + Other_DnaFragmentasiUserID, + Other_DnaFragmentasiLastUpdated + ) + VALUES( + {$orderdetail_id}, + {$doctor_id}, + {$methode_id}, + '{$prm['halo_luas']}', + '{$prm['halo_sedang']}', + '{$prm['halo_sempit']}', + '{$prm['tanpa_halo']}', + '{$prm['dfi']}', + '{$prm['kesimpulan']}', + '{$prm['catatan']}', + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } else { + $sql = "UPDATE other_dnafragmentasi SET + Other_DnaFragmentasiT_OrderDetailID = {$orderdetail_id}, + Other_DnaFragmentasiM_DoctorID = {$doctor_id}, + Other_DnaFragmentasiOther_DnaFragmentasiMethodeID = '{$methode_id}', + Other_DnaFragmentasiHaloLuas = '{$prm['halo_luas']}', + Other_DnaFragmentasiHaloSedang = '{$prm['halo_sedang']}', + Other_DnaFragmentasiHaloSempit = '{$prm['halo_sempit']}', + Other_DnaFragmentasiTanpaHalo = '{$prm['tanpa_halo']}', + Other_DnaFragmentasiDFI = '{$prm['dfi']}', + Other_DnaFragmentasiKesimpulan = '{$prm['kesimpulan']}', + Other_DnaFragmentasiCatatan = '{$prm['catatan']}', + Other_DnaFragmentasiLastUpdated = NOW(), + Other_DnaFragmentasiUserID = {$userid} + WHERE + Other_DnaFragmentasiID = {$prm['xid']}"; + //echo $sql; + $this->db_smartone->query($sql); + } + + + $result = array("total" => 1, "records" => array(), "sql" => ''); + $this->sys_ok($result); + exit; + } +} diff --git a/application/controllers/mockup/process/resultentry-v23/9/Re_px.php b/application/controllers/mockup/process/resultentry-v23/9/Re_px.php index 6be4d6c2..655a10d5 100644 --- a/application/controllers/mockup/process/resultentry-v23/9/Re_px.php +++ b/application/controllers/mockup/process/resultentry-v23/9/Re_px.php @@ -1,2556 +1,2553 @@ -db_smartone = $this->load->database("onedev", true); - $this->load->helper(array('form', 'url')); - } - function getMethodeID($natTestID) - { - $sql = "select M_MethodePriorityNat_MethodeID MethodeID, Nat_MethodeName - from - m_methode_priority - join nat_methode on Nat_MethodeID = M_MethodePriorityNat_MethodeID - and Nat_MethodeIsActive = 'Y' - join m_instrumentmethode on M_InstrumentMethodeNat_MethodeID = Nat_MethodeID and M_InstrumentMethodeIsActive = 'Y' - join nat_instrument on M_InstrumentMethodeNat_InstrumentID = Nat_InstrumentID - and Nat_InstrumentIsActive ='Y' - where M_MethodePriorityIsActive = 'Y' - and M_MethodePriorityNat_TestID = $natTestID - and M_MethodePriorityM_DayOfWeekID = dayofweek(now()) - order by M_MethodePriorityNumber desc - limit 0,1 "; - $qry = $this->db->query($sql); - if ($qry) { - $rows = $qry->result_array(); - if (count($rows) > 0) return array($rows[0]["MethodeID"], $rows[0]["Nat_MethodeName"]); - } - //2nd - $sql = "select - M_InstrumentMethodeNat_MethodeID MethodeID, Nat_MethodeName - from m_instrumentmethode - join nat_methode on M_InstrumentMethodeNat_MethodeID = Nat_MethodeID - and Nat_MethodeIsActive = 'Y' - join nat_instrument on M_InstrumentMethodeNat_InstrumentID = Nat_InstrumentID - and Nat_InstrumentIsActive ='Y' - where M_InstrumentMethodeNat_TestID = $natTestID - and M_InstrumentMethodeIsActive = 'Y' - order by M_InstrumentMethodePriority desc - limit 0,1"; - $qry = $this->db->query($sql); - if ($qry) { - $rows = $qry->result_array(); - if (count($rows) > 0) return array($rows[0]["MethodeID"], $rows[0]["Nat_MethodeName"]); - } - // - $sql = "select Nat_NormalValueNat_MethodeID MethodeID, Nat_MethodeName - from - nat_normalvalue - join nat_methode on Nat_NormalValueNat_MethodeID = Nat_MethodeID - and Nat_MethodeIsActive = 'Y' - where Nat_NormalValueNat_TestID = $natTestID - and Nat_NormalValueIsActive = 'Y' - order by Nat_NormalValueID - limit 0,1"; - $qry = $this->db->query($sql); - if ($qry) { - $rows = $qry->result_array(); - if (count($rows) > 0) return array($rows[0]["MethodeID"], $rows[0]["Nat_MethodeName"]); - } - return array(0, ""); - } - function get_normal_value($methodeID, $natTestID, $sexID, $ageInDay) - { - $sql = "select fn_sampling_get_normal($methodeID, $natTestID, $sexID, $ageInDay) as normalValueID"; - $qry = $this->db->query($sql); - if ($qry) { - $rows = $qry->result_array(); - if (count($rows) > 0) return $rows[0]["normalValueID"]; - } - return 0; - } - function fn_fix_normal($order_id) - { - $sql = "select - T_OrderDetailID, M_PatientM_SexID, fn_global_age_count_day(M_PatientDOB, date(T_OrderHeaderDate)) Dob , - T_TestNat_TestID - from t_orderheader - join m_patient on T_OrderHeaderID = $order_id and T_OrderHeaderM_PatientID = M_PatientID - join t_orderdetail on T_OrderDetailT_OrderHeaderID = T_OrderHeaderID - and T_OrderDetailIsACtive = 'Y' - and ( T_OrderDetailNat_NormalValueID is null or T_OrderDetailNat_NormalValueID = 0 ) - join t_test on T_OrderDetailT_TestID = T_TestID and T_TestIsResult = 'Y' "; - $qry = $this->db->query($sql); - if (! $qry) { - return; - } - $rows = $qry->result_array(); - if (count($rows) == 0) return; - $sql_u = "update t_orderdetail - join nat_normalvalue on T_OrderDetailID = ? and Nat_NormalValueID = ? - set - T_OrderDetailNat_NormalValueID = Nat_NormalValueID, - T_OrderDetailNormalValueNote = Nat_NormalValueNote, - T_OrderDetailNormalValueDescription = Nat_NormalValueDescription, - T_OrderDetailMinValue = Nat_NormalValueMinValue, - T_OrderDetailMaxValue = Nat_NormalValueMaxValue, - T_OrderDetailMinValueInclusive = Nat_NormalValueMinValueInclusive, - T_OrderDetailMaxValueInclusive = Nat_NormalValueMaxValueInclusive, - T_OrderDetailNat_MethodeID = ?, - T_OrderdetailNat_MethodeName =?"; - - foreach ($rows as $r) { - $T_OrderDetailID = $r["T_OrderDetailID"]; - $sexID = $r["M_PatientM_SexID"]; - $ageInDay = $r["Dob"]; - $natTestID = $r["T_TestNat_TestID"]; - list($methodeID, $methodeName) = $this->getMethodeID($natTestID); - if ($methodeID == 0) continue; - $normalValueID = $this->get_normal_value($methodeID, $natTestID, $sexID, $ageInDay); - if ($normalValueID == 0) return; - $this->db->query($sql_u, array($T_OrderDetailID, $normalValueID, $methodeID, $methodeName)); - } - } - function update_order_sample($targetID, $sourceID) - { - $sql = "update t_ordersample target - join t_ordersample source on - target.T_OrderSampleID = ? - and target.T_OrderSampleWorklistReceive = 'N' - and source.T_OrderSampleID = ? - set - target.T_OrderSampleSampling = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSampling, source.T_OrderSampleSampling), - target.T_OrderSampleSamplingDate = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingDate, source.T_OrderSampleSamplingDate), - target.T_OrderSampleSamplingTime = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingTime, source.T_OrderSampleSamplingTime), - target.T_OrderSampleSamplingUserID = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingUserID, source.T_OrderSampleSamplingUserID), - - target.T_OrderSampleReceive = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceive, source.T_OrderSampleReceive), - target.T_OrderSampleReceiveDate = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveDate, source.T_OrderSampleReceiveDate), - target.T_OrderSampleReceiveTime = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveTime, source.T_OrderSampleReceiveTime), - target.T_OrderSampleReceiveUserID = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveUserID, source.T_OrderSampleReceiveUserID), - - target.T_OrderSampleVerification = if(target.T_OrderSampleVerification='Y',target.T_OrderSampleVerification, source.T_OrderSampleVerification), - target.T_OrderSampleVerificationDate =if(target.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationDate, source.T_OrderSampleVerificationDate), - target.T_OrderSampleVerificationTime =if(source.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationTime, source.T_OrderSampleVerificationTime), - target.T_OrderSampleVerificationUserID =if(source.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationUserID, source.T_OrderSampleVerificationUserID), - - target.T_OrderSampleProcessing = if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessing, source.T_OrderSampleProcessing), - target.T_OrderSampleProcessingDate= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingDate, source.T_OrderSampleProcessingDate), - target.T_OrderSampleProcessingTime= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingTime, source.T_OrderSampleProcessingTime), - target.T_OrderSampleProcessingUserID= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingUserID, source.T_OrderSampleProcessingUserID), - - target.T_OrderSampleReceiveHandling =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandling, source.T_OrderSampleReceiveHandling ), - target.T_OrderSampleReceiveHandlingDate =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingDate, source.T_OrderSampleReceiveHandlingDate), - target.T_OrderSampleReceiveHandlingTime =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingTime, source.T_OrderSampleReceiveHandlingTime), - target.T_OrderSampleReceiveHandlingUserID =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingUserID, source.T_OrderSampleReceiveHandlingUserID), - - target.T_OrderSampleHandling = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandling, source.T_OrderSampleHandling), - target.T_OrderSampleHandlingDate = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingDate, source.T_OrderSampleHandlingDate), - target.T_OrderSampleHandlingTime = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingTime, source.T_OrderSampleHandlingTime), - target.T_OrderSampleHandlingUserID = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingUserID, source.T_OrderSampleHandlingUserID), - - target.T_OrderSampleWorklistReceive = source.T_OrderSampleWorklistReceive, - target.T_OrderSampleWorklistReceiveDatetime = source.T_OrderSampleWorklistReceiveDateTime, - target.T_OrderSampleWorklistReceiveUserID = source.T_OrderSampleWorklistReceiveUserID - "; - $qry = $this->db->query($sql, array($targetID, $sourceID)); - if (! $qry) { - echo json_encode(array("status" => "ERR", "message" => print_r($this->db->error(), true))); - exit; - } - } - function fix_sample_serum($headerID) - { - //cari t_ordersample yg belum worklist receive dengan code 017% - $sql = "select T_OrderSampleID - from t_ordersample - join t_sampletype on - T_OrderSampleT_OrderHeaderID = ? - and T_OrderSampleWorklistReceive = 'N' - and T_OrderSampleIsActive = 'Y' - and T_OrderSampleT_SampleTypeID = T_SampletypeID - and T_SampleTypeCode like '017%' - "; - $qry = $this->db->query($sql, array($headerID)); - if (!$qry) { - echo json_encode(array("status" => "ERR", "message" => print_r($this->db->error(), true))); - exit; - } - $rows = $qry->result_array(); - if (count($rows) == 0) return; - //cari T_OrderSample yang sudah di receive yg terakhir - $sql = "select T_OrderSampleID - from t_ordersample - join t_sampletype on - T_OrderSampleT_OrderHeaderID = ? - and T_OrderSampleWorklistReceive = 'Y' - and T_OrderSampleIsActive = 'Y' - and T_OrderSampleT_SampleTypeID = T_SampletypeID - and T_SampleTypeCode like '017%' - order by T_OrderSampleWorklistReceiveDatetime desc - limit 0,1 - "; - $qry = $this->db->query($sql, array($headerID)); - if (!$qry) { - echo json_encode(array("status" => "ERR", "message" => print_r($this->db->error(), true))); - exit; - } - $rcv_rows = $qry->result_array(); - if (count($rcv_rows) == 0) return; - - //print_r($rows); - //print_r($rcv_rows); - $rcv_T_OrderSampleID = $rcv_rows[0]["T_OrderSampleID"]; - //ada yg belum di receive - foreach ($rows as $r) { - $T_OrderSampleID = $r["T_OrderSampleID"]; - $this->update_order_sample($T_OrderSampleID, $rcv_T_OrderSampleID); - } - } - public function search() - { - $prm = $this->sys_input; - $max_rst = 99; - - $id = $prm["order_id"]; - if ($id > 0) { - $this->fix_sample_serum($id); - $this->fn_fix_normal($id); - } - $lang = $this->lang_default_code; - $lang_id = isset($prm['lang_id']) ? $prm['lang_id'] : '0'; - - if ($lang_id != 0) { - $l = $this->db_smartone->where("Nat_LangID", $lang_id)->get("nat_lang")->row(); - $lang = $l->Nat_LangCode; - } - - //tambahan fajri - $sql = " UPDATE t_orderdetail - JOIN t_test ON T_OrderDetailT_TestID = T_TestID - SET T_OrderDetailT_TestIsResult = T_TestIsResult - WHERE - T_OrderDetailT_OrderHeaderID = {$id} AND - T_OrderDetailT_TestIsResult = '' AND - T_OrderDetailIsActive = 'Y'"; - $this->db_smartone->query($sql); - - $tot_count = 0; - $lq = ""; - $group_id = 0; - if (isset($prm['group_id'])) - $group_id = $prm['group_id']; - - if ($group_id != 0) { - $sql = "select distinct T_WorklistDetailNat_TestID Nat_TestID - from t_worklistdetailv2 - where T_WorklistDetailT_WorklistID = {$group_id}"; - $qry = $this->db_smartone->query($sql); - $rows = $qry->result_array(); - $nat_test_ids = "0"; - foreach ($rows as $r) { - $nat_test_ids .= ", " . $r["Nat_TestID"]; - } - $q_group = " ( $nat_test_ids ) "; - - $sql = " - SELECT a1.*, cOUNT(a2.T_OrderDetailID) level - FROM ( - SELECT IFNULL(y.T_OrderDetailT_TestID, x.T_OrderDetailT_TestID) t_testid, - IFNULL(y.T_OrderDetailT_TestName, y.T_OrderDetailT_TestName) t_testname, - y.T_OrderDetailResult result, y.T_OrderDetailResult result_old, y.T_OrderDetailNote note, y.T_OrderDetailNote note_old, - y.T_OrderDetailID id, - y.T_OrderDetailT_TestIsResult is_result, a.T_TestIsQuantitative is_quantitative, - y.T_OrderDetailResultFlag result_flag, - y.T_OrderDetailNat_NormalValueID normal_id, - y.T_OrderDetailNormalValueNote normal_note, y.T_OrderDetailNat_UnitName unit_name, - y.T_OrderdetailNat_MethodeID methode_id, y.T_OrderdetailNat_MethodeName methode_name, - a.T_TestNat_TestID nattest_id, a.T_TestID tx_id, count(T_ResultInstrumentID) as result_instrument_n, - y.T_OrderDetailVerification, T_OrderSampleReceive sample_receive, - T_OrderSampleProcessing sample_processing, T_OrderSampleWorklistReceive sample_worklist_receive, - IF(T_OrderDetailAddOnPreAnalytic = 'Y', T_OrderDetailAddOnPreAnalytic, PreAnalyticIsOk) pre_analytic, - T_OrderDetailAddOnPreAnalytic, - T_OrderHeaderID order_id, y.T_OrderDetailT_TestSasCode test_sas_code, - tx.T_TestSasCode, - T_OrderDetailAddOnResample `resample`, T_OrderDetailAddOnResampleStatus resample_status, - T_OrderDetailAddOnRef ref, y.T_OrderDetailVerification verification, y.T_OrderDetailValidation validation, - T_OrderPromiseDateTime, Group_ResultName as ResultGroupName - FROM t_orderdetail x - left join t_orderpromise on x.T_OrderDetailT_OrderPromiseID = T_OrderPromiseID - JOIN t_test tx ON x.T_OrderDetailT_TestID = T_TestID - JOIN t_test tcheck on tcheck.T_TestNat_TestID in {$q_group} - and ( tx.T_TestID = tcheck.T_TestID or tx.T_TestSasCode like concat(tcheck.T_TestSasCode,'%')) - LEFT JOIN group_resultdetail ON Group_ResultDetailT_TestID = x.T_OrderDetailT_TestID AND Group_ResultDetailIsActive = 'Y' - LEFT JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND Group_ResultFlagNonLab = 'N' - LEFT JOIN t_orderdetail y ON x.T_OrderDetailT_TestSasCode LIKE CONCAT(y.T_OrderDetailT_TestSasCode, '%') - AND x.T_OrderDetailT_OrderHeaderID = y.T_OrderDetailT_OrderHeaderID - AND y.T_OrderDetailIsActive = 'Y' - LEFT JOIN t_orderdetailaddon ON x.T_OrderDetailID = T_OrderDetailAddOnT_OrderDetailID - JOIN t_orderheader ON y.T_OrderDetailT_OrderHeaderID = T_OrderHeaderID - LEFT JOIN t_test a ON y.T_OrderDetailT_TestID = a.T_TestID - AND a.T_TestIsNonLab = '' - LEFT JOIN (SELECT T_OrderSampleT_SampleTypeID, T_OrderSampleReceive, T_OrderSampleProcessing, T_OrderSampleWorklistReceive - FROM t_ordersample WHERE T_OrderSampleT_OrderHeaderID = {$id} - AND T_OrderSampleIsactive = 'Y' - GROUP BY T_OrderSampleT_SampleTypeID) os ON a.T_TestT_SampleTypeID = os.T_OrderSampleT_SampleTypeID - or os.T_OrderSampleT_SampleTypeID = fn_sampletype_from_local(a.T_TestNat_TestID) - - LEFT JOIN t_resultinstrument ON T_ResultInstrumentT_OrderDetailID = x.T_OrderDetailID - LEFT JOIN pre_analytic ON PreAnalyticNat_TestID = a.T_TestNat_TestID AND PreAnalyticDate = date(now()) and PreAnalyticIsActive = 'Y' - WHERE x.T_OrderDetailT_OrderHeaderID = {$id} - AND x.T_OrderDetailIsActive = 'Y' - GROUP BY y.T_OrderDetailT_TestID - ORDER BY y.T_OrderDetailT_TestSasCode ASC - ) a1 - - LEFT JOIN t_orderdetail a2 ON a2.T_OrderDetailT_OrderHeaderID = a1.order_id - AND a2.T_OrderDetailIsActive = 'Y' - AND a1.test_sas_code LIKE CONCAT(a2.T_OrderDetailT_testSasCode, '%') - GROUP BY a1.t_testid - order by a1.test_sas_code -"; - $query = $this->db_smartone->query($sql); - $lq = $this->db_smartone->last_query(); - } else { - $sql = " - SELECT a1.*, cOUNT(a2.T_OrderDetailID) level - FROM ( - SELECT IFNULL(y.T_OrderDetailT_TestID, x.T_OrderDetailT_TestID) t_testid, - IFNULL(y.T_OrderDetailT_TestName, y.T_OrderDetailT_TestName) t_testname, - y.T_OrderDetailResult result, y.T_OrderDetailResult result_old, y.T_OrderDetailNote note, y.T_OrderDetailNote note_old, - y.T_OrderDetailID id, - y.T_OrderDetailT_TestIsResult is_result, a.T_TestIsQuantitative is_quantitative, - y.T_OrderDetailResultFlag result_flag, - y.T_OrderDetailNat_NormalValueID normal_id, - y.T_OrderDetailNormalValueNote normal_note, y.T_OrderDetailNat_UnitName unit_name, - y.T_OrderdetailNat_MethodeID methode_id, y.T_OrderdetailNat_MethodeName methode_name, - a.T_TestNat_TestID nattest_id, a.T_TestID tx_id, count(T_ResultInstrumentID) as result_instrument_n, - y.T_OrderDetailVerification, T_OrderSampleReceive sample_receive, - T_OrderSampleProcessing sample_processing, T_OrderSampleWorklistReceive sample_worklist_receive, - IF(T_OrderDetailAddOnPreAnalytic = 'Y', T_OrderDetailAddOnPreAnalytic, PreAnalyticIsOk) pre_analytic, - T_OrderDetailAddOnPreAnalytic, - T_OrderHeaderID order_id, y.T_OrderDetailT_TestSasCode test_sas_code, - tx.T_TestSasCode, - T_OrderDetailAddOnResample `resample`, T_OrderDetailAddOnResampleStatus resample_status, - T_OrderDetailAddOnRef ref, y.T_OrderDetailVerification verification, y.T_OrderDetailValidation validation, - T_OrderPromiseDateTime , Group_ResultName as ResultGroupName - FROM t_orderdetail x - left join t_orderpromise on x.T_OrderDetailT_OrderPromiseID = T_OrderPromiseID - JOIN t_test tx ON x.T_OrderDetailT_TestID = T_TestID - LEFT JOIN group_resultdetail ON Group_ResultDetailT_TestID = x.T_OrderDetailT_TestID AND Group_ResultDetailIsActive = 'Y' - LEFT JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND Group_ResultFlagNonLab = 'N' - LEFT JOIN t_orderdetail y ON x.T_OrderDetailT_TestSasCode LIKE CONCAT(y.T_OrderDetailT_TestSasCode, '%') - AND x.T_OrderDetailT_OrderHeaderID = y.T_OrderDetailT_OrderHeaderID - AND y.T_OrderDetailIsActive = 'Y' - - LEFT JOIN t_orderdetailaddon ON x.T_OrderDetailID = T_OrderDetailAddOnT_OrderDetailID - - JOIN t_orderheader ON y.T_OrderDetailT_OrderHeaderID = T_OrderHeaderID - LEFT JOIN t_test a ON y.T_OrderDetailT_TestID = a.T_TestID - AND a.T_TestIsNonLab = '' - LEFT JOIN (SELECT T_OrderSampleT_SampleTypeID, T_OrderSampleReceive, T_OrderSampleProcessing, T_OrderSampleWorklistReceive - FROM t_ordersample WHERE T_OrderSampleT_OrderHeaderID = {$id} - AND T_OrderSampleIsactive = 'Y' - GROUP BY T_OrderSampleT_SampleTypeID) os ON a.T_TestT_SampleTypeID = os.T_OrderSampleT_SampleTypeID - or os.T_OrderSampleT_SampleTypeID = fn_sampletype_from_local(a.T_TestNat_TestID) - - LEFT JOIN t_resultinstrument ON T_ResultInstrumentT_OrderDetailID = x.T_OrderDetailID - LEFT JOIN pre_analytic ON PreAnalyticNat_TestID = a.T_TestNat_TestID AND PreAnalyticDate = date(now()) and PreAnalyticIsActive = 'Y' - WHERE x.T_OrderDetailT_OrderHeaderID = {$id} - AND x.T_OrderDetailIsActive = 'Y' - GROUP BY y.T_OrderDetailT_TestID - ORDER BY y.T_OrderDetailT_TestSasCode ASC - ) a1 - - LEFT JOIN t_orderdetail a2 ON a2.T_OrderDetailT_OrderHeaderID = a1.order_id - AND a2.T_OrderDetailIsActive = 'Y' - AND a1.test_sas_code LIKE CONCAT(a2.T_OrderDetailT_testSasCode, '%') - GROUP BY a1.t_testid - order by a1.test_sas_code -"; - //echo $sql; - $query = $this->db_smartone->query($sql); - $lq = $this->db_smartone->last_query(); - } - // file_put_contents("/xtmp/re-query.sql",$lq); - - if ($query) { - $rst = []; - $rows = $query->result_array(); - - foreach ($rows as $k => $v) { - - if ($v['is_result'] == "Y" && $v['is_quantitative'] == "N") { - $v['template'] = []; - $x = $this->db_smartone->query("CALL sp_master_resulttemplate_get('{$v['t_testid']}')"); - $this->clean_mysqli_connection($this->db_smartone->conn_id); - if ($x) - $v['template'] = $x->result_array(); - } - - // IF Rujukan, by pas Pre Analytik - if ($v['ref'] == 'Y') - $v['pre_analytic'] = 'Y'; - if ($v["id"] == "885455") { - //sipe workaround - //$v["sample_receive"] = "Y"; - $v["sample_worklist_receive"] = "Y"; - } - $rst[] = $v; - } - - $result = array("total" => $tot_count, "records" => $rst, "total_display" => sizeof($rows), "q" => $lq); - $this->sys_ok($result); - } else { - $this->sys_error_db("RE Px rows", $this->db_smartone); - exit; - } - } - - public function save() - { - $prm = $this->sys_input; - $data = json_decode($prm["data"]); - $lang = $this->lang_default_code; - $lang_id = isset($prm['lang_id']) ? $prm['lang_id'] : '0'; - - if ($lang_id != 0) { - $l = $this->db_smartone->where("Nat_LangID", $lang_id)->get("nat_lang")->row(); - $lang = $l->Nat_LangCode; - } - - $sql_norm = "select T_OrderDetailMinValue, T_OrderDetailMaxValue, - T_OrderDetailMinValueInclusive, T_OrderDetailMaxValueInclusive, - Nat_TestFlagLow, Nat_TestFlagHigh - from t_orderdetail - join t_test on T_OrderDetailT_TestID = T_TestID - join nat_test on T_TestNat_TestID = Nat_TestID and T_TestIsActive = 'Y' - where T_OrderDetailID = ? "; - - $ids = []; - foreach ($data as $k => $v) { - if ($v->resultInstrumentID > 0) { - $sql_i = "select T_ResultInstrumentNat_NormalValueID normalValueID - from t_resultinstrument - where T_ResultInstrumentID = ?"; - $qry_i = $this->db_smartone->query($sql_i, array($v->resultInstrumentID)); - if ($qry_i) { - $rows_i = $qry_i->result_array(); - - if (count($rows_i) > 0) { - $sql_iu = "update t_orderdetail, nat_normalvalue , nat_methode - set T_OrderDetailMinValue = Nat_NormalValueMinValue, - T_OrderDetailMinValueInclusive = Nat_NormalValueMinValueInclusive, - T_OrderDetailMaxValue = Nat_NormalValueMaxValue , - T_OrderDetailMaxValueInclusive = Nat_NormalValueMaxValueInclusive, - T_OrderDetailNormalValueNote = Nat_NormalValueNote, - T_OrderDetailNormalValueDescription = Nat_NormalValueDescription, - T_OrderDetailNat_NormalValueID = Nat_NormalValueID, - T_OrderDetailNat_MethodeID = Nat_NormalValueNat_MethodeID, - T_OrderDetailNat_MethodeName = Nat_MethodeName - where T_OrderDetailID = ? and Nat_NormalValueID = ? - and Nat_NormalValueNat_MethodeID = Nat_MethodeID - "; - $this->db_smartone->query($sql_iu, array($v->id, $rows_i[0]["normalValueID"])); - //file_put_contents("/xtmp/update-nilai-normal", $this->db_smartone->last_query() . "\n", FILE_APPEND); - } - } - } - $y = $this->db_smartone->query("SELECT fn_process_sample_handling_perfect('{$v->order_id}', '{$v->test_id}') c") - ->row(); - $req_status = $y->c; - $qry_norm = $this->db_smartone->query($sql_norm, $v->id); - $result_flag = ""; - if ($qry_norm) { - $rows_norm = $qry_norm->result_array(); - if (count($rows_norm) > 0) { - $r = $rows_norm[0]; - if (is_numeric($v->result)) { - - if ($r["T_OrderDetailMinValueInclusive"] == "Y" && $v->result < $r["T_OrderDetailMinValue"]) { - $result_flag = $r["Nat_TestFlagLow"]; - } - if ($r["T_OrderDetailMinValueInclusive"] == "N" && $v->result <= $r["T_OrderDetailMinValue"]) { - $result_flag = $r["Nat_TestFlagLow"]; - } - if ($r["T_OrderDetailMaxValueInclusive"] == "Y" && $v->result > $r["T_OrderDetailMaxValue"]) { - $result_flag = $r["Nat_TestFlagHigh"]; - } - if ($r["T_OrderDetailMaxValueInclusive"] == "N" && $v->result >= $r["T_OrderDetailMaxValue"]) { - $result_flag = $r["Nat_TestFlagHigh"]; - } - } - } - } - if ($lang == $this->lang_default_code) { - $this->db_smartone->set('T_OrderDetailResult', $v->result) - ->set('T_OrderDetailResultFlag', $result_flag) - ->set('T_OrderDetailNote', $v->note) - ->set('T_OrderDetailReqStatus', $req_status) - ->where('T_OrderDetailID', $v->id) - ->update('t_orderdetail'); - } else { - $this->db_smartone->set('T_OrderDetailLangResult', $v->result) - ->set('T_OrderDetailLangNote', $v->note) - ->where('T_OrderDetailLangID', $v->id) - ->update('t_orderdetaillang'); - } - - $ids[] = $v->id; - } - - // LOG Process - $order = $this->db_smartone->select('T_OrderDetailT_OrderHeaderID id, T_OrderHeaderLabNumber lab_number', false) - ->join('t_orderheader', 'T_OrderHeaderID = T_OrderDetailT_OrderHeaderID') - ->where('T_OrderDetailID', $data[0]->id) - ->get('t_orderdetail') - ->row(); - - $dblog = $this->load->database("onelog", true); - $dblog->set('Log_ProcessCode', 'PROCESS.Result.Entry') - ->set('Log_ProcessOrderID', $order->id) - ->set('Log_ProcessOrderNumber', $order->lab_number) - ->set('Log_ProcessJson', json_encode($data)) - ->set('Log_ProcessUserID', $this->sys_user['M_UserID']) - ->insert('log_process'); - // END OF Log Process - //auto calculation - $this->load->library("Resultcalc"); - $rows = $this->resultcalc->auto($order->id); - - try { - foreach ($ids as $id) { - $this->db_smartone->query("call sp_set_normal_value_flag($id)"); - $this->clean_mysqli_connection($this->db_smartone->conn_id); - } - } catch (Exception $e) { - } - - $this->sys_ok($ids); - } - - public function save_template() - { - $prm = $this->sys_input; - - $n = $this->db_smartone->select("COUNT(T_ResultTemplateID) n") - ->where("T_ResultTemplateT_TestID", $prm['test_id']) - ->where("T_ResultTemplateIsActive", "Y") - ->where("T_ResultTemplateValue", $prm['value']) - ->get('t_resulttemplate') - ->row(); - if ($n->n > 0) { - $this->sys_error_db("Insert Result Template", $this->db_smartone); - return; - } - - $r = $this->db_smartone->set("T_ResultTemplateT_TestID", $prm['test_id']) - ->set("T_ResultTemplateValue", $prm['value']) - ->insert('t_resulttemplate'); - if ($r) { - $template = []; - $x = $this->db_smartone->query("CALL sp_master_resulttemplate_get('{$prm['test_id']}')"); - $this->clean_mysqli_connection($this->db_smartone->conn_id); - if ($x) - $template = $x->result_array(); - - $this->sys_ok($template); - } - } - - public function export() - { - $prm = $this->sys_input; - - $sql = "CALL sp_process_result_lang(?, ?, ?, ?)"; - $query = $this->db_smartone->query($sql, [$prm['order_id'], $prm['lang_id'], $prm['is_si'], $this->sys_user['M_UserID']]); - if ($query) { - $r = $query->row(); - if ($r->status == "OK") { - $this->sys_ok($r->data); - return; - } - - $this->sys_error_db("Message : " . $r->message, $this->db_smartone); - } else { - $this->sys_error_db("Lang Result", $this->db_smartone); - return; - } - } - - public function search_group() - { - $prm = $this->sys_input; - $max_rst = 100; - - // QUERY TOTAL - $sql = "select count(*) total - from t_worklist - where T_WorklistIsActive = 'Y' - order by T_WorklistName ASC"; - $query = $this->db_smartone->query($sql); - - if ($query) { - $tot_count = $query->result_array()[0]["total"]; - } else { - $this->sys_error_db("worklist count", $this->db_smartone); - exit; - } - - $sql = "select T_WorklistID group_id, T_WorklistName group_name - from t_worklist - where T_WorklistIsActive = 'Y' - order by T_WorklistName ASC - limit 0, {$max_rst}"; - $query = $this->db_smartone->query($sql); - - if ($query) { - $rows = $query->result_array(); - foreach ($rows as $k => $v) - $rows[$k]['data'] = json_decode($v['data']); - $result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows), "q" => $this->db_smartone->last_query()); - $this->sys_ok($result); - } else { - $this->sys_error_db("worklist rows", $this->db_smartone); - exit; - } - } - - public function search_rerun() - { - $prm = $this->sys_input; - $id = $prm["detail_id"]; - - $sql = "CALL sp_process_result_rerun(?)"; - $query = $this->db_smartone->query($sql, [$id]); - - if ($query) { - $rows = $query->result_array(); - $this->sys_ok(["records" => $rows]); - } else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - - - function getdoctorsfna() - { - $prm = $this->sys_input; - // $id = $prm["id"]; - - $sql = " SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY M_DoctorName ASC"; - //echo $sql; - $query = $this->db_smartone->query($sql); - - if ($query) { - $rows = $query->result_array(); - $this->sys_ok(["records" => $rows]); - } else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - function getgolongandarah() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $images = array(); - $sql = "SELECT So_ImageUploadBloodTypeID as xid, - CONCAT('/one-media/one-image-nonlab/',So_ImageUploadBloodTypeName) as image_url - FROM t_orderdetail - JOIN so_imageupload_bloodtype ON So_ImageUploadBloodTypeT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND - So_ImageUploadBloodTypeIsActive = 'Y' - WHERE - T_OrderDetailID = {$id} AND - T_OrderDetailIsActive = 'Y' - GROUP BY So_ImageUploadBloodTypeID"; - $images = $this->db_smartone->query($sql)->result_array(); - - $rst = array('images' => $images); - $this->sys_ok(["records" => $rst]); - } - - function getfnaresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT Other_FNADetailsID as xid, - Other_FNAT_OrderDetailID as orderdetail_id, - Other_FNADetailsCode as code, - Other_FNADetailsLabel as label, - Other_FNADetailsResult as result, - IFNULL(Other_FNAM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_FNAM_DoctorID) OR Other_FNAM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_fna - JOIN other_fnadetails ON Other_FNADetailsOther_FNAID = Other_FNAID AND Other_FNADetailsIsActive = 'Y' - LEFT JOIN m_doctor ON Other_FNAM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_FNAT_OrderDetailID = {$id} AND Other_FNAIsActive = 'Y' - GROUP BY Other_FNADetailsID - ORDER BY Other_FNADetailsCode ASC"; - $query = $this->db_smartone->query($sql); - - if ($query) { - $rows = $query->result_array(); - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $images = array(); - $sql = "SELECT So_ImageUploadID as xid, - CONCAT('/one-media/one-image-nonlab/',So_ImageUploadNewName) as image_url - FROM t_orderdetail - JOIN so_imageupload ON So_ImageUploadT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND - So_ImageUploadIsActive = 'Y' - WHERE - T_OrderDetailID = {$id} AND - T_OrderDetailIsActive = 'Y' - GROUP BY So_ImageUploadID"; - $images = $this->db_smartone->query($sql)->result_array(); - - $rst = array('doctors' => $doctors, 'results' => $rows, 'images' => $images); - $this->sys_ok(["records" => $rst]); - } else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - function uploadimageblood() - { - if (! $this->isLogin) { - $this->sys_error("Invalid Token"); - exit; - } - - $userid = $this->sys_user["M_UserID"]; - $data = []; - //print_r($_SERVER); - - $prm = $this->sys_input; - $orderid = $this->input->post('orderid'); - $labnumber = $this->input->post('labnumber'); - $nattest_id = $this->input->post('nattest_id'); - $sql = "UPDATE so_imageupload_bloodtype SET - So_ImageUploadBloodTypeIsActive = 'N', - So_ImageUploadBloodTypeUserID = {$userid} - WHERE - So_ImageUploadBloodTypeT_OrderHeaderID = {$orderid}"; - //echo $sql; - $this->db_onedev->query($sql); - //$config['upload_path'] = 'assets/'; - - $sqlselect = "SELECT COUNT(*) as total FROM flag_blood_type WHERE FlagBloodTypeT_OrderHeaderID = ? AND FlagBloodTypeIsActive = 'Y'"; - $qryselect = $this->db_onedev->query($sqlselect, array($orderid)); - if (!$qryselect) { - $this->db_onedev->trans_rollback(); - $this->sys_error_db("Select Blood Type", $this->db_onedev); - exit; - } - $row = $qryselect->row(); - if ($row->total == 0) { - $sqlinsert = "INSERT INTO flag_blood_type( - FlagBloodTypeT_OrderHeaderID, - FlagBloodTypeNat_TestID, - FlagBloodTypeCreated, - FlagBloodTypeUserID, - FlagBloodTypeIsActive) VALUES(?,?,NOW(),?,'Y')"; - $qryinsert = $this->db_onedev->query($sqlinsert, array($orderid, $nattest_id, $userid)); - if (!$qryinsert) { - $this->db_onedev->trans_rollback(); - $this->db_onedev->sys_error_db("Insert Blood Type", $this->db_onedev); - exit; - } - } else { - $sqlupdate = "UPDATE flag_blood_type SET - FlagBloodTypeNat_TestID = ?, - FlagBloodTypeLastUpdated = NOW(), - FlagBloodTypeUserID = ? - WHERE FlagBloodTypeT_OrderHeaderID = ?"; - $qryupdate = $this->db_onedev->query($sqlupdate, array($nattest_id, $userid, $orderid)); - if (!$qryupdate) { - $this->db_onedev->trans_rollback(); - $this->db_onedev->sys_error_db("Update Blood Type", $this->db_onedev); - exit; - } - } - - $path = '/home/one/project/one/one-media/one-image-nonlab/'; - //echo $path; - $config['upload_path'] = $path; - $config['allowed_types'] = 'jpg|jpeg|png|gif'; - - $config['max_size'] = '10000'; - $count = count($_FILES['files']['name']); - //echo $count; - $this->load->library('upload', $config); - - $error = []; - for ($i = 0; $i < $count; $i++) { - - - if (!empty($_FILES['files']['name'][$i])) { - - $_FILES['file']['name'] = $_FILES['files']['name'][$i]; - - $_FILES['file']['type'] = $_FILES['files']['type'][$i]; - - $_FILES['file']['tmp_name'] = $_FILES['files']['tmp_name'][$i]; - - $_FILES['file']['error'] = $_FILES['files']['error'][$i]; - - $_FILES['file']['size'] = $_FILES['files']['size'][$i]; - - $namex = $orderid . '-' . $labnumber . '-' . $this->generateRandomString(5); - //echo $namex; - - $config['file_name'] = $namex; - $this->upload->initialize($config); - //echo $config['file_name'] ; - - if ($this->upload->do_upload('file')) { - - $uploadData = $this->upload->data(); - - $filename = $uploadData['file_name']; - //echo $filename; - - - $sql = "INSERT INTO so_imageupload_bloodtype ( - So_ImageUploadBloodTypeT_OrderHeaderID, - So_ImageUploadBloodTypeT_OrderHeaderLabNumber, - So_ImageUploadBloodTypeName, - So_ImageUploadBloodTypeCreated, - So_ImageUploadBloodTypeUserID - ) - VALUES( - {$orderid}, - '{$labnumber}', - '{$filename}', - NOW(), - {$userid} - )"; - //echo $sql; - $this->db_onedev->query($sql); - $xlast_id = $this->db_onedev->insert_id(); - $data['totalFiles'][] = array('xid' => $xlast_id, 'image_url' => '/one-media/one-image-nonlab/' . $filename); - } else { - $error = array('error' => $this->upload->display_errors()); - } - } - } - - $result = array("total" => count($data['totalFiles']), "records" => $data['totalFiles'], 'errors' => $error); - $this->sys_ok($result); - } - - function uploadimage() - { - if (! $this->isLogin) { - $this->sys_error("Invalid Token"); - exit; - } - - $userid = $this->sys_user["M_UserID"]; - $data = []; - //print_r($_SERVER); - - $prm = $this->sys_input; - $orderid = $this->input->post('orderid'); - $labnumber = $this->input->post('labnumber'); - $sql = "UPDATE so_imageupload SET - So_ImageUploadIsActive = 'N', - So_ImageUploadUserID = {$userid} - WHERE - So_ImageUploadT_OrderHeaderID = {$orderid}"; - //echo $sql; - $this->db_onedev->query($sql); - //$config['upload_path'] = 'assets/'; - - $path = '/home/one/project/one/one-media/one-image-nonlab/'; - //echo $path; - $config['upload_path'] = $path; - $config['allowed_types'] = 'jpg|jpeg|png|gif'; - - $config['max_size'] = '10000'; - $count = count($_FILES['files']['name']); - //echo $count; - $this->load->library('upload', $config); - - $error = []; - for ($i = 0; $i < $count; $i++) { - - - if (!empty($_FILES['files']['name'][$i])) { - - - - $_FILES['file']['name'] = $_FILES['files']['name'][$i]; - - $_FILES['file']['type'] = $_FILES['files']['type'][$i]; - - $_FILES['file']['tmp_name'] = $_FILES['files']['tmp_name'][$i]; - - $_FILES['file']['error'] = $_FILES['files']['error'][$i]; - - $_FILES['file']['size'] = $_FILES['files']['size'][$i]; - - - - $namex = $orderid . '-' . $labnumber . '-' . $this->generateRandomString(5); - //echo $namex; - - $config['file_name'] = $namex; - $this->upload->initialize($config); - //echo $config['file_name'] ; - - - - - - if ($this->upload->do_upload('file')) { - - $uploadData = $this->upload->data(); - - $filename = $uploadData['file_name']; - //echo $filename; - - - $sql = "INSERT INTO so_imageupload ( - So_ImageUploadT_OrderHeaderID, - So_ImageUploadT_OrderHeaderLabNumber, - So_ImageUploadT_SampleTypeID, - So_ImageUploadOldName, - So_ImageUploadNewName, - So_ImageUploadCreated, - So_ImageUploadUserID - ) - VALUES( - {$orderid}, - '{$labnumber}', - '150', - '{$_FILES['files']['name'][$i]}', - '{$filename}', - NOW(), - {$userid} - - )"; - //echo $sql; - $this->db_onedev->query($sql); - $xlast_id = $this->db_onedev->insert_id(); - $data['totalFiles'][] = array('xid' => $xlast_id, 'image_url' => '/one-media/one-image-nonlab/' . $filename); - } else { - $error = array('error' => $this->upload->display_errors()); - } - } - } - - $result = array("total" => count($data['totalFiles']), "records" => $data['totalFiles'], 'errors' => $error); - $this->sys_ok($result); - } - - - function generateRandomString($length = 10) - { - $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; - $charactersLength = strlen($characters); - $randomString = ''; - for ($i = 0; $i < $length; $i++) { - $randomString .= $characters[rand(0, $charactersLength - 1)]; - } - return $randomString; - } - - function getcytologiresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT Other_CytologiDetailsID as xid, - Other_CytologiT_OrderDetailID as orderdetail_id, - Other_CytologiDetailsCode as code, - Other_CytologiDetailsLabel as label, - Other_CytologiDetailsResult as result, - IFNULL(Other_CytologiM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_CytologiM_DoctorID) OR Other_CytologiM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_cytologi - JOIN other_cytologidetails ON Other_CytologiDetailsOther_CytologiID = Other_CytologiID AND Other_CytologiDetailsIsActive = 'Y' - LEFT JOIN m_doctor ON Other_CytologiM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_CytologiT_OrderDetailID = {$id} AND Other_CytologiIsActive = 'Y' - GROUP BY Other_CytologiDetailsID - ORDER BY Other_CytologiDetailsCode ASC"; - //echo $sql; - $query = $this->db_smartone->query($sql); - - if ($query) { - $rows = $query->result_array(); - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $rst = array('doctors' => $doctors, 'results' => $rows); - $this->sys_ok(["records" => $rst]); - } else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - function getmikroresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT - Other_MikroID as xid, - Other_MikroHasilBiakan as hasil_biakan, - Other_MikroSampleTypeName as sample_name, - Other_MikroT_OrderDetailID as orderdetail_id, - Other_MikroResult as result_value, - '' as result_other, - IFNULL(T_BacteriaID,0) as T_BacteriaID, - IFNULL(T_BacteriaName,'') as T_BacteriaName, - '' as details, - IFNULL(Other_MikroM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_MikroM_DoctorID) OR Other_MikroM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_mikro - LEFT JOIN t_bacteria ON Other_MikroT_BacteriaID = T_BacteriaID - LEFT JOIN m_doctor ON Other_MikroM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_MikroT_OrderDetailID = {$id} AND Other_MikroIsActive = 'Y' - GROUP BY Other_MikroID"; - //echo $sql; - $query = $this->db_smartone->query($sql); - - if ($query) { - $row = $query->row_array(); - if ($row) { - if ($row['result_value'] != 'Positif' && $row['result_value'] != 'Negatif') { - $row['result_other'] = $row['result_value']; - $row['result_value'] = 'other'; - } - $sql = "SELECT '' as xno, - Other_MikroDetailsID as xid, - Other_MikroDetailsValue as value, - IF(Other_MikroDetailsNote = 'R','Y','N') as chx_r, - IF(Other_MikroDetailsNote = 'I','Y','N') as chx_i, - IF(Other_MikroDetailsNote = 'S','Y','N') as chx_s, - Other_MikroDetailsNote as note, - t_antibiotic.* - FROM other_mikrodetails - LEFT JOIN t_antibiotic ON Other_MikroDetailsT_AntibioticID = T_AntibioticID - WHERE - Other_MikroDetailsOther_MikroID = {$row['xid']} AND Other_MikroDetailsIsActive = 'Y' - GROUP BY Other_MikroDetailsID - ORDER BY T_AntibioticName ASC"; - //echo $sql; - $details = $this->db_smartone->query($sql)->result_array(); - if (details) { - foreach ($details as $k => $v) { - $details[$k]['xno'] = $k + 1; - } - } - $row['details'] = $details; - } else { - $row = array('xid' => '0', 'hasil_biakan' => '', 'result_value' => 'Negatif', 'sample_name' => '', 'orderdetail_id' => $id, 'T_BacteriaID' => '0', 'T_BacteriaName' => '0', 'details' => array(), 'doctor_id' => '0', 'doctor_name' => '0'); - } - } else { - $row = array('xid' => '0', 'hasil_biakan' => '', 'result_value' => 'Negatif', 'sample_name' => '', 'orderdetail_id' => $id, 'T_BacteriaID' => '0', 'T_BacteriaName' => '0', 'details' => array(), 'doctor_id' => '0', 'doctor_name' => '0'); - } - //print_r($row); - - - - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 7 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $sql = " - SELECT '0' as id, 'Belum memilih bakteria' as name - UNION - SELECT T_BacteriaID as id, T_BacteriaName as name - FROM t_bacteria - WHERE - T_BacteriaIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $bacteries = $this->db_smartone->query($sql)->result_array(); - $rst = array('doctors' => $doctors, 'bacteries' => $bacteries, 'results' => $row); - $this->sys_ok(["records" => $rst]); - } - function getantibiotics() - { - $prm = $this->sys_input; - $id = $prm["id"]; - $sql = " SELECT '' as xno, - 0 as xid, - '' as hasil_biakan, - '' as sample_name, - 0 as value, - 'Y' as chx_r, - 'N' as chx_i, - 'N' as chx_s, - 'R' as note, - t_antibiotic.* - FROM t_antibiotic - WHERE - T_AntibioticT_BacteriaID = {$prm['id']} AND T_AntibioticIsActive= 'Y' - ORDER BY T_AntibioticName ASC"; - //echo $sql; - $rows = $this->db_smartone->query($sql)->result_array(); - if (rows) { - foreach ($rows as $k => $v) { - $rows[$k]['xno'] = $k + 1; - } - } - - $this->sys_ok(["records" => $rows]); - } - function getlcprepresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - $sql = " SELECT Other_LcprepDetailsID as xid, - Other_LcprepID as header_id, - Other_LcprepT_orderDetailID as orderdetail_id, - Other_LcprepDetailsCode as code, - Other_LcprepDetailsLabel as label, - Other_LcprepDetailsResult as result, - IFNULL(Other_LcprepM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_LcprepM_DoctorID) OR Other_LcprepM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_lcprep - JOIN other_lcprepdetails ON Other_LcprepDetailsOther_LcprepID = Other_LcprepID AND Other_LcprepDetailsIsActive = 'Y' - LEFT JOIN m_doctor ON Other_LcprepM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_LcprepT_orderDetailID = {$id} AND Other_LcprepIsActive = 'Y' - GROUP BY Other_LcprepDetailsOther_LcprepID, Other_LcprepDetailsCode - ORDER BY Other_LcprepDetailsCode ASC"; - //echo $sql; - $rows = $this->db_smartone->query($sql)->result_array(); - if (!$rows) { - $rows = array( - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'A', - 'label' => 'DESKRIPSI', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ), - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'B', - 'label' => 'KESIMPULAN', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ) - ); - } - - $header_id = $rows[0]['header_id']; - $sql = "SELECT IFNULL(Other_LcprepAdekuasiID,0) as xid, - Lcprep_AdekuasiID as id, - Lcprep_AdekuasiLabel as name, - IF(ISNULL(Other_LcprepAdekuasiID),'N',Other_LcprepAdekuasiChex) as chex - FROM lcprep_adekuasi - LEFT JOIN other_lcprepadekuasi ON Other_LcprepAdekuasiLcprep_AdekuasiID = Lcprep_AdekuasiID AND - Other_LcprepAdekuasiOther_LcprepID = {$header_id} AND - Other_LcprepAdekuasiIsActive = 'Y' - WHERE - Lcprep_AdekuasiIsActive = 'Y' - GROUP BY Lcprep_AdekuasiID - ORDER BY Lcprep_AdekuasiOrder ASC - "; - //echo $sql; - $adeakuasi = $this->db_smartone->query($sql)->result_array(); - foreach ($adeakuasi as $kc => $vc) { - $adeakuasi[$kc]['chex'] = $vc['chex'] == 'N' ? false : true; - } - - $sql = "SELECT IFNULL(Other_LcprepKategoriUmumID,0) as xid, - Lcprep_KategoriUmumID as id, - Lcprep_KategoriUmumLabel as name, - IF(ISNULL(Other_LcprepKategoriUmumID),'N',Other_LcprepKategoriUmumChex) as chex - FROM lcprep_kategoriumum - LEFT JOIN other_lcprepkategoriumum ON Other_LcprepKategoriUmumLcprep_KategoriUmumID = Lcprep_KategoriUmumID AND - Other_LcprepKategoriUmumOther_LcprepID = {$header_id} AND - Other_LcprepKategoriUmumIsActive = 'Y' - WHERE - Lcprep_KategoriUmumIsActive = 'Y' - GROUP BY Lcprep_KategoriUmumID - "; - //echo $sql; - $kategoriumum = $this->db_smartone->query($sql)->result_array(); - foreach ($kategoriumum as $kc => $vc) { - $kategoriumum[$kc]['chex'] = $vc['chex'] == 'N' ? false : true; - } - - $sql = " - SELECT Lcprep_InterpretasiGroupID as group_id, - Lcprep_InterpretasiGroupName as group_name, - '' as subgroups - FROM lcprep_interpretasigroup - WHERE - Lcprep_InterpretasiGroupIsActive = 'Y' - "; - //echo $sql; - $interpretasi = $this->db_smartone->query($sql)->result_array(); - foreach ($interpretasi as $k => $v) { - $subgroups = array(); - $sql = "SELECT Lcprep_InterpretasiSubgroupID as subgroup_id, - Lcprep_InterpretasiSubgroupName as subgroup_name, - '' as childs - FROM lcprep_interpretasisubgroup - WHERE - Lcprep_InterpretasiSubgroupLcprep_InterpretasiGroupID = {$v['group_id']} AND Lcprep_InterpretasiSubgroupIsActive = 'Y'"; - //echo $sql; - $subgroups = $this->db_smartone->query($sql)->result_array(); - if (count($subgroups) > 0) { - foreach ($subgroups as $ki => $vi) { - $childs = array(); - $sql = "SELECT IFNULL(Other_LcprepInterpretasiID,0) as xid, - IFNULL(Other_LcprepInterpretasiChex,'N') as chex, - IFNULL(Other_LcprepInterpretasiValue,'') as value, - Lcprep_InterpretasiID as id, - Lcprep_InterpretasiLcprep_InterpretasiSubgroupID as subgroup_id, - Lcprep_InterpretasiCode as code, - Lcprep_InterpretasiName as name, - Lcprep_InterpretasiParentID as parent_id, - Lcprep_InterpretasiIsParent as is_parent, - Lcprep_InterpretasiHasResult as has_result, - Lcprep_InterpretasiTypeResult as type_result - FROM lcprep_interpretasi - LEFT JOIN other_lcprepinterpretasi ON Other_LcprepInterpretasiOther_LcprepID = {$header_id} AND - Other_LcprepInterpretasiLcprep_InterpretasiID = Lcprep_InterpretasiID AND - Other_LcprepInterpretasiIsActive = 'Y' - WHERE - Lcprep_InterpretasiLcprep_InterpretasiSubgroupID = {$vi['subgroup_id']} AND Lcprep_InterpretasiIsActive = 'Y' - GROUP BY Lcprep_InterpretasiID Order BY Lcprep_InterpretasiCode ASC"; - $childs = $this->db_smartone->query($sql)->result_array(); - if ($childs) { - foreach ($childs as $kc => $vc) { - $childs[$kc]['chex'] = $vc['chex'] == 'N' ? false : true; - } - } - $subgroups[$ki]['childs'] = $childs; - } - } - - $interpretasi[$k]['subgroups'] = $subgroups; - } - - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $rst = array('doctors' => $doctors, 'results' => $rows, 'adekuasi' => $adeakuasi, 'kategoriumum' => $kategoriumum, 'interpretasi' => $interpretasi); - $this->sys_ok(["records" => $rst]); - } - - function getpapsmearresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT Other_PapSmearDetailsID as xid, - Other_PapSmearID as header_id, - Other_PapSmearT_OrderDetailID as orderdetail_id, - Other_PapSmearDetailsCode as code, - Other_PapSmearDetailsLabel as label, - Other_PapSmearDetailsResult as result, - IFNULL(Other_PapSmearM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_PapSmearM_DoctorID) OR Other_PapSmearM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_papsmear - JOIN other_papsmeardetails ON Other_PapSmearDetailsOther_PapSmearID = Other_PapSmearID AND Other_PapSmearDetailsIsActive = 'Y' - LEFT JOIN m_doctor ON Other_PapSmearM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_PapSmearT_OrderDetailID = {$id} AND Other_PapSmearIsActive = 'Y' - GROUP BY Other_PapSmearDetailsID - ORDER BY Other_PapSmearDetailsCode ASC"; - //echo $sql; - $rows = $this->db_smartone->query($sql)->result_array(); - if (!$rows) { - $rows = array( - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'A', - 'label' => 'Makroskopik', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ), - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'B', - 'label' => 'Mikroskopik', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ), - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'C', - 'label' => 'Kesimpulan', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ) - ); - } - - $header_id = $rows[0]['header_id']; - $sql = "SELECT Other_PapSmearMaturasiID as xid, - Other_PapSmearMaturasiValue as value - FROM other_papsmearmaturasi - WHERE - Other_PapSmearMaturasiOther_PapSmearID = {$header_id} AND - Other_PapSmearMaturasiIsActive = 'Y' - "; - //echo $sql; - $dt_maturasi = $this->db_smartone->query($sql)->row_array(); - if (!$dt_maturasi) { - $maturasi = array('xid' => '0', 'value' => array('', '', '')); - } else { - $value = explode('/', $dt_maturasi['value']); - $maturasi = array('xid' => $dt_maturasi['xid'], 'value' => $value); - } - - $sql = "SELECT IFNULL(Other_PapSmearBahanID,0) as xid, - M_PapSmearBahanID as bahan_id, - M_PapSmearBahanName as name, - IF(ISNULL(Other_PapSmearBahanID),'N','Y') as selected - FROM m_papsmearbahan - LEFT JOIN other_papsmearbahan ON Other_PapSmearBahanM_PapSmearBahanID = M_PapSmearBahanID AND - Other_PapSmearBahanOther_PapSmearID = {$header_id} AND - Other_PapSmearBahanIsActive = 'Y' - WHERE - M_PapSmearBahanIsActive = 'Y' - ORDER BY M_PapSmearBahanID ASC - "; - //echo $sql; - $bahans = $this->db_smartone->query($sql)->result_array(); - - $sql = "SELECT IFNULL(Other_PapsmearCategoryID,0) as xid, - M_PapSmearCategoryID as category_id, - M_PapSmearCategoryName as name, - IF(ISNULL(Other_PapsmearCategoryID),'N','Y') as selected - FROM m_papsmearcategory - LEFT JOIN other_papsmearcategory ON Other_PapsmearCategoryM_PapSmearCategoryID = M_PapSmearCategoryID AND - Other_PapsmearCategoryOther_PapSmearID = {$header_id} AND - Other_PapsmearCategoryIsActive = 'Y' - WHERE - M_PapSmearCategoryIsActive = 'Y' - ORDER BY M_PapSmearCategoryID ASC - "; - //echo $sql; - $categories = $this->db_smartone->query($sql)->result_array(); - - $sql = "SELECT IFNULL(Other_PapSmearCheckID,0) as xid, - M_PapSmearCheckID as check_id, - M_PapSmearCheckLabel as name, - IF(ISNULL(Other_PapSmearCheckID),'N','Y') as selected, - Other_PapSmearCheckNote as note - FROM m_papsmearcheck - LEFT JOIN other_papsmearcheck ON Other_PapSmearCheckM_PapSmearCheckID = M_PapSmearCheckID AND - Other_PapSmearCheckOther_PapSmearID = {$header_id} AND - Other_PapSmearCheckIsActive = 'Y' - WHERE - M_PapSmearCheckIsActive = 'Y' - ORDER BY M_PapSmearCheckCode ASC - "; - $checks = $this->db_smartone->query($sql)->result_array(); - - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $rst = array('doctors' => $doctors, 'checks' => $checks, 'bahans' => $bahans, 'categories' => $categories, 'maturasi' => $maturasi, 'results' => $rows); - $this->sys_ok(["records" => $rst]); - } - - function saveresult_lcprep() - { - $prm = $this->sys_input; - $detail_id = $prm['detail_id']; - $doctor_id = $prm['doctor']; - $adekuasi = $prm['adekuasi']; - $kategoriumum = $prm['kategoriumum']; - $interpretasi = $prm['interpretasi']; - $results = $prm['results']; - - $userid = $this->sys_user['M_UserID']; - - $header_id = 0; - $sql = "SELECT * FROM other_lcprep WHERE Other_LcprepT_orderDetailID = {$detail_id} AND Other_LcprepIsActive = 'Y'"; - $dt_header = $this->db_smartone->query($sql)->row_array(); - if ($dt_header) { - $header_id = $dt_header['Other_LcprepID']; - } - if ($header_id == 0) { - $sql = "INSERT INTO other_lcprep( - Other_LcprepT_orderDetailID, - Other_LcprepM_DoctorID, - Other_LcprepUserID, - Other_LcprepCreated - ) - VALUES( - {$detail_id}, - {$doctor_id}, - {$userid}, - NOW() - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } else { - $sql = "UPDATE other_lcprep SET Other_LcprepM_DoctorID = {$doctor_id}, Other_LcprepUserID = {$userid} WHERE Other_LcprepID = {$header_id}"; - $this->db_smartone->query($sql); - } - - if ($adekuasi) { - foreach ($adekuasi as $k => $v) { - $selected = $v['chex'] ? 'Y' : 'N'; - if (intval($v['xid'] == 0)) { - $sql = "UPDATE other_lcprepadekuasi SET Other_LcprepAdekuasiIsActive = 'N' - WHERE - Other_LcprepAdekuasiOther_LcprepID = {$header_id} AND - Other_LcprepAdekuasiIsActive = 'Y' AND - Other_LcprepAdekuasiLcprep_AdekuasiID = {$v['id']}"; - $this->db_smartone->query($sql); - $sql = "INSERT INTO other_lcprepadekuasi ( - Other_LcprepAdekuasiOther_LcprepID, - Other_LcprepAdekuasiLcprep_AdekuasiID, - Other_LcprepAdekuasiChex, - Other_LcprepAdekuasiUserID, - Other_LcprepAdekuasiCreated - ) - VALUES( - {$header_id}, - {$v['id']}, - '{$selected}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - //echo $sql; - } - if (intval($v['xid'] != 0)) { - - $sql = "UPDATE other_lcprepadekuasi SET - Other_LcprepAdekuasiChex = '{$selected}', - Other_LcprepAdekuasiUserID = {$userid} - WHERE - Other_LcprepAdekuasiID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - - //echo $sql; - } - } - - if ($kategoriumum) { - foreach ($kategoriumum as $k => $v) { - $selected = $v['chex'] ? 'Y' : 'N'; - if (intval($v['xid'] == 0)) { - $sql = "UPDATE other_lcprepkategoriumum SET Other_LcprepKategoriUmumIsActive = 'N' - WHERE - Other_LcprepKategoriUmumOther_LcprepID = {$header_id} AND - Other_LcprepKategoriUmumLcprep_KategoriUmumID = {$v['id']} AND - Other_LcprepKategoriUmumIsActive = 'Y' - "; - $this->db_smartone->query($sql); - $sql = "INSERT INTO other_lcprepkategoriumum ( - Other_LcprepKategoriUmumOther_LcprepID, - Other_LcprepKategoriUmumLcprep_KategoriUmumID, - Other_LcprepKategoriUmumChex, - Other_LcprepKategoriUmumUserID, - Other_LcprepKategoriUmumCreated - ) - VALUES( - {$header_id}, - {$v['id']}, - '{$selected}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if (intval($v['xid'] != 0)) { - $sql = "UPDATE other_lcprepkategoriumum SET - Other_LcprepKategoriUmumChex = '{$selected}', - Other_LcprepKategoriUmumUserID = {$userid} - WHERE - Other_LcprepKategoriUmumID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - - //echo $sql; - } - } - - if ($results) { - foreach ($results as $k => $v) { - if (intval($v['xid'] == 0)) { - $sql = "UPDATE other_lcprepdetails SET Other_LcprepDetailsIsActive = 'N' - WHERE - Other_LcprepDetailsOther_LcprepID = {$header_id} AND - Other_LcprepDetailsCode = '{$v['code']}' AND - Other_LcprepDetailsIsActive = 'Y'"; - $this->db_smartone->query($sql); - $sql = "INSERT INTO other_lcprepdetails ( - Other_LcprepDetailsOther_LcprepID, - Other_LcprepDetailsCode, - Other_LcprepDetailsLabel, - Other_LcprepDetailsResult, - Other_LcprepDetailsUserID, - Other_LcprepDetailsCreated - ) - VALUES( - {$header_id}, - '{$v['code']}', - '{$v['label']}', - '{$v['result']}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if (intval($v['xid'] != 0)) { - $sql = "UPDATE other_lcprepdetails SET - Other_LcprepDetailsCode = '{$v['code']}', - Other_LcprepDetailsLabel = '{$v['label']}', - Other_LcprepDetailsResult = '{$v['result']}', - Other_LcprepDetailsUserID = {$userid} - WHERE - Other_LcprepDetailsID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - //echo $sql; - } - } - - if ($interpretasi) { - foreach ($interpretasi as $k => $v) { - if (count($v['subgroups']) > 0) { - foreach ($v['subgroups'] as $ik => $iv) { - if (count($iv['childs']) > 0) { - foreach ($iv['childs'] as $iik => $iiv) { - if (intval($iiv['xid'] == 0)) { - $chex = $iiv['chex'] ? 'Y' : 'N'; - $sql = "UPDATE other_lcprepinterpretasi SET Other_LcprepInterpretasiIsActive = 'N' - WHERE - Other_LcprepInterpretasiOther_LcprepID = {$header_id} AND - Other_LcprepInterpretasiLcprep_InterpretasiID = '{$iiv['id']}' AND - Other_LcprepInterpretasiIsActive = 'Y'"; - $this->db_smartone->query($sql); - $sql = "INSERT INTO other_lcprepinterpretasi ( - Other_LcprepInterpretasiOther_LcprepID, - Other_LcprepInterpretasiLcprep_InterpretasiID, - Other_LcprepInterpretasiChex, - Other_LcprepInterpretasiValue, - Other_LcprepInterpretasiUserID, - Other_LcprepInterpretasiCreated - ) - VALUES( - {$header_id}, - '{$iiv['id']}', - '{$chex}', - '{$iiv['value']}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - - if (intval($iiv['xid'] != 0)) { - $chex = $iiv['chex'] ? 'Y' : 'N'; - $sql = "UPDATE other_lcprepinterpretasi SET - Other_LcprepInterpretasiChex = '{$chex}', - Other_LcprepInterpretasiValue = '{$iiv['value']}', - Other_LcprepInterpretasiUserID = {$userid} - WHERE - Other_LcprepInterpretasiID = {$iiv['xid']}"; - $this->db_smartone->query($sql); - //echo $sql; - - } - } - } - } - } - //echo $sql; - } - } - - - $result = array("total" => 1, "records" => array(), "sql" => ''); - $this->sys_ok($result); - exit; - } - - function saveresult_papsmear() - { - $prm = $this->sys_input; - $detail_id = $prm['detail_id']; - $doctor_id = $prm['doctor']; - $checks = $prm['checks']; - $maturasi = $prm['maturasi']; - $bahans = $prm['bahans']; - $categories = $prm['categories']; - $results = $prm['results']; - - $userid = $this->sys_user['M_UserID']; - - $header_id = 0; - $sql = "SELECT * FROM other_papsmear WHERE Other_PapSmearT_OrderDetailID = {$detail_id} AND Other_PapSmearIsActive = 'Y'"; - $dt_header = $this->db_smartone->query($sql)->row_array(); - if ($dt_header) { - $header_id = $dt_header['Other_PapSmearID']; - } - if ($header_id == 0) { - $sql = "INSERT INTO other_papsmear( - Other_PapSmearT_OrderDetailID, - Other_PapSmearM_DoctorID, - Other_PapSmearUserID, - Other_PapSmearCreated - ) - VALUES( - {$detail_id}, - {$doctor_id}, - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } else { - $sql = "UPDATE other_papsmear SET Other_PapSmearM_DoctorID = {$doctor_id}, Other_PapSmearUserID = {$userid} WHERE Other_PapSmearID = {$header_id}"; - $this->db_smartone->query($sql); - } - - if ($checks) { - foreach ($checks as $k => $v) { - if (intval($v['xid']) == 0 && $v['selected'] === 'Y') { - $sql = "INSERT INTO other_papsmearcheck ( - Other_PapSmearCheckOther_PapSmearID, - Other_PapSmearCheckM_PapSmearCheckID, - Other_PapSmearCheckNote, - Other_PapSmearCheckUserID, - Other_PapSmearCheckCreated - ) - VALUES( - {$header_id}, - {$v['check_id']}, - '{$v['note']}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if (intval($v['xid']) != 0 && $v['selected'] === 'N') { - $sql = "UPDATE other_papsmearcheck SET - Other_PapSmearCheckIsActive = 'N', - Other_PapSmearCheckUserID = {$userid} - WHERE - Other_PapSmearCheckID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - if (intval($v['xid']) != 0 && $v['selected'] === 'Y') { - $sql = "UPDATE other_papsmearcheck SET - Other_PapSmearCheckNote = '{$v['note']}', - Other_PapSmearCheckUserID = {$userid} - WHERE - Other_PapSmearCheckID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - //echo $sql; - } - } - - if ($maturasi) { - if (intval($maturasi['xid']) == 0) { - $value = join("/", $maturasi['value']); - $sql = "INSERT INTO other_papsmearmaturasi ( - Other_PapSmearMaturasiOther_PapSmearID, - Other_PapSmearMaturasiValue, - Other_PapSmearMaturasiUserID, - Other_PapSmearMaturasiCreated - ) - VALUE( - {$header_id}, - '{$value}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - //echo $sql; - } - if (intval($maturasi['xid']) != 0) { - $value = join("/", $maturasi['value']); - $sql = "UPDATE other_papsmearmaturasi SET - Other_PapSmearMaturasiValue = '{$value}', - Other_PapSmearMaturasiUserID = {$userid} - WHERE - Other_PapSmearMaturasiID = {$maturasi['xid']}"; - // echo $sql; - $this->db_smartone->query($sql); - } - } - - if ($bahans) { - foreach ($bahans as $k => $v) { - if (intval($v['xid']) == 0 && $v['selected'] === 'Y') { - $sql = "INSERT INTO other_papsmearbahan ( - Other_PapSmearBahanOther_PapSmearID, - Other_PapSmearBahanM_PapSmearBahanID, - Other_PapSmearBahanUserID, - Other_PapSmearBahanCreated - ) - VALUES( - {$header_id}, - {$v['bahan_id']}, - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if (intval($v['xid']) != 0 && $v['selected'] === 'N') { - $sql = "UPDATE other_papsmearbahan SET - Other_PapSmearBahanIsActive = 'N', - Other_PapsmearCategoryUserID = {$userid} - WHERE - Other_PapSmearBahanID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - if (intval($v['xid']) != 0 && $v['selected'] === 'Y') { - $sql = "UPDATE other_papsmearbahan SET - Other_PapSmearBahanIsActive = 'Y', - Other_PapsmearCategoryUserID = {$userid} - WHERE - Other_PapSmearBahanID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - //echo $sql; - } - } - - if ($categories) { - foreach ($categories as $k => $v) { - if (intval($v['xid']) == 0 && $v['selected'] === 'Y') { - $sql = "INSERT INTO other_papsmearcategory ( - Other_PapsmearCategoryOther_PapSmearID, - Other_PapsmearCategoryM_PapSmearCategoryID, - Other_PapsmearCategoryUserID, - Other_PapsmearCategoryCreated - ) - VALUES( - {$header_id}, - {$v['category_id']}, - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if (intval($v['xid']) != 0 && $v['selected'] === 'N') { - $sql = "UPDATE other_papsmearcategory SET - Other_PapsmearCategoryIsActive = 'N', - Other_PapsmearCategoryUserID = {$userid} - WHERE - Other_PapsmearCategoryID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - //echo $sql; - if (intval($v['xid']) != 0 && $v['selected'] === 'Y') { - $sql = "UPDATE other_papsmearcategory SET - Other_PapsmearCategoryIsActive = 'Y', - Other_PapsmearCategoryUserID = {$userid} - WHERE - Other_PapsmearCategoryID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - } - } - - if ($results) { - foreach ($results as $k => $v) { - if (intval($v['xid']) == 0) { - $sql = "INSERT INTO other_papsmeardetails ( - Other_PapSmearDetailsOther_PapSmearID, - Other_PapSmearDetailsCode, - Other_PapSmearDetailsLabel, - Other_PapSmearDetailsResult, - Other_PapSmearDetailsUserID, - Other_PapSmearDetailsCreated - ) - VALUES( - {$header_id}, - '{$v['code']}', - '{$v['label']}', - '{$v['result']}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if (intval($v['xid']) != 0) { - $sql = "UPDATE other_papsmeardetails SET - Other_PapSmearDetailsCode = '{$v['code']}', - Other_PapSmearDetailsLabel = '{$v['label']}', - Other_PapSmearDetailsResult = '{$v['result']}', - Other_PapSmearDetailsUserID = {$userid} - WHERE - Other_PapSmearDetailsID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - //echo $sql; - } - } - - $result = array("total" => 1, "records" => array(), "sql" => ''); - $this->sys_ok($result); - exit; - } - - function saveresult_fna() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = $inp['doctor']; - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - if ($prm[0]['xid'] == '0') { - $sql = "INSERT INTO other_fna( - Other_FNAM_DoctorID, - Other_FNAT_OrderDetailID, - Other_FNAUserID, - Other_FNACreated - ) - VALUES( - {$doctor_id}, - {$prm[0]['orderdetail_id']}, - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } else { - $sql = "SELECT * FROM other_fna WHERE Other_FNAT_OrderDetailID = {$prm[0]['orderdetail_id']} AND Other_FNAIsActive = 'Y'"; - $data_header = $this->db_smartone->query($sql)->row_array(); - $header_id = $data_header['Other_FNAID']; - $sql = "UPDATE other_fna SET - Other_FNAM_DoctorID = {$doctor_id}, - Other_FNAUserID = {$userid} - WHERE - Other_FNAID = {$header_id}"; - $this->db_smartone->query($sql); - } - foreach ($prm as $k => $v) { - if ($v['xid'] == '0') { - $results = str_replace("'", "\\'", $v['result']); - $sql = "INSERT INTO other_fnadetails( - Other_FNADetailsOther_FNAID , - Other_FNADetailsCode, - Other_FNADetailsLabel, - Other_FNADetailsResult, - Other_FNADetailsCreated, - Other_FNADetailsUserID - ) - VALUES( - {$header_id}, - '{$v['code']}', - '{$v['label']}', - '{$results}', - NOW(), - {$userid} - )"; - $query = $this->db_smartone->query($sql); - } else { - $results = str_replace("'", "\\'", $v['result']); - $sql = "UPDATE other_fnadetails SET - Other_FNADetailsResult = '{$results}', - Other_FNADetailsUserID = {$userid} - WHERE - Other_FNADetailsID = {$v['xid']}"; - $query = $this->db_smartone->query($sql); - } - } - - $result = array("total" => 1, "records" => array(), "sql" => ''); - $this->sys_ok($result); - exit; - } - - function saveresult_cytologi() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = $inp['doctor']; - - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - if ($prm[0]['xid'] == '0') { - $sql = "INSERT INTO other_cytologi( - Other_CytologiT_OrderDetailID, - Other_CytologiM_DoctorID, - Other_CytologiUserID, - Other_CytologiCreated - ) - VALUES( - {$prm[0]['orderdetail_id']}, - {$doctor_id}, - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } else { - $sql = "SELECT * FROM other_cytologi WHERE Other_CytologiT_OrderDetailID = {$prm[0]['orderdetail_id']} AND Other_CytologiIsActive = 'Y'"; - $data_header = $this->db_smartone->query($sql)->row_array(); - $header_id = $data_header['Other_CytologiID']; - $sql = "UPDATE other_cytologi SET - Other_CytologiM_DoctorID = {$doctor_id}, - Other_CytologiUserID = {$userid} - WHERE - Other_CytologiID = {$header_id}"; - $this->db_smartone->query($sql); - } - foreach ($prm as $k => $v) { - if ($v['xid'] == '0') { - $results = str_replace("'", "\\'", $v['result']); - $sql = "INSERT INTO other_cytologidetails( - Other_CytologiDetailsOther_CytologiID , - Other_CytologiDetailsCode, - Other_CytologiDetailsLabel, - Other_CytologiDetailsResult, - Other_CytologiDetailsCreated, - Other_CytologiDetailsUserID - ) - VALUES( - {$header_id}, - '{$v['code']}', - '{$v['label']}', - '{$results}', - NOW(), - {$userid} - )"; - $query = $this->db_smartone->query($sql); - } else { - $results = str_replace("'", "\\'", $v['result']); - $sql = "UPDATE other_cytologidetails SET - Other_CytologiDetailsResult = '{$results}', - Other_CytologiDetailsUserID = {$userid} - WHERE - Other_CytologiDetailsID = {$v['xid']}"; - $query = $this->db_smartone->query($sql); - } - } - - $result = array("total" => 1, "records" => array(), "sql" => ''); - $this->sys_ok($result); - exit; - } - - function saveresult_mikro() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = $inp['doctor']; - $backteria_id = $inp['bacteria']; - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - - if ($inp['result_value'] != 'Negatif' && $inp['result_value'] != 'Positif') { - $prm['result_value'] = $prm['result_other']; - } else { - $prm['result_value'] = $inp['result_value']; - } - - if ($prm['xid'] == '0') { - $sql = "INSERT INTO other_mikro( - Other_MikroM_DoctorID, - Other_MikroResult, - Other_MikroT_BacteriaID, - Other_MikroT_OrderDetailID, - Other_MikroHasilBiakan, - Other_MikroSampleTypeName, - Other_MikroUserID, - Other_MikroCreated - ) - VALUES( - {$doctor_id}, - '{$prm['result_value']}', - {$backteria_id}, - {$prm['orderdetail_id']}, - '{$prm['hasil_biakan']}', - '{$prm['sample_name']}', - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } else { - $sql = "SELECT * FROM other_mikro WHERE Other_MikroT_OrderDetailID = {$prm['orderdetail_id']} AND Other_MikroIsActive = 'Y'"; - $data_header = $this->db_smartone->query($sql)->row_array(); - $header_id = $data_header['Other_MikroID']; - $sql = "UPDATE other_mikro SET - Other_MikroResult = '{$prm['result_value']}', - Other_MikroM_DoctorID = {$doctor_id}, - Other_MikroT_BacteriaID = {$backteria_id}, - Other_MikroHasilBiakan = '{$prm['hasil_biakan']}', - Other_MikroSampleTypeName = '{$prm['sample_name']}', - Other_MikroUserID = {$userid} - WHERE - Other_MikroID = {$header_id}"; - //echo $sql; - $this->db_smartone->query($sql); - } - - - - $sql = "UPDATE other_mikrodetails SET Other_MikroDetailsIsActive = 'N', Other_MikroDetailsUserID = 0 WHERE Other_MikroDetailsOther_MikroID = {$header_id}"; - $this->db_smartone->query($sql); - - $results = $prm['details']; - if ($inp['result_value'] == 'Positif') { - foreach ($results as $k => $v) { - if ($v['xid'] == '0') { - $sql = "INSERT INTO other_mikrodetails( - Other_MikroDetailsOther_MikroID , - Other_MikroDetailsT_AntibioticID, - Other_MikroDetailsValue, - Other_MikroDetailsNote, - Other_MikroDetailsCreated, - Other_MikroDetailsUserID - ) - VALUES( - {$header_id}, - '{$v['T_AntibioticID']}', - '{$v['value']}', - '{$v['note']}', - NOW(), - {$userid} - )"; - $query = $this->db_smartone->query($sql); - } else { - $sql = "UPDATE other_mikrodetails SET - Other_MikroDetailsT_AntibioticID = '{$v['T_AntibioticID']}', - Other_MikroDetailsValue = '{$v['value']}', - Other_MikroDetailsNote = '{$v['note']}', - Other_MikroDetailsIsActive = 'Y', - Other_MikroDetailsUserID = {$userid} - WHERE - Other_MikroDetailsID = {$v['xid']}"; - //echo $sql; - $query = $this->db_smartone->query($sql); - } - } - } - - - $result = array("total" => 1, "records" => array(), "sql" => ''); - $this->sys_ok($result); - exit; - } - - - function get_doctors_preparasi_sperma() - { - $prm = $this->sys_input; - // $id = $prm["id"]; - - $sql = " SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 10 AND - M_DoctorSOIsActive = 'Y' - ORDER BY M_DoctorName ASC"; - //echo $sql; - $query = $this->db_smartone->query($sql); - - if ($query) { - $rows = $query->result_array(); - $this->sys_ok(["records" => $rows]); - } else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - - function getpreparasispermaresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT other_preparasisperma.*, - Other_PreparasiSpermaID as xid, - Other_PreparasiSpermaT_OrderDetailID as orderdetail_id, - IFNULL(Other_PreparasiSpermaM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_PreparasiSpermaM_DoctorID) OR Other_PreparasiSpermaM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_preparasisperma - LEFT JOIN m_doctor ON Other_PreparasiSpermaM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_PreparasiSpermaT_OrderDetailID = {$id} AND Other_PreparasiSpermaIsActive = 'Y' - GROUP BY Other_PreparasiSpermaID"; - $query = $this->db_smartone->query($sql); - - if ($query) { - $rows = $query->row_array(); - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 10 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $images = array(); - $sql = "SELECT Other_PreparasiSpermaImgID as xid, - Other_PreparasiSpermaImgType as type, - CONCAT('/one-media/one-image-nonlab/',Other_PreparasiSpermaImgNewName) as image_url - FROM t_orderdetail - JOIN other_preparasisperma_img ON Other_PreparasiSpermaImgT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND - Other_PreparasiSpermaImgIsActive = 'Y' - WHERE - T_OrderDetailID = {$id} AND - T_OrderDetailIsActive = 'Y' - GROUP BY Other_PreparasiSpermaImgID"; - //echo $sql; - $images = $this->db_smartone->query($sql)->result_array(); - - $rst = array('doctors' => $doctors, 'results' => $rows, 'images' => $images); - $this->sys_ok(["records" => $rst]); - } else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - - function uploadimage_preparasi_sperma() - { - if (! $this->isLogin) { - $this->sys_error("Invalid Token"); - exit; - } - - $userid = $this->sys_user["M_UserID"]; - $data = []; - //print_r($_SERVER); - - $prm = $this->sys_input; - $orderid = $this->input->post('orderid'); - $type = $this->input->post('type'); - $labnumber = $this->input->post('labnumber'); - $sql = "UPDATE other_preparasisperma_img SET - Other_PreparasiSpermaImgIsActive = 'N', - Other_PreparasiSpermaImgUserID = {$userid} - WHERE - Other_PreparasiSpermaImgT_OrderHeaderID = {$orderid} AND - Other_PreparasiSpermaImgType = '{$type}'"; - //echo $sql; - $this->db_onedev->query($sql); - //$config['upload_path'] = 'assets/'; - - $path = '/home/one/project/one/one-media/one-image-nonlab/'; - //echo $path; - $config['upload_path'] = $path; - $config['allowed_types'] = 'jpg|jpeg|png|gif'; - - $config['max_size'] = '10000'; - $count = count($_FILES['files']['name']); - //echo $count; - $this->load->library('upload', $config); - - $error = []; - for ($i = 0; $i < $count; $i++) { - - - if (!empty($_FILES['files']['name'][$i])) { - - - - $_FILES['file']['name'] = $_FILES['files']['name'][$i]; - - $_FILES['file']['type'] = $_FILES['files']['type'][$i]; - - $_FILES['file']['tmp_name'] = $_FILES['files']['tmp_name'][$i]; - - $_FILES['file']['error'] = $_FILES['files']['error'][$i]; - - $_FILES['file']['size'] = $_FILES['files']['size'][$i]; - - - - $namex = $orderid . '-' . $labnumber . '-' . $this->generateRandomString(5); - //echo $namex; - - $config['file_name'] = $namex; - $this->upload->initialize($config); - //echo $config['file_name'] ; - - - - - - if ($this->upload->do_upload('file')) { - - $uploadData = $this->upload->data(); - - $filename = $uploadData['file_name']; - //echo $filename; - - - $sql = "INSERT INTO other_preparasisperma_img ( - Other_PreparasiSpermaImgT_OrderHeaderID, - Other_PreparasiSpermaImgType, - Other_PreparasiSpermaImgOldName, - Other_PreparasiSpermaImgNewName, - Other_PreparasiSpermaImgCreated, - Other_PreparasiSpermaImgUserID - ) - VALUES( - {$orderid}, - '{$type}', - '{$_FILES['files']['name'][$i]}', - '{$filename}', - NOW(), - {$userid} - - )"; - //echo $sql; - $this->db_onedev->query($sql); - $xlast_id = $this->db_onedev->insert_id(); - $data['totalFiles'][] = array('xid' => $xlast_id, 'type' => $type, 'image_url' => '/one-media/one-image-nonlab/' . $filename); - } else { - $error = array('error' => $this->upload->display_errors()); - } - } - } - - $result = array("total" => count($data['totalFiles']), "records" => $data['totalFiles'], 'errors' => $error); - $this->sys_ok($result); - } - - - function saveresult_preparasi_sperma() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = $inp['doctor']; - $orderdetail_id = $inp['orderdetailid']; - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - if ($prm['xid'] == '0') { - $sql = "INSERT INTO other_preparasisperma( - Other_PreparasiSpermaM_DoctorID, - Other_PreparasiSpermaT_OrderDetailID, - Other_PreparasiSpermaPreMotilitasA, - Other_PreparasiSpermaPreMotilitasB, - Other_PreparasiSpermaPreMotilitasC, - Other_PreparasiSpermaPreKonsentrasi, - Other_PreparasiSpermaPreKontaminan, - Other_PreparasiSpermaPostMotilitasA, - Other_PreparasiSpermaPostMotilitasB, - Other_PreparasiSpermaPostMotilitasC, - Other_PreparasiSpermaPostKonsentrasi, - Other_PreparasiSpermaPostKontaminan, - Other_PreparasiSpermaNote, - Other_PreparasiSpermaUserID, - Other_PreparasiSpermaCreated - ) - VALUES( - {$doctor_id}, - {$orderdetail_id}, - '{$prm['Other_PreparasiSpermaPreMotilitasA']}', - '{$prm['Other_PreparasiSpermaPreMotilitasB']}', - '{$prm['Other_PreparasiSpermaPreMotilitasC']}', - '{$prm['Other_PreparasiSpermaPreKonsentrasi']}', - '{$prm['Other_PreparasiSpermaPreKontaminan']}', - '{$prm['Other_PreparasiSpermaPostMotilitasA']}', - '{$prm['Other_PreparasiSpermaPostMotilitasB']}', - '{$prm['Other_PreparasiSpermaPostMotilitasC']}', - '{$prm['Other_PreparasiSpermaPostKonsentrasi']}', - '{$prm['Other_PreparasiSpermaPostKontaminan']}', - '{$prm['Other_PreparasiSpermaNote']}', - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } else { - $sql = "SELECT * FROM other_preparasisperma WHERE Other_PreparasiSpermaT_OrderDetailID = {$orderdetail_id} AND Other_PreparasiSpermaIsActive = 'Y'"; - $data_header = $this->db_smartone->query($sql)->row_array(); - $header_id = $data_header['Other_PreparasiSpermaID']; - $sql = "UPDATE other_preparasisperma SET - Other_PreparasiSpermaM_DoctorID = {$doctor_id}, - Other_PreparasiSpermaPreMotilitasA = '{$prm['Other_PreparasiSpermaPreMotilitasA']}', - Other_PreparasiSpermaPreMotilitasB = '{$prm['Other_PreparasiSpermaPreMotilitasB']}', - Other_PreparasiSpermaPreMotilitasC = '{$prm['Other_PreparasiSpermaPreMotilitasC']}', - Other_PreparasiSpermaPreKonsentrasi = '{$prm['Other_PreparasiSpermaPreKonsentrasi']}', - Other_PreparasiSpermaPreKontaminan = '{$prm['Other_PreparasiSpermaPreKontaminan']}', - Other_PreparasiSpermaPostMotilitasA = '{$prm['Other_PreparasiSpermaPostMotilitasA']}', - Other_PreparasiSpermaPostMotilitasB = '{$prm['Other_PreparasiSpermaPostMotilitasB']}', - Other_PreparasiSpermaPostMotilitasC = '{$prm['Other_PreparasiSpermaPostMotilitasC']}', - Other_PreparasiSpermaPostKonsentrasi = '{$prm['Other_PreparasiSpermaPostKonsentrasi']}', - Other_PreparasiSpermaPostKontaminan = '{$prm['Other_PreparasiSpermaPostKontaminan']}', - Other_PreparasiSpermaNote = '{$prm['Other_PreparasiSpermaNote']}', - Other_PreparasiSpermaUserID = {$userid} - WHERE - Other_PreparasiSpermaID = {$header_id}"; - $this->db_smartone->query($sql); - } - - - $result = array("total" => 1, "records" => array(), "sql" => ''); - $this->sys_ok($result); - exit; - } - - function getdnafragmentasiresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT other_dnafragmentasi.*, - Other_DnaFragmentasiID as xid, - Other_DnaFragmentasiT_OrderDetailID as orderdetail_id, - IFNULL(Other_DnaFragmentasiM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_DnaFragmentasiM_DoctorID) OR Other_DnaFragmentasiM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name, - IFNULL(Other_DnaFragmentasiOther_DnaFragmentasiMethodeID,0) as methode_id, - IFNULL(Other_DnaFragmentasiMethodeName,'') as methode_name, - Other_DnaFragmentasiHaloLuas as halo_luas, - Other_DnaFragmentasiHaloSedang as halo_sedang, - Other_DnaFragmentasiHaloSempit as halo_sempit, - Other_DnaFragmentasiTanpaHalo as tanpa_halo, - Other_DnaFragmentasiDFI as dfi, - Other_DnaFragmentasiKesimpulan as kesimpulan, - Other_DnaFragmentasiCatatan as catatan - FROM other_dnafragmentasi - LEFT JOIN m_doctor ON Other_DnaFragmentasiM_DoctorID = M_DoctorID - LEFT JOIN other_dnafragmentasimethode ON Other_DnaFragmentasiOther_DnaFragmentasiMethodeID = Other_DnaFragmentasiMethodeID - WHERE - Other_DnaFragmentasiT_OrderDetailID = {$id} AND Other_DnaFragmentasiIsActive = 'Y' - GROUP BY Other_DnaFragmentasiID - LIMIT 1"; - //echo $sql; - $query = $this->db_smartone->query($sql); - - if ($query) { - $rows = $query->row_array(); - if (!$rows) { - $rows = array( - 'xid' => 0, - 'orderdetail_id' => $id, - 'doctor_id' => 0, - 'doctor_name' => '', - 'methode_id' => 0, - 'methode_name' => '', - 'halo_luas' => '', - 'halo_sedang' => '', - 'tanpa_halo' => '', - 'dfi' => '', - 'kesimpulan' => '', - 'catatan' => '' - ); - } - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID - WHERE - M_DoctorSONat_SubGroupID = 4 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - - $sql = " - SELECT '0' as id, 'Belum memilih metode' as name - UNION - SELECT Other_DnaFragmentasiMethodeID as id, Other_DnaFragmentasiMethodeName as name - FROM other_dnafragmentasimethode - WHERE - Other_DnaFragmentasiMethodeIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $methodes = $this->db_smartone->query($sql)->result_array(); - - - $rst = array('doctors' => $doctors, 'methodes' => $methodes, 'results' => $rows); - $this->sys_ok(["records" => $rst]); - } else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - function saveresult_dnafragmentasi() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = $inp['doctor']['id']; - $methode_id = $inp['methode']['id']; - $orderdetail_id = $inp['results']['orderdetail_id']; - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - if (intval($prm['xid']) == 0) { - $sql = "INSERT INTO other_dnafragmentasi( - Other_DnaFragmentasiT_OrderDetailID, - Other_DnaFragmentasiM_DoctorID, - Other_DnaFragmentasiOther_DnaFragmentasiMethodeID, - Other_DnaFragmentasiHaloLuas, - Other_DnaFragmentasiHaloSedang, - Other_DnaFragmentasiHaloSempit, - Other_DnaFragmentasiTanpaHalo, - Other_DnaFragmentasiDFI, - Other_DnaFragmentasiKesimpulan, - Other_DnaFragmentasiCatatan, - Other_DnaFragmentasiUserID, - Other_DnaFragmentasiLastUpdated - ) - VALUES( - {$orderdetail_id}, - {$doctor_id}, - {$methode_id}, - '{$prm['halo_luas']}', - '{$prm['halo_sedang']}', - '{$prm['halo_sempit']}', - '{$prm['tanpa_halo']}', - '{$prm['dfi']}', - '{$prm['kesimpulan']}', - '{$prm['catatan']}', - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } else { - $sql = "UPDATE other_dnafragmentasi SET - Other_DnaFragmentasiT_OrderDetailID = {$orderdetail_id}, - Other_DnaFragmentasiM_DoctorID = {$doctor_id}, - Other_DnaFragmentasiOther_DnaFragmentasiMethodeID = '{$methode_id}', - Other_DnaFragmentasiHaloLuas = '{$prm['halo_luas']}', - Other_DnaFragmentasiHaloSedang = '{$prm['halo_sedang']}', - Other_DnaFragmentasiHaloSempit = '{$prm['halo_sempit']}', - Other_DnaFragmentasiTanpaHalo = '{$prm['tanpa_halo']}', - Other_DnaFragmentasiDFI = '{$prm['dfi']}', - Other_DnaFragmentasiKesimpulan = '{$prm['kesimpulan']}', - Other_DnaFragmentasiCatatan = '{$prm['catatan']}', - Other_DnaFragmentasiLastUpdated = NOW(), - Other_DnaFragmentasiUserID = {$userid} - WHERE - Other_DnaFragmentasiID = {$prm['xid']}"; - //echo $sql; - $this->db_smartone->query($sql); - } - - - $result = array("total" => 1, "records" => array(), "sql" => ''); - $this->sys_ok($result); - exit; - } -} +db_smartone = $this->load->database("onedev", true); + $this->load->helper(array('form', 'url')); + } + function getMethodeID($natTestID) + { + $sql = "select M_MethodePriorityNat_MethodeID MethodeID, Nat_MethodeName + from + m_methode_priority + join nat_methode on Nat_MethodeID = M_MethodePriorityNat_MethodeID + and Nat_MethodeIsActive = 'Y' + join m_instrumentmethode on M_InstrumentMethodeNat_MethodeID = Nat_MethodeID and M_InstrumentMethodeIsActive = 'Y' + join nat_instrument on M_InstrumentMethodeNat_InstrumentID = Nat_InstrumentID + and Nat_InstrumentIsActive ='Y' + where M_MethodePriorityIsActive = 'Y' + and M_MethodePriorityNat_TestID = $natTestID + and M_MethodePriorityM_DayOfWeekID = dayofweek(now()) + order by M_MethodePriorityNumber desc + limit 0,1 "; + $qry = $this->db->query($sql); + if ($qry) { + $rows = $qry->result_array(); + if (count($rows) > 0) return array($rows[0]["MethodeID"], $rows[0]["Nat_MethodeName"]); + } + //2nd + $sql = "select + M_InstrumentMethodeNat_MethodeID MethodeID, Nat_MethodeName + from m_instrumentmethode + join nat_methode on M_InstrumentMethodeNat_MethodeID = Nat_MethodeID + and Nat_MethodeIsActive = 'Y' + join nat_instrument on M_InstrumentMethodeNat_InstrumentID = Nat_InstrumentID + and Nat_InstrumentIsActive ='Y' + where M_InstrumentMethodeNat_TestID = $natTestID + and M_InstrumentMethodeIsActive = 'Y' + order by M_InstrumentMethodePriority desc + limit 0,1"; + $qry = $this->db->query($sql); + if ($qry) { + $rows = $qry->result_array(); + if (count($rows) > 0) return array($rows[0]["MethodeID"], $rows[0]["Nat_MethodeName"]); + } + // + $sql = "select Nat_NormalValueNat_MethodeID MethodeID, Nat_MethodeName + from + nat_normalvalue + join nat_methode on Nat_NormalValueNat_MethodeID = Nat_MethodeID + and Nat_MethodeIsActive = 'Y' + where Nat_NormalValueNat_TestID = $natTestID + and Nat_NormalValueIsActive = 'Y' + order by Nat_NormalValueID + limit 0,1"; + $qry = $this->db->query($sql); + if ($qry) { + $rows = $qry->result_array(); + if (count($rows) > 0) return array($rows[0]["MethodeID"], $rows[0]["Nat_MethodeName"]); + } + return array(0, ""); + } + function get_normal_value($methodeID, $natTestID, $sexID, $ageInDay) + { + $this->load->library('ibl_sampling_normal'); + return $this->ibl_sampling_normal->get_normal_value_id($methodeID, $natTestID, $sexID, $ageInDay); + } + return 0; + } + function fn_fix_normal($order_id) + { + $sql = "select + T_OrderDetailID, M_PatientM_SexID, fn_global_age_count_day(M_PatientDOB, date(T_OrderHeaderDate)) Dob , + T_TestNat_TestID + from t_orderheader + join m_patient on T_OrderHeaderID = $order_id and T_OrderHeaderM_PatientID = M_PatientID + join t_orderdetail on T_OrderDetailT_OrderHeaderID = T_OrderHeaderID + and T_OrderDetailIsACtive = 'Y' + and ( T_OrderDetailNat_NormalValueID is null or T_OrderDetailNat_NormalValueID = 0 ) + join t_test on T_OrderDetailT_TestID = T_TestID and T_TestIsResult = 'Y' "; + $qry = $this->db->query($sql); + if (! $qry) { + return; + } + $rows = $qry->result_array(); + if (count($rows) == 0) return; + $sql_u = "update t_orderdetail + join nat_normalvalue on T_OrderDetailID = ? and Nat_NormalValueID = ? + set + T_OrderDetailNat_NormalValueID = Nat_NormalValueID, + T_OrderDetailNormalValueNote = Nat_NormalValueNote, + T_OrderDetailNormalValueDescription = Nat_NormalValueDescription, + T_OrderDetailMinValue = Nat_NormalValueMinValue, + T_OrderDetailMaxValue = Nat_NormalValueMaxValue, + T_OrderDetailMinValueInclusive = Nat_NormalValueMinValueInclusive, + T_OrderDetailMaxValueInclusive = Nat_NormalValueMaxValueInclusive, + T_OrderDetailNat_MethodeID = ?, + T_OrderdetailNat_MethodeName =?"; + + foreach ($rows as $r) { + $T_OrderDetailID = $r["T_OrderDetailID"]; + $sexID = $r["M_PatientM_SexID"]; + $ageInDay = $r["Dob"]; + $natTestID = $r["T_TestNat_TestID"]; + list($methodeID, $methodeName) = $this->getMethodeID($natTestID); + if ($methodeID == 0) continue; + $normalValueID = $this->get_normal_value($methodeID, $natTestID, $sexID, $ageInDay); + if ($normalValueID == 0) return; + $this->db->query($sql_u, array($T_OrderDetailID, $normalValueID, $methodeID, $methodeName)); + } + } + function update_order_sample($targetID, $sourceID) + { + $sql = "update t_ordersample target + join t_ordersample source on + target.T_OrderSampleID = ? + and target.T_OrderSampleWorklistReceive = 'N' + and source.T_OrderSampleID = ? + set + target.T_OrderSampleSampling = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSampling, source.T_OrderSampleSampling), + target.T_OrderSampleSamplingDate = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingDate, source.T_OrderSampleSamplingDate), + target.T_OrderSampleSamplingTime = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingTime, source.T_OrderSampleSamplingTime), + target.T_OrderSampleSamplingUserID = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingUserID, source.T_OrderSampleSamplingUserID), + + target.T_OrderSampleReceive = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceive, source.T_OrderSampleReceive), + target.T_OrderSampleReceiveDate = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveDate, source.T_OrderSampleReceiveDate), + target.T_OrderSampleReceiveTime = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveTime, source.T_OrderSampleReceiveTime), + target.T_OrderSampleReceiveUserID = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveUserID, source.T_OrderSampleReceiveUserID), + + target.T_OrderSampleVerification = if(target.T_OrderSampleVerification='Y',target.T_OrderSampleVerification, source.T_OrderSampleVerification), + target.T_OrderSampleVerificationDate =if(target.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationDate, source.T_OrderSampleVerificationDate), + target.T_OrderSampleVerificationTime =if(source.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationTime, source.T_OrderSampleVerificationTime), + target.T_OrderSampleVerificationUserID =if(source.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationUserID, source.T_OrderSampleVerificationUserID), + + target.T_OrderSampleProcessing = if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessing, source.T_OrderSampleProcessing), + target.T_OrderSampleProcessingDate= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingDate, source.T_OrderSampleProcessingDate), + target.T_OrderSampleProcessingTime= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingTime, source.T_OrderSampleProcessingTime), + target.T_OrderSampleProcessingUserID= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingUserID, source.T_OrderSampleProcessingUserID), + + target.T_OrderSampleReceiveHandling =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandling, source.T_OrderSampleReceiveHandling ), + target.T_OrderSampleReceiveHandlingDate =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingDate, source.T_OrderSampleReceiveHandlingDate), + target.T_OrderSampleReceiveHandlingTime =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingTime, source.T_OrderSampleReceiveHandlingTime), + target.T_OrderSampleReceiveHandlingUserID =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingUserID, source.T_OrderSampleReceiveHandlingUserID), + + target.T_OrderSampleHandling = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandling, source.T_OrderSampleHandling), + target.T_OrderSampleHandlingDate = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingDate, source.T_OrderSampleHandlingDate), + target.T_OrderSampleHandlingTime = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingTime, source.T_OrderSampleHandlingTime), + target.T_OrderSampleHandlingUserID = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingUserID, source.T_OrderSampleHandlingUserID), + + target.T_OrderSampleWorklistReceive = source.T_OrderSampleWorklistReceive, + target.T_OrderSampleWorklistReceiveDatetime = source.T_OrderSampleWorklistReceiveDateTime, + target.T_OrderSampleWorklistReceiveUserID = source.T_OrderSampleWorklistReceiveUserID + "; + $qry = $this->db->query($sql, array($targetID, $sourceID)); + if (! $qry) { + echo json_encode(array("status" => "ERR", "message" => print_r($this->db->error(), true))); + exit; + } + } + function fix_sample_serum($headerID) + { + //cari t_ordersample yg belum worklist receive dengan code 017% + $sql = "select T_OrderSampleID + from t_ordersample + join t_sampletype on + T_OrderSampleT_OrderHeaderID = ? + and T_OrderSampleWorklistReceive = 'N' + and T_OrderSampleIsActive = 'Y' + and T_OrderSampleT_SampleTypeID = T_SampletypeID + and T_SampleTypeCode like '017%' + "; + $qry = $this->db->query($sql, array($headerID)); + if (!$qry) { + echo json_encode(array("status" => "ERR", "message" => print_r($this->db->error(), true))); + exit; + } + $rows = $qry->result_array(); + if (count($rows) == 0) return; + //cari T_OrderSample yang sudah di receive yg terakhir + $sql = "select T_OrderSampleID + from t_ordersample + join t_sampletype on + T_OrderSampleT_OrderHeaderID = ? + and T_OrderSampleWorklistReceive = 'Y' + and T_OrderSampleIsActive = 'Y' + and T_OrderSampleT_SampleTypeID = T_SampletypeID + and T_SampleTypeCode like '017%' + order by T_OrderSampleWorklistReceiveDatetime desc + limit 0,1 + "; + $qry = $this->db->query($sql, array($headerID)); + if (!$qry) { + echo json_encode(array("status" => "ERR", "message" => print_r($this->db->error(), true))); + exit; + } + $rcv_rows = $qry->result_array(); + if (count($rcv_rows) == 0) return; + + //print_r($rows); + //print_r($rcv_rows); + $rcv_T_OrderSampleID = $rcv_rows[0]["T_OrderSampleID"]; + //ada yg belum di receive + foreach ($rows as $r) { + $T_OrderSampleID = $r["T_OrderSampleID"]; + $this->update_order_sample($T_OrderSampleID, $rcv_T_OrderSampleID); + } + } + public function search() + { + $prm = $this->sys_input; + $max_rst = 99; + + $id = $prm["order_id"]; + if ($id > 0) { + $this->fix_sample_serum($id); + $this->fn_fix_normal($id); + } + $lang = $this->lang_default_code; + $lang_id = isset($prm['lang_id']) ? $prm['lang_id'] : '0'; + + if ($lang_id != 0) { + $l = $this->db_smartone->where("Nat_LangID", $lang_id)->get("nat_lang")->row(); + $lang = $l->Nat_LangCode; + } + + //tambahan fajri + $sql = " UPDATE t_orderdetail + JOIN t_test ON T_OrderDetailT_TestID = T_TestID + SET T_OrderDetailT_TestIsResult = T_TestIsResult + WHERE + T_OrderDetailT_OrderHeaderID = {$id} AND + T_OrderDetailT_TestIsResult = '' AND + T_OrderDetailIsActive = 'Y'"; + $this->db_smartone->query($sql); + + $tot_count = 0; + $lq = ""; + $group_id = 0; + if (isset($prm['group_id'])) + $group_id = $prm['group_id']; + + if ($group_id != 0) { + $sql = "select distinct T_WorklistDetailNat_TestID Nat_TestID + from t_worklistdetailv2 + where T_WorklistDetailT_WorklistID = {$group_id}"; + $qry = $this->db_smartone->query($sql); + $rows = $qry->result_array(); + $nat_test_ids = "0"; + foreach ($rows as $r) { + $nat_test_ids .= ", " . $r["Nat_TestID"]; + } + $q_group = " ( $nat_test_ids ) "; + + $sql = " + SELECT a1.*, cOUNT(a2.T_OrderDetailID) level + FROM ( + SELECT IFNULL(y.T_OrderDetailT_TestID, x.T_OrderDetailT_TestID) t_testid, + IFNULL(y.T_OrderDetailT_TestName, y.T_OrderDetailT_TestName) t_testname, + y.T_OrderDetailResult result, y.T_OrderDetailResult result_old, y.T_OrderDetailNote note, y.T_OrderDetailNote note_old, + y.T_OrderDetailID id, + y.T_OrderDetailT_TestIsResult is_result, a.T_TestIsQuantitative is_quantitative, + y.T_OrderDetailResultFlag result_flag, + y.T_OrderDetailNat_NormalValueID normal_id, + y.T_OrderDetailNormalValueNote normal_note, y.T_OrderDetailNat_UnitName unit_name, + y.T_OrderdetailNat_MethodeID methode_id, y.T_OrderdetailNat_MethodeName methode_name, + a.T_TestNat_TestID nattest_id, a.T_TestID tx_id, count(T_ResultInstrumentID) as result_instrument_n, + y.T_OrderDetailVerification, T_OrderSampleReceive sample_receive, + T_OrderSampleProcessing sample_processing, T_OrderSampleWorklistReceive sample_worklist_receive, + IF(T_OrderDetailAddOnPreAnalytic = 'Y', T_OrderDetailAddOnPreAnalytic, PreAnalyticIsOk) pre_analytic, + T_OrderDetailAddOnPreAnalytic, + T_OrderHeaderID order_id, y.T_OrderDetailT_TestSasCode test_sas_code, + tx.T_TestSasCode, + T_OrderDetailAddOnResample `resample`, T_OrderDetailAddOnResampleStatus resample_status, + T_OrderDetailAddOnRef ref, y.T_OrderDetailVerification verification, y.T_OrderDetailValidation validation, + T_OrderPromiseDateTime, Group_ResultName as ResultGroupName + FROM t_orderdetail x + left join t_orderpromise on x.T_OrderDetailT_OrderPromiseID = T_OrderPromiseID + JOIN t_test tx ON x.T_OrderDetailT_TestID = T_TestID + JOIN t_test tcheck on tcheck.T_TestNat_TestID in {$q_group} + and ( tx.T_TestID = tcheck.T_TestID or tx.T_TestSasCode like concat(tcheck.T_TestSasCode,'%')) + LEFT JOIN group_resultdetail ON Group_ResultDetailT_TestID = x.T_OrderDetailT_TestID AND Group_ResultDetailIsActive = 'Y' + LEFT JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND Group_ResultFlagNonLab = 'N' + LEFT JOIN t_orderdetail y ON x.T_OrderDetailT_TestSasCode LIKE CONCAT(y.T_OrderDetailT_TestSasCode, '%') + AND x.T_OrderDetailT_OrderHeaderID = y.T_OrderDetailT_OrderHeaderID + AND y.T_OrderDetailIsActive = 'Y' + LEFT JOIN t_orderdetailaddon ON x.T_OrderDetailID = T_OrderDetailAddOnT_OrderDetailID + JOIN t_orderheader ON y.T_OrderDetailT_OrderHeaderID = T_OrderHeaderID + LEFT JOIN t_test a ON y.T_OrderDetailT_TestID = a.T_TestID + AND a.T_TestIsNonLab = '' + LEFT JOIN (SELECT T_OrderSampleT_SampleTypeID, T_OrderSampleReceive, T_OrderSampleProcessing, T_OrderSampleWorklistReceive + FROM t_ordersample WHERE T_OrderSampleT_OrderHeaderID = {$id} + AND T_OrderSampleIsactive = 'Y' + GROUP BY T_OrderSampleT_SampleTypeID) os ON a.T_TestT_SampleTypeID = os.T_OrderSampleT_SampleTypeID + or os.T_OrderSampleT_SampleTypeID = fn_sampletype_from_local(a.T_TestNat_TestID) + + LEFT JOIN t_resultinstrument ON T_ResultInstrumentT_OrderDetailID = x.T_OrderDetailID + LEFT JOIN pre_analytic ON PreAnalyticNat_TestID = a.T_TestNat_TestID AND PreAnalyticDate = date(now()) and PreAnalyticIsActive = 'Y' + WHERE x.T_OrderDetailT_OrderHeaderID = {$id} + AND x.T_OrderDetailIsActive = 'Y' + GROUP BY y.T_OrderDetailT_TestID + ORDER BY y.T_OrderDetailT_TestSasCode ASC + ) a1 + + LEFT JOIN t_orderdetail a2 ON a2.T_OrderDetailT_OrderHeaderID = a1.order_id + AND a2.T_OrderDetailIsActive = 'Y' + AND a1.test_sas_code LIKE CONCAT(a2.T_OrderDetailT_testSasCode, '%') + GROUP BY a1.t_testid + order by a1.test_sas_code +"; + $query = $this->db_smartone->query($sql); + $lq = $this->db_smartone->last_query(); + } else { + $sql = " + SELECT a1.*, cOUNT(a2.T_OrderDetailID) level + FROM ( + SELECT IFNULL(y.T_OrderDetailT_TestID, x.T_OrderDetailT_TestID) t_testid, + IFNULL(y.T_OrderDetailT_TestName, y.T_OrderDetailT_TestName) t_testname, + y.T_OrderDetailResult result, y.T_OrderDetailResult result_old, y.T_OrderDetailNote note, y.T_OrderDetailNote note_old, + y.T_OrderDetailID id, + y.T_OrderDetailT_TestIsResult is_result, a.T_TestIsQuantitative is_quantitative, + y.T_OrderDetailResultFlag result_flag, + y.T_OrderDetailNat_NormalValueID normal_id, + y.T_OrderDetailNormalValueNote normal_note, y.T_OrderDetailNat_UnitName unit_name, + y.T_OrderdetailNat_MethodeID methode_id, y.T_OrderdetailNat_MethodeName methode_name, + a.T_TestNat_TestID nattest_id, a.T_TestID tx_id, count(T_ResultInstrumentID) as result_instrument_n, + y.T_OrderDetailVerification, T_OrderSampleReceive sample_receive, + T_OrderSampleProcessing sample_processing, T_OrderSampleWorklistReceive sample_worklist_receive, + IF(T_OrderDetailAddOnPreAnalytic = 'Y', T_OrderDetailAddOnPreAnalytic, PreAnalyticIsOk) pre_analytic, + T_OrderDetailAddOnPreAnalytic, + T_OrderHeaderID order_id, y.T_OrderDetailT_TestSasCode test_sas_code, + tx.T_TestSasCode, + T_OrderDetailAddOnResample `resample`, T_OrderDetailAddOnResampleStatus resample_status, + T_OrderDetailAddOnRef ref, y.T_OrderDetailVerification verification, y.T_OrderDetailValidation validation, + T_OrderPromiseDateTime , Group_ResultName as ResultGroupName + FROM t_orderdetail x + left join t_orderpromise on x.T_OrderDetailT_OrderPromiseID = T_OrderPromiseID + JOIN t_test tx ON x.T_OrderDetailT_TestID = T_TestID + LEFT JOIN group_resultdetail ON Group_ResultDetailT_TestID = x.T_OrderDetailT_TestID AND Group_ResultDetailIsActive = 'Y' + LEFT JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND Group_ResultFlagNonLab = 'N' + LEFT JOIN t_orderdetail y ON x.T_OrderDetailT_TestSasCode LIKE CONCAT(y.T_OrderDetailT_TestSasCode, '%') + AND x.T_OrderDetailT_OrderHeaderID = y.T_OrderDetailT_OrderHeaderID + AND y.T_OrderDetailIsActive = 'Y' + + LEFT JOIN t_orderdetailaddon ON x.T_OrderDetailID = T_OrderDetailAddOnT_OrderDetailID + + JOIN t_orderheader ON y.T_OrderDetailT_OrderHeaderID = T_OrderHeaderID + LEFT JOIN t_test a ON y.T_OrderDetailT_TestID = a.T_TestID + AND a.T_TestIsNonLab = '' + LEFT JOIN (SELECT T_OrderSampleT_SampleTypeID, T_OrderSampleReceive, T_OrderSampleProcessing, T_OrderSampleWorklistReceive + FROM t_ordersample WHERE T_OrderSampleT_OrderHeaderID = {$id} + AND T_OrderSampleIsactive = 'Y' + GROUP BY T_OrderSampleT_SampleTypeID) os ON a.T_TestT_SampleTypeID = os.T_OrderSampleT_SampleTypeID + or os.T_OrderSampleT_SampleTypeID = fn_sampletype_from_local(a.T_TestNat_TestID) + + LEFT JOIN t_resultinstrument ON T_ResultInstrumentT_OrderDetailID = x.T_OrderDetailID + LEFT JOIN pre_analytic ON PreAnalyticNat_TestID = a.T_TestNat_TestID AND PreAnalyticDate = date(now()) and PreAnalyticIsActive = 'Y' + WHERE x.T_OrderDetailT_OrderHeaderID = {$id} + AND x.T_OrderDetailIsActive = 'Y' + GROUP BY y.T_OrderDetailT_TestID + ORDER BY y.T_OrderDetailT_TestSasCode ASC + ) a1 + + LEFT JOIN t_orderdetail a2 ON a2.T_OrderDetailT_OrderHeaderID = a1.order_id + AND a2.T_OrderDetailIsActive = 'Y' + AND a1.test_sas_code LIKE CONCAT(a2.T_OrderDetailT_testSasCode, '%') + GROUP BY a1.t_testid + order by a1.test_sas_code +"; + //echo $sql; + $query = $this->db_smartone->query($sql); + $lq = $this->db_smartone->last_query(); + } + // file_put_contents("/xtmp/re-query.sql",$lq); + + if ($query) { + $rst = []; + $rows = $query->result_array(); + + foreach ($rows as $k => $v) { + + if ($v['is_result'] == "Y" && $v['is_quantitative'] == "N") { + $v['template'] = []; + $x = $this->db_smartone->query("CALL sp_master_resulttemplate_get('{$v['t_testid']}')"); + $this->clean_mysqli_connection($this->db_smartone->conn_id); + if ($x) + $v['template'] = $x->result_array(); + } + + // IF Rujukan, by pas Pre Analytik + if ($v['ref'] == 'Y') + $v['pre_analytic'] = 'Y'; + if ($v["id"] == "885455") { + //sipe workaround + //$v["sample_receive"] = "Y"; + $v["sample_worklist_receive"] = "Y"; + } + $rst[] = $v; + } + + $result = array("total" => $tot_count, "records" => $rst, "total_display" => sizeof($rows), "q" => $lq); + $this->sys_ok($result); + } else { + $this->sys_error_db("RE Px rows", $this->db_smartone); + exit; + } + } + + public function save() + { + $prm = $this->sys_input; + $data = json_decode($prm["data"]); + $lang = $this->lang_default_code; + $lang_id = isset($prm['lang_id']) ? $prm['lang_id'] : '0'; + + if ($lang_id != 0) { + $l = $this->db_smartone->where("Nat_LangID", $lang_id)->get("nat_lang")->row(); + $lang = $l->Nat_LangCode; + } + + $sql_norm = "select T_OrderDetailMinValue, T_OrderDetailMaxValue, + T_OrderDetailMinValueInclusive, T_OrderDetailMaxValueInclusive, + Nat_TestFlagLow, Nat_TestFlagHigh + from t_orderdetail + join t_test on T_OrderDetailT_TestID = T_TestID + join nat_test on T_TestNat_TestID = Nat_TestID and T_TestIsActive = 'Y' + where T_OrderDetailID = ? "; + + $ids = []; + foreach ($data as $k => $v) { + if ($v->resultInstrumentID > 0) { + $sql_i = "select T_ResultInstrumentNat_NormalValueID normalValueID + from t_resultinstrument + where T_ResultInstrumentID = ?"; + $qry_i = $this->db_smartone->query($sql_i, array($v->resultInstrumentID)); + if ($qry_i) { + $rows_i = $qry_i->result_array(); + + if (count($rows_i) > 0) { + $sql_iu = "update t_orderdetail, nat_normalvalue , nat_methode + set T_OrderDetailMinValue = Nat_NormalValueMinValue, + T_OrderDetailMinValueInclusive = Nat_NormalValueMinValueInclusive, + T_OrderDetailMaxValue = Nat_NormalValueMaxValue , + T_OrderDetailMaxValueInclusive = Nat_NormalValueMaxValueInclusive, + T_OrderDetailNormalValueNote = Nat_NormalValueNote, + T_OrderDetailNormalValueDescription = Nat_NormalValueDescription, + T_OrderDetailNat_NormalValueID = Nat_NormalValueID, + T_OrderDetailNat_MethodeID = Nat_NormalValueNat_MethodeID, + T_OrderDetailNat_MethodeName = Nat_MethodeName + where T_OrderDetailID = ? and Nat_NormalValueID = ? + and Nat_NormalValueNat_MethodeID = Nat_MethodeID + "; + $this->db_smartone->query($sql_iu, array($v->id, $rows_i[0]["normalValueID"])); + //file_put_contents("/xtmp/update-nilai-normal", $this->db_smartone->last_query() . "\n", FILE_APPEND); + } + } + } + $y = $this->db_smartone->query("SELECT fn_process_sample_handling_perfect('{$v->order_id}', '{$v->test_id}') c") + ->row(); + $req_status = $y->c; + $qry_norm = $this->db_smartone->query($sql_norm, $v->id); + $result_flag = ""; + if ($qry_norm) { + $rows_norm = $qry_norm->result_array(); + if (count($rows_norm) > 0) { + $r = $rows_norm[0]; + if (is_numeric($v->result)) { + + if ($r["T_OrderDetailMinValueInclusive"] == "Y" && $v->result < $r["T_OrderDetailMinValue"]) { + $result_flag = $r["Nat_TestFlagLow"]; + } + if ($r["T_OrderDetailMinValueInclusive"] == "N" && $v->result <= $r["T_OrderDetailMinValue"]) { + $result_flag = $r["Nat_TestFlagLow"]; + } + if ($r["T_OrderDetailMaxValueInclusive"] == "Y" && $v->result > $r["T_OrderDetailMaxValue"]) { + $result_flag = $r["Nat_TestFlagHigh"]; + } + if ($r["T_OrderDetailMaxValueInclusive"] == "N" && $v->result >= $r["T_OrderDetailMaxValue"]) { + $result_flag = $r["Nat_TestFlagHigh"]; + } + } + } + } + if ($lang == $this->lang_default_code) { + $this->db_smartone->set('T_OrderDetailResult', $v->result) + ->set('T_OrderDetailResultFlag', $result_flag) + ->set('T_OrderDetailNote', $v->note) + ->set('T_OrderDetailReqStatus', $req_status) + ->where('T_OrderDetailID', $v->id) + ->update('t_orderdetail'); + } else { + $this->db_smartone->set('T_OrderDetailLangResult', $v->result) + ->set('T_OrderDetailLangNote', $v->note) + ->where('T_OrderDetailLangID', $v->id) + ->update('t_orderdetaillang'); + } + + $ids[] = $v->id; + } + + // LOG Process + $order = $this->db_smartone->select('T_OrderDetailT_OrderHeaderID id, T_OrderHeaderLabNumber lab_number', false) + ->join('t_orderheader', 'T_OrderHeaderID = T_OrderDetailT_OrderHeaderID') + ->where('T_OrderDetailID', $data[0]->id) + ->get('t_orderdetail') + ->row(); + + $dblog = $this->load->database("onelog", true); + $dblog->set('Log_ProcessCode', 'PROCESS.Result.Entry') + ->set('Log_ProcessOrderID', $order->id) + ->set('Log_ProcessOrderNumber', $order->lab_number) + ->set('Log_ProcessJson', json_encode($data)) + ->set('Log_ProcessUserID', $this->sys_user['M_UserID']) + ->insert('log_process'); + // END OF Log Process + //auto calculation + $this->load->library("Resultcalc"); + $rows = $this->resultcalc->auto($order->id); + + try { + foreach ($ids as $id) { + $this->db_smartone->query("call sp_set_normal_value_flag($id)"); + $this->clean_mysqli_connection($this->db_smartone->conn_id); + } + } catch (Exception $e) { + } + + $this->sys_ok($ids); + } + + public function save_template() + { + $prm = $this->sys_input; + + $n = $this->db_smartone->select("COUNT(T_ResultTemplateID) n") + ->where("T_ResultTemplateT_TestID", $prm['test_id']) + ->where("T_ResultTemplateIsActive", "Y") + ->where("T_ResultTemplateValue", $prm['value']) + ->get('t_resulttemplate') + ->row(); + if ($n->n > 0) { + $this->sys_error_db("Insert Result Template", $this->db_smartone); + return; + } + + $r = $this->db_smartone->set("T_ResultTemplateT_TestID", $prm['test_id']) + ->set("T_ResultTemplateValue", $prm['value']) + ->insert('t_resulttemplate'); + if ($r) { + $template = []; + $x = $this->db_smartone->query("CALL sp_master_resulttemplate_get('{$prm['test_id']}')"); + $this->clean_mysqli_connection($this->db_smartone->conn_id); + if ($x) + $template = $x->result_array(); + + $this->sys_ok($template); + } + } + + public function export() + { + $prm = $this->sys_input; + + $sql = "CALL sp_process_result_lang(?, ?, ?, ?)"; + $query = $this->db_smartone->query($sql, [$prm['order_id'], $prm['lang_id'], $prm['is_si'], $this->sys_user['M_UserID']]); + if ($query) { + $r = $query->row(); + if ($r->status == "OK") { + $this->sys_ok($r->data); + return; + } + + $this->sys_error_db("Message : " . $r->message, $this->db_smartone); + } else { + $this->sys_error_db("Lang Result", $this->db_smartone); + return; + } + } + + public function search_group() + { + $prm = $this->sys_input; + $max_rst = 100; + + // QUERY TOTAL + $sql = "select count(*) total + from t_worklist + where T_WorklistIsActive = 'Y' + order by T_WorklistName ASC"; + $query = $this->db_smartone->query($sql); + + if ($query) { + $tot_count = $query->result_array()[0]["total"]; + } else { + $this->sys_error_db("worklist count", $this->db_smartone); + exit; + } + + $sql = "select T_WorklistID group_id, T_WorklistName group_name + from t_worklist + where T_WorklistIsActive = 'Y' + order by T_WorklistName ASC + limit 0, {$max_rst}"; + $query = $this->db_smartone->query($sql); + + if ($query) { + $rows = $query->result_array(); + foreach ($rows as $k => $v) + $rows[$k]['data'] = json_decode($v['data']); + $result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows), "q" => $this->db_smartone->last_query()); + $this->sys_ok($result); + } else { + $this->sys_error_db("worklist rows", $this->db_smartone); + exit; + } + } + + public function search_rerun() + { + $prm = $this->sys_input; + $id = $prm["detail_id"]; + + $sql = "CALL sp_process_result_rerun(?)"; + $query = $this->db_smartone->query($sql, [$id]); + + if ($query) { + $rows = $query->result_array(); + $this->sys_ok(["records" => $rows]); + } else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + + + function getdoctorsfna() + { + $prm = $this->sys_input; + // $id = $prm["id"]; + + $sql = " SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY M_DoctorName ASC"; + //echo $sql; + $query = $this->db_smartone->query($sql); + + if ($query) { + $rows = $query->result_array(); + $this->sys_ok(["records" => $rows]); + } else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + function getgolongandarah() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $images = array(); + $sql = "SELECT So_ImageUploadBloodTypeID as xid, + CONCAT('/one-media/one-image-nonlab/',So_ImageUploadBloodTypeName) as image_url + FROM t_orderdetail + JOIN so_imageupload_bloodtype ON So_ImageUploadBloodTypeT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND + So_ImageUploadBloodTypeIsActive = 'Y' + WHERE + T_OrderDetailID = {$id} AND + T_OrderDetailIsActive = 'Y' + GROUP BY So_ImageUploadBloodTypeID"; + $images = $this->db_smartone->query($sql)->result_array(); + + $rst = array('images' => $images); + $this->sys_ok(["records" => $rst]); + } + + function getfnaresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT Other_FNADetailsID as xid, + Other_FNAT_OrderDetailID as orderdetail_id, + Other_FNADetailsCode as code, + Other_FNADetailsLabel as label, + Other_FNADetailsResult as result, + IFNULL(Other_FNAM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_FNAM_DoctorID) OR Other_FNAM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_fna + JOIN other_fnadetails ON Other_FNADetailsOther_FNAID = Other_FNAID AND Other_FNADetailsIsActive = 'Y' + LEFT JOIN m_doctor ON Other_FNAM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_FNAT_OrderDetailID = {$id} AND Other_FNAIsActive = 'Y' + GROUP BY Other_FNADetailsID + ORDER BY Other_FNADetailsCode ASC"; + $query = $this->db_smartone->query($sql); + + if ($query) { + $rows = $query->result_array(); + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $images = array(); + $sql = "SELECT So_ImageUploadID as xid, + CONCAT('/one-media/one-image-nonlab/',So_ImageUploadNewName) as image_url + FROM t_orderdetail + JOIN so_imageupload ON So_ImageUploadT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND + So_ImageUploadIsActive = 'Y' + WHERE + T_OrderDetailID = {$id} AND + T_OrderDetailIsActive = 'Y' + GROUP BY So_ImageUploadID"; + $images = $this->db_smartone->query($sql)->result_array(); + + $rst = array('doctors' => $doctors, 'results' => $rows, 'images' => $images); + $this->sys_ok(["records" => $rst]); + } else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + function uploadimageblood() + { + if (! $this->isLogin) { + $this->sys_error("Invalid Token"); + exit; + } + + $userid = $this->sys_user["M_UserID"]; + $data = []; + //print_r($_SERVER); + + $prm = $this->sys_input; + $orderid = $this->input->post('orderid'); + $labnumber = $this->input->post('labnumber'); + $nattest_id = $this->input->post('nattest_id'); + $sql = "UPDATE so_imageupload_bloodtype SET + So_ImageUploadBloodTypeIsActive = 'N', + So_ImageUploadBloodTypeUserID = {$userid} + WHERE + So_ImageUploadBloodTypeT_OrderHeaderID = {$orderid}"; + //echo $sql; + $this->db_onedev->query($sql); + //$config['upload_path'] = 'assets/'; + + $sqlselect = "SELECT COUNT(*) as total FROM flag_blood_type WHERE FlagBloodTypeT_OrderHeaderID = ? AND FlagBloodTypeIsActive = 'Y'"; + $qryselect = $this->db_onedev->query($sqlselect, array($orderid)); + if (!$qryselect) { + $this->db_onedev->trans_rollback(); + $this->sys_error_db("Select Blood Type", $this->db_onedev); + exit; + } + $row = $qryselect->row(); + if ($row->total == 0) { + $sqlinsert = "INSERT INTO flag_blood_type( + FlagBloodTypeT_OrderHeaderID, + FlagBloodTypeNat_TestID, + FlagBloodTypeCreated, + FlagBloodTypeUserID, + FlagBloodTypeIsActive) VALUES(?,?,NOW(),?,'Y')"; + $qryinsert = $this->db_onedev->query($sqlinsert, array($orderid, $nattest_id, $userid)); + if (!$qryinsert) { + $this->db_onedev->trans_rollback(); + $this->db_onedev->sys_error_db("Insert Blood Type", $this->db_onedev); + exit; + } + } else { + $sqlupdate = "UPDATE flag_blood_type SET + FlagBloodTypeNat_TestID = ?, + FlagBloodTypeLastUpdated = NOW(), + FlagBloodTypeUserID = ? + WHERE FlagBloodTypeT_OrderHeaderID = ?"; + $qryupdate = $this->db_onedev->query($sqlupdate, array($nattest_id, $userid, $orderid)); + if (!$qryupdate) { + $this->db_onedev->trans_rollback(); + $this->db_onedev->sys_error_db("Update Blood Type", $this->db_onedev); + exit; + } + } + + $path = '/home/one/project/one/one-media/one-image-nonlab/'; + //echo $path; + $config['upload_path'] = $path; + $config['allowed_types'] = 'jpg|jpeg|png|gif'; + + $config['max_size'] = '10000'; + $count = count($_FILES['files']['name']); + //echo $count; + $this->load->library('upload', $config); + + $error = []; + for ($i = 0; $i < $count; $i++) { + + + if (!empty($_FILES['files']['name'][$i])) { + + $_FILES['file']['name'] = $_FILES['files']['name'][$i]; + + $_FILES['file']['type'] = $_FILES['files']['type'][$i]; + + $_FILES['file']['tmp_name'] = $_FILES['files']['tmp_name'][$i]; + + $_FILES['file']['error'] = $_FILES['files']['error'][$i]; + + $_FILES['file']['size'] = $_FILES['files']['size'][$i]; + + $namex = $orderid . '-' . $labnumber . '-' . $this->generateRandomString(5); + //echo $namex; + + $config['file_name'] = $namex; + $this->upload->initialize($config); + //echo $config['file_name'] ; + + if ($this->upload->do_upload('file')) { + + $uploadData = $this->upload->data(); + + $filename = $uploadData['file_name']; + //echo $filename; + + + $sql = "INSERT INTO so_imageupload_bloodtype ( + So_ImageUploadBloodTypeT_OrderHeaderID, + So_ImageUploadBloodTypeT_OrderHeaderLabNumber, + So_ImageUploadBloodTypeName, + So_ImageUploadBloodTypeCreated, + So_ImageUploadBloodTypeUserID + ) + VALUES( + {$orderid}, + '{$labnumber}', + '{$filename}', + NOW(), + {$userid} + )"; + //echo $sql; + $this->db_onedev->query($sql); + $xlast_id = $this->db_onedev->insert_id(); + $data['totalFiles'][] = array('xid' => $xlast_id, 'image_url' => '/one-media/one-image-nonlab/' . $filename); + } else { + $error = array('error' => $this->upload->display_errors()); + } + } + } + + $result = array("total" => count($data['totalFiles']), "records" => $data['totalFiles'], 'errors' => $error); + $this->sys_ok($result); + } + + function uploadimage() + { + if (! $this->isLogin) { + $this->sys_error("Invalid Token"); + exit; + } + + $userid = $this->sys_user["M_UserID"]; + $data = []; + //print_r($_SERVER); + + $prm = $this->sys_input; + $orderid = $this->input->post('orderid'); + $labnumber = $this->input->post('labnumber'); + $sql = "UPDATE so_imageupload SET + So_ImageUploadIsActive = 'N', + So_ImageUploadUserID = {$userid} + WHERE + So_ImageUploadT_OrderHeaderID = {$orderid}"; + //echo $sql; + $this->db_onedev->query($sql); + //$config['upload_path'] = 'assets/'; + + $path = '/home/one/project/one/one-media/one-image-nonlab/'; + //echo $path; + $config['upload_path'] = $path; + $config['allowed_types'] = 'jpg|jpeg|png|gif'; + + $config['max_size'] = '10000'; + $count = count($_FILES['files']['name']); + //echo $count; + $this->load->library('upload', $config); + + $error = []; + for ($i = 0; $i < $count; $i++) { + + + if (!empty($_FILES['files']['name'][$i])) { + + + + $_FILES['file']['name'] = $_FILES['files']['name'][$i]; + + $_FILES['file']['type'] = $_FILES['files']['type'][$i]; + + $_FILES['file']['tmp_name'] = $_FILES['files']['tmp_name'][$i]; + + $_FILES['file']['error'] = $_FILES['files']['error'][$i]; + + $_FILES['file']['size'] = $_FILES['files']['size'][$i]; + + + + $namex = $orderid . '-' . $labnumber . '-' . $this->generateRandomString(5); + //echo $namex; + + $config['file_name'] = $namex; + $this->upload->initialize($config); + //echo $config['file_name'] ; + + + + + + if ($this->upload->do_upload('file')) { + + $uploadData = $this->upload->data(); + + $filename = $uploadData['file_name']; + //echo $filename; + + + $sql = "INSERT INTO so_imageupload ( + So_ImageUploadT_OrderHeaderID, + So_ImageUploadT_OrderHeaderLabNumber, + So_ImageUploadT_SampleTypeID, + So_ImageUploadOldName, + So_ImageUploadNewName, + So_ImageUploadCreated, + So_ImageUploadUserID + ) + VALUES( + {$orderid}, + '{$labnumber}', + '150', + '{$_FILES['files']['name'][$i]}', + '{$filename}', + NOW(), + {$userid} + + )"; + //echo $sql; + $this->db_onedev->query($sql); + $xlast_id = $this->db_onedev->insert_id(); + $data['totalFiles'][] = array('xid' => $xlast_id, 'image_url' => '/one-media/one-image-nonlab/' . $filename); + } else { + $error = array('error' => $this->upload->display_errors()); + } + } + } + + $result = array("total" => count($data['totalFiles']), "records" => $data['totalFiles'], 'errors' => $error); + $this->sys_ok($result); + } + + + function generateRandomString($length = 10) + { + $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; + $charactersLength = strlen($characters); + $randomString = ''; + for ($i = 0; $i < $length; $i++) { + $randomString .= $characters[rand(0, $charactersLength - 1)]; + } + return $randomString; + } + + function getcytologiresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT Other_CytologiDetailsID as xid, + Other_CytologiT_OrderDetailID as orderdetail_id, + Other_CytologiDetailsCode as code, + Other_CytologiDetailsLabel as label, + Other_CytologiDetailsResult as result, + IFNULL(Other_CytologiM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_CytologiM_DoctorID) OR Other_CytologiM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_cytologi + JOIN other_cytologidetails ON Other_CytologiDetailsOther_CytologiID = Other_CytologiID AND Other_CytologiDetailsIsActive = 'Y' + LEFT JOIN m_doctor ON Other_CytologiM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_CytologiT_OrderDetailID = {$id} AND Other_CytologiIsActive = 'Y' + GROUP BY Other_CytologiDetailsID + ORDER BY Other_CytologiDetailsCode ASC"; + //echo $sql; + $query = $this->db_smartone->query($sql); + + if ($query) { + $rows = $query->result_array(); + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $rst = array('doctors' => $doctors, 'results' => $rows); + $this->sys_ok(["records" => $rst]); + } else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + function getmikroresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT + Other_MikroID as xid, + Other_MikroHasilBiakan as hasil_biakan, + Other_MikroSampleTypeName as sample_name, + Other_MikroT_OrderDetailID as orderdetail_id, + Other_MikroResult as result_value, + '' as result_other, + IFNULL(T_BacteriaID,0) as T_BacteriaID, + IFNULL(T_BacteriaName,'') as T_BacteriaName, + '' as details, + IFNULL(Other_MikroM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_MikroM_DoctorID) OR Other_MikroM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_mikro + LEFT JOIN t_bacteria ON Other_MikroT_BacteriaID = T_BacteriaID + LEFT JOIN m_doctor ON Other_MikroM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_MikroT_OrderDetailID = {$id} AND Other_MikroIsActive = 'Y' + GROUP BY Other_MikroID"; + //echo $sql; + $query = $this->db_smartone->query($sql); + + if ($query) { + $row = $query->row_array(); + if ($row) { + if ($row['result_value'] != 'Positif' && $row['result_value'] != 'Negatif') { + $row['result_other'] = $row['result_value']; + $row['result_value'] = 'other'; + } + $sql = "SELECT '' as xno, + Other_MikroDetailsID as xid, + Other_MikroDetailsValue as value, + IF(Other_MikroDetailsNote = 'R','Y','N') as chx_r, + IF(Other_MikroDetailsNote = 'I','Y','N') as chx_i, + IF(Other_MikroDetailsNote = 'S','Y','N') as chx_s, + Other_MikroDetailsNote as note, + t_antibiotic.* + FROM other_mikrodetails + LEFT JOIN t_antibiotic ON Other_MikroDetailsT_AntibioticID = T_AntibioticID + WHERE + Other_MikroDetailsOther_MikroID = {$row['xid']} AND Other_MikroDetailsIsActive = 'Y' + GROUP BY Other_MikroDetailsID + ORDER BY T_AntibioticName ASC"; + //echo $sql; + $details = $this->db_smartone->query($sql)->result_array(); + if (details) { + foreach ($details as $k => $v) { + $details[$k]['xno'] = $k + 1; + } + } + $row['details'] = $details; + } else { + $row = array('xid' => '0', 'hasil_biakan' => '', 'result_value' => 'Negatif', 'sample_name' => '', 'orderdetail_id' => $id, 'T_BacteriaID' => '0', 'T_BacteriaName' => '0', 'details' => array(), 'doctor_id' => '0', 'doctor_name' => '0'); + } + } else { + $row = array('xid' => '0', 'hasil_biakan' => '', 'result_value' => 'Negatif', 'sample_name' => '', 'orderdetail_id' => $id, 'T_BacteriaID' => '0', 'T_BacteriaName' => '0', 'details' => array(), 'doctor_id' => '0', 'doctor_name' => '0'); + } + //print_r($row); + + + + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 7 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $sql = " + SELECT '0' as id, 'Belum memilih bakteria' as name + UNION + SELECT T_BacteriaID as id, T_BacteriaName as name + FROM t_bacteria + WHERE + T_BacteriaIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $bacteries = $this->db_smartone->query($sql)->result_array(); + $rst = array('doctors' => $doctors, 'bacteries' => $bacteries, 'results' => $row); + $this->sys_ok(["records" => $rst]); + } + function getantibiotics() + { + $prm = $this->sys_input; + $id = $prm["id"]; + $sql = " SELECT '' as xno, + 0 as xid, + '' as hasil_biakan, + '' as sample_name, + 0 as value, + 'Y' as chx_r, + 'N' as chx_i, + 'N' as chx_s, + 'R' as note, + t_antibiotic.* + FROM t_antibiotic + WHERE + T_AntibioticT_BacteriaID = {$prm['id']} AND T_AntibioticIsActive= 'Y' + ORDER BY T_AntibioticName ASC"; + //echo $sql; + $rows = $this->db_smartone->query($sql)->result_array(); + if (rows) { + foreach ($rows as $k => $v) { + $rows[$k]['xno'] = $k + 1; + } + } + + $this->sys_ok(["records" => $rows]); + } + function getlcprepresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + $sql = " SELECT Other_LcprepDetailsID as xid, + Other_LcprepID as header_id, + Other_LcprepT_orderDetailID as orderdetail_id, + Other_LcprepDetailsCode as code, + Other_LcprepDetailsLabel as label, + Other_LcprepDetailsResult as result, + IFNULL(Other_LcprepM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_LcprepM_DoctorID) OR Other_LcprepM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_lcprep + JOIN other_lcprepdetails ON Other_LcprepDetailsOther_LcprepID = Other_LcprepID AND Other_LcprepDetailsIsActive = 'Y' + LEFT JOIN m_doctor ON Other_LcprepM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_LcprepT_orderDetailID = {$id} AND Other_LcprepIsActive = 'Y' + GROUP BY Other_LcprepDetailsOther_LcprepID, Other_LcprepDetailsCode + ORDER BY Other_LcprepDetailsCode ASC"; + //echo $sql; + $rows = $this->db_smartone->query($sql)->result_array(); + if (!$rows) { + $rows = array( + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'A', + 'label' => 'DESKRIPSI', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ), + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'B', + 'label' => 'KESIMPULAN', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ) + ); + } + + $header_id = $rows[0]['header_id']; + $sql = "SELECT IFNULL(Other_LcprepAdekuasiID,0) as xid, + Lcprep_AdekuasiID as id, + Lcprep_AdekuasiLabel as name, + IF(ISNULL(Other_LcprepAdekuasiID),'N',Other_LcprepAdekuasiChex) as chex + FROM lcprep_adekuasi + LEFT JOIN other_lcprepadekuasi ON Other_LcprepAdekuasiLcprep_AdekuasiID = Lcprep_AdekuasiID AND + Other_LcprepAdekuasiOther_LcprepID = {$header_id} AND + Other_LcprepAdekuasiIsActive = 'Y' + WHERE + Lcprep_AdekuasiIsActive = 'Y' + GROUP BY Lcprep_AdekuasiID + ORDER BY Lcprep_AdekuasiOrder ASC + "; + //echo $sql; + $adeakuasi = $this->db_smartone->query($sql)->result_array(); + foreach ($adeakuasi as $kc => $vc) { + $adeakuasi[$kc]['chex'] = $vc['chex'] == 'N' ? false : true; + } + + $sql = "SELECT IFNULL(Other_LcprepKategoriUmumID,0) as xid, + Lcprep_KategoriUmumID as id, + Lcprep_KategoriUmumLabel as name, + IF(ISNULL(Other_LcprepKategoriUmumID),'N',Other_LcprepKategoriUmumChex) as chex + FROM lcprep_kategoriumum + LEFT JOIN other_lcprepkategoriumum ON Other_LcprepKategoriUmumLcprep_KategoriUmumID = Lcprep_KategoriUmumID AND + Other_LcprepKategoriUmumOther_LcprepID = {$header_id} AND + Other_LcprepKategoriUmumIsActive = 'Y' + WHERE + Lcprep_KategoriUmumIsActive = 'Y' + GROUP BY Lcprep_KategoriUmumID + "; + //echo $sql; + $kategoriumum = $this->db_smartone->query($sql)->result_array(); + foreach ($kategoriumum as $kc => $vc) { + $kategoriumum[$kc]['chex'] = $vc['chex'] == 'N' ? false : true; + } + + $sql = " + SELECT Lcprep_InterpretasiGroupID as group_id, + Lcprep_InterpretasiGroupName as group_name, + '' as subgroups + FROM lcprep_interpretasigroup + WHERE + Lcprep_InterpretasiGroupIsActive = 'Y' + "; + //echo $sql; + $interpretasi = $this->db_smartone->query($sql)->result_array(); + foreach ($interpretasi as $k => $v) { + $subgroups = array(); + $sql = "SELECT Lcprep_InterpretasiSubgroupID as subgroup_id, + Lcprep_InterpretasiSubgroupName as subgroup_name, + '' as childs + FROM lcprep_interpretasisubgroup + WHERE + Lcprep_InterpretasiSubgroupLcprep_InterpretasiGroupID = {$v['group_id']} AND Lcprep_InterpretasiSubgroupIsActive = 'Y'"; + //echo $sql; + $subgroups = $this->db_smartone->query($sql)->result_array(); + if (count($subgroups) > 0) { + foreach ($subgroups as $ki => $vi) { + $childs = array(); + $sql = "SELECT IFNULL(Other_LcprepInterpretasiID,0) as xid, + IFNULL(Other_LcprepInterpretasiChex,'N') as chex, + IFNULL(Other_LcprepInterpretasiValue,'') as value, + Lcprep_InterpretasiID as id, + Lcprep_InterpretasiLcprep_InterpretasiSubgroupID as subgroup_id, + Lcprep_InterpretasiCode as code, + Lcprep_InterpretasiName as name, + Lcprep_InterpretasiParentID as parent_id, + Lcprep_InterpretasiIsParent as is_parent, + Lcprep_InterpretasiHasResult as has_result, + Lcprep_InterpretasiTypeResult as type_result + FROM lcprep_interpretasi + LEFT JOIN other_lcprepinterpretasi ON Other_LcprepInterpretasiOther_LcprepID = {$header_id} AND + Other_LcprepInterpretasiLcprep_InterpretasiID = Lcprep_InterpretasiID AND + Other_LcprepInterpretasiIsActive = 'Y' + WHERE + Lcprep_InterpretasiLcprep_InterpretasiSubgroupID = {$vi['subgroup_id']} AND Lcprep_InterpretasiIsActive = 'Y' + GROUP BY Lcprep_InterpretasiID Order BY Lcprep_InterpretasiCode ASC"; + $childs = $this->db_smartone->query($sql)->result_array(); + if ($childs) { + foreach ($childs as $kc => $vc) { + $childs[$kc]['chex'] = $vc['chex'] == 'N' ? false : true; + } + } + $subgroups[$ki]['childs'] = $childs; + } + } + + $interpretasi[$k]['subgroups'] = $subgroups; + } + + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $rst = array('doctors' => $doctors, 'results' => $rows, 'adekuasi' => $adeakuasi, 'kategoriumum' => $kategoriumum, 'interpretasi' => $interpretasi); + $this->sys_ok(["records" => $rst]); + } + + function getpapsmearresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT Other_PapSmearDetailsID as xid, + Other_PapSmearID as header_id, + Other_PapSmearT_OrderDetailID as orderdetail_id, + Other_PapSmearDetailsCode as code, + Other_PapSmearDetailsLabel as label, + Other_PapSmearDetailsResult as result, + IFNULL(Other_PapSmearM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_PapSmearM_DoctorID) OR Other_PapSmearM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_papsmear + JOIN other_papsmeardetails ON Other_PapSmearDetailsOther_PapSmearID = Other_PapSmearID AND Other_PapSmearDetailsIsActive = 'Y' + LEFT JOIN m_doctor ON Other_PapSmearM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_PapSmearT_OrderDetailID = {$id} AND Other_PapSmearIsActive = 'Y' + GROUP BY Other_PapSmearDetailsID + ORDER BY Other_PapSmearDetailsCode ASC"; + //echo $sql; + $rows = $this->db_smartone->query($sql)->result_array(); + if (!$rows) { + $rows = array( + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'A', + 'label' => 'Makroskopik', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ), + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'B', + 'label' => 'Mikroskopik', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ), + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'C', + 'label' => 'Kesimpulan', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ) + ); + } + + $header_id = $rows[0]['header_id']; + $sql = "SELECT Other_PapSmearMaturasiID as xid, + Other_PapSmearMaturasiValue as value + FROM other_papsmearmaturasi + WHERE + Other_PapSmearMaturasiOther_PapSmearID = {$header_id} AND + Other_PapSmearMaturasiIsActive = 'Y' + "; + //echo $sql; + $dt_maturasi = $this->db_smartone->query($sql)->row_array(); + if (!$dt_maturasi) { + $maturasi = array('xid' => '0', 'value' => array('', '', '')); + } else { + $value = explode('/', $dt_maturasi['value']); + $maturasi = array('xid' => $dt_maturasi['xid'], 'value' => $value); + } + + $sql = "SELECT IFNULL(Other_PapSmearBahanID,0) as xid, + M_PapSmearBahanID as bahan_id, + M_PapSmearBahanName as name, + IF(ISNULL(Other_PapSmearBahanID),'N','Y') as selected + FROM m_papsmearbahan + LEFT JOIN other_papsmearbahan ON Other_PapSmearBahanM_PapSmearBahanID = M_PapSmearBahanID AND + Other_PapSmearBahanOther_PapSmearID = {$header_id} AND + Other_PapSmearBahanIsActive = 'Y' + WHERE + M_PapSmearBahanIsActive = 'Y' + ORDER BY M_PapSmearBahanID ASC + "; + //echo $sql; + $bahans = $this->db_smartone->query($sql)->result_array(); + + $sql = "SELECT IFNULL(Other_PapsmearCategoryID,0) as xid, + M_PapSmearCategoryID as category_id, + M_PapSmearCategoryName as name, + IF(ISNULL(Other_PapsmearCategoryID),'N','Y') as selected + FROM m_papsmearcategory + LEFT JOIN other_papsmearcategory ON Other_PapsmearCategoryM_PapSmearCategoryID = M_PapSmearCategoryID AND + Other_PapsmearCategoryOther_PapSmearID = {$header_id} AND + Other_PapsmearCategoryIsActive = 'Y' + WHERE + M_PapSmearCategoryIsActive = 'Y' + ORDER BY M_PapSmearCategoryID ASC + "; + //echo $sql; + $categories = $this->db_smartone->query($sql)->result_array(); + + $sql = "SELECT IFNULL(Other_PapSmearCheckID,0) as xid, + M_PapSmearCheckID as check_id, + M_PapSmearCheckLabel as name, + IF(ISNULL(Other_PapSmearCheckID),'N','Y') as selected, + Other_PapSmearCheckNote as note + FROM m_papsmearcheck + LEFT JOIN other_papsmearcheck ON Other_PapSmearCheckM_PapSmearCheckID = M_PapSmearCheckID AND + Other_PapSmearCheckOther_PapSmearID = {$header_id} AND + Other_PapSmearCheckIsActive = 'Y' + WHERE + M_PapSmearCheckIsActive = 'Y' + ORDER BY M_PapSmearCheckCode ASC + "; + $checks = $this->db_smartone->query($sql)->result_array(); + + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $rst = array('doctors' => $doctors, 'checks' => $checks, 'bahans' => $bahans, 'categories' => $categories, 'maturasi' => $maturasi, 'results' => $rows); + $this->sys_ok(["records" => $rst]); + } + + function saveresult_lcprep() + { + $prm = $this->sys_input; + $detail_id = $prm['detail_id']; + $doctor_id = $prm['doctor']; + $adekuasi = $prm['adekuasi']; + $kategoriumum = $prm['kategoriumum']; + $interpretasi = $prm['interpretasi']; + $results = $prm['results']; + + $userid = $this->sys_user['M_UserID']; + + $header_id = 0; + $sql = "SELECT * FROM other_lcprep WHERE Other_LcprepT_orderDetailID = {$detail_id} AND Other_LcprepIsActive = 'Y'"; + $dt_header = $this->db_smartone->query($sql)->row_array(); + if ($dt_header) { + $header_id = $dt_header['Other_LcprepID']; + } + if ($header_id == 0) { + $sql = "INSERT INTO other_lcprep( + Other_LcprepT_orderDetailID, + Other_LcprepM_DoctorID, + Other_LcprepUserID, + Other_LcprepCreated + ) + VALUES( + {$detail_id}, + {$doctor_id}, + {$userid}, + NOW() + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } else { + $sql = "UPDATE other_lcprep SET Other_LcprepM_DoctorID = {$doctor_id}, Other_LcprepUserID = {$userid} WHERE Other_LcprepID = {$header_id}"; + $this->db_smartone->query($sql); + } + + if ($adekuasi) { + foreach ($adekuasi as $k => $v) { + $selected = $v['chex'] ? 'Y' : 'N'; + if (intval($v['xid'] == 0)) { + $sql = "UPDATE other_lcprepadekuasi SET Other_LcprepAdekuasiIsActive = 'N' + WHERE + Other_LcprepAdekuasiOther_LcprepID = {$header_id} AND + Other_LcprepAdekuasiIsActive = 'Y' AND + Other_LcprepAdekuasiLcprep_AdekuasiID = {$v['id']}"; + $this->db_smartone->query($sql); + $sql = "INSERT INTO other_lcprepadekuasi ( + Other_LcprepAdekuasiOther_LcprepID, + Other_LcprepAdekuasiLcprep_AdekuasiID, + Other_LcprepAdekuasiChex, + Other_LcprepAdekuasiUserID, + Other_LcprepAdekuasiCreated + ) + VALUES( + {$header_id}, + {$v['id']}, + '{$selected}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + //echo $sql; + } + if (intval($v['xid'] != 0)) { + + $sql = "UPDATE other_lcprepadekuasi SET + Other_LcprepAdekuasiChex = '{$selected}', + Other_LcprepAdekuasiUserID = {$userid} + WHERE + Other_LcprepAdekuasiID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + + //echo $sql; + } + } + + if ($kategoriumum) { + foreach ($kategoriumum as $k => $v) { + $selected = $v['chex'] ? 'Y' : 'N'; + if (intval($v['xid'] == 0)) { + $sql = "UPDATE other_lcprepkategoriumum SET Other_LcprepKategoriUmumIsActive = 'N' + WHERE + Other_LcprepKategoriUmumOther_LcprepID = {$header_id} AND + Other_LcprepKategoriUmumLcprep_KategoriUmumID = {$v['id']} AND + Other_LcprepKategoriUmumIsActive = 'Y' + "; + $this->db_smartone->query($sql); + $sql = "INSERT INTO other_lcprepkategoriumum ( + Other_LcprepKategoriUmumOther_LcprepID, + Other_LcprepKategoriUmumLcprep_KategoriUmumID, + Other_LcprepKategoriUmumChex, + Other_LcprepKategoriUmumUserID, + Other_LcprepKategoriUmumCreated + ) + VALUES( + {$header_id}, + {$v['id']}, + '{$selected}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if (intval($v['xid'] != 0)) { + $sql = "UPDATE other_lcprepkategoriumum SET + Other_LcprepKategoriUmumChex = '{$selected}', + Other_LcprepKategoriUmumUserID = {$userid} + WHERE + Other_LcprepKategoriUmumID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + + //echo $sql; + } + } + + if ($results) { + foreach ($results as $k => $v) { + if (intval($v['xid'] == 0)) { + $sql = "UPDATE other_lcprepdetails SET Other_LcprepDetailsIsActive = 'N' + WHERE + Other_LcprepDetailsOther_LcprepID = {$header_id} AND + Other_LcprepDetailsCode = '{$v['code']}' AND + Other_LcprepDetailsIsActive = 'Y'"; + $this->db_smartone->query($sql); + $sql = "INSERT INTO other_lcprepdetails ( + Other_LcprepDetailsOther_LcprepID, + Other_LcprepDetailsCode, + Other_LcprepDetailsLabel, + Other_LcprepDetailsResult, + Other_LcprepDetailsUserID, + Other_LcprepDetailsCreated + ) + VALUES( + {$header_id}, + '{$v['code']}', + '{$v['label']}', + '{$v['result']}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if (intval($v['xid'] != 0)) { + $sql = "UPDATE other_lcprepdetails SET + Other_LcprepDetailsCode = '{$v['code']}', + Other_LcprepDetailsLabel = '{$v['label']}', + Other_LcprepDetailsResult = '{$v['result']}', + Other_LcprepDetailsUserID = {$userid} + WHERE + Other_LcprepDetailsID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + //echo $sql; + } + } + + if ($interpretasi) { + foreach ($interpretasi as $k => $v) { + if (count($v['subgroups']) > 0) { + foreach ($v['subgroups'] as $ik => $iv) { + if (count($iv['childs']) > 0) { + foreach ($iv['childs'] as $iik => $iiv) { + if (intval($iiv['xid'] == 0)) { + $chex = $iiv['chex'] ? 'Y' : 'N'; + $sql = "UPDATE other_lcprepinterpretasi SET Other_LcprepInterpretasiIsActive = 'N' + WHERE + Other_LcprepInterpretasiOther_LcprepID = {$header_id} AND + Other_LcprepInterpretasiLcprep_InterpretasiID = '{$iiv['id']}' AND + Other_LcprepInterpretasiIsActive = 'Y'"; + $this->db_smartone->query($sql); + $sql = "INSERT INTO other_lcprepinterpretasi ( + Other_LcprepInterpretasiOther_LcprepID, + Other_LcprepInterpretasiLcprep_InterpretasiID, + Other_LcprepInterpretasiChex, + Other_LcprepInterpretasiValue, + Other_LcprepInterpretasiUserID, + Other_LcprepInterpretasiCreated + ) + VALUES( + {$header_id}, + '{$iiv['id']}', + '{$chex}', + '{$iiv['value']}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + + if (intval($iiv['xid'] != 0)) { + $chex = $iiv['chex'] ? 'Y' : 'N'; + $sql = "UPDATE other_lcprepinterpretasi SET + Other_LcprepInterpretasiChex = '{$chex}', + Other_LcprepInterpretasiValue = '{$iiv['value']}', + Other_LcprepInterpretasiUserID = {$userid} + WHERE + Other_LcprepInterpretasiID = {$iiv['xid']}"; + $this->db_smartone->query($sql); + //echo $sql; + + } + } + } + } + } + //echo $sql; + } + } + + + $result = array("total" => 1, "records" => array(), "sql" => ''); + $this->sys_ok($result); + exit; + } + + function saveresult_papsmear() + { + $prm = $this->sys_input; + $detail_id = $prm['detail_id']; + $doctor_id = $prm['doctor']; + $checks = $prm['checks']; + $maturasi = $prm['maturasi']; + $bahans = $prm['bahans']; + $categories = $prm['categories']; + $results = $prm['results']; + + $userid = $this->sys_user['M_UserID']; + + $header_id = 0; + $sql = "SELECT * FROM other_papsmear WHERE Other_PapSmearT_OrderDetailID = {$detail_id} AND Other_PapSmearIsActive = 'Y'"; + $dt_header = $this->db_smartone->query($sql)->row_array(); + if ($dt_header) { + $header_id = $dt_header['Other_PapSmearID']; + } + if ($header_id == 0) { + $sql = "INSERT INTO other_papsmear( + Other_PapSmearT_OrderDetailID, + Other_PapSmearM_DoctorID, + Other_PapSmearUserID, + Other_PapSmearCreated + ) + VALUES( + {$detail_id}, + {$doctor_id}, + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } else { + $sql = "UPDATE other_papsmear SET Other_PapSmearM_DoctorID = {$doctor_id}, Other_PapSmearUserID = {$userid} WHERE Other_PapSmearID = {$header_id}"; + $this->db_smartone->query($sql); + } + + if ($checks) { + foreach ($checks as $k => $v) { + if (intval($v['xid']) == 0 && $v['selected'] === 'Y') { + $sql = "INSERT INTO other_papsmearcheck ( + Other_PapSmearCheckOther_PapSmearID, + Other_PapSmearCheckM_PapSmearCheckID, + Other_PapSmearCheckNote, + Other_PapSmearCheckUserID, + Other_PapSmearCheckCreated + ) + VALUES( + {$header_id}, + {$v['check_id']}, + '{$v['note']}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if (intval($v['xid']) != 0 && $v['selected'] === 'N') { + $sql = "UPDATE other_papsmearcheck SET + Other_PapSmearCheckIsActive = 'N', + Other_PapSmearCheckUserID = {$userid} + WHERE + Other_PapSmearCheckID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + if (intval($v['xid']) != 0 && $v['selected'] === 'Y') { + $sql = "UPDATE other_papsmearcheck SET + Other_PapSmearCheckNote = '{$v['note']}', + Other_PapSmearCheckUserID = {$userid} + WHERE + Other_PapSmearCheckID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + //echo $sql; + } + } + + if ($maturasi) { + if (intval($maturasi['xid']) == 0) { + $value = join("/", $maturasi['value']); + $sql = "INSERT INTO other_papsmearmaturasi ( + Other_PapSmearMaturasiOther_PapSmearID, + Other_PapSmearMaturasiValue, + Other_PapSmearMaturasiUserID, + Other_PapSmearMaturasiCreated + ) + VALUE( + {$header_id}, + '{$value}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + //echo $sql; + } + if (intval($maturasi['xid']) != 0) { + $value = join("/", $maturasi['value']); + $sql = "UPDATE other_papsmearmaturasi SET + Other_PapSmearMaturasiValue = '{$value}', + Other_PapSmearMaturasiUserID = {$userid} + WHERE + Other_PapSmearMaturasiID = {$maturasi['xid']}"; + // echo $sql; + $this->db_smartone->query($sql); + } + } + + if ($bahans) { + foreach ($bahans as $k => $v) { + if (intval($v['xid']) == 0 && $v['selected'] === 'Y') { + $sql = "INSERT INTO other_papsmearbahan ( + Other_PapSmearBahanOther_PapSmearID, + Other_PapSmearBahanM_PapSmearBahanID, + Other_PapSmearBahanUserID, + Other_PapSmearBahanCreated + ) + VALUES( + {$header_id}, + {$v['bahan_id']}, + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if (intval($v['xid']) != 0 && $v['selected'] === 'N') { + $sql = "UPDATE other_papsmearbahan SET + Other_PapSmearBahanIsActive = 'N', + Other_PapsmearCategoryUserID = {$userid} + WHERE + Other_PapSmearBahanID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + if (intval($v['xid']) != 0 && $v['selected'] === 'Y') { + $sql = "UPDATE other_papsmearbahan SET + Other_PapSmearBahanIsActive = 'Y', + Other_PapsmearCategoryUserID = {$userid} + WHERE + Other_PapSmearBahanID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + //echo $sql; + } + } + + if ($categories) { + foreach ($categories as $k => $v) { + if (intval($v['xid']) == 0 && $v['selected'] === 'Y') { + $sql = "INSERT INTO other_papsmearcategory ( + Other_PapsmearCategoryOther_PapSmearID, + Other_PapsmearCategoryM_PapSmearCategoryID, + Other_PapsmearCategoryUserID, + Other_PapsmearCategoryCreated + ) + VALUES( + {$header_id}, + {$v['category_id']}, + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if (intval($v['xid']) != 0 && $v['selected'] === 'N') { + $sql = "UPDATE other_papsmearcategory SET + Other_PapsmearCategoryIsActive = 'N', + Other_PapsmearCategoryUserID = {$userid} + WHERE + Other_PapsmearCategoryID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + //echo $sql; + if (intval($v['xid']) != 0 && $v['selected'] === 'Y') { + $sql = "UPDATE other_papsmearcategory SET + Other_PapsmearCategoryIsActive = 'Y', + Other_PapsmearCategoryUserID = {$userid} + WHERE + Other_PapsmearCategoryID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + } + } + + if ($results) { + foreach ($results as $k => $v) { + if (intval($v['xid']) == 0) { + $sql = "INSERT INTO other_papsmeardetails ( + Other_PapSmearDetailsOther_PapSmearID, + Other_PapSmearDetailsCode, + Other_PapSmearDetailsLabel, + Other_PapSmearDetailsResult, + Other_PapSmearDetailsUserID, + Other_PapSmearDetailsCreated + ) + VALUES( + {$header_id}, + '{$v['code']}', + '{$v['label']}', + '{$v['result']}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if (intval($v['xid']) != 0) { + $sql = "UPDATE other_papsmeardetails SET + Other_PapSmearDetailsCode = '{$v['code']}', + Other_PapSmearDetailsLabel = '{$v['label']}', + Other_PapSmearDetailsResult = '{$v['result']}', + Other_PapSmearDetailsUserID = {$userid} + WHERE + Other_PapSmearDetailsID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + //echo $sql; + } + } + + $result = array("total" => 1, "records" => array(), "sql" => ''); + $this->sys_ok($result); + exit; + } + + function saveresult_fna() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = $inp['doctor']; + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + if ($prm[0]['xid'] == '0') { + $sql = "INSERT INTO other_fna( + Other_FNAM_DoctorID, + Other_FNAT_OrderDetailID, + Other_FNAUserID, + Other_FNACreated + ) + VALUES( + {$doctor_id}, + {$prm[0]['orderdetail_id']}, + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } else { + $sql = "SELECT * FROM other_fna WHERE Other_FNAT_OrderDetailID = {$prm[0]['orderdetail_id']} AND Other_FNAIsActive = 'Y'"; + $data_header = $this->db_smartone->query($sql)->row_array(); + $header_id = $data_header['Other_FNAID']; + $sql = "UPDATE other_fna SET + Other_FNAM_DoctorID = {$doctor_id}, + Other_FNAUserID = {$userid} + WHERE + Other_FNAID = {$header_id}"; + $this->db_smartone->query($sql); + } + foreach ($prm as $k => $v) { + if ($v['xid'] == '0') { + $results = str_replace("'", "\\'", $v['result']); + $sql = "INSERT INTO other_fnadetails( + Other_FNADetailsOther_FNAID , + Other_FNADetailsCode, + Other_FNADetailsLabel, + Other_FNADetailsResult, + Other_FNADetailsCreated, + Other_FNADetailsUserID + ) + VALUES( + {$header_id}, + '{$v['code']}', + '{$v['label']}', + '{$results}', + NOW(), + {$userid} + )"; + $query = $this->db_smartone->query($sql); + } else { + $results = str_replace("'", "\\'", $v['result']); + $sql = "UPDATE other_fnadetails SET + Other_FNADetailsResult = '{$results}', + Other_FNADetailsUserID = {$userid} + WHERE + Other_FNADetailsID = {$v['xid']}"; + $query = $this->db_smartone->query($sql); + } + } + + $result = array("total" => 1, "records" => array(), "sql" => ''); + $this->sys_ok($result); + exit; + } + + function saveresult_cytologi() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = $inp['doctor']; + + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + if ($prm[0]['xid'] == '0') { + $sql = "INSERT INTO other_cytologi( + Other_CytologiT_OrderDetailID, + Other_CytologiM_DoctorID, + Other_CytologiUserID, + Other_CytologiCreated + ) + VALUES( + {$prm[0]['orderdetail_id']}, + {$doctor_id}, + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } else { + $sql = "SELECT * FROM other_cytologi WHERE Other_CytologiT_OrderDetailID = {$prm[0]['orderdetail_id']} AND Other_CytologiIsActive = 'Y'"; + $data_header = $this->db_smartone->query($sql)->row_array(); + $header_id = $data_header['Other_CytologiID']; + $sql = "UPDATE other_cytologi SET + Other_CytologiM_DoctorID = {$doctor_id}, + Other_CytologiUserID = {$userid} + WHERE + Other_CytologiID = {$header_id}"; + $this->db_smartone->query($sql); + } + foreach ($prm as $k => $v) { + if ($v['xid'] == '0') { + $results = str_replace("'", "\\'", $v['result']); + $sql = "INSERT INTO other_cytologidetails( + Other_CytologiDetailsOther_CytologiID , + Other_CytologiDetailsCode, + Other_CytologiDetailsLabel, + Other_CytologiDetailsResult, + Other_CytologiDetailsCreated, + Other_CytologiDetailsUserID + ) + VALUES( + {$header_id}, + '{$v['code']}', + '{$v['label']}', + '{$results}', + NOW(), + {$userid} + )"; + $query = $this->db_smartone->query($sql); + } else { + $results = str_replace("'", "\\'", $v['result']); + $sql = "UPDATE other_cytologidetails SET + Other_CytologiDetailsResult = '{$results}', + Other_CytologiDetailsUserID = {$userid} + WHERE + Other_CytologiDetailsID = {$v['xid']}"; + $query = $this->db_smartone->query($sql); + } + } + + $result = array("total" => 1, "records" => array(), "sql" => ''); + $this->sys_ok($result); + exit; + } + + function saveresult_mikro() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = $inp['doctor']; + $backteria_id = $inp['bacteria']; + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + + if ($inp['result_value'] != 'Negatif' && $inp['result_value'] != 'Positif') { + $prm['result_value'] = $prm['result_other']; + } else { + $prm['result_value'] = $inp['result_value']; + } + + if ($prm['xid'] == '0') { + $sql = "INSERT INTO other_mikro( + Other_MikroM_DoctorID, + Other_MikroResult, + Other_MikroT_BacteriaID, + Other_MikroT_OrderDetailID, + Other_MikroHasilBiakan, + Other_MikroSampleTypeName, + Other_MikroUserID, + Other_MikroCreated + ) + VALUES( + {$doctor_id}, + '{$prm['result_value']}', + {$backteria_id}, + {$prm['orderdetail_id']}, + '{$prm['hasil_biakan']}', + '{$prm['sample_name']}', + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } else { + $sql = "SELECT * FROM other_mikro WHERE Other_MikroT_OrderDetailID = {$prm['orderdetail_id']} AND Other_MikroIsActive = 'Y'"; + $data_header = $this->db_smartone->query($sql)->row_array(); + $header_id = $data_header['Other_MikroID']; + $sql = "UPDATE other_mikro SET + Other_MikroResult = '{$prm['result_value']}', + Other_MikroM_DoctorID = {$doctor_id}, + Other_MikroT_BacteriaID = {$backteria_id}, + Other_MikroHasilBiakan = '{$prm['hasil_biakan']}', + Other_MikroSampleTypeName = '{$prm['sample_name']}', + Other_MikroUserID = {$userid} + WHERE + Other_MikroID = {$header_id}"; + //echo $sql; + $this->db_smartone->query($sql); + } + + + + $sql = "UPDATE other_mikrodetails SET Other_MikroDetailsIsActive = 'N', Other_MikroDetailsUserID = 0 WHERE Other_MikroDetailsOther_MikroID = {$header_id}"; + $this->db_smartone->query($sql); + + $results = $prm['details']; + if ($inp['result_value'] == 'Positif') { + foreach ($results as $k => $v) { + if ($v['xid'] == '0') { + $sql = "INSERT INTO other_mikrodetails( + Other_MikroDetailsOther_MikroID , + Other_MikroDetailsT_AntibioticID, + Other_MikroDetailsValue, + Other_MikroDetailsNote, + Other_MikroDetailsCreated, + Other_MikroDetailsUserID + ) + VALUES( + {$header_id}, + '{$v['T_AntibioticID']}', + '{$v['value']}', + '{$v['note']}', + NOW(), + {$userid} + )"; + $query = $this->db_smartone->query($sql); + } else { + $sql = "UPDATE other_mikrodetails SET + Other_MikroDetailsT_AntibioticID = '{$v['T_AntibioticID']}', + Other_MikroDetailsValue = '{$v['value']}', + Other_MikroDetailsNote = '{$v['note']}', + Other_MikroDetailsIsActive = 'Y', + Other_MikroDetailsUserID = {$userid} + WHERE + Other_MikroDetailsID = {$v['xid']}"; + //echo $sql; + $query = $this->db_smartone->query($sql); + } + } + } + + + $result = array("total" => 1, "records" => array(), "sql" => ''); + $this->sys_ok($result); + exit; + } + + + function get_doctors_preparasi_sperma() + { + $prm = $this->sys_input; + // $id = $prm["id"]; + + $sql = " SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 10 AND + M_DoctorSOIsActive = 'Y' + ORDER BY M_DoctorName ASC"; + //echo $sql; + $query = $this->db_smartone->query($sql); + + if ($query) { + $rows = $query->result_array(); + $this->sys_ok(["records" => $rows]); + } else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + + function getpreparasispermaresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT other_preparasisperma.*, + Other_PreparasiSpermaID as xid, + Other_PreparasiSpermaT_OrderDetailID as orderdetail_id, + IFNULL(Other_PreparasiSpermaM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_PreparasiSpermaM_DoctorID) OR Other_PreparasiSpermaM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_preparasisperma + LEFT JOIN m_doctor ON Other_PreparasiSpermaM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_PreparasiSpermaT_OrderDetailID = {$id} AND Other_PreparasiSpermaIsActive = 'Y' + GROUP BY Other_PreparasiSpermaID"; + $query = $this->db_smartone->query($sql); + + if ($query) { + $rows = $query->row_array(); + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 10 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $images = array(); + $sql = "SELECT Other_PreparasiSpermaImgID as xid, + Other_PreparasiSpermaImgType as type, + CONCAT('/one-media/one-image-nonlab/',Other_PreparasiSpermaImgNewName) as image_url + FROM t_orderdetail + JOIN other_preparasisperma_img ON Other_PreparasiSpermaImgT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND + Other_PreparasiSpermaImgIsActive = 'Y' + WHERE + T_OrderDetailID = {$id} AND + T_OrderDetailIsActive = 'Y' + GROUP BY Other_PreparasiSpermaImgID"; + //echo $sql; + $images = $this->db_smartone->query($sql)->result_array(); + + $rst = array('doctors' => $doctors, 'results' => $rows, 'images' => $images); + $this->sys_ok(["records" => $rst]); + } else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + + function uploadimage_preparasi_sperma() + { + if (! $this->isLogin) { + $this->sys_error("Invalid Token"); + exit; + } + + $userid = $this->sys_user["M_UserID"]; + $data = []; + //print_r($_SERVER); + + $prm = $this->sys_input; + $orderid = $this->input->post('orderid'); + $type = $this->input->post('type'); + $labnumber = $this->input->post('labnumber'); + $sql = "UPDATE other_preparasisperma_img SET + Other_PreparasiSpermaImgIsActive = 'N', + Other_PreparasiSpermaImgUserID = {$userid} + WHERE + Other_PreparasiSpermaImgT_OrderHeaderID = {$orderid} AND + Other_PreparasiSpermaImgType = '{$type}'"; + //echo $sql; + $this->db_onedev->query($sql); + //$config['upload_path'] = 'assets/'; + + $path = '/home/one/project/one/one-media/one-image-nonlab/'; + //echo $path; + $config['upload_path'] = $path; + $config['allowed_types'] = 'jpg|jpeg|png|gif'; + + $config['max_size'] = '10000'; + $count = count($_FILES['files']['name']); + //echo $count; + $this->load->library('upload', $config); + + $error = []; + for ($i = 0; $i < $count; $i++) { + + + if (!empty($_FILES['files']['name'][$i])) { + + + + $_FILES['file']['name'] = $_FILES['files']['name'][$i]; + + $_FILES['file']['type'] = $_FILES['files']['type'][$i]; + + $_FILES['file']['tmp_name'] = $_FILES['files']['tmp_name'][$i]; + + $_FILES['file']['error'] = $_FILES['files']['error'][$i]; + + $_FILES['file']['size'] = $_FILES['files']['size'][$i]; + + + + $namex = $orderid . '-' . $labnumber . '-' . $this->generateRandomString(5); + //echo $namex; + + $config['file_name'] = $namex; + $this->upload->initialize($config); + //echo $config['file_name'] ; + + + + + + if ($this->upload->do_upload('file')) { + + $uploadData = $this->upload->data(); + + $filename = $uploadData['file_name']; + //echo $filename; + + + $sql = "INSERT INTO other_preparasisperma_img ( + Other_PreparasiSpermaImgT_OrderHeaderID, + Other_PreparasiSpermaImgType, + Other_PreparasiSpermaImgOldName, + Other_PreparasiSpermaImgNewName, + Other_PreparasiSpermaImgCreated, + Other_PreparasiSpermaImgUserID + ) + VALUES( + {$orderid}, + '{$type}', + '{$_FILES['files']['name'][$i]}', + '{$filename}', + NOW(), + {$userid} + + )"; + //echo $sql; + $this->db_onedev->query($sql); + $xlast_id = $this->db_onedev->insert_id(); + $data['totalFiles'][] = array('xid' => $xlast_id, 'type' => $type, 'image_url' => '/one-media/one-image-nonlab/' . $filename); + } else { + $error = array('error' => $this->upload->display_errors()); + } + } + } + + $result = array("total" => count($data['totalFiles']), "records" => $data['totalFiles'], 'errors' => $error); + $this->sys_ok($result); + } + + + function saveresult_preparasi_sperma() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = $inp['doctor']; + $orderdetail_id = $inp['orderdetailid']; + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + if ($prm['xid'] == '0') { + $sql = "INSERT INTO other_preparasisperma( + Other_PreparasiSpermaM_DoctorID, + Other_PreparasiSpermaT_OrderDetailID, + Other_PreparasiSpermaPreMotilitasA, + Other_PreparasiSpermaPreMotilitasB, + Other_PreparasiSpermaPreMotilitasC, + Other_PreparasiSpermaPreKonsentrasi, + Other_PreparasiSpermaPreKontaminan, + Other_PreparasiSpermaPostMotilitasA, + Other_PreparasiSpermaPostMotilitasB, + Other_PreparasiSpermaPostMotilitasC, + Other_PreparasiSpermaPostKonsentrasi, + Other_PreparasiSpermaPostKontaminan, + Other_PreparasiSpermaNote, + Other_PreparasiSpermaUserID, + Other_PreparasiSpermaCreated + ) + VALUES( + {$doctor_id}, + {$orderdetail_id}, + '{$prm['Other_PreparasiSpermaPreMotilitasA']}', + '{$prm['Other_PreparasiSpermaPreMotilitasB']}', + '{$prm['Other_PreparasiSpermaPreMotilitasC']}', + '{$prm['Other_PreparasiSpermaPreKonsentrasi']}', + '{$prm['Other_PreparasiSpermaPreKontaminan']}', + '{$prm['Other_PreparasiSpermaPostMotilitasA']}', + '{$prm['Other_PreparasiSpermaPostMotilitasB']}', + '{$prm['Other_PreparasiSpermaPostMotilitasC']}', + '{$prm['Other_PreparasiSpermaPostKonsentrasi']}', + '{$prm['Other_PreparasiSpermaPostKontaminan']}', + '{$prm['Other_PreparasiSpermaNote']}', + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } else { + $sql = "SELECT * FROM other_preparasisperma WHERE Other_PreparasiSpermaT_OrderDetailID = {$orderdetail_id} AND Other_PreparasiSpermaIsActive = 'Y'"; + $data_header = $this->db_smartone->query($sql)->row_array(); + $header_id = $data_header['Other_PreparasiSpermaID']; + $sql = "UPDATE other_preparasisperma SET + Other_PreparasiSpermaM_DoctorID = {$doctor_id}, + Other_PreparasiSpermaPreMotilitasA = '{$prm['Other_PreparasiSpermaPreMotilitasA']}', + Other_PreparasiSpermaPreMotilitasB = '{$prm['Other_PreparasiSpermaPreMotilitasB']}', + Other_PreparasiSpermaPreMotilitasC = '{$prm['Other_PreparasiSpermaPreMotilitasC']}', + Other_PreparasiSpermaPreKonsentrasi = '{$prm['Other_PreparasiSpermaPreKonsentrasi']}', + Other_PreparasiSpermaPreKontaminan = '{$prm['Other_PreparasiSpermaPreKontaminan']}', + Other_PreparasiSpermaPostMotilitasA = '{$prm['Other_PreparasiSpermaPostMotilitasA']}', + Other_PreparasiSpermaPostMotilitasB = '{$prm['Other_PreparasiSpermaPostMotilitasB']}', + Other_PreparasiSpermaPostMotilitasC = '{$prm['Other_PreparasiSpermaPostMotilitasC']}', + Other_PreparasiSpermaPostKonsentrasi = '{$prm['Other_PreparasiSpermaPostKonsentrasi']}', + Other_PreparasiSpermaPostKontaminan = '{$prm['Other_PreparasiSpermaPostKontaminan']}', + Other_PreparasiSpermaNote = '{$prm['Other_PreparasiSpermaNote']}', + Other_PreparasiSpermaUserID = {$userid} + WHERE + Other_PreparasiSpermaID = {$header_id}"; + $this->db_smartone->query($sql); + } + + + $result = array("total" => 1, "records" => array(), "sql" => ''); + $this->sys_ok($result); + exit; + } + + function getdnafragmentasiresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT other_dnafragmentasi.*, + Other_DnaFragmentasiID as xid, + Other_DnaFragmentasiT_OrderDetailID as orderdetail_id, + IFNULL(Other_DnaFragmentasiM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_DnaFragmentasiM_DoctorID) OR Other_DnaFragmentasiM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name, + IFNULL(Other_DnaFragmentasiOther_DnaFragmentasiMethodeID,0) as methode_id, + IFNULL(Other_DnaFragmentasiMethodeName,'') as methode_name, + Other_DnaFragmentasiHaloLuas as halo_luas, + Other_DnaFragmentasiHaloSedang as halo_sedang, + Other_DnaFragmentasiHaloSempit as halo_sempit, + Other_DnaFragmentasiTanpaHalo as tanpa_halo, + Other_DnaFragmentasiDFI as dfi, + Other_DnaFragmentasiKesimpulan as kesimpulan, + Other_DnaFragmentasiCatatan as catatan + FROM other_dnafragmentasi + LEFT JOIN m_doctor ON Other_DnaFragmentasiM_DoctorID = M_DoctorID + LEFT JOIN other_dnafragmentasimethode ON Other_DnaFragmentasiOther_DnaFragmentasiMethodeID = Other_DnaFragmentasiMethodeID + WHERE + Other_DnaFragmentasiT_OrderDetailID = {$id} AND Other_DnaFragmentasiIsActive = 'Y' + GROUP BY Other_DnaFragmentasiID + LIMIT 1"; + //echo $sql; + $query = $this->db_smartone->query($sql); + + if ($query) { + $rows = $query->row_array(); + if (!$rows) { + $rows = array( + 'xid' => 0, + 'orderdetail_id' => $id, + 'doctor_id' => 0, + 'doctor_name' => '', + 'methode_id' => 0, + 'methode_name' => '', + 'halo_luas' => '', + 'halo_sedang' => '', + 'tanpa_halo' => '', + 'dfi' => '', + 'kesimpulan' => '', + 'catatan' => '' + ); + } + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID + WHERE + M_DoctorSONat_SubGroupID = 4 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + + $sql = " + SELECT '0' as id, 'Belum memilih metode' as name + UNION + SELECT Other_DnaFragmentasiMethodeID as id, Other_DnaFragmentasiMethodeName as name + FROM other_dnafragmentasimethode + WHERE + Other_DnaFragmentasiMethodeIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $methodes = $this->db_smartone->query($sql)->result_array(); + + + $rst = array('doctors' => $doctors, 'methodes' => $methodes, 'results' => $rows); + $this->sys_ok(["records" => $rst]); + } else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + function saveresult_dnafragmentasi() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = $inp['doctor']['id']; + $methode_id = $inp['methode']['id']; + $orderdetail_id = $inp['results']['orderdetail_id']; + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + if (intval($prm['xid']) == 0) { + $sql = "INSERT INTO other_dnafragmentasi( + Other_DnaFragmentasiT_OrderDetailID, + Other_DnaFragmentasiM_DoctorID, + Other_DnaFragmentasiOther_DnaFragmentasiMethodeID, + Other_DnaFragmentasiHaloLuas, + Other_DnaFragmentasiHaloSedang, + Other_DnaFragmentasiHaloSempit, + Other_DnaFragmentasiTanpaHalo, + Other_DnaFragmentasiDFI, + Other_DnaFragmentasiKesimpulan, + Other_DnaFragmentasiCatatan, + Other_DnaFragmentasiUserID, + Other_DnaFragmentasiLastUpdated + ) + VALUES( + {$orderdetail_id}, + {$doctor_id}, + {$methode_id}, + '{$prm['halo_luas']}', + '{$prm['halo_sedang']}', + '{$prm['halo_sempit']}', + '{$prm['tanpa_halo']}', + '{$prm['dfi']}', + '{$prm['kesimpulan']}', + '{$prm['catatan']}', + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } else { + $sql = "UPDATE other_dnafragmentasi SET + Other_DnaFragmentasiT_OrderDetailID = {$orderdetail_id}, + Other_DnaFragmentasiM_DoctorID = {$doctor_id}, + Other_DnaFragmentasiOther_DnaFragmentasiMethodeID = '{$methode_id}', + Other_DnaFragmentasiHaloLuas = '{$prm['halo_luas']}', + Other_DnaFragmentasiHaloSedang = '{$prm['halo_sedang']}', + Other_DnaFragmentasiHaloSempit = '{$prm['halo_sempit']}', + Other_DnaFragmentasiTanpaHalo = '{$prm['tanpa_halo']}', + Other_DnaFragmentasiDFI = '{$prm['dfi']}', + Other_DnaFragmentasiKesimpulan = '{$prm['kesimpulan']}', + Other_DnaFragmentasiCatatan = '{$prm['catatan']}', + Other_DnaFragmentasiLastUpdated = NOW(), + Other_DnaFragmentasiUserID = {$userid} + WHERE + Other_DnaFragmentasiID = {$prm['xid']}"; + //echo $sql; + $this->db_smartone->query($sql); + } + + + $result = array("total" => 1, "records" => array(), "sql" => ''); + $this->sys_ok($result); + exit; + } +} diff --git a/application/controllers/mockup/process/resultentry-v23/Re_px.php b/application/controllers/mockup/process/resultentry-v23/Re_px.php index ea70e877..0938e075 100644 --- a/application/controllers/mockup/process/resultentry-v23/Re_px.php +++ b/application/controllers/mockup/process/resultentry-v23/Re_px.php @@ -1,218 +1,215 @@ -db_smartone = $this->load->database("onedev", true); - $this->db_lab = $this->load->database('one_lab_log', TRUE); - $this->load->helper(array('form', 'url')); - } - function getMethodeID($natTestID) - { - $sql = "select M_MethodePriorityNat_MethodeID MethodeID, Nat_MethodeName - from - m_methode_priority - join nat_methode on Nat_MethodeID = M_MethodePriorityNat_MethodeID - and Nat_MethodeIsActive = 'Y' - join m_instrumentmethode on M_InstrumentMethodeNat_MethodeID = Nat_MethodeID and M_InstrumentMethodeIsActive = 'Y' - join nat_instrument on M_InstrumentMethodeNat_InstrumentID = Nat_InstrumentID - and Nat_InstrumentIsActive ='Y' - where M_MethodePriorityIsActive = 'Y' - and M_MethodePriorityNat_TestID = $natTestID - and M_MethodePriorityM_DayOfWeekID = dayofweek(now()) - order by M_MethodePriorityNumber desc - limit 0,1 "; - $qry = $this->db->query($sql); - if ($qry) { - $rows = $qry->result_array(); - if (count($rows) > 0) return array($rows[0]["MethodeID"], $rows[0]["Nat_MethodeName"]); - } - //2nd - $sql = "select - M_InstrumentMethodeNat_MethodeID MethodeID, Nat_MethodeName - from m_instrumentmethode - join nat_methode on M_InstrumentMethodeNat_MethodeID = Nat_MethodeID - and Nat_MethodeIsActive = 'Y' - join nat_instrument on M_InstrumentMethodeNat_InstrumentID = Nat_InstrumentID - and Nat_InstrumentIsActive ='Y' - where M_InstrumentMethodeNat_TestID = $natTestID - and M_InstrumentMethodeIsActive = 'Y' - order by M_InstrumentMethodePriority desc - limit 0,1"; - $qry = $this->db->query($sql); - if ($qry) { - $rows = $qry->result_array(); - if (count($rows) > 0) return array($rows[0]["MethodeID"], $rows[0]["Nat_MethodeName"]); - } - // - $sql = "select Nat_NormalValueNat_MethodeID MethodeID, Nat_MethodeName - from - nat_normalvalue - join nat_methode on Nat_NormalValueNat_MethodeID = Nat_MethodeID - and Nat_MethodeIsActive = 'Y' - where Nat_NormalValueNat_TestID = $natTestID - and Nat_NormalValueIsActive = 'Y' - order by Nat_NormalValueID - limit 0,1"; - $qry = $this->db->query($sql); - if ($qry) { - $rows = $qry->result_array(); - if (count($rows) > 0) return array($rows[0]["MethodeID"], $rows[0]["Nat_MethodeName"]); - } - return array(0, ""); - } - function get_normal_value($methodeID, $natTestID, $sexID, $ageInDay) - { - $sql = "select fn_sampling_get_normal($methodeID, $natTestID, $sexID, $ageInDay) as normalValueID"; - $qry = $this->db->query($sql); - if ($qry) { - $rows = $qry->result_array(); - if (count($rows) > 0) return $rows[0]["normalValueID"]; - } - return 0; - } - function fn_fix_normal($order_id) - { - $sql = "select - T_OrderDetailID, M_PatientM_SexID, fn_global_age_count_day(M_PatientDOB, date(T_OrderHeaderDate)) Dob , - T_TestNat_TestID - from t_orderheader - join m_patient on T_OrderHeaderID = $order_id and T_OrderHeaderM_PatientID = M_PatientID - join t_orderdetail on T_OrderDetailT_OrderHeaderID = T_OrderHeaderID - and T_OrderDetailIsACtive = 'Y' - and ( T_OrderDetailNat_NormalValueID is null or T_OrderDetailNat_NormalValueID = 0 ) - join t_test on T_OrderDetailT_TestID = T_TestID and T_TestIsResult = 'Y' "; - $qry = $this->db->query($sql); - if (! $qry) { - return; - } - $rows = $qry->result_array(); - if (count($rows) == 0) return; - $sql_u = "update t_orderdetail - join nat_normalvalue on T_OrderDetailID = ? and Nat_NormalValueID = ? - set - T_OrderDetailNat_NormalValueID = Nat_NormalValueID, - T_OrderDetailNormalValueNote = Nat_NormalValueNote, - T_OrderDetailNormalValueDescription = Nat_NormalValueDescription, - T_OrderDetailMinValue = Nat_NormalValueMinValue, - T_OrderDetailMaxValue = Nat_NormalValueMaxValue, - T_OrderDetailMinValueInclusive = Nat_NormalValueMinValueInclusive, - T_OrderDetailMaxValueInclusive = Nat_NormalValueMaxValueInclusive, - T_OrderDetailNat_MethodeID = ?, - T_OrderdetailNat_MethodeName =?"; - - foreach ($rows as $r) { - $T_OrderDetailID = $r["T_OrderDetailID"]; - $sexID = $r["M_PatientM_SexID"]; - $ageInDay = $r["Dob"]; - $natTestID = $r["T_TestNat_TestID"]; - list($methodeID, $methodeName) = $this->getMethodeID($natTestID); - if ($methodeID == 0) continue; - $normalValueID = $this->get_normal_value($methodeID, $natTestID, $sexID, $ageInDay); - if ($normalValueID == 0) return; - $this->db->query($sql_u, array($T_OrderDetailID, $normalValueID, $methodeID, $methodeName)); - } - } - function update_order_sample($targetID, $sourceID) - { - $sql = "update t_ordersample target - join t_ordersample source on - target.T_OrderSampleID = ? - and target.T_OrderSampleWorklistReceive = 'N' - and source.T_OrderSampleID = ? - set - target.T_OrderSampleSampling = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSampling, source.T_OrderSampleSampling), - target.T_OrderSampleSamplingDate = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingDate, source.T_OrderSampleSamplingDate), - target.T_OrderSampleSamplingTime = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingTime, source.T_OrderSampleSamplingTime), - target.T_OrderSampleSamplingUserID = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingUserID, source.T_OrderSampleSamplingUserID), - - target.T_OrderSampleReceive = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceive, source.T_OrderSampleReceive), - target.T_OrderSampleReceiveDate = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveDate, source.T_OrderSampleReceiveDate), - target.T_OrderSampleReceiveTime = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveTime, source.T_OrderSampleReceiveTime), - target.T_OrderSampleReceiveUserID = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveUserID, source.T_OrderSampleReceiveUserID), - - target.T_OrderSampleVerification = if(target.T_OrderSampleVerification='Y',target.T_OrderSampleVerification, source.T_OrderSampleVerification), - target.T_OrderSampleVerificationDate =if(target.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationDate, source.T_OrderSampleVerificationDate), - target.T_OrderSampleVerificationTime =if(source.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationTime, source.T_OrderSampleVerificationTime), - target.T_OrderSampleVerificationUserID =if(source.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationUserID, source.T_OrderSampleVerificationUserID), - - target.T_OrderSampleProcessing = if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessing, source.T_OrderSampleProcessing), - target.T_OrderSampleProcessingDate= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingDate, source.T_OrderSampleProcessingDate), - target.T_OrderSampleProcessingTime= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingTime, source.T_OrderSampleProcessingTime), - target.T_OrderSampleProcessingUserID= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingUserID, source.T_OrderSampleProcessingUserID), - - target.T_OrderSampleReceiveHandling =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandling, source.T_OrderSampleReceiveHandling ), - target.T_OrderSampleReceiveHandlingDate =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingDate, source.T_OrderSampleReceiveHandlingDate), - target.T_OrderSampleReceiveHandlingTime =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingTime, source.T_OrderSampleReceiveHandlingTime), - target.T_OrderSampleReceiveHandlingUserID =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingUserID, source.T_OrderSampleReceiveHandlingUserID), - - target.T_OrderSampleHandling = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandling, source.T_OrderSampleHandling), - target.T_OrderSampleHandlingDate = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingDate, source.T_OrderSampleHandlingDate), - target.T_OrderSampleHandlingTime = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingTime, source.T_OrderSampleHandlingTime), - target.T_OrderSampleHandlingUserID = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingUserID, source.T_OrderSampleHandlingUserID), - - target.T_OrderSampleWorklistReceive = source.T_OrderSampleWorklistReceive, - target.T_OrderSampleWorklistReceiveDatetime = source.T_OrderSampleWorklistReceiveDateTime, - target.T_OrderSampleWorklistReceiveUserID = source.T_OrderSampleWorklistReceiveUserID - "; - $qry = $this->db->query($sql, array($targetID, $sourceID)); - if (! $qry) { - echo json_encode(array("status" => "ERR", "message" => print_r($this->db->error(), true))); - exit; - } - } +db_smartone = $this->load->database("onedev", true); + $this->db_lab = $this->load->database('one_lab_log', TRUE); + $this->load->helper(array('form', 'url')); + } + function getMethodeID($natTestID) + { + $sql = "select M_MethodePriorityNat_MethodeID MethodeID, Nat_MethodeName + from + m_methode_priority + join nat_methode on Nat_MethodeID = M_MethodePriorityNat_MethodeID + and Nat_MethodeIsActive = 'Y' + join m_instrumentmethode on M_InstrumentMethodeNat_MethodeID = Nat_MethodeID and M_InstrumentMethodeIsActive = 'Y' + join nat_instrument on M_InstrumentMethodeNat_InstrumentID = Nat_InstrumentID + and Nat_InstrumentIsActive ='Y' + where M_MethodePriorityIsActive = 'Y' + and M_MethodePriorityNat_TestID = $natTestID + and M_MethodePriorityM_DayOfWeekID = dayofweek(now()) + order by M_MethodePriorityNumber desc + limit 0,1 "; + $qry = $this->db->query($sql); + if ($qry) { + $rows = $qry->result_array(); + if (count($rows) > 0) return array($rows[0]["MethodeID"], $rows[0]["Nat_MethodeName"]); + } + //2nd + $sql = "select + M_InstrumentMethodeNat_MethodeID MethodeID, Nat_MethodeName + from m_instrumentmethode + join nat_methode on M_InstrumentMethodeNat_MethodeID = Nat_MethodeID + and Nat_MethodeIsActive = 'Y' + join nat_instrument on M_InstrumentMethodeNat_InstrumentID = Nat_InstrumentID + and Nat_InstrumentIsActive ='Y' + where M_InstrumentMethodeNat_TestID = $natTestID + and M_InstrumentMethodeIsActive = 'Y' + order by M_InstrumentMethodePriority desc + limit 0,1"; + $qry = $this->db->query($sql); + if ($qry) { + $rows = $qry->result_array(); + if (count($rows) > 0) return array($rows[0]["MethodeID"], $rows[0]["Nat_MethodeName"]); + } + // + $sql = "select Nat_NormalValueNat_MethodeID MethodeID, Nat_MethodeName + from + nat_normalvalue + join nat_methode on Nat_NormalValueNat_MethodeID = Nat_MethodeID + and Nat_MethodeIsActive = 'Y' + where Nat_NormalValueNat_TestID = $natTestID + and Nat_NormalValueIsActive = 'Y' + order by Nat_NormalValueID + limit 0,1"; + $qry = $this->db->query($sql); + if ($qry) { + $rows = $qry->result_array(); + if (count($rows) > 0) return array($rows[0]["MethodeID"], $rows[0]["Nat_MethodeName"]); + } + return array(0, ""); + } + function get_normal_value($methodeID, $natTestID, $sexID, $ageInDay) + { + $this->load->library('ibl_sampling_normal'); + return $this->ibl_sampling_normal->get_normal_value_id($methodeID, $natTestID, $sexID, $ageInDay); + } + return 0; + } + function fn_fix_normal($order_id) + { + $sql = "select + T_OrderDetailID, M_PatientM_SexID, fn_global_age_count_day(M_PatientDOB, date(T_OrderHeaderDate)) Dob , + T_TestNat_TestID + from t_orderheader + join m_patient on T_OrderHeaderID = $order_id and T_OrderHeaderM_PatientID = M_PatientID + join t_orderdetail on T_OrderDetailT_OrderHeaderID = T_OrderHeaderID + and T_OrderDetailIsACtive = 'Y' + and ( T_OrderDetailNat_NormalValueID is null or T_OrderDetailNat_NormalValueID = 0 ) + join t_test on T_OrderDetailT_TestID = T_TestID and T_TestIsResult = 'Y' "; + $qry = $this->db->query($sql); + if (! $qry) { + return; + } + $rows = $qry->result_array(); + if (count($rows) == 0) return; + $sql_u = "update t_orderdetail + join nat_normalvalue on T_OrderDetailID = ? and Nat_NormalValueID = ? + set + T_OrderDetailNat_NormalValueID = Nat_NormalValueID, + T_OrderDetailNormalValueNote = Nat_NormalValueNote, + T_OrderDetailNormalValueDescription = Nat_NormalValueDescription, + T_OrderDetailMinValue = Nat_NormalValueMinValue, + T_OrderDetailMaxValue = Nat_NormalValueMaxValue, + T_OrderDetailMinValueInclusive = Nat_NormalValueMinValueInclusive, + T_OrderDetailMaxValueInclusive = Nat_NormalValueMaxValueInclusive, + T_OrderDetailNat_MethodeID = ?, + T_OrderdetailNat_MethodeName =?"; + + foreach ($rows as $r) { + $T_OrderDetailID = $r["T_OrderDetailID"]; + $sexID = $r["M_PatientM_SexID"]; + $ageInDay = $r["Dob"]; + $natTestID = $r["T_TestNat_TestID"]; + list($methodeID, $methodeName) = $this->getMethodeID($natTestID); + if ($methodeID == 0) continue; + $normalValueID = $this->get_normal_value($methodeID, $natTestID, $sexID, $ageInDay); + if ($normalValueID == 0) return; + $this->db->query($sql_u, array($T_OrderDetailID, $normalValueID, $methodeID, $methodeName)); + } + } + function update_order_sample($targetID, $sourceID) + { + $sql = "update t_ordersample target + join t_ordersample source on + target.T_OrderSampleID = ? + and target.T_OrderSampleWorklistReceive = 'N' + and source.T_OrderSampleID = ? + set + target.T_OrderSampleSampling = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSampling, source.T_OrderSampleSampling), + target.T_OrderSampleSamplingDate = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingDate, source.T_OrderSampleSamplingDate), + target.T_OrderSampleSamplingTime = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingTime, source.T_OrderSampleSamplingTime), + target.T_OrderSampleSamplingUserID = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingUserID, source.T_OrderSampleSamplingUserID), + + target.T_OrderSampleReceive = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceive, source.T_OrderSampleReceive), + target.T_OrderSampleReceiveDate = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveDate, source.T_OrderSampleReceiveDate), + target.T_OrderSampleReceiveTime = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveTime, source.T_OrderSampleReceiveTime), + target.T_OrderSampleReceiveUserID = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveUserID, source.T_OrderSampleReceiveUserID), + + target.T_OrderSampleVerification = if(target.T_OrderSampleVerification='Y',target.T_OrderSampleVerification, source.T_OrderSampleVerification), + target.T_OrderSampleVerificationDate =if(target.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationDate, source.T_OrderSampleVerificationDate), + target.T_OrderSampleVerificationTime =if(source.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationTime, source.T_OrderSampleVerificationTime), + target.T_OrderSampleVerificationUserID =if(source.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationUserID, source.T_OrderSampleVerificationUserID), + + target.T_OrderSampleProcessing = if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessing, source.T_OrderSampleProcessing), + target.T_OrderSampleProcessingDate= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingDate, source.T_OrderSampleProcessingDate), + target.T_OrderSampleProcessingTime= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingTime, source.T_OrderSampleProcessingTime), + target.T_OrderSampleProcessingUserID= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingUserID, source.T_OrderSampleProcessingUserID), + + target.T_OrderSampleReceiveHandling =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandling, source.T_OrderSampleReceiveHandling ), + target.T_OrderSampleReceiveHandlingDate =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingDate, source.T_OrderSampleReceiveHandlingDate), + target.T_OrderSampleReceiveHandlingTime =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingTime, source.T_OrderSampleReceiveHandlingTime), + target.T_OrderSampleReceiveHandlingUserID =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingUserID, source.T_OrderSampleReceiveHandlingUserID), + + target.T_OrderSampleHandling = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandling, source.T_OrderSampleHandling), + target.T_OrderSampleHandlingDate = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingDate, source.T_OrderSampleHandlingDate), + target.T_OrderSampleHandlingTime = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingTime, source.T_OrderSampleHandlingTime), + target.T_OrderSampleHandlingUserID = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingUserID, source.T_OrderSampleHandlingUserID), + + target.T_OrderSampleWorklistReceive = source.T_OrderSampleWorklistReceive, + target.T_OrderSampleWorklistReceiveDatetime = source.T_OrderSampleWorklistReceiveDateTime, + target.T_OrderSampleWorklistReceiveUserID = source.T_OrderSampleWorklistReceiveUserID + "; + $qry = $this->db->query($sql, array($targetID, $sourceID)); + if (! $qry) { + echo json_encode(array("status" => "ERR", "message" => print_r($this->db->error(), true))); + exit; + } + } function fix_sample_serum($headerID) { - //cari t_ordersample yg belum worklist receive dengan code 017% - $sql = "select T_OrderSampleID - from t_ordersample - join t_sampletype on - T_OrderSampleT_OrderHeaderID = ? - and T_OrderSampleWorklistReceive = 'N' - and T_OrderSampleIsActive = 'Y' - and T_OrderSampleT_SampleTypeID = T_SampletypeID - and T_SampleTypeCode like '017%' - "; - $qry = $this->db->query($sql, array($headerID)); - if (!$qry) { - echo json_encode(array("status" => "ERR", "message" => print_r($this->db->error(), true))); - exit; - } - $rows = $qry->result_array(); - if (count($rows) == 0) return; - //cari T_OrderSample yang sudah di receive yg terakhir - $sql = "select T_OrderSampleID - from t_ordersample - join t_sampletype on - T_OrderSampleT_OrderHeaderID = ? - and T_OrderSampleWorklistReceive = 'Y' - and T_OrderSampleIsActive = 'Y' - and T_OrderSampleT_SampleTypeID = T_SampletypeID - and T_SampleTypeCode like '017%' - order by T_OrderSampleWorklistReceiveDatetime desc - limit 0,1 - "; - $qry = $this->db->query($sql, array($headerID)); - if (!$qry) { - echo json_encode(array("status" => "ERR", "message" => print_r($this->db->error(), true))); - exit; - } - $rcv_rows = $qry->result_array(); - if (count($rcv_rows) == 0) return; - - //print_r($rows); - //print_r($rcv_rows); - $rcv_T_OrderSampleID = $rcv_rows[0]["T_OrderSampleID"]; - //ada yg belum di receive + //cari t_ordersample yg belum worklist receive dengan code 017% + $sql = "select T_OrderSampleID + from t_ordersample + join t_sampletype on + T_OrderSampleT_OrderHeaderID = ? + and T_OrderSampleWorklistReceive = 'N' + and T_OrderSampleIsActive = 'Y' + and T_OrderSampleT_SampleTypeID = T_SampletypeID + and T_SampleTypeCode like '017%' + "; + $qry = $this->db->query($sql, array($headerID)); + if (!$qry) { + echo json_encode(array("status" => "ERR", "message" => print_r($this->db->error(), true))); + exit; + } + $rows = $qry->result_array(); + if (count($rows) == 0) return; + //cari T_OrderSample yang sudah di receive yg terakhir + $sql = "select T_OrderSampleID + from t_ordersample + join t_sampletype on + T_OrderSampleT_OrderHeaderID = ? + and T_OrderSampleWorklistReceive = 'Y' + and T_OrderSampleIsActive = 'Y' + and T_OrderSampleT_SampleTypeID = T_SampletypeID + and T_SampleTypeCode like '017%' + order by T_OrderSampleWorklistReceiveDatetime desc + limit 0,1 + "; + $qry = $this->db->query($sql, array($headerID)); + if (!$qry) { + echo json_encode(array("status" => "ERR", "message" => print_r($this->db->error(), true))); + exit; + } + $rcv_rows = $qry->result_array(); + if (count($rcv_rows) == 0) return; + + //print_r($rows); + //print_r($rcv_rows); + $rcv_T_OrderSampleID = $rcv_rows[0]["T_OrderSampleID"]; + //ada yg belum di receive foreach ($rows as $r) { $T_OrderSampleID = $r["T_OrderSampleID"]; $this->update_order_sample($T_OrderSampleID, $rcv_T_OrderSampleID); @@ -478,7 +475,8 @@ class Re_px extends MY_Controller return; } - $call = $this->call_multi_result_procedure("CALL sp_sampling_check_normal_setting({$order_detail_id})"); + $this->load->library('ibl_sampling_normal'); + $call = $this->ibl_sampling_normal->check_setting_by_order_detail($order_detail_id); if (!$call["ok"]) { $this->sys_error($call["message"]); return; @@ -514,7 +512,8 @@ class Re_px extends MY_Controller return; } - $call = $this->call_multi_result_procedure("CALL sp_sampling_fix_normal_by_orderdetail({$order_detail_id})"); + $this->load->library('ibl_sampling_normal'); + $call = $this->ibl_sampling_normal->fix_by_order_detail($order_detail_id); if (!$call["ok"]) { $this->sys_error($call["message"]); return; @@ -534,278 +533,278 @@ class Re_px extends MY_Controller public function search() { $prm = $this->sys_input; - $max_rst = 99; - - $id = $prm["order_id"]; - if ($id > 0) { - $this->fix_sample_serum($id); - $this->fn_fix_normal($id); - } - $lang = $this->lang_default_code; - $lang_id = isset($prm['lang_id']) ? $prm['lang_id'] : '0'; - - if ($lang_id != 0) { - $l = $this->db_smartone->where("Nat_LangID", $lang_id)->get("nat_lang")->row(); - $lang = $l->Nat_LangCode; - } - - //tambahan fajri - $sql = " UPDATE t_orderdetail - JOIN t_test ON T_OrderDetailT_TestID = T_TestID - SET T_OrderDetailT_TestIsResult = T_TestIsResult - WHERE - T_OrderDetailT_OrderHeaderID = {$id} AND - T_OrderDetailT_TestIsResult = '' AND - T_OrderDetailIsActive = 'Y'"; - $this->db_smartone->query($sql); - - $tot_count = 0; - $lq = ""; - $group_id = 0; - if (isset($prm['group_id'])) - $group_id = $prm['group_id']; - - if ($group_id != 0) { - $sql = "select distinct T_WorklistDetailNat_TestID Nat_TestID - from t_worklistdetailv2 - where T_WorklistDetailT_WorklistID = {$group_id}"; - $qry = $this->db_smartone->query($sql); - $rows = $qry->result_array(); - $nat_test_ids = "0"; - foreach ($rows as $r) { - $nat_test_ids .= ", " . $r["Nat_TestID"]; - } - $q_group = " ( $nat_test_ids ) "; - - $sql = " - SELECT a1.*, cOUNT(a2.T_OrderDetailID) level - FROM ( - SELECT IFNULL(y.T_OrderDetailT_TestID, x.T_OrderDetailT_TestID) t_testid, - IFNULL(y.T_OrderDetailT_TestName, y.T_OrderDetailT_TestName) t_testname, - y.T_OrderDetailResult result, y.T_OrderDetailResult result_old, y.T_OrderDetailNote note, y.T_OrderDetailNote note_old, - y.T_OrderDetailID id, - y.T_OrderDetailT_TestIsResult is_result, a.T_TestIsQuantitative is_quantitative, - y.T_OrderDetailResultFlag result_flag, - y.T_OrderDetailNat_NormalValueID normal_id, - y.T_OrderDetailNormalValueNote normal_note, y.T_OrderDetailNat_UnitName unit_name, - y.T_OrderdetailNat_MethodeID methode_id, y.T_OrderdetailNat_MethodeName methode_name, - a.T_TestNat_TestID nattest_id, a.T_TestID tx_id, count(T_ResultInstrumentID) as result_instrument_n, - y.T_OrderDetailVerification, T_OrderSampleReceive sample_receive, - T_OrderSampleProcessing sample_processing, T_OrderSampleWorklistReceive sample_worklist_receive, - IF(T_OrderDetailAddOnPreAnalytic = 'Y', T_OrderDetailAddOnPreAnalytic, PreAnalyticIsOk) pre_analytic, - T_OrderDetailAddOnPreAnalytic, - T_OrderHeaderID order_id, y.T_OrderDetailT_TestSasCode test_sas_code, - tx.T_TestSasCode, - T_OrderDetailAddOnResample `resample`, T_OrderDetailAddOnResampleStatus resample_status, - T_OrderDetailAddOnRef ref, y.T_OrderDetailVerification verification, y.T_OrderDetailValidation validation, - T_OrderPromiseDateTime, Group_ResultName as ResultGroupName - FROM t_orderdetail x - left join t_orderpromise on x.T_OrderDetailT_OrderPromiseID = T_OrderPromiseID - JOIN t_test tx ON x.T_OrderDetailT_TestID = T_TestID - JOIN t_test tcheck on tcheck.T_TestNat_TestID in {$q_group} - and ( tx.T_TestID = tcheck.T_TestID or tx.T_TestSasCode like concat(tcheck.T_TestSasCode,'%')) - JOIN group_resultdetail ON Group_ResultDetailT_TestID = x.T_OrderDetailT_TestID AND Group_ResultDetailIsActive = 'Y' - JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND Group_ResultResumeMcu = 'LAB' - LEFT JOIN t_orderdetail y ON x.T_OrderDetailT_TestSasCode LIKE CONCAT(y.T_OrderDetailT_TestSasCode, '%') - AND x.T_OrderDetailT_OrderHeaderID = y.T_OrderDetailT_OrderHeaderID - AND y.T_OrderDetailIsActive = 'Y' - LEFT JOIN t_orderdetailaddon ON x.T_OrderDetailID = T_OrderDetailAddOnT_OrderDetailID - JOIN t_orderheader ON y.T_OrderDetailT_OrderHeaderID = T_OrderHeaderID - LEFT JOIN t_test a ON y.T_OrderDetailT_TestID = a.T_TestID - AND a.T_TestIsNonLab = '' - LEFT JOIN (SELECT T_OrderSampleT_SampleTypeID, T_OrderSampleReceive, T_OrderSampleProcessing, T_OrderSampleWorklistReceive - FROM t_ordersample WHERE T_OrderSampleT_OrderHeaderID = {$id} - AND T_OrderSampleIsactive = 'Y' - GROUP BY T_OrderSampleT_SampleTypeID) os ON a.T_TestT_SampleTypeID = os.T_OrderSampleT_SampleTypeID - or os.T_OrderSampleT_SampleTypeID = fn_sampletype_from_local(a.T_TestNat_TestID) - - LEFT JOIN t_resultinstrument ON T_ResultInstrumentT_OrderDetailID = x.T_OrderDetailID - LEFT JOIN pre_analytic ON PreAnalyticNat_TestID = a.T_TestNat_TestID AND PreAnalyticDate = date(now()) and PreAnalyticIsActive = 'Y' - WHERE x.T_OrderDetailT_OrderHeaderID = {$id} - AND x.T_OrderDetailIsActive = 'Y' - GROUP BY y.T_OrderDetailT_TestID - ORDER BY y.T_OrderDetailT_TestSasCode ASC - ) a1 - - LEFT JOIN t_orderdetail a2 ON a2.T_OrderDetailT_OrderHeaderID = a1.order_id - AND a2.T_OrderDetailIsActive = 'Y' - AND a1.test_sas_code LIKE CONCAT(a2.T_OrderDetailT_testSasCode, '%') - GROUP BY a1.t_testid - order by a1.test_sas_code -"; - $query = $this->db_smartone->query($sql); - $lq = $this->db_smartone->last_query(); - } else { - $sql = " - SELECT a1.*, cOUNT(a2.T_OrderDetailID) level - FROM ( - SELECT IFNULL(y.T_OrderDetailT_TestID, x.T_OrderDetailT_TestID) t_testid, - IFNULL(y.T_OrderDetailT_TestName, y.T_OrderDetailT_TestName) t_testname, - y.T_OrderDetailResult result, y.T_OrderDetailResult result_old, y.T_OrderDetailNote note, y.T_OrderDetailNote note_old, - y.T_OrderDetailID id, - y.T_OrderDetailT_TestIsResult is_result, a.T_TestIsQuantitative is_quantitative, - y.T_OrderDetailResultFlag result_flag, - y.T_OrderDetailNat_NormalValueID normal_id, - y.T_OrderDetailNormalValueNote normal_note, y.T_OrderDetailNat_UnitName unit_name, - y.T_OrderdetailNat_MethodeID methode_id, y.T_OrderdetailNat_MethodeName methode_name, - a.T_TestNat_TestID nattest_id, a.T_TestID tx_id, count(T_ResultInstrumentID) as result_instrument_n, - y.T_OrderDetailVerification, T_OrderSampleReceive sample_receive, - T_OrderSampleProcessing sample_processing, T_OrderSampleWorklistReceive sample_worklist_receive, - IF(T_OrderDetailAddOnPreAnalytic = 'Y', T_OrderDetailAddOnPreAnalytic, PreAnalyticIsOk) pre_analytic, - T_OrderDetailAddOnPreAnalytic, - T_OrderHeaderID order_id, y.T_OrderDetailT_TestSasCode test_sas_code, - tx.T_TestSasCode, - T_OrderDetailAddOnResample `resample`, T_OrderDetailAddOnResampleStatus resample_status, - T_OrderDetailAddOnRef ref, y.T_OrderDetailVerification verification, y.T_OrderDetailValidation validation, - T_OrderPromiseDateTime , Group_ResultName as ResultGroupName - FROM t_orderdetail x - left join t_orderpromise on x.T_OrderDetailT_OrderPromiseID = T_OrderPromiseID - JOIN t_test tx ON x.T_OrderDetailT_TestID = T_TestID - JOIN group_resultdetail ON Group_ResultDetailT_TestID = x.T_OrderDetailT_TestID AND Group_ResultDetailIsActive = 'Y' - JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND Group_ResultResumeMcu = 'LAB' - LEFT JOIN t_orderdetail y ON x.T_OrderDetailT_TestSasCode LIKE CONCAT(y.T_OrderDetailT_TestSasCode, '%') - AND x.T_OrderDetailT_OrderHeaderID = y.T_OrderDetailT_OrderHeaderID - AND y.T_OrderDetailIsActive = 'Y' - - LEFT JOIN t_orderdetailaddon ON x.T_OrderDetailID = T_OrderDetailAddOnT_OrderDetailID - - JOIN t_orderheader ON y.T_OrderDetailT_OrderHeaderID = T_OrderHeaderID - LEFT JOIN t_test a ON y.T_OrderDetailT_TestID = a.T_TestID - AND a.T_TestIsNonLab = '' - LEFT JOIN (SELECT T_OrderSampleT_SampleTypeID, T_OrderSampleReceive, T_OrderSampleProcessing, T_OrderSampleWorklistReceive - FROM t_ordersample WHERE T_OrderSampleT_OrderHeaderID = {$id} - AND T_OrderSampleIsactive = 'Y' - GROUP BY T_OrderSampleT_SampleTypeID) os ON a.T_TestT_SampleTypeID = os.T_OrderSampleT_SampleTypeID - or os.T_OrderSampleT_SampleTypeID = fn_sampletype_from_local(a.T_TestNat_TestID) - - LEFT JOIN t_resultinstrument ON T_ResultInstrumentT_OrderDetailID = x.T_OrderDetailID - LEFT JOIN pre_analytic ON PreAnalyticNat_TestID = a.T_TestNat_TestID AND PreAnalyticDate = date(now()) and PreAnalyticIsActive = 'Y' - WHERE x.T_OrderDetailT_OrderHeaderID = {$id} - AND x.T_OrderDetailIsActive = 'Y' - GROUP BY y.T_OrderDetailT_TestID - ORDER BY y.T_OrderDetailT_TestSasCode ASC - ) a1 - - LEFT JOIN t_orderdetail a2 ON a2.T_OrderDetailT_OrderHeaderID = a1.order_id - AND a2.T_OrderDetailIsActive = 'Y' - AND a1.test_sas_code LIKE CONCAT(a2.T_OrderDetailT_testSasCode, '%') - GROUP BY a1.t_testid - order by a1.test_sas_code -"; - //echo $sql; - $query = $this->db_smartone->query($sql); - $lq = $this->db_smartone->last_query(); - } - // file_put_contents("/xtmp/re-query.sql",$lq); - - if ($query) { - $rst = []; - $rows = $query->result_array(); - - foreach ($rows as $k => $v) { - - if ($v['is_result'] == "Y" && $v['is_quantitative'] == "N") { - $v['template'] = []; - $x = $this->db_smartone->query("CALL sp_master_resulttemplate_get('{$v['t_testid']}')"); - $this->clean_mysqli_connection($this->db_smartone->conn_id); - if ($x) - $v['template'] = $x->result_array(); - } - - // IF Rujukan, by pas Pre Analytik - if ($v['ref'] == 'Y') - $v['pre_analytic'] = 'Y'; - if ($v["id"] == "885455") { - //sipe workaround - //$v["sample_receive"] = "Y"; - $v["sample_worklist_receive"] = "Y"; - } - $rst[] = $v; - } - - $result = array("total" => $tot_count, "records" => $rst, "total_display" => sizeof($rows), "q" => $lq); - $this->sys_ok($result); - } else { - $this->sys_error_db("RE Px rows", $this->db_smartone); - exit; - } - } - - public function save() - { - $prm = $this->sys_input; - $data = json_decode($prm["data"]); - $lang = $this->lang_default_code; - $lang_id = isset($prm['lang_id']) ? $prm['lang_id'] : '0'; - - if ($lang_id != 0) { - $l = $this->db_smartone->where("Nat_LangID", $lang_id)->get("nat_lang")->row(); - $lang = $l->Nat_LangCode; - } - - $sql_norm = "select T_OrderDetailMinValue, T_OrderDetailMaxValue, - T_OrderDetailMinValueInclusive, T_OrderDetailMaxValueInclusive, - Nat_TestFlagLow, Nat_TestFlagHigh - from t_orderdetail - join t_test on T_OrderDetailT_TestID = T_TestID - join nat_test on T_TestNat_TestID = Nat_TestID and T_TestIsActive = 'Y' - where T_OrderDetailID = ? "; - - $ids = []; - foreach ($data as $k => $v) { - if ($v->resultInstrumentID > 0) { - $sql_i = "select T_ResultInstrumentNat_NormalValueID normalValueID - from t_resultinstrument - where T_ResultInstrumentID = ?"; - $qry_i = $this->db_smartone->query($sql_i, array($v->resultInstrumentID)); - if ($qry_i) { - $rows_i = $qry_i->result_array(); - - if (count($rows_i) > 0) { - $sql_iu = "update t_orderdetail, nat_normalvalue , nat_methode - set T_OrderDetailMinValue = Nat_NormalValueMinValue, - T_OrderDetailMinValueInclusive = Nat_NormalValueMinValueInclusive, - T_OrderDetailMaxValue = Nat_NormalValueMaxValue , - T_OrderDetailMaxValueInclusive = Nat_NormalValueMaxValueInclusive, - T_OrderDetailNormalValueNote = Nat_NormalValueNote, - T_OrderDetailNormalValueDescription = Nat_NormalValueDescription, - T_OrderDetailNat_NormalValueID = Nat_NormalValueID, - T_OrderDetailNat_MethodeID = Nat_NormalValueNat_MethodeID, - T_OrderDetailNat_MethodeName = Nat_MethodeName - where T_OrderDetailID = ? and Nat_NormalValueID = ? - and Nat_NormalValueNat_MethodeID = Nat_MethodeID - "; - $this->db_smartone->query($sql_iu, array($v->id, $rows_i[0]["normalValueID"])); - //file_put_contents("/xtmp/update-nilai-normal", $this->db_smartone->last_query() . "\n", FILE_APPEND); - } - } - } - $y = $this->db_smartone->query("SELECT fn_process_sample_handling_perfect('{$v->order_id}', '{$v->test_id}') c") - ->row(); - $req_status = $y->c; - $qry_norm = $this->db_smartone->query($sql_norm, $v->id); - $result_flag = ""; - if ($qry_norm) { - $rows_norm = $qry_norm->result_array(); - if (count($rows_norm) > 0) { - $r = $rows_norm[0]; - if (is_numeric($v->result)) { - - if ($r["T_OrderDetailMinValueInclusive"] == "Y" && $v->result < $r["T_OrderDetailMinValue"]) { - $result_flag = $r["Nat_TestFlagLow"]; - } - if ($r["T_OrderDetailMinValueInclusive"] == "N" && $v->result <= $r["T_OrderDetailMinValue"]) { - $result_flag = $r["Nat_TestFlagLow"]; - } - if ($r["T_OrderDetailMaxValueInclusive"] == "Y" && $v->result > $r["T_OrderDetailMaxValue"]) { - $result_flag = $r["Nat_TestFlagHigh"]; - } - if ($r["T_OrderDetailMaxValueInclusive"] == "N" && $v->result >= $r["T_OrderDetailMaxValue"]) { - $result_flag = $r["Nat_TestFlagHigh"]; - } - } - } - } + $max_rst = 99; + + $id = $prm["order_id"]; + if ($id > 0) { + $this->fix_sample_serum($id); + $this->fn_fix_normal($id); + } + $lang = $this->lang_default_code; + $lang_id = isset($prm['lang_id']) ? $prm['lang_id'] : '0'; + + if ($lang_id != 0) { + $l = $this->db_smartone->where("Nat_LangID", $lang_id)->get("nat_lang")->row(); + $lang = $l->Nat_LangCode; + } + + //tambahan fajri + $sql = " UPDATE t_orderdetail + JOIN t_test ON T_OrderDetailT_TestID = T_TestID + SET T_OrderDetailT_TestIsResult = T_TestIsResult + WHERE + T_OrderDetailT_OrderHeaderID = {$id} AND + T_OrderDetailT_TestIsResult = '' AND + T_OrderDetailIsActive = 'Y'"; + $this->db_smartone->query($sql); + + $tot_count = 0; + $lq = ""; + $group_id = 0; + if (isset($prm['group_id'])) + $group_id = $prm['group_id']; + + if ($group_id != 0) { + $sql = "select distinct T_WorklistDetailNat_TestID Nat_TestID + from t_worklistdetailv2 + where T_WorklistDetailT_WorklistID = {$group_id}"; + $qry = $this->db_smartone->query($sql); + $rows = $qry->result_array(); + $nat_test_ids = "0"; + foreach ($rows as $r) { + $nat_test_ids .= ", " . $r["Nat_TestID"]; + } + $q_group = " ( $nat_test_ids ) "; + + $sql = " + SELECT a1.*, cOUNT(a2.T_OrderDetailID) level + FROM ( + SELECT IFNULL(y.T_OrderDetailT_TestID, x.T_OrderDetailT_TestID) t_testid, + IFNULL(y.T_OrderDetailT_TestName, y.T_OrderDetailT_TestName) t_testname, + y.T_OrderDetailResult result, y.T_OrderDetailResult result_old, y.T_OrderDetailNote note, y.T_OrderDetailNote note_old, + y.T_OrderDetailID id, + y.T_OrderDetailT_TestIsResult is_result, a.T_TestIsQuantitative is_quantitative, + y.T_OrderDetailResultFlag result_flag, + y.T_OrderDetailNat_NormalValueID normal_id, + y.T_OrderDetailNormalValueNote normal_note, y.T_OrderDetailNat_UnitName unit_name, + y.T_OrderdetailNat_MethodeID methode_id, y.T_OrderdetailNat_MethodeName methode_name, + a.T_TestNat_TestID nattest_id, a.T_TestID tx_id, count(T_ResultInstrumentID) as result_instrument_n, + y.T_OrderDetailVerification, T_OrderSampleReceive sample_receive, + T_OrderSampleProcessing sample_processing, T_OrderSampleWorklistReceive sample_worklist_receive, + IF(T_OrderDetailAddOnPreAnalytic = 'Y', T_OrderDetailAddOnPreAnalytic, PreAnalyticIsOk) pre_analytic, + T_OrderDetailAddOnPreAnalytic, + T_OrderHeaderID order_id, y.T_OrderDetailT_TestSasCode test_sas_code, + tx.T_TestSasCode, + T_OrderDetailAddOnResample `resample`, T_OrderDetailAddOnResampleStatus resample_status, + T_OrderDetailAddOnRef ref, y.T_OrderDetailVerification verification, y.T_OrderDetailValidation validation, + T_OrderPromiseDateTime, Group_ResultName as ResultGroupName + FROM t_orderdetail x + left join t_orderpromise on x.T_OrderDetailT_OrderPromiseID = T_OrderPromiseID + JOIN t_test tx ON x.T_OrderDetailT_TestID = T_TestID + JOIN t_test tcheck on tcheck.T_TestNat_TestID in {$q_group} + and ( tx.T_TestID = tcheck.T_TestID or tx.T_TestSasCode like concat(tcheck.T_TestSasCode,'%')) + JOIN group_resultdetail ON Group_ResultDetailT_TestID = x.T_OrderDetailT_TestID AND Group_ResultDetailIsActive = 'Y' + JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND Group_ResultResumeMcu = 'LAB' + LEFT JOIN t_orderdetail y ON x.T_OrderDetailT_TestSasCode LIKE CONCAT(y.T_OrderDetailT_TestSasCode, '%') + AND x.T_OrderDetailT_OrderHeaderID = y.T_OrderDetailT_OrderHeaderID + AND y.T_OrderDetailIsActive = 'Y' + LEFT JOIN t_orderdetailaddon ON x.T_OrderDetailID = T_OrderDetailAddOnT_OrderDetailID + JOIN t_orderheader ON y.T_OrderDetailT_OrderHeaderID = T_OrderHeaderID + LEFT JOIN t_test a ON y.T_OrderDetailT_TestID = a.T_TestID + AND a.T_TestIsNonLab = '' + LEFT JOIN (SELECT T_OrderSampleT_SampleTypeID, T_OrderSampleReceive, T_OrderSampleProcessing, T_OrderSampleWorklistReceive + FROM t_ordersample WHERE T_OrderSampleT_OrderHeaderID = {$id} + AND T_OrderSampleIsactive = 'Y' + GROUP BY T_OrderSampleT_SampleTypeID) os ON a.T_TestT_SampleTypeID = os.T_OrderSampleT_SampleTypeID + or os.T_OrderSampleT_SampleTypeID = fn_sampletype_from_local(a.T_TestNat_TestID) + + LEFT JOIN t_resultinstrument ON T_ResultInstrumentT_OrderDetailID = x.T_OrderDetailID + LEFT JOIN pre_analytic ON PreAnalyticNat_TestID = a.T_TestNat_TestID AND PreAnalyticDate = date(now()) and PreAnalyticIsActive = 'Y' + WHERE x.T_OrderDetailT_OrderHeaderID = {$id} + AND x.T_OrderDetailIsActive = 'Y' + GROUP BY y.T_OrderDetailT_TestID + ORDER BY y.T_OrderDetailT_TestSasCode ASC + ) a1 + + LEFT JOIN t_orderdetail a2 ON a2.T_OrderDetailT_OrderHeaderID = a1.order_id + AND a2.T_OrderDetailIsActive = 'Y' + AND a1.test_sas_code LIKE CONCAT(a2.T_OrderDetailT_testSasCode, '%') + GROUP BY a1.t_testid + order by a1.test_sas_code +"; + $query = $this->db_smartone->query($sql); + $lq = $this->db_smartone->last_query(); + } else { + $sql = " + SELECT a1.*, cOUNT(a2.T_OrderDetailID) level + FROM ( + SELECT IFNULL(y.T_OrderDetailT_TestID, x.T_OrderDetailT_TestID) t_testid, + IFNULL(y.T_OrderDetailT_TestName, y.T_OrderDetailT_TestName) t_testname, + y.T_OrderDetailResult result, y.T_OrderDetailResult result_old, y.T_OrderDetailNote note, y.T_OrderDetailNote note_old, + y.T_OrderDetailID id, + y.T_OrderDetailT_TestIsResult is_result, a.T_TestIsQuantitative is_quantitative, + y.T_OrderDetailResultFlag result_flag, + y.T_OrderDetailNat_NormalValueID normal_id, + y.T_OrderDetailNormalValueNote normal_note, y.T_OrderDetailNat_UnitName unit_name, + y.T_OrderdetailNat_MethodeID methode_id, y.T_OrderdetailNat_MethodeName methode_name, + a.T_TestNat_TestID nattest_id, a.T_TestID tx_id, count(T_ResultInstrumentID) as result_instrument_n, + y.T_OrderDetailVerification, T_OrderSampleReceive sample_receive, + T_OrderSampleProcessing sample_processing, T_OrderSampleWorklistReceive sample_worklist_receive, + IF(T_OrderDetailAddOnPreAnalytic = 'Y', T_OrderDetailAddOnPreAnalytic, PreAnalyticIsOk) pre_analytic, + T_OrderDetailAddOnPreAnalytic, + T_OrderHeaderID order_id, y.T_OrderDetailT_TestSasCode test_sas_code, + tx.T_TestSasCode, + T_OrderDetailAddOnResample `resample`, T_OrderDetailAddOnResampleStatus resample_status, + T_OrderDetailAddOnRef ref, y.T_OrderDetailVerification verification, y.T_OrderDetailValidation validation, + T_OrderPromiseDateTime , Group_ResultName as ResultGroupName + FROM t_orderdetail x + left join t_orderpromise on x.T_OrderDetailT_OrderPromiseID = T_OrderPromiseID + JOIN t_test tx ON x.T_OrderDetailT_TestID = T_TestID + JOIN group_resultdetail ON Group_ResultDetailT_TestID = x.T_OrderDetailT_TestID AND Group_ResultDetailIsActive = 'Y' + JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND Group_ResultResumeMcu = 'LAB' + LEFT JOIN t_orderdetail y ON x.T_OrderDetailT_TestSasCode LIKE CONCAT(y.T_OrderDetailT_TestSasCode, '%') + AND x.T_OrderDetailT_OrderHeaderID = y.T_OrderDetailT_OrderHeaderID + AND y.T_OrderDetailIsActive = 'Y' + + LEFT JOIN t_orderdetailaddon ON x.T_OrderDetailID = T_OrderDetailAddOnT_OrderDetailID + + JOIN t_orderheader ON y.T_OrderDetailT_OrderHeaderID = T_OrderHeaderID + LEFT JOIN t_test a ON y.T_OrderDetailT_TestID = a.T_TestID + AND a.T_TestIsNonLab = '' + LEFT JOIN (SELECT T_OrderSampleT_SampleTypeID, T_OrderSampleReceive, T_OrderSampleProcessing, T_OrderSampleWorklistReceive + FROM t_ordersample WHERE T_OrderSampleT_OrderHeaderID = {$id} + AND T_OrderSampleIsactive = 'Y' + GROUP BY T_OrderSampleT_SampleTypeID) os ON a.T_TestT_SampleTypeID = os.T_OrderSampleT_SampleTypeID + or os.T_OrderSampleT_SampleTypeID = fn_sampletype_from_local(a.T_TestNat_TestID) + + LEFT JOIN t_resultinstrument ON T_ResultInstrumentT_OrderDetailID = x.T_OrderDetailID + LEFT JOIN pre_analytic ON PreAnalyticNat_TestID = a.T_TestNat_TestID AND PreAnalyticDate = date(now()) and PreAnalyticIsActive = 'Y' + WHERE x.T_OrderDetailT_OrderHeaderID = {$id} + AND x.T_OrderDetailIsActive = 'Y' + GROUP BY y.T_OrderDetailT_TestID + ORDER BY y.T_OrderDetailT_TestSasCode ASC + ) a1 + + LEFT JOIN t_orderdetail a2 ON a2.T_OrderDetailT_OrderHeaderID = a1.order_id + AND a2.T_OrderDetailIsActive = 'Y' + AND a1.test_sas_code LIKE CONCAT(a2.T_OrderDetailT_testSasCode, '%') + GROUP BY a1.t_testid + order by a1.test_sas_code +"; + //echo $sql; + $query = $this->db_smartone->query($sql); + $lq = $this->db_smartone->last_query(); + } + // file_put_contents("/xtmp/re-query.sql",$lq); + + if ($query) { + $rst = []; + $rows = $query->result_array(); + + foreach ($rows as $k => $v) { + + if ($v['is_result'] == "Y" && $v['is_quantitative'] == "N") { + $v['template'] = []; + $x = $this->db_smartone->query("CALL sp_master_resulttemplate_get('{$v['t_testid']}')"); + $this->clean_mysqli_connection($this->db_smartone->conn_id); + if ($x) + $v['template'] = $x->result_array(); + } + + // IF Rujukan, by pas Pre Analytik + if ($v['ref'] == 'Y') + $v['pre_analytic'] = 'Y'; + if ($v["id"] == "885455") { + //sipe workaround + //$v["sample_receive"] = "Y"; + $v["sample_worklist_receive"] = "Y"; + } + $rst[] = $v; + } + + $result = array("total" => $tot_count, "records" => $rst, "total_display" => sizeof($rows), "q" => $lq); + $this->sys_ok($result); + } else { + $this->sys_error_db("RE Px rows", $this->db_smartone); + exit; + } + } + + public function save() + { + $prm = $this->sys_input; + $data = json_decode($prm["data"]); + $lang = $this->lang_default_code; + $lang_id = isset($prm['lang_id']) ? $prm['lang_id'] : '0'; + + if ($lang_id != 0) { + $l = $this->db_smartone->where("Nat_LangID", $lang_id)->get("nat_lang")->row(); + $lang = $l->Nat_LangCode; + } + + $sql_norm = "select T_OrderDetailMinValue, T_OrderDetailMaxValue, + T_OrderDetailMinValueInclusive, T_OrderDetailMaxValueInclusive, + Nat_TestFlagLow, Nat_TestFlagHigh + from t_orderdetail + join t_test on T_OrderDetailT_TestID = T_TestID + join nat_test on T_TestNat_TestID = Nat_TestID and T_TestIsActive = 'Y' + where T_OrderDetailID = ? "; + + $ids = []; + foreach ($data as $k => $v) { + if ($v->resultInstrumentID > 0) { + $sql_i = "select T_ResultInstrumentNat_NormalValueID normalValueID + from t_resultinstrument + where T_ResultInstrumentID = ?"; + $qry_i = $this->db_smartone->query($sql_i, array($v->resultInstrumentID)); + if ($qry_i) { + $rows_i = $qry_i->result_array(); + + if (count($rows_i) > 0) { + $sql_iu = "update t_orderdetail, nat_normalvalue , nat_methode + set T_OrderDetailMinValue = Nat_NormalValueMinValue, + T_OrderDetailMinValueInclusive = Nat_NormalValueMinValueInclusive, + T_OrderDetailMaxValue = Nat_NormalValueMaxValue , + T_OrderDetailMaxValueInclusive = Nat_NormalValueMaxValueInclusive, + T_OrderDetailNormalValueNote = Nat_NormalValueNote, + T_OrderDetailNormalValueDescription = Nat_NormalValueDescription, + T_OrderDetailNat_NormalValueID = Nat_NormalValueID, + T_OrderDetailNat_MethodeID = Nat_NormalValueNat_MethodeID, + T_OrderDetailNat_MethodeName = Nat_MethodeName + where T_OrderDetailID = ? and Nat_NormalValueID = ? + and Nat_NormalValueNat_MethodeID = Nat_MethodeID + "; + $this->db_smartone->query($sql_iu, array($v->id, $rows_i[0]["normalValueID"])); + //file_put_contents("/xtmp/update-nilai-normal", $this->db_smartone->last_query() . "\n", FILE_APPEND); + } + } + } + $y = $this->db_smartone->query("SELECT fn_process_sample_handling_perfect('{$v->order_id}', '{$v->test_id}') c") + ->row(); + $req_status = $y->c; + $qry_norm = $this->db_smartone->query($sql_norm, $v->id); + $result_flag = ""; + if ($qry_norm) { + $rows_norm = $qry_norm->result_array(); + if (count($rows_norm) > 0) { + $r = $rows_norm[0]; + if (is_numeric($v->result)) { + + if ($r["T_OrderDetailMinValueInclusive"] == "Y" && $v->result < $r["T_OrderDetailMinValue"]) { + $result_flag = $r["Nat_TestFlagLow"]; + } + if ($r["T_OrderDetailMinValueInclusive"] == "N" && $v->result <= $r["T_OrderDetailMinValue"]) { + $result_flag = $r["Nat_TestFlagLow"]; + } + if ($r["T_OrderDetailMaxValueInclusive"] == "Y" && $v->result > $r["T_OrderDetailMaxValue"]) { + $result_flag = $r["Nat_TestFlagHigh"]; + } + if ($r["T_OrderDetailMaxValueInclusive"] == "N" && $v->result >= $r["T_OrderDetailMaxValue"]) { + $result_flag = $r["Nat_TestFlagHigh"]; + } + } + } + } if ($lang == $this->lang_default_code) { $result_save = $this->db_smartone->set('T_OrderDetailResult', $v->result) ->set('T_OrderDetailResultFlag', $result_flag) @@ -827,2610 +826,2610 @@ class Re_px extends MY_Controller return; } } - - - - $ids[] = $v->id; - - //log detail - - $sql = "SELECT COUNT(*) n FROM log_orderdetail WHERE Log_OrderDetailT_OrderDetailID = ? AND Log_OrderDetailResult = ? ORDER BY Log_OrderDetailID DESC LIMIT 1"; - $qry = $this->db_lab->query($sql, [$v->id, $v->result]); - if ($qry) { - $n = $qry->row(); - - if ($n->n == 0) { - $sql = "SELECT * FROM t_orderdetail WHERE T_OrderDetailID = ?"; - $qry_order = $this->db_smartone->query($sql, [$v->id]); - $dt_orderdetail = $qry_order->row(); - $dt_detail_log = json_encode($dt_orderdetail); - - $sql = "INSERT INTO log_orderdetail ( - Log_OrderDetailStatus, - Log_OrderDetailT_OrderDetailID, - Log_OrderDetailResult, - Log_OrderDetailJSON, - Log_OrderDetailCreated, - Log_OrderDetailUserID - ) - VALUES (?,?, ?, ?, NOW(), ?)"; - $this->db_lab->query($sql, ['RESULTENTRY', $v->id, $v->result, $dt_detail_log, $this->sys_user['M_UserID']]); - //echo $this->db_lab->last_query(); - //exit(); - } - } - } - - // LOG Process - $order = $this->db_smartone->select('T_OrderDetailT_OrderHeaderID id, T_OrderHeaderLabNumber lab_number', false) - ->join('t_orderheader', 'T_OrderHeaderID = T_OrderDetailT_OrderHeaderID') - ->where('T_OrderDetailID', $data[0]->id) - ->get('t_orderdetail') - ->row(); - - $dblog = $this->db_lab; - $dblog->set('Log_ProcessCode', 'PROCESS.Result.Entry') - ->set('Log_ProcessOrderID', $order->id) - ->set('Log_ProcessOrderNumber', $order->lab_number) - ->set('Log_ProcessJson', json_encode($data)) - ->set('Log_ProcessUserID', $this->sys_user['M_UserID']) - ->insert('log_process'); - // END OF Log Process + + + + $ids[] = $v->id; + + //log detail + + $sql = "SELECT COUNT(*) n FROM log_orderdetail WHERE Log_OrderDetailT_OrderDetailID = ? AND Log_OrderDetailResult = ? ORDER BY Log_OrderDetailID DESC LIMIT 1"; + $qry = $this->db_lab->query($sql, [$v->id, $v->result]); + if ($qry) { + $n = $qry->row(); + + if ($n->n == 0) { + $sql = "SELECT * FROM t_orderdetail WHERE T_OrderDetailID = ?"; + $qry_order = $this->db_smartone->query($sql, [$v->id]); + $dt_orderdetail = $qry_order->row(); + $dt_detail_log = json_encode($dt_orderdetail); + + $sql = "INSERT INTO log_orderdetail ( + Log_OrderDetailStatus, + Log_OrderDetailT_OrderDetailID, + Log_OrderDetailResult, + Log_OrderDetailJSON, + Log_OrderDetailCreated, + Log_OrderDetailUserID + ) + VALUES (?,?, ?, ?, NOW(), ?)"; + $this->db_lab->query($sql, ['RESULTENTRY', $v->id, $v->result, $dt_detail_log, $this->sys_user['M_UserID']]); + //echo $this->db_lab->last_query(); + //exit(); + } + } + } + + // LOG Process + $order = $this->db_smartone->select('T_OrderDetailT_OrderHeaderID id, T_OrderHeaderLabNumber lab_number', false) + ->join('t_orderheader', 'T_OrderHeaderID = T_OrderDetailT_OrderHeaderID') + ->where('T_OrderDetailID', $data[0]->id) + ->get('t_orderdetail') + ->row(); + + $dblog = $this->db_lab; + $dblog->set('Log_ProcessCode', 'PROCESS.Result.Entry') + ->set('Log_ProcessOrderID', $order->id) + ->set('Log_ProcessOrderNumber', $order->lab_number) + ->set('Log_ProcessJson', json_encode($data)) + ->set('Log_ProcessUserID', $this->sys_user['M_UserID']) + ->insert('log_process'); + // END OF Log Process //auto calculation $this->load->library("Resultcalc"); $rows = $this->resultcalc->auto($order->id, "", $ids); - - try { - foreach ($ids as $id) { - $this->db_smartone->query("call sp_set_normal_value_flag($id)"); - $this->clean_mysqli_connection($this->db_smartone->conn_id); - } - } catch (Exception $e) { - } - - $this->sys_ok($ids); - } - - public function save_template() - { - $prm = $this->sys_input; - - $n = $this->db_smartone->select("COUNT(T_ResultTemplateID) n") - ->where("T_ResultTemplateT_TestID", $prm['test_id']) - ->where("T_ResultTemplateIsActive", "Y") - ->where("T_ResultTemplateValue", $prm['value']) - ->get('t_resulttemplate') - ->row(); - if ($n->n > 0) { - $this->sys_error_db("Insert Result Template", $this->db_smartone); - return; - } - - $r = $this->db_smartone->set("T_ResultTemplateT_TestID", $prm['test_id']) - ->set("T_ResultTemplateValue", $prm['value']) - ->insert('t_resulttemplate'); - if ($r) { - $template = []; - $x = $this->db_smartone->query("CALL sp_master_resulttemplate_get('{$prm['test_id']}')"); - $this->clean_mysqli_connection($this->db_smartone->conn_id); - if ($x) - $template = $x->result_array(); - - $this->sys_ok($template); - } - } - - public function export() - { - $prm = $this->sys_input; - - $sql = "CALL sp_process_result_lang(?, ?, ?, ?)"; - $query = $this->db_smartone->query($sql, [$prm['order_id'], $prm['lang_id'], $prm['is_si'], $this->sys_user['M_UserID']]); - if ($query) { - $r = $query->row(); - if ($r->status == "OK") { - $this->sys_ok($r->data); - return; - } - - $this->sys_error_db("Message : " . $r->message, $this->db_smartone); - } else { - $this->sys_error_db("Lang Result", $this->db_smartone); - return; - } - } - - public function search_group() - { - $prm = $this->sys_input; - $max_rst = 100; - - // QUERY TOTAL - $sql = "select count(*) total - from t_worklist - where T_WorklistIsActive = 'Y' - order by T_WorklistName ASC"; - $query = $this->db_smartone->query($sql); - - if ($query) { - $tot_count = $query->result_array()[0]["total"]; - } else { - $this->sys_error_db("worklist count", $this->db_smartone); - exit; - } - - $sql = "select T_WorklistID group_id, T_WorklistName group_name - from t_worklist - where T_WorklistIsActive = 'Y' - order by T_WorklistName ASC - limit 0, {$max_rst}"; - $query = $this->db_smartone->query($sql); - - if ($query) { - $rows = $query->result_array(); - foreach ($rows as $k => $v) - $rows[$k]['data'] = json_decode($v['data']); - $result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows), "q" => $this->db_smartone->last_query()); - $this->sys_ok($result); - } else { - $this->sys_error_db("worklist rows", $this->db_smartone); - exit; - } - } - - public function search_rerun() - { - $prm = $this->sys_input; - $id = $prm["detail_id"]; - - $sql = "CALL sp_process_result_rerun(?)"; - $query = $this->db_smartone->query($sql, [$id]); - - if ($query) { - $rows = $query->result_array(); - $this->sys_ok(["records" => $rows]); - } else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - - - function getdoctorsfna() - { - $prm = $this->sys_input; - // $id = $prm["id"]; - - $sql = " SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY M_DoctorName ASC"; - //echo $sql; - $query = $this->db_smartone->query($sql); - - if ($query) { - $rows = $query->result_array(); - $this->sys_ok(["records" => $rows]); - } else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - function getgolongandarah() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $images = array(); - $sql = "SELECT So_ImageUploadBloodTypeID as xid, - CONCAT('/one-media/one-image-nonlab/',So_ImageUploadBloodTypeName) as image_url - FROM t_orderdetail - JOIN so_imageupload_bloodtype ON So_ImageUploadBloodTypeT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND - So_ImageUploadBloodTypeIsActive = 'Y' - WHERE - T_OrderDetailID = {$id} AND - T_OrderDetailIsActive = 'Y' - GROUP BY So_ImageUploadBloodTypeID"; - $images = $this->db_smartone->query($sql)->result_array(); - - $rst = array('images' => $images); - $this->sys_ok(["records" => $rst]); - } - - function getfnaresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT Other_FNADetailsID as xid, - Other_FNAT_OrderDetailID as orderdetail_id, - Other_FNADetailsCode as code, - Other_FNADetailsLabel as label, - Other_FNADetailsResult as result, - IFNULL(Other_FNAM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_FNAM_DoctorID) OR Other_FNAM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_fna - JOIN other_fnadetails ON Other_FNADetailsOther_FNAID = Other_FNAID AND Other_FNADetailsIsActive = 'Y' - LEFT JOIN m_doctor ON Other_FNAM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_FNAT_OrderDetailID = {$id} AND Other_FNAIsActive = 'Y' - GROUP BY Other_FNADetailsID - ORDER BY Other_FNADetailsCode ASC"; - $query = $this->db_smartone->query($sql); - - if ($query) { - $rows = $query->result_array(); - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $images = array(); - $sql = "SELECT So_ImageUploadID as xid, - CONCAT('/one-media/one-image-nonlab/',So_ImageUploadNewName) as image_url - FROM t_orderdetail - JOIN so_imageupload ON So_ImageUploadT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND - So_ImageUploadIsActive = 'Y' - WHERE - T_OrderDetailID = {$id} AND - T_OrderDetailIsActive = 'Y' - GROUP BY So_ImageUploadID"; - $images = $this->db_smartone->query($sql)->result_array(); - - $rst = array('doctors' => $doctors, 'results' => $rows, 'images' => $images); - $this->sys_ok(["records" => $rst]); - } else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - function getpatologianatomyresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT Other_PatologiAnatomyID as xid, - Other_PatologiAnatomyT_OrderDetailID as orderdetail_id, - Other_PatologiAnatomyNoSediaan as no_sediaan, - Other_PatologiAnatomyDiagnosaKlinis as diagnosa, - Other_PatologiAnatomyKeteranganKlinis as klinis, - Other_PatologiAnatomyLokasiOrgan as lokasi, - Other_PatologiAnatomyMakroskopik as makroskopik, - Other_PatologiAnatomyMikroskopik as mikroskopik, - Other_PatologiAnatomyKesimpulan as kesimpulan, - IFNULL(Other_PatologiAnatomyM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_PatologiAnatomyM_DoctorID) OR Other_PatologiAnatomyM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_patologi_anatomy - LEFT JOIN m_doctor ON Other_PatologiAnatomyM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_PatologiAnatomyT_OrderDetailID = {$id} AND Other_PatologiAnatomyIsActive = 'Y' - GROUP BY Other_PatologiAnatomyID - ORDER BY Other_PatologiAnatomyID ASC - LIMIT 1"; - $query = $this->db_smartone->query($sql); - - if ($query) { - $rows = $query->row_array(); - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - - $sql = "SELECT So_ImageUploadPatologyAnatomyID as xid, - CONCAT('/one-media/one-image-nonlab/',So_ImageUploadPatologyAnatomyNewName) as image_url, - So_ImageUploadPatologyAnatomyType as type - FROM t_orderdetail - JOIN so_imageupload_patology_anatomy ON So_ImageUploadPatologyAnatomyT_OrderHeaderID= T_OrderDetailT_OrderHeaderID AND - So_ImageUploadPatologyAnatomyIsActive= 'Y' - WHERE - T_OrderDetailID = {$id} AND - T_OrderDetailIsActive = 'Y' - GROUP BY So_ImageUploadPatologyAnatomyID"; - $images = $this->db_smartone->query($sql)->result_array(); - $mikro = []; - $makro = []; - - foreach ($images as $key => $value) { - - if ($value['type'] == 'mikro') { - $mikro[] = $value; - } - if ($value['type'] == 'makro') { - $makro[] = $value; - } - } - - $rst = array('doctors' => $doctors, 'result' => $rows, "mikro" => $mikro, "makro" => $makro); - $this->sys_ok(["records" => $rst]); - } else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - - function uploadimageblood() - { - if (! $this->isLogin) { - $this->sys_error("Invalid Token"); - exit; - } - - $userid = $this->sys_user["M_UserID"]; - $data = []; - //print_r($_SERVER); - - $prm = $this->sys_input; - $orderid = $this->input->post('orderid'); - $labnumber = $this->input->post('labnumber'); - $nattest_id = $this->input->post('nattest_id'); - $sql = "UPDATE so_imageupload_bloodtype SET - So_ImageUploadBloodTypeIsActive = 'N', - So_ImageUploadBloodTypeUserID = {$userid} - WHERE - So_ImageUploadBloodTypeT_OrderHeaderID = {$orderid}"; - //echo $sql; - $this->db_onedev->query($sql); - //$config['upload_path'] = 'assets/'; - - $path = '/home/one/project/one/one-media/one-image-nonlab/'; - //echo $path; - $config['upload_path'] = $path; - $config['allowed_types'] = 'jpg|jpeg|png|gif'; - - $config['max_size'] = '10000'; - $count = count($_FILES['files']['name']); - //echo $count; - $this->load->library('upload', $config); - - $error = []; - for ($i = 0; $i < $count; $i++) { - - - if (!empty($_FILES['files']['name'][$i])) { - - $_FILES['file']['name'] = $_FILES['files']['name'][$i]; - - $_FILES['file']['type'] = $_FILES['files']['type'][$i]; - - $_FILES['file']['tmp_name'] = $_FILES['files']['tmp_name'][$i]; - - $_FILES['file']['error'] = $_FILES['files']['error'][$i]; - - $_FILES['file']['size'] = $_FILES['files']['size'][$i]; - - $namex = $orderid . '-' . $labnumber . '-' . $this->generateRandomString(5); - //echo $namex; - - $config['file_name'] = $namex; - $this->upload->initialize($config); - //echo $config['file_name'] ; - - if ($this->upload->do_upload('file')) { - - $uploadData = $this->upload->data(); - - $filename = $uploadData['file_name']; - //echo $filename; - - - $sql = "INSERT INTO so_imageupload_bloodtype ( - So_ImageUploadBloodTypeT_OrderHeaderID, - So_ImageUploadBloodTypeT_OrderHeaderLabNumber, - So_ImageUploadBloodTypeName, - So_ImageUploadBloodTypeCreated, - So_ImageUploadBloodTypeUserID - ) - VALUES( - {$orderid}, - '{$labnumber}', - '{$filename}', - NOW(), - {$userid} - )"; - //echo $sql; - $this->db_onedev->query($sql); - $xlast_id = $this->db_onedev->insert_id(); - $data['totalFiles'][] = array('xid' => $xlast_id, 'image_url' => '/one-media/one-image-nonlab/' . $filename); - } else { - $error = array('error' => $this->upload->display_errors()); - } - } - } - - $result = array("total" => count($data['totalFiles']), "records" => $data['totalFiles'], 'errors' => $error); - $this->sys_ok($result); - } - - function uploadimage() - { - if (! $this->isLogin) { - $this->sys_error("Invalid Token"); - exit; - } - - $userid = $this->sys_user["M_UserID"]; - $data = []; - //print_r($_SERVER); - - $prm = $this->sys_input; - $orderid = $this->input->post('orderid'); - $labnumber = $this->input->post('labnumber'); - $sql = "UPDATE so_imageupload SET - So_ImageUploadIsActive = 'N', - So_ImageUploadUserID = {$userid} - WHERE - So_ImageUploadT_OrderHeaderID = {$orderid}"; - //echo $sql; - $this->db_onedev->query($sql); - //$config['upload_path'] = 'assets/'; - - $path = '/home/one/project/one/one-media/one-image-nonlab/'; - //echo $path; - $config['upload_path'] = $path; - $config['allowed_types'] = 'jpg|jpeg|png|gif'; - - $config['max_size'] = '10000'; - $count = count($_FILES['files']['name']); - //echo $count; - $this->load->library('upload', $config); - - $error = []; - for ($i = 0; $i < $count; $i++) { - - - if (!empty($_FILES['files']['name'][$i])) { - - - - $_FILES['file']['name'] = $_FILES['files']['name'][$i]; - - $_FILES['file']['type'] = $_FILES['files']['type'][$i]; - - $_FILES['file']['tmp_name'] = $_FILES['files']['tmp_name'][$i]; - - $_FILES['file']['error'] = $_FILES['files']['error'][$i]; - - $_FILES['file']['size'] = $_FILES['files']['size'][$i]; - - - - $namex = $orderid . '-' . $labnumber . '-' . $this->generateRandomString(5); - //echo $namex; - - $config['file_name'] = $namex; - $this->upload->initialize($config); - //echo $config['file_name'] ; - - - - - - if ($this->upload->do_upload('file')) { - - $uploadData = $this->upload->data(); - - $filename = $uploadData['file_name']; - //echo $filename; - - - $sql = "INSERT INTO so_imageupload ( - So_ImageUploadT_OrderHeaderID, - So_ImageUploadT_OrderHeaderLabNumber, - So_ImageUploadT_SampleTypeID, - So_ImageUploadOldName, - So_ImageUploadNewName, - So_ImageUploadCreated, - So_ImageUploadUserID - ) - VALUES( - {$orderid}, - '{$labnumber}', - '150', - '{$_FILES['files']['name'][$i]}', - '{$filename}', - NOW(), - {$userid} - - )"; - //echo $sql; - $this->db_onedev->query($sql); - $xlast_id = $this->db_onedev->insert_id(); - $data['totalFiles'][] = array('xid' => $xlast_id, 'image_url' => '/one-media/one-image-nonlab/' . $filename); - } else { - $error = array('error' => $this->upload->display_errors()); - } - } - } - - $result = array("total" => count($data['totalFiles']), "records" => $data['totalFiles'], 'errors' => $error); - $this->sys_ok($result); - } - function uploadimagePatologiAnatomi() - { - if (! $this->isLogin) { - $this->sys_error("Invalid Token"); - exit; - } - - $userid = $this->sys_user["M_UserID"]; - $data = []; - //print_r($_SERVER); - - $prm = $this->sys_input; - $orderid = $this->input->post('orderid'); - $type = $this->input->post('type'); - $labnumber = $this->input->post('labnumber'); - $sql = "UPDATE so_imageupload_patology_anatomy SET - So_ImageUploadPatologyAnatomyIsActive = 'N', - So_ImageUploadPatologyAnatomyUserID = {$userid} - WHERE - So_ImageUploadPatologyAnatomyT_OrderHeaderID = {$orderid} - AND So_ImageUploadPatologyAnatomyType = '{$type}'"; - //echo $sql; - $qry = $this->db_onedev->query($sql); - $last_qry = $this->db_onedev->last_query(); - if (!$qry) { - $message = $this->db_onedev->error(); - $message['last_qry'] = $last_qry; - $this->sys_error_db($message); - exit; - } - //$config['upload_path'] = 'assets/'; - - $path = '/home/one/project/one/one-media/one-image-nonlab/'; - //echo $path; - $config['upload_path'] = $path; - $config['allowed_types'] = 'jpg|jpeg|png|gif'; - - $config['max_size'] = '10000'; - $count = count($_FILES['files']['name']); - //echo $count; - $this->load->library('upload', $config); - - $error = []; - for ($i = 0; $i < $count; $i++) { - - - if (!empty($_FILES['files']['name'][$i])) { - - - - $_FILES['file']['name'] = $_FILES['files']['name'][$i]; - - $_FILES['file']['type'] = $_FILES['files']['type'][$i]; - - $_FILES['file']['tmp_name'] = $_FILES['files']['tmp_name'][$i]; - - $_FILES['file']['error'] = $_FILES['files']['error'][$i]; - - $_FILES['file']['size'] = $_FILES['files']['size'][$i]; - - - - $namex = $orderid . '-' . $labnumber . '-' . $this->generateRandomString(5); - //echo $namex; - - $config['file_name'] = $namex; - $this->upload->initialize($config); - //echo $config['file_name'] ; - - - - - - if ($this->upload->do_upload('file')) { - - $uploadData = $this->upload->data(); - - $filename = $uploadData['file_name']; - //echo $filename; - - - $sql = "INSERT INTO so_imageupload_patology_anatomy ( - So_ImageUploadPatologyAnatomyT_OrderHeaderID, - So_ImageUploadPatologyAnatomyT_OrderHeaderLabNumber, - So_ImageUploadPatologyAnatomyT_SampleTypeID, - So_ImageUploadPatologyAnatomyOldName, - So_ImageUploadPatologyAnatomyNewName, - So_ImageUploadPatologyAnatomyCreated, - So_ImageUploadPatologyAnatomyUserID, - So_ImageUploadPatologyAnatomyType - ) - VALUES( - {$orderid}, - '{$labnumber}', - '145', - '{$_FILES['files']['name'][$i]}', - '{$filename}', - NOW(), - {$userid}, - '{$type}' - - )"; - //echo $sql; - $qry = $this->db_onedev->query($sql); - $last_qry = $this->db_onedev->last_query(); - if (!$qry) { - $message = $this->db_onedev->error(); - $message['last_qry'] = $last_qry; - $this->sys_error_db($message); - exit; - } - $xlast_id = $this->db_onedev->insert_id(); - $data['totalFiles'][] = array('xid' => $xlast_id, 'image_url' => '/one-media/one-image-nonlab/' . $filename); - } else { - $error = array('error' => $this->upload->display_errors()); - } - } - } - - $result = array("total" => count($data['totalFiles']), "records" => $data['totalFiles'], 'errors' => $error); - $this->sys_ok($result); - } - - - function generateRandomString($length = 10) - { - $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; - $charactersLength = strlen($characters); - $randomString = ''; - for ($i = 0; $i < $length; $i++) { - $randomString .= $characters[rand(0, $charactersLength - 1)]; - } - return $randomString; - } - - function getcytologiresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT Other_CytologiDetailsID as xid, - Other_CytologiT_OrderDetailID as orderdetail_id, - Other_CytologiDetailsCode as code, - Other_CytologiDetailsLabel as label, - Other_CytologiDetailsResult as result, - IFNULL(Other_CytologiM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_CytologiM_DoctorID) OR Other_CytologiM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_cytologi - JOIN other_cytologidetails ON Other_CytologiDetailsOther_CytologiID = Other_CytologiID AND Other_CytologiDetailsIsActive = 'Y' - LEFT JOIN m_doctor ON Other_CytologiM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_CytologiT_OrderDetailID = {$id} AND Other_CytologiIsActive = 'Y' - GROUP BY Other_CytologiDetailsID - ORDER BY Other_CytologiDetailsCode ASC"; - //echo $sql; - $query = $this->db_smartone->query($sql); - - if ($query) { - $rows = $query->result_array(); - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $rst = array('doctors' => $doctors, 'results' => $rows); - $this->sys_ok(["records" => $rst]); - } else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - function getmikroresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT - Other_MikroID as xid, - Other_MikroHasilBiakan as hasil_biakan, - Other_MikroSampleTypeName as sample_name, - Other_MikroT_OrderDetailID as orderdetail_id, - Other_MikroResult as result_value, - '' as result_other, - IFNULL(T_BacteriaID,0) as T_BacteriaID, - IFNULL(T_BacteriaName,'') as T_BacteriaName, - '' as details, - IFNULL(Other_MikroM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_MikroM_DoctorID) OR Other_MikroM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_mikro - LEFT JOIN t_bacteria ON Other_MikroT_BacteriaID = T_BacteriaID - LEFT JOIN m_doctor ON Other_MikroM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_MikroT_OrderDetailID = {$id} AND Other_MikroIsActive = 'Y' - GROUP BY Other_MikroID"; - //echo $sql; - $query = $this->db_smartone->query($sql); - - if ($query) { - $row = $query->row_array(); - if ($row) { - if ($row['result_value'] != 'Positif' && $row['result_value'] != 'Negatif') { - $row['result_other'] = $row['result_value']; - $row['result_value'] = 'other'; - } - $sql = "SELECT '' as xno, - Other_MikroDetailsID as xid, - Other_MikroDetailsValue as value, - IF(Other_MikroDetailsNote = 'R','Y','N') as chx_r, - IF(Other_MikroDetailsNote = 'I','Y','N') as chx_i, - IF(Other_MikroDetailsNote = 'S','Y','N') as chx_s, - Other_MikroDetailsNote as note, - t_antibiotic.* - FROM other_mikrodetails - LEFT JOIN t_antibiotic ON Other_MikroDetailsT_AntibioticID = T_AntibioticID - WHERE - Other_MikroDetailsOther_MikroID = {$row['xid']} AND Other_MikroDetailsIsActive = 'Y' - GROUP BY Other_MikroDetailsID - ORDER BY T_AntibioticName ASC"; - //echo $sql; - $details = $this->db_smartone->query($sql)->result_array(); - if ($details) { - foreach ($details as $k => $v) { - $details[$k]['xno'] = $k + 1; - } - } - $row['details'] = $details; - } else { - $row = array('xid' => '0', 'hasil_biakan' => '', 'result_value' => 'Negatif', 'sample_name' => '', 'orderdetail_id' => $id, 'T_BacteriaID' => '0', 'T_BacteriaName' => '0', 'details' => array(), 'doctor_id' => '0', 'doctor_name' => '0'); - } - } else { - $row = array('xid' => '0', 'hasil_biakan' => '', 'result_value' => 'Negatif', 'sample_name' => '', 'orderdetail_id' => $id, 'T_BacteriaID' => '0', 'T_BacteriaName' => '0', 'details' => array(), 'doctor_id' => '0', 'doctor_name' => '0'); - } - //print_r($row); - - - - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 7 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $sql = " - SELECT '0' as id, 'Belum memilih bakteria' as name - UNION - SELECT T_BacteriaID as id, T_BacteriaName as name - FROM t_bacteria - WHERE - T_BacteriaIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $bacteries = $this->db_smartone->query($sql)->result_array(); - $rst = array('doctors' => $doctors, 'bacteries' => $bacteries, 'results' => $row); - $this->sys_ok(["records" => $rst]); - } - function getantibiotics() - { - $prm = $this->sys_input; - $id = $prm["id"]; - $sql = " SELECT '' as xno, - 0 as xid, - '' as hasil_biakan, - '' as sample_name, - 0 as value, - 'Y' as chx_r, - 'N' as chx_i, - 'N' as chx_s, - 'R' as note, - t_antibiotic.* - FROM t_antibiotic - WHERE - T_AntibioticT_BacteriaID = {$prm['id']} AND T_AntibioticIsActive= 'Y' - ORDER BY T_AntibioticName ASC"; - //echo $sql; - $rows = $this->db_smartone->query($sql)->result_array(); - if (rows) { - foreach ($rows as $k => $v) { - $rows[$k]['xno'] = $k + 1; - } - } - - $this->sys_ok(["records" => $rows]); - } - function getlcprepresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = "SELECT T_OrderDetailVerification as verification, T_OrderDetailValidation as validation FROM t_orderdetail WHERE T_OrderDetailID = ?"; - $order = $this->db_smartone->query($sql, array($id))->row_array(); - - - $sql = " SELECT Other_LcprepDetailsID as xid, - Other_LcprepID as header_id, - Other_LcprepT_orderDetailID as orderdetail_id, - Other_LcprepDetailsCode as code, - Other_LcprepDetailsLabel as label, - Other_LcprepDetailsResult as result, - IFNULL(Other_LcprepM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_LcprepM_DoctorID) OR Other_LcprepM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_lcprep - JOIN other_lcprepdetails ON Other_LcprepDetailsOther_LcprepID = Other_LcprepID AND Other_LcprepDetailsIsActive = 'Y' - LEFT JOIN m_doctor ON Other_LcprepM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_LcprepT_orderDetailID = ? AND Other_LcprepIsActive = 'Y' - GROUP BY Other_LcprepDetailsOther_LcprepID, Other_LcprepDetailsCode - ORDER BY Other_LcprepDetailsCode ASC"; - //echo $sql; - $rows = $this->db_smartone->query($sql, array($id))->result_array(); - if (count($rows) == 0) { - $rows = array( - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'A', - 'label' => 'DESKRIPSI', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ), - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'B', - 'label' => 'KESIMPULAN', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ) - ); - } - - $other_rows = array(); - $langs = array(array('id' => 1, 'name' => 'Bahasa Indonesia')); - $selected_lang = array(array('id' => 1, 'name' => 'Bahasa Indonesia')); - $sql = "SELECT T_OrderHeaderAddOnSecondM_LangID as lang_id, - M_LangName as lang_name - FROM t_orderdetail - JOIN t_orderheader ON T_OrderDetailT_OrderHeaderID = T_OrderHeaderID AND T_OrderHeaderIsActive = 'Y' - JOIN t_orderheaderaddon ON T_OrderHeaderAddonT_OrderHeaderID = T_OrderHeaderID AND T_OrderHeaderAddonIsActive = 'Y' - JOIN m_lang ON T_OrderHeaderAddOnSecondM_LangID = M_LangID AND M_LangIsActive = 'Y' - WHERE T_OrderDetailID = {$id} AND T_OrderDetailIsActive = 'Y'"; - - $other_lang = $this->db_smartone->query($sql)->result_array(); - if (count($other_lang) > 0) { - $langs[] = array('id' => $other_lang[0]['lang_id'], 'name' => $other_lang[0]['lang_name']); - $selected_lang = array('id' => $other_lang[0]['lang_id'], 'name' => $other_lang[0]['lang_name']); - - - $sql = " SELECT Other_LcprepDetailsLangsID as xid, - Other_LcprepID as header_id, - Other_LcprepT_orderDetailID as orderdetail_id, - Other_LcprepDetailsLangsCode as code, - Other_LcprepDetailsLangsLabel as label, - Other_LcprepDetailsLangsResult as result, - IFNULL(Other_LcprepM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_LcprepM_DoctorID) OR Other_LcprepM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_lcprep - JOIN other_lcprepdetails_lang ON Other_LcprepDetailsLangsOther_LcprepID = Other_LcprepID AND Other_LcprepDetailsLangsIsActive = 'Y' - LEFT JOIN m_doctor ON Other_LcprepM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_LcprepT_orderDetailID = {$id} AND Other_LcprepDetailsLangsIsActive = 'Y' - GROUP BY Other_LcprepDetailsLangsOther_LcprepID, Other_LcprepDetailsLangsCode - ORDER BY Other_LcprepDetailsLangsCode ASC"; - // echo $sql; - $other_rows = $this->db_smartone->query($sql)->result_array(); - if (count($other_rows) == 0) { - $other_rows = array( - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'AA', - 'label' => 'DESCRIPTION', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ), - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'BB', - 'label' => 'CONCLUSION', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ) - ); - } - } - - $header_id = $rows[0]['header_id']; - $sql = "SELECT IFNULL(Other_LcprepAdekuasiID,0) as xid, - Lcprep_AdekuasiID as id, - Lcprep_AdekuasiLabel as name, - Lcprep_AdekuasiLabel as name_en, - IF(ISNULL(Other_LcprepAdekuasiID),'N',Other_LcprepAdekuasiChex) as chex - FROM lcprep_adekuasi - LEFT JOIN other_lcprepadekuasi ON Other_LcprepAdekuasiLcprep_AdekuasiID = Lcprep_AdekuasiID AND - Other_LcprepAdekuasiOther_LcprepID = {$header_id} AND - Other_LcprepAdekuasiIsActive = 'Y' - WHERE - Lcprep_AdekuasiIsActive = 'Y' - GROUP BY Lcprep_AdekuasiID - ORDER BY Lcprep_AdekuasiOrder ASC - "; - //echo $sql; - $adeakuasi = $this->db_smartone->query($sql)->result_array(); - foreach ($adeakuasi as $kc => $vc) { - $adeakuasi[$kc]['chex'] = $vc['chex'] == 'N' ? false : true; - $adeakuasi[$kc]['name_en'] = $this->translate_word($vc['name']); - } - - $sql = "SELECT IFNULL(Other_LcprepKategoriUmumID,0) as xid, - Lcprep_KategoriUmumID as id, - Lcprep_KategoriUmumLabel as name, - Lcprep_KategoriUmumLabel as name_en, - IF(ISNULL(Other_LcprepKategoriUmumID),'N',Other_LcprepKategoriUmumChex) as chex - FROM lcprep_kategoriumum - LEFT JOIN other_lcprepkategoriumum ON Other_LcprepKategoriUmumLcprep_KategoriUmumID = Lcprep_KategoriUmumID AND - Other_LcprepKategoriUmumOther_LcprepID = {$header_id} AND - Other_LcprepKategoriUmumIsActive = 'Y' - WHERE - Lcprep_KategoriUmumIsActive = 'Y' - GROUP BY Lcprep_KategoriUmumID - "; - //echo $sql; - $kategoriumum = $this->db_smartone->query($sql)->result_array(); - foreach ($kategoriumum as $kc => $vc) { - $kategoriumum[$kc]['chex'] = $vc['chex'] == 'N' ? false : true; - $kategoriumum[$kc]['name_en'] = $this->translate_word($vc['name']); - } - - $sql = " - SELECT Lcprep_InterpretasiGroupID as group_id, - Lcprep_InterpretasiGroupName as group_name, - Lcprep_InterpretasiGroupName as group_name_en, - '' as subgroups - FROM lcprep_interpretasigroup - WHERE - Lcprep_InterpretasiGroupIsActive = 'Y' - "; - //echo $sql; - $interpretasi = $this->db_smartone->query($sql)->result_array(); - foreach ($interpretasi as $k => $v) { - $interpretasi[$k]['group_name_en'] = $this->translate_word($v['group_name']); - $subgroups = array(); - $sql = "SELECT Lcprep_InterpretasiSubgroupID as subgroup_id, - Lcprep_InterpretasiSubgroupName as subgroup_name, - Lcprep_InterpretasiSubgroupName as subgroup_name_en, - '' as childs - FROM lcprep_interpretasisubgroup - WHERE - Lcprep_InterpretasiSubgroupLcprep_InterpretasiGroupID = {$v['group_id']} AND Lcprep_InterpretasiSubgroupIsActive = 'Y'"; - //echo $sql; - $subgroups = $this->db_smartone->query($sql)->result_array(); - if (count($subgroups) > 0) { - foreach ($subgroups as $ki => $vi) { - $subgroups[$ki]['subgroup_name_en'] = $this->translate_word($vi['subgroup_name']); - $childs = array(); - - $sql = "SELECT IFNULL(Other_LcprepInterpretasiID,0) as xid, - IFNULL(Other_LcprepInterpretasiChex,'N') as chex, - IFNULL(Other_LcprepInterpretasiValue,'') as value, - IFNULL(Other_LcprepInterpretasiValueEng,'') as value_en, - Lcprep_InterpretasiID as id, - Lcprep_InterpretasiLcprep_InterpretasiSubgroupID as subgroup_id, - Lcprep_InterpretasiCode as code, - Lcprep_InterpretasiName as name, - Lcprep_InterpretasiName as name_en, - Lcprep_InterpretasiParentID as parent_id, - Lcprep_InterpretasiIsParent as is_parent, - Lcprep_InterpretasiHasResult as has_result, - Lcprep_InterpretasiTypeResult as type_result - FROM lcprep_interpretasi - LEFT JOIN other_lcprepinterpretasi ON Other_LcprepInterpretasiOther_LcprepID = {$header_id} AND - Other_LcprepInterpretasiLcprep_InterpretasiID = Lcprep_InterpretasiID AND - Other_LcprepInterpretasiIsActive = 'Y' - WHERE - Lcprep_InterpretasiLcprep_InterpretasiSubgroupID = {$vi['subgroup_id']} AND Lcprep_InterpretasiIsActive = 'Y' - GROUP BY Lcprep_InterpretasiID Order BY Lcprep_InterpretasiCode ASC"; - $childs = $this->db_smartone->query($sql)->result_array(); - if ($childs) { - foreach ($childs as $kc => $vc) { - $childs[$kc]['chex'] = $vc['chex'] == 'N' ? false : true; - $childs[$kc]['name_en'] = $this->translate_word($vc['name']); - } - } - $subgroups[$ki]['childs'] = $childs; - } - } - - $interpretasi[$k]['subgroups'] = $subgroups; - } - - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - - - - $rst = array('order' => $order, 'langs' => $langs, 'selected_lang' => $selected_lang, 'doctors' => $doctors, 'results' => $rows, 'other_results' => $other_rows, 'adekuasi' => $adeakuasi, 'kategoriumum' => $kategoriumum, 'interpretasi' => $interpretasi); - $this->sys_ok(["records" => $rst]); - } - - function translate_word($word) - { - $sql = "SELECT * - FROM translate_word - WHERE Translate_WordNat_LangID = '2' AND - BINARY Translate_WordFrom = '{$word}' AND - Translate_WordIsActive = 'Y' - LIMIT 1"; - $dt = $this->db_smartone->query($sql)->result_array(); - if (count($dt) > 0) { - return $dt[0]['Translate_WordTo']; - } else { - return $word; - } - } - - function getpapsmearresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT Other_PapSmearDetailsID as xid, - Other_PapSmearID as header_id, - Other_PapSmearT_OrderDetailID as orderdetail_id, - Other_PapSmearDetailsCode as code, - Other_PapSmearDetailsLabel as label, - Other_PapSmearDetailsResult as result, - IFNULL(Other_PapSmearM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_PapSmearM_DoctorID) OR Other_PapSmearM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_papsmear - JOIN other_papsmeardetails ON Other_PapSmearDetailsOther_PapSmearID = Other_PapSmearID AND Other_PapSmearDetailsIsActive = 'Y' - LEFT JOIN m_doctor ON Other_PapSmearM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_PapSmearT_OrderDetailID = {$id} AND Other_PapSmearIsActive = 'Y' - GROUP BY Other_PapSmearDetailsID - ORDER BY Other_PapSmearDetailsCode ASC"; - //echo $sql; - $rows = $this->db_smartone->query($sql)->result_array(); - if (!$rows) { - $rows = array( - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'A', - 'label' => 'Makroskopik', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ), - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'B', - 'label' => 'Mikroskopik', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ), - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'C', - 'label' => 'Kesimpulan', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ) - ); - } - - $header_id = $rows[0]['header_id']; - $sql = "SELECT Other_PapSmearMaturasiID as xid, - Other_PapSmearMaturasiValue as value - FROM other_papsmearmaturasi - WHERE - Other_PapSmearMaturasiOther_PapSmearID = {$header_id} AND - Other_PapSmearMaturasiIsActive = 'Y' - "; - //echo $sql; - $dt_maturasi = $this->db_smartone->query($sql)->row_array(); - if (!$dt_maturasi) { - $maturasi = array('xid' => '0', 'value' => array('', '', '')); - } else { - $value = explode('/', $dt_maturasi['value']); - $maturasi = array('xid' => $dt_maturasi['xid'], 'value' => $value); - } - - $sql = "SELECT IFNULL(Other_PapSmearBahanID,0) as xid, - M_PapSmearBahanID as bahan_id, - M_PapSmearBahanName as name, - IF(ISNULL(Other_PapSmearBahanID),'N','Y') as selected - FROM m_papsmearbahan - LEFT JOIN other_papsmearbahan ON Other_PapSmearBahanM_PapSmearBahanID = M_PapSmearBahanID AND - Other_PapSmearBahanOther_PapSmearID = {$header_id} AND - Other_PapSmearBahanIsActive = 'Y' - WHERE - M_PapSmearBahanIsActive = 'Y' - ORDER BY M_PapSmearBahanID ASC - "; - //echo $sql; - $bahans = $this->db_smartone->query($sql)->result_array(); - - $sql = "SELECT IFNULL(Other_PapsmearCategoryID,0) as xid, - M_PapSmearCategoryID as category_id, - M_PapSmearCategoryName as name, - IF(ISNULL(Other_PapsmearCategoryID),'N','Y') as selected - FROM m_papsmearcategory - LEFT JOIN other_papsmearcategory ON Other_PapsmearCategoryM_PapSmearCategoryID = M_PapSmearCategoryID AND - Other_PapsmearCategoryOther_PapSmearID = {$header_id} AND - Other_PapsmearCategoryIsActive = 'Y' - WHERE - M_PapSmearCategoryIsActive = 'Y' - ORDER BY M_PapSmearCategoryID ASC - "; - //echo $sql; - $categories = $this->db_smartone->query($sql)->result_array(); - - $sql = "SELECT IFNULL(Other_PapSmearCheckID,0) as xid, - M_PapSmearCheckID as check_id, - M_PapSmearCheckLabel as name, - IF(ISNULL(Other_PapSmearCheckID),'N','Y') as selected, - Other_PapSmearCheckNote as note - FROM m_papsmearcheck - LEFT JOIN other_papsmearcheck ON Other_PapSmearCheckM_PapSmearCheckID = M_PapSmearCheckID AND - Other_PapSmearCheckOther_PapSmearID = {$header_id} AND - Other_PapSmearCheckIsActive = 'Y' - WHERE - M_PapSmearCheckIsActive = 'Y' - ORDER BY M_PapSmearCheckCode ASC - "; - $checks = $this->db_smartone->query($sql)->result_array(); - - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $rst = array('doctors' => $doctors, 'checks' => $checks, 'bahans' => $bahans, 'categories' => $categories, 'maturasi' => $maturasi, 'results' => $rows); - $this->sys_ok(["records" => $rst]); - } - - function saveresult_lcprep() - { - $prm = $this->sys_input; - $detail_id = $prm['detail_id']; - $doctor_id = $prm['doctor']; - $adekuasi = $prm['adekuasi']; - $kategoriumum = $prm['kategoriumum']; - $interpretasi = $prm['interpretasi']; - $results = $prm['results']; - $selected_lang = $prm['selected_lang']; - $other_results = $prm['other_results']; - - $userid = $this->sys_user['M_UserID']; - - $header_id = 0; - $sql = "SELECT * FROM other_lcprep WHERE Other_LcprepT_orderDetailID = ? AND Other_LcprepIsActive = 'Y'"; - $dt_header = $this->db_smartone->query($sql, array($detail_id))->row_array(); - if ($dt_header) { - $header_id = $dt_header['Other_LcprepID']; - } - if ($header_id == 0) { - $sql = "INSERT INTO other_lcprep( - Other_LcprepT_orderDetailID, - Other_LcprepM_DoctorID, - Other_LcprepUserID, - Other_LcprepCreated - ) - VALUES( - ?, - ?, - ?, - NOW() - )"; - //echo $sql; - $query = $this->db_smartone->query($sql, array($detail_id, $doctor_id, $userid)); - if (!$query) { - echo $this->db_smartone->last_query(); - exit; - } - $header_id = $this->db_smartone->insert_id(); - } else { - $sql = "UPDATE other_lcprep SET Other_LcprepM_DoctorID = ?, Other_LcprepUserID = ? WHERE Other_LcprepID = ?"; - $query = $this->db_smartone->query($sql, array($doctor_id, $userid, $header_id)); - if (!$query) { - echo $this->db_smartone->last_query(); - exit; - } - } - - - - if ($adekuasi) { - foreach ($adekuasi as $k => $v) { - $selected = $v['chex'] ? 'Y' : 'N'; - if (intval($v['xid'] == 0)) { - $sql = "UPDATE other_lcprepadekuasi SET Other_LcprepAdekuasiIsActive = 'N' - WHERE - Other_LcprepAdekuasiOther_LcprepID = ? AND - Other_LcprepAdekuasiIsActive = 'Y' AND - Other_LcprepAdekuasiLcprep_AdekuasiID = ?"; - $query = $this->db_smartone->query($sql, array($header_id, $v['id'])); - if (!$query) { - echo $this->db_smartone->last_query(); - exit; - } - $sql = "INSERT INTO other_lcprepadekuasi ( - Other_LcprepAdekuasiOther_LcprepID, - Other_LcprepAdekuasiLcprep_AdekuasiID, - Other_LcprepAdekuasiChex, - Other_LcprepAdekuasiUserID, - Other_LcprepAdekuasiCreated - ) - VALUES( - ?, - ?, - ?, - ?, - NOW() - )"; - $query = $this->db_smartone->query($sql, array($header_id, $v['id'], $selected, $userid)); - if (!$query) { - echo $this->db_smartone->last_query(); - exit; - } - //echo $sql; - } - if (intval($v['xid'] != 0)) { - - $sql = "UPDATE other_lcprepadekuasi SET - Other_LcprepAdekuasiChex = ?, - Other_LcprepAdekuasiUserID = ? - WHERE - Other_LcprepAdekuasiID = ? - "; - $query = $this->db_smartone->query($sql, array($selected, $userid, $v['xid'])); - if (!$query) { - echo $this->db_smartone->last_query(); - exit; - } - } - - //echo $sql; - } - } - - if ($kategoriumum) { - foreach ($kategoriumum as $k => $v) { - $selected = $v['chex'] ? 'Y' : 'N'; - if (intval($v['xid'] == 0)) { - $sql = "UPDATE other_lcprepkategoriumum SET Other_LcprepKategoriUmumIsActive = 'N' - WHERE - Other_LcprepKategoriUmumOther_LcprepID = ? AND - Other_LcprepKategoriUmumLcprep_KategoriUmumID = ? AND - Other_LcprepKategoriUmumIsActive = 'Y' - "; - $query = $this->db_smartone->query($sql, array($header_id, $v['id'])); - if (!$query) { - echo $this->db_smartone->last_query(); - exit; - } - $sql = "INSERT INTO other_lcprepkategoriumum ( - Other_LcprepKategoriUmumOther_LcprepID, - Other_LcprepKategoriUmumLcprep_KategoriUmumID, - Other_LcprepKategoriUmumChex, - Other_LcprepKategoriUmumUserID, - Other_LcprepKategoriUmumCreated - ) - VALUES( - ?, - ?, - ?, - ?, - NOW() - )"; - $query = $this->db_smartone->query($sql, array($header_id, $v['id'], $selected, $userid)); - if (!$query) { - echo $this->db_smartone->last_query(); - exit; - } - } - if (intval($v['xid'] != 0)) { - $sql = "UPDATE other_lcprepkategoriumum SET - Other_LcprepKategoriUmumChex = ?, - Other_LcprepKategoriUmumUserID = ? - WHERE - Other_LcprepKategoriUmumID = ? - "; - $query = $this->db_smartone->query($sql, array($selected, $userid, $v['xid'])); - if (!$query) { - echo $this->db_smartone->last_query(); - exit; - } - } - - //echo $sql; - } - } - - if (count($results) > 0 && intval($selected_lang) == 1) { - foreach ($results as $k => $v) { - if (intval($v['xid'] == 0)) { - $sql = "UPDATE other_lcprepdetails SET Other_LcprepDetailsIsActive = 'N' - WHERE - Other_LcprepDetailsOther_LcprepID = ? AND - Other_LcprepDetailsCode = ? AND - Other_LcprepDetailsIsActive = 'Y'"; - $query = $this->db_smartone->query($sql, array($header_id, $v['code'])); - if (!$query) { - echo $this->db_smartone->last_query(); - exit; - } - $sql = "INSERT INTO other_lcprepdetails ( - Other_LcprepDetailsOther_LcprepID, - Other_LcprepDetailsCode, - Other_LcprepDetailsLabel, - Other_LcprepDetailsResult, - Other_LcprepDetailsUserID, - Other_LcprepDetailsCreated - ) - VALUES( - ?, - ?, - ?, - ?, - ?, - NOW() - )"; - $query = $this->db_smartone->query($sql, array($header_id, $v['code'], $v['label'], $v['result'], $userid)); - if (!$query) { - echo $this->db_smartone->last_query(); - exit; - } - } - if (intval($v['xid'] != 0)) { - $sql = "UPDATE other_lcprepdetails SET - Other_LcprepDetailsCode = ?, - Other_LcprepDetailsLabel = ?, - Other_LcprepDetailsResult = ?, - Other_LcprepDetailsUserID = ? - WHERE - Other_LcprepDetailsID = ? - "; - $query = $this->db_smartone->query($sql, array($v['code'], $v['label'], $v['result'], $userid, $v['xid'])); - if (!$query) { - echo $this->db_smartone->last_query(); - exit; - } - } - //echo $sql; - } - } - - if (count($other_results) > 0 && intval($selected_lang) == 2) { - foreach ($other_results as $k => $v) { - if (intval($v['xid'] == 0)) { - $sql = "UPDATE other_lcprepdetails_lang SET Other_LcprepDetailsLangsIsActive = 'N' - WHERE - Other_LcprepDetailsLangsOther_LcprepID = ? AND - Other_LcprepDetailsLangsCode = ? AND - Other_LcprepDetailsLangsIsActive = 'Y'"; - $query = $this->db_smartone->query($sql, array($header_id, $v['code'])); - if (!$query) { - echo $this->db_smartone->last_query(); - exit; - } - //echo $this->db_smartone->last_query(); - $sql = "INSERT INTO other_lcprepdetails_lang ( - Other_LcprepDetailsLangsOther_LcprepID, - Other_LcprepDetailsLangsCode, - Other_LcprepDetailsLangsLabel, - Other_LcprepDetailsLangsResult, - Other_LcprepDetailsLangsCreatedUserID, - Other_LcprepDetailsLangsCreated - ) - VALUES( - ?, - ?, - ?, - ?, - ?, - NOW() - )"; - $query = $this->db_smartone->query($sql, array($header_id, $v['code'], $v['label'], $v['result'], $userid)); - if (!$query) { - echo $this->db_smartone->last_query(); - exit; - } - //echo $this->db_smartone->last_query(); - } - if (intval($v['xid'] != 0)) { - $sql = "UPDATE other_lcprepdetails_lang SET - Other_LcprepDetailsLangsCode = ?, - Other_LcprepDetailsLangsLabel = ?, - Other_LcprepDetailsLangsResult = ?, - Other_LcprepDetailsLangsUpdatedUserID = ?, - Other_LcprepDetailsLangsUpdated = NOW() - WHERE - Other_LcprepDetailsLangsID = ? - "; - $query = $this->db_smartone->query($sql, array($v['code'], $v['label'], $v['result'], $userid, $v['xid'])); - if (!$query) { - echo $this->db_smartone->last_query(); - exit; - } - } - //echo $sql; - } - } - - if ($interpretasi) { - foreach ($interpretasi as $k => $v) { - if (count($v['subgroups']) > 0) { - foreach ($v['subgroups'] as $ik => $iv) { - if (count($iv['childs']) > 0) { - foreach ($iv['childs'] as $iik => $iiv) { - if (intval($iiv['xid'] == 0)) { - $chex = $iiv['chex'] ? 'Y' : 'N'; - $sql = "UPDATE other_lcprepinterpretasi SET Other_LcprepInterpretasiIsActive = 'N' - WHERE - Other_LcprepInterpretasiOther_LcprepID = ? AND - Other_LcprepInterpretasiLcprep_InterpretasiID = ? AND - Other_LcprepInterpretasiIsActive = 'Y'"; - $query = $this->db_smartone->query($sql, array($header_id, $iiv['id'])); - if (!$query) { - echo $this->db_smartone->last_query(); - exit; - } - $sql = "INSERT INTO other_lcprepinterpretasi ( - Other_LcprepInterpretasiOther_LcprepID, - Other_LcprepInterpretasiLcprep_InterpretasiID, - Other_LcprepInterpretasiChex, - Other_LcprepInterpretasiValue, - Other_LcprepInterpretasiValueEng, - Other_LcprepInterpretasiUserID, - Other_LcprepInterpretasiCreated - ) - VALUES( - ?, - ?, - ?, - ?, - ?, - ?, - NOW() - )"; - $query = $this->db_smartone->query($sql, array($header_id, $iiv['id'], $chex, $iiv['value'], $iiv['value_en'], $userid)); - if (!$query) { - echo $this->db_smartone->last_query(); - exit; - } - } - - if (intval($iiv['xid'] != 0)) { - $chex = $iiv['chex'] ? 'Y' : 'N'; - $sql = "UPDATE other_lcprepinterpretasi SET - Other_LcprepInterpretasiChex = ?, - Other_LcprepInterpretasiValue = ?, - Other_LcprepInterpretasiValueEng = ?, - Other_LcprepInterpretasiUserID = ? - WHERE - Other_LcprepInterpretasiID = ? - "; - $query = $this->db_smartone->query($sql, array($chex, $iiv['value'], $iiv['value_en'], $userid, $iiv['xid'])); - if (!$query) { - echo $this->db_smartone->last_query(); - exit; - } - //echo $sql; - - } - } - } - } - } - //echo $sql; - } - } - - - $result = array("total" => 1, "records" => array(), "sql" => ''); - $this->sys_ok($result); - exit; - } - - function saveresult_papsmear() - { - $prm = $this->sys_input; - $detail_id = $prm['detail_id']; - $doctor_id = $prm['doctor']; - $checks = $prm['checks']; - $maturasi = $prm['maturasi']; - $bahans = $prm['bahans']; - $categories = $prm['categories']; - $results = $prm['results']; - - $userid = $this->sys_user['M_UserID']; - - $header_id = 0; - $sql = "SELECT * FROM other_papsmear WHERE Other_PapSmearT_OrderDetailID = {$detail_id} AND Other_PapSmearIsActive = 'Y'"; - $dt_header = $this->db_smartone->query($sql)->row_array(); - if ($dt_header) { - $header_id = $dt_header['Other_PapSmearID']; - } - if ($header_id == 0) { - $sql = "INSERT INTO other_papsmear( - Other_PapSmearT_OrderDetailID, - Other_PapSmearM_DoctorID, - Other_PapSmearUserID, - Other_PapSmearCreated - ) - VALUES( - {$detail_id}, - {$doctor_id}, - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } else { - $sql = "UPDATE other_papsmear SET Other_PapSmearM_DoctorID = {$doctor_id}, Other_PapSmearUserID = {$userid} WHERE Other_PapSmearID = {$header_id}"; - $this->db_smartone->query($sql); - } - - if ($checks) { - foreach ($checks as $k => $v) { - if (intval($v['xid']) == 0 && $v['selected'] === 'Y') { - $sql = "INSERT INTO other_papsmearcheck ( - Other_PapSmearCheckOther_PapSmearID, - Other_PapSmearCheckM_PapSmearCheckID, - Other_PapSmearCheckNote, - Other_PapSmearCheckUserID, - Other_PapSmearCheckCreated - ) - VALUES( - {$header_id}, - {$v['check_id']}, - '{$v['note']}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if (intval($v['xid']) != 0 && $v['selected'] === 'N') { - $sql = "UPDATE other_papsmearcheck SET - Other_PapSmearCheckIsActive = 'N', - Other_PapSmearCheckUserID = {$userid} - WHERE - Other_PapSmearCheckID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - if (intval($v['xid']) != 0 && $v['selected'] === 'Y') { - $sql = "UPDATE other_papsmearcheck SET - Other_PapSmearCheckNote = '{$v['note']}', - Other_PapSmearCheckUserID = {$userid} - WHERE - Other_PapSmearCheckID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - //echo $sql; - } - } - - if ($maturasi) { - if (intval($maturasi['xid']) == 0) { - $value = join("/", $maturasi['value']); - $sql = "INSERT INTO other_papsmearmaturasi ( - Other_PapSmearMaturasiOther_PapSmearID, - Other_PapSmearMaturasiValue, - Other_PapSmearMaturasiUserID, - Other_PapSmearMaturasiCreated - ) - VALUE( - {$header_id}, - '{$value}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - //echo $sql; - } - if (intval($maturasi['xid']) != 0) { - $value = join("/", $maturasi['value']); - $sql = "UPDATE other_papsmearmaturasi SET - Other_PapSmearMaturasiValue = '{$value}', - Other_PapSmearMaturasiUserID = {$userid} - WHERE - Other_PapSmearMaturasiID = {$maturasi['xid']}"; - // echo $sql; - $this->db_smartone->query($sql); - } - } - - if ($bahans) { - foreach ($bahans as $k => $v) { - if (intval($v['xid']) == 0 && $v['selected'] === 'Y') { - $sql = "INSERT INTO other_papsmearbahan ( - Other_PapSmearBahanOther_PapSmearID, - Other_PapSmearBahanM_PapSmearBahanID, - Other_PapSmearBahanUserID, - Other_PapSmearBahanCreated - ) - VALUES( - {$header_id}, - {$v['bahan_id']}, - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if (intval($v['xid']) != 0 && $v['selected'] === 'N') { - $sql = "UPDATE other_papsmearbahan SET - Other_PapSmearBahanIsActive = 'N', - Other_PapsmearCategoryUserID = {$userid} - WHERE - Other_PapSmearBahanID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - if (intval($v['xid']) != 0 && $v['selected'] === 'Y') { - $sql = "UPDATE other_papsmearbahan SET - Other_PapSmearBahanIsActive = 'Y', - Other_PapsmearCategoryUserID = {$userid} - WHERE - Other_PapSmearBahanID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - //echo $sql; - } - } - - if ($categories) { - foreach ($categories as $k => $v) { - if (intval($v['xid']) == 0 && $v['selected'] === 'Y') { - $sql = "INSERT INTO other_papsmearcategory ( - Other_PapsmearCategoryOther_PapSmearID, - Other_PapsmearCategoryM_PapSmearCategoryID, - Other_PapsmearCategoryUserID, - Other_PapsmearCategoryCreated - ) - VALUES( - {$header_id}, - {$v['category_id']}, - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if (intval($v['xid']) != 0 && $v['selected'] === 'N') { - $sql = "UPDATE other_papsmearcategory SET - Other_PapsmearCategoryIsActive = 'N', - Other_PapsmearCategoryUserID = {$userid} - WHERE - Other_PapsmearCategoryID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - //echo $sql; - if (intval($v['xid']) != 0 && $v['selected'] === 'Y') { - $sql = "UPDATE other_papsmearcategory SET - Other_PapsmearCategoryIsActive = 'Y', - Other_PapsmearCategoryUserID = {$userid} - WHERE - Other_PapsmearCategoryID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - } - } - - if ($results) { - foreach ($results as $k => $v) { - if (intval($v['xid']) == 0) { - $sql = "INSERT INTO other_papsmeardetails ( - Other_PapSmearDetailsOther_PapSmearID, - Other_PapSmearDetailsCode, - Other_PapSmearDetailsLabel, - Other_PapSmearDetailsResult, - Other_PapSmearDetailsUserID, - Other_PapSmearDetailsCreated - ) - VALUES( - {$header_id}, - '{$v['code']}', - '{$v['label']}', - '{$v['result']}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if (intval($v['xid']) != 0) { - $sql = "UPDATE other_papsmeardetails SET - Other_PapSmearDetailsCode = '{$v['code']}', - Other_PapSmearDetailsLabel = '{$v['label']}', - Other_PapSmearDetailsResult = '{$v['result']}', - Other_PapSmearDetailsUserID = {$userid} - WHERE - Other_PapSmearDetailsID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - //echo $sql; - } - } - - $result = array("total" => 1, "records" => array(), "sql" => ''); - $this->sys_ok($result); - exit; - } - - function saveresult_fna() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = $inp['doctor']; - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - if ($prm[0]['xid'] == '0') { - $sql = "INSERT INTO other_fna( - Other_FNAM_DoctorID, - Other_FNAT_OrderDetailID, - Other_FNAUserID, - Other_FNACreated - ) - VALUES( - {$doctor_id}, - {$prm[0]['orderdetail_id']}, - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } else { - $sql = "SELECT * FROM other_fna WHERE Other_FNAT_OrderDetailID = {$prm[0]['orderdetail_id']} AND Other_FNAIsActive = 'Y'"; - $data_header = $this->db_smartone->query($sql)->row_array(); - $header_id = $data_header['Other_FNAID']; - $sql = "UPDATE other_fna SET - Other_FNAM_DoctorID = {$doctor_id}, - Other_FNAUserID = {$userid} - WHERE - Other_FNAID = {$header_id}"; - $this->db_smartone->query($sql); - } - foreach ($prm as $k => $v) { - if ($v['xid'] == '0') { - $results = str_replace("'", "\\'", $v['result']); - $sql = "INSERT INTO other_fnadetails( - Other_FNADetailsOther_FNAID , - Other_FNADetailsCode, - Other_FNADetailsLabel, - Other_FNADetailsResult, - Other_FNADetailsCreated, - Other_FNADetailsUserID - ) - VALUES( - {$header_id}, - '{$v['code']}', - '{$v['label']}', - '{$results}', - NOW(), - {$userid} - )"; - $query = $this->db_smartone->query($sql); - } else { - $results = str_replace("'", "\\'", $v['result']); - $sql = "UPDATE other_fnadetails SET - Other_FNADetailsResult = '{$results}', - Other_FNADetailsUserID = {$userid} - WHERE - Other_FNADetailsID = {$v['xid']}"; - $query = $this->db_smartone->query($sql); - } - } - - $result = array("total" => 1, "records" => array(), "sql" => ''); - $this->sys_ok($result); - exit; - } - - function saveresult_patologianatomy() - { - - $inp = $this->sys_input; - $doctor_id = $inp['doctor']; - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - if ($inp['xid'] == '0') { - $sql = "INSERT INTO other_patologi_anatomy( - Other_PatologiAnatomyT_OrderDetailID, - Other_PatologiAnatomyM_DoctorID, - Other_PatologiAnatomyNoSediaan, - Other_PatologiAnatomyDiagnosaKlinis, - Other_PatologiAnatomyKeteranganKlinis, - Other_PatologiAnatomyLokasiOrgan, - Other_PatologiAnatomyMakroskopik, - Other_PatologiAnatomyMikroskopik, - Other_PatologiAnatomyKesimpulan, - Other_PatologiAnatomyUserID, - Other_PatologiAnatomyCreated - ) - VALUES( - {$inp['detail_id']}, - {$doctor_id}, - '{$inp['no_sediaan']}', - '{$inp['diagnosa']}', - '{$inp['klinis']}', - '{$inp['lokasi']}', - '{$inp['makroskopik']}', - '{$inp['mikroskopik']}', - '{$inp['kesimpulan']}', - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } else { - $sql = "UPDATE other_patologi_anatomy SET - Other_PatologiAnatomyM_DoctorID = ?, - Other_PatologiAnatomyNoSediaan = ?, - Other_PatologiAnatomyKeteranganKlinis = ?, - Other_PatologiAnatomyDiagnosaKlinis = ?, - Other_PatologiAnatomyLokasiOrgan = ?, - Other_PatologiAnatomyMakroskopik = ?, - Other_PatologiAnatomyMikroskopik = ?, - Other_PatologiAnatomyKesimpulan = ?, - Other_PatologiAnatomyUserID = ? - WHERE - Other_PatologiAnatomyT_OrderDetailID = ? AND Other_PatologiAnatomyIsActive = 'Y'"; - $this->db_smartone->query($sql, array( - $doctor_id, - $inp['no_sediaan'], - $inp['klinis'], - $inp['diagnosa'], - $inp['lokasi'], - $inp['makroskopik'], - $inp['mikroskopik'], - $inp['kesimpulan'], - $userid, - $inp['detail_id'] - )); - //echo $this->db_smartone->last_query(); - - } - - $inp_rst = array( - 'doctor_id' => $doctor_id, - 'no_sediaan' => $inp['no_sediaan'], - 'klinis' => $inp['klinis'], - 'diagnosa' => $inp['diagnosa'], - 'lokasi' => $inp['lokasi'], - 'makroskopik' => $inp['makroskopik'], - 'mikroskopik' => $inp['mikroskopik'], - 'kesimpulan' => $inp['kesimpulan'] - ); - $log_json = json_encode($inp_rst); - - $sql = "INSERT INTO log_other_patologianatomy ( - Log_OtherPatologiAnatomyT_OrderDetailID, - Log_OtherPatologiAnatomyDateTime, - Log_OtherPatologiAnatomySON, - Log_OtherPatologiAnatomyUserID - )VALUE( - {$inp['detail_id']}, - NOW(), - '{$log_json}', - {$userid} - )"; - $this->db_smartone->query($sql); - //echo $this->db_smartone->last_query(); - - $result = array("total" => 1, "records" => array(), "sql" => ''); - $this->sys_ok($result); - exit; - } - - function saveresult_cytologi() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = $inp['doctor']; - - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - if ($prm[0]['xid'] == '0') { - $sql = "INSERT INTO other_cytologi( - Other_CytologiT_OrderDetailID, - Other_CytologiM_DoctorID, - Other_CytologiUserID, - Other_CytologiCreated - ) - VALUES( - {$prm[0]['orderdetail_id']}, - {$doctor_id}, - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } else { - $sql = "SELECT * FROM other_cytologi WHERE Other_CytologiT_OrderDetailID = {$prm[0]['orderdetail_id']} AND Other_CytologiIsActive = 'Y'"; - $data_header = $this->db_smartone->query($sql)->row_array(); - $header_id = $data_header['Other_CytologiID']; - $sql = "UPDATE other_cytologi SET - Other_CytologiM_DoctorID = {$doctor_id}, - Other_CytologiUserID = {$userid} - WHERE - Other_CytologiID = {$header_id}"; - $this->db_smartone->query($sql); - } - foreach ($prm as $k => $v) { - if ($v['xid'] == '0') { - $results = str_replace("'", "\\'", $v['result']); - $sql = "INSERT INTO other_cytologidetails( - Other_CytologiDetailsOther_CytologiID , - Other_CytologiDetailsCode, - Other_CytologiDetailsLabel, - Other_CytologiDetailsResult, - Other_CytologiDetailsCreated, - Other_CytologiDetailsUserID - ) - VALUES( - {$header_id}, - '{$v['code']}', - '{$v['label']}', - '{$results}', - NOW(), - {$userid} - )"; - $query = $this->db_smartone->query($sql); - } else { - $results = str_replace("'", "\\'", $v['result']); - $sql = "UPDATE other_cytologidetails SET - Other_CytologiDetailsResult = '{$results}', - Other_CytologiDetailsUserID = {$userid} - WHERE - Other_CytologiDetailsID = {$v['xid']}"; - $query = $this->db_smartone->query($sql); - } - } - - $result = array("total" => 1, "records" => array(), "sql" => ''); - $this->sys_ok($result); - exit; - } - - function saveresult_mikro() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = $inp['doctor']; - $backteria_id = $inp['bacteria']; - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - - if ($inp['result_value'] != 'Negatif' && $inp['result_value'] != 'Positif') { - $prm['result_value'] = $prm['result_other']; - } else { - $prm['result_value'] = $inp['result_value']; - } - - if ($prm['xid'] == '0') { - $sql = "INSERT INTO other_mikro( - Other_MikroM_DoctorID, - Other_MikroResult, - Other_MikroT_BacteriaID, - Other_MikroT_OrderDetailID, - Other_MikroHasilBiakan, - Other_MikroSampleTypeName, - Other_MikroUserID, - Other_MikroCreated - ) - VALUES( - {$doctor_id}, - '{$prm['result_value']}', - {$backteria_id}, - {$prm['orderdetail_id']}, - '{$prm['hasil_biakan']}', - '{$prm['sample_name']}', - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } else { - $sql = "SELECT * FROM other_mikro WHERE Other_MikroT_OrderDetailID = {$prm['orderdetail_id']} AND Other_MikroIsActive = 'Y'"; - $data_header = $this->db_smartone->query($sql)->row_array(); - $header_id = $data_header['Other_MikroID']; - $sql = "UPDATE other_mikro SET - Other_MikroResult = '{$prm['result_value']}', - Other_MikroM_DoctorID = {$doctor_id}, - Other_MikroT_BacteriaID = {$backteria_id}, - Other_MikroHasilBiakan = '{$prm['hasil_biakan']}', - Other_MikroSampleTypeName = '{$prm['sample_name']}', - Other_MikroUserID = {$userid} - WHERE - Other_MikroID = {$header_id}"; - //echo $sql; - $this->db_smartone->query($sql); - } - - - - $sql = "UPDATE other_mikrodetails SET Other_MikroDetailsIsActive = 'N', Other_MikroDetailsUserID = 0 WHERE Other_MikroDetailsOther_MikroID = {$header_id}"; - $this->db_smartone->query($sql); - - $results = $prm['details']; - if ($inp['result_value'] == 'Positif') { - foreach ($results as $k => $v) { - if ($v['xid'] == '0') { - $sql = "INSERT INTO other_mikrodetails( - Other_MikroDetailsOther_MikroID , - Other_MikroDetailsT_AntibioticID, - Other_MikroDetailsValue, - Other_MikroDetailsNote, - Other_MikroDetailsCreated, - Other_MikroDetailsUserID - ) - VALUES( - {$header_id}, - '{$v['T_AntibioticID']}', - '{$v['value']}', - '{$v['note']}', - NOW(), - {$userid} - )"; - $query = $this->db_smartone->query($sql); - } else { - $sql = "UPDATE other_mikrodetails SET - Other_MikroDetailsT_AntibioticID = '{$v['T_AntibioticID']}', - Other_MikroDetailsValue = '{$v['value']}', - Other_MikroDetailsNote = '{$v['note']}', - Other_MikroDetailsIsActive = 'Y', - Other_MikroDetailsUserID = {$userid} - WHERE - Other_MikroDetailsID = {$v['xid']}"; - //echo $sql; - $query = $this->db_smartone->query($sql); - } - } - } - - - $result = array("total" => 1, "records" => array(), "sql" => ''); - $this->sys_ok($result); - exit; - } - - - function get_doctors_preparasi_sperma() - { - $prm = $this->sys_input; - // $id = $prm["id"]; - - $sql = " SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 10 AND - M_DoctorSOIsActive = 'Y' - ORDER BY M_DoctorName ASC"; - //echo $sql; - $query = $this->db_smartone->query($sql); - $rows = $query->result_array(); - $sql = " - SELECT '0' as id, 'Belum memilih metode' as name - UNION - SELECT M_MethodeSpermaID as id, M_MethodeSpermaName as name - FROM m_methodesperma - WHERE - M_MethodeSpermaIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $methodes = $this->db_smartone->query($sql)->result_array(); - - - $this->sys_ok(["records" => $rows, "methodes" => $methodes]); - } - - - function getpreparasispermaresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT other_preparasisperma.*, - Other_PreparasiSpermaID as xid, - Other_PreparasiSpermaT_OrderDetailID as orderdetail_id, - IFNULL(Other_PreparasiSpermaM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_PreparasiSpermaM_DoctorID) OR Other_PreparasiSpermaM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name, - IFNULL(M_MethodeSpermaID,0) as methode_id, - IFNULL(M_MethodeSpermaName,'') as methode_name - FROM other_preparasisperma - LEFT JOIN m_doctor ON Other_PreparasiSpermaM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - LEFT JOIN m_methodesperma ON Other_PreparasiSpermaM_MethodeSpermaID = M_MethodeSpermaID AND - M_MethodeSpermaIsActive = 'Y' - WHERE - Other_PreparasiSpermaT_OrderDetailID = {$id} AND Other_PreparasiSpermaIsActive = 'Y' - GROUP BY Other_PreparasiSpermaID"; - $query = $this->db_smartone->query($sql); - - if ($query) { - $rows = $query->row_array(); - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 10 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $sql = " - SELECT '0' as id, 'Belum memilih metode' as name - UNION - SELECT M_MethodeSpermaID as id, M_MethodeSpermaName as name - FROM m_methodesperma - WHERE - M_MethodeSpermaIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $methodes = $this->db_smartone->query($sql)->result_array(); - $images = array(); - $sql = "SELECT Other_PreparasiSpermaImgID as xid, - Other_PreparasiSpermaImgType as type, - CONCAT('/one-media/one-image-nonlab/',Other_PreparasiSpermaImgNewName) as image_url - FROM t_orderdetail - JOIN other_preparasisperma_img ON Other_PreparasiSpermaImgT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND - Other_PreparasiSpermaImgIsActive = 'Y' - WHERE - T_OrderDetailID = {$id} AND - T_OrderDetailIsActive = 'Y' - GROUP BY Other_PreparasiSpermaImgID"; - //echo $sql; - $images = $this->db_smartone->query($sql)->result_array(); - - $rst = array('doctors' => $doctors, 'methodes' => $methodes, 'results' => $rows, 'images' => $images); - $this->sys_ok(["records" => $rst]); - } else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - - function uploadimage_preparasi_sperma() - { - if (! $this->isLogin) { - $this->sys_error("Invalid Token"); - exit; - } - - $userid = $this->sys_user["M_UserID"]; - $data = []; - //print_r($_SERVER); - - $prm = $this->sys_input; - $orderid = $this->input->post('orderid'); - $type = $this->input->post('type'); - $labnumber = $this->input->post('labnumber'); - $sql = "UPDATE other_preparasisperma_img SET - Other_PreparasiSpermaImgIsActive = 'N', - Other_PreparasiSpermaImgUserID = {$userid} - WHERE - Other_PreparasiSpermaImgT_OrderHeaderID = {$orderid} AND - Other_PreparasiSpermaImgType = '{$type}'"; - //echo $sql; - $this->db_onedev->query($sql); - //$config['upload_path'] = 'assets/'; - - $path = '/home/one/project/one/one-media/one-image-nonlab/'; - //echo $path; - $config['upload_path'] = $path; - $config['allowed_types'] = 'jpg|jpeg|png|gif'; - - $config['max_size'] = '10000'; - $count = count($_FILES['files']['name']); - //echo $count; - $this->load->library('upload', $config); - - $error = []; - for ($i = 0; $i < $count; $i++) { - - - if (!empty($_FILES['files']['name'][$i])) { - - - - $_FILES['file']['name'] = $_FILES['files']['name'][$i]; - - $_FILES['file']['type'] = $_FILES['files']['type'][$i]; - - $_FILES['file']['tmp_name'] = $_FILES['files']['tmp_name'][$i]; - - $_FILES['file']['error'] = $_FILES['files']['error'][$i]; - - $_FILES['file']['size'] = $_FILES['files']['size'][$i]; - - - - $namex = $orderid . '-' . $labnumber . '-' . $this->generateRandomString(5); - //echo $namex; - - $config['file_name'] = $namex; - $this->upload->initialize($config); - //echo $config['file_name'] ; - - - - - - if ($this->upload->do_upload('file')) { - - $uploadData = $this->upload->data(); - - $filename = $uploadData['file_name']; - //echo $filename; - - - $sql = "INSERT INTO other_preparasisperma_img ( - Other_PreparasiSpermaImgT_OrderHeaderID, - Other_PreparasiSpermaImgType, - Other_PreparasiSpermaImgOldName, - Other_PreparasiSpermaImgNewName, - Other_PreparasiSpermaImgCreated, - Other_PreparasiSpermaImgUserID - ) - VALUES( - {$orderid}, - '{$type}', - '{$_FILES['files']['name'][$i]}', - '{$filename}', - NOW(), - {$userid} - - )"; - //echo $sql; - $this->db_onedev->query($sql); - $xlast_id = $this->db_onedev->insert_id(); - $data['totalFiles'][] = array('xid' => $xlast_id, 'type' => $type, 'image_url' => '/one-media/one-image-nonlab/' . $filename); - } else { - $error = array('error' => $this->upload->display_errors()); - } - } - } - - $result = array("total" => count($data['totalFiles']), "records" => $data['totalFiles'], 'errors' => $error); - $this->sys_ok($result); - } - - - function saveresult_preparasi_sperma() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = isset($inp['doctor']) ? $inp['doctor'] : 0; - $methode_id = isset($inp['methode']) ? $inp['methode'] : 0; - $orderdetail_id = $inp['orderdetailid']; - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - if ($prm['xid'] == '0') { - $sql = "INSERT INTO other_preparasisperma( - Other_PreparasiSpermaM_DoctorID, - Other_PreparasiSpermaT_OrderDetailID, - Other_PreparasiSpermaPreMotilitasA, - Other_PreparasiSpermaPreMotilitasB, - Other_PreparasiSpermaPreMotilitasC, - Other_PreparasiSpermaPreKonsentrasi, - Other_PreparasiSpermaPreKontaminan, - Other_PreparasiSpermaPostMotilitasA, - Other_PreparasiSpermaPostMotilitasB, - Other_PreparasiSpermaPostMotilitasC, - Other_PreparasiSpermaPostKonsentrasi, - Other_PreparasiSpermaPostKontaminan, - Other_PreparasiSpermaPreVolume, - Other_PreparasiSpermaPostVolume, - Other_PreparasiSpermaM_MethodeSpermaID, - Other_PreparasiSpermaNote, - Other_PreparasiSpermaUserID, - Other_PreparasiSpermaCreated - ) - VALUES( - {$doctor_id}, - {$orderdetail_id}, - '{$prm['Other_PreparasiSpermaPreMotilitasA']}', - '{$prm['Other_PreparasiSpermaPreMotilitasB']}', - '{$prm['Other_PreparasiSpermaPreMotilitasC']}', - '{$prm['Other_PreparasiSpermaPreKonsentrasi']}', - '{$prm['Other_PreparasiSpermaPreKontaminan']}', - '{$prm['Other_PreparasiSpermaPostMotilitasA']}', - '{$prm['Other_PreparasiSpermaPostMotilitasB']}', - '{$prm['Other_PreparasiSpermaPostMotilitasC']}', - '{$prm['Other_PreparasiSpermaPostKonsentrasi']}', - '{$prm['Other_PreparasiSpermaPostKontaminan']}', - '{$prm['Other_PreparasiSpermaPreVolume']}', - '{$prm['Other_PreparasiSpermaPostVolume']}', - '{$methode_id}', - '{$prm['Other_PreparasiSpermaNote']}', - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } else { - $sql = "SELECT * FROM other_preparasisperma WHERE Other_PreparasiSpermaT_OrderDetailID = {$orderdetail_id} AND Other_PreparasiSpermaIsActive = 'Y'"; - $data_header = $this->db_smartone->query($sql)->row_array(); - $header_id = $data_header['Other_PreparasiSpermaID']; - $sql = "UPDATE other_preparasisperma SET - Other_PreparasiSpermaM_DoctorID = {$doctor_id}, - Other_PreparasiSpermaPreMotilitasA = '{$prm['Other_PreparasiSpermaPreMotilitasA']}', - Other_PreparasiSpermaPreMotilitasB = '{$prm['Other_PreparasiSpermaPreMotilitasB']}', - Other_PreparasiSpermaPreMotilitasC = '{$prm['Other_PreparasiSpermaPreMotilitasC']}', - Other_PreparasiSpermaPreKonsentrasi = '{$prm['Other_PreparasiSpermaPreKonsentrasi']}', - Other_PreparasiSpermaPreKontaminan = '{$prm['Other_PreparasiSpermaPreKontaminan']}', - Other_PreparasiSpermaPostMotilitasA = '{$prm['Other_PreparasiSpermaPostMotilitasA']}', - Other_PreparasiSpermaPostMotilitasB = '{$prm['Other_PreparasiSpermaPostMotilitasB']}', - Other_PreparasiSpermaPostMotilitasC = '{$prm['Other_PreparasiSpermaPostMotilitasC']}', - Other_PreparasiSpermaPostKonsentrasi = '{$prm['Other_PreparasiSpermaPostKonsentrasi']}', - Other_PreparasiSpermaPostKontaminan = '{$prm['Other_PreparasiSpermaPostKontaminan']}', - Other_PreparasiSpermaPreVolume = '{$prm['Other_PreparasiSpermaPreVolume']}', - Other_PreparasiSpermaPostVolume = '{$prm['Other_PreparasiSpermaPostVolume']}', - Other_PreparasiSpermaM_MethodeSpermaID = '{$methode_id}', - Other_PreparasiSpermaNote = '{$prm['Other_PreparasiSpermaNote']}', - Other_PreparasiSpermaUserID = {$userid} - WHERE - Other_PreparasiSpermaID = {$header_id}"; - $this->db_smartone->query($sql); - } - - - $result = array("total" => 1, "records" => array(), "sql" => ''); - $this->sys_ok($result); - exit; - } - - function getdnafragmentasiresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT other_dnafragmentasi.*, - Other_DnaFragmentasiID as xid, - Other_DnaFragmentasiT_OrderDetailID as orderdetail_id, - IFNULL(Other_DnaFragmentasiM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_DnaFragmentasiM_DoctorID) OR Other_DnaFragmentasiM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name, - IFNULL(Other_DnaFragmentasiOther_DnaFragmentasiMethodeID,0) as methode_id, - IFNULL(Other_DnaFragmentasiMethodeName,'') as methode_name, - Other_DnaFragmentasiHaloLuas as halo_luas, - Other_DnaFragmentasiHaloSedang as halo_sedang, - Other_DnaFragmentasiHaloSempit as halo_sempit, - Other_DnaFragmentasiTanpaHalo as tanpa_halo, - Other_DnaFragmentasiDFI as dfi, - Other_DnaFragmentasiKesimpulan as kesimpulan, - Other_DnaFragmentasiCatatan as catatan - FROM other_dnafragmentasi - LEFT JOIN m_doctor ON Other_DnaFragmentasiM_DoctorID = M_DoctorID - LEFT JOIN other_dnafragmentasimethode ON Other_DnaFragmentasiOther_DnaFragmentasiMethodeID = Other_DnaFragmentasiMethodeID - WHERE - Other_DnaFragmentasiT_OrderDetailID = {$id} AND Other_DnaFragmentasiIsActive = 'Y' - GROUP BY Other_DnaFragmentasiID - LIMIT 1"; - //echo $sql; - $query = $this->db_smartone->query($sql); - - if ($query) { - $rows = $query->row_array(); - if (!$rows) { - $rows = array( - 'xid' => 0, - 'orderdetail_id' => $id, - 'doctor_id' => 0, - 'doctor_name' => '', - 'methode_id' => 0, - 'methode_name' => '', - 'halo_luas' => '', - 'halo_sedang' => '', - 'tanpa_halo' => '', - 'dfi' => '', - 'kesimpulan' => '', - 'catatan' => '' - ); - } - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID - WHERE - M_DoctorSONat_SubGroupID = 4 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - - $sql = " - SELECT '0' as id, 'Belum memilih metode' as name - UNION - SELECT Other_DnaFragmentasiMethodeID as id, Other_DnaFragmentasiMethodeName as name - FROM other_dnafragmentasimethode - WHERE - Other_DnaFragmentasiMethodeIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $methodes = $this->db_smartone->query($sql)->result_array(); - - - $rst = array('doctors' => $doctors, 'methodes' => $methodes, 'results' => $rows); - $this->sys_ok(["records" => $rst]); - } else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - function saveresult_dnafragmentasi() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = $inp['doctor']['id']; - $methode_id = $inp['methode']['id']; - $orderdetail_id = $inp['results']['orderdetail_id']; - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - if (intval($prm['xid']) == 0) { - $sql = "INSERT INTO other_dnafragmentasi( - Other_DnaFragmentasiT_OrderDetailID, - Other_DnaFragmentasiM_DoctorID, - Other_DnaFragmentasiOther_DnaFragmentasiMethodeID, - Other_DnaFragmentasiHaloLuas, - Other_DnaFragmentasiHaloSedang, - Other_DnaFragmentasiHaloSempit, - Other_DnaFragmentasiTanpaHalo, - Other_DnaFragmentasiDFI, - Other_DnaFragmentasiKesimpulan, - Other_DnaFragmentasiCatatan, - Other_DnaFragmentasiUserID, - Other_DnaFragmentasiLastUpdated - ) - VALUES( - {$orderdetail_id}, - {$doctor_id}, - {$methode_id}, - '{$prm['halo_luas']}', - '{$prm['halo_sedang']}', - '{$prm['halo_sempit']}', - '{$prm['tanpa_halo']}', - '{$prm['dfi']}', - '{$prm['kesimpulan']}', - '{$prm['catatan']}', - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } else { - $sql = "UPDATE other_dnafragmentasi SET - Other_DnaFragmentasiT_OrderDetailID = {$orderdetail_id}, - Other_DnaFragmentasiM_DoctorID = {$doctor_id}, - Other_DnaFragmentasiOther_DnaFragmentasiMethodeID = '{$methode_id}', - Other_DnaFragmentasiHaloLuas = '{$prm['halo_luas']}', - Other_DnaFragmentasiHaloSedang = '{$prm['halo_sedang']}', - Other_DnaFragmentasiHaloSempit = '{$prm['halo_sempit']}', - Other_DnaFragmentasiTanpaHalo = '{$prm['tanpa_halo']}', - Other_DnaFragmentasiDFI = '{$prm['dfi']}', - Other_DnaFragmentasiKesimpulan = '{$prm['kesimpulan']}', - Other_DnaFragmentasiCatatan = '{$prm['catatan']}', - Other_DnaFragmentasiLastUpdated = NOW(), - Other_DnaFragmentasiUserID = {$userid} - WHERE - Other_DnaFragmentasiID = {$prm['xid']}"; - //echo $sql; - $this->db_smartone->query($sql); - } - - - $result = array("total" => 1, "records" => array(), "sql" => ''); - $this->sys_ok($result); - exit; - } - - function get_flag_bloodtype() - { - $prm = $this->sys_input; - $sql = "SELECT FlagBloodTypeID, - FlagBloodTypeNat_TestID - FROM flag_blood_type - WHERE FlagBloodTypeIsActive = 'Y'"; - $qry = $this->db_smartone->query($sql); - if (!$qry) { - $this->sys_error_db("get flag blood type error", $this->db_smartone); - exit; - } - $row = $qry->row(); - $result = array('records' => $row); - $this->sys_ok($result); - } -} + + try { + foreach ($ids as $id) { + $this->db_smartone->query("call sp_set_normal_value_flag($id)"); + $this->clean_mysqli_connection($this->db_smartone->conn_id); + } + } catch (Exception $e) { + } + + $this->sys_ok($ids); + } + + public function save_template() + { + $prm = $this->sys_input; + + $n = $this->db_smartone->select("COUNT(T_ResultTemplateID) n") + ->where("T_ResultTemplateT_TestID", $prm['test_id']) + ->where("T_ResultTemplateIsActive", "Y") + ->where("T_ResultTemplateValue", $prm['value']) + ->get('t_resulttemplate') + ->row(); + if ($n->n > 0) { + $this->sys_error_db("Insert Result Template", $this->db_smartone); + return; + } + + $r = $this->db_smartone->set("T_ResultTemplateT_TestID", $prm['test_id']) + ->set("T_ResultTemplateValue", $prm['value']) + ->insert('t_resulttemplate'); + if ($r) { + $template = []; + $x = $this->db_smartone->query("CALL sp_master_resulttemplate_get('{$prm['test_id']}')"); + $this->clean_mysqli_connection($this->db_smartone->conn_id); + if ($x) + $template = $x->result_array(); + + $this->sys_ok($template); + } + } + + public function export() + { + $prm = $this->sys_input; + + $sql = "CALL sp_process_result_lang(?, ?, ?, ?)"; + $query = $this->db_smartone->query($sql, [$prm['order_id'], $prm['lang_id'], $prm['is_si'], $this->sys_user['M_UserID']]); + if ($query) { + $r = $query->row(); + if ($r->status == "OK") { + $this->sys_ok($r->data); + return; + } + + $this->sys_error_db("Message : " . $r->message, $this->db_smartone); + } else { + $this->sys_error_db("Lang Result", $this->db_smartone); + return; + } + } + + public function search_group() + { + $prm = $this->sys_input; + $max_rst = 100; + + // QUERY TOTAL + $sql = "select count(*) total + from t_worklist + where T_WorklistIsActive = 'Y' + order by T_WorklistName ASC"; + $query = $this->db_smartone->query($sql); + + if ($query) { + $tot_count = $query->result_array()[0]["total"]; + } else { + $this->sys_error_db("worklist count", $this->db_smartone); + exit; + } + + $sql = "select T_WorklistID group_id, T_WorklistName group_name + from t_worklist + where T_WorklistIsActive = 'Y' + order by T_WorklistName ASC + limit 0, {$max_rst}"; + $query = $this->db_smartone->query($sql); + + if ($query) { + $rows = $query->result_array(); + foreach ($rows as $k => $v) + $rows[$k]['data'] = json_decode($v['data']); + $result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows), "q" => $this->db_smartone->last_query()); + $this->sys_ok($result); + } else { + $this->sys_error_db("worklist rows", $this->db_smartone); + exit; + } + } + + public function search_rerun() + { + $prm = $this->sys_input; + $id = $prm["detail_id"]; + + $sql = "CALL sp_process_result_rerun(?)"; + $query = $this->db_smartone->query($sql, [$id]); + + if ($query) { + $rows = $query->result_array(); + $this->sys_ok(["records" => $rows]); + } else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + + + function getdoctorsfna() + { + $prm = $this->sys_input; + // $id = $prm["id"]; + + $sql = " SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY M_DoctorName ASC"; + //echo $sql; + $query = $this->db_smartone->query($sql); + + if ($query) { + $rows = $query->result_array(); + $this->sys_ok(["records" => $rows]); + } else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + function getgolongandarah() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $images = array(); + $sql = "SELECT So_ImageUploadBloodTypeID as xid, + CONCAT('/one-media/one-image-nonlab/',So_ImageUploadBloodTypeName) as image_url + FROM t_orderdetail + JOIN so_imageupload_bloodtype ON So_ImageUploadBloodTypeT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND + So_ImageUploadBloodTypeIsActive = 'Y' + WHERE + T_OrderDetailID = {$id} AND + T_OrderDetailIsActive = 'Y' + GROUP BY So_ImageUploadBloodTypeID"; + $images = $this->db_smartone->query($sql)->result_array(); + + $rst = array('images' => $images); + $this->sys_ok(["records" => $rst]); + } + + function getfnaresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT Other_FNADetailsID as xid, + Other_FNAT_OrderDetailID as orderdetail_id, + Other_FNADetailsCode as code, + Other_FNADetailsLabel as label, + Other_FNADetailsResult as result, + IFNULL(Other_FNAM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_FNAM_DoctorID) OR Other_FNAM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_fna + JOIN other_fnadetails ON Other_FNADetailsOther_FNAID = Other_FNAID AND Other_FNADetailsIsActive = 'Y' + LEFT JOIN m_doctor ON Other_FNAM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_FNAT_OrderDetailID = {$id} AND Other_FNAIsActive = 'Y' + GROUP BY Other_FNADetailsID + ORDER BY Other_FNADetailsCode ASC"; + $query = $this->db_smartone->query($sql); + + if ($query) { + $rows = $query->result_array(); + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $images = array(); + $sql = "SELECT So_ImageUploadID as xid, + CONCAT('/one-media/one-image-nonlab/',So_ImageUploadNewName) as image_url + FROM t_orderdetail + JOIN so_imageupload ON So_ImageUploadT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND + So_ImageUploadIsActive = 'Y' + WHERE + T_OrderDetailID = {$id} AND + T_OrderDetailIsActive = 'Y' + GROUP BY So_ImageUploadID"; + $images = $this->db_smartone->query($sql)->result_array(); + + $rst = array('doctors' => $doctors, 'results' => $rows, 'images' => $images); + $this->sys_ok(["records" => $rst]); + } else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + function getpatologianatomyresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT Other_PatologiAnatomyID as xid, + Other_PatologiAnatomyT_OrderDetailID as orderdetail_id, + Other_PatologiAnatomyNoSediaan as no_sediaan, + Other_PatologiAnatomyDiagnosaKlinis as diagnosa, + Other_PatologiAnatomyKeteranganKlinis as klinis, + Other_PatologiAnatomyLokasiOrgan as lokasi, + Other_PatologiAnatomyMakroskopik as makroskopik, + Other_PatologiAnatomyMikroskopik as mikroskopik, + Other_PatologiAnatomyKesimpulan as kesimpulan, + IFNULL(Other_PatologiAnatomyM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_PatologiAnatomyM_DoctorID) OR Other_PatologiAnatomyM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_patologi_anatomy + LEFT JOIN m_doctor ON Other_PatologiAnatomyM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_PatologiAnatomyT_OrderDetailID = {$id} AND Other_PatologiAnatomyIsActive = 'Y' + GROUP BY Other_PatologiAnatomyID + ORDER BY Other_PatologiAnatomyID ASC + LIMIT 1"; + $query = $this->db_smartone->query($sql); + + if ($query) { + $rows = $query->row_array(); + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + + $sql = "SELECT So_ImageUploadPatologyAnatomyID as xid, + CONCAT('/one-media/one-image-nonlab/',So_ImageUploadPatologyAnatomyNewName) as image_url, + So_ImageUploadPatologyAnatomyType as type + FROM t_orderdetail + JOIN so_imageupload_patology_anatomy ON So_ImageUploadPatologyAnatomyT_OrderHeaderID= T_OrderDetailT_OrderHeaderID AND + So_ImageUploadPatologyAnatomyIsActive= 'Y' + WHERE + T_OrderDetailID = {$id} AND + T_OrderDetailIsActive = 'Y' + GROUP BY So_ImageUploadPatologyAnatomyID"; + $images = $this->db_smartone->query($sql)->result_array(); + $mikro = []; + $makro = []; + + foreach ($images as $key => $value) { + + if ($value['type'] == 'mikro') { + $mikro[] = $value; + } + if ($value['type'] == 'makro') { + $makro[] = $value; + } + } + + $rst = array('doctors' => $doctors, 'result' => $rows, "mikro" => $mikro, "makro" => $makro); + $this->sys_ok(["records" => $rst]); + } else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + + function uploadimageblood() + { + if (! $this->isLogin) { + $this->sys_error("Invalid Token"); + exit; + } + + $userid = $this->sys_user["M_UserID"]; + $data = []; + //print_r($_SERVER); + + $prm = $this->sys_input; + $orderid = $this->input->post('orderid'); + $labnumber = $this->input->post('labnumber'); + $nattest_id = $this->input->post('nattest_id'); + $sql = "UPDATE so_imageupload_bloodtype SET + So_ImageUploadBloodTypeIsActive = 'N', + So_ImageUploadBloodTypeUserID = {$userid} + WHERE + So_ImageUploadBloodTypeT_OrderHeaderID = {$orderid}"; + //echo $sql; + $this->db_onedev->query($sql); + //$config['upload_path'] = 'assets/'; + + $path = '/home/one/project/one/one-media/one-image-nonlab/'; + //echo $path; + $config['upload_path'] = $path; + $config['allowed_types'] = 'jpg|jpeg|png|gif'; + + $config['max_size'] = '10000'; + $count = count($_FILES['files']['name']); + //echo $count; + $this->load->library('upload', $config); + + $error = []; + for ($i = 0; $i < $count; $i++) { + + + if (!empty($_FILES['files']['name'][$i])) { + + $_FILES['file']['name'] = $_FILES['files']['name'][$i]; + + $_FILES['file']['type'] = $_FILES['files']['type'][$i]; + + $_FILES['file']['tmp_name'] = $_FILES['files']['tmp_name'][$i]; + + $_FILES['file']['error'] = $_FILES['files']['error'][$i]; + + $_FILES['file']['size'] = $_FILES['files']['size'][$i]; + + $namex = $orderid . '-' . $labnumber . '-' . $this->generateRandomString(5); + //echo $namex; + + $config['file_name'] = $namex; + $this->upload->initialize($config); + //echo $config['file_name'] ; + + if ($this->upload->do_upload('file')) { + + $uploadData = $this->upload->data(); + + $filename = $uploadData['file_name']; + //echo $filename; + + + $sql = "INSERT INTO so_imageupload_bloodtype ( + So_ImageUploadBloodTypeT_OrderHeaderID, + So_ImageUploadBloodTypeT_OrderHeaderLabNumber, + So_ImageUploadBloodTypeName, + So_ImageUploadBloodTypeCreated, + So_ImageUploadBloodTypeUserID + ) + VALUES( + {$orderid}, + '{$labnumber}', + '{$filename}', + NOW(), + {$userid} + )"; + //echo $sql; + $this->db_onedev->query($sql); + $xlast_id = $this->db_onedev->insert_id(); + $data['totalFiles'][] = array('xid' => $xlast_id, 'image_url' => '/one-media/one-image-nonlab/' . $filename); + } else { + $error = array('error' => $this->upload->display_errors()); + } + } + } + + $result = array("total" => count($data['totalFiles']), "records" => $data['totalFiles'], 'errors' => $error); + $this->sys_ok($result); + } + + function uploadimage() + { + if (! $this->isLogin) { + $this->sys_error("Invalid Token"); + exit; + } + + $userid = $this->sys_user["M_UserID"]; + $data = []; + //print_r($_SERVER); + + $prm = $this->sys_input; + $orderid = $this->input->post('orderid'); + $labnumber = $this->input->post('labnumber'); + $sql = "UPDATE so_imageupload SET + So_ImageUploadIsActive = 'N', + So_ImageUploadUserID = {$userid} + WHERE + So_ImageUploadT_OrderHeaderID = {$orderid}"; + //echo $sql; + $this->db_onedev->query($sql); + //$config['upload_path'] = 'assets/'; + + $path = '/home/one/project/one/one-media/one-image-nonlab/'; + //echo $path; + $config['upload_path'] = $path; + $config['allowed_types'] = 'jpg|jpeg|png|gif'; + + $config['max_size'] = '10000'; + $count = count($_FILES['files']['name']); + //echo $count; + $this->load->library('upload', $config); + + $error = []; + for ($i = 0; $i < $count; $i++) { + + + if (!empty($_FILES['files']['name'][$i])) { + + + + $_FILES['file']['name'] = $_FILES['files']['name'][$i]; + + $_FILES['file']['type'] = $_FILES['files']['type'][$i]; + + $_FILES['file']['tmp_name'] = $_FILES['files']['tmp_name'][$i]; + + $_FILES['file']['error'] = $_FILES['files']['error'][$i]; + + $_FILES['file']['size'] = $_FILES['files']['size'][$i]; + + + + $namex = $orderid . '-' . $labnumber . '-' . $this->generateRandomString(5); + //echo $namex; + + $config['file_name'] = $namex; + $this->upload->initialize($config); + //echo $config['file_name'] ; + + + + + + if ($this->upload->do_upload('file')) { + + $uploadData = $this->upload->data(); + + $filename = $uploadData['file_name']; + //echo $filename; + + + $sql = "INSERT INTO so_imageupload ( + So_ImageUploadT_OrderHeaderID, + So_ImageUploadT_OrderHeaderLabNumber, + So_ImageUploadT_SampleTypeID, + So_ImageUploadOldName, + So_ImageUploadNewName, + So_ImageUploadCreated, + So_ImageUploadUserID + ) + VALUES( + {$orderid}, + '{$labnumber}', + '150', + '{$_FILES['files']['name'][$i]}', + '{$filename}', + NOW(), + {$userid} + + )"; + //echo $sql; + $this->db_onedev->query($sql); + $xlast_id = $this->db_onedev->insert_id(); + $data['totalFiles'][] = array('xid' => $xlast_id, 'image_url' => '/one-media/one-image-nonlab/' . $filename); + } else { + $error = array('error' => $this->upload->display_errors()); + } + } + } + + $result = array("total" => count($data['totalFiles']), "records" => $data['totalFiles'], 'errors' => $error); + $this->sys_ok($result); + } + function uploadimagePatologiAnatomi() + { + if (! $this->isLogin) { + $this->sys_error("Invalid Token"); + exit; + } + + $userid = $this->sys_user["M_UserID"]; + $data = []; + //print_r($_SERVER); + + $prm = $this->sys_input; + $orderid = $this->input->post('orderid'); + $type = $this->input->post('type'); + $labnumber = $this->input->post('labnumber'); + $sql = "UPDATE so_imageupload_patology_anatomy SET + So_ImageUploadPatologyAnatomyIsActive = 'N', + So_ImageUploadPatologyAnatomyUserID = {$userid} + WHERE + So_ImageUploadPatologyAnatomyT_OrderHeaderID = {$orderid} + AND So_ImageUploadPatologyAnatomyType = '{$type}'"; + //echo $sql; + $qry = $this->db_onedev->query($sql); + $last_qry = $this->db_onedev->last_query(); + if (!$qry) { + $message = $this->db_onedev->error(); + $message['last_qry'] = $last_qry; + $this->sys_error_db($message); + exit; + } + //$config['upload_path'] = 'assets/'; + + $path = '/home/one/project/one/one-media/one-image-nonlab/'; + //echo $path; + $config['upload_path'] = $path; + $config['allowed_types'] = 'jpg|jpeg|png|gif'; + + $config['max_size'] = '10000'; + $count = count($_FILES['files']['name']); + //echo $count; + $this->load->library('upload', $config); + + $error = []; + for ($i = 0; $i < $count; $i++) { + + + if (!empty($_FILES['files']['name'][$i])) { + + + + $_FILES['file']['name'] = $_FILES['files']['name'][$i]; + + $_FILES['file']['type'] = $_FILES['files']['type'][$i]; + + $_FILES['file']['tmp_name'] = $_FILES['files']['tmp_name'][$i]; + + $_FILES['file']['error'] = $_FILES['files']['error'][$i]; + + $_FILES['file']['size'] = $_FILES['files']['size'][$i]; + + + + $namex = $orderid . '-' . $labnumber . '-' . $this->generateRandomString(5); + //echo $namex; + + $config['file_name'] = $namex; + $this->upload->initialize($config); + //echo $config['file_name'] ; + + + + + + if ($this->upload->do_upload('file')) { + + $uploadData = $this->upload->data(); + + $filename = $uploadData['file_name']; + //echo $filename; + + + $sql = "INSERT INTO so_imageupload_patology_anatomy ( + So_ImageUploadPatologyAnatomyT_OrderHeaderID, + So_ImageUploadPatologyAnatomyT_OrderHeaderLabNumber, + So_ImageUploadPatologyAnatomyT_SampleTypeID, + So_ImageUploadPatologyAnatomyOldName, + So_ImageUploadPatologyAnatomyNewName, + So_ImageUploadPatologyAnatomyCreated, + So_ImageUploadPatologyAnatomyUserID, + So_ImageUploadPatologyAnatomyType + ) + VALUES( + {$orderid}, + '{$labnumber}', + '145', + '{$_FILES['files']['name'][$i]}', + '{$filename}', + NOW(), + {$userid}, + '{$type}' + + )"; + //echo $sql; + $qry = $this->db_onedev->query($sql); + $last_qry = $this->db_onedev->last_query(); + if (!$qry) { + $message = $this->db_onedev->error(); + $message['last_qry'] = $last_qry; + $this->sys_error_db($message); + exit; + } + $xlast_id = $this->db_onedev->insert_id(); + $data['totalFiles'][] = array('xid' => $xlast_id, 'image_url' => '/one-media/one-image-nonlab/' . $filename); + } else { + $error = array('error' => $this->upload->display_errors()); + } + } + } + + $result = array("total" => count($data['totalFiles']), "records" => $data['totalFiles'], 'errors' => $error); + $this->sys_ok($result); + } + + + function generateRandomString($length = 10) + { + $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; + $charactersLength = strlen($characters); + $randomString = ''; + for ($i = 0; $i < $length; $i++) { + $randomString .= $characters[rand(0, $charactersLength - 1)]; + } + return $randomString; + } + + function getcytologiresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT Other_CytologiDetailsID as xid, + Other_CytologiT_OrderDetailID as orderdetail_id, + Other_CytologiDetailsCode as code, + Other_CytologiDetailsLabel as label, + Other_CytologiDetailsResult as result, + IFNULL(Other_CytologiM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_CytologiM_DoctorID) OR Other_CytologiM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_cytologi + JOIN other_cytologidetails ON Other_CytologiDetailsOther_CytologiID = Other_CytologiID AND Other_CytologiDetailsIsActive = 'Y' + LEFT JOIN m_doctor ON Other_CytologiM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_CytologiT_OrderDetailID = {$id} AND Other_CytologiIsActive = 'Y' + GROUP BY Other_CytologiDetailsID + ORDER BY Other_CytologiDetailsCode ASC"; + //echo $sql; + $query = $this->db_smartone->query($sql); + + if ($query) { + $rows = $query->result_array(); + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $rst = array('doctors' => $doctors, 'results' => $rows); + $this->sys_ok(["records" => $rst]); + } else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + function getmikroresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT + Other_MikroID as xid, + Other_MikroHasilBiakan as hasil_biakan, + Other_MikroSampleTypeName as sample_name, + Other_MikroT_OrderDetailID as orderdetail_id, + Other_MikroResult as result_value, + '' as result_other, + IFNULL(T_BacteriaID,0) as T_BacteriaID, + IFNULL(T_BacteriaName,'') as T_BacteriaName, + '' as details, + IFNULL(Other_MikroM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_MikroM_DoctorID) OR Other_MikroM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_mikro + LEFT JOIN t_bacteria ON Other_MikroT_BacteriaID = T_BacteriaID + LEFT JOIN m_doctor ON Other_MikroM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_MikroT_OrderDetailID = {$id} AND Other_MikroIsActive = 'Y' + GROUP BY Other_MikroID"; + //echo $sql; + $query = $this->db_smartone->query($sql); + + if ($query) { + $row = $query->row_array(); + if ($row) { + if ($row['result_value'] != 'Positif' && $row['result_value'] != 'Negatif') { + $row['result_other'] = $row['result_value']; + $row['result_value'] = 'other'; + } + $sql = "SELECT '' as xno, + Other_MikroDetailsID as xid, + Other_MikroDetailsValue as value, + IF(Other_MikroDetailsNote = 'R','Y','N') as chx_r, + IF(Other_MikroDetailsNote = 'I','Y','N') as chx_i, + IF(Other_MikroDetailsNote = 'S','Y','N') as chx_s, + Other_MikroDetailsNote as note, + t_antibiotic.* + FROM other_mikrodetails + LEFT JOIN t_antibiotic ON Other_MikroDetailsT_AntibioticID = T_AntibioticID + WHERE + Other_MikroDetailsOther_MikroID = {$row['xid']} AND Other_MikroDetailsIsActive = 'Y' + GROUP BY Other_MikroDetailsID + ORDER BY T_AntibioticName ASC"; + //echo $sql; + $details = $this->db_smartone->query($sql)->result_array(); + if ($details) { + foreach ($details as $k => $v) { + $details[$k]['xno'] = $k + 1; + } + } + $row['details'] = $details; + } else { + $row = array('xid' => '0', 'hasil_biakan' => '', 'result_value' => 'Negatif', 'sample_name' => '', 'orderdetail_id' => $id, 'T_BacteriaID' => '0', 'T_BacteriaName' => '0', 'details' => array(), 'doctor_id' => '0', 'doctor_name' => '0'); + } + } else { + $row = array('xid' => '0', 'hasil_biakan' => '', 'result_value' => 'Negatif', 'sample_name' => '', 'orderdetail_id' => $id, 'T_BacteriaID' => '0', 'T_BacteriaName' => '0', 'details' => array(), 'doctor_id' => '0', 'doctor_name' => '0'); + } + //print_r($row); + + + + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 7 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $sql = " + SELECT '0' as id, 'Belum memilih bakteria' as name + UNION + SELECT T_BacteriaID as id, T_BacteriaName as name + FROM t_bacteria + WHERE + T_BacteriaIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $bacteries = $this->db_smartone->query($sql)->result_array(); + $rst = array('doctors' => $doctors, 'bacteries' => $bacteries, 'results' => $row); + $this->sys_ok(["records" => $rst]); + } + function getantibiotics() + { + $prm = $this->sys_input; + $id = $prm["id"]; + $sql = " SELECT '' as xno, + 0 as xid, + '' as hasil_biakan, + '' as sample_name, + 0 as value, + 'Y' as chx_r, + 'N' as chx_i, + 'N' as chx_s, + 'R' as note, + t_antibiotic.* + FROM t_antibiotic + WHERE + T_AntibioticT_BacteriaID = {$prm['id']} AND T_AntibioticIsActive= 'Y' + ORDER BY T_AntibioticName ASC"; + //echo $sql; + $rows = $this->db_smartone->query($sql)->result_array(); + if (rows) { + foreach ($rows as $k => $v) { + $rows[$k]['xno'] = $k + 1; + } + } + + $this->sys_ok(["records" => $rows]); + } + function getlcprepresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = "SELECT T_OrderDetailVerification as verification, T_OrderDetailValidation as validation FROM t_orderdetail WHERE T_OrderDetailID = ?"; + $order = $this->db_smartone->query($sql, array($id))->row_array(); + + + $sql = " SELECT Other_LcprepDetailsID as xid, + Other_LcprepID as header_id, + Other_LcprepT_orderDetailID as orderdetail_id, + Other_LcprepDetailsCode as code, + Other_LcprepDetailsLabel as label, + Other_LcprepDetailsResult as result, + IFNULL(Other_LcprepM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_LcprepM_DoctorID) OR Other_LcprepM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_lcprep + JOIN other_lcprepdetails ON Other_LcprepDetailsOther_LcprepID = Other_LcprepID AND Other_LcprepDetailsIsActive = 'Y' + LEFT JOIN m_doctor ON Other_LcprepM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_LcprepT_orderDetailID = ? AND Other_LcprepIsActive = 'Y' + GROUP BY Other_LcprepDetailsOther_LcprepID, Other_LcprepDetailsCode + ORDER BY Other_LcprepDetailsCode ASC"; + //echo $sql; + $rows = $this->db_smartone->query($sql, array($id))->result_array(); + if (count($rows) == 0) { + $rows = array( + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'A', + 'label' => 'DESKRIPSI', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ), + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'B', + 'label' => 'KESIMPULAN', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ) + ); + } + + $other_rows = array(); + $langs = array(array('id' => 1, 'name' => 'Bahasa Indonesia')); + $selected_lang = array(array('id' => 1, 'name' => 'Bahasa Indonesia')); + $sql = "SELECT T_OrderHeaderAddOnSecondM_LangID as lang_id, + M_LangName as lang_name + FROM t_orderdetail + JOIN t_orderheader ON T_OrderDetailT_OrderHeaderID = T_OrderHeaderID AND T_OrderHeaderIsActive = 'Y' + JOIN t_orderheaderaddon ON T_OrderHeaderAddonT_OrderHeaderID = T_OrderHeaderID AND T_OrderHeaderAddonIsActive = 'Y' + JOIN m_lang ON T_OrderHeaderAddOnSecondM_LangID = M_LangID AND M_LangIsActive = 'Y' + WHERE T_OrderDetailID = {$id} AND T_OrderDetailIsActive = 'Y'"; + + $other_lang = $this->db_smartone->query($sql)->result_array(); + if (count($other_lang) > 0) { + $langs[] = array('id' => $other_lang[0]['lang_id'], 'name' => $other_lang[0]['lang_name']); + $selected_lang = array('id' => $other_lang[0]['lang_id'], 'name' => $other_lang[0]['lang_name']); + + + $sql = " SELECT Other_LcprepDetailsLangsID as xid, + Other_LcprepID as header_id, + Other_LcprepT_orderDetailID as orderdetail_id, + Other_LcprepDetailsLangsCode as code, + Other_LcprepDetailsLangsLabel as label, + Other_LcprepDetailsLangsResult as result, + IFNULL(Other_LcprepM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_LcprepM_DoctorID) OR Other_LcprepM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_lcprep + JOIN other_lcprepdetails_lang ON Other_LcprepDetailsLangsOther_LcprepID = Other_LcprepID AND Other_LcprepDetailsLangsIsActive = 'Y' + LEFT JOIN m_doctor ON Other_LcprepM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_LcprepT_orderDetailID = {$id} AND Other_LcprepDetailsLangsIsActive = 'Y' + GROUP BY Other_LcprepDetailsLangsOther_LcprepID, Other_LcprepDetailsLangsCode + ORDER BY Other_LcprepDetailsLangsCode ASC"; + // echo $sql; + $other_rows = $this->db_smartone->query($sql)->result_array(); + if (count($other_rows) == 0) { + $other_rows = array( + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'AA', + 'label' => 'DESCRIPTION', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ), + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'BB', + 'label' => 'CONCLUSION', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ) + ); + } + } + + $header_id = $rows[0]['header_id']; + $sql = "SELECT IFNULL(Other_LcprepAdekuasiID,0) as xid, + Lcprep_AdekuasiID as id, + Lcprep_AdekuasiLabel as name, + Lcprep_AdekuasiLabel as name_en, + IF(ISNULL(Other_LcprepAdekuasiID),'N',Other_LcprepAdekuasiChex) as chex + FROM lcprep_adekuasi + LEFT JOIN other_lcprepadekuasi ON Other_LcprepAdekuasiLcprep_AdekuasiID = Lcprep_AdekuasiID AND + Other_LcprepAdekuasiOther_LcprepID = {$header_id} AND + Other_LcprepAdekuasiIsActive = 'Y' + WHERE + Lcprep_AdekuasiIsActive = 'Y' + GROUP BY Lcprep_AdekuasiID + ORDER BY Lcprep_AdekuasiOrder ASC + "; + //echo $sql; + $adeakuasi = $this->db_smartone->query($sql)->result_array(); + foreach ($adeakuasi as $kc => $vc) { + $adeakuasi[$kc]['chex'] = $vc['chex'] == 'N' ? false : true; + $adeakuasi[$kc]['name_en'] = $this->translate_word($vc['name']); + } + + $sql = "SELECT IFNULL(Other_LcprepKategoriUmumID,0) as xid, + Lcprep_KategoriUmumID as id, + Lcprep_KategoriUmumLabel as name, + Lcprep_KategoriUmumLabel as name_en, + IF(ISNULL(Other_LcprepKategoriUmumID),'N',Other_LcprepKategoriUmumChex) as chex + FROM lcprep_kategoriumum + LEFT JOIN other_lcprepkategoriumum ON Other_LcprepKategoriUmumLcprep_KategoriUmumID = Lcprep_KategoriUmumID AND + Other_LcprepKategoriUmumOther_LcprepID = {$header_id} AND + Other_LcprepKategoriUmumIsActive = 'Y' + WHERE + Lcprep_KategoriUmumIsActive = 'Y' + GROUP BY Lcprep_KategoriUmumID + "; + //echo $sql; + $kategoriumum = $this->db_smartone->query($sql)->result_array(); + foreach ($kategoriumum as $kc => $vc) { + $kategoriumum[$kc]['chex'] = $vc['chex'] == 'N' ? false : true; + $kategoriumum[$kc]['name_en'] = $this->translate_word($vc['name']); + } + + $sql = " + SELECT Lcprep_InterpretasiGroupID as group_id, + Lcprep_InterpretasiGroupName as group_name, + Lcprep_InterpretasiGroupName as group_name_en, + '' as subgroups + FROM lcprep_interpretasigroup + WHERE + Lcprep_InterpretasiGroupIsActive = 'Y' + "; + //echo $sql; + $interpretasi = $this->db_smartone->query($sql)->result_array(); + foreach ($interpretasi as $k => $v) { + $interpretasi[$k]['group_name_en'] = $this->translate_word($v['group_name']); + $subgroups = array(); + $sql = "SELECT Lcprep_InterpretasiSubgroupID as subgroup_id, + Lcprep_InterpretasiSubgroupName as subgroup_name, + Lcprep_InterpretasiSubgroupName as subgroup_name_en, + '' as childs + FROM lcprep_interpretasisubgroup + WHERE + Lcprep_InterpretasiSubgroupLcprep_InterpretasiGroupID = {$v['group_id']} AND Lcprep_InterpretasiSubgroupIsActive = 'Y'"; + //echo $sql; + $subgroups = $this->db_smartone->query($sql)->result_array(); + if (count($subgroups) > 0) { + foreach ($subgroups as $ki => $vi) { + $subgroups[$ki]['subgroup_name_en'] = $this->translate_word($vi['subgroup_name']); + $childs = array(); + + $sql = "SELECT IFNULL(Other_LcprepInterpretasiID,0) as xid, + IFNULL(Other_LcprepInterpretasiChex,'N') as chex, + IFNULL(Other_LcprepInterpretasiValue,'') as value, + IFNULL(Other_LcprepInterpretasiValueEng,'') as value_en, + Lcprep_InterpretasiID as id, + Lcprep_InterpretasiLcprep_InterpretasiSubgroupID as subgroup_id, + Lcprep_InterpretasiCode as code, + Lcprep_InterpretasiName as name, + Lcprep_InterpretasiName as name_en, + Lcprep_InterpretasiParentID as parent_id, + Lcprep_InterpretasiIsParent as is_parent, + Lcprep_InterpretasiHasResult as has_result, + Lcprep_InterpretasiTypeResult as type_result + FROM lcprep_interpretasi + LEFT JOIN other_lcprepinterpretasi ON Other_LcprepInterpretasiOther_LcprepID = {$header_id} AND + Other_LcprepInterpretasiLcprep_InterpretasiID = Lcprep_InterpretasiID AND + Other_LcprepInterpretasiIsActive = 'Y' + WHERE + Lcprep_InterpretasiLcprep_InterpretasiSubgroupID = {$vi['subgroup_id']} AND Lcprep_InterpretasiIsActive = 'Y' + GROUP BY Lcprep_InterpretasiID Order BY Lcprep_InterpretasiCode ASC"; + $childs = $this->db_smartone->query($sql)->result_array(); + if ($childs) { + foreach ($childs as $kc => $vc) { + $childs[$kc]['chex'] = $vc['chex'] == 'N' ? false : true; + $childs[$kc]['name_en'] = $this->translate_word($vc['name']); + } + } + $subgroups[$ki]['childs'] = $childs; + } + } + + $interpretasi[$k]['subgroups'] = $subgroups; + } + + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + + + + $rst = array('order' => $order, 'langs' => $langs, 'selected_lang' => $selected_lang, 'doctors' => $doctors, 'results' => $rows, 'other_results' => $other_rows, 'adekuasi' => $adeakuasi, 'kategoriumum' => $kategoriumum, 'interpretasi' => $interpretasi); + $this->sys_ok(["records" => $rst]); + } + + function translate_word($word) + { + $sql = "SELECT * + FROM translate_word + WHERE Translate_WordNat_LangID = '2' AND + BINARY Translate_WordFrom = '{$word}' AND + Translate_WordIsActive = 'Y' + LIMIT 1"; + $dt = $this->db_smartone->query($sql)->result_array(); + if (count($dt) > 0) { + return $dt[0]['Translate_WordTo']; + } else { + return $word; + } + } + + function getpapsmearresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT Other_PapSmearDetailsID as xid, + Other_PapSmearID as header_id, + Other_PapSmearT_OrderDetailID as orderdetail_id, + Other_PapSmearDetailsCode as code, + Other_PapSmearDetailsLabel as label, + Other_PapSmearDetailsResult as result, + IFNULL(Other_PapSmearM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_PapSmearM_DoctorID) OR Other_PapSmearM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_papsmear + JOIN other_papsmeardetails ON Other_PapSmearDetailsOther_PapSmearID = Other_PapSmearID AND Other_PapSmearDetailsIsActive = 'Y' + LEFT JOIN m_doctor ON Other_PapSmearM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_PapSmearT_OrderDetailID = {$id} AND Other_PapSmearIsActive = 'Y' + GROUP BY Other_PapSmearDetailsID + ORDER BY Other_PapSmearDetailsCode ASC"; + //echo $sql; + $rows = $this->db_smartone->query($sql)->result_array(); + if (!$rows) { + $rows = array( + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'A', + 'label' => 'Makroskopik', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ), + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'B', + 'label' => 'Mikroskopik', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ), + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'C', + 'label' => 'Kesimpulan', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ) + ); + } + + $header_id = $rows[0]['header_id']; + $sql = "SELECT Other_PapSmearMaturasiID as xid, + Other_PapSmearMaturasiValue as value + FROM other_papsmearmaturasi + WHERE + Other_PapSmearMaturasiOther_PapSmearID = {$header_id} AND + Other_PapSmearMaturasiIsActive = 'Y' + "; + //echo $sql; + $dt_maturasi = $this->db_smartone->query($sql)->row_array(); + if (!$dt_maturasi) { + $maturasi = array('xid' => '0', 'value' => array('', '', '')); + } else { + $value = explode('/', $dt_maturasi['value']); + $maturasi = array('xid' => $dt_maturasi['xid'], 'value' => $value); + } + + $sql = "SELECT IFNULL(Other_PapSmearBahanID,0) as xid, + M_PapSmearBahanID as bahan_id, + M_PapSmearBahanName as name, + IF(ISNULL(Other_PapSmearBahanID),'N','Y') as selected + FROM m_papsmearbahan + LEFT JOIN other_papsmearbahan ON Other_PapSmearBahanM_PapSmearBahanID = M_PapSmearBahanID AND + Other_PapSmearBahanOther_PapSmearID = {$header_id} AND + Other_PapSmearBahanIsActive = 'Y' + WHERE + M_PapSmearBahanIsActive = 'Y' + ORDER BY M_PapSmearBahanID ASC + "; + //echo $sql; + $bahans = $this->db_smartone->query($sql)->result_array(); + + $sql = "SELECT IFNULL(Other_PapsmearCategoryID,0) as xid, + M_PapSmearCategoryID as category_id, + M_PapSmearCategoryName as name, + IF(ISNULL(Other_PapsmearCategoryID),'N','Y') as selected + FROM m_papsmearcategory + LEFT JOIN other_papsmearcategory ON Other_PapsmearCategoryM_PapSmearCategoryID = M_PapSmearCategoryID AND + Other_PapsmearCategoryOther_PapSmearID = {$header_id} AND + Other_PapsmearCategoryIsActive = 'Y' + WHERE + M_PapSmearCategoryIsActive = 'Y' + ORDER BY M_PapSmearCategoryID ASC + "; + //echo $sql; + $categories = $this->db_smartone->query($sql)->result_array(); + + $sql = "SELECT IFNULL(Other_PapSmearCheckID,0) as xid, + M_PapSmearCheckID as check_id, + M_PapSmearCheckLabel as name, + IF(ISNULL(Other_PapSmearCheckID),'N','Y') as selected, + Other_PapSmearCheckNote as note + FROM m_papsmearcheck + LEFT JOIN other_papsmearcheck ON Other_PapSmearCheckM_PapSmearCheckID = M_PapSmearCheckID AND + Other_PapSmearCheckOther_PapSmearID = {$header_id} AND + Other_PapSmearCheckIsActive = 'Y' + WHERE + M_PapSmearCheckIsActive = 'Y' + ORDER BY M_PapSmearCheckCode ASC + "; + $checks = $this->db_smartone->query($sql)->result_array(); + + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $rst = array('doctors' => $doctors, 'checks' => $checks, 'bahans' => $bahans, 'categories' => $categories, 'maturasi' => $maturasi, 'results' => $rows); + $this->sys_ok(["records" => $rst]); + } + + function saveresult_lcprep() + { + $prm = $this->sys_input; + $detail_id = $prm['detail_id']; + $doctor_id = $prm['doctor']; + $adekuasi = $prm['adekuasi']; + $kategoriumum = $prm['kategoriumum']; + $interpretasi = $prm['interpretasi']; + $results = $prm['results']; + $selected_lang = $prm['selected_lang']; + $other_results = $prm['other_results']; + + $userid = $this->sys_user['M_UserID']; + + $header_id = 0; + $sql = "SELECT * FROM other_lcprep WHERE Other_LcprepT_orderDetailID = ? AND Other_LcprepIsActive = 'Y'"; + $dt_header = $this->db_smartone->query($sql, array($detail_id))->row_array(); + if ($dt_header) { + $header_id = $dt_header['Other_LcprepID']; + } + if ($header_id == 0) { + $sql = "INSERT INTO other_lcprep( + Other_LcprepT_orderDetailID, + Other_LcprepM_DoctorID, + Other_LcprepUserID, + Other_LcprepCreated + ) + VALUES( + ?, + ?, + ?, + NOW() + )"; + //echo $sql; + $query = $this->db_smartone->query($sql, array($detail_id, $doctor_id, $userid)); + if (!$query) { + echo $this->db_smartone->last_query(); + exit; + } + $header_id = $this->db_smartone->insert_id(); + } else { + $sql = "UPDATE other_lcprep SET Other_LcprepM_DoctorID = ?, Other_LcprepUserID = ? WHERE Other_LcprepID = ?"; + $query = $this->db_smartone->query($sql, array($doctor_id, $userid, $header_id)); + if (!$query) { + echo $this->db_smartone->last_query(); + exit; + } + } + + + + if ($adekuasi) { + foreach ($adekuasi as $k => $v) { + $selected = $v['chex'] ? 'Y' : 'N'; + if (intval($v['xid'] == 0)) { + $sql = "UPDATE other_lcprepadekuasi SET Other_LcprepAdekuasiIsActive = 'N' + WHERE + Other_LcprepAdekuasiOther_LcprepID = ? AND + Other_LcprepAdekuasiIsActive = 'Y' AND + Other_LcprepAdekuasiLcprep_AdekuasiID = ?"; + $query = $this->db_smartone->query($sql, array($header_id, $v['id'])); + if (!$query) { + echo $this->db_smartone->last_query(); + exit; + } + $sql = "INSERT INTO other_lcprepadekuasi ( + Other_LcprepAdekuasiOther_LcprepID, + Other_LcprepAdekuasiLcprep_AdekuasiID, + Other_LcprepAdekuasiChex, + Other_LcprepAdekuasiUserID, + Other_LcprepAdekuasiCreated + ) + VALUES( + ?, + ?, + ?, + ?, + NOW() + )"; + $query = $this->db_smartone->query($sql, array($header_id, $v['id'], $selected, $userid)); + if (!$query) { + echo $this->db_smartone->last_query(); + exit; + } + //echo $sql; + } + if (intval($v['xid'] != 0)) { + + $sql = "UPDATE other_lcprepadekuasi SET + Other_LcprepAdekuasiChex = ?, + Other_LcprepAdekuasiUserID = ? + WHERE + Other_LcprepAdekuasiID = ? + "; + $query = $this->db_smartone->query($sql, array($selected, $userid, $v['xid'])); + if (!$query) { + echo $this->db_smartone->last_query(); + exit; + } + } + + //echo $sql; + } + } + + if ($kategoriumum) { + foreach ($kategoriumum as $k => $v) { + $selected = $v['chex'] ? 'Y' : 'N'; + if (intval($v['xid'] == 0)) { + $sql = "UPDATE other_lcprepkategoriumum SET Other_LcprepKategoriUmumIsActive = 'N' + WHERE + Other_LcprepKategoriUmumOther_LcprepID = ? AND + Other_LcprepKategoriUmumLcprep_KategoriUmumID = ? AND + Other_LcprepKategoriUmumIsActive = 'Y' + "; + $query = $this->db_smartone->query($sql, array($header_id, $v['id'])); + if (!$query) { + echo $this->db_smartone->last_query(); + exit; + } + $sql = "INSERT INTO other_lcprepkategoriumum ( + Other_LcprepKategoriUmumOther_LcprepID, + Other_LcprepKategoriUmumLcprep_KategoriUmumID, + Other_LcprepKategoriUmumChex, + Other_LcprepKategoriUmumUserID, + Other_LcprepKategoriUmumCreated + ) + VALUES( + ?, + ?, + ?, + ?, + NOW() + )"; + $query = $this->db_smartone->query($sql, array($header_id, $v['id'], $selected, $userid)); + if (!$query) { + echo $this->db_smartone->last_query(); + exit; + } + } + if (intval($v['xid'] != 0)) { + $sql = "UPDATE other_lcprepkategoriumum SET + Other_LcprepKategoriUmumChex = ?, + Other_LcprepKategoriUmumUserID = ? + WHERE + Other_LcprepKategoriUmumID = ? + "; + $query = $this->db_smartone->query($sql, array($selected, $userid, $v['xid'])); + if (!$query) { + echo $this->db_smartone->last_query(); + exit; + } + } + + //echo $sql; + } + } + + if (count($results) > 0 && intval($selected_lang) == 1) { + foreach ($results as $k => $v) { + if (intval($v['xid'] == 0)) { + $sql = "UPDATE other_lcprepdetails SET Other_LcprepDetailsIsActive = 'N' + WHERE + Other_LcprepDetailsOther_LcprepID = ? AND + Other_LcprepDetailsCode = ? AND + Other_LcprepDetailsIsActive = 'Y'"; + $query = $this->db_smartone->query($sql, array($header_id, $v['code'])); + if (!$query) { + echo $this->db_smartone->last_query(); + exit; + } + $sql = "INSERT INTO other_lcprepdetails ( + Other_LcprepDetailsOther_LcprepID, + Other_LcprepDetailsCode, + Other_LcprepDetailsLabel, + Other_LcprepDetailsResult, + Other_LcprepDetailsUserID, + Other_LcprepDetailsCreated + ) + VALUES( + ?, + ?, + ?, + ?, + ?, + NOW() + )"; + $query = $this->db_smartone->query($sql, array($header_id, $v['code'], $v['label'], $v['result'], $userid)); + if (!$query) { + echo $this->db_smartone->last_query(); + exit; + } + } + if (intval($v['xid'] != 0)) { + $sql = "UPDATE other_lcprepdetails SET + Other_LcprepDetailsCode = ?, + Other_LcprepDetailsLabel = ?, + Other_LcprepDetailsResult = ?, + Other_LcprepDetailsUserID = ? + WHERE + Other_LcprepDetailsID = ? + "; + $query = $this->db_smartone->query($sql, array($v['code'], $v['label'], $v['result'], $userid, $v['xid'])); + if (!$query) { + echo $this->db_smartone->last_query(); + exit; + } + } + //echo $sql; + } + } + + if (count($other_results) > 0 && intval($selected_lang) == 2) { + foreach ($other_results as $k => $v) { + if (intval($v['xid'] == 0)) { + $sql = "UPDATE other_lcprepdetails_lang SET Other_LcprepDetailsLangsIsActive = 'N' + WHERE + Other_LcprepDetailsLangsOther_LcprepID = ? AND + Other_LcprepDetailsLangsCode = ? AND + Other_LcprepDetailsLangsIsActive = 'Y'"; + $query = $this->db_smartone->query($sql, array($header_id, $v['code'])); + if (!$query) { + echo $this->db_smartone->last_query(); + exit; + } + //echo $this->db_smartone->last_query(); + $sql = "INSERT INTO other_lcprepdetails_lang ( + Other_LcprepDetailsLangsOther_LcprepID, + Other_LcprepDetailsLangsCode, + Other_LcprepDetailsLangsLabel, + Other_LcprepDetailsLangsResult, + Other_LcprepDetailsLangsCreatedUserID, + Other_LcprepDetailsLangsCreated + ) + VALUES( + ?, + ?, + ?, + ?, + ?, + NOW() + )"; + $query = $this->db_smartone->query($sql, array($header_id, $v['code'], $v['label'], $v['result'], $userid)); + if (!$query) { + echo $this->db_smartone->last_query(); + exit; + } + //echo $this->db_smartone->last_query(); + } + if (intval($v['xid'] != 0)) { + $sql = "UPDATE other_lcprepdetails_lang SET + Other_LcprepDetailsLangsCode = ?, + Other_LcprepDetailsLangsLabel = ?, + Other_LcprepDetailsLangsResult = ?, + Other_LcprepDetailsLangsUpdatedUserID = ?, + Other_LcprepDetailsLangsUpdated = NOW() + WHERE + Other_LcprepDetailsLangsID = ? + "; + $query = $this->db_smartone->query($sql, array($v['code'], $v['label'], $v['result'], $userid, $v['xid'])); + if (!$query) { + echo $this->db_smartone->last_query(); + exit; + } + } + //echo $sql; + } + } + + if ($interpretasi) { + foreach ($interpretasi as $k => $v) { + if (count($v['subgroups']) > 0) { + foreach ($v['subgroups'] as $ik => $iv) { + if (count($iv['childs']) > 0) { + foreach ($iv['childs'] as $iik => $iiv) { + if (intval($iiv['xid'] == 0)) { + $chex = $iiv['chex'] ? 'Y' : 'N'; + $sql = "UPDATE other_lcprepinterpretasi SET Other_LcprepInterpretasiIsActive = 'N' + WHERE + Other_LcprepInterpretasiOther_LcprepID = ? AND + Other_LcprepInterpretasiLcprep_InterpretasiID = ? AND + Other_LcprepInterpretasiIsActive = 'Y'"; + $query = $this->db_smartone->query($sql, array($header_id, $iiv['id'])); + if (!$query) { + echo $this->db_smartone->last_query(); + exit; + } + $sql = "INSERT INTO other_lcprepinterpretasi ( + Other_LcprepInterpretasiOther_LcprepID, + Other_LcprepInterpretasiLcprep_InterpretasiID, + Other_LcprepInterpretasiChex, + Other_LcprepInterpretasiValue, + Other_LcprepInterpretasiValueEng, + Other_LcprepInterpretasiUserID, + Other_LcprepInterpretasiCreated + ) + VALUES( + ?, + ?, + ?, + ?, + ?, + ?, + NOW() + )"; + $query = $this->db_smartone->query($sql, array($header_id, $iiv['id'], $chex, $iiv['value'], $iiv['value_en'], $userid)); + if (!$query) { + echo $this->db_smartone->last_query(); + exit; + } + } + + if (intval($iiv['xid'] != 0)) { + $chex = $iiv['chex'] ? 'Y' : 'N'; + $sql = "UPDATE other_lcprepinterpretasi SET + Other_LcprepInterpretasiChex = ?, + Other_LcprepInterpretasiValue = ?, + Other_LcprepInterpretasiValueEng = ?, + Other_LcprepInterpretasiUserID = ? + WHERE + Other_LcprepInterpretasiID = ? + "; + $query = $this->db_smartone->query($sql, array($chex, $iiv['value'], $iiv['value_en'], $userid, $iiv['xid'])); + if (!$query) { + echo $this->db_smartone->last_query(); + exit; + } + //echo $sql; + + } + } + } + } + } + //echo $sql; + } + } + + + $result = array("total" => 1, "records" => array(), "sql" => ''); + $this->sys_ok($result); + exit; + } + + function saveresult_papsmear() + { + $prm = $this->sys_input; + $detail_id = $prm['detail_id']; + $doctor_id = $prm['doctor']; + $checks = $prm['checks']; + $maturasi = $prm['maturasi']; + $bahans = $prm['bahans']; + $categories = $prm['categories']; + $results = $prm['results']; + + $userid = $this->sys_user['M_UserID']; + + $header_id = 0; + $sql = "SELECT * FROM other_papsmear WHERE Other_PapSmearT_OrderDetailID = {$detail_id} AND Other_PapSmearIsActive = 'Y'"; + $dt_header = $this->db_smartone->query($sql)->row_array(); + if ($dt_header) { + $header_id = $dt_header['Other_PapSmearID']; + } + if ($header_id == 0) { + $sql = "INSERT INTO other_papsmear( + Other_PapSmearT_OrderDetailID, + Other_PapSmearM_DoctorID, + Other_PapSmearUserID, + Other_PapSmearCreated + ) + VALUES( + {$detail_id}, + {$doctor_id}, + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } else { + $sql = "UPDATE other_papsmear SET Other_PapSmearM_DoctorID = {$doctor_id}, Other_PapSmearUserID = {$userid} WHERE Other_PapSmearID = {$header_id}"; + $this->db_smartone->query($sql); + } + + if ($checks) { + foreach ($checks as $k => $v) { + if (intval($v['xid']) == 0 && $v['selected'] === 'Y') { + $sql = "INSERT INTO other_papsmearcheck ( + Other_PapSmearCheckOther_PapSmearID, + Other_PapSmearCheckM_PapSmearCheckID, + Other_PapSmearCheckNote, + Other_PapSmearCheckUserID, + Other_PapSmearCheckCreated + ) + VALUES( + {$header_id}, + {$v['check_id']}, + '{$v['note']}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if (intval($v['xid']) != 0 && $v['selected'] === 'N') { + $sql = "UPDATE other_papsmearcheck SET + Other_PapSmearCheckIsActive = 'N', + Other_PapSmearCheckUserID = {$userid} + WHERE + Other_PapSmearCheckID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + if (intval($v['xid']) != 0 && $v['selected'] === 'Y') { + $sql = "UPDATE other_papsmearcheck SET + Other_PapSmearCheckNote = '{$v['note']}', + Other_PapSmearCheckUserID = {$userid} + WHERE + Other_PapSmearCheckID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + //echo $sql; + } + } + + if ($maturasi) { + if (intval($maturasi['xid']) == 0) { + $value = join("/", $maturasi['value']); + $sql = "INSERT INTO other_papsmearmaturasi ( + Other_PapSmearMaturasiOther_PapSmearID, + Other_PapSmearMaturasiValue, + Other_PapSmearMaturasiUserID, + Other_PapSmearMaturasiCreated + ) + VALUE( + {$header_id}, + '{$value}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + //echo $sql; + } + if (intval($maturasi['xid']) != 0) { + $value = join("/", $maturasi['value']); + $sql = "UPDATE other_papsmearmaturasi SET + Other_PapSmearMaturasiValue = '{$value}', + Other_PapSmearMaturasiUserID = {$userid} + WHERE + Other_PapSmearMaturasiID = {$maturasi['xid']}"; + // echo $sql; + $this->db_smartone->query($sql); + } + } + + if ($bahans) { + foreach ($bahans as $k => $v) { + if (intval($v['xid']) == 0 && $v['selected'] === 'Y') { + $sql = "INSERT INTO other_papsmearbahan ( + Other_PapSmearBahanOther_PapSmearID, + Other_PapSmearBahanM_PapSmearBahanID, + Other_PapSmearBahanUserID, + Other_PapSmearBahanCreated + ) + VALUES( + {$header_id}, + {$v['bahan_id']}, + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if (intval($v['xid']) != 0 && $v['selected'] === 'N') { + $sql = "UPDATE other_papsmearbahan SET + Other_PapSmearBahanIsActive = 'N', + Other_PapsmearCategoryUserID = {$userid} + WHERE + Other_PapSmearBahanID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + if (intval($v['xid']) != 0 && $v['selected'] === 'Y') { + $sql = "UPDATE other_papsmearbahan SET + Other_PapSmearBahanIsActive = 'Y', + Other_PapsmearCategoryUserID = {$userid} + WHERE + Other_PapSmearBahanID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + //echo $sql; + } + } + + if ($categories) { + foreach ($categories as $k => $v) { + if (intval($v['xid']) == 0 && $v['selected'] === 'Y') { + $sql = "INSERT INTO other_papsmearcategory ( + Other_PapsmearCategoryOther_PapSmearID, + Other_PapsmearCategoryM_PapSmearCategoryID, + Other_PapsmearCategoryUserID, + Other_PapsmearCategoryCreated + ) + VALUES( + {$header_id}, + {$v['category_id']}, + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if (intval($v['xid']) != 0 && $v['selected'] === 'N') { + $sql = "UPDATE other_papsmearcategory SET + Other_PapsmearCategoryIsActive = 'N', + Other_PapsmearCategoryUserID = {$userid} + WHERE + Other_PapsmearCategoryID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + //echo $sql; + if (intval($v['xid']) != 0 && $v['selected'] === 'Y') { + $sql = "UPDATE other_papsmearcategory SET + Other_PapsmearCategoryIsActive = 'Y', + Other_PapsmearCategoryUserID = {$userid} + WHERE + Other_PapsmearCategoryID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + } + } + + if ($results) { + foreach ($results as $k => $v) { + if (intval($v['xid']) == 0) { + $sql = "INSERT INTO other_papsmeardetails ( + Other_PapSmearDetailsOther_PapSmearID, + Other_PapSmearDetailsCode, + Other_PapSmearDetailsLabel, + Other_PapSmearDetailsResult, + Other_PapSmearDetailsUserID, + Other_PapSmearDetailsCreated + ) + VALUES( + {$header_id}, + '{$v['code']}', + '{$v['label']}', + '{$v['result']}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if (intval($v['xid']) != 0) { + $sql = "UPDATE other_papsmeardetails SET + Other_PapSmearDetailsCode = '{$v['code']}', + Other_PapSmearDetailsLabel = '{$v['label']}', + Other_PapSmearDetailsResult = '{$v['result']}', + Other_PapSmearDetailsUserID = {$userid} + WHERE + Other_PapSmearDetailsID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + //echo $sql; + } + } + + $result = array("total" => 1, "records" => array(), "sql" => ''); + $this->sys_ok($result); + exit; + } + + function saveresult_fna() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = $inp['doctor']; + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + if ($prm[0]['xid'] == '0') { + $sql = "INSERT INTO other_fna( + Other_FNAM_DoctorID, + Other_FNAT_OrderDetailID, + Other_FNAUserID, + Other_FNACreated + ) + VALUES( + {$doctor_id}, + {$prm[0]['orderdetail_id']}, + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } else { + $sql = "SELECT * FROM other_fna WHERE Other_FNAT_OrderDetailID = {$prm[0]['orderdetail_id']} AND Other_FNAIsActive = 'Y'"; + $data_header = $this->db_smartone->query($sql)->row_array(); + $header_id = $data_header['Other_FNAID']; + $sql = "UPDATE other_fna SET + Other_FNAM_DoctorID = {$doctor_id}, + Other_FNAUserID = {$userid} + WHERE + Other_FNAID = {$header_id}"; + $this->db_smartone->query($sql); + } + foreach ($prm as $k => $v) { + if ($v['xid'] == '0') { + $results = str_replace("'", "\\'", $v['result']); + $sql = "INSERT INTO other_fnadetails( + Other_FNADetailsOther_FNAID , + Other_FNADetailsCode, + Other_FNADetailsLabel, + Other_FNADetailsResult, + Other_FNADetailsCreated, + Other_FNADetailsUserID + ) + VALUES( + {$header_id}, + '{$v['code']}', + '{$v['label']}', + '{$results}', + NOW(), + {$userid} + )"; + $query = $this->db_smartone->query($sql); + } else { + $results = str_replace("'", "\\'", $v['result']); + $sql = "UPDATE other_fnadetails SET + Other_FNADetailsResult = '{$results}', + Other_FNADetailsUserID = {$userid} + WHERE + Other_FNADetailsID = {$v['xid']}"; + $query = $this->db_smartone->query($sql); + } + } + + $result = array("total" => 1, "records" => array(), "sql" => ''); + $this->sys_ok($result); + exit; + } + + function saveresult_patologianatomy() + { + + $inp = $this->sys_input; + $doctor_id = $inp['doctor']; + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + if ($inp['xid'] == '0') { + $sql = "INSERT INTO other_patologi_anatomy( + Other_PatologiAnatomyT_OrderDetailID, + Other_PatologiAnatomyM_DoctorID, + Other_PatologiAnatomyNoSediaan, + Other_PatologiAnatomyDiagnosaKlinis, + Other_PatologiAnatomyKeteranganKlinis, + Other_PatologiAnatomyLokasiOrgan, + Other_PatologiAnatomyMakroskopik, + Other_PatologiAnatomyMikroskopik, + Other_PatologiAnatomyKesimpulan, + Other_PatologiAnatomyUserID, + Other_PatologiAnatomyCreated + ) + VALUES( + {$inp['detail_id']}, + {$doctor_id}, + '{$inp['no_sediaan']}', + '{$inp['diagnosa']}', + '{$inp['klinis']}', + '{$inp['lokasi']}', + '{$inp['makroskopik']}', + '{$inp['mikroskopik']}', + '{$inp['kesimpulan']}', + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } else { + $sql = "UPDATE other_patologi_anatomy SET + Other_PatologiAnatomyM_DoctorID = ?, + Other_PatologiAnatomyNoSediaan = ?, + Other_PatologiAnatomyKeteranganKlinis = ?, + Other_PatologiAnatomyDiagnosaKlinis = ?, + Other_PatologiAnatomyLokasiOrgan = ?, + Other_PatologiAnatomyMakroskopik = ?, + Other_PatologiAnatomyMikroskopik = ?, + Other_PatologiAnatomyKesimpulan = ?, + Other_PatologiAnatomyUserID = ? + WHERE + Other_PatologiAnatomyT_OrderDetailID = ? AND Other_PatologiAnatomyIsActive = 'Y'"; + $this->db_smartone->query($sql, array( + $doctor_id, + $inp['no_sediaan'], + $inp['klinis'], + $inp['diagnosa'], + $inp['lokasi'], + $inp['makroskopik'], + $inp['mikroskopik'], + $inp['kesimpulan'], + $userid, + $inp['detail_id'] + )); + //echo $this->db_smartone->last_query(); + + } + + $inp_rst = array( + 'doctor_id' => $doctor_id, + 'no_sediaan' => $inp['no_sediaan'], + 'klinis' => $inp['klinis'], + 'diagnosa' => $inp['diagnosa'], + 'lokasi' => $inp['lokasi'], + 'makroskopik' => $inp['makroskopik'], + 'mikroskopik' => $inp['mikroskopik'], + 'kesimpulan' => $inp['kesimpulan'] + ); + $log_json = json_encode($inp_rst); + + $sql = "INSERT INTO log_other_patologianatomy ( + Log_OtherPatologiAnatomyT_OrderDetailID, + Log_OtherPatologiAnatomyDateTime, + Log_OtherPatologiAnatomySON, + Log_OtherPatologiAnatomyUserID + )VALUE( + {$inp['detail_id']}, + NOW(), + '{$log_json}', + {$userid} + )"; + $this->db_smartone->query($sql); + //echo $this->db_smartone->last_query(); + + $result = array("total" => 1, "records" => array(), "sql" => ''); + $this->sys_ok($result); + exit; + } + + function saveresult_cytologi() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = $inp['doctor']; + + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + if ($prm[0]['xid'] == '0') { + $sql = "INSERT INTO other_cytologi( + Other_CytologiT_OrderDetailID, + Other_CytologiM_DoctorID, + Other_CytologiUserID, + Other_CytologiCreated + ) + VALUES( + {$prm[0]['orderdetail_id']}, + {$doctor_id}, + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } else { + $sql = "SELECT * FROM other_cytologi WHERE Other_CytologiT_OrderDetailID = {$prm[0]['orderdetail_id']} AND Other_CytologiIsActive = 'Y'"; + $data_header = $this->db_smartone->query($sql)->row_array(); + $header_id = $data_header['Other_CytologiID']; + $sql = "UPDATE other_cytologi SET + Other_CytologiM_DoctorID = {$doctor_id}, + Other_CytologiUserID = {$userid} + WHERE + Other_CytologiID = {$header_id}"; + $this->db_smartone->query($sql); + } + foreach ($prm as $k => $v) { + if ($v['xid'] == '0') { + $results = str_replace("'", "\\'", $v['result']); + $sql = "INSERT INTO other_cytologidetails( + Other_CytologiDetailsOther_CytologiID , + Other_CytologiDetailsCode, + Other_CytologiDetailsLabel, + Other_CytologiDetailsResult, + Other_CytologiDetailsCreated, + Other_CytologiDetailsUserID + ) + VALUES( + {$header_id}, + '{$v['code']}', + '{$v['label']}', + '{$results}', + NOW(), + {$userid} + )"; + $query = $this->db_smartone->query($sql); + } else { + $results = str_replace("'", "\\'", $v['result']); + $sql = "UPDATE other_cytologidetails SET + Other_CytologiDetailsResult = '{$results}', + Other_CytologiDetailsUserID = {$userid} + WHERE + Other_CytologiDetailsID = {$v['xid']}"; + $query = $this->db_smartone->query($sql); + } + } + + $result = array("total" => 1, "records" => array(), "sql" => ''); + $this->sys_ok($result); + exit; + } + + function saveresult_mikro() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = $inp['doctor']; + $backteria_id = $inp['bacteria']; + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + + if ($inp['result_value'] != 'Negatif' && $inp['result_value'] != 'Positif') { + $prm['result_value'] = $prm['result_other']; + } else { + $prm['result_value'] = $inp['result_value']; + } + + if ($prm['xid'] == '0') { + $sql = "INSERT INTO other_mikro( + Other_MikroM_DoctorID, + Other_MikroResult, + Other_MikroT_BacteriaID, + Other_MikroT_OrderDetailID, + Other_MikroHasilBiakan, + Other_MikroSampleTypeName, + Other_MikroUserID, + Other_MikroCreated + ) + VALUES( + {$doctor_id}, + '{$prm['result_value']}', + {$backteria_id}, + {$prm['orderdetail_id']}, + '{$prm['hasil_biakan']}', + '{$prm['sample_name']}', + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } else { + $sql = "SELECT * FROM other_mikro WHERE Other_MikroT_OrderDetailID = {$prm['orderdetail_id']} AND Other_MikroIsActive = 'Y'"; + $data_header = $this->db_smartone->query($sql)->row_array(); + $header_id = $data_header['Other_MikroID']; + $sql = "UPDATE other_mikro SET + Other_MikroResult = '{$prm['result_value']}', + Other_MikroM_DoctorID = {$doctor_id}, + Other_MikroT_BacteriaID = {$backteria_id}, + Other_MikroHasilBiakan = '{$prm['hasil_biakan']}', + Other_MikroSampleTypeName = '{$prm['sample_name']}', + Other_MikroUserID = {$userid} + WHERE + Other_MikroID = {$header_id}"; + //echo $sql; + $this->db_smartone->query($sql); + } + + + + $sql = "UPDATE other_mikrodetails SET Other_MikroDetailsIsActive = 'N', Other_MikroDetailsUserID = 0 WHERE Other_MikroDetailsOther_MikroID = {$header_id}"; + $this->db_smartone->query($sql); + + $results = $prm['details']; + if ($inp['result_value'] == 'Positif') { + foreach ($results as $k => $v) { + if ($v['xid'] == '0') { + $sql = "INSERT INTO other_mikrodetails( + Other_MikroDetailsOther_MikroID , + Other_MikroDetailsT_AntibioticID, + Other_MikroDetailsValue, + Other_MikroDetailsNote, + Other_MikroDetailsCreated, + Other_MikroDetailsUserID + ) + VALUES( + {$header_id}, + '{$v['T_AntibioticID']}', + '{$v['value']}', + '{$v['note']}', + NOW(), + {$userid} + )"; + $query = $this->db_smartone->query($sql); + } else { + $sql = "UPDATE other_mikrodetails SET + Other_MikroDetailsT_AntibioticID = '{$v['T_AntibioticID']}', + Other_MikroDetailsValue = '{$v['value']}', + Other_MikroDetailsNote = '{$v['note']}', + Other_MikroDetailsIsActive = 'Y', + Other_MikroDetailsUserID = {$userid} + WHERE + Other_MikroDetailsID = {$v['xid']}"; + //echo $sql; + $query = $this->db_smartone->query($sql); + } + } + } + + + $result = array("total" => 1, "records" => array(), "sql" => ''); + $this->sys_ok($result); + exit; + } + + + function get_doctors_preparasi_sperma() + { + $prm = $this->sys_input; + // $id = $prm["id"]; + + $sql = " SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 10 AND + M_DoctorSOIsActive = 'Y' + ORDER BY M_DoctorName ASC"; + //echo $sql; + $query = $this->db_smartone->query($sql); + $rows = $query->result_array(); + $sql = " + SELECT '0' as id, 'Belum memilih metode' as name + UNION + SELECT M_MethodeSpermaID as id, M_MethodeSpermaName as name + FROM m_methodesperma + WHERE + M_MethodeSpermaIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $methodes = $this->db_smartone->query($sql)->result_array(); + + + $this->sys_ok(["records" => $rows, "methodes" => $methodes]); + } + + + function getpreparasispermaresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT other_preparasisperma.*, + Other_PreparasiSpermaID as xid, + Other_PreparasiSpermaT_OrderDetailID as orderdetail_id, + IFNULL(Other_PreparasiSpermaM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_PreparasiSpermaM_DoctorID) OR Other_PreparasiSpermaM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name, + IFNULL(M_MethodeSpermaID,0) as methode_id, + IFNULL(M_MethodeSpermaName,'') as methode_name + FROM other_preparasisperma + LEFT JOIN m_doctor ON Other_PreparasiSpermaM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + LEFT JOIN m_methodesperma ON Other_PreparasiSpermaM_MethodeSpermaID = M_MethodeSpermaID AND + M_MethodeSpermaIsActive = 'Y' + WHERE + Other_PreparasiSpermaT_OrderDetailID = {$id} AND Other_PreparasiSpermaIsActive = 'Y' + GROUP BY Other_PreparasiSpermaID"; + $query = $this->db_smartone->query($sql); + + if ($query) { + $rows = $query->row_array(); + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 10 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $sql = " + SELECT '0' as id, 'Belum memilih metode' as name + UNION + SELECT M_MethodeSpermaID as id, M_MethodeSpermaName as name + FROM m_methodesperma + WHERE + M_MethodeSpermaIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $methodes = $this->db_smartone->query($sql)->result_array(); + $images = array(); + $sql = "SELECT Other_PreparasiSpermaImgID as xid, + Other_PreparasiSpermaImgType as type, + CONCAT('/one-media/one-image-nonlab/',Other_PreparasiSpermaImgNewName) as image_url + FROM t_orderdetail + JOIN other_preparasisperma_img ON Other_PreparasiSpermaImgT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND + Other_PreparasiSpermaImgIsActive = 'Y' + WHERE + T_OrderDetailID = {$id} AND + T_OrderDetailIsActive = 'Y' + GROUP BY Other_PreparasiSpermaImgID"; + //echo $sql; + $images = $this->db_smartone->query($sql)->result_array(); + + $rst = array('doctors' => $doctors, 'methodes' => $methodes, 'results' => $rows, 'images' => $images); + $this->sys_ok(["records" => $rst]); + } else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + + function uploadimage_preparasi_sperma() + { + if (! $this->isLogin) { + $this->sys_error("Invalid Token"); + exit; + } + + $userid = $this->sys_user["M_UserID"]; + $data = []; + //print_r($_SERVER); + + $prm = $this->sys_input; + $orderid = $this->input->post('orderid'); + $type = $this->input->post('type'); + $labnumber = $this->input->post('labnumber'); + $sql = "UPDATE other_preparasisperma_img SET + Other_PreparasiSpermaImgIsActive = 'N', + Other_PreparasiSpermaImgUserID = {$userid} + WHERE + Other_PreparasiSpermaImgT_OrderHeaderID = {$orderid} AND + Other_PreparasiSpermaImgType = '{$type}'"; + //echo $sql; + $this->db_onedev->query($sql); + //$config['upload_path'] = 'assets/'; + + $path = '/home/one/project/one/one-media/one-image-nonlab/'; + //echo $path; + $config['upload_path'] = $path; + $config['allowed_types'] = 'jpg|jpeg|png|gif'; + + $config['max_size'] = '10000'; + $count = count($_FILES['files']['name']); + //echo $count; + $this->load->library('upload', $config); + + $error = []; + for ($i = 0; $i < $count; $i++) { + + + if (!empty($_FILES['files']['name'][$i])) { + + + + $_FILES['file']['name'] = $_FILES['files']['name'][$i]; + + $_FILES['file']['type'] = $_FILES['files']['type'][$i]; + + $_FILES['file']['tmp_name'] = $_FILES['files']['tmp_name'][$i]; + + $_FILES['file']['error'] = $_FILES['files']['error'][$i]; + + $_FILES['file']['size'] = $_FILES['files']['size'][$i]; + + + + $namex = $orderid . '-' . $labnumber . '-' . $this->generateRandomString(5); + //echo $namex; + + $config['file_name'] = $namex; + $this->upload->initialize($config); + //echo $config['file_name'] ; + + + + + + if ($this->upload->do_upload('file')) { + + $uploadData = $this->upload->data(); + + $filename = $uploadData['file_name']; + //echo $filename; + + + $sql = "INSERT INTO other_preparasisperma_img ( + Other_PreparasiSpermaImgT_OrderHeaderID, + Other_PreparasiSpermaImgType, + Other_PreparasiSpermaImgOldName, + Other_PreparasiSpermaImgNewName, + Other_PreparasiSpermaImgCreated, + Other_PreparasiSpermaImgUserID + ) + VALUES( + {$orderid}, + '{$type}', + '{$_FILES['files']['name'][$i]}', + '{$filename}', + NOW(), + {$userid} + + )"; + //echo $sql; + $this->db_onedev->query($sql); + $xlast_id = $this->db_onedev->insert_id(); + $data['totalFiles'][] = array('xid' => $xlast_id, 'type' => $type, 'image_url' => '/one-media/one-image-nonlab/' . $filename); + } else { + $error = array('error' => $this->upload->display_errors()); + } + } + } + + $result = array("total" => count($data['totalFiles']), "records" => $data['totalFiles'], 'errors' => $error); + $this->sys_ok($result); + } + + + function saveresult_preparasi_sperma() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = isset($inp['doctor']) ? $inp['doctor'] : 0; + $methode_id = isset($inp['methode']) ? $inp['methode'] : 0; + $orderdetail_id = $inp['orderdetailid']; + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + if ($prm['xid'] == '0') { + $sql = "INSERT INTO other_preparasisperma( + Other_PreparasiSpermaM_DoctorID, + Other_PreparasiSpermaT_OrderDetailID, + Other_PreparasiSpermaPreMotilitasA, + Other_PreparasiSpermaPreMotilitasB, + Other_PreparasiSpermaPreMotilitasC, + Other_PreparasiSpermaPreKonsentrasi, + Other_PreparasiSpermaPreKontaminan, + Other_PreparasiSpermaPostMotilitasA, + Other_PreparasiSpermaPostMotilitasB, + Other_PreparasiSpermaPostMotilitasC, + Other_PreparasiSpermaPostKonsentrasi, + Other_PreparasiSpermaPostKontaminan, + Other_PreparasiSpermaPreVolume, + Other_PreparasiSpermaPostVolume, + Other_PreparasiSpermaM_MethodeSpermaID, + Other_PreparasiSpermaNote, + Other_PreparasiSpermaUserID, + Other_PreparasiSpermaCreated + ) + VALUES( + {$doctor_id}, + {$orderdetail_id}, + '{$prm['Other_PreparasiSpermaPreMotilitasA']}', + '{$prm['Other_PreparasiSpermaPreMotilitasB']}', + '{$prm['Other_PreparasiSpermaPreMotilitasC']}', + '{$prm['Other_PreparasiSpermaPreKonsentrasi']}', + '{$prm['Other_PreparasiSpermaPreKontaminan']}', + '{$prm['Other_PreparasiSpermaPostMotilitasA']}', + '{$prm['Other_PreparasiSpermaPostMotilitasB']}', + '{$prm['Other_PreparasiSpermaPostMotilitasC']}', + '{$prm['Other_PreparasiSpermaPostKonsentrasi']}', + '{$prm['Other_PreparasiSpermaPostKontaminan']}', + '{$prm['Other_PreparasiSpermaPreVolume']}', + '{$prm['Other_PreparasiSpermaPostVolume']}', + '{$methode_id}', + '{$prm['Other_PreparasiSpermaNote']}', + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } else { + $sql = "SELECT * FROM other_preparasisperma WHERE Other_PreparasiSpermaT_OrderDetailID = {$orderdetail_id} AND Other_PreparasiSpermaIsActive = 'Y'"; + $data_header = $this->db_smartone->query($sql)->row_array(); + $header_id = $data_header['Other_PreparasiSpermaID']; + $sql = "UPDATE other_preparasisperma SET + Other_PreparasiSpermaM_DoctorID = {$doctor_id}, + Other_PreparasiSpermaPreMotilitasA = '{$prm['Other_PreparasiSpermaPreMotilitasA']}', + Other_PreparasiSpermaPreMotilitasB = '{$prm['Other_PreparasiSpermaPreMotilitasB']}', + Other_PreparasiSpermaPreMotilitasC = '{$prm['Other_PreparasiSpermaPreMotilitasC']}', + Other_PreparasiSpermaPreKonsentrasi = '{$prm['Other_PreparasiSpermaPreKonsentrasi']}', + Other_PreparasiSpermaPreKontaminan = '{$prm['Other_PreparasiSpermaPreKontaminan']}', + Other_PreparasiSpermaPostMotilitasA = '{$prm['Other_PreparasiSpermaPostMotilitasA']}', + Other_PreparasiSpermaPostMotilitasB = '{$prm['Other_PreparasiSpermaPostMotilitasB']}', + Other_PreparasiSpermaPostMotilitasC = '{$prm['Other_PreparasiSpermaPostMotilitasC']}', + Other_PreparasiSpermaPostKonsentrasi = '{$prm['Other_PreparasiSpermaPostKonsentrasi']}', + Other_PreparasiSpermaPostKontaminan = '{$prm['Other_PreparasiSpermaPostKontaminan']}', + Other_PreparasiSpermaPreVolume = '{$prm['Other_PreparasiSpermaPreVolume']}', + Other_PreparasiSpermaPostVolume = '{$prm['Other_PreparasiSpermaPostVolume']}', + Other_PreparasiSpermaM_MethodeSpermaID = '{$methode_id}', + Other_PreparasiSpermaNote = '{$prm['Other_PreparasiSpermaNote']}', + Other_PreparasiSpermaUserID = {$userid} + WHERE + Other_PreparasiSpermaID = {$header_id}"; + $this->db_smartone->query($sql); + } + + + $result = array("total" => 1, "records" => array(), "sql" => ''); + $this->sys_ok($result); + exit; + } + + function getdnafragmentasiresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT other_dnafragmentasi.*, + Other_DnaFragmentasiID as xid, + Other_DnaFragmentasiT_OrderDetailID as orderdetail_id, + IFNULL(Other_DnaFragmentasiM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_DnaFragmentasiM_DoctorID) OR Other_DnaFragmentasiM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name, + IFNULL(Other_DnaFragmentasiOther_DnaFragmentasiMethodeID,0) as methode_id, + IFNULL(Other_DnaFragmentasiMethodeName,'') as methode_name, + Other_DnaFragmentasiHaloLuas as halo_luas, + Other_DnaFragmentasiHaloSedang as halo_sedang, + Other_DnaFragmentasiHaloSempit as halo_sempit, + Other_DnaFragmentasiTanpaHalo as tanpa_halo, + Other_DnaFragmentasiDFI as dfi, + Other_DnaFragmentasiKesimpulan as kesimpulan, + Other_DnaFragmentasiCatatan as catatan + FROM other_dnafragmentasi + LEFT JOIN m_doctor ON Other_DnaFragmentasiM_DoctorID = M_DoctorID + LEFT JOIN other_dnafragmentasimethode ON Other_DnaFragmentasiOther_DnaFragmentasiMethodeID = Other_DnaFragmentasiMethodeID + WHERE + Other_DnaFragmentasiT_OrderDetailID = {$id} AND Other_DnaFragmentasiIsActive = 'Y' + GROUP BY Other_DnaFragmentasiID + LIMIT 1"; + //echo $sql; + $query = $this->db_smartone->query($sql); + + if ($query) { + $rows = $query->row_array(); + if (!$rows) { + $rows = array( + 'xid' => 0, + 'orderdetail_id' => $id, + 'doctor_id' => 0, + 'doctor_name' => '', + 'methode_id' => 0, + 'methode_name' => '', + 'halo_luas' => '', + 'halo_sedang' => '', + 'tanpa_halo' => '', + 'dfi' => '', + 'kesimpulan' => '', + 'catatan' => '' + ); + } + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID + WHERE + M_DoctorSONat_SubGroupID = 4 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + + $sql = " + SELECT '0' as id, 'Belum memilih metode' as name + UNION + SELECT Other_DnaFragmentasiMethodeID as id, Other_DnaFragmentasiMethodeName as name + FROM other_dnafragmentasimethode + WHERE + Other_DnaFragmentasiMethodeIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $methodes = $this->db_smartone->query($sql)->result_array(); + + + $rst = array('doctors' => $doctors, 'methodes' => $methodes, 'results' => $rows); + $this->sys_ok(["records" => $rst]); + } else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + function saveresult_dnafragmentasi() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = $inp['doctor']['id']; + $methode_id = $inp['methode']['id']; + $orderdetail_id = $inp['results']['orderdetail_id']; + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + if (intval($prm['xid']) == 0) { + $sql = "INSERT INTO other_dnafragmentasi( + Other_DnaFragmentasiT_OrderDetailID, + Other_DnaFragmentasiM_DoctorID, + Other_DnaFragmentasiOther_DnaFragmentasiMethodeID, + Other_DnaFragmentasiHaloLuas, + Other_DnaFragmentasiHaloSedang, + Other_DnaFragmentasiHaloSempit, + Other_DnaFragmentasiTanpaHalo, + Other_DnaFragmentasiDFI, + Other_DnaFragmentasiKesimpulan, + Other_DnaFragmentasiCatatan, + Other_DnaFragmentasiUserID, + Other_DnaFragmentasiLastUpdated + ) + VALUES( + {$orderdetail_id}, + {$doctor_id}, + {$methode_id}, + '{$prm['halo_luas']}', + '{$prm['halo_sedang']}', + '{$prm['halo_sempit']}', + '{$prm['tanpa_halo']}', + '{$prm['dfi']}', + '{$prm['kesimpulan']}', + '{$prm['catatan']}', + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } else { + $sql = "UPDATE other_dnafragmentasi SET + Other_DnaFragmentasiT_OrderDetailID = {$orderdetail_id}, + Other_DnaFragmentasiM_DoctorID = {$doctor_id}, + Other_DnaFragmentasiOther_DnaFragmentasiMethodeID = '{$methode_id}', + Other_DnaFragmentasiHaloLuas = '{$prm['halo_luas']}', + Other_DnaFragmentasiHaloSedang = '{$prm['halo_sedang']}', + Other_DnaFragmentasiHaloSempit = '{$prm['halo_sempit']}', + Other_DnaFragmentasiTanpaHalo = '{$prm['tanpa_halo']}', + Other_DnaFragmentasiDFI = '{$prm['dfi']}', + Other_DnaFragmentasiKesimpulan = '{$prm['kesimpulan']}', + Other_DnaFragmentasiCatatan = '{$prm['catatan']}', + Other_DnaFragmentasiLastUpdated = NOW(), + Other_DnaFragmentasiUserID = {$userid} + WHERE + Other_DnaFragmentasiID = {$prm['xid']}"; + //echo $sql; + $this->db_smartone->query($sql); + } + + + $result = array("total" => 1, "records" => array(), "sql" => ''); + $this->sys_ok($result); + exit; + } + + function get_flag_bloodtype() + { + $prm = $this->sys_input; + $sql = "SELECT FlagBloodTypeID, + FlagBloodTypeNat_TestID + FROM flag_blood_type + WHERE FlagBloodTypeIsActive = 'Y'"; + $qry = $this->db_smartone->query($sql); + if (!$qry) { + $this->sys_error_db("get flag blood type error", $this->db_smartone); + exit; + } + $row = $qry->row(); + $result = array('records' => $row); + $this->sys_ok($result); + } +} diff --git a/application/controllers/mockup/process/resultentry-westone-030925/9/Re_px.php b/application/controllers/mockup/process/resultentry-westone-030925/9/Re_px.php index 08699539..e0631de5 100644 --- a/application/controllers/mockup/process/resultentry-westone-030925/9/Re_px.php +++ b/application/controllers/mockup/process/resultentry-westone-030925/9/Re_px.php @@ -1,2467 +1,2464 @@ -db_smartone = $this->load->database("onedev", true); - $this->load->helper(array('form', 'url')); - } - function getMethodeID($natTestID) { - $sql = "select M_MethodePriorityNat_MethodeID MethodeID, Nat_MethodeName - from - m_methode_priority - join nat_methode on Nat_MethodeID = M_MethodePriorityNat_MethodeID - and Nat_MethodeIsActive = 'Y' - join m_instrumentmethode on M_InstrumentMethodeNat_MethodeID = Nat_MethodeID and M_InstrumentMethodeIsActive = 'Y' - join nat_instrument on M_InstrumentMethodeNat_InstrumentID = Nat_InstrumentID - and Nat_InstrumentIsActive ='Y' - where M_MethodePriorityIsActive = 'Y' - and M_MethodePriorityNat_TestID = $natTestID - and M_MethodePriorityM_DayOfWeekID = dayofweek(now()) - order by M_MethodePriorityNumber desc - limit 0,1 "; - $qry = $this->db->query($sql); - if ($qry) { - $rows = $qry->result_array(); - if (count($rows) > 0 ) return array($rows[0]["MethodeID"],$rows[0]["Nat_MethodeName"]); - } - //2nd - $sql= "select - M_InstrumentMethodeNat_MethodeID MethodeID, Nat_MethodeName - from m_instrumentmethode - join nat_methode on M_InstrumentMethodeNat_MethodeID = Nat_MethodeID - and Nat_MethodeIsActive = 'Y' - join nat_instrument on M_InstrumentMethodeNat_InstrumentID = Nat_InstrumentID - and Nat_InstrumentIsActive ='Y' - where M_InstrumentMethodeNat_TestID = $natTestID - and M_InstrumentMethodeIsActive = 'Y' - order by M_InstrumentMethodePriority desc - limit 0,1"; - $qry = $this->db->query($sql); - if ($qry) { - $rows = $qry->result_array(); - if (count($rows) > 0 ) return array($rows[0]["MethodeID"],$rows[0]["Nat_MethodeName"]); - } - // - $sql = "select Nat_NormalValueNat_MethodeID MethodeID, Nat_MethodeName - from - nat_normalvalue - join nat_methode on Nat_NormalValueNat_MethodeID = Nat_MethodeID - and Nat_MethodeIsActive = 'Y' - where Nat_NormalValueNat_TestID = $natTestID - and Nat_NormalValueIsActive = 'Y' - order by Nat_NormalValueID - limit 0,1"; - $qry = $this->db->query($sql); - if ($qry) { - $rows = $qry->result_array(); - if (count($rows) > 0 ) return array($rows[0]["MethodeID"],$rows[0]["Nat_MethodeName"]); - } - return array(0,""); - } - function get_normal_value($methodeID, $natTestID, $sexID, $ageInDay ) { - $sql = "select fn_sampling_get_normal($methodeID, $natTestID, $sexID, $ageInDay) as normalValueID"; - $qry = $this->db->query($sql); - if ($qry) { - $rows = $qry->result_array(); - if (count($rows) > 0 ) return $rows[0]["normalValueID"]; - } - return 0; - } - function fn_fix_normal($order_id) { - $sql = "select - T_OrderDetailID, M_PatientM_SexID, fn_global_age_count_day(M_PatientDOB, date(T_OrderHeaderDate)) Dob , - T_TestNat_TestID - from t_orderheader - join m_patient on T_OrderHeaderID = $order_id and T_OrderHeaderM_PatientID = M_PatientID - join t_orderdetail on T_OrderDetailT_OrderHeaderID = T_OrderHeaderID - and T_OrderDetailIsACtive = 'Y' - and ( T_OrderDetailNat_NormalValueID is null or T_OrderDetailNat_NormalValueID = 0 ) - join t_test on T_OrderDetailT_TestID = T_TestID and T_TestIsResult = 'Y' "; - $qry = $this->db->query($sql); - if(! $qry) { - return; - } - $rows = $qry->result_array(); - if(count($rows) == 0 ) return; - $sql_u = "update t_orderdetail - join nat_normalvalue on T_OrderDetailID = ? and Nat_NormalValueID = ? - set - T_OrderDetailNat_NormalValueID = Nat_NormalValueID, - T_OrderDetailNormalValueNote = Nat_NormalValueNote, - T_OrderDetailNormalValueDescription = Nat_NormalValueDescription, - T_OrderDetailMinValue = Nat_NormalValueMinValue, - T_OrderDetailMaxValue = Nat_NormalValueMaxValue, - T_OrderDetailMinValueInclusive = Nat_NormalValueMinValueInclusive, - T_OrderDetailMaxValueInclusive = Nat_NormalValueMaxValueInclusive, - T_OrderDetailNat_MethodeID = ?, - T_OrderdetailNat_MethodeName =?"; - - foreach($rows as $r) { - $T_OrderDetailID = $r["T_OrderDetailID"]; - $sexID = $r["M_PatientM_SexID"]; - $ageInDay = $r["Dob"]; - $natTestID = $r["T_TestNat_TestID"]; - list($methodeID,$methodeName) = $this->getMethodeID($natTestID); - if ($methodeID == 0 ) continue; - $normalValueID = $this->get_normal_value($methodeID, $natTestID, $sexID, $ageInDay); - if ($normalValueID == 0) return; - $this->db->query($sql_u, array($T_OrderDetailID, $normalValueID, $methodeID, $methodeName)); - } - } - function update_order_sample($targetID, $sourceID) { - $sql = "update t_ordersample target - join t_ordersample source on - target.T_OrderSampleID = ? - and target.T_OrderSampleWorklistReceive = 'N' - and source.T_OrderSampleID = ? - set - target.T_OrderSampleSampling = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSampling, source.T_OrderSampleSampling), - target.T_OrderSampleSamplingDate = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingDate, source.T_OrderSampleSamplingDate), - target.T_OrderSampleSamplingTime = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingTime, source.T_OrderSampleSamplingTime), - target.T_OrderSampleSamplingUserID = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingUserID, source.T_OrderSampleSamplingUserID), - - target.T_OrderSampleReceive = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceive, source.T_OrderSampleReceive), - target.T_OrderSampleReceiveDate = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveDate, source.T_OrderSampleReceiveDate), - target.T_OrderSampleReceiveTime = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveTime, source.T_OrderSampleReceiveTime), - target.T_OrderSampleReceiveUserID = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveUserID, source.T_OrderSampleReceiveUserID), - - target.T_OrderSampleVerification = if(target.T_OrderSampleVerification='Y',target.T_OrderSampleVerification, source.T_OrderSampleVerification), - target.T_OrderSampleVerificationDate =if(target.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationDate, source.T_OrderSampleVerificationDate), - target.T_OrderSampleVerificationTime =if(source.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationTime, source.T_OrderSampleVerificationTime), - target.T_OrderSampleVerificationUserID =if(source.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationUserID, source.T_OrderSampleVerificationUserID), - - target.T_OrderSampleProcessing = if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessing, source.T_OrderSampleProcessing), - target.T_OrderSampleProcessingDate= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingDate, source.T_OrderSampleProcessingDate), - target.T_OrderSampleProcessingTime= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingTime, source.T_OrderSampleProcessingTime), - target.T_OrderSampleProcessingUserID= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingUserID, source.T_OrderSampleProcessingUserID), - - target.T_OrderSampleReceiveHandling =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandling, source.T_OrderSampleReceiveHandling ), - target.T_OrderSampleReceiveHandlingDate =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingDate, source.T_OrderSampleReceiveHandlingDate), - target.T_OrderSampleReceiveHandlingTime =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingTime, source.T_OrderSampleReceiveHandlingTime), - target.T_OrderSampleReceiveHandlingUserID =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingUserID, source.T_OrderSampleReceiveHandlingUserID), - - target.T_OrderSampleHandling = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandling, source.T_OrderSampleHandling), - target.T_OrderSampleHandlingDate = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingDate, source.T_OrderSampleHandlingDate), - target.T_OrderSampleHandlingTime = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingTime, source.T_OrderSampleHandlingTime), - target.T_OrderSampleHandlingUserID = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingUserID, source.T_OrderSampleHandlingUserID), - - target.T_OrderSampleWorklistReceive = source.T_OrderSampleWorklistReceive, - target.T_OrderSampleWorklistReceiveDatetime = source.T_OrderSampleWorklistReceiveDateTime, - target.T_OrderSampleWorklistReceiveUserID = source.T_OrderSampleWorklistReceiveUserID - "; - $qry = $this->db->query($sql,array($targetID,$sourceID)); - if(! $qry ) { - echo json_encode(array( "status" => "ERR" , "message" => print_r($this->db->error(),true))); - exit; - } - } - function fix_sample_serum($headerID) { - //cari t_ordersample yg belum worklist receive dengan code 017% - $sql = "select T_OrderSampleID - from t_ordersample - join t_sampletype on - T_OrderSampleT_OrderHeaderID = ? - and T_OrderSampleWorklistReceive = 'N' - and T_OrderSampleIsActive = 'Y' - and T_OrderSampleT_SampleTypeID = T_SampletypeID - and T_SampleTypeCode like '017%' - "; - $qry = $this->db->query($sql, array($headerID)); - if(!$qry) { - echo json_encode(array( "status" => "ERR" , "message" => print_r($this->db->error(),true))); - exit; - } - $rows = $qry->result_array(); - if (count($rows) == 0 ) return; - //cari T_OrderSample yang sudah di receive yg terakhir - $sql = "select T_OrderSampleID - from t_ordersample - join t_sampletype on - T_OrderSampleT_OrderHeaderID = ? - and T_OrderSampleWorklistReceive = 'Y' - and T_OrderSampleIsActive = 'Y' - and T_OrderSampleT_SampleTypeID = T_SampletypeID - and T_SampleTypeCode like '017%' - order by T_OrderSampleWorklistReceiveDatetime desc - limit 0,1 - "; - $qry = $this->db->query($sql, array($headerID)); - if(!$qry) { - echo json_encode(array( "status" => "ERR" , "message" => print_r($this->db->error(),true))); - exit; - } - $rcv_rows = $qry->result_array(); - if (count($rcv_rows) == 0 ) return; - - //print_r($rows); - //print_r($rcv_rows); - $rcv_T_OrderSampleID = $rcv_rows[0]["T_OrderSampleID"]; - //ada yg belum di receive - foreach($rows as $r) { - $T_OrderSampleID = $r["T_OrderSampleID"]; - $this->update_order_sample($T_OrderSampleID,$rcv_T_OrderSampleID); - } - } - public function search() - { - $prm = $this->sys_input; - $max_rst = 99; - - $id = $prm["order_id"]; - if ($id > 0 ) { - $this->fix_sample_serum($id); - $this->fn_fix_normal($id); - } - $lang = $this->lang_default_code; - $lang_id = isset($prm['lang_id']) ? $prm['lang_id'] : '0'; - - if ($lang_id != 0) - { - $l = $this->db_smartone->where("Nat_LangID", $lang_id)->get("nat_lang")->row(); - $lang = $l->Nat_LangCode; - } - - //tambahan fajri - $sql = " UPDATE t_orderdetail - JOIN t_test ON T_OrderDetailT_TestID = T_TestID - SET T_OrderDetailT_TestIsResult = T_TestIsResult - WHERE - T_OrderDetailT_OrderHeaderID = {$id} AND - T_OrderDetailT_TestIsResult = '' AND - T_OrderDetailIsActive = 'Y'"; - $this->db_smartone->query($sql); - - $tot_count = 0; - $lq = ""; - $group_id = 0; - if (isset($prm['group_id'])) - $group_id = $prm['group_id']; - - if ($group_id != 0) - { - $sql = "select distinct T_WorklistDetailNat_TestID Nat_TestID - from t_worklistdetailv2 - where T_WorklistDetailT_WorklistID = {$group_id}"; - $qry = $this->db_smartone->query($sql); - $rows = $qry->result_array(); - $nat_test_ids = "0"; - foreach($rows as $r) { - $nat_test_ids .= ", " . $r["Nat_TestID"]; - } - $q_group = " ( $nat_test_ids ) "; - - $sql = " - SELECT a1.*, cOUNT(a2.T_OrderDetailID) level - FROM ( - SELECT IFNULL(y.T_OrderDetailT_TestID, x.T_OrderDetailT_TestID) t_testid, - IFNULL(y.T_OrderDetailT_TestName, y.T_OrderDetailT_TestName) t_testname, - y.T_OrderDetailResult result, y.T_OrderDetailResult result_old, y.T_OrderDetailNote note, y.T_OrderDetailNote note_old, - y.T_OrderDetailID id, - y.T_OrderDetailT_TestIsResult is_result, a.T_TestIsQuantitative is_quantitative, - y.T_OrderDetailResultFlag result_flag, - y.T_OrderDetailNat_NormalValueID normal_id, - y.T_OrderDetailNormalValueNote normal_note, y.T_OrderDetailNat_UnitName unit_name, - y.T_OrderdetailNat_MethodeID methode_id, y.T_OrderdetailNat_MethodeName methode_name, - a.T_TestNat_TestID nattest_id, a.T_TestID tx_id, count(T_ResultInstrumentID) as result_instrument_n, - y.T_OrderDetailVerification, T_OrderSampleReceive sample_receive, - T_OrderSampleProcessing sample_processing, T_OrderSampleWorklistReceive sample_worklist_receive, - IF(T_OrderDetailAddOnPreAnalytic = 'Y', T_OrderDetailAddOnPreAnalytic, PreAnalyticIsOk) pre_analytic, - T_OrderDetailAddOnPreAnalytic, - T_OrderHeaderID order_id, y.T_OrderDetailT_TestSasCode test_sas_code, - tx.T_TestSasCode, - T_OrderDetailAddOnResample `resample`, T_OrderDetailAddOnResampleStatus resample_status, - T_OrderDetailAddOnRef ref, y.T_OrderDetailVerification verification, y.T_OrderDetailValidation validation, - T_OrderPromiseDateTime, Group_ResultName as ResultGroupName - FROM t_orderdetail x - left join t_orderpromise on x.T_OrderDetailT_OrderPromiseID = T_OrderPromiseID - JOIN t_test tx ON x.T_OrderDetailT_TestID = T_TestID - JOIN t_test tcheck on tcheck.T_TestNat_TestID in {$q_group} - and ( tx.T_TestID = tcheck.T_TestID or tx.T_TestSasCode like concat(tcheck.T_TestSasCode,'%')) - LEFT JOIN group_resultdetail ON Group_ResultDetailT_TestID = x.T_OrderDetailT_TestID AND Group_ResultDetailIsActive = 'Y' - LEFT JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND Group_ResultFlagNonLab = 'N' - LEFT JOIN t_orderdetail y ON x.T_OrderDetailT_TestSasCode LIKE CONCAT(y.T_OrderDetailT_TestSasCode, '%') - AND x.T_OrderDetailT_OrderHeaderID = y.T_OrderDetailT_OrderHeaderID - AND y.T_OrderDetailIsActive = 'Y' - LEFT JOIN t_orderdetailaddon ON x.T_OrderDetailID = T_OrderDetailAddOnT_OrderDetailID - JOIN t_orderheader ON y.T_OrderDetailT_OrderHeaderID = T_OrderHeaderID - LEFT JOIN t_test a ON y.T_OrderDetailT_TestID = a.T_TestID - AND a.T_TestIsNonLab = '' - LEFT JOIN (SELECT T_OrderSampleT_SampleTypeID, T_OrderSampleReceive, T_OrderSampleProcessing, T_OrderSampleWorklistReceive - FROM t_ordersample WHERE T_OrderSampleT_OrderHeaderID = {$id} - AND T_OrderSampleIsactive = 'Y' - GROUP BY T_OrderSampleT_SampleTypeID) os ON a.T_TestT_SampleTypeID = os.T_OrderSampleT_SampleTypeID - or os.T_OrderSampleT_SampleTypeID = fn_sampletype_from_local(a.T_TestNat_TestID) - - LEFT JOIN t_resultinstrument ON T_ResultInstrumentT_OrderDetailID = x.T_OrderDetailID - LEFT JOIN pre_analytic ON PreAnalyticNat_TestID = a.T_TestNat_TestID AND PreAnalyticDate = date(now()) and PreAnalyticIsActive = 'Y' - WHERE x.T_OrderDetailT_OrderHeaderID = {$id} - AND x.T_OrderDetailIsActive = 'Y' - GROUP BY y.T_OrderDetailT_TestID - ORDER BY y.T_OrderDetailT_TestSasCode ASC - ) a1 - - LEFT JOIN t_orderdetail a2 ON a2.T_OrderDetailT_OrderHeaderID = a1.order_id - AND a2.T_OrderDetailIsActive = 'Y' - AND a1.test_sas_code LIKE CONCAT(a2.T_OrderDetailT_testSasCode, '%') - GROUP BY a1.t_testid - order by a1.test_sas_code -"; - $query = $this->db_smartone->query($sql); - $lq = $this->db_smartone->last_query(); - } - else - { - $sql = " - SELECT a1.*, cOUNT(a2.T_OrderDetailID) level - FROM ( - SELECT IFNULL(y.T_OrderDetailT_TestID, x.T_OrderDetailT_TestID) t_testid, - IFNULL(y.T_OrderDetailT_TestName, y.T_OrderDetailT_TestName) t_testname, - y.T_OrderDetailResult result, y.T_OrderDetailResult result_old, y.T_OrderDetailNote note, y.T_OrderDetailNote note_old, - y.T_OrderDetailID id, - y.T_OrderDetailT_TestIsResult is_result, a.T_TestIsQuantitative is_quantitative, - y.T_OrderDetailResultFlag result_flag, - y.T_OrderDetailNat_NormalValueID normal_id, - y.T_OrderDetailNormalValueNote normal_note, y.T_OrderDetailNat_UnitName unit_name, - y.T_OrderdetailNat_MethodeID methode_id, y.T_OrderdetailNat_MethodeName methode_name, - a.T_TestNat_TestID nattest_id, a.T_TestID tx_id, count(T_ResultInstrumentID) as result_instrument_n, - y.T_OrderDetailVerification, T_OrderSampleReceive sample_receive, - T_OrderSampleProcessing sample_processing, T_OrderSampleWorklistReceive sample_worklist_receive, - IF(T_OrderDetailAddOnPreAnalytic = 'Y', T_OrderDetailAddOnPreAnalytic, PreAnalyticIsOk) pre_analytic, - T_OrderDetailAddOnPreAnalytic, - T_OrderHeaderID order_id, y.T_OrderDetailT_TestSasCode test_sas_code, - tx.T_TestSasCode, - T_OrderDetailAddOnResample `resample`, T_OrderDetailAddOnResampleStatus resample_status, - T_OrderDetailAddOnRef ref, y.T_OrderDetailVerification verification, y.T_OrderDetailValidation validation, - T_OrderPromiseDateTime , Group_ResultName as ResultGroupName - FROM t_orderdetail x - left join t_orderpromise on x.T_OrderDetailT_OrderPromiseID = T_OrderPromiseID - JOIN t_test tx ON x.T_OrderDetailT_TestID = T_TestID - LEFT JOIN group_resultdetail ON Group_ResultDetailT_TestID = x.T_OrderDetailT_TestID AND Group_ResultDetailIsActive = 'Y' - LEFT JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND Group_ResultFlagNonLab = 'N' - LEFT JOIN t_orderdetail y ON x.T_OrderDetailT_TestSasCode LIKE CONCAT(y.T_OrderDetailT_TestSasCode, '%') - AND x.T_OrderDetailT_OrderHeaderID = y.T_OrderDetailT_OrderHeaderID - AND y.T_OrderDetailIsActive = 'Y' - - LEFT JOIN t_orderdetailaddon ON x.T_OrderDetailID = T_OrderDetailAddOnT_OrderDetailID - - JOIN t_orderheader ON y.T_OrderDetailT_OrderHeaderID = T_OrderHeaderID - LEFT JOIN t_test a ON y.T_OrderDetailT_TestID = a.T_TestID - AND a.T_TestIsNonLab = '' - LEFT JOIN (SELECT T_OrderSampleT_SampleTypeID, T_OrderSampleReceive, T_OrderSampleProcessing, T_OrderSampleWorklistReceive - FROM t_ordersample WHERE T_OrderSampleT_OrderHeaderID = {$id} - AND T_OrderSampleIsactive = 'Y' - GROUP BY T_OrderSampleT_SampleTypeID) os ON a.T_TestT_SampleTypeID = os.T_OrderSampleT_SampleTypeID - or os.T_OrderSampleT_SampleTypeID = fn_sampletype_from_local(a.T_TestNat_TestID) - - LEFT JOIN t_resultinstrument ON T_ResultInstrumentT_OrderDetailID = x.T_OrderDetailID - LEFT JOIN pre_analytic ON PreAnalyticNat_TestID = a.T_TestNat_TestID AND PreAnalyticDate = date(now()) and PreAnalyticIsActive = 'Y' - WHERE x.T_OrderDetailT_OrderHeaderID = {$id} - AND x.T_OrderDetailIsActive = 'Y' - GROUP BY y.T_OrderDetailT_TestID - ORDER BY y.T_OrderDetailT_TestSasCode ASC - ) a1 - - LEFT JOIN t_orderdetail a2 ON a2.T_OrderDetailT_OrderHeaderID = a1.order_id - AND a2.T_OrderDetailIsActive = 'Y' - AND a1.test_sas_code LIKE CONCAT(a2.T_OrderDetailT_testSasCode, '%') - GROUP BY a1.t_testid - order by a1.test_sas_code -"; -//echo $sql; - $query = $this->db_smartone->query($sql); - $lq = $this->db_smartone->last_query(); - } - // file_put_contents("/xtmp/re-query.sql",$lq); - - if ($query) { - $rst = []; - $rows = $query->result_array(); - - foreach($rows as $k => $v) - { - - if ($v['is_result'] == "Y" && $v['is_quantitative'] == "N") - { - $v['template'] = []; - $x = $this->db_smartone->query("CALL sp_master_resulttemplate_get('{$v['t_testid']}')"); - $this->clean_mysqli_connection($this->db_smartone->conn_id); - if ($x) - $v['template'] = $x->result_array(); - } - - // IF Rujukan, by pas Pre Analytik - if ($v['ref'] == 'Y') - $v['pre_analytic'] = 'Y'; - if ($v["id"] == "885455" ) - { - //sipe workaround - //$v["sample_receive"] = "Y"; - $v["sample_worklist_receive"] = "Y"; - } - $rst[] = $v; - } - - $result = array("total" => $tot_count, "records" => $rst, "total_display" => sizeof($rows), "q" => $lq); - $this->sys_ok($result); - } - else { - $this->sys_error_db("RE Px rows", $this->db_smartone); - exit; - } - } - - public function save() - { - $prm = $this->sys_input; - $data = json_decode($prm["data"]); - $lang = $this->lang_default_code; - $lang_id = isset($prm['lang_id']) ? $prm['lang_id'] : '0'; - - if ($lang_id != 0) - { - $l = $this->db_smartone->where("Nat_LangID", $lang_id)->get("nat_lang")->row(); - $lang = $l->Nat_LangCode; - } - - $sql_norm = "select T_OrderDetailMinValue, T_OrderDetailMaxValue, - T_OrderDetailMinValueInclusive, T_OrderDetailMaxValueInclusive, - Nat_TestFlagLow, Nat_TestFlagHigh - from t_orderdetail - join t_test on T_OrderDetailT_TestID = T_TestID - join nat_test on T_TestNat_TestID = Nat_TestID and T_TestIsActive = 'Y' - where T_OrderDetailID = ? "; - - $ids = []; - foreach ($data as $k => $v) - { - if ( $v->resultInstrumentID > 0 ) { - $sql_i = "select T_ResultInstrumentNat_NormalValueID normalValueID - from t_resultinstrument - where T_ResultInstrumentID = ?"; - $qry_i = $this->db_smartone->query($sql_i, array($v->resultInstrumentID)); - if ($qry_i) { - $rows_i = $qry_i->result_array(); - - if (count($rows_i) > 0 ) { - $sql_iu = "update t_orderdetail, nat_normalvalue , nat_methode - set T_OrderDetailMinValue = Nat_NormalValueMinValue, - T_OrderDetailMinValueInclusive = Nat_NormalValueMinValueInclusive, - T_OrderDetailMaxValue = Nat_NormalValueMaxValue , - T_OrderDetailMaxValueInclusive = Nat_NormalValueMaxValueInclusive, - T_OrderDetailNormalValueNote = Nat_NormalValueNote, - T_OrderDetailNormalValueDescription = Nat_NormalValueDescription, - T_OrderDetailNat_NormalValueID = Nat_NormalValueID, - T_OrderDetailNat_MethodeID = Nat_NormalValueNat_MethodeID, - T_OrderDetailNat_MethodeName = Nat_MethodeName - where T_OrderDetailID = ? and Nat_NormalValueID = ? - and Nat_NormalValueNat_MethodeID = Nat_MethodeID - "; - $this->db_smartone->query($sql_iu, array($v->id, $rows_i[0]["normalValueID"])); - //file_put_contents("/xtmp/update-nilai-normal", $this->db_smartone->last_query() . "\n", FILE_APPEND); - } - } - } - $y = $this->db_smartone->query("SELECT fn_process_sample_handling_perfect('{$v->order_id}', '{$v->test_id}') c") - ->row(); - $req_status = $y->c; - $qry_norm = $this->db_smartone->query($sql_norm,$v->id); - $result_flag = ""; - if ($qry_norm) { - $rows_norm = $qry_norm->result_array(); - if (count($rows_norm) > 0 ) { - $r = $rows_norm[0]; - if (is_numeric($v->result)) { - - if ( $r["T_OrderDetailMinValueInclusive"] == "Y" && $v->result < $r["T_OrderDetailMinValue"] ) { - $result_flag = $r["Nat_TestFlagLow"]; - } - if ( $r["T_OrderDetailMinValueInclusive"] == "N" && $v->result <= $r["T_OrderDetailMinValue"] ) { - $result_flag = $r["Nat_TestFlagLow"]; - } - if ( $r["T_OrderDetailMaxValueInclusive"] == "Y" && $v->result > $r["T_OrderDetailMaxValue"] ) { - $result_flag = $r["Nat_TestFlagHigh"]; - } - if ( $r["T_OrderDetailMaxValueInclusive"] == "N" && $v->result >= $r["T_OrderDetailMaxValue"] ) { - $result_flag = $r["Nat_TestFlagHigh"]; - } - } - } - } - if ($lang == $this->lang_default_code) - { - $this->db_smartone->set('T_OrderDetailResult', $v->result) - ->set('T_OrderDetailResultFlag', $result_flag) - ->set('T_OrderDetailNote', $v->note) - ->set('T_OrderDetailReqStatus', $req_status) - ->where('T_OrderDetailID', $v->id) - ->update('t_orderdetail'); - } - else - { - $this->db_smartone->set('T_OrderDetailLangResult', $v->result) - ->set('T_OrderDetailLangNote', $v->note) - ->where('T_OrderDetailLangID', $v->id) - ->update('t_orderdetaillang'); - } - - $ids[] = $v->id; - } - - // LOG Process - $order = $this->db_smartone->select('T_OrderDetailT_OrderHeaderID id, T_OrderHeaderLabNumber lab_number', false) - ->join('t_orderheader', 'T_OrderHeaderID = T_OrderDetailT_OrderHeaderID') - ->where('T_OrderDetailID', $data[0]->id) - ->get('t_orderdetail') - ->row(); - - $dblog = $this->load->database("onelog", true); - $dblog->set('Log_ProcessCode', 'PROCESS.Result.Entry') - ->set('Log_ProcessOrderID', $order->id) - ->set('Log_ProcessOrderNumber', $order->lab_number) - ->set('Log_ProcessJson', json_encode($data)) - ->set('Log_ProcessUserID', $this->sys_user['M_UserID']) - ->insert('log_process'); - // END OF Log Process - //auto calculation - $this->load->library("Resultcalc"); - $rows = $this->resultcalc->auto($order->id); - - try { - foreach($ids as $id ) { - $this->db_smartone->query("call sp_set_normal_value_flag($id)"); - $this->clean_mysqli_connection($this->db_smartone->conn_id); - } - } catch(Exception $e) { - } - - $this->sys_ok($ids); - } - - public function save_template() - { - $prm = $this->sys_input; - - $n = $this->db_smartone->select("COUNT(T_ResultTemplateID) n") - ->where("T_ResultTemplateT_TestID", $prm['test_id']) - ->where("T_ResultTemplateIsActive", "Y") - ->where("T_ResultTemplateValue", $prm['value']) - ->get('t_resulttemplate') - ->row(); - if ($n->n > 0) - { - $this->sys_error_db("Insert Result Template", $this->db_smartone); - return; - } - - $r = $this->db_smartone->set("T_ResultTemplateT_TestID", $prm['test_id']) - ->set("T_ResultTemplateValue", $prm['value']) - ->insert('t_resulttemplate'); - if ($r) - { - $template = []; - $x = $this->db_smartone->query("CALL sp_master_resulttemplate_get('{$prm['test_id']}')"); - $this->clean_mysqli_connection($this->db_smartone->conn_id); - if ($x) - $template = $x->result_array(); - - $this->sys_ok($template); - } - } - - public function export() - { - $prm = $this->sys_input; - - $sql = "CALL sp_process_result_lang(?, ?, ?, ?)"; - $query = $this->db_smartone->query($sql, [$prm['order_id'], $prm['lang_id'], $prm['is_si'], $this->sys_user['M_UserID']]); - if ($query) - { - $r = $query->row(); - if ($r->status == "OK") - { - $this->sys_ok($r->data); - return; - } - - $this->sys_error_db("Message : " . $r->message, $this->db_smartone); - } - else - { - $this->sys_error_db("Lang Result", $this->db_smartone); - return; - } - } - - public function search_group() - { - $prm = $this->sys_input; - $max_rst = 100; - - // QUERY TOTAL - $sql = "select count(*) total - from t_worklist - where T_WorklistIsActive = 'Y' - order by T_WorklistName ASC"; - $query = $this->db_smartone->query($sql); - - if ($query) { - $tot_count = $query->result_array()[0]["total"]; - } - else { - $this->sys_error_db("worklist count", $this->db_smartone); - exit; - } - - $sql = "select T_WorklistID group_id, T_WorklistName group_name - from t_worklist - where T_WorklistIsActive = 'Y' - order by T_WorklistName ASC - limit 0, {$max_rst}"; - $query = $this->db_smartone->query($sql); - - if ($query) { - $rows = $query->result_array(); - foreach ($rows as $k => $v) - $rows[$k]['data'] = json_decode($v['data']); - $result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows), "q" => $this->db_smartone->last_query()); - $this->sys_ok($result); - } - else { - $this->sys_error_db("worklist rows", $this->db_smartone); - exit; - } - } - - public function search_rerun() - { - $prm = $this->sys_input; - $id = $prm["detail_id"]; - - $sql = "CALL sp_process_result_rerun(?)"; - $query = $this->db_smartone->query($sql, [$id]); - - if ($query) - { - $rows = $query->result_array(); - $this->sys_ok(["records"=>$rows]); - } - else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - - - function getdoctorsfna() - { - $prm = $this->sys_input; - // $id = $prm["id"]; - - $sql = " SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY M_DoctorName ASC"; - //echo $sql; - $query = $this->db_smartone->query($sql); - - if ($query) - { - $rows = $query->result_array(); - $this->sys_ok(["records"=>$rows]); - } - else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - function getfnaresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT Other_FNADetailsID as xid, - Other_FNAT_OrderDetailID as orderdetail_id, - Other_FNADetailsCode as code, - Other_FNADetailsLabel as label, - Other_FNADetailsResult as result, - IFNULL(Other_FNAM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_FNAM_DoctorID) OR Other_FNAM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_fna - JOIN other_fnadetails ON Other_FNADetailsOther_FNAID = Other_FNAID AND Other_FNADetailsIsActive = 'Y' - LEFT JOIN m_doctor ON Other_FNAM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_FNAT_OrderDetailID = {$id} AND Other_FNAIsActive = 'Y' - GROUP BY Other_FNADetailsID - ORDER BY Other_FNADetailsCode ASC"; - $query = $this->db_smartone->query($sql); - - if ($query) - { - $rows = $query->result_array(); - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $images = array(); - $sql = "SELECT So_ImageUploadID as xid, - CONCAT('/one-media/one-image-nonlab/',So_ImageUploadNewName) as image_url - FROM t_orderdetail - JOIN so_imageupload ON So_ImageUploadT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND - So_ImageUploadIsActive = 'Y' - WHERE - T_OrderDetailID = {$id} AND - T_OrderDetailIsActive = 'Y' - GROUP BY So_ImageUploadID"; - $images = $this->db_smartone->query($sql)->result_array(); - - $rst = array('doctors'=>$doctors,'results'=>$rows,'images'=>$images); - $this->sys_ok(["records"=>$rst]); - } - else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - - function uploadimage(){ - if (! $this->isLogin) { - $this->sys_error("Invalid Token"); - exit; - } - - $userid = $this->sys_user["M_UserID"]; - $data = []; - //print_r($_SERVER); - - $prm = $this->sys_input; - $orderid = $this->input->post('orderid'); - $labnumber = $this->input->post('labnumber'); - $sql = "UPDATE so_imageupload SET - So_ImageUploadIsActive = 'N', - So_ImageUploadUserID = {$userid} - WHERE - So_ImageUploadT_OrderHeaderID = {$orderid}"; - //echo $sql; - $this->db_onedev->query($sql); - //$config['upload_path'] = 'assets/'; - - $path = '/home/one/project/one/one-media/one-image-nonlab/'; - //echo $path; - $config['upload_path'] = $path; - $config['allowed_types'] = 'jpg|jpeg|png|gif'; - - $config['max_size'] = '10000'; - $count = count($_FILES['files']['name']); - //echo $count; - $this->load->library('upload',$config); - - $error = []; - for($i=0;$i<$count;$i++){ - - - if(!empty($_FILES['files']['name'][$i])){ - - - - $_FILES['file']['name'] = $_FILES['files']['name'][$i]; - - $_FILES['file']['type'] = $_FILES['files']['type'][$i]; - - $_FILES['file']['tmp_name'] = $_FILES['files']['tmp_name'][$i]; - - $_FILES['file']['error'] = $_FILES['files']['error'][$i]; - - $_FILES['file']['size'] = $_FILES['files']['size'][$i]; - - - - $namex = $orderid.'-'.$labnumber.'-'.$this->generateRandomString(5); - //echo $namex; - - $config['file_name'] = $namex; - $this->upload->initialize($config); - //echo $config['file_name'] ; - - - - - - if($this->upload->do_upload('file')){ - - $uploadData = $this->upload->data(); - - $filename = $uploadData['file_name']; - //echo $filename; - - - $sql = "INSERT INTO so_imageupload ( - So_ImageUploadT_OrderHeaderID, - So_ImageUploadT_OrderHeaderLabNumber, - So_ImageUploadT_SampleTypeID, - So_ImageUploadOldName, - So_ImageUploadNewName, - So_ImageUploadCreated, - So_ImageUploadUserID - ) - VALUES( - {$orderid}, - '{$labnumber}', - '150', - '{$_FILES['files']['name'][$i]}', - '{$filename}', - NOW(), - {$userid} - - )"; - //echo $sql; - $this->db_onedev->query($sql); - $xlast_id = $this->db_onedev->insert_id(); - $data['totalFiles'][] = array('xid' => $xlast_id ,'image_url' => '/one-media/one-image-nonlab/'.$filename); - - } - else{ - $error = array('error' => $this->upload->display_errors()); - } - - } - - - - } - - $result = array("total" =>count( $data['totalFiles']), "records" => $data['totalFiles'],'errors'=>$error); - $this->sys_ok($result); - } - - - function generateRandomString($length = 10) { - $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; - $charactersLength = strlen($characters); - $randomString = ''; - for ($i = 0; $i < $length; $i++) { - $randomString .= $characters[rand(0, $charactersLength - 1)]; - } - return $randomString; - } - - function getcytologiresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT Other_CytologiDetailsID as xid, - Other_CytologiT_OrderDetailID as orderdetail_id, - Other_CytologiDetailsCode as code, - Other_CytologiDetailsLabel as label, - Other_CytologiDetailsResult as result, - IFNULL(Other_CytologiM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_CytologiM_DoctorID) OR Other_CytologiM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_cytologi - JOIN other_cytologidetails ON Other_CytologiDetailsOther_CytologiID = Other_CytologiID AND Other_CytologiDetailsIsActive = 'Y' - LEFT JOIN m_doctor ON Other_CytologiM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_CytologiT_OrderDetailID = {$id} AND Other_CytologiIsActive = 'Y' - GROUP BY Other_CytologiDetailsID - ORDER BY Other_CytologiDetailsCode ASC"; - //echo $sql; - $query = $this->db_smartone->query($sql); - - if ($query) - { - $rows = $query->result_array(); - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $rst = array('doctors'=>$doctors,'results'=>$rows); - $this->sys_ok(["records"=>$rst]); - } - else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - function getmikroresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT - Other_MikroID as xid, - Other_MikroHasilBiakan as hasil_biakan, - Other_MikroSampleTypeName as sample_name, - Other_MikroT_OrderDetailID as orderdetail_id, - Other_MikroResult as result_value, - '' as result_other, - IFNULL(T_BacteriaID,0) as T_BacteriaID, - IFNULL(T_BacteriaName,'') as T_BacteriaName, - '' as details, - IFNULL(Other_MikroM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_MikroM_DoctorID) OR Other_MikroM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_mikro - LEFT JOIN t_bacteria ON Other_MikroT_BacteriaID = T_BacteriaID - LEFT JOIN m_doctor ON Other_MikroM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_MikroT_OrderDetailID = {$id} AND Other_MikroIsActive = 'Y' - GROUP BY Other_MikroID"; - //echo $sql; - $query = $this->db_smartone->query($sql); - - if ($query) - { - $row = $query->row_array(); - if($row){ - if($row['result_value'] != 'Positif' && $row['result_value'] != 'Negatif'){ - $row['result_other'] = $row['result_value']; - $row['result_value'] = 'other'; - } - $sql = "SELECT '' as xno, - Other_MikroDetailsID as xid, - Other_MikroDetailsValue as value, - IF(Other_MikroDetailsNote = 'R','Y','N') as chx_r, - IF(Other_MikroDetailsNote = 'I','Y','N') as chx_i, - IF(Other_MikroDetailsNote = 'S','Y','N') as chx_s, - Other_MikroDetailsNote as note, - t_antibiotic.* - FROM other_mikrodetails - LEFT JOIN t_antibiotic ON Other_MikroDetailsT_AntibioticID = T_AntibioticID - WHERE - Other_MikroDetailsOther_MikroID = {$row['xid']} AND Other_MikroDetailsIsActive = 'Y' - GROUP BY Other_MikroDetailsID - ORDER BY T_AntibioticName ASC"; - //echo $sql; - $details = $this->db_smartone->query($sql)->result_array(); - if(details){ - foreach($details as $k => $v){ - $details[$k]['xno'] = $k + 1; - } - } - $row['details'] = $details; - } - else{ - $row = array('xid'=>'0','hasil_biakan' => '','result_value'=>'Negatif','sample_name' => '','orderdetail_id'=>$id, 'T_BacteriaID'=>'0','T_BacteriaName'=>'0','details'=>array(),'doctor_id'=>'0','doctor_name'=>'0'); - } - } - else{ - $row = array('xid'=>'0','hasil_biakan' => '','result_value'=>'Negatif','sample_name' => '','orderdetail_id'=>$id, 'T_BacteriaID'=>'0','T_BacteriaName'=>'0','details'=>array(),'doctor_id'=>'0','doctor_name'=>'0'); - } - //print_r($row); - - - - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 7 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $sql = " - SELECT '0' as id, 'Belum memilih bakteria' as name - UNION - SELECT T_BacteriaID as id, T_BacteriaName as name - FROM t_bacteria - WHERE - T_BacteriaIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $bacteries = $this->db_smartone->query($sql)->result_array(); - $rst = array('doctors'=>$doctors,'bacteries'=>$bacteries,'results'=>$row); - $this->sys_ok(["records"=>$rst]); - } - function getantibiotics(){ - $prm = $this->sys_input; - $id = $prm["id"]; - $sql = " SELECT '' as xno, - 0 as xid, - '' as hasil_biakan, - '' as sample_name, - 0 as value, - 'Y' as chx_r, - 'N' as chx_i, - 'N' as chx_s, - 'R' as note, - t_antibiotic.* - FROM t_antibiotic - WHERE - T_AntibioticT_BacteriaID = {$prm['id']} AND T_AntibioticIsActive= 'Y' - ORDER BY T_AntibioticName ASC"; - //echo $sql; - $rows = $this->db_smartone->query($sql)->result_array(); - if(rows){ - foreach($rows as $k => $v){ - $rows[$k]['xno'] = $k + 1; - } - } - - $this->sys_ok(["records"=>$rows]); - } - function getlcprepresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - $sql = " SELECT Other_LcprepDetailsID as xid, - Other_LcprepID as header_id, - Other_LcprepT_orderDetailID as orderdetail_id, - Other_LcprepDetailsCode as code, - Other_LcprepDetailsLabel as label, - Other_LcprepDetailsResult as result, - IFNULL(Other_LcprepM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_LcprepM_DoctorID) OR Other_LcprepM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_lcprep - JOIN other_lcprepdetails ON Other_LcprepDetailsOther_LcprepID = Other_LcprepID AND Other_LcprepDetailsIsActive = 'Y' - LEFT JOIN m_doctor ON Other_LcprepM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_LcprepT_orderDetailID = {$id} AND Other_LcprepIsActive = 'Y' - GROUP BY Other_LcprepDetailsOther_LcprepID, Other_LcprepDetailsCode - ORDER BY Other_LcprepDetailsCode ASC"; - //echo $sql; - $rows = $this->db_smartone->query($sql)->result_array(); - if(!$rows){ - $rows = array( - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'A', - 'label' => 'DESKRIPSI', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ), - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'B', - 'label' => 'KESIMPULAN', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ) - ); - } - - $header_id = $rows[0]['header_id']; - $sql = "SELECT IFNULL(Other_LcprepAdekuasiID,0) as xid, - Lcprep_AdekuasiID as id, - Lcprep_AdekuasiLabel as name, - IF(ISNULL(Other_LcprepAdekuasiID),'N',Other_LcprepAdekuasiChex) as chex - FROM lcprep_adekuasi - LEFT JOIN other_lcprepadekuasi ON Other_LcprepAdekuasiLcprep_AdekuasiID = Lcprep_AdekuasiID AND - Other_LcprepAdekuasiOther_LcprepID = {$header_id} AND - Other_LcprepAdekuasiIsActive = 'Y' - WHERE - Lcprep_AdekuasiIsActive = 'Y' - GROUP BY Lcprep_AdekuasiID - ORDER BY Lcprep_AdekuasiOrder ASC - "; - //echo $sql; - $adeakuasi = $this->db_smartone->query($sql)->result_array(); - foreach($adeakuasi as $kc => $vc){ - $adeakuasi[$kc]['chex'] = $vc['chex'] == 'N'?false:true; - } - - $sql = "SELECT IFNULL(Other_LcprepKategoriUmumID,0) as xid, - Lcprep_KategoriUmumID as id, - Lcprep_KategoriUmumLabel as name, - IF(ISNULL(Other_LcprepKategoriUmumID),'N',Other_LcprepKategoriUmumChex) as chex - FROM lcprep_kategoriumum - LEFT JOIN other_lcprepkategoriumum ON Other_LcprepKategoriUmumLcprep_KategoriUmumID = Lcprep_KategoriUmumID AND - Other_LcprepKategoriUmumOther_LcprepID = {$header_id} AND - Other_LcprepKategoriUmumIsActive = 'Y' - WHERE - Lcprep_KategoriUmumIsActive = 'Y' - GROUP BY Lcprep_KategoriUmumID - "; - //echo $sql; - $kategoriumum = $this->db_smartone->query($sql)->result_array(); - foreach($kategoriumum as $kc => $vc){ - $kategoriumum[$kc]['chex'] = $vc['chex'] == 'N'?false:true; - } - - $sql = " - SELECT Lcprep_InterpretasiGroupID as group_id, - Lcprep_InterpretasiGroupName as group_name, - '' as subgroups - FROM lcprep_interpretasigroup - WHERE - Lcprep_InterpretasiGroupIsActive = 'Y' - "; - //echo $sql; - $interpretasi = $this->db_smartone->query($sql)->result_array(); - foreach($interpretasi as $k => $v){ - $subgroups = array(); - $sql = "SELECT Lcprep_InterpretasiSubgroupID as subgroup_id, - Lcprep_InterpretasiSubgroupName as subgroup_name, - '' as childs - FROM lcprep_interpretasisubgroup - WHERE - Lcprep_InterpretasiSubgroupLcprep_InterpretasiGroupID = {$v['group_id']} AND Lcprep_InterpretasiSubgroupIsActive = 'Y'"; - //echo $sql; - $subgroups = $this->db_smartone->query($sql)->result_array(); - if(count($subgroups) > 0){ - foreach($subgroups as $ki => $vi){ - $childs = array(); - $sql = "SELECT IFNULL(Other_LcprepInterpretasiID,0) as xid, - IFNULL(Other_LcprepInterpretasiChex,'N') as chex, - IFNULL(Other_LcprepInterpretasiValue,'') as value, - Lcprep_InterpretasiID as id, - Lcprep_InterpretasiLcprep_InterpretasiSubgroupID as subgroup_id, - Lcprep_InterpretasiCode as code, - Lcprep_InterpretasiName as name, - Lcprep_InterpretasiParentID as parent_id, - Lcprep_InterpretasiIsParent as is_parent, - Lcprep_InterpretasiHasResult as has_result, - Lcprep_InterpretasiTypeResult as type_result - FROM lcprep_interpretasi - LEFT JOIN other_lcprepinterpretasi ON Other_LcprepInterpretasiOther_LcprepID = {$header_id} AND - Other_LcprepInterpretasiLcprep_InterpretasiID = Lcprep_InterpretasiID AND - Other_LcprepInterpretasiIsActive = 'Y' - WHERE - Lcprep_InterpretasiLcprep_InterpretasiSubgroupID = {$vi['subgroup_id']} AND Lcprep_InterpretasiIsActive = 'Y' - GROUP BY Lcprep_InterpretasiID Order BY Lcprep_InterpretasiCode ASC"; - $childs = $this->db_smartone->query($sql)->result_array(); - if($childs){ - foreach($childs as $kc => $vc){ - $childs[$kc]['chex'] = $vc['chex'] == 'N'?false:true; - } - } - $subgroups[$ki]['childs'] = $childs; - } - } - - $interpretasi[$k]['subgroups'] = $subgroups; - } - - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $rst = array('doctors'=>$doctors,'results'=>$rows,'adekuasi'=>$adeakuasi,'kategoriumum'=>$kategoriumum,'interpretasi'=>$interpretasi); - $this->sys_ok(["records"=>$rst]); - } - - function getpapsmearresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT Other_PapSmearDetailsID as xid, - Other_PapSmearID as header_id, - Other_PapSmearT_OrderDetailID as orderdetail_id, - Other_PapSmearDetailsCode as code, - Other_PapSmearDetailsLabel as label, - Other_PapSmearDetailsResult as result, - IFNULL(Other_PapSmearM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_PapSmearM_DoctorID) OR Other_PapSmearM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_papsmear - JOIN other_papsmeardetails ON Other_PapSmearDetailsOther_PapSmearID = Other_PapSmearID AND Other_PapSmearDetailsIsActive = 'Y' - LEFT JOIN m_doctor ON Other_PapSmearM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_PapSmearT_OrderDetailID = {$id} AND Other_PapSmearIsActive = 'Y' - GROUP BY Other_PapSmearDetailsID - ORDER BY Other_PapSmearDetailsCode ASC"; - //echo $sql; - $rows = $this->db_smartone->query($sql)->result_array(); - if(!$rows){ - $rows = array( - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'A', - 'label' => 'Makroskopik', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ), - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'B', - 'label' => 'Mikroskopik', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ), - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'C', - 'label' => 'Kesimpulan', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ) - ); - } - - $header_id = $rows[0]['header_id']; - $sql = "SELECT Other_PapSmearMaturasiID as xid, - Other_PapSmearMaturasiValue as value - FROM other_papsmearmaturasi - WHERE - Other_PapSmearMaturasiOther_PapSmearID = {$header_id} AND - Other_PapSmearMaturasiIsActive = 'Y' - "; - //echo $sql; - $dt_maturasi = $this->db_smartone->query($sql)->row_array(); - if(!$dt_maturasi){ - $maturasi = array('xid'=>'0','value'=> array('','','')); - } - else{ - $value = explode('/',$dt_maturasi['value']); - $maturasi = array('xid'=>$dt_maturasi['xid'],'value'=> $value); - } - - $sql = "SELECT IFNULL(Other_PapSmearBahanID,0) as xid, - M_PapSmearBahanID as bahan_id, - M_PapSmearBahanName as name, - IF(ISNULL(Other_PapSmearBahanID),'N','Y') as selected - FROM m_papsmearbahan - LEFT JOIN other_papsmearbahan ON Other_PapSmearBahanM_PapSmearBahanID = M_PapSmearBahanID AND - Other_PapSmearBahanOther_PapSmearID = {$header_id} AND - Other_PapSmearBahanIsActive = 'Y' - WHERE - M_PapSmearBahanIsActive = 'Y' - ORDER BY M_PapSmearBahanID ASC - "; - //echo $sql; - $bahans = $this->db_smartone->query($sql)->result_array(); - - $sql = "SELECT IFNULL(Other_PapsmearCategoryID,0) as xid, - M_PapSmearCategoryID as category_id, - M_PapSmearCategoryName as name, - IF(ISNULL(Other_PapsmearCategoryID),'N','Y') as selected - FROM m_papsmearcategory - LEFT JOIN other_papsmearcategory ON Other_PapsmearCategoryM_PapSmearCategoryID = M_PapSmearCategoryID AND - Other_PapsmearCategoryOther_PapSmearID = {$header_id} AND - Other_PapsmearCategoryIsActive = 'Y' - WHERE - M_PapSmearCategoryIsActive = 'Y' - ORDER BY M_PapSmearCategoryID ASC - "; - //echo $sql; - $categories = $this->db_smartone->query($sql)->result_array(); - - $sql = "SELECT IFNULL(Other_PapSmearCheckID,0) as xid, - M_PapSmearCheckID as check_id, - M_PapSmearCheckLabel as name, - IF(ISNULL(Other_PapSmearCheckID),'N','Y') as selected, - Other_PapSmearCheckNote as note - FROM m_papsmearcheck - LEFT JOIN other_papsmearcheck ON Other_PapSmearCheckM_PapSmearCheckID = M_PapSmearCheckID AND - Other_PapSmearCheckOther_PapSmearID = {$header_id} AND - Other_PapSmearCheckIsActive = 'Y' - WHERE - M_PapSmearCheckIsActive = 'Y' - ORDER BY M_PapSmearCheckCode ASC - "; - $checks = $this->db_smartone->query($sql)->result_array(); - - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $rst = array('doctors'=>$doctors,'checks'=>$checks,'bahans'=>$bahans,'categories'=>$categories,'maturasi'=>$maturasi,'results'=>$rows); - $this->sys_ok(["records"=>$rst]); - - } - - function saveresult_lcprep() - { - $prm = $this->sys_input; - $detail_id = $prm['detail_id']; - $doctor_id = $prm['doctor']; - $adekuasi = $prm['adekuasi']; - $kategoriumum = $prm['kategoriumum']; - $interpretasi = $prm['interpretasi']; - $results = $prm['results']; - - $userid = $this->sys_user['M_UserID']; - - $header_id = 0; - $sql = "SELECT * FROM other_lcprep WHERE Other_LcprepT_orderDetailID = {$detail_id} AND Other_LcprepIsActive = 'Y'"; - $dt_header = $this->db_smartone->query($sql)->row_array(); - if($dt_header){ - $header_id = $dt_header['Other_LcprepID']; - } - if($header_id == 0){ - $sql = "INSERT INTO other_lcprep( - Other_LcprepT_orderDetailID, - Other_LcprepM_DoctorID, - Other_LcprepUserID, - Other_LcprepCreated - ) - VALUES( - {$detail_id}, - {$doctor_id}, - {$userid}, - NOW() - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - }else{ - $sql = "UPDATE other_lcprep SET Other_LcprepM_DoctorID = {$doctor_id}, Other_LcprepUserID = {$userid} WHERE Other_LcprepID = {$header_id}"; - $this->db_smartone->query($sql); - } - - if($adekuasi){ - foreach($adekuasi as $k =>$v){ - $selected = $v['chex']?'Y':'N'; - if(intval($v['xid'] == 0)){ - $sql = "UPDATE other_lcprepadekuasi SET Other_LcprepAdekuasiIsActive = 'N' - WHERE - Other_LcprepAdekuasiOther_LcprepID = {$header_id} AND - Other_LcprepAdekuasiIsActive = 'Y' AND - Other_LcprepAdekuasiLcprep_AdekuasiID = {$v['id']}"; - $this->db_smartone->query($sql); - $sql = "INSERT INTO other_lcprepadekuasi ( - Other_LcprepAdekuasiOther_LcprepID, - Other_LcprepAdekuasiLcprep_AdekuasiID, - Other_LcprepAdekuasiChex, - Other_LcprepAdekuasiUserID, - Other_LcprepAdekuasiCreated - ) - VALUES( - {$header_id}, - {$v['id']}, - '{$selected}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - //echo $sql; - } - if(intval($v['xid'] != 0)){ - - $sql = "UPDATE other_lcprepadekuasi SET - Other_LcprepAdekuasiChex = '{$selected}', - Other_LcprepAdekuasiUserID = {$userid} - WHERE - Other_LcprepAdekuasiID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - - //echo $sql; - } - } - - if($kategoriumum){ - foreach($kategoriumum as $k =>$v){ - $selected = $v['chex']?'Y':'N'; - if(intval($v['xid'] == 0)){ - $sql = "UPDATE other_lcprepkategoriumum SET Other_LcprepKategoriUmumIsActive = 'N' - WHERE - Other_LcprepKategoriUmumOther_LcprepID = {$header_id} AND - Other_LcprepKategoriUmumLcprep_KategoriUmumID = {$v['id']} AND - Other_LcprepKategoriUmumIsActive = 'Y' - "; - $this->db_smartone->query($sql); - $sql = "INSERT INTO other_lcprepkategoriumum ( - Other_LcprepKategoriUmumOther_LcprepID, - Other_LcprepKategoriUmumLcprep_KategoriUmumID, - Other_LcprepKategoriUmumChex, - Other_LcprepKategoriUmumUserID, - Other_LcprepKategoriUmumCreated - ) - VALUES( - {$header_id}, - {$v['id']}, - '{$selected}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if(intval($v['xid'] != 0)){ - $sql = "UPDATE other_lcprepkategoriumum SET - Other_LcprepKategoriUmumChex = '{$selected }', - Other_LcprepKategoriUmumUserID = {$userid} - WHERE - Other_LcprepKategoriUmumID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - - //echo $sql; - } - } - - if($results){ - foreach($results as $k =>$v){ - if(intval($v['xid'] == 0)){ - $sql = "UPDATE other_lcprepdetails SET Other_LcprepDetailsIsActive = 'N' - WHERE - Other_LcprepDetailsOther_LcprepID = {$header_id} AND - Other_LcprepDetailsCode = '{$v['code']}' AND - Other_LcprepDetailsIsActive = 'Y'"; - $this->db_smartone->query($sql); - $sql = "INSERT INTO other_lcprepdetails ( - Other_LcprepDetailsOther_LcprepID, - Other_LcprepDetailsCode, - Other_LcprepDetailsLabel, - Other_LcprepDetailsResult, - Other_LcprepDetailsUserID, - Other_LcprepDetailsCreated - ) - VALUES( - {$header_id}, - '{$v['code']}', - '{$v['label']}', - '{$v['result']}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if(intval($v['xid'] != 0)){ - $sql = "UPDATE other_lcprepdetails SET - Other_LcprepDetailsCode = '{$v['code']}', - Other_LcprepDetailsLabel = '{$v['label']}', - Other_LcprepDetailsResult = '{$v['result']}', - Other_LcprepDetailsUserID = {$userid} - WHERE - Other_LcprepDetailsID = {$v['xid']}"; - $this->db_smartone->query($sql); - - } - //echo $sql; - } - } - - if($interpretasi){ - foreach($interpretasi as $k =>$v){ - if(count($v['subgroups']) > 0){ - foreach($v['subgroups'] as $ik => $iv){ - if(count($iv['childs']) > 0){ - foreach($iv['childs'] as $iik => $iiv){ - if(intval($iiv['xid'] == 0)){ - $chex = $iiv['chex'] ? 'Y':'N'; - $sql = "UPDATE other_lcprepinterpretasi SET Other_LcprepInterpretasiIsActive = 'N' - WHERE - Other_LcprepInterpretasiOther_LcprepID = {$header_id} AND - Other_LcprepInterpretasiLcprep_InterpretasiID = '{$iiv['id']}' AND - Other_LcprepInterpretasiIsActive = 'Y'"; - $this->db_smartone->query($sql); - $sql = "INSERT INTO other_lcprepinterpretasi ( - Other_LcprepInterpretasiOther_LcprepID, - Other_LcprepInterpretasiLcprep_InterpretasiID, - Other_LcprepInterpretasiChex, - Other_LcprepInterpretasiValue, - Other_LcprepInterpretasiUserID, - Other_LcprepInterpretasiCreated - ) - VALUES( - {$header_id}, - '{$iiv['id']}', - '{$chex}', - '{$iiv['value']}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - - if(intval($iiv['xid'] != 0)){ - $chex = $iiv['chex'] ? 'Y':'N'; - $sql = "UPDATE other_lcprepinterpretasi SET - Other_LcprepInterpretasiChex = '{$chex}', - Other_LcprepInterpretasiValue = '{$iiv['value']}', - Other_LcprepInterpretasiUserID = {$userid} - WHERE - Other_LcprepInterpretasiID = {$iiv['xid']}"; - $this->db_smartone->query($sql); - //echo $sql; - - } - - } - } - } - } - //echo $sql; - } - } - - - $result = array("total" => 1, "records" => array(), "sql"=> ''); - $this->sys_ok($result); - exit; - } - - function saveresult_papsmear() - { - $prm = $this->sys_input; - $detail_id = $prm['detail_id']; - $doctor_id = $prm['doctor']; - $checks = $prm['checks']; - $maturasi = $prm['maturasi']; - $bahans = $prm['bahans']; - $categories = $prm['categories']; - $results = $prm['results']; - - $userid = $this->sys_user['M_UserID']; - - $header_id = 0; - $sql = "SELECT * FROM other_papsmear WHERE Other_PapSmearT_OrderDetailID = {$detail_id} AND Other_PapSmearIsActive = 'Y'"; - $dt_header = $this->db_smartone->query($sql)->row_array(); - if($dt_header){ - $header_id = $dt_header['Other_PapSmearID']; - } - if($header_id == 0){ - $sql = "INSERT INTO other_papsmear( - Other_PapSmearT_OrderDetailID, - Other_PapSmearM_DoctorID, - Other_PapSmearUserID, - Other_PapSmearCreated - ) - VALUES( - {$detail_id}, - {$doctor_id}, - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } - else{ - $sql = "UPDATE other_papsmear SET Other_PapSmearM_DoctorID = {$doctor_id}, Other_PapSmearUserID = {$userid} WHERE Other_PapSmearID = {$header_id}"; - $this->db_smartone->query($sql); - } - - if($checks){ - foreach($checks as $k =>$v){ - if(intval($v['xid']) == 0 && $v['selected'] === 'Y'){ - $sql = "INSERT INTO other_papsmearcheck ( - Other_PapSmearCheckOther_PapSmearID, - Other_PapSmearCheckM_PapSmearCheckID, - Other_PapSmearCheckNote, - Other_PapSmearCheckUserID, - Other_PapSmearCheckCreated - ) - VALUES( - {$header_id}, - {$v['check_id']}, - '{$v['note']}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if(intval($v['xid']) != 0 && $v['selected'] === 'N'){ - $sql = "UPDATE other_papsmearcheck SET - Other_PapSmearCheckIsActive = 'N', - Other_PapSmearCheckUserID = {$userid} - WHERE - Other_PapSmearCheckID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - if(intval($v['xid']) != 0 && $v['selected'] === 'Y'){ - $sql = "UPDATE other_papsmearcheck SET - Other_PapSmearCheckNote = '{$v['note']}', - Other_PapSmearCheckUserID = {$userid} - WHERE - Other_PapSmearCheckID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - //echo $sql; - } - } - - if($maturasi){ - if(intval($maturasi['xid']) == 0){ - $value = join("/",$maturasi['value']); - $sql = "INSERT INTO other_papsmearmaturasi ( - Other_PapSmearMaturasiOther_PapSmearID, - Other_PapSmearMaturasiValue, - Other_PapSmearMaturasiUserID, - Other_PapSmearMaturasiCreated - ) - VALUE( - {$header_id}, - '{$value}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - //echo $sql; - } - if(intval($maturasi['xid']) != 0){ - $value = join("/",$maturasi['value']); - $sql = "UPDATE other_papsmearmaturasi SET - Other_PapSmearMaturasiValue = '{$value}', - Other_PapSmearMaturasiUserID = {$userid} - WHERE - Other_PapSmearMaturasiID = {$maturasi['xid']}"; - // echo $sql; - $this->db_smartone->query($sql); - } - } - - if($bahans){ - foreach($bahans as $k =>$v){ - if(intval($v['xid']) == 0 && $v['selected'] === 'Y'){ - $sql = "INSERT INTO other_papsmearbahan ( - Other_PapSmearBahanOther_PapSmearID, - Other_PapSmearBahanM_PapSmearBahanID, - Other_PapSmearBahanUserID, - Other_PapSmearBahanCreated - ) - VALUES( - {$header_id}, - {$v['bahan_id']}, - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if(intval($v['xid']) != 0 && $v['selected'] === 'N'){ - $sql = "UPDATE other_papsmearbahan SET - Other_PapSmearBahanIsActive = 'N', - Other_PapsmearCategoryUserID = {$userid} - WHERE - Other_PapSmearBahanID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - if(intval($v['xid']) != 0 && $v['selected'] === 'Y'){ - $sql = "UPDATE other_papsmearbahan SET - Other_PapSmearBahanIsActive = 'Y', - Other_PapsmearCategoryUserID = {$userid} - WHERE - Other_PapSmearBahanID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - //echo $sql; - } - } - - if($categories){ - foreach($categories as $k =>$v){ - if(intval($v['xid']) == 0 && $v['selected'] === 'Y'){ - $sql = "INSERT INTO other_papsmearcategory ( - Other_PapsmearCategoryOther_PapSmearID, - Other_PapsmearCategoryM_PapSmearCategoryID, - Other_PapsmearCategoryUserID, - Other_PapsmearCategoryCreated - ) - VALUES( - {$header_id}, - {$v['category_id']}, - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if(intval($v['xid']) != 0 && $v['selected'] === 'N'){ - $sql = "UPDATE other_papsmearcategory SET - Other_PapsmearCategoryIsActive = 'N', - Other_PapsmearCategoryUserID = {$userid} - WHERE - Other_PapsmearCategoryID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - //echo $sql; - if(intval($v['xid']) != 0 && $v['selected'] === 'Y'){ - $sql = "UPDATE other_papsmearcategory SET - Other_PapsmearCategoryIsActive = 'Y', - Other_PapsmearCategoryUserID = {$userid} - WHERE - Other_PapsmearCategoryID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - } - } - - if($results){ - foreach($results as $k =>$v){ - if(intval($v['xid']) == 0){ - $sql = "INSERT INTO other_papsmeardetails ( - Other_PapSmearDetailsOther_PapSmearID, - Other_PapSmearDetailsCode, - Other_PapSmearDetailsLabel, - Other_PapSmearDetailsResult, - Other_PapSmearDetailsUserID, - Other_PapSmearDetailsCreated - ) - VALUES( - {$header_id}, - '{$v['code']}', - '{$v['label']}', - '{$v['result']}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if(intval($v['xid']) != 0){ - $sql = "UPDATE other_papsmeardetails SET - Other_PapSmearDetailsCode = '{$v['code']}', - Other_PapSmearDetailsLabel = '{$v['label']}', - Other_PapSmearDetailsResult = '{$v['result']}', - Other_PapSmearDetailsUserID = {$userid} - WHERE - Other_PapSmearDetailsID = {$v['xid']}"; - $this->db_smartone->query($sql); - - } - //echo $sql; - } - } - - $result = array("total" => 1, "records" => array(), "sql"=> ''); - $this->sys_ok($result); - exit; - } - - function saveresult_fna() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = $inp['doctor']; - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - if($prm[0]['xid'] == '0'){ - $sql = "INSERT INTO other_fna( - Other_FNAM_DoctorID, - Other_FNAT_OrderDetailID, - Other_FNAUserID, - Other_FNACreated - ) - VALUES( - {$doctor_id}, - {$prm[0]['orderdetail_id']}, - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } - else{ - $sql = "SELECT * FROM other_fna WHERE Other_FNAT_OrderDetailID = {$prm[0]['orderdetail_id']} AND Other_FNAIsActive = 'Y'"; - $data_header = $this->db_smartone->query($sql)->row_array(); - $header_id = $data_header['Other_FNAID']; - $sql = "UPDATE other_fna SET - Other_FNAM_DoctorID = {$doctor_id}, - Other_FNAUserID = {$userid} - WHERE - Other_FNAID = {$header_id}"; - $this->db_smartone->query($sql); - } - foreach($prm as $k => $v){ - if($v['xid'] == '0'){ - $results = str_replace("'", "\\'", $v['result']); - $sql = "INSERT INTO other_fnadetails( - Other_FNADetailsOther_FNAID , - Other_FNADetailsCode, - Other_FNADetailsLabel, - Other_FNADetailsResult, - Other_FNADetailsCreated, - Other_FNADetailsUserID - ) - VALUES( - {$header_id}, - '{$v['code']}', - '{$v['label']}', - '{$results}', - NOW(), - {$userid} - )"; - $query = $this->db_smartone->query($sql); - } - else{ - $results = str_replace("'", "\\'", $v['result']); - $sql = "UPDATE other_fnadetails SET - Other_FNADetailsResult = '{$results}', - Other_FNADetailsUserID = {$userid} - WHERE - Other_FNADetailsID = {$v['xid']}"; - $query = $this->db_smartone->query($sql); - } - } - - $result = array("total" => 1, "records" => array(), "sql"=> ''); - $this->sys_ok($result); - exit; - } - - function saveresult_cytologi() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = $inp['doctor']; - - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - if($prm[0]['xid'] == '0'){ - $sql = "INSERT INTO other_cytologi( - Other_CytologiT_OrderDetailID, - Other_CytologiM_DoctorID, - Other_CytologiUserID, - Other_CytologiCreated - ) - VALUES( - {$prm[0]['orderdetail_id']}, - {$doctor_id}, - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } - else{ - $sql = "SELECT * FROM other_cytologi WHERE Other_CytologiT_OrderDetailID = {$prm[0]['orderdetail_id']} AND Other_CytologiIsActive = 'Y'"; - $data_header = $this->db_smartone->query($sql)->row_array(); - $header_id = $data_header['Other_CytologiID']; - $sql = "UPDATE other_cytologi SET - Other_CytologiM_DoctorID = {$doctor_id}, - Other_CytologiUserID = {$userid} - WHERE - Other_CytologiID = {$header_id}"; - $this->db_smartone->query($sql); - } - foreach($prm as $k => $v){ - if($v['xid'] == '0'){ - $results = str_replace("'", "\\'", $v['result']); - $sql = "INSERT INTO other_cytologidetails( - Other_CytologiDetailsOther_CytologiID , - Other_CytologiDetailsCode, - Other_CytologiDetailsLabel, - Other_CytologiDetailsResult, - Other_CytologiDetailsCreated, - Other_CytologiDetailsUserID - ) - VALUES( - {$header_id}, - '{$v['code']}', - '{$v['label']}', - '{$results}', - NOW(), - {$userid} - )"; - $query = $this->db_smartone->query($sql); - } - else{ - $results = str_replace("'", "\\'", $v['result']); - $sql = "UPDATE other_cytologidetails SET - Other_CytologiDetailsResult = '{$results}', - Other_CytologiDetailsUserID = {$userid} - WHERE - Other_CytologiDetailsID = {$v['xid']}"; - $query = $this->db_smartone->query($sql); - } - } - - $result = array("total" => 1, "records" => array(), "sql"=> ''); - $this->sys_ok($result); - exit; - } - - function saveresult_mikro() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = $inp['doctor']; - $backteria_id = $inp['bacteria']; - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - - if($inp['result_value'] != 'Negatif' && $inp['result_value'] != 'Positif'){ - $prm['result_value'] = $prm['result_other']; - } - else{ - $prm['result_value'] = $inp['result_value']; - } - - if($prm['xid'] == '0'){ - $sql = "INSERT INTO other_mikro( - Other_MikroM_DoctorID, - Other_MikroResult, - Other_MikroT_BacteriaID, - Other_MikroT_OrderDetailID, - Other_MikroHasilBiakan, - Other_MikroSampleTypeName, - Other_MikroUserID, - Other_MikroCreated - ) - VALUES( - {$doctor_id}, - '{$prm['result_value']}', - {$backteria_id}, - {$prm['orderdetail_id']}, - '{$prm['hasil_biakan']}', - '{$prm['sample_name']}', - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } - else{ - $sql = "SELECT * FROM other_mikro WHERE Other_MikroT_OrderDetailID = {$prm['orderdetail_id']} AND Other_MikroIsActive = 'Y'"; - $data_header = $this->db_smartone->query($sql)->row_array(); - $header_id = $data_header['Other_MikroID']; - $sql = "UPDATE other_mikro SET - Other_MikroResult = '{$prm['result_value']}', - Other_MikroM_DoctorID = {$doctor_id}, - Other_MikroT_BacteriaID = {$backteria_id}, - Other_MikroHasilBiakan = '{$prm['hasil_biakan']}', - Other_MikroSampleTypeName = '{$prm['sample_name']}', - Other_MikroUserID = {$userid} - WHERE - Other_MikroID = {$header_id}"; - //echo $sql; - $this->db_smartone->query($sql); - } - - - - $sql = "UPDATE other_mikrodetails SET Other_MikroDetailsIsActive = 'N', Other_MikroDetailsUserID = 0 WHERE Other_MikroDetailsOther_MikroID = {$header_id}"; - $this->db_smartone->query($sql); - - $results = $prm['details']; - if($inp['result_value'] == 'Positif'){ - foreach($results as $k => $v){ - if($v['xid'] == '0'){ - $sql = "INSERT INTO other_mikrodetails( - Other_MikroDetailsOther_MikroID , - Other_MikroDetailsT_AntibioticID, - Other_MikroDetailsValue, - Other_MikroDetailsNote, - Other_MikroDetailsCreated, - Other_MikroDetailsUserID - ) - VALUES( - {$header_id}, - '{$v['T_AntibioticID']}', - '{$v['value']}', - '{$v['note']}', - NOW(), - {$userid} - )"; - $query = $this->db_smartone->query($sql); - } - else{ - $sql = "UPDATE other_mikrodetails SET - Other_MikroDetailsT_AntibioticID = '{$v['T_AntibioticID']}', - Other_MikroDetailsValue = '{$v['value']}', - Other_MikroDetailsNote = '{$v['note']}', - Other_MikroDetailsIsActive = 'Y', - Other_MikroDetailsUserID = {$userid} - WHERE - Other_MikroDetailsID = {$v['xid']}"; - //echo $sql; - $query = $this->db_smartone->query($sql); - } - } - } - - - $result = array("total" => 1, "records" => array(), "sql"=> ''); - $this->sys_ok($result); - exit; - } - - - function get_doctors_preparasi_sperma() - { - $prm = $this->sys_input; - // $id = $prm["id"]; - - $sql = " SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 10 AND - M_DoctorSOIsActive = 'Y' - ORDER BY M_DoctorName ASC"; - //echo $sql; - $query = $this->db_smartone->query($sql); - - if ($query) - { - $rows = $query->result_array(); - $this->sys_ok(["records"=>$rows]); - } - else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - - function getpreparasispermaresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT other_preparasisperma.*, - Other_PreparasiSpermaID as xid, - Other_PreparasiSpermaT_OrderDetailID as orderdetail_id, - IFNULL(Other_PreparasiSpermaM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_PreparasiSpermaM_DoctorID) OR Other_PreparasiSpermaM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_preparasisperma - LEFT JOIN m_doctor ON Other_PreparasiSpermaM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_PreparasiSpermaT_OrderDetailID = {$id} AND Other_PreparasiSpermaIsActive = 'Y' - GROUP BY Other_PreparasiSpermaID"; - $query = $this->db_smartone->query($sql); - - if ($query) - { - $rows = $query->row_array(); - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 10 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $images = array(); - $sql = "SELECT Other_PreparasiSpermaImgID as xid, - Other_PreparasiSpermaImgType as type, - CONCAT('/one-media/one-image-nonlab/',Other_PreparasiSpermaImgNewName) as image_url - FROM t_orderdetail - JOIN other_preparasisperma_img ON Other_PreparasiSpermaImgT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND - Other_PreparasiSpermaImgIsActive = 'Y' - WHERE - T_OrderDetailID = {$id} AND - T_OrderDetailIsActive = 'Y' - GROUP BY Other_PreparasiSpermaImgID"; - //echo $sql; - $images = $this->db_smartone->query($sql)->result_array(); - - $rst = array('doctors'=>$doctors,'results'=>$rows,'images'=>$images); - $this->sys_ok(["records"=>$rst]); - } - else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - - function uploadimage_preparasi_sperma(){ - if (! $this->isLogin) { - $this->sys_error("Invalid Token"); - exit; - } - - $userid = $this->sys_user["M_UserID"]; - $data = []; - //print_r($_SERVER); - - $prm = $this->sys_input; - $orderid = $this->input->post('orderid'); - $type = $this->input->post('type'); - $labnumber = $this->input->post('labnumber'); - $sql = "UPDATE other_preparasisperma_img SET - Other_PreparasiSpermaImgIsActive = 'N', - Other_PreparasiSpermaImgUserID = {$userid} - WHERE - Other_PreparasiSpermaImgT_OrderHeaderID = {$orderid} AND - Other_PreparasiSpermaImgType = '{$type}'"; - //echo $sql; - $this->db_onedev->query($sql); - //$config['upload_path'] = 'assets/'; - - $path = '/home/one/project/one/one-media/one-image-nonlab/'; - //echo $path; - $config['upload_path'] = $path; - $config['allowed_types'] = 'jpg|jpeg|png|gif'; - - $config['max_size'] = '10000'; - $count = count($_FILES['files']['name']); - //echo $count; - $this->load->library('upload',$config); - - $error = []; - for($i=0;$i<$count;$i++){ - - - if(!empty($_FILES['files']['name'][$i])){ - - - - $_FILES['file']['name'] = $_FILES['files']['name'][$i]; - - $_FILES['file']['type'] = $_FILES['files']['type'][$i]; - - $_FILES['file']['tmp_name'] = $_FILES['files']['tmp_name'][$i]; - - $_FILES['file']['error'] = $_FILES['files']['error'][$i]; - - $_FILES['file']['size'] = $_FILES['files']['size'][$i]; - - - - $namex = $orderid.'-'.$labnumber.'-'.$this->generateRandomString(5); - //echo $namex; - - $config['file_name'] = $namex; - $this->upload->initialize($config); - //echo $config['file_name'] ; - - - - - - if($this->upload->do_upload('file')){ - - $uploadData = $this->upload->data(); - - $filename = $uploadData['file_name']; - //echo $filename; - - - $sql = "INSERT INTO other_preparasisperma_img ( - Other_PreparasiSpermaImgT_OrderHeaderID, - Other_PreparasiSpermaImgType, - Other_PreparasiSpermaImgOldName, - Other_PreparasiSpermaImgNewName, - Other_PreparasiSpermaImgCreated, - Other_PreparasiSpermaImgUserID - ) - VALUES( - {$orderid}, - '{$type}', - '{$_FILES['files']['name'][$i]}', - '{$filename}', - NOW(), - {$userid} - - )"; - //echo $sql; - $this->db_onedev->query($sql); - $xlast_id = $this->db_onedev->insert_id(); - $data['totalFiles'][] = array('xid' => $xlast_id ,'type'=>$type,'image_url' => '/one-media/one-image-nonlab/'.$filename); - - } - else{ - $error = array('error' => $this->upload->display_errors()); - } - - } - - - - } - - $result = array("total" =>count( $data['totalFiles']), "records" => $data['totalFiles'],'errors'=>$error); - $this->sys_ok($result); - } - - - function saveresult_preparasi_sperma() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = $inp['doctor']; - $orderdetail_id = $inp['orderdetailid']; - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - if($prm['xid'] == '0'){ - $sql = "INSERT INTO other_preparasisperma( - Other_PreparasiSpermaM_DoctorID, - Other_PreparasiSpermaT_OrderDetailID, - Other_PreparasiSpermaPreMotilitasA, - Other_PreparasiSpermaPreMotilitasB, - Other_PreparasiSpermaPreMotilitasC, - Other_PreparasiSpermaPreKonsentrasi, - Other_PreparasiSpermaPreKontaminan, - Other_PreparasiSpermaPostMotilitasA, - Other_PreparasiSpermaPostMotilitasB, - Other_PreparasiSpermaPostMotilitasC, - Other_PreparasiSpermaPostKonsentrasi, - Other_PreparasiSpermaPostKontaminan, - Other_PreparasiSpermaNote, - Other_PreparasiSpermaUserID, - Other_PreparasiSpermaCreated - ) - VALUES( - {$doctor_id}, - {$orderdetail_id}, - '{$prm['Other_PreparasiSpermaPreMotilitasA']}', - '{$prm['Other_PreparasiSpermaPreMotilitasB']}', - '{$prm['Other_PreparasiSpermaPreMotilitasC']}', - '{$prm['Other_PreparasiSpermaPreKonsentrasi']}', - '{$prm['Other_PreparasiSpermaPreKontaminan']}', - '{$prm['Other_PreparasiSpermaPostMotilitasA']}', - '{$prm['Other_PreparasiSpermaPostMotilitasB']}', - '{$prm['Other_PreparasiSpermaPostMotilitasC']}', - '{$prm['Other_PreparasiSpermaPostKonsentrasi']}', - '{$prm['Other_PreparasiSpermaPostKontaminan']}', - '{$prm['Other_PreparasiSpermaNote']}', - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } - else{ - $sql = "SELECT * FROM other_preparasisperma WHERE Other_PreparasiSpermaT_OrderDetailID = {$orderdetail_id} AND Other_PreparasiSpermaIsActive = 'Y'"; - $data_header = $this->db_smartone->query($sql)->row_array(); - $header_id = $data_header['Other_PreparasiSpermaID']; - $sql = "UPDATE other_preparasisperma SET - Other_PreparasiSpermaM_DoctorID = {$doctor_id}, - Other_PreparasiSpermaPreMotilitasA = '{$prm['Other_PreparasiSpermaPreMotilitasA']}', - Other_PreparasiSpermaPreMotilitasB = '{$prm['Other_PreparasiSpermaPreMotilitasB']}', - Other_PreparasiSpermaPreMotilitasC = '{$prm['Other_PreparasiSpermaPreMotilitasC']}', - Other_PreparasiSpermaPreKonsentrasi = '{$prm['Other_PreparasiSpermaPreKonsentrasi']}', - Other_PreparasiSpermaPreKontaminan = '{$prm['Other_PreparasiSpermaPreKontaminan']}', - Other_PreparasiSpermaPostMotilitasA = '{$prm['Other_PreparasiSpermaPostMotilitasA']}', - Other_PreparasiSpermaPostMotilitasB = '{$prm['Other_PreparasiSpermaPostMotilitasB']}', - Other_PreparasiSpermaPostMotilitasC = '{$prm['Other_PreparasiSpermaPostMotilitasC']}', - Other_PreparasiSpermaPostKonsentrasi = '{$prm['Other_PreparasiSpermaPostKonsentrasi']}', - Other_PreparasiSpermaPostKontaminan = '{$prm['Other_PreparasiSpermaPostKontaminan']}', - Other_PreparasiSpermaNote = '{$prm['Other_PreparasiSpermaNote']}', - Other_PreparasiSpermaUserID = {$userid} - WHERE - Other_PreparasiSpermaID = {$header_id}"; - $this->db_smartone->query($sql); - } - - - $result = array("total" => 1, "records" => array(), "sql"=> ''); - $this->sys_ok($result); - exit; - } - - function getdnafragmentasiresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT other_dnafragmentasi.*, - Other_DnaFragmentasiID as xid, - Other_DnaFragmentasiT_OrderDetailID as orderdetail_id, - IFNULL(Other_DnaFragmentasiM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_DnaFragmentasiM_DoctorID) OR Other_DnaFragmentasiM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name, - IFNULL(Other_DnaFragmentasiOther_DnaFragmentasiMethodeID,0) as methode_id, - IFNULL(Other_DnaFragmentasiMethodeName,'') as methode_name, - Other_DnaFragmentasiHaloLuas as halo_luas, - Other_DnaFragmentasiHaloSedang as halo_sedang, - Other_DnaFragmentasiHaloSempit as halo_sempit, - Other_DnaFragmentasiTanpaHalo as tanpa_halo, - Other_DnaFragmentasiDFI as dfi, - Other_DnaFragmentasiKesimpulan as kesimpulan, - Other_DnaFragmentasiCatatan as catatan - FROM other_dnafragmentasi - LEFT JOIN m_doctor ON Other_DnaFragmentasiM_DoctorID = M_DoctorID - LEFT JOIN other_dnafragmentasimethode ON Other_DnaFragmentasiOther_DnaFragmentasiMethodeID = Other_DnaFragmentasiMethodeID - WHERE - Other_DnaFragmentasiT_OrderDetailID = {$id} AND Other_DnaFragmentasiIsActive = 'Y' - GROUP BY Other_DnaFragmentasiID - LIMIT 1"; - //echo $sql; - $query = $this->db_smartone->query($sql); - - if ($query) - { - $rows = $query->row_array(); - if(!$rows){ - $rows = array( - 'xid' => 0, - 'orderdetail_id' =>$id, - 'doctor_id' => 0, - 'doctor_name' => '', - 'methode_id' => 0, - 'methode_name' => '', - 'halo_luas' => '', - 'halo_sedang' => '', - 'tanpa_halo' => '', - 'dfi' => '', - 'kesimpulan' => '', - 'catatan' => '' - ); - } - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID - WHERE - M_DoctorSONat_SubGroupID = 4 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - - $sql = " - SELECT '0' as id, 'Belum memilih metode' as name - UNION - SELECT Other_DnaFragmentasiMethodeID as id, Other_DnaFragmentasiMethodeName as name - FROM other_dnafragmentasimethode - WHERE - Other_DnaFragmentasiMethodeIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $methodes = $this->db_smartone->query($sql)->result_array(); - - - $rst = array('doctors'=>$doctors,'methodes'=>$methodes,'results'=>$rows); - $this->sys_ok(["records"=>$rst]); - } - else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - function saveresult_dnafragmentasi() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = $inp['doctor']['id']; - $methode_id = $inp['methode']['id']; - $orderdetail_id = $inp['results']['orderdetail_id']; - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - if(intval($prm['xid']) == 0){ - $sql = "INSERT INTO other_dnafragmentasi( - Other_DnaFragmentasiT_OrderDetailID, - Other_DnaFragmentasiM_DoctorID, - Other_DnaFragmentasiOther_DnaFragmentasiMethodeID, - Other_DnaFragmentasiHaloLuas, - Other_DnaFragmentasiHaloSedang, - Other_DnaFragmentasiHaloSempit, - Other_DnaFragmentasiTanpaHalo, - Other_DnaFragmentasiDFI, - Other_DnaFragmentasiKesimpulan, - Other_DnaFragmentasiCatatan, - Other_DnaFragmentasiUserID, - Other_DnaFragmentasiLastUpdated - ) - VALUES( - {$orderdetail_id}, - {$doctor_id}, - {$methode_id}, - '{$prm['halo_luas']}', - '{$prm['halo_sedang']}', - '{$prm['halo_sempit']}', - '{$prm['tanpa_halo']}', - '{$prm['dfi']}', - '{$prm['kesimpulan']}', - '{$prm['catatan']}', - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } - else{ - $sql = "UPDATE other_dnafragmentasi SET - Other_DnaFragmentasiT_OrderDetailID = {$orderdetail_id}, - Other_DnaFragmentasiM_DoctorID = {$doctor_id}, - Other_DnaFragmentasiOther_DnaFragmentasiMethodeID = '{$methode_id}', - Other_DnaFragmentasiHaloLuas = '{$prm['halo_luas']}', - Other_DnaFragmentasiHaloSedang = '{$prm['halo_sedang']}', - Other_DnaFragmentasiHaloSempit = '{$prm['halo_sempit']}', - Other_DnaFragmentasiTanpaHalo = '{$prm['tanpa_halo']}', - Other_DnaFragmentasiDFI = '{$prm['dfi']}', - Other_DnaFragmentasiKesimpulan = '{$prm['kesimpulan']}', - Other_DnaFragmentasiCatatan = '{$prm['catatan']}', - Other_DnaFragmentasiLastUpdated = NOW(), - Other_DnaFragmentasiUserID = {$userid} - WHERE - Other_DnaFragmentasiID = {$prm['xid']}"; - //echo $sql; - $this->db_smartone->query($sql); - } - - - $result = array("total" => 1, "records" => array(), "sql"=> ''); - $this->sys_ok($result); - exit; - } - - -} - +db_smartone = $this->load->database("onedev", true); + $this->load->helper(array('form', 'url')); + } + function getMethodeID($natTestID) { + $sql = "select M_MethodePriorityNat_MethodeID MethodeID, Nat_MethodeName + from + m_methode_priority + join nat_methode on Nat_MethodeID = M_MethodePriorityNat_MethodeID + and Nat_MethodeIsActive = 'Y' + join m_instrumentmethode on M_InstrumentMethodeNat_MethodeID = Nat_MethodeID and M_InstrumentMethodeIsActive = 'Y' + join nat_instrument on M_InstrumentMethodeNat_InstrumentID = Nat_InstrumentID + and Nat_InstrumentIsActive ='Y' + where M_MethodePriorityIsActive = 'Y' + and M_MethodePriorityNat_TestID = $natTestID + and M_MethodePriorityM_DayOfWeekID = dayofweek(now()) + order by M_MethodePriorityNumber desc + limit 0,1 "; + $qry = $this->db->query($sql); + if ($qry) { + $rows = $qry->result_array(); + if (count($rows) > 0 ) return array($rows[0]["MethodeID"],$rows[0]["Nat_MethodeName"]); + } + //2nd + $sql= "select + M_InstrumentMethodeNat_MethodeID MethodeID, Nat_MethodeName + from m_instrumentmethode + join nat_methode on M_InstrumentMethodeNat_MethodeID = Nat_MethodeID + and Nat_MethodeIsActive = 'Y' + join nat_instrument on M_InstrumentMethodeNat_InstrumentID = Nat_InstrumentID + and Nat_InstrumentIsActive ='Y' + where M_InstrumentMethodeNat_TestID = $natTestID + and M_InstrumentMethodeIsActive = 'Y' + order by M_InstrumentMethodePriority desc + limit 0,1"; + $qry = $this->db->query($sql); + if ($qry) { + $rows = $qry->result_array(); + if (count($rows) > 0 ) return array($rows[0]["MethodeID"],$rows[0]["Nat_MethodeName"]); + } + // + $sql = "select Nat_NormalValueNat_MethodeID MethodeID, Nat_MethodeName + from + nat_normalvalue + join nat_methode on Nat_NormalValueNat_MethodeID = Nat_MethodeID + and Nat_MethodeIsActive = 'Y' + where Nat_NormalValueNat_TestID = $natTestID + and Nat_NormalValueIsActive = 'Y' + order by Nat_NormalValueID + limit 0,1"; + $qry = $this->db->query($sql); + if ($qry) { + $rows = $qry->result_array(); + if (count($rows) > 0 ) return array($rows[0]["MethodeID"],$rows[0]["Nat_MethodeName"]); + } + return array(0,""); + } + function get_normal_value($methodeID, $natTestID, $sexID, $ageInDay ) { + $this->load->library('ibl_sampling_normal'); + return $this->ibl_sampling_normal->get_normal_value_id($methodeID, $natTestID, $sexID, $ageInDay); + } + return 0; + } + function fn_fix_normal($order_id) { + $sql = "select + T_OrderDetailID, M_PatientM_SexID, fn_global_age_count_day(M_PatientDOB, date(T_OrderHeaderDate)) Dob , + T_TestNat_TestID + from t_orderheader + join m_patient on T_OrderHeaderID = $order_id and T_OrderHeaderM_PatientID = M_PatientID + join t_orderdetail on T_OrderDetailT_OrderHeaderID = T_OrderHeaderID + and T_OrderDetailIsACtive = 'Y' + and ( T_OrderDetailNat_NormalValueID is null or T_OrderDetailNat_NormalValueID = 0 ) + join t_test on T_OrderDetailT_TestID = T_TestID and T_TestIsResult = 'Y' "; + $qry = $this->db->query($sql); + if(! $qry) { + return; + } + $rows = $qry->result_array(); + if(count($rows) == 0 ) return; + $sql_u = "update t_orderdetail + join nat_normalvalue on T_OrderDetailID = ? and Nat_NormalValueID = ? + set + T_OrderDetailNat_NormalValueID = Nat_NormalValueID, + T_OrderDetailNormalValueNote = Nat_NormalValueNote, + T_OrderDetailNormalValueDescription = Nat_NormalValueDescription, + T_OrderDetailMinValue = Nat_NormalValueMinValue, + T_OrderDetailMaxValue = Nat_NormalValueMaxValue, + T_OrderDetailMinValueInclusive = Nat_NormalValueMinValueInclusive, + T_OrderDetailMaxValueInclusive = Nat_NormalValueMaxValueInclusive, + T_OrderDetailNat_MethodeID = ?, + T_OrderdetailNat_MethodeName =?"; + + foreach($rows as $r) { + $T_OrderDetailID = $r["T_OrderDetailID"]; + $sexID = $r["M_PatientM_SexID"]; + $ageInDay = $r["Dob"]; + $natTestID = $r["T_TestNat_TestID"]; + list($methodeID,$methodeName) = $this->getMethodeID($natTestID); + if ($methodeID == 0 ) continue; + $normalValueID = $this->get_normal_value($methodeID, $natTestID, $sexID, $ageInDay); + if ($normalValueID == 0) return; + $this->db->query($sql_u, array($T_OrderDetailID, $normalValueID, $methodeID, $methodeName)); + } + } + function update_order_sample($targetID, $sourceID) { + $sql = "update t_ordersample target + join t_ordersample source on + target.T_OrderSampleID = ? + and target.T_OrderSampleWorklistReceive = 'N' + and source.T_OrderSampleID = ? + set + target.T_OrderSampleSampling = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSampling, source.T_OrderSampleSampling), + target.T_OrderSampleSamplingDate = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingDate, source.T_OrderSampleSamplingDate), + target.T_OrderSampleSamplingTime = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingTime, source.T_OrderSampleSamplingTime), + target.T_OrderSampleSamplingUserID = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingUserID, source.T_OrderSampleSamplingUserID), + + target.T_OrderSampleReceive = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceive, source.T_OrderSampleReceive), + target.T_OrderSampleReceiveDate = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveDate, source.T_OrderSampleReceiveDate), + target.T_OrderSampleReceiveTime = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveTime, source.T_OrderSampleReceiveTime), + target.T_OrderSampleReceiveUserID = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveUserID, source.T_OrderSampleReceiveUserID), + + target.T_OrderSampleVerification = if(target.T_OrderSampleVerification='Y',target.T_OrderSampleVerification, source.T_OrderSampleVerification), + target.T_OrderSampleVerificationDate =if(target.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationDate, source.T_OrderSampleVerificationDate), + target.T_OrderSampleVerificationTime =if(source.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationTime, source.T_OrderSampleVerificationTime), + target.T_OrderSampleVerificationUserID =if(source.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationUserID, source.T_OrderSampleVerificationUserID), + + target.T_OrderSampleProcessing = if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessing, source.T_OrderSampleProcessing), + target.T_OrderSampleProcessingDate= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingDate, source.T_OrderSampleProcessingDate), + target.T_OrderSampleProcessingTime= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingTime, source.T_OrderSampleProcessingTime), + target.T_OrderSampleProcessingUserID= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingUserID, source.T_OrderSampleProcessingUserID), + + target.T_OrderSampleReceiveHandling =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandling, source.T_OrderSampleReceiveHandling ), + target.T_OrderSampleReceiveHandlingDate =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingDate, source.T_OrderSampleReceiveHandlingDate), + target.T_OrderSampleReceiveHandlingTime =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingTime, source.T_OrderSampleReceiveHandlingTime), + target.T_OrderSampleReceiveHandlingUserID =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingUserID, source.T_OrderSampleReceiveHandlingUserID), + + target.T_OrderSampleHandling = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandling, source.T_OrderSampleHandling), + target.T_OrderSampleHandlingDate = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingDate, source.T_OrderSampleHandlingDate), + target.T_OrderSampleHandlingTime = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingTime, source.T_OrderSampleHandlingTime), + target.T_OrderSampleHandlingUserID = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingUserID, source.T_OrderSampleHandlingUserID), + + target.T_OrderSampleWorklistReceive = source.T_OrderSampleWorklistReceive, + target.T_OrderSampleWorklistReceiveDatetime = source.T_OrderSampleWorklistReceiveDateTime, + target.T_OrderSampleWorklistReceiveUserID = source.T_OrderSampleWorklistReceiveUserID + "; + $qry = $this->db->query($sql,array($targetID,$sourceID)); + if(! $qry ) { + echo json_encode(array( "status" => "ERR" , "message" => print_r($this->db->error(),true))); + exit; + } + } + function fix_sample_serum($headerID) { + //cari t_ordersample yg belum worklist receive dengan code 017% + $sql = "select T_OrderSampleID + from t_ordersample + join t_sampletype on + T_OrderSampleT_OrderHeaderID = ? + and T_OrderSampleWorklistReceive = 'N' + and T_OrderSampleIsActive = 'Y' + and T_OrderSampleT_SampleTypeID = T_SampletypeID + and T_SampleTypeCode like '017%' + "; + $qry = $this->db->query($sql, array($headerID)); + if(!$qry) { + echo json_encode(array( "status" => "ERR" , "message" => print_r($this->db->error(),true))); + exit; + } + $rows = $qry->result_array(); + if (count($rows) == 0 ) return; + //cari T_OrderSample yang sudah di receive yg terakhir + $sql = "select T_OrderSampleID + from t_ordersample + join t_sampletype on + T_OrderSampleT_OrderHeaderID = ? + and T_OrderSampleWorklistReceive = 'Y' + and T_OrderSampleIsActive = 'Y' + and T_OrderSampleT_SampleTypeID = T_SampletypeID + and T_SampleTypeCode like '017%' + order by T_OrderSampleWorklistReceiveDatetime desc + limit 0,1 + "; + $qry = $this->db->query($sql, array($headerID)); + if(!$qry) { + echo json_encode(array( "status" => "ERR" , "message" => print_r($this->db->error(),true))); + exit; + } + $rcv_rows = $qry->result_array(); + if (count($rcv_rows) == 0 ) return; + + //print_r($rows); + //print_r($rcv_rows); + $rcv_T_OrderSampleID = $rcv_rows[0]["T_OrderSampleID"]; + //ada yg belum di receive + foreach($rows as $r) { + $T_OrderSampleID = $r["T_OrderSampleID"]; + $this->update_order_sample($T_OrderSampleID,$rcv_T_OrderSampleID); + } + } + public function search() + { + $prm = $this->sys_input; + $max_rst = 99; + + $id = $prm["order_id"]; + if ($id > 0 ) { + $this->fix_sample_serum($id); + $this->fn_fix_normal($id); + } + $lang = $this->lang_default_code; + $lang_id = isset($prm['lang_id']) ? $prm['lang_id'] : '0'; + + if ($lang_id != 0) + { + $l = $this->db_smartone->where("Nat_LangID", $lang_id)->get("nat_lang")->row(); + $lang = $l->Nat_LangCode; + } + + //tambahan fajri + $sql = " UPDATE t_orderdetail + JOIN t_test ON T_OrderDetailT_TestID = T_TestID + SET T_OrderDetailT_TestIsResult = T_TestIsResult + WHERE + T_OrderDetailT_OrderHeaderID = {$id} AND + T_OrderDetailT_TestIsResult = '' AND + T_OrderDetailIsActive = 'Y'"; + $this->db_smartone->query($sql); + + $tot_count = 0; + $lq = ""; + $group_id = 0; + if (isset($prm['group_id'])) + $group_id = $prm['group_id']; + + if ($group_id != 0) + { + $sql = "select distinct T_WorklistDetailNat_TestID Nat_TestID + from t_worklistdetailv2 + where T_WorklistDetailT_WorklistID = {$group_id}"; + $qry = $this->db_smartone->query($sql); + $rows = $qry->result_array(); + $nat_test_ids = "0"; + foreach($rows as $r) { + $nat_test_ids .= ", " . $r["Nat_TestID"]; + } + $q_group = " ( $nat_test_ids ) "; + + $sql = " + SELECT a1.*, cOUNT(a2.T_OrderDetailID) level + FROM ( + SELECT IFNULL(y.T_OrderDetailT_TestID, x.T_OrderDetailT_TestID) t_testid, + IFNULL(y.T_OrderDetailT_TestName, y.T_OrderDetailT_TestName) t_testname, + y.T_OrderDetailResult result, y.T_OrderDetailResult result_old, y.T_OrderDetailNote note, y.T_OrderDetailNote note_old, + y.T_OrderDetailID id, + y.T_OrderDetailT_TestIsResult is_result, a.T_TestIsQuantitative is_quantitative, + y.T_OrderDetailResultFlag result_flag, + y.T_OrderDetailNat_NormalValueID normal_id, + y.T_OrderDetailNormalValueNote normal_note, y.T_OrderDetailNat_UnitName unit_name, + y.T_OrderdetailNat_MethodeID methode_id, y.T_OrderdetailNat_MethodeName methode_name, + a.T_TestNat_TestID nattest_id, a.T_TestID tx_id, count(T_ResultInstrumentID) as result_instrument_n, + y.T_OrderDetailVerification, T_OrderSampleReceive sample_receive, + T_OrderSampleProcessing sample_processing, T_OrderSampleWorklistReceive sample_worklist_receive, + IF(T_OrderDetailAddOnPreAnalytic = 'Y', T_OrderDetailAddOnPreAnalytic, PreAnalyticIsOk) pre_analytic, + T_OrderDetailAddOnPreAnalytic, + T_OrderHeaderID order_id, y.T_OrderDetailT_TestSasCode test_sas_code, + tx.T_TestSasCode, + T_OrderDetailAddOnResample `resample`, T_OrderDetailAddOnResampleStatus resample_status, + T_OrderDetailAddOnRef ref, y.T_OrderDetailVerification verification, y.T_OrderDetailValidation validation, + T_OrderPromiseDateTime, Group_ResultName as ResultGroupName + FROM t_orderdetail x + left join t_orderpromise on x.T_OrderDetailT_OrderPromiseID = T_OrderPromiseID + JOIN t_test tx ON x.T_OrderDetailT_TestID = T_TestID + JOIN t_test tcheck on tcheck.T_TestNat_TestID in {$q_group} + and ( tx.T_TestID = tcheck.T_TestID or tx.T_TestSasCode like concat(tcheck.T_TestSasCode,'%')) + LEFT JOIN group_resultdetail ON Group_ResultDetailT_TestID = x.T_OrderDetailT_TestID AND Group_ResultDetailIsActive = 'Y' + LEFT JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND Group_ResultFlagNonLab = 'N' + LEFT JOIN t_orderdetail y ON x.T_OrderDetailT_TestSasCode LIKE CONCAT(y.T_OrderDetailT_TestSasCode, '%') + AND x.T_OrderDetailT_OrderHeaderID = y.T_OrderDetailT_OrderHeaderID + AND y.T_OrderDetailIsActive = 'Y' + LEFT JOIN t_orderdetailaddon ON x.T_OrderDetailID = T_OrderDetailAddOnT_OrderDetailID + JOIN t_orderheader ON y.T_OrderDetailT_OrderHeaderID = T_OrderHeaderID + LEFT JOIN t_test a ON y.T_OrderDetailT_TestID = a.T_TestID + AND a.T_TestIsNonLab = '' + LEFT JOIN (SELECT T_OrderSampleT_SampleTypeID, T_OrderSampleReceive, T_OrderSampleProcessing, T_OrderSampleWorklistReceive + FROM t_ordersample WHERE T_OrderSampleT_OrderHeaderID = {$id} + AND T_OrderSampleIsactive = 'Y' + GROUP BY T_OrderSampleT_SampleTypeID) os ON a.T_TestT_SampleTypeID = os.T_OrderSampleT_SampleTypeID + or os.T_OrderSampleT_SampleTypeID = fn_sampletype_from_local(a.T_TestNat_TestID) + + LEFT JOIN t_resultinstrument ON T_ResultInstrumentT_OrderDetailID = x.T_OrderDetailID + LEFT JOIN pre_analytic ON PreAnalyticNat_TestID = a.T_TestNat_TestID AND PreAnalyticDate = date(now()) and PreAnalyticIsActive = 'Y' + WHERE x.T_OrderDetailT_OrderHeaderID = {$id} + AND x.T_OrderDetailIsActive = 'Y' + GROUP BY y.T_OrderDetailT_TestID + ORDER BY y.T_OrderDetailT_TestSasCode ASC + ) a1 + + LEFT JOIN t_orderdetail a2 ON a2.T_OrderDetailT_OrderHeaderID = a1.order_id + AND a2.T_OrderDetailIsActive = 'Y' + AND a1.test_sas_code LIKE CONCAT(a2.T_OrderDetailT_testSasCode, '%') + GROUP BY a1.t_testid + order by a1.test_sas_code +"; + $query = $this->db_smartone->query($sql); + $lq = $this->db_smartone->last_query(); + } + else + { + $sql = " + SELECT a1.*, cOUNT(a2.T_OrderDetailID) level + FROM ( + SELECT IFNULL(y.T_OrderDetailT_TestID, x.T_OrderDetailT_TestID) t_testid, + IFNULL(y.T_OrderDetailT_TestName, y.T_OrderDetailT_TestName) t_testname, + y.T_OrderDetailResult result, y.T_OrderDetailResult result_old, y.T_OrderDetailNote note, y.T_OrderDetailNote note_old, + y.T_OrderDetailID id, + y.T_OrderDetailT_TestIsResult is_result, a.T_TestIsQuantitative is_quantitative, + y.T_OrderDetailResultFlag result_flag, + y.T_OrderDetailNat_NormalValueID normal_id, + y.T_OrderDetailNormalValueNote normal_note, y.T_OrderDetailNat_UnitName unit_name, + y.T_OrderdetailNat_MethodeID methode_id, y.T_OrderdetailNat_MethodeName methode_name, + a.T_TestNat_TestID nattest_id, a.T_TestID tx_id, count(T_ResultInstrumentID) as result_instrument_n, + y.T_OrderDetailVerification, T_OrderSampleReceive sample_receive, + T_OrderSampleProcessing sample_processing, T_OrderSampleWorklistReceive sample_worklist_receive, + IF(T_OrderDetailAddOnPreAnalytic = 'Y', T_OrderDetailAddOnPreAnalytic, PreAnalyticIsOk) pre_analytic, + T_OrderDetailAddOnPreAnalytic, + T_OrderHeaderID order_id, y.T_OrderDetailT_TestSasCode test_sas_code, + tx.T_TestSasCode, + T_OrderDetailAddOnResample `resample`, T_OrderDetailAddOnResampleStatus resample_status, + T_OrderDetailAddOnRef ref, y.T_OrderDetailVerification verification, y.T_OrderDetailValidation validation, + T_OrderPromiseDateTime , Group_ResultName as ResultGroupName + FROM t_orderdetail x + left join t_orderpromise on x.T_OrderDetailT_OrderPromiseID = T_OrderPromiseID + JOIN t_test tx ON x.T_OrderDetailT_TestID = T_TestID + LEFT JOIN group_resultdetail ON Group_ResultDetailT_TestID = x.T_OrderDetailT_TestID AND Group_ResultDetailIsActive = 'Y' + LEFT JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND Group_ResultFlagNonLab = 'N' + LEFT JOIN t_orderdetail y ON x.T_OrderDetailT_TestSasCode LIKE CONCAT(y.T_OrderDetailT_TestSasCode, '%') + AND x.T_OrderDetailT_OrderHeaderID = y.T_OrderDetailT_OrderHeaderID + AND y.T_OrderDetailIsActive = 'Y' + + LEFT JOIN t_orderdetailaddon ON x.T_OrderDetailID = T_OrderDetailAddOnT_OrderDetailID + + JOIN t_orderheader ON y.T_OrderDetailT_OrderHeaderID = T_OrderHeaderID + LEFT JOIN t_test a ON y.T_OrderDetailT_TestID = a.T_TestID + AND a.T_TestIsNonLab = '' + LEFT JOIN (SELECT T_OrderSampleT_SampleTypeID, T_OrderSampleReceive, T_OrderSampleProcessing, T_OrderSampleWorklistReceive + FROM t_ordersample WHERE T_OrderSampleT_OrderHeaderID = {$id} + AND T_OrderSampleIsactive = 'Y' + GROUP BY T_OrderSampleT_SampleTypeID) os ON a.T_TestT_SampleTypeID = os.T_OrderSampleT_SampleTypeID + or os.T_OrderSampleT_SampleTypeID = fn_sampletype_from_local(a.T_TestNat_TestID) + + LEFT JOIN t_resultinstrument ON T_ResultInstrumentT_OrderDetailID = x.T_OrderDetailID + LEFT JOIN pre_analytic ON PreAnalyticNat_TestID = a.T_TestNat_TestID AND PreAnalyticDate = date(now()) and PreAnalyticIsActive = 'Y' + WHERE x.T_OrderDetailT_OrderHeaderID = {$id} + AND x.T_OrderDetailIsActive = 'Y' + GROUP BY y.T_OrderDetailT_TestID + ORDER BY y.T_OrderDetailT_TestSasCode ASC + ) a1 + + LEFT JOIN t_orderdetail a2 ON a2.T_OrderDetailT_OrderHeaderID = a1.order_id + AND a2.T_OrderDetailIsActive = 'Y' + AND a1.test_sas_code LIKE CONCAT(a2.T_OrderDetailT_testSasCode, '%') + GROUP BY a1.t_testid + order by a1.test_sas_code +"; +//echo $sql; + $query = $this->db_smartone->query($sql); + $lq = $this->db_smartone->last_query(); + } + // file_put_contents("/xtmp/re-query.sql",$lq); + + if ($query) { + $rst = []; + $rows = $query->result_array(); + + foreach($rows as $k => $v) + { + + if ($v['is_result'] == "Y" && $v['is_quantitative'] == "N") + { + $v['template'] = []; + $x = $this->db_smartone->query("CALL sp_master_resulttemplate_get('{$v['t_testid']}')"); + $this->clean_mysqli_connection($this->db_smartone->conn_id); + if ($x) + $v['template'] = $x->result_array(); + } + + // IF Rujukan, by pas Pre Analytik + if ($v['ref'] == 'Y') + $v['pre_analytic'] = 'Y'; + if ($v["id"] == "885455" ) + { + //sipe workaround + //$v["sample_receive"] = "Y"; + $v["sample_worklist_receive"] = "Y"; + } + $rst[] = $v; + } + + $result = array("total" => $tot_count, "records" => $rst, "total_display" => sizeof($rows), "q" => $lq); + $this->sys_ok($result); + } + else { + $this->sys_error_db("RE Px rows", $this->db_smartone); + exit; + } + } + + public function save() + { + $prm = $this->sys_input; + $data = json_decode($prm["data"]); + $lang = $this->lang_default_code; + $lang_id = isset($prm['lang_id']) ? $prm['lang_id'] : '0'; + + if ($lang_id != 0) + { + $l = $this->db_smartone->where("Nat_LangID", $lang_id)->get("nat_lang")->row(); + $lang = $l->Nat_LangCode; + } + + $sql_norm = "select T_OrderDetailMinValue, T_OrderDetailMaxValue, + T_OrderDetailMinValueInclusive, T_OrderDetailMaxValueInclusive, + Nat_TestFlagLow, Nat_TestFlagHigh + from t_orderdetail + join t_test on T_OrderDetailT_TestID = T_TestID + join nat_test on T_TestNat_TestID = Nat_TestID and T_TestIsActive = 'Y' + where T_OrderDetailID = ? "; + + $ids = []; + foreach ($data as $k => $v) + { + if ( $v->resultInstrumentID > 0 ) { + $sql_i = "select T_ResultInstrumentNat_NormalValueID normalValueID + from t_resultinstrument + where T_ResultInstrumentID = ?"; + $qry_i = $this->db_smartone->query($sql_i, array($v->resultInstrumentID)); + if ($qry_i) { + $rows_i = $qry_i->result_array(); + + if (count($rows_i) > 0 ) { + $sql_iu = "update t_orderdetail, nat_normalvalue , nat_methode + set T_OrderDetailMinValue = Nat_NormalValueMinValue, + T_OrderDetailMinValueInclusive = Nat_NormalValueMinValueInclusive, + T_OrderDetailMaxValue = Nat_NormalValueMaxValue , + T_OrderDetailMaxValueInclusive = Nat_NormalValueMaxValueInclusive, + T_OrderDetailNormalValueNote = Nat_NormalValueNote, + T_OrderDetailNormalValueDescription = Nat_NormalValueDescription, + T_OrderDetailNat_NormalValueID = Nat_NormalValueID, + T_OrderDetailNat_MethodeID = Nat_NormalValueNat_MethodeID, + T_OrderDetailNat_MethodeName = Nat_MethodeName + where T_OrderDetailID = ? and Nat_NormalValueID = ? + and Nat_NormalValueNat_MethodeID = Nat_MethodeID + "; + $this->db_smartone->query($sql_iu, array($v->id, $rows_i[0]["normalValueID"])); + //file_put_contents("/xtmp/update-nilai-normal", $this->db_smartone->last_query() . "\n", FILE_APPEND); + } + } + } + $y = $this->db_smartone->query("SELECT fn_process_sample_handling_perfect('{$v->order_id}', '{$v->test_id}') c") + ->row(); + $req_status = $y->c; + $qry_norm = $this->db_smartone->query($sql_norm,$v->id); + $result_flag = ""; + if ($qry_norm) { + $rows_norm = $qry_norm->result_array(); + if (count($rows_norm) > 0 ) { + $r = $rows_norm[0]; + if (is_numeric($v->result)) { + + if ( $r["T_OrderDetailMinValueInclusive"] == "Y" && $v->result < $r["T_OrderDetailMinValue"] ) { + $result_flag = $r["Nat_TestFlagLow"]; + } + if ( $r["T_OrderDetailMinValueInclusive"] == "N" && $v->result <= $r["T_OrderDetailMinValue"] ) { + $result_flag = $r["Nat_TestFlagLow"]; + } + if ( $r["T_OrderDetailMaxValueInclusive"] == "Y" && $v->result > $r["T_OrderDetailMaxValue"] ) { + $result_flag = $r["Nat_TestFlagHigh"]; + } + if ( $r["T_OrderDetailMaxValueInclusive"] == "N" && $v->result >= $r["T_OrderDetailMaxValue"] ) { + $result_flag = $r["Nat_TestFlagHigh"]; + } + } + } + } + if ($lang == $this->lang_default_code) + { + $this->db_smartone->set('T_OrderDetailResult', $v->result) + ->set('T_OrderDetailResultFlag', $result_flag) + ->set('T_OrderDetailNote', $v->note) + ->set('T_OrderDetailReqStatus', $req_status) + ->where('T_OrderDetailID', $v->id) + ->update('t_orderdetail'); + } + else + { + $this->db_smartone->set('T_OrderDetailLangResult', $v->result) + ->set('T_OrderDetailLangNote', $v->note) + ->where('T_OrderDetailLangID', $v->id) + ->update('t_orderdetaillang'); + } + + $ids[] = $v->id; + } + + // LOG Process + $order = $this->db_smartone->select('T_OrderDetailT_OrderHeaderID id, T_OrderHeaderLabNumber lab_number', false) + ->join('t_orderheader', 'T_OrderHeaderID = T_OrderDetailT_OrderHeaderID') + ->where('T_OrderDetailID', $data[0]->id) + ->get('t_orderdetail') + ->row(); + + $dblog = $this->load->database("onelog", true); + $dblog->set('Log_ProcessCode', 'PROCESS.Result.Entry') + ->set('Log_ProcessOrderID', $order->id) + ->set('Log_ProcessOrderNumber', $order->lab_number) + ->set('Log_ProcessJson', json_encode($data)) + ->set('Log_ProcessUserID', $this->sys_user['M_UserID']) + ->insert('log_process'); + // END OF Log Process + //auto calculation + $this->load->library("Resultcalc"); + $rows = $this->resultcalc->auto($order->id); + + try { + foreach($ids as $id ) { + $this->db_smartone->query("call sp_set_normal_value_flag($id)"); + $this->clean_mysqli_connection($this->db_smartone->conn_id); + } + } catch(Exception $e) { + } + + $this->sys_ok($ids); + } + + public function save_template() + { + $prm = $this->sys_input; + + $n = $this->db_smartone->select("COUNT(T_ResultTemplateID) n") + ->where("T_ResultTemplateT_TestID", $prm['test_id']) + ->where("T_ResultTemplateIsActive", "Y") + ->where("T_ResultTemplateValue", $prm['value']) + ->get('t_resulttemplate') + ->row(); + if ($n->n > 0) + { + $this->sys_error_db("Insert Result Template", $this->db_smartone); + return; + } + + $r = $this->db_smartone->set("T_ResultTemplateT_TestID", $prm['test_id']) + ->set("T_ResultTemplateValue", $prm['value']) + ->insert('t_resulttemplate'); + if ($r) + { + $template = []; + $x = $this->db_smartone->query("CALL sp_master_resulttemplate_get('{$prm['test_id']}')"); + $this->clean_mysqli_connection($this->db_smartone->conn_id); + if ($x) + $template = $x->result_array(); + + $this->sys_ok($template); + } + } + + public function export() + { + $prm = $this->sys_input; + + $sql = "CALL sp_process_result_lang(?, ?, ?, ?)"; + $query = $this->db_smartone->query($sql, [$prm['order_id'], $prm['lang_id'], $prm['is_si'], $this->sys_user['M_UserID']]); + if ($query) + { + $r = $query->row(); + if ($r->status == "OK") + { + $this->sys_ok($r->data); + return; + } + + $this->sys_error_db("Message : " . $r->message, $this->db_smartone); + } + else + { + $this->sys_error_db("Lang Result", $this->db_smartone); + return; + } + } + + public function search_group() + { + $prm = $this->sys_input; + $max_rst = 100; + + // QUERY TOTAL + $sql = "select count(*) total + from t_worklist + where T_WorklistIsActive = 'Y' + order by T_WorklistName ASC"; + $query = $this->db_smartone->query($sql); + + if ($query) { + $tot_count = $query->result_array()[0]["total"]; + } + else { + $this->sys_error_db("worklist count", $this->db_smartone); + exit; + } + + $sql = "select T_WorklistID group_id, T_WorklistName group_name + from t_worklist + where T_WorklistIsActive = 'Y' + order by T_WorklistName ASC + limit 0, {$max_rst}"; + $query = $this->db_smartone->query($sql); + + if ($query) { + $rows = $query->result_array(); + foreach ($rows as $k => $v) + $rows[$k]['data'] = json_decode($v['data']); + $result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows), "q" => $this->db_smartone->last_query()); + $this->sys_ok($result); + } + else { + $this->sys_error_db("worklist rows", $this->db_smartone); + exit; + } + } + + public function search_rerun() + { + $prm = $this->sys_input; + $id = $prm["detail_id"]; + + $sql = "CALL sp_process_result_rerun(?)"; + $query = $this->db_smartone->query($sql, [$id]); + + if ($query) + { + $rows = $query->result_array(); + $this->sys_ok(["records"=>$rows]); + } + else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + + + function getdoctorsfna() + { + $prm = $this->sys_input; + // $id = $prm["id"]; + + $sql = " SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY M_DoctorName ASC"; + //echo $sql; + $query = $this->db_smartone->query($sql); + + if ($query) + { + $rows = $query->result_array(); + $this->sys_ok(["records"=>$rows]); + } + else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + function getfnaresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT Other_FNADetailsID as xid, + Other_FNAT_OrderDetailID as orderdetail_id, + Other_FNADetailsCode as code, + Other_FNADetailsLabel as label, + Other_FNADetailsResult as result, + IFNULL(Other_FNAM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_FNAM_DoctorID) OR Other_FNAM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_fna + JOIN other_fnadetails ON Other_FNADetailsOther_FNAID = Other_FNAID AND Other_FNADetailsIsActive = 'Y' + LEFT JOIN m_doctor ON Other_FNAM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_FNAT_OrderDetailID = {$id} AND Other_FNAIsActive = 'Y' + GROUP BY Other_FNADetailsID + ORDER BY Other_FNADetailsCode ASC"; + $query = $this->db_smartone->query($sql); + + if ($query) + { + $rows = $query->result_array(); + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $images = array(); + $sql = "SELECT So_ImageUploadID as xid, + CONCAT('/one-media/one-image-nonlab/',So_ImageUploadNewName) as image_url + FROM t_orderdetail + JOIN so_imageupload ON So_ImageUploadT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND + So_ImageUploadIsActive = 'Y' + WHERE + T_OrderDetailID = {$id} AND + T_OrderDetailIsActive = 'Y' + GROUP BY So_ImageUploadID"; + $images = $this->db_smartone->query($sql)->result_array(); + + $rst = array('doctors'=>$doctors,'results'=>$rows,'images'=>$images); + $this->sys_ok(["records"=>$rst]); + } + else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + + function uploadimage(){ + if (! $this->isLogin) { + $this->sys_error("Invalid Token"); + exit; + } + + $userid = $this->sys_user["M_UserID"]; + $data = []; + //print_r($_SERVER); + + $prm = $this->sys_input; + $orderid = $this->input->post('orderid'); + $labnumber = $this->input->post('labnumber'); + $sql = "UPDATE so_imageupload SET + So_ImageUploadIsActive = 'N', + So_ImageUploadUserID = {$userid} + WHERE + So_ImageUploadT_OrderHeaderID = {$orderid}"; + //echo $sql; + $this->db_onedev->query($sql); + //$config['upload_path'] = 'assets/'; + + $path = '/home/one/project/one/one-media/one-image-nonlab/'; + //echo $path; + $config['upload_path'] = $path; + $config['allowed_types'] = 'jpg|jpeg|png|gif'; + + $config['max_size'] = '10000'; + $count = count($_FILES['files']['name']); + //echo $count; + $this->load->library('upload',$config); + + $error = []; + for($i=0;$i<$count;$i++){ + + + if(!empty($_FILES['files']['name'][$i])){ + + + + $_FILES['file']['name'] = $_FILES['files']['name'][$i]; + + $_FILES['file']['type'] = $_FILES['files']['type'][$i]; + + $_FILES['file']['tmp_name'] = $_FILES['files']['tmp_name'][$i]; + + $_FILES['file']['error'] = $_FILES['files']['error'][$i]; + + $_FILES['file']['size'] = $_FILES['files']['size'][$i]; + + + + $namex = $orderid.'-'.$labnumber.'-'.$this->generateRandomString(5); + //echo $namex; + + $config['file_name'] = $namex; + $this->upload->initialize($config); + //echo $config['file_name'] ; + + + + + + if($this->upload->do_upload('file')){ + + $uploadData = $this->upload->data(); + + $filename = $uploadData['file_name']; + //echo $filename; + + + $sql = "INSERT INTO so_imageupload ( + So_ImageUploadT_OrderHeaderID, + So_ImageUploadT_OrderHeaderLabNumber, + So_ImageUploadT_SampleTypeID, + So_ImageUploadOldName, + So_ImageUploadNewName, + So_ImageUploadCreated, + So_ImageUploadUserID + ) + VALUES( + {$orderid}, + '{$labnumber}', + '150', + '{$_FILES['files']['name'][$i]}', + '{$filename}', + NOW(), + {$userid} + + )"; + //echo $sql; + $this->db_onedev->query($sql); + $xlast_id = $this->db_onedev->insert_id(); + $data['totalFiles'][] = array('xid' => $xlast_id ,'image_url' => '/one-media/one-image-nonlab/'.$filename); + + } + else{ + $error = array('error' => $this->upload->display_errors()); + } + + } + + + + } + + $result = array("total" =>count( $data['totalFiles']), "records" => $data['totalFiles'],'errors'=>$error); + $this->sys_ok($result); + } + + + function generateRandomString($length = 10) { + $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; + $charactersLength = strlen($characters); + $randomString = ''; + for ($i = 0; $i < $length; $i++) { + $randomString .= $characters[rand(0, $charactersLength - 1)]; + } + return $randomString; + } + + function getcytologiresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT Other_CytologiDetailsID as xid, + Other_CytologiT_OrderDetailID as orderdetail_id, + Other_CytologiDetailsCode as code, + Other_CytologiDetailsLabel as label, + Other_CytologiDetailsResult as result, + IFNULL(Other_CytologiM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_CytologiM_DoctorID) OR Other_CytologiM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_cytologi + JOIN other_cytologidetails ON Other_CytologiDetailsOther_CytologiID = Other_CytologiID AND Other_CytologiDetailsIsActive = 'Y' + LEFT JOIN m_doctor ON Other_CytologiM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_CytologiT_OrderDetailID = {$id} AND Other_CytologiIsActive = 'Y' + GROUP BY Other_CytologiDetailsID + ORDER BY Other_CytologiDetailsCode ASC"; + //echo $sql; + $query = $this->db_smartone->query($sql); + + if ($query) + { + $rows = $query->result_array(); + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $rst = array('doctors'=>$doctors,'results'=>$rows); + $this->sys_ok(["records"=>$rst]); + } + else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + function getmikroresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT + Other_MikroID as xid, + Other_MikroHasilBiakan as hasil_biakan, + Other_MikroSampleTypeName as sample_name, + Other_MikroT_OrderDetailID as orderdetail_id, + Other_MikroResult as result_value, + '' as result_other, + IFNULL(T_BacteriaID,0) as T_BacteriaID, + IFNULL(T_BacteriaName,'') as T_BacteriaName, + '' as details, + IFNULL(Other_MikroM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_MikroM_DoctorID) OR Other_MikroM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_mikro + LEFT JOIN t_bacteria ON Other_MikroT_BacteriaID = T_BacteriaID + LEFT JOIN m_doctor ON Other_MikroM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_MikroT_OrderDetailID = {$id} AND Other_MikroIsActive = 'Y' + GROUP BY Other_MikroID"; + //echo $sql; + $query = $this->db_smartone->query($sql); + + if ($query) + { + $row = $query->row_array(); + if($row){ + if($row['result_value'] != 'Positif' && $row['result_value'] != 'Negatif'){ + $row['result_other'] = $row['result_value']; + $row['result_value'] = 'other'; + } + $sql = "SELECT '' as xno, + Other_MikroDetailsID as xid, + Other_MikroDetailsValue as value, + IF(Other_MikroDetailsNote = 'R','Y','N') as chx_r, + IF(Other_MikroDetailsNote = 'I','Y','N') as chx_i, + IF(Other_MikroDetailsNote = 'S','Y','N') as chx_s, + Other_MikroDetailsNote as note, + t_antibiotic.* + FROM other_mikrodetails + LEFT JOIN t_antibiotic ON Other_MikroDetailsT_AntibioticID = T_AntibioticID + WHERE + Other_MikroDetailsOther_MikroID = {$row['xid']} AND Other_MikroDetailsIsActive = 'Y' + GROUP BY Other_MikroDetailsID + ORDER BY T_AntibioticName ASC"; + //echo $sql; + $details = $this->db_smartone->query($sql)->result_array(); + if(details){ + foreach($details as $k => $v){ + $details[$k]['xno'] = $k + 1; + } + } + $row['details'] = $details; + } + else{ + $row = array('xid'=>'0','hasil_biakan' => '','result_value'=>'Negatif','sample_name' => '','orderdetail_id'=>$id, 'T_BacteriaID'=>'0','T_BacteriaName'=>'0','details'=>array(),'doctor_id'=>'0','doctor_name'=>'0'); + } + } + else{ + $row = array('xid'=>'0','hasil_biakan' => '','result_value'=>'Negatif','sample_name' => '','orderdetail_id'=>$id, 'T_BacteriaID'=>'0','T_BacteriaName'=>'0','details'=>array(),'doctor_id'=>'0','doctor_name'=>'0'); + } + //print_r($row); + + + + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 7 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $sql = " + SELECT '0' as id, 'Belum memilih bakteria' as name + UNION + SELECT T_BacteriaID as id, T_BacteriaName as name + FROM t_bacteria + WHERE + T_BacteriaIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $bacteries = $this->db_smartone->query($sql)->result_array(); + $rst = array('doctors'=>$doctors,'bacteries'=>$bacteries,'results'=>$row); + $this->sys_ok(["records"=>$rst]); + } + function getantibiotics(){ + $prm = $this->sys_input; + $id = $prm["id"]; + $sql = " SELECT '' as xno, + 0 as xid, + '' as hasil_biakan, + '' as sample_name, + 0 as value, + 'Y' as chx_r, + 'N' as chx_i, + 'N' as chx_s, + 'R' as note, + t_antibiotic.* + FROM t_antibiotic + WHERE + T_AntibioticT_BacteriaID = {$prm['id']} AND T_AntibioticIsActive= 'Y' + ORDER BY T_AntibioticName ASC"; + //echo $sql; + $rows = $this->db_smartone->query($sql)->result_array(); + if(rows){ + foreach($rows as $k => $v){ + $rows[$k]['xno'] = $k + 1; + } + } + + $this->sys_ok(["records"=>$rows]); + } + function getlcprepresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + $sql = " SELECT Other_LcprepDetailsID as xid, + Other_LcprepID as header_id, + Other_LcprepT_orderDetailID as orderdetail_id, + Other_LcprepDetailsCode as code, + Other_LcprepDetailsLabel as label, + Other_LcprepDetailsResult as result, + IFNULL(Other_LcprepM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_LcprepM_DoctorID) OR Other_LcprepM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_lcprep + JOIN other_lcprepdetails ON Other_LcprepDetailsOther_LcprepID = Other_LcprepID AND Other_LcprepDetailsIsActive = 'Y' + LEFT JOIN m_doctor ON Other_LcprepM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_LcprepT_orderDetailID = {$id} AND Other_LcprepIsActive = 'Y' + GROUP BY Other_LcprepDetailsOther_LcprepID, Other_LcprepDetailsCode + ORDER BY Other_LcprepDetailsCode ASC"; + //echo $sql; + $rows = $this->db_smartone->query($sql)->result_array(); + if(!$rows){ + $rows = array( + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'A', + 'label' => 'DESKRIPSI', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ), + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'B', + 'label' => 'KESIMPULAN', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ) + ); + } + + $header_id = $rows[0]['header_id']; + $sql = "SELECT IFNULL(Other_LcprepAdekuasiID,0) as xid, + Lcprep_AdekuasiID as id, + Lcprep_AdekuasiLabel as name, + IF(ISNULL(Other_LcprepAdekuasiID),'N',Other_LcprepAdekuasiChex) as chex + FROM lcprep_adekuasi + LEFT JOIN other_lcprepadekuasi ON Other_LcprepAdekuasiLcprep_AdekuasiID = Lcprep_AdekuasiID AND + Other_LcprepAdekuasiOther_LcprepID = {$header_id} AND + Other_LcprepAdekuasiIsActive = 'Y' + WHERE + Lcprep_AdekuasiIsActive = 'Y' + GROUP BY Lcprep_AdekuasiID + ORDER BY Lcprep_AdekuasiOrder ASC + "; + //echo $sql; + $adeakuasi = $this->db_smartone->query($sql)->result_array(); + foreach($adeakuasi as $kc => $vc){ + $adeakuasi[$kc]['chex'] = $vc['chex'] == 'N'?false:true; + } + + $sql = "SELECT IFNULL(Other_LcprepKategoriUmumID,0) as xid, + Lcprep_KategoriUmumID as id, + Lcprep_KategoriUmumLabel as name, + IF(ISNULL(Other_LcprepKategoriUmumID),'N',Other_LcprepKategoriUmumChex) as chex + FROM lcprep_kategoriumum + LEFT JOIN other_lcprepkategoriumum ON Other_LcprepKategoriUmumLcprep_KategoriUmumID = Lcprep_KategoriUmumID AND + Other_LcprepKategoriUmumOther_LcprepID = {$header_id} AND + Other_LcprepKategoriUmumIsActive = 'Y' + WHERE + Lcprep_KategoriUmumIsActive = 'Y' + GROUP BY Lcprep_KategoriUmumID + "; + //echo $sql; + $kategoriumum = $this->db_smartone->query($sql)->result_array(); + foreach($kategoriumum as $kc => $vc){ + $kategoriumum[$kc]['chex'] = $vc['chex'] == 'N'?false:true; + } + + $sql = " + SELECT Lcprep_InterpretasiGroupID as group_id, + Lcprep_InterpretasiGroupName as group_name, + '' as subgroups + FROM lcprep_interpretasigroup + WHERE + Lcprep_InterpretasiGroupIsActive = 'Y' + "; + //echo $sql; + $interpretasi = $this->db_smartone->query($sql)->result_array(); + foreach($interpretasi as $k => $v){ + $subgroups = array(); + $sql = "SELECT Lcprep_InterpretasiSubgroupID as subgroup_id, + Lcprep_InterpretasiSubgroupName as subgroup_name, + '' as childs + FROM lcprep_interpretasisubgroup + WHERE + Lcprep_InterpretasiSubgroupLcprep_InterpretasiGroupID = {$v['group_id']} AND Lcprep_InterpretasiSubgroupIsActive = 'Y'"; + //echo $sql; + $subgroups = $this->db_smartone->query($sql)->result_array(); + if(count($subgroups) > 0){ + foreach($subgroups as $ki => $vi){ + $childs = array(); + $sql = "SELECT IFNULL(Other_LcprepInterpretasiID,0) as xid, + IFNULL(Other_LcprepInterpretasiChex,'N') as chex, + IFNULL(Other_LcprepInterpretasiValue,'') as value, + Lcprep_InterpretasiID as id, + Lcprep_InterpretasiLcprep_InterpretasiSubgroupID as subgroup_id, + Lcprep_InterpretasiCode as code, + Lcprep_InterpretasiName as name, + Lcprep_InterpretasiParentID as parent_id, + Lcprep_InterpretasiIsParent as is_parent, + Lcprep_InterpretasiHasResult as has_result, + Lcprep_InterpretasiTypeResult as type_result + FROM lcprep_interpretasi + LEFT JOIN other_lcprepinterpretasi ON Other_LcprepInterpretasiOther_LcprepID = {$header_id} AND + Other_LcprepInterpretasiLcprep_InterpretasiID = Lcprep_InterpretasiID AND + Other_LcprepInterpretasiIsActive = 'Y' + WHERE + Lcprep_InterpretasiLcprep_InterpretasiSubgroupID = {$vi['subgroup_id']} AND Lcprep_InterpretasiIsActive = 'Y' + GROUP BY Lcprep_InterpretasiID Order BY Lcprep_InterpretasiCode ASC"; + $childs = $this->db_smartone->query($sql)->result_array(); + if($childs){ + foreach($childs as $kc => $vc){ + $childs[$kc]['chex'] = $vc['chex'] == 'N'?false:true; + } + } + $subgroups[$ki]['childs'] = $childs; + } + } + + $interpretasi[$k]['subgroups'] = $subgroups; + } + + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $rst = array('doctors'=>$doctors,'results'=>$rows,'adekuasi'=>$adeakuasi,'kategoriumum'=>$kategoriumum,'interpretasi'=>$interpretasi); + $this->sys_ok(["records"=>$rst]); + } + + function getpapsmearresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT Other_PapSmearDetailsID as xid, + Other_PapSmearID as header_id, + Other_PapSmearT_OrderDetailID as orderdetail_id, + Other_PapSmearDetailsCode as code, + Other_PapSmearDetailsLabel as label, + Other_PapSmearDetailsResult as result, + IFNULL(Other_PapSmearM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_PapSmearM_DoctorID) OR Other_PapSmearM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_papsmear + JOIN other_papsmeardetails ON Other_PapSmearDetailsOther_PapSmearID = Other_PapSmearID AND Other_PapSmearDetailsIsActive = 'Y' + LEFT JOIN m_doctor ON Other_PapSmearM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_PapSmearT_OrderDetailID = {$id} AND Other_PapSmearIsActive = 'Y' + GROUP BY Other_PapSmearDetailsID + ORDER BY Other_PapSmearDetailsCode ASC"; + //echo $sql; + $rows = $this->db_smartone->query($sql)->result_array(); + if(!$rows){ + $rows = array( + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'A', + 'label' => 'Makroskopik', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ), + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'B', + 'label' => 'Mikroskopik', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ), + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'C', + 'label' => 'Kesimpulan', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ) + ); + } + + $header_id = $rows[0]['header_id']; + $sql = "SELECT Other_PapSmearMaturasiID as xid, + Other_PapSmearMaturasiValue as value + FROM other_papsmearmaturasi + WHERE + Other_PapSmearMaturasiOther_PapSmearID = {$header_id} AND + Other_PapSmearMaturasiIsActive = 'Y' + "; + //echo $sql; + $dt_maturasi = $this->db_smartone->query($sql)->row_array(); + if(!$dt_maturasi){ + $maturasi = array('xid'=>'0','value'=> array('','','')); + } + else{ + $value = explode('/',$dt_maturasi['value']); + $maturasi = array('xid'=>$dt_maturasi['xid'],'value'=> $value); + } + + $sql = "SELECT IFNULL(Other_PapSmearBahanID,0) as xid, + M_PapSmearBahanID as bahan_id, + M_PapSmearBahanName as name, + IF(ISNULL(Other_PapSmearBahanID),'N','Y') as selected + FROM m_papsmearbahan + LEFT JOIN other_papsmearbahan ON Other_PapSmearBahanM_PapSmearBahanID = M_PapSmearBahanID AND + Other_PapSmearBahanOther_PapSmearID = {$header_id} AND + Other_PapSmearBahanIsActive = 'Y' + WHERE + M_PapSmearBahanIsActive = 'Y' + ORDER BY M_PapSmearBahanID ASC + "; + //echo $sql; + $bahans = $this->db_smartone->query($sql)->result_array(); + + $sql = "SELECT IFNULL(Other_PapsmearCategoryID,0) as xid, + M_PapSmearCategoryID as category_id, + M_PapSmearCategoryName as name, + IF(ISNULL(Other_PapsmearCategoryID),'N','Y') as selected + FROM m_papsmearcategory + LEFT JOIN other_papsmearcategory ON Other_PapsmearCategoryM_PapSmearCategoryID = M_PapSmearCategoryID AND + Other_PapsmearCategoryOther_PapSmearID = {$header_id} AND + Other_PapsmearCategoryIsActive = 'Y' + WHERE + M_PapSmearCategoryIsActive = 'Y' + ORDER BY M_PapSmearCategoryID ASC + "; + //echo $sql; + $categories = $this->db_smartone->query($sql)->result_array(); + + $sql = "SELECT IFNULL(Other_PapSmearCheckID,0) as xid, + M_PapSmearCheckID as check_id, + M_PapSmearCheckLabel as name, + IF(ISNULL(Other_PapSmearCheckID),'N','Y') as selected, + Other_PapSmearCheckNote as note + FROM m_papsmearcheck + LEFT JOIN other_papsmearcheck ON Other_PapSmearCheckM_PapSmearCheckID = M_PapSmearCheckID AND + Other_PapSmearCheckOther_PapSmearID = {$header_id} AND + Other_PapSmearCheckIsActive = 'Y' + WHERE + M_PapSmearCheckIsActive = 'Y' + ORDER BY M_PapSmearCheckCode ASC + "; + $checks = $this->db_smartone->query($sql)->result_array(); + + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $rst = array('doctors'=>$doctors,'checks'=>$checks,'bahans'=>$bahans,'categories'=>$categories,'maturasi'=>$maturasi,'results'=>$rows); + $this->sys_ok(["records"=>$rst]); + + } + + function saveresult_lcprep() + { + $prm = $this->sys_input; + $detail_id = $prm['detail_id']; + $doctor_id = $prm['doctor']; + $adekuasi = $prm['adekuasi']; + $kategoriumum = $prm['kategoriumum']; + $interpretasi = $prm['interpretasi']; + $results = $prm['results']; + + $userid = $this->sys_user['M_UserID']; + + $header_id = 0; + $sql = "SELECT * FROM other_lcprep WHERE Other_LcprepT_orderDetailID = {$detail_id} AND Other_LcprepIsActive = 'Y'"; + $dt_header = $this->db_smartone->query($sql)->row_array(); + if($dt_header){ + $header_id = $dt_header['Other_LcprepID']; + } + if($header_id == 0){ + $sql = "INSERT INTO other_lcprep( + Other_LcprepT_orderDetailID, + Other_LcprepM_DoctorID, + Other_LcprepUserID, + Other_LcprepCreated + ) + VALUES( + {$detail_id}, + {$doctor_id}, + {$userid}, + NOW() + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + }else{ + $sql = "UPDATE other_lcprep SET Other_LcprepM_DoctorID = {$doctor_id}, Other_LcprepUserID = {$userid} WHERE Other_LcprepID = {$header_id}"; + $this->db_smartone->query($sql); + } + + if($adekuasi){ + foreach($adekuasi as $k =>$v){ + $selected = $v['chex']?'Y':'N'; + if(intval($v['xid'] == 0)){ + $sql = "UPDATE other_lcprepadekuasi SET Other_LcprepAdekuasiIsActive = 'N' + WHERE + Other_LcprepAdekuasiOther_LcprepID = {$header_id} AND + Other_LcprepAdekuasiIsActive = 'Y' AND + Other_LcprepAdekuasiLcprep_AdekuasiID = {$v['id']}"; + $this->db_smartone->query($sql); + $sql = "INSERT INTO other_lcprepadekuasi ( + Other_LcprepAdekuasiOther_LcprepID, + Other_LcprepAdekuasiLcprep_AdekuasiID, + Other_LcprepAdekuasiChex, + Other_LcprepAdekuasiUserID, + Other_LcprepAdekuasiCreated + ) + VALUES( + {$header_id}, + {$v['id']}, + '{$selected}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + //echo $sql; + } + if(intval($v['xid'] != 0)){ + + $sql = "UPDATE other_lcprepadekuasi SET + Other_LcprepAdekuasiChex = '{$selected}', + Other_LcprepAdekuasiUserID = {$userid} + WHERE + Other_LcprepAdekuasiID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + + //echo $sql; + } + } + + if($kategoriumum){ + foreach($kategoriumum as $k =>$v){ + $selected = $v['chex']?'Y':'N'; + if(intval($v['xid'] == 0)){ + $sql = "UPDATE other_lcprepkategoriumum SET Other_LcprepKategoriUmumIsActive = 'N' + WHERE + Other_LcprepKategoriUmumOther_LcprepID = {$header_id} AND + Other_LcprepKategoriUmumLcprep_KategoriUmumID = {$v['id']} AND + Other_LcprepKategoriUmumIsActive = 'Y' + "; + $this->db_smartone->query($sql); + $sql = "INSERT INTO other_lcprepkategoriumum ( + Other_LcprepKategoriUmumOther_LcprepID, + Other_LcprepKategoriUmumLcprep_KategoriUmumID, + Other_LcprepKategoriUmumChex, + Other_LcprepKategoriUmumUserID, + Other_LcprepKategoriUmumCreated + ) + VALUES( + {$header_id}, + {$v['id']}, + '{$selected}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if(intval($v['xid'] != 0)){ + $sql = "UPDATE other_lcprepkategoriumum SET + Other_LcprepKategoriUmumChex = '{$selected }', + Other_LcprepKategoriUmumUserID = {$userid} + WHERE + Other_LcprepKategoriUmumID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + + //echo $sql; + } + } + + if($results){ + foreach($results as $k =>$v){ + if(intval($v['xid'] == 0)){ + $sql = "UPDATE other_lcprepdetails SET Other_LcprepDetailsIsActive = 'N' + WHERE + Other_LcprepDetailsOther_LcprepID = {$header_id} AND + Other_LcprepDetailsCode = '{$v['code']}' AND + Other_LcprepDetailsIsActive = 'Y'"; + $this->db_smartone->query($sql); + $sql = "INSERT INTO other_lcprepdetails ( + Other_LcprepDetailsOther_LcprepID, + Other_LcprepDetailsCode, + Other_LcprepDetailsLabel, + Other_LcprepDetailsResult, + Other_LcprepDetailsUserID, + Other_LcprepDetailsCreated + ) + VALUES( + {$header_id}, + '{$v['code']}', + '{$v['label']}', + '{$v['result']}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if(intval($v['xid'] != 0)){ + $sql = "UPDATE other_lcprepdetails SET + Other_LcprepDetailsCode = '{$v['code']}', + Other_LcprepDetailsLabel = '{$v['label']}', + Other_LcprepDetailsResult = '{$v['result']}', + Other_LcprepDetailsUserID = {$userid} + WHERE + Other_LcprepDetailsID = {$v['xid']}"; + $this->db_smartone->query($sql); + + } + //echo $sql; + } + } + + if($interpretasi){ + foreach($interpretasi as $k =>$v){ + if(count($v['subgroups']) > 0){ + foreach($v['subgroups'] as $ik => $iv){ + if(count($iv['childs']) > 0){ + foreach($iv['childs'] as $iik => $iiv){ + if(intval($iiv['xid'] == 0)){ + $chex = $iiv['chex'] ? 'Y':'N'; + $sql = "UPDATE other_lcprepinterpretasi SET Other_LcprepInterpretasiIsActive = 'N' + WHERE + Other_LcprepInterpretasiOther_LcprepID = {$header_id} AND + Other_LcprepInterpretasiLcprep_InterpretasiID = '{$iiv['id']}' AND + Other_LcprepInterpretasiIsActive = 'Y'"; + $this->db_smartone->query($sql); + $sql = "INSERT INTO other_lcprepinterpretasi ( + Other_LcprepInterpretasiOther_LcprepID, + Other_LcprepInterpretasiLcprep_InterpretasiID, + Other_LcprepInterpretasiChex, + Other_LcprepInterpretasiValue, + Other_LcprepInterpretasiUserID, + Other_LcprepInterpretasiCreated + ) + VALUES( + {$header_id}, + '{$iiv['id']}', + '{$chex}', + '{$iiv['value']}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + + if(intval($iiv['xid'] != 0)){ + $chex = $iiv['chex'] ? 'Y':'N'; + $sql = "UPDATE other_lcprepinterpretasi SET + Other_LcprepInterpretasiChex = '{$chex}', + Other_LcprepInterpretasiValue = '{$iiv['value']}', + Other_LcprepInterpretasiUserID = {$userid} + WHERE + Other_LcprepInterpretasiID = {$iiv['xid']}"; + $this->db_smartone->query($sql); + //echo $sql; + + } + + } + } + } + } + //echo $sql; + } + } + + + $result = array("total" => 1, "records" => array(), "sql"=> ''); + $this->sys_ok($result); + exit; + } + + function saveresult_papsmear() + { + $prm = $this->sys_input; + $detail_id = $prm['detail_id']; + $doctor_id = $prm['doctor']; + $checks = $prm['checks']; + $maturasi = $prm['maturasi']; + $bahans = $prm['bahans']; + $categories = $prm['categories']; + $results = $prm['results']; + + $userid = $this->sys_user['M_UserID']; + + $header_id = 0; + $sql = "SELECT * FROM other_papsmear WHERE Other_PapSmearT_OrderDetailID = {$detail_id} AND Other_PapSmearIsActive = 'Y'"; + $dt_header = $this->db_smartone->query($sql)->row_array(); + if($dt_header){ + $header_id = $dt_header['Other_PapSmearID']; + } + if($header_id == 0){ + $sql = "INSERT INTO other_papsmear( + Other_PapSmearT_OrderDetailID, + Other_PapSmearM_DoctorID, + Other_PapSmearUserID, + Other_PapSmearCreated + ) + VALUES( + {$detail_id}, + {$doctor_id}, + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } + else{ + $sql = "UPDATE other_papsmear SET Other_PapSmearM_DoctorID = {$doctor_id}, Other_PapSmearUserID = {$userid} WHERE Other_PapSmearID = {$header_id}"; + $this->db_smartone->query($sql); + } + + if($checks){ + foreach($checks as $k =>$v){ + if(intval($v['xid']) == 0 && $v['selected'] === 'Y'){ + $sql = "INSERT INTO other_papsmearcheck ( + Other_PapSmearCheckOther_PapSmearID, + Other_PapSmearCheckM_PapSmearCheckID, + Other_PapSmearCheckNote, + Other_PapSmearCheckUserID, + Other_PapSmearCheckCreated + ) + VALUES( + {$header_id}, + {$v['check_id']}, + '{$v['note']}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if(intval($v['xid']) != 0 && $v['selected'] === 'N'){ + $sql = "UPDATE other_papsmearcheck SET + Other_PapSmearCheckIsActive = 'N', + Other_PapSmearCheckUserID = {$userid} + WHERE + Other_PapSmearCheckID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + if(intval($v['xid']) != 0 && $v['selected'] === 'Y'){ + $sql = "UPDATE other_papsmearcheck SET + Other_PapSmearCheckNote = '{$v['note']}', + Other_PapSmearCheckUserID = {$userid} + WHERE + Other_PapSmearCheckID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + //echo $sql; + } + } + + if($maturasi){ + if(intval($maturasi['xid']) == 0){ + $value = join("/",$maturasi['value']); + $sql = "INSERT INTO other_papsmearmaturasi ( + Other_PapSmearMaturasiOther_PapSmearID, + Other_PapSmearMaturasiValue, + Other_PapSmearMaturasiUserID, + Other_PapSmearMaturasiCreated + ) + VALUE( + {$header_id}, + '{$value}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + //echo $sql; + } + if(intval($maturasi['xid']) != 0){ + $value = join("/",$maturasi['value']); + $sql = "UPDATE other_papsmearmaturasi SET + Other_PapSmearMaturasiValue = '{$value}', + Other_PapSmearMaturasiUserID = {$userid} + WHERE + Other_PapSmearMaturasiID = {$maturasi['xid']}"; + // echo $sql; + $this->db_smartone->query($sql); + } + } + + if($bahans){ + foreach($bahans as $k =>$v){ + if(intval($v['xid']) == 0 && $v['selected'] === 'Y'){ + $sql = "INSERT INTO other_papsmearbahan ( + Other_PapSmearBahanOther_PapSmearID, + Other_PapSmearBahanM_PapSmearBahanID, + Other_PapSmearBahanUserID, + Other_PapSmearBahanCreated + ) + VALUES( + {$header_id}, + {$v['bahan_id']}, + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if(intval($v['xid']) != 0 && $v['selected'] === 'N'){ + $sql = "UPDATE other_papsmearbahan SET + Other_PapSmearBahanIsActive = 'N', + Other_PapsmearCategoryUserID = {$userid} + WHERE + Other_PapSmearBahanID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + if(intval($v['xid']) != 0 && $v['selected'] === 'Y'){ + $sql = "UPDATE other_papsmearbahan SET + Other_PapSmearBahanIsActive = 'Y', + Other_PapsmearCategoryUserID = {$userid} + WHERE + Other_PapSmearBahanID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + //echo $sql; + } + } + + if($categories){ + foreach($categories as $k =>$v){ + if(intval($v['xid']) == 0 && $v['selected'] === 'Y'){ + $sql = "INSERT INTO other_papsmearcategory ( + Other_PapsmearCategoryOther_PapSmearID, + Other_PapsmearCategoryM_PapSmearCategoryID, + Other_PapsmearCategoryUserID, + Other_PapsmearCategoryCreated + ) + VALUES( + {$header_id}, + {$v['category_id']}, + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if(intval($v['xid']) != 0 && $v['selected'] === 'N'){ + $sql = "UPDATE other_papsmearcategory SET + Other_PapsmearCategoryIsActive = 'N', + Other_PapsmearCategoryUserID = {$userid} + WHERE + Other_PapsmearCategoryID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + //echo $sql; + if(intval($v['xid']) != 0 && $v['selected'] === 'Y'){ + $sql = "UPDATE other_papsmearcategory SET + Other_PapsmearCategoryIsActive = 'Y', + Other_PapsmearCategoryUserID = {$userid} + WHERE + Other_PapsmearCategoryID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + } + } + + if($results){ + foreach($results as $k =>$v){ + if(intval($v['xid']) == 0){ + $sql = "INSERT INTO other_papsmeardetails ( + Other_PapSmearDetailsOther_PapSmearID, + Other_PapSmearDetailsCode, + Other_PapSmearDetailsLabel, + Other_PapSmearDetailsResult, + Other_PapSmearDetailsUserID, + Other_PapSmearDetailsCreated + ) + VALUES( + {$header_id}, + '{$v['code']}', + '{$v['label']}', + '{$v['result']}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if(intval($v['xid']) != 0){ + $sql = "UPDATE other_papsmeardetails SET + Other_PapSmearDetailsCode = '{$v['code']}', + Other_PapSmearDetailsLabel = '{$v['label']}', + Other_PapSmearDetailsResult = '{$v['result']}', + Other_PapSmearDetailsUserID = {$userid} + WHERE + Other_PapSmearDetailsID = {$v['xid']}"; + $this->db_smartone->query($sql); + + } + //echo $sql; + } + } + + $result = array("total" => 1, "records" => array(), "sql"=> ''); + $this->sys_ok($result); + exit; + } + + function saveresult_fna() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = $inp['doctor']; + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + if($prm[0]['xid'] == '0'){ + $sql = "INSERT INTO other_fna( + Other_FNAM_DoctorID, + Other_FNAT_OrderDetailID, + Other_FNAUserID, + Other_FNACreated + ) + VALUES( + {$doctor_id}, + {$prm[0]['orderdetail_id']}, + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } + else{ + $sql = "SELECT * FROM other_fna WHERE Other_FNAT_OrderDetailID = {$prm[0]['orderdetail_id']} AND Other_FNAIsActive = 'Y'"; + $data_header = $this->db_smartone->query($sql)->row_array(); + $header_id = $data_header['Other_FNAID']; + $sql = "UPDATE other_fna SET + Other_FNAM_DoctorID = {$doctor_id}, + Other_FNAUserID = {$userid} + WHERE + Other_FNAID = {$header_id}"; + $this->db_smartone->query($sql); + } + foreach($prm as $k => $v){ + if($v['xid'] == '0'){ + $results = str_replace("'", "\\'", $v['result']); + $sql = "INSERT INTO other_fnadetails( + Other_FNADetailsOther_FNAID , + Other_FNADetailsCode, + Other_FNADetailsLabel, + Other_FNADetailsResult, + Other_FNADetailsCreated, + Other_FNADetailsUserID + ) + VALUES( + {$header_id}, + '{$v['code']}', + '{$v['label']}', + '{$results}', + NOW(), + {$userid} + )"; + $query = $this->db_smartone->query($sql); + } + else{ + $results = str_replace("'", "\\'", $v['result']); + $sql = "UPDATE other_fnadetails SET + Other_FNADetailsResult = '{$results}', + Other_FNADetailsUserID = {$userid} + WHERE + Other_FNADetailsID = {$v['xid']}"; + $query = $this->db_smartone->query($sql); + } + } + + $result = array("total" => 1, "records" => array(), "sql"=> ''); + $this->sys_ok($result); + exit; + } + + function saveresult_cytologi() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = $inp['doctor']; + + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + if($prm[0]['xid'] == '0'){ + $sql = "INSERT INTO other_cytologi( + Other_CytologiT_OrderDetailID, + Other_CytologiM_DoctorID, + Other_CytologiUserID, + Other_CytologiCreated + ) + VALUES( + {$prm[0]['orderdetail_id']}, + {$doctor_id}, + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } + else{ + $sql = "SELECT * FROM other_cytologi WHERE Other_CytologiT_OrderDetailID = {$prm[0]['orderdetail_id']} AND Other_CytologiIsActive = 'Y'"; + $data_header = $this->db_smartone->query($sql)->row_array(); + $header_id = $data_header['Other_CytologiID']; + $sql = "UPDATE other_cytologi SET + Other_CytologiM_DoctorID = {$doctor_id}, + Other_CytologiUserID = {$userid} + WHERE + Other_CytologiID = {$header_id}"; + $this->db_smartone->query($sql); + } + foreach($prm as $k => $v){ + if($v['xid'] == '0'){ + $results = str_replace("'", "\\'", $v['result']); + $sql = "INSERT INTO other_cytologidetails( + Other_CytologiDetailsOther_CytologiID , + Other_CytologiDetailsCode, + Other_CytologiDetailsLabel, + Other_CytologiDetailsResult, + Other_CytologiDetailsCreated, + Other_CytologiDetailsUserID + ) + VALUES( + {$header_id}, + '{$v['code']}', + '{$v['label']}', + '{$results}', + NOW(), + {$userid} + )"; + $query = $this->db_smartone->query($sql); + } + else{ + $results = str_replace("'", "\\'", $v['result']); + $sql = "UPDATE other_cytologidetails SET + Other_CytologiDetailsResult = '{$results}', + Other_CytologiDetailsUserID = {$userid} + WHERE + Other_CytologiDetailsID = {$v['xid']}"; + $query = $this->db_smartone->query($sql); + } + } + + $result = array("total" => 1, "records" => array(), "sql"=> ''); + $this->sys_ok($result); + exit; + } + + function saveresult_mikro() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = $inp['doctor']; + $backteria_id = $inp['bacteria']; + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + + if($inp['result_value'] != 'Negatif' && $inp['result_value'] != 'Positif'){ + $prm['result_value'] = $prm['result_other']; + } + else{ + $prm['result_value'] = $inp['result_value']; + } + + if($prm['xid'] == '0'){ + $sql = "INSERT INTO other_mikro( + Other_MikroM_DoctorID, + Other_MikroResult, + Other_MikroT_BacteriaID, + Other_MikroT_OrderDetailID, + Other_MikroHasilBiakan, + Other_MikroSampleTypeName, + Other_MikroUserID, + Other_MikroCreated + ) + VALUES( + {$doctor_id}, + '{$prm['result_value']}', + {$backteria_id}, + {$prm['orderdetail_id']}, + '{$prm['hasil_biakan']}', + '{$prm['sample_name']}', + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } + else{ + $sql = "SELECT * FROM other_mikro WHERE Other_MikroT_OrderDetailID = {$prm['orderdetail_id']} AND Other_MikroIsActive = 'Y'"; + $data_header = $this->db_smartone->query($sql)->row_array(); + $header_id = $data_header['Other_MikroID']; + $sql = "UPDATE other_mikro SET + Other_MikroResult = '{$prm['result_value']}', + Other_MikroM_DoctorID = {$doctor_id}, + Other_MikroT_BacteriaID = {$backteria_id}, + Other_MikroHasilBiakan = '{$prm['hasil_biakan']}', + Other_MikroSampleTypeName = '{$prm['sample_name']}', + Other_MikroUserID = {$userid} + WHERE + Other_MikroID = {$header_id}"; + //echo $sql; + $this->db_smartone->query($sql); + } + + + + $sql = "UPDATE other_mikrodetails SET Other_MikroDetailsIsActive = 'N', Other_MikroDetailsUserID = 0 WHERE Other_MikroDetailsOther_MikroID = {$header_id}"; + $this->db_smartone->query($sql); + + $results = $prm['details']; + if($inp['result_value'] == 'Positif'){ + foreach($results as $k => $v){ + if($v['xid'] == '0'){ + $sql = "INSERT INTO other_mikrodetails( + Other_MikroDetailsOther_MikroID , + Other_MikroDetailsT_AntibioticID, + Other_MikroDetailsValue, + Other_MikroDetailsNote, + Other_MikroDetailsCreated, + Other_MikroDetailsUserID + ) + VALUES( + {$header_id}, + '{$v['T_AntibioticID']}', + '{$v['value']}', + '{$v['note']}', + NOW(), + {$userid} + )"; + $query = $this->db_smartone->query($sql); + } + else{ + $sql = "UPDATE other_mikrodetails SET + Other_MikroDetailsT_AntibioticID = '{$v['T_AntibioticID']}', + Other_MikroDetailsValue = '{$v['value']}', + Other_MikroDetailsNote = '{$v['note']}', + Other_MikroDetailsIsActive = 'Y', + Other_MikroDetailsUserID = {$userid} + WHERE + Other_MikroDetailsID = {$v['xid']}"; + //echo $sql; + $query = $this->db_smartone->query($sql); + } + } + } + + + $result = array("total" => 1, "records" => array(), "sql"=> ''); + $this->sys_ok($result); + exit; + } + + + function get_doctors_preparasi_sperma() + { + $prm = $this->sys_input; + // $id = $prm["id"]; + + $sql = " SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 10 AND + M_DoctorSOIsActive = 'Y' + ORDER BY M_DoctorName ASC"; + //echo $sql; + $query = $this->db_smartone->query($sql); + + if ($query) + { + $rows = $query->result_array(); + $this->sys_ok(["records"=>$rows]); + } + else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + + function getpreparasispermaresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT other_preparasisperma.*, + Other_PreparasiSpermaID as xid, + Other_PreparasiSpermaT_OrderDetailID as orderdetail_id, + IFNULL(Other_PreparasiSpermaM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_PreparasiSpermaM_DoctorID) OR Other_PreparasiSpermaM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_preparasisperma + LEFT JOIN m_doctor ON Other_PreparasiSpermaM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_PreparasiSpermaT_OrderDetailID = {$id} AND Other_PreparasiSpermaIsActive = 'Y' + GROUP BY Other_PreparasiSpermaID"; + $query = $this->db_smartone->query($sql); + + if ($query) + { + $rows = $query->row_array(); + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 10 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $images = array(); + $sql = "SELECT Other_PreparasiSpermaImgID as xid, + Other_PreparasiSpermaImgType as type, + CONCAT('/one-media/one-image-nonlab/',Other_PreparasiSpermaImgNewName) as image_url + FROM t_orderdetail + JOIN other_preparasisperma_img ON Other_PreparasiSpermaImgT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND + Other_PreparasiSpermaImgIsActive = 'Y' + WHERE + T_OrderDetailID = {$id} AND + T_OrderDetailIsActive = 'Y' + GROUP BY Other_PreparasiSpermaImgID"; + //echo $sql; + $images = $this->db_smartone->query($sql)->result_array(); + + $rst = array('doctors'=>$doctors,'results'=>$rows,'images'=>$images); + $this->sys_ok(["records"=>$rst]); + } + else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + + function uploadimage_preparasi_sperma(){ + if (! $this->isLogin) { + $this->sys_error("Invalid Token"); + exit; + } + + $userid = $this->sys_user["M_UserID"]; + $data = []; + //print_r($_SERVER); + + $prm = $this->sys_input; + $orderid = $this->input->post('orderid'); + $type = $this->input->post('type'); + $labnumber = $this->input->post('labnumber'); + $sql = "UPDATE other_preparasisperma_img SET + Other_PreparasiSpermaImgIsActive = 'N', + Other_PreparasiSpermaImgUserID = {$userid} + WHERE + Other_PreparasiSpermaImgT_OrderHeaderID = {$orderid} AND + Other_PreparasiSpermaImgType = '{$type}'"; + //echo $sql; + $this->db_onedev->query($sql); + //$config['upload_path'] = 'assets/'; + + $path = '/home/one/project/one/one-media/one-image-nonlab/'; + //echo $path; + $config['upload_path'] = $path; + $config['allowed_types'] = 'jpg|jpeg|png|gif'; + + $config['max_size'] = '10000'; + $count = count($_FILES['files']['name']); + //echo $count; + $this->load->library('upload',$config); + + $error = []; + for($i=0;$i<$count;$i++){ + + + if(!empty($_FILES['files']['name'][$i])){ + + + + $_FILES['file']['name'] = $_FILES['files']['name'][$i]; + + $_FILES['file']['type'] = $_FILES['files']['type'][$i]; + + $_FILES['file']['tmp_name'] = $_FILES['files']['tmp_name'][$i]; + + $_FILES['file']['error'] = $_FILES['files']['error'][$i]; + + $_FILES['file']['size'] = $_FILES['files']['size'][$i]; + + + + $namex = $orderid.'-'.$labnumber.'-'.$this->generateRandomString(5); + //echo $namex; + + $config['file_name'] = $namex; + $this->upload->initialize($config); + //echo $config['file_name'] ; + + + + + + if($this->upload->do_upload('file')){ + + $uploadData = $this->upload->data(); + + $filename = $uploadData['file_name']; + //echo $filename; + + + $sql = "INSERT INTO other_preparasisperma_img ( + Other_PreparasiSpermaImgT_OrderHeaderID, + Other_PreparasiSpermaImgType, + Other_PreparasiSpermaImgOldName, + Other_PreparasiSpermaImgNewName, + Other_PreparasiSpermaImgCreated, + Other_PreparasiSpermaImgUserID + ) + VALUES( + {$orderid}, + '{$type}', + '{$_FILES['files']['name'][$i]}', + '{$filename}', + NOW(), + {$userid} + + )"; + //echo $sql; + $this->db_onedev->query($sql); + $xlast_id = $this->db_onedev->insert_id(); + $data['totalFiles'][] = array('xid' => $xlast_id ,'type'=>$type,'image_url' => '/one-media/one-image-nonlab/'.$filename); + + } + else{ + $error = array('error' => $this->upload->display_errors()); + } + + } + + + + } + + $result = array("total" =>count( $data['totalFiles']), "records" => $data['totalFiles'],'errors'=>$error); + $this->sys_ok($result); + } + + + function saveresult_preparasi_sperma() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = $inp['doctor']; + $orderdetail_id = $inp['orderdetailid']; + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + if($prm['xid'] == '0'){ + $sql = "INSERT INTO other_preparasisperma( + Other_PreparasiSpermaM_DoctorID, + Other_PreparasiSpermaT_OrderDetailID, + Other_PreparasiSpermaPreMotilitasA, + Other_PreparasiSpermaPreMotilitasB, + Other_PreparasiSpermaPreMotilitasC, + Other_PreparasiSpermaPreKonsentrasi, + Other_PreparasiSpermaPreKontaminan, + Other_PreparasiSpermaPostMotilitasA, + Other_PreparasiSpermaPostMotilitasB, + Other_PreparasiSpermaPostMotilitasC, + Other_PreparasiSpermaPostKonsentrasi, + Other_PreparasiSpermaPostKontaminan, + Other_PreparasiSpermaNote, + Other_PreparasiSpermaUserID, + Other_PreparasiSpermaCreated + ) + VALUES( + {$doctor_id}, + {$orderdetail_id}, + '{$prm['Other_PreparasiSpermaPreMotilitasA']}', + '{$prm['Other_PreparasiSpermaPreMotilitasB']}', + '{$prm['Other_PreparasiSpermaPreMotilitasC']}', + '{$prm['Other_PreparasiSpermaPreKonsentrasi']}', + '{$prm['Other_PreparasiSpermaPreKontaminan']}', + '{$prm['Other_PreparasiSpermaPostMotilitasA']}', + '{$prm['Other_PreparasiSpermaPostMotilitasB']}', + '{$prm['Other_PreparasiSpermaPostMotilitasC']}', + '{$prm['Other_PreparasiSpermaPostKonsentrasi']}', + '{$prm['Other_PreparasiSpermaPostKontaminan']}', + '{$prm['Other_PreparasiSpermaNote']}', + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } + else{ + $sql = "SELECT * FROM other_preparasisperma WHERE Other_PreparasiSpermaT_OrderDetailID = {$orderdetail_id} AND Other_PreparasiSpermaIsActive = 'Y'"; + $data_header = $this->db_smartone->query($sql)->row_array(); + $header_id = $data_header['Other_PreparasiSpermaID']; + $sql = "UPDATE other_preparasisperma SET + Other_PreparasiSpermaM_DoctorID = {$doctor_id}, + Other_PreparasiSpermaPreMotilitasA = '{$prm['Other_PreparasiSpermaPreMotilitasA']}', + Other_PreparasiSpermaPreMotilitasB = '{$prm['Other_PreparasiSpermaPreMotilitasB']}', + Other_PreparasiSpermaPreMotilitasC = '{$prm['Other_PreparasiSpermaPreMotilitasC']}', + Other_PreparasiSpermaPreKonsentrasi = '{$prm['Other_PreparasiSpermaPreKonsentrasi']}', + Other_PreparasiSpermaPreKontaminan = '{$prm['Other_PreparasiSpermaPreKontaminan']}', + Other_PreparasiSpermaPostMotilitasA = '{$prm['Other_PreparasiSpermaPostMotilitasA']}', + Other_PreparasiSpermaPostMotilitasB = '{$prm['Other_PreparasiSpermaPostMotilitasB']}', + Other_PreparasiSpermaPostMotilitasC = '{$prm['Other_PreparasiSpermaPostMotilitasC']}', + Other_PreparasiSpermaPostKonsentrasi = '{$prm['Other_PreparasiSpermaPostKonsentrasi']}', + Other_PreparasiSpermaPostKontaminan = '{$prm['Other_PreparasiSpermaPostKontaminan']}', + Other_PreparasiSpermaNote = '{$prm['Other_PreparasiSpermaNote']}', + Other_PreparasiSpermaUserID = {$userid} + WHERE + Other_PreparasiSpermaID = {$header_id}"; + $this->db_smartone->query($sql); + } + + + $result = array("total" => 1, "records" => array(), "sql"=> ''); + $this->sys_ok($result); + exit; + } + + function getdnafragmentasiresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT other_dnafragmentasi.*, + Other_DnaFragmentasiID as xid, + Other_DnaFragmentasiT_OrderDetailID as orderdetail_id, + IFNULL(Other_DnaFragmentasiM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_DnaFragmentasiM_DoctorID) OR Other_DnaFragmentasiM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name, + IFNULL(Other_DnaFragmentasiOther_DnaFragmentasiMethodeID,0) as methode_id, + IFNULL(Other_DnaFragmentasiMethodeName,'') as methode_name, + Other_DnaFragmentasiHaloLuas as halo_luas, + Other_DnaFragmentasiHaloSedang as halo_sedang, + Other_DnaFragmentasiHaloSempit as halo_sempit, + Other_DnaFragmentasiTanpaHalo as tanpa_halo, + Other_DnaFragmentasiDFI as dfi, + Other_DnaFragmentasiKesimpulan as kesimpulan, + Other_DnaFragmentasiCatatan as catatan + FROM other_dnafragmentasi + LEFT JOIN m_doctor ON Other_DnaFragmentasiM_DoctorID = M_DoctorID + LEFT JOIN other_dnafragmentasimethode ON Other_DnaFragmentasiOther_DnaFragmentasiMethodeID = Other_DnaFragmentasiMethodeID + WHERE + Other_DnaFragmentasiT_OrderDetailID = {$id} AND Other_DnaFragmentasiIsActive = 'Y' + GROUP BY Other_DnaFragmentasiID + LIMIT 1"; + //echo $sql; + $query = $this->db_smartone->query($sql); + + if ($query) + { + $rows = $query->row_array(); + if(!$rows){ + $rows = array( + 'xid' => 0, + 'orderdetail_id' =>$id, + 'doctor_id' => 0, + 'doctor_name' => '', + 'methode_id' => 0, + 'methode_name' => '', + 'halo_luas' => '', + 'halo_sedang' => '', + 'tanpa_halo' => '', + 'dfi' => '', + 'kesimpulan' => '', + 'catatan' => '' + ); + } + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID + WHERE + M_DoctorSONat_SubGroupID = 4 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + + $sql = " + SELECT '0' as id, 'Belum memilih metode' as name + UNION + SELECT Other_DnaFragmentasiMethodeID as id, Other_DnaFragmentasiMethodeName as name + FROM other_dnafragmentasimethode + WHERE + Other_DnaFragmentasiMethodeIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $methodes = $this->db_smartone->query($sql)->result_array(); + + + $rst = array('doctors'=>$doctors,'methodes'=>$methodes,'results'=>$rows); + $this->sys_ok(["records"=>$rst]); + } + else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + function saveresult_dnafragmentasi() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = $inp['doctor']['id']; + $methode_id = $inp['methode']['id']; + $orderdetail_id = $inp['results']['orderdetail_id']; + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + if(intval($prm['xid']) == 0){ + $sql = "INSERT INTO other_dnafragmentasi( + Other_DnaFragmentasiT_OrderDetailID, + Other_DnaFragmentasiM_DoctorID, + Other_DnaFragmentasiOther_DnaFragmentasiMethodeID, + Other_DnaFragmentasiHaloLuas, + Other_DnaFragmentasiHaloSedang, + Other_DnaFragmentasiHaloSempit, + Other_DnaFragmentasiTanpaHalo, + Other_DnaFragmentasiDFI, + Other_DnaFragmentasiKesimpulan, + Other_DnaFragmentasiCatatan, + Other_DnaFragmentasiUserID, + Other_DnaFragmentasiLastUpdated + ) + VALUES( + {$orderdetail_id}, + {$doctor_id}, + {$methode_id}, + '{$prm['halo_luas']}', + '{$prm['halo_sedang']}', + '{$prm['halo_sempit']}', + '{$prm['tanpa_halo']}', + '{$prm['dfi']}', + '{$prm['kesimpulan']}', + '{$prm['catatan']}', + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } + else{ + $sql = "UPDATE other_dnafragmentasi SET + Other_DnaFragmentasiT_OrderDetailID = {$orderdetail_id}, + Other_DnaFragmentasiM_DoctorID = {$doctor_id}, + Other_DnaFragmentasiOther_DnaFragmentasiMethodeID = '{$methode_id}', + Other_DnaFragmentasiHaloLuas = '{$prm['halo_luas']}', + Other_DnaFragmentasiHaloSedang = '{$prm['halo_sedang']}', + Other_DnaFragmentasiHaloSempit = '{$prm['halo_sempit']}', + Other_DnaFragmentasiTanpaHalo = '{$prm['tanpa_halo']}', + Other_DnaFragmentasiDFI = '{$prm['dfi']}', + Other_DnaFragmentasiKesimpulan = '{$prm['kesimpulan']}', + Other_DnaFragmentasiCatatan = '{$prm['catatan']}', + Other_DnaFragmentasiLastUpdated = NOW(), + Other_DnaFragmentasiUserID = {$userid} + WHERE + Other_DnaFragmentasiID = {$prm['xid']}"; + //echo $sql; + $this->db_smartone->query($sql); + } + + + $result = array("total" => 1, "records" => array(), "sql"=> ''); + $this->sys_ok($result); + exit; + } + + +} + diff --git a/application/controllers/mockup/process/resultentry-westone-030925/Re_px.php b/application/controllers/mockup/process/resultentry-westone-030925/Re_px.php index ae3abcaf..cf16ddfb 100644 --- a/application/controllers/mockup/process/resultentry-westone-030925/Re_px.php +++ b/application/controllers/mockup/process/resultentry-westone-030925/Re_px.php @@ -1,2986 +1,2983 @@ -db_smartone = $this->load->database("onedev", true); - $this->db_lab = $this->load->database('one_lab_log', TRUE); - $this->load->helper(array('form', 'url')); - } - function getMethodeID($natTestID) - { - $sql = "select M_MethodePriorityNat_MethodeID MethodeID, Nat_MethodeName - from - m_methode_priority - join nat_methode on Nat_MethodeID = M_MethodePriorityNat_MethodeID - and Nat_MethodeIsActive = 'Y' - join m_instrumentmethode on M_InstrumentMethodeNat_MethodeID = Nat_MethodeID and M_InstrumentMethodeIsActive = 'Y' - join nat_instrument on M_InstrumentMethodeNat_InstrumentID = Nat_InstrumentID - and Nat_InstrumentIsActive ='Y' - where M_MethodePriorityIsActive = 'Y' - and M_MethodePriorityNat_TestID = $natTestID - and M_MethodePriorityM_DayOfWeekID = dayofweek(now()) - order by M_MethodePriorityNumber desc - limit 0,1 "; - $qry = $this->db->query($sql); - if ($qry) { - $rows = $qry->result_array(); - if (count($rows) > 0) return array($rows[0]["MethodeID"], $rows[0]["Nat_MethodeName"]); - } - //2nd - $sql = "select - M_InstrumentMethodeNat_MethodeID MethodeID, Nat_MethodeName - from m_instrumentmethode - join nat_methode on M_InstrumentMethodeNat_MethodeID = Nat_MethodeID - and Nat_MethodeIsActive = 'Y' - join nat_instrument on M_InstrumentMethodeNat_InstrumentID = Nat_InstrumentID - and Nat_InstrumentIsActive ='Y' - where M_InstrumentMethodeNat_TestID = $natTestID - and M_InstrumentMethodeIsActive = 'Y' - order by M_InstrumentMethodePriority desc - limit 0,1"; - $qry = $this->db->query($sql); - if ($qry) { - $rows = $qry->result_array(); - if (count($rows) > 0) return array($rows[0]["MethodeID"], $rows[0]["Nat_MethodeName"]); - } - // - $sql = "select Nat_NormalValueNat_MethodeID MethodeID, Nat_MethodeName - from - nat_normalvalue - join nat_methode on Nat_NormalValueNat_MethodeID = Nat_MethodeID - and Nat_MethodeIsActive = 'Y' - where Nat_NormalValueNat_TestID = $natTestID - and Nat_NormalValueIsActive = 'Y' - order by Nat_NormalValueID - limit 0,1"; - $qry = $this->db->query($sql); - if ($qry) { - $rows = $qry->result_array(); - if (count($rows) > 0) return array($rows[0]["MethodeID"], $rows[0]["Nat_MethodeName"]); - } - return array(0, ""); - } - function get_normal_value($methodeID, $natTestID, $sexID, $ageInDay) - { - $sql = "select fn_sampling_get_normal($methodeID, $natTestID, $sexID, $ageInDay) as normalValueID"; - $qry = $this->db->query($sql); - if ($qry) { - $rows = $qry->result_array(); - if (count($rows) > 0) return $rows[0]["normalValueID"]; - } - return 0; - } - function fn_fix_normal($order_id) - { - $sql = "select - T_OrderDetailID, M_PatientM_SexID, fn_global_age_count_day(M_PatientDOB, date(T_OrderHeaderDate)) Dob , - T_TestNat_TestID - from t_orderheader - join m_patient on T_OrderHeaderID = $order_id and T_OrderHeaderM_PatientID = M_PatientID - join t_orderdetail on T_OrderDetailT_OrderHeaderID = T_OrderHeaderID - and T_OrderDetailIsACtive = 'Y' - and ( T_OrderDetailNat_NormalValueID is null or T_OrderDetailNat_NormalValueID = 0 ) - join t_test on T_OrderDetailT_TestID = T_TestID and T_TestIsResult = 'Y' "; - $qry = $this->db->query($sql); - if (! $qry) { - return; - } - $rows = $qry->result_array(); - if (count($rows) == 0) return; - $sql_u = "update t_orderdetail - join nat_normalvalue on T_OrderDetailID = ? and Nat_NormalValueID = ? - set - T_OrderDetailNat_NormalValueID = Nat_NormalValueID, - T_OrderDetailNormalValueNote = Nat_NormalValueNote, - T_OrderDetailNormalValueDescription = Nat_NormalValueDescription, - T_OrderDetailMinValue = Nat_NormalValueMinValue, - T_OrderDetailMaxValue = Nat_NormalValueMaxValue, - T_OrderDetailMinValueInclusive = Nat_NormalValueMinValueInclusive, - T_OrderDetailMaxValueInclusive = Nat_NormalValueMaxValueInclusive, - T_OrderDetailNat_MethodeID = ?, - T_OrderdetailNat_MethodeName =?"; - - foreach ($rows as $r) { - $T_OrderDetailID = $r["T_OrderDetailID"]; - $sexID = $r["M_PatientM_SexID"]; - $ageInDay = $r["Dob"]; - $natTestID = $r["T_TestNat_TestID"]; - list($methodeID, $methodeName) = $this->getMethodeID($natTestID); - if ($methodeID == 0) continue; - $normalValueID = $this->get_normal_value($methodeID, $natTestID, $sexID, $ageInDay); - if ($normalValueID == 0) return; - $this->db->query($sql_u, array($T_OrderDetailID, $normalValueID, $methodeID, $methodeName)); - } - } - function update_order_sample($targetID, $sourceID) - { - $sql = "update t_ordersample target - join t_ordersample source on - target.T_OrderSampleID = ? - and target.T_OrderSampleWorklistReceive = 'N' - and source.T_OrderSampleID = ? - set - target.T_OrderSampleSampling = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSampling, source.T_OrderSampleSampling), - target.T_OrderSampleSamplingDate = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingDate, source.T_OrderSampleSamplingDate), - target.T_OrderSampleSamplingTime = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingTime, source.T_OrderSampleSamplingTime), - target.T_OrderSampleSamplingUserID = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingUserID, source.T_OrderSampleSamplingUserID), - - target.T_OrderSampleReceive = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceive, source.T_OrderSampleReceive), - target.T_OrderSampleReceiveDate = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveDate, source.T_OrderSampleReceiveDate), - target.T_OrderSampleReceiveTime = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveTime, source.T_OrderSampleReceiveTime), - target.T_OrderSampleReceiveUserID = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveUserID, source.T_OrderSampleReceiveUserID), - - target.T_OrderSampleVerification = if(target.T_OrderSampleVerification='Y',target.T_OrderSampleVerification, source.T_OrderSampleVerification), - target.T_OrderSampleVerificationDate =if(target.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationDate, source.T_OrderSampleVerificationDate), - target.T_OrderSampleVerificationTime =if(source.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationTime, source.T_OrderSampleVerificationTime), - target.T_OrderSampleVerificationUserID =if(source.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationUserID, source.T_OrderSampleVerificationUserID), - - target.T_OrderSampleProcessing = if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessing, source.T_OrderSampleProcessing), - target.T_OrderSampleProcessingDate= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingDate, source.T_OrderSampleProcessingDate), - target.T_OrderSampleProcessingTime= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingTime, source.T_OrderSampleProcessingTime), - target.T_OrderSampleProcessingUserID= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingUserID, source.T_OrderSampleProcessingUserID), - - target.T_OrderSampleReceiveHandling =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandling, source.T_OrderSampleReceiveHandling ), - target.T_OrderSampleReceiveHandlingDate =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingDate, source.T_OrderSampleReceiveHandlingDate), - target.T_OrderSampleReceiveHandlingTime =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingTime, source.T_OrderSampleReceiveHandlingTime), - target.T_OrderSampleReceiveHandlingUserID =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingUserID, source.T_OrderSampleReceiveHandlingUserID), - - target.T_OrderSampleHandling = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandling, source.T_OrderSampleHandling), - target.T_OrderSampleHandlingDate = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingDate, source.T_OrderSampleHandlingDate), - target.T_OrderSampleHandlingTime = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingTime, source.T_OrderSampleHandlingTime), - target.T_OrderSampleHandlingUserID = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingUserID, source.T_OrderSampleHandlingUserID), - - target.T_OrderSampleWorklistReceive = source.T_OrderSampleWorklistReceive, - target.T_OrderSampleWorklistReceiveDatetime = source.T_OrderSampleWorklistReceiveDateTime, - target.T_OrderSampleWorklistReceiveUserID = source.T_OrderSampleWorklistReceiveUserID - "; - $qry = $this->db->query($sql, array($targetID, $sourceID)); - if (! $qry) { - echo json_encode(array("status" => "ERR", "message" => print_r($this->db->error(), true))); - exit; - } - } - function fix_sample_serum($headerID) - { - //cari t_ordersample yg belum worklist receive dengan code 017% - $sql = "select T_OrderSampleID - from t_ordersample - join t_sampletype on - T_OrderSampleT_OrderHeaderID = ? - and T_OrderSampleWorklistReceive = 'N' - and T_OrderSampleIsActive = 'Y' - and T_OrderSampleT_SampleTypeID = T_SampletypeID - and T_SampleTypeCode like '017%' - "; - $qry = $this->db->query($sql, array($headerID)); - if (!$qry) { - echo json_encode(array("status" => "ERR", "message" => print_r($this->db->error(), true))); - exit; - } - $rows = $qry->result_array(); - if (count($rows) == 0) return; - //cari T_OrderSample yang sudah di receive yg terakhir - $sql = "select T_OrderSampleID - from t_ordersample - join t_sampletype on - T_OrderSampleT_OrderHeaderID = ? - and T_OrderSampleWorklistReceive = 'Y' - and T_OrderSampleIsActive = 'Y' - and T_OrderSampleT_SampleTypeID = T_SampletypeID - and T_SampleTypeCode like '017%' - order by T_OrderSampleWorklistReceiveDatetime desc - limit 0,1 - "; - $qry = $this->db->query($sql, array($headerID)); - if (!$qry) { - echo json_encode(array("status" => "ERR", "message" => print_r($this->db->error(), true))); - exit; - } - $rcv_rows = $qry->result_array(); - if (count($rcv_rows) == 0) return; - - //print_r($rows); - //print_r($rcv_rows); - $rcv_T_OrderSampleID = $rcv_rows[0]["T_OrderSampleID"]; - //ada yg belum di receive - foreach ($rows as $r) { - $T_OrderSampleID = $r["T_OrderSampleID"]; - $this->update_order_sample($T_OrderSampleID, $rcv_T_OrderSampleID); - } - } - public function search() - { - $prm = $this->sys_input; - $max_rst = 99; - - $id = $prm["order_id"]; - if ($id > 0) { - $this->fix_sample_serum($id); - $this->fn_fix_normal($id); - } - $lang = $this->lang_default_code; - $lang_id = isset($prm['lang_id']) ? $prm['lang_id'] : '0'; - - if ($lang_id != 0) { - $l = $this->db_smartone->where("Nat_LangID", $lang_id)->get("nat_lang")->row(); - $lang = $l->Nat_LangCode; - } - - //tambahan fajri - $sql = " UPDATE t_orderdetail - JOIN t_test ON T_OrderDetailT_TestID = T_TestID - SET T_OrderDetailT_TestIsResult = T_TestIsResult - WHERE - T_OrderDetailT_OrderHeaderID = {$id} AND - T_OrderDetailT_TestIsResult = '' AND - T_OrderDetailIsActive = 'Y'"; - $this->db_smartone->query($sql); - - $tot_count = 0; - $lq = ""; - $group_id = 0; - if (isset($prm['group_id'])) - $group_id = $prm['group_id']; - - if ($group_id != 0) { - $sql = "select distinct T_WorklistDetailNat_TestID Nat_TestID - from t_worklistdetailv2 - where T_WorklistDetailT_WorklistID = {$group_id}"; - $qry = $this->db_smartone->query($sql); - $rows = $qry->result_array(); - $nat_test_ids = "0"; - foreach ($rows as $r) { - $nat_test_ids .= ", " . $r["Nat_TestID"]; - } - $q_group = " ( $nat_test_ids ) "; - - $sql = " - SELECT a1.*, cOUNT(a2.T_OrderDetailID) level - FROM ( - SELECT IFNULL(y.T_OrderDetailT_TestID, x.T_OrderDetailT_TestID) t_testid, - IFNULL(y.T_OrderDetailT_TestName, y.T_OrderDetailT_TestName) t_testname, - y.T_OrderDetailResult result, y.T_OrderDetailResult result_old, y.T_OrderDetailNote note, y.T_OrderDetailNote note_old, - y.T_OrderDetailID id, - y.T_OrderDetailT_TestIsResult is_result, a.T_TestIsQuantitative is_quantitative, - y.T_OrderDetailResultFlag result_flag, - y.T_OrderDetailNat_NormalValueID normal_id, - y.T_OrderDetailNormalValueNote normal_note, y.T_OrderDetailNat_UnitName unit_name, - y.T_OrderdetailNat_MethodeID methode_id, y.T_OrderdetailNat_MethodeName methode_name, - a.T_TestNat_TestID nattest_id, a.T_TestID tx_id, count(T_ResultInstrumentID) as result_instrument_n, - y.T_OrderDetailVerification, T_OrderSampleReceive sample_receive, - T_OrderSampleProcessing sample_processing, T_OrderSampleWorklistReceive sample_worklist_receive, - IF(T_OrderDetailAddOnPreAnalytic = 'Y', T_OrderDetailAddOnPreAnalytic, PreAnalyticIsOk) pre_analytic, - T_OrderDetailAddOnPreAnalytic, - T_OrderHeaderID order_id, y.T_OrderDetailT_TestSasCode test_sas_code, - tx.T_TestSasCode, - T_OrderDetailAddOnResample `resample`, T_OrderDetailAddOnResampleStatus resample_status, - T_OrderDetailAddOnRef ref, y.T_OrderDetailVerification verification, y.T_OrderDetailValidation validation, - T_OrderPromiseDateTime, Group_ResultName as ResultGroupName - FROM t_orderdetail x - left join t_orderpromise on x.T_OrderDetailT_OrderPromiseID = T_OrderPromiseID - JOIN t_test tx ON x.T_OrderDetailT_TestID = T_TestID - JOIN t_test tcheck on tcheck.T_TestNat_TestID in {$q_group} - and ( tx.T_TestID = tcheck.T_TestID or tx.T_TestSasCode like concat(tcheck.T_TestSasCode,'%')) - JOIN group_resultdetail ON Group_ResultDetailT_TestID = x.T_OrderDetailT_TestID AND Group_ResultDetailIsActive = 'Y' - JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND Group_ResultResumeMcu = 'LAB' - LEFT JOIN t_orderdetail y ON x.T_OrderDetailT_TestSasCode LIKE CONCAT(y.T_OrderDetailT_TestSasCode, '%') - AND x.T_OrderDetailT_OrderHeaderID = y.T_OrderDetailT_OrderHeaderID - AND y.T_OrderDetailIsActive = 'Y' - LEFT JOIN t_orderdetailaddon ON x.T_OrderDetailID = T_OrderDetailAddOnT_OrderDetailID - JOIN t_orderheader ON y.T_OrderDetailT_OrderHeaderID = T_OrderHeaderID - LEFT JOIN t_test a ON y.T_OrderDetailT_TestID = a.T_TestID - AND a.T_TestIsNonLab = '' - LEFT JOIN (SELECT T_OrderSampleT_SampleTypeID, T_OrderSampleReceive, T_OrderSampleProcessing, T_OrderSampleWorklistReceive - FROM t_ordersample WHERE T_OrderSampleT_OrderHeaderID = {$id} - AND T_OrderSampleIsactive = 'Y' - GROUP BY T_OrderSampleT_SampleTypeID) os ON a.T_TestT_SampleTypeID = os.T_OrderSampleT_SampleTypeID - or os.T_OrderSampleT_SampleTypeID = fn_sampletype_from_local(a.T_TestNat_TestID) - - LEFT JOIN t_resultinstrument ON T_ResultInstrumentT_OrderDetailID = x.T_OrderDetailID - LEFT JOIN pre_analytic ON PreAnalyticNat_TestID = a.T_TestNat_TestID AND PreAnalyticDate = date(now()) and PreAnalyticIsActive = 'Y' - WHERE x.T_OrderDetailT_OrderHeaderID = {$id} - AND x.T_OrderDetailIsActive = 'Y' - GROUP BY y.T_OrderDetailT_TestID - ORDER BY y.T_OrderDetailT_TestSasCode ASC - ) a1 - - LEFT JOIN t_orderdetail a2 ON a2.T_OrderDetailT_OrderHeaderID = a1.order_id - AND a2.T_OrderDetailIsActive = 'Y' - AND a1.test_sas_code LIKE CONCAT(a2.T_OrderDetailT_testSasCode, '%') - GROUP BY a1.t_testid - order by a1.test_sas_code -"; - $query = $this->db_smartone->query($sql); - $lq = $this->db_smartone->last_query(); - } else { - $sql = " - SELECT a1.*, cOUNT(a2.T_OrderDetailID) level - FROM ( - SELECT IFNULL(y.T_OrderDetailT_TestID, x.T_OrderDetailT_TestID) t_testid, - IFNULL(y.T_OrderDetailT_TestName, y.T_OrderDetailT_TestName) t_testname, - y.T_OrderDetailResult result, y.T_OrderDetailResult result_old, y.T_OrderDetailNote note, y.T_OrderDetailNote note_old, - y.T_OrderDetailID id, - y.T_OrderDetailT_TestIsResult is_result, a.T_TestIsQuantitative is_quantitative, - y.T_OrderDetailResultFlag result_flag, - y.T_OrderDetailNat_NormalValueID normal_id, - y.T_OrderDetailNormalValueNote normal_note, y.T_OrderDetailNat_UnitName unit_name, - y.T_OrderdetailNat_MethodeID methode_id, y.T_OrderdetailNat_MethodeName methode_name, - a.T_TestNat_TestID nattest_id, a.T_TestID tx_id, count(T_ResultInstrumentID) as result_instrument_n, - y.T_OrderDetailVerification, T_OrderSampleReceive sample_receive, - T_OrderSampleProcessing sample_processing, T_OrderSampleWorklistReceive sample_worklist_receive, - IF(T_OrderDetailAddOnPreAnalytic = 'Y', T_OrderDetailAddOnPreAnalytic, PreAnalyticIsOk) pre_analytic, - T_OrderDetailAddOnPreAnalytic, - T_OrderHeaderID order_id, y.T_OrderDetailT_TestSasCode test_sas_code, - tx.T_TestSasCode, - T_OrderDetailAddOnResample `resample`, T_OrderDetailAddOnResampleStatus resample_status, - T_OrderDetailAddOnRef ref, y.T_OrderDetailVerification verification, y.T_OrderDetailValidation validation, - T_OrderPromiseDateTime , Group_ResultName as ResultGroupName - FROM t_orderdetail x - left join t_orderpromise on x.T_OrderDetailT_OrderPromiseID = T_OrderPromiseID - JOIN t_test tx ON x.T_OrderDetailT_TestID = T_TestID - JOIN group_resultdetail ON Group_ResultDetailT_TestID = x.T_OrderDetailT_TestID AND Group_ResultDetailIsActive = 'Y' - JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND Group_ResultResumeMcu = 'LAB' - LEFT JOIN t_orderdetail y ON x.T_OrderDetailT_TestSasCode LIKE CONCAT(y.T_OrderDetailT_TestSasCode, '%') - AND x.T_OrderDetailT_OrderHeaderID = y.T_OrderDetailT_OrderHeaderID - AND y.T_OrderDetailIsActive = 'Y' - - LEFT JOIN t_orderdetailaddon ON x.T_OrderDetailID = T_OrderDetailAddOnT_OrderDetailID - - JOIN t_orderheader ON y.T_OrderDetailT_OrderHeaderID = T_OrderHeaderID - LEFT JOIN t_test a ON y.T_OrderDetailT_TestID = a.T_TestID - AND a.T_TestIsNonLab = '' - LEFT JOIN (SELECT T_OrderSampleT_SampleTypeID, T_OrderSampleReceive, T_OrderSampleProcessing, T_OrderSampleWorklistReceive - FROM t_ordersample WHERE T_OrderSampleT_OrderHeaderID = {$id} - AND T_OrderSampleIsactive = 'Y' - GROUP BY T_OrderSampleT_SampleTypeID) os ON a.T_TestT_SampleTypeID = os.T_OrderSampleT_SampleTypeID - or os.T_OrderSampleT_SampleTypeID = fn_sampletype_from_local(a.T_TestNat_TestID) - - LEFT JOIN t_resultinstrument ON T_ResultInstrumentT_OrderDetailID = x.T_OrderDetailID - LEFT JOIN pre_analytic ON PreAnalyticNat_TestID = a.T_TestNat_TestID AND PreAnalyticDate = date(now()) and PreAnalyticIsActive = 'Y' - WHERE x.T_OrderDetailT_OrderHeaderID = {$id} - AND x.T_OrderDetailIsActive = 'Y' - GROUP BY y.T_OrderDetailT_TestID - ORDER BY y.T_OrderDetailT_TestSasCode ASC - ) a1 - - LEFT JOIN t_orderdetail a2 ON a2.T_OrderDetailT_OrderHeaderID = a1.order_id - AND a2.T_OrderDetailIsActive = 'Y' - AND a1.test_sas_code LIKE CONCAT(a2.T_OrderDetailT_testSasCode, '%') - GROUP BY a1.t_testid - order by a1.test_sas_code -"; - //echo $sql; - $query = $this->db_smartone->query($sql); - $lq = $this->db_smartone->last_query(); - } - // file_put_contents("/xtmp/re-query.sql",$lq); - - if ($query) { - $rst = []; - $rows = $query->result_array(); - - foreach ($rows as $k => $v) { - - if ($v['is_result'] == "Y" && $v['is_quantitative'] == "N") { - $v['template'] = []; - $x = $this->db_smartone->query("CALL sp_master_resulttemplate_get('{$v['t_testid']}')"); - $this->clean_mysqli_connection($this->db_smartone->conn_id); - if ($x) - $v['template'] = $x->result_array(); - } - - // IF Rujukan, by pas Pre Analytik - if ($v['ref'] == 'Y') - $v['pre_analytic'] = 'Y'; - if ($v["id"] == "885455") { - //sipe workaround - //$v["sample_receive"] = "Y"; - $v["sample_worklist_receive"] = "Y"; - } - $rst[] = $v; - } - - $result = array("total" => $tot_count, "records" => $rst, "total_display" => sizeof($rows), "q" => $lq); - $this->sys_ok($result); - } else { - $this->sys_error_db("RE Px rows", $this->db_smartone); - exit; - } - } - - public function save() - { - $prm = $this->sys_input; - $data = json_decode($prm["data"]); - $lang = $this->lang_default_code; - $lang_id = isset($prm['lang_id']) ? $prm['lang_id'] : '0'; - - if ($lang_id != 0) { - $l = $this->db_smartone->where("Nat_LangID", $lang_id)->get("nat_lang")->row(); - $lang = $l->Nat_LangCode; - } - - $sql_norm = "select T_OrderDetailMinValue, T_OrderDetailMaxValue, - T_OrderDetailMinValueInclusive, T_OrderDetailMaxValueInclusive, - Nat_TestFlagLow, Nat_TestFlagHigh - from t_orderdetail - join t_test on T_OrderDetailT_TestID = T_TestID - join nat_test on T_TestNat_TestID = Nat_TestID and T_TestIsActive = 'Y' - where T_OrderDetailID = ? "; - - $ids = []; - foreach ($data as $k => $v) { - if ($v->resultInstrumentID > 0) { - $sql_i = "select T_ResultInstrumentNat_NormalValueID normalValueID - from t_resultinstrument - where T_ResultInstrumentID = ?"; - $qry_i = $this->db_smartone->query($sql_i, array($v->resultInstrumentID)); - if ($qry_i) { - $rows_i = $qry_i->result_array(); - - if (count($rows_i) > 0) { - $sql_iu = "update t_orderdetail, nat_normalvalue , nat_methode - set T_OrderDetailMinValue = Nat_NormalValueMinValue, - T_OrderDetailMinValueInclusive = Nat_NormalValueMinValueInclusive, - T_OrderDetailMaxValue = Nat_NormalValueMaxValue , - T_OrderDetailMaxValueInclusive = Nat_NormalValueMaxValueInclusive, - T_OrderDetailNormalValueNote = Nat_NormalValueNote, - T_OrderDetailNormalValueDescription = Nat_NormalValueDescription, - T_OrderDetailNat_NormalValueID = Nat_NormalValueID, - T_OrderDetailNat_MethodeID = Nat_NormalValueNat_MethodeID, - T_OrderDetailNat_MethodeName = Nat_MethodeName - where T_OrderDetailID = ? and Nat_NormalValueID = ? - and Nat_NormalValueNat_MethodeID = Nat_MethodeID - "; - $this->db_smartone->query($sql_iu, array($v->id, $rows_i[0]["normalValueID"])); - //file_put_contents("/xtmp/update-nilai-normal", $this->db_smartone->last_query() . "\n", FILE_APPEND); - } - } - } - $y = $this->db_smartone->query("SELECT fn_process_sample_handling_perfect('{$v->order_id}', '{$v->test_id}') c") - ->row(); - $req_status = $y->c; - $qry_norm = $this->db_smartone->query($sql_norm, $v->id); - $result_flag = ""; - if ($qry_norm) { - $rows_norm = $qry_norm->result_array(); - if (count($rows_norm) > 0) { - $r = $rows_norm[0]; - if (is_numeric($v->result)) { - - if ($r["T_OrderDetailMinValueInclusive"] == "Y" && $v->result < $r["T_OrderDetailMinValue"]) { - $result_flag = $r["Nat_TestFlagLow"]; - } - if ($r["T_OrderDetailMinValueInclusive"] == "N" && $v->result <= $r["T_OrderDetailMinValue"]) { - $result_flag = $r["Nat_TestFlagLow"]; - } - if ($r["T_OrderDetailMaxValueInclusive"] == "Y" && $v->result > $r["T_OrderDetailMaxValue"]) { - $result_flag = $r["Nat_TestFlagHigh"]; - } - if ($r["T_OrderDetailMaxValueInclusive"] == "N" && $v->result >= $r["T_OrderDetailMaxValue"]) { - $result_flag = $r["Nat_TestFlagHigh"]; - } - } - } - } - if ($lang == $this->lang_default_code) { - $this->db_smartone->set('T_OrderDetailResult', $v->result) - ->set('T_OrderDetailResultFlag', $result_flag) - ->set('T_OrderDetailNote', $v->note) - ->set('T_OrderDetailReqStatus', $req_status) - ->where('T_OrderDetailID', $v->id) - ->update('t_orderdetail'); - } else { - $this->db_smartone->set('T_OrderDetailLangResult', $v->result) - ->set('T_OrderDetailLangNote', $v->note) - ->where('T_OrderDetailLangID', $v->id) - ->update('t_orderdetaillang'); - } - - - - $ids[] = $v->id; - - //log detail - - $sql = "SELECT COUNT(*) n FROM log_orderdetail WHERE Log_OrderDetailT_OrderDetailID = ? AND Log_OrderDetailResult = ? ORDER BY Log_OrderDetailID DESC LIMIT 1"; - $qry = $this->db_lab->query($sql, [$v->id, $v->result]); - if ($qry) { - $n = $qry->row(); - - if ($n->n == 0) { - $sql = "SELECT * FROM t_orderdetail WHERE T_OrderDetailID = ?"; - $qry_order = $this->db_smartone->query($sql, [$v->id]); - $dt_orderdetail = $qry_order->row(); - $dt_detail_log = json_encode($dt_orderdetail); - - $sql = "INSERT INTO log_orderdetail ( - Log_OrderDetailStatus, - Log_OrderDetailT_OrderDetailID, - Log_OrderDetailResult, - Log_OrderDetailJSON, - Log_OrderDetailCreated, - Log_OrderDetailUserID - ) - VALUES (?,?, ?, ?, NOW(), ?)"; - $this->db_lab->query($sql, ['RESULTENTRY',$v->id, $v->result, $dt_detail_log, $this->sys_user['M_UserID']]); - //echo $this->db_lab->last_query(); - //exit(); - } - } - } - - // LOG Process - $order = $this->db_smartone->select('T_OrderDetailT_OrderHeaderID id, T_OrderHeaderLabNumber lab_number', false) - ->join('t_orderheader', 'T_OrderHeaderID = T_OrderDetailT_OrderHeaderID') - ->where('T_OrderDetailID', $data[0]->id) - ->get('t_orderdetail') - ->row(); - - $dblog = $this->db_lab; - $dblog->set('Log_ProcessCode', 'PROCESS.Result.Entry') - ->set('Log_ProcessOrderID', $order->id) - ->set('Log_ProcessOrderNumber', $order->lab_number) - ->set('Log_ProcessJson', json_encode($data)) - ->set('Log_ProcessUserID', $this->sys_user['M_UserID']) - ->insert('log_process'); - // END OF Log Process - //auto calculation - $this->load->library("Resultcalc"); - $rows = $this->resultcalc->auto($order->id); - - try { - foreach ($ids as $id) { - $this->db_smartone->query("call sp_set_normal_value_flag($id)"); - $this->clean_mysqli_connection($this->db_smartone->conn_id); - } - } catch (Exception $e) { - } - - $this->sys_ok($ids); - } - - public function save_template() - { - $prm = $this->sys_input; - - $n = $this->db_smartone->select("COUNT(T_ResultTemplateID) n") - ->where("T_ResultTemplateT_TestID", $prm['test_id']) - ->where("T_ResultTemplateIsActive", "Y") - ->where("T_ResultTemplateValue", $prm['value']) - ->get('t_resulttemplate') - ->row(); - if ($n->n > 0) { - $this->sys_error_db("Insert Result Template", $this->db_smartone); - return; - } - - $r = $this->db_smartone->set("T_ResultTemplateT_TestID", $prm['test_id']) - ->set("T_ResultTemplateValue", $prm['value']) - ->insert('t_resulttemplate'); - if ($r) { - $template = []; - $x = $this->db_smartone->query("CALL sp_master_resulttemplate_get('{$prm['test_id']}')"); - $this->clean_mysqli_connection($this->db_smartone->conn_id); - if ($x) - $template = $x->result_array(); - - $this->sys_ok($template); - } - } - - public function export() - { - $prm = $this->sys_input; - - $sql = "CALL sp_process_result_lang(?, ?, ?, ?)"; - $query = $this->db_smartone->query($sql, [$prm['order_id'], $prm['lang_id'], $prm['is_si'], $this->sys_user['M_UserID']]); - if ($query) { - $r = $query->row(); - if ($r->status == "OK") { - $this->sys_ok($r->data); - return; - } - - $this->sys_error_db("Message : " . $r->message, $this->db_smartone); - } else { - $this->sys_error_db("Lang Result", $this->db_smartone); - return; - } - } - - public function search_group() - { - $prm = $this->sys_input; - $max_rst = 100; - - // QUERY TOTAL - $sql = "select count(*) total - from t_worklist - where T_WorklistIsActive = 'Y' - order by T_WorklistName ASC"; - $query = $this->db_smartone->query($sql); - - if ($query) { - $tot_count = $query->result_array()[0]["total"]; - } else { - $this->sys_error_db("worklist count", $this->db_smartone); - exit; - } - - $sql = "select T_WorklistID group_id, T_WorklistName group_name - from t_worklist - where T_WorklistIsActive = 'Y' - order by T_WorklistName ASC - limit 0, {$max_rst}"; - $query = $this->db_smartone->query($sql); - - if ($query) { - $rows = $query->result_array(); - foreach ($rows as $k => $v) - $rows[$k]['data'] = json_decode($v['data']); - $result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows), "q" => $this->db_smartone->last_query()); - $this->sys_ok($result); - } else { - $this->sys_error_db("worklist rows", $this->db_smartone); - exit; - } - } - - public function search_rerun() - { - $prm = $this->sys_input; - $id = $prm["detail_id"]; - - $sql = "CALL sp_process_result_rerun(?)"; - $query = $this->db_smartone->query($sql, [$id]); - - if ($query) { - $rows = $query->result_array(); - $this->sys_ok(["records" => $rows]); - } else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - - - function getdoctorsfna() - { - $prm = $this->sys_input; - // $id = $prm["id"]; - - $sql = " SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY M_DoctorName ASC"; - //echo $sql; - $query = $this->db_smartone->query($sql); - - if ($query) { - $rows = $query->result_array(); - $this->sys_ok(["records" => $rows]); - } else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - function getfnaresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT Other_FNADetailsID as xid, - Other_FNAT_OrderDetailID as orderdetail_id, - Other_FNADetailsCode as code, - Other_FNADetailsLabel as label, - Other_FNADetailsResult as result, - IFNULL(Other_FNAM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_FNAM_DoctorID) OR Other_FNAM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_fna - JOIN other_fnadetails ON Other_FNADetailsOther_FNAID = Other_FNAID AND Other_FNADetailsIsActive = 'Y' - LEFT JOIN m_doctor ON Other_FNAM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_FNAT_OrderDetailID = {$id} AND Other_FNAIsActive = 'Y' - GROUP BY Other_FNADetailsID - ORDER BY Other_FNADetailsCode ASC"; - $query = $this->db_smartone->query($sql); - - if ($query) { - $rows = $query->result_array(); - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $images = array(); - $sql = "SELECT So_ImageUploadID as xid, - CONCAT('/one-media/one-image-nonlab/',So_ImageUploadNewName) as image_url - FROM t_orderdetail - JOIN so_imageupload ON So_ImageUploadT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND - So_ImageUploadIsActive = 'Y' - WHERE - T_OrderDetailID = {$id} AND - T_OrderDetailIsActive = 'Y' - GROUP BY So_ImageUploadID"; - $images = $this->db_smartone->query($sql)->result_array(); - - $rst = array('doctors' => $doctors, 'results' => $rows, 'images' => $images); - $this->sys_ok(["records" => $rst]); - } else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - function getpatologianatomyresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT Other_PatologiAnatomyID as xid, - Other_PatologiAnatomyT_OrderDetailID as orderdetail_id, - Other_PatologiAnatomyNoSediaan as no_sediaan, - Other_PatologiAnatomyDiagnosaKlinis as diagnosa, - Other_PatologiAnatomyKeteranganKlinis as klinis, - Other_PatologiAnatomyLokasiOrgan as lokasi, - Other_PatologiAnatomyMakroskopik as makroskopik, - Other_PatologiAnatomyMikroskopik as mikroskopik, - Other_PatologiAnatomyKesimpulan as kesimpulan, - IFNULL(Other_PatologiAnatomyM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_PatologiAnatomyM_DoctorID) OR Other_PatologiAnatomyM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_patologi_anatomy - LEFT JOIN m_doctor ON Other_PatologiAnatomyM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_PatologiAnatomyT_OrderDetailID = {$id} AND Other_PatologiAnatomyIsActive = 'Y' - GROUP BY Other_PatologiAnatomyID - ORDER BY Other_PatologiAnatomyID ASC - LIMIT 1"; - $query = $this->db_smartone->query($sql); - - if ($query) { - $rows = $query->row_array(); - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - - $sql = "SELECT So_ImageUploadPatologyAnatomyID as xid, - CONCAT('/one-media/one-image-nonlab/',So_ImageUploadPatologyAnatomyNewName) as image_url, - So_ImageUploadPatologyAnatomyType as type - FROM t_orderdetail - JOIN so_imageupload_patology_anatomy ON So_ImageUploadPatologyAnatomyT_OrderHeaderID= T_OrderDetailT_OrderHeaderID AND - So_ImageUploadPatologyAnatomyIsActive= 'Y' - WHERE - T_OrderDetailID = {$id} AND - T_OrderDetailIsActive = 'Y' - GROUP BY So_ImageUploadPatologyAnatomyID"; - $images = $this->db_smartone->query($sql)->result_array(); - $mikro = []; - $makro = []; - - foreach ($images as $key => $value) { - - if ($value['type'] == 'mikro') { - $mikro[] = $value; - } - if ($value['type'] == 'makro') { - $makro[] = $value; - } - } - - $rst = array('doctors' => $doctors, 'result' => $rows, "mikro" => $mikro, "makro" => $makro); - $this->sys_ok(["records" => $rst]); - } else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - - - - function uploadimage() - { - if (! $this->isLogin) { - $this->sys_error("Invalid Token"); - exit; - } - - $userid = $this->sys_user["M_UserID"]; - $data = []; - //print_r($_SERVER); - - $prm = $this->sys_input; - $orderid = $this->input->post('orderid'); - $labnumber = $this->input->post('labnumber'); - $sql = "UPDATE so_imageupload SET - So_ImageUploadIsActive = 'N', - So_ImageUploadUserID = {$userid} - WHERE - So_ImageUploadT_OrderHeaderID = {$orderid}"; - //echo $sql; - $this->db_onedev->query($sql); - //$config['upload_path'] = 'assets/'; - - $path = '/home/one/project/one/one-media/one-image-nonlab/'; - //echo $path; - $config['upload_path'] = $path; - $config['allowed_types'] = 'jpg|jpeg|png|gif'; - - $config['max_size'] = '10000'; - $count = count($_FILES['files']['name']); - //echo $count; - $this->load->library('upload', $config); - - $error = []; - for ($i = 0; $i < $count; $i++) { - - - if (!empty($_FILES['files']['name'][$i])) { - - - - $_FILES['file']['name'] = $_FILES['files']['name'][$i]; - - $_FILES['file']['type'] = $_FILES['files']['type'][$i]; - - $_FILES['file']['tmp_name'] = $_FILES['files']['tmp_name'][$i]; - - $_FILES['file']['error'] = $_FILES['files']['error'][$i]; - - $_FILES['file']['size'] = $_FILES['files']['size'][$i]; - - - - $namex = $orderid . '-' . $labnumber . '-' . $this->generateRandomString(5); - //echo $namex; - - $config['file_name'] = $namex; - $this->upload->initialize($config); - //echo $config['file_name'] ; - - - - - - if ($this->upload->do_upload('file')) { - - $uploadData = $this->upload->data(); - - $filename = $uploadData['file_name']; - //echo $filename; - - - $sql = "INSERT INTO so_imageupload ( - So_ImageUploadT_OrderHeaderID, - So_ImageUploadT_OrderHeaderLabNumber, - So_ImageUploadT_SampleTypeID, - So_ImageUploadOldName, - So_ImageUploadNewName, - So_ImageUploadCreated, - So_ImageUploadUserID - ) - VALUES( - {$orderid}, - '{$labnumber}', - '150', - '{$_FILES['files']['name'][$i]}', - '{$filename}', - NOW(), - {$userid} - - )"; - //echo $sql; - $this->db_onedev->query($sql); - $xlast_id = $this->db_onedev->insert_id(); - $data['totalFiles'][] = array('xid' => $xlast_id, 'image_url' => '/one-media/one-image-nonlab/' . $filename); - } else { - $error = array('error' => $this->upload->display_errors()); - } - } - } - - $result = array("total" => count($data['totalFiles']), "records" => $data['totalFiles'], 'errors' => $error); - $this->sys_ok($result); - } - function uploadimagePatologiAnatomi() - { - if (! $this->isLogin) { - $this->sys_error("Invalid Token"); - exit; - } - - $userid = $this->sys_user["M_UserID"]; - $data = []; - //print_r($_SERVER); - - $prm = $this->sys_input; - $orderid = $this->input->post('orderid'); - $type = $this->input->post('type'); - $labnumber = $this->input->post('labnumber'); - $sql = "UPDATE so_imageupload_patology_anatomy SET - So_ImageUploadPatologyAnatomyIsActive = 'N', - So_ImageUploadPatologyAnatomyUserID = {$userid} - WHERE - So_ImageUploadPatologyAnatomyT_OrderHeaderID = {$orderid} - AND So_ImageUploadPatologyAnatomyType = '{$type}'"; - //echo $sql; - $qry = $this->db_onedev->query($sql); - $last_qry = $this->db_onedev->last_query(); - if (!$qry) { - $message = $this->db_onedev->error(); - $message['last_qry'] = $last_qry; - $this->sys_error_db($message); - exit; - } - //$config['upload_path'] = 'assets/'; - - $path = '/home/one/project/one/one-media/one-image-nonlab/'; - //echo $path; - $config['upload_path'] = $path; - $config['allowed_types'] = 'jpg|jpeg|png|gif'; - - $config['max_size'] = '10000'; - $count = count($_FILES['files']['name']); - //echo $count; - $this->load->library('upload', $config); - - $error = []; - for ($i = 0; $i < $count; $i++) { - - - if (!empty($_FILES['files']['name'][$i])) { - - - - $_FILES['file']['name'] = $_FILES['files']['name'][$i]; - - $_FILES['file']['type'] = $_FILES['files']['type'][$i]; - - $_FILES['file']['tmp_name'] = $_FILES['files']['tmp_name'][$i]; - - $_FILES['file']['error'] = $_FILES['files']['error'][$i]; - - $_FILES['file']['size'] = $_FILES['files']['size'][$i]; - - - - $namex = $orderid . '-' . $labnumber . '-' . $this->generateRandomString(5); - //echo $namex; - - $config['file_name'] = $namex; - $this->upload->initialize($config); - //echo $config['file_name'] ; - - - - - - if ($this->upload->do_upload('file')) { - - $uploadData = $this->upload->data(); - - $filename = $uploadData['file_name']; - //echo $filename; - - - $sql = "INSERT INTO so_imageupload_patology_anatomy ( - So_ImageUploadPatologyAnatomyT_OrderHeaderID, - So_ImageUploadPatologyAnatomyT_OrderHeaderLabNumber, - So_ImageUploadPatologyAnatomyT_SampleTypeID, - So_ImageUploadPatologyAnatomyOldName, - So_ImageUploadPatologyAnatomyNewName, - So_ImageUploadPatologyAnatomyCreated, - So_ImageUploadPatologyAnatomyUserID, - So_ImageUploadPatologyAnatomyType - ) - VALUES( - {$orderid}, - '{$labnumber}', - '145', - '{$_FILES['files']['name'][$i]}', - '{$filename}', - NOW(), - {$userid}, - '{$type}' - - )"; - //echo $sql; - $qry = $this->db_onedev->query($sql); - $last_qry = $this->db_onedev->last_query(); - if (!$qry) { - $message = $this->db_onedev->error(); - $message['last_qry'] = $last_qry; - $this->sys_error_db($message); - exit; - } - $xlast_id = $this->db_onedev->insert_id(); - $data['totalFiles'][] = array('xid' => $xlast_id, 'image_url' => '/one-media/one-image-nonlab/' . $filename); - } else { - $error = array('error' => $this->upload->display_errors()); - } - } - } - - $result = array("total" => count($data['totalFiles']), "records" => $data['totalFiles'], 'errors' => $error); - $this->sys_ok($result); - } - - - function generateRandomString($length = 10) - { - $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; - $charactersLength = strlen($characters); - $randomString = ''; - for ($i = 0; $i < $length; $i++) { - $randomString .= $characters[rand(0, $charactersLength - 1)]; - } - return $randomString; - } - - function getcytologiresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT Other_CytologiDetailsID as xid, - Other_CytologiT_OrderDetailID as orderdetail_id, - Other_CytologiDetailsCode as code, - Other_CytologiDetailsLabel as label, - Other_CytologiDetailsResult as result, - IFNULL(Other_CytologiM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_CytologiM_DoctorID) OR Other_CytologiM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_cytologi - JOIN other_cytologidetails ON Other_CytologiDetailsOther_CytologiID = Other_CytologiID AND Other_CytologiDetailsIsActive = 'Y' - LEFT JOIN m_doctor ON Other_CytologiM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_CytologiT_OrderDetailID = {$id} AND Other_CytologiIsActive = 'Y' - GROUP BY Other_CytologiDetailsID - ORDER BY Other_CytologiDetailsCode ASC"; - //echo $sql; - $query = $this->db_smartone->query($sql); - - if ($query) { - $rows = $query->result_array(); - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $rst = array('doctors' => $doctors, 'results' => $rows); - $this->sys_ok(["records" => $rst]); - } else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - function getmikroresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT - Other_MikroID as xid, - Other_MikroHasilBiakan as hasil_biakan, - Other_MikroSampleTypeName as sample_name, - Other_MikroT_OrderDetailID as orderdetail_id, - Other_MikroResult as result_value, - '' as result_other, - IFNULL(T_BacteriaID,0) as T_BacteriaID, - IFNULL(T_BacteriaName,'') as T_BacteriaName, - '' as details, - IFNULL(Other_MikroM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_MikroM_DoctorID) OR Other_MikroM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_mikro - LEFT JOIN t_bacteria ON Other_MikroT_BacteriaID = T_BacteriaID - LEFT JOIN m_doctor ON Other_MikroM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_MikroT_OrderDetailID = {$id} AND Other_MikroIsActive = 'Y' - GROUP BY Other_MikroID"; - //echo $sql; - $query = $this->db_smartone->query($sql); - - if ($query) { - $row = $query->row_array(); - if ($row) { - if ($row['result_value'] != 'Positif' && $row['result_value'] != 'Negatif') { - $row['result_other'] = $row['result_value']; - $row['result_value'] = 'other'; - } - $sql = "SELECT '' as xno, - Other_MikroDetailsID as xid, - Other_MikroDetailsValue as value, - IF(Other_MikroDetailsNote = 'R','Y','N') as chx_r, - IF(Other_MikroDetailsNote = 'I','Y','N') as chx_i, - IF(Other_MikroDetailsNote = 'S','Y','N') as chx_s, - Other_MikroDetailsNote as note, - t_antibiotic.* - FROM other_mikrodetails - LEFT JOIN t_antibiotic ON Other_MikroDetailsT_AntibioticID = T_AntibioticID - WHERE - Other_MikroDetailsOther_MikroID = {$row['xid']} AND Other_MikroDetailsIsActive = 'Y' - GROUP BY Other_MikroDetailsID - ORDER BY T_AntibioticName ASC"; - //echo $sql; - $details = $this->db_smartone->query($sql)->result_array(); - if ($details) { - foreach ($details as $k => $v) { - $details[$k]['xno'] = $k + 1; - } - } - $row['details'] = $details; - } else { - $row = array('xid' => '0', 'hasil_biakan' => '', 'result_value' => 'Negatif', 'sample_name' => '', 'orderdetail_id' => $id, 'T_BacteriaID' => '0', 'T_BacteriaName' => '0', 'details' => array(), 'doctor_id' => '0', 'doctor_name' => '0'); - } - } else { - $row = array('xid' => '0', 'hasil_biakan' => '', 'result_value' => 'Negatif', 'sample_name' => '', 'orderdetail_id' => $id, 'T_BacteriaID' => '0', 'T_BacteriaName' => '0', 'details' => array(), 'doctor_id' => '0', 'doctor_name' => '0'); - } - //print_r($row); - - - - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 7 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $sql = " - SELECT '0' as id, 'Belum memilih bakteria' as name - UNION - SELECT T_BacteriaID as id, T_BacteriaName as name - FROM t_bacteria - WHERE - T_BacteriaIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $bacteries = $this->db_smartone->query($sql)->result_array(); - $rst = array('doctors' => $doctors, 'bacteries' => $bacteries, 'results' => $row); - $this->sys_ok(["records" => $rst]); - } - function getantibiotics() - { - $prm = $this->sys_input; - $id = $prm["id"]; - $sql = " SELECT '' as xno, - 0 as xid, - '' as hasil_biakan, - '' as sample_name, - 0 as value, - 'Y' as chx_r, - 'N' as chx_i, - 'N' as chx_s, - 'R' as note, - t_antibiotic.* - FROM t_antibiotic - WHERE - T_AntibioticT_BacteriaID = {$prm['id']} AND T_AntibioticIsActive= 'Y' - ORDER BY T_AntibioticName ASC"; - //echo $sql; - $rows = $this->db_smartone->query($sql)->result_array(); - if (rows) { - foreach ($rows as $k => $v) { - $rows[$k]['xno'] = $k + 1; - } - } - - $this->sys_ok(["records" => $rows]); - } - function getlcprepresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = "SELECT T_OrderDetailVerification as verification, T_OrderDetailValidation as validation FROM t_orderdetail WHERE T_OrderDetailID = ?"; - $order = $this->db_smartone->query($sql, array($id))->row_array(); - - - $sql = " SELECT Other_LcprepDetailsID as xid, - Other_LcprepID as header_id, - Other_LcprepT_orderDetailID as orderdetail_id, - Other_LcprepDetailsCode as code, - Other_LcprepDetailsLabel as label, - Other_LcprepDetailsResult as result, - IFNULL(Other_LcprepM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_LcprepM_DoctorID) OR Other_LcprepM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_lcprep - JOIN other_lcprepdetails ON Other_LcprepDetailsOther_LcprepID = Other_LcprepID AND Other_LcprepDetailsIsActive = 'Y' - LEFT JOIN m_doctor ON Other_LcprepM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_LcprepT_orderDetailID = ? AND Other_LcprepIsActive = 'Y' - GROUP BY Other_LcprepDetailsOther_LcprepID, Other_LcprepDetailsCode - ORDER BY Other_LcprepDetailsCode ASC"; - //echo $sql; - $rows = $this->db_smartone->query($sql, array($id))->result_array(); - if (count($rows) == 0) { - $rows = array( - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'A', - 'label' => 'DESKRIPSI', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ), - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'B', - 'label' => 'KESIMPULAN', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ) - ); - } - - $other_rows = array(); - $langs = array(array('id' => 1, 'name' => 'Bahasa Indonesia')); - $selected_lang = array(array('id' => 1, 'name' => 'Bahasa Indonesia')); - $sql = "SELECT T_OrderHeaderAddOnSecondM_LangID as lang_id, - M_LangName as lang_name - FROM t_orderdetail - JOIN t_orderheader ON T_OrderDetailT_OrderHeaderID = T_OrderHeaderID AND T_OrderHeaderIsActive = 'Y' - JOIN t_orderheaderaddon ON T_OrderHeaderAddonT_OrderHeaderID = T_OrderHeaderID AND T_OrderHeaderAddonIsActive = 'Y' - JOIN m_lang ON T_OrderHeaderAddOnSecondM_LangID = M_LangID AND M_LangIsActive = 'Y' - WHERE T_OrderDetailID = {$id} AND T_OrderDetailIsActive = 'Y'"; - - $other_lang = $this->db_smartone->query($sql)->result_array(); - if (count($other_lang) > 0) { - $langs[] = array('id' => $other_lang[0]['lang_id'], 'name' => $other_lang[0]['lang_name']); - $selected_lang = array('id' => $other_lang[0]['lang_id'], 'name' => $other_lang[0]['lang_name']); - - - $sql = " SELECT Other_LcprepDetailsLangsID as xid, - Other_LcprepID as header_id, - Other_LcprepT_orderDetailID as orderdetail_id, - Other_LcprepDetailsLangsCode as code, - Other_LcprepDetailsLangsLabel as label, - Other_LcprepDetailsLangsResult as result, - IFNULL(Other_LcprepM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_LcprepM_DoctorID) OR Other_LcprepM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_lcprep - JOIN other_lcprepdetails_lang ON Other_LcprepDetailsLangsOther_LcprepID = Other_LcprepID AND Other_LcprepDetailsLangsIsActive = 'Y' - LEFT JOIN m_doctor ON Other_LcprepM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_LcprepT_orderDetailID = {$id} AND Other_LcprepDetailsLangsIsActive = 'Y' - GROUP BY Other_LcprepDetailsLangsOther_LcprepID, Other_LcprepDetailsLangsCode - ORDER BY Other_LcprepDetailsLangsCode ASC"; - // echo $sql; - $other_rows = $this->db_smartone->query($sql)->result_array(); - if (count($other_rows) == 0) { - $other_rows = array( - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'AA', - 'label' => 'DESCRIPTION', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ), - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'BB', - 'label' => 'CONCLUSION', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ) - ); - } - } - - $header_id = $rows[0]['header_id']; - $sql = "SELECT IFNULL(Other_LcprepAdekuasiID,0) as xid, - Lcprep_AdekuasiID as id, - Lcprep_AdekuasiLabel as name, - Lcprep_AdekuasiLabel as name_en, - IF(ISNULL(Other_LcprepAdekuasiID),'N',Other_LcprepAdekuasiChex) as chex - FROM lcprep_adekuasi - LEFT JOIN other_lcprepadekuasi ON Other_LcprepAdekuasiLcprep_AdekuasiID = Lcprep_AdekuasiID AND - Other_LcprepAdekuasiOther_LcprepID = {$header_id} AND - Other_LcprepAdekuasiIsActive = 'Y' - WHERE - Lcprep_AdekuasiIsActive = 'Y' - GROUP BY Lcprep_AdekuasiID - ORDER BY Lcprep_AdekuasiOrder ASC - "; - //echo $sql; - $adeakuasi = $this->db_smartone->query($sql)->result_array(); - foreach ($adeakuasi as $kc => $vc) { - $adeakuasi[$kc]['chex'] = $vc['chex'] == 'N' ? false : true; - $adeakuasi[$kc]['name_en'] = $this->translate_word($vc['name']); - } - - $sql = "SELECT IFNULL(Other_LcprepKategoriUmumID,0) as xid, - Lcprep_KategoriUmumID as id, - Lcprep_KategoriUmumLabel as name, - Lcprep_KategoriUmumLabel as name_en, - IF(ISNULL(Other_LcprepKategoriUmumID),'N',Other_LcprepKategoriUmumChex) as chex - FROM lcprep_kategoriumum - LEFT JOIN other_lcprepkategoriumum ON Other_LcprepKategoriUmumLcprep_KategoriUmumID = Lcprep_KategoriUmumID AND - Other_LcprepKategoriUmumOther_LcprepID = {$header_id} AND - Other_LcprepKategoriUmumIsActive = 'Y' - WHERE - Lcprep_KategoriUmumIsActive = 'Y' - GROUP BY Lcprep_KategoriUmumID - "; - //echo $sql; - $kategoriumum = $this->db_smartone->query($sql)->result_array(); - foreach ($kategoriumum as $kc => $vc) { - $kategoriumum[$kc]['chex'] = $vc['chex'] == 'N' ? false : true; - $kategoriumum[$kc]['name_en'] = $this->translate_word($vc['name']); - } - - $sql = " - SELECT Lcprep_InterpretasiGroupID as group_id, - Lcprep_InterpretasiGroupName as group_name, - Lcprep_InterpretasiGroupName as group_name_en, - '' as subgroups - FROM lcprep_interpretasigroup - WHERE - Lcprep_InterpretasiGroupIsActive = 'Y' - "; - //echo $sql; - $interpretasi = $this->db_smartone->query($sql)->result_array(); - foreach ($interpretasi as $k => $v) { - $interpretasi[$k]['group_name_en'] = $this->translate_word($v['group_name']); - $subgroups = array(); - $sql = "SELECT Lcprep_InterpretasiSubgroupID as subgroup_id, - Lcprep_InterpretasiSubgroupName as subgroup_name, - Lcprep_InterpretasiSubgroupName as subgroup_name_en, - '' as childs - FROM lcprep_interpretasisubgroup - WHERE - Lcprep_InterpretasiSubgroupLcprep_InterpretasiGroupID = {$v['group_id']} AND Lcprep_InterpretasiSubgroupIsActive = 'Y'"; - //echo $sql; - $subgroups = $this->db_smartone->query($sql)->result_array(); - if (count($subgroups) > 0) { - foreach ($subgroups as $ki => $vi) { - $subgroups[$ki]['subgroup_name_en'] = $this->translate_word($vi['subgroup_name']); - $childs = array(); - - $sql = "SELECT IFNULL(Other_LcprepInterpretasiID,0) as xid, - IFNULL(Other_LcprepInterpretasiChex,'N') as chex, - IFNULL(Other_LcprepInterpretasiValue,'') as value, - IFNULL(Other_LcprepInterpretasiValueEng,'') as value_en, - Lcprep_InterpretasiID as id, - Lcprep_InterpretasiLcprep_InterpretasiSubgroupID as subgroup_id, - Lcprep_InterpretasiCode as code, - Lcprep_InterpretasiName as name, - Lcprep_InterpretasiName as name_en, - Lcprep_InterpretasiParentID as parent_id, - Lcprep_InterpretasiIsParent as is_parent, - Lcprep_InterpretasiHasResult as has_result, - Lcprep_InterpretasiTypeResult as type_result - FROM lcprep_interpretasi - LEFT JOIN other_lcprepinterpretasi ON Other_LcprepInterpretasiOther_LcprepID = {$header_id} AND - Other_LcprepInterpretasiLcprep_InterpretasiID = Lcprep_InterpretasiID AND - Other_LcprepInterpretasiIsActive = 'Y' - WHERE - Lcprep_InterpretasiLcprep_InterpretasiSubgroupID = {$vi['subgroup_id']} AND Lcprep_InterpretasiIsActive = 'Y' - GROUP BY Lcprep_InterpretasiID Order BY Lcprep_InterpretasiCode ASC"; - $childs = $this->db_smartone->query($sql)->result_array(); - if ($childs) { - foreach ($childs as $kc => $vc) { - $childs[$kc]['chex'] = $vc['chex'] == 'N' ? false : true; - $childs[$kc]['name_en'] = $this->translate_word($vc['name']); - } - } - $subgroups[$ki]['childs'] = $childs; - } - } - - $interpretasi[$k]['subgroups'] = $subgroups; - } - - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - - - - $rst = array('order' => $order, 'langs' => $langs, 'selected_lang' => $selected_lang, 'doctors' => $doctors, 'results' => $rows, 'other_results' => $other_rows, 'adekuasi' => $adeakuasi, 'kategoriumum' => $kategoriumum, 'interpretasi' => $interpretasi); - $this->sys_ok(["records" => $rst]); - } - - function translate_word($word) - { - $sql = "SELECT * - FROM translate_word - WHERE Translate_WordNat_LangID = '2' AND - BINARY Translate_WordFrom = '{$word}' AND - Translate_WordIsActive = 'Y' - LIMIT 1"; - $dt = $this->db_smartone->query($sql)->result_array(); - if (count($dt) > 0) { - return $dt[0]['Translate_WordTo']; - } else { - return $word; - } - } - - function getpapsmearresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT Other_PapSmearDetailsID as xid, - Other_PapSmearID as header_id, - Other_PapSmearT_OrderDetailID as orderdetail_id, - Other_PapSmearDetailsCode as code, - Other_PapSmearDetailsLabel as label, - Other_PapSmearDetailsResult as result, - IFNULL(Other_PapSmearM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_PapSmearM_DoctorID) OR Other_PapSmearM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_papsmear - JOIN other_papsmeardetails ON Other_PapSmearDetailsOther_PapSmearID = Other_PapSmearID AND Other_PapSmearDetailsIsActive = 'Y' - LEFT JOIN m_doctor ON Other_PapSmearM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_PapSmearT_OrderDetailID = {$id} AND Other_PapSmearIsActive = 'Y' - GROUP BY Other_PapSmearDetailsID - ORDER BY Other_PapSmearDetailsCode ASC"; - //echo $sql; - $rows = $this->db_smartone->query($sql)->result_array(); - if (!$rows) { - $rows = array( - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'A', - 'label' => 'Makroskopik', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ), - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'B', - 'label' => 'Mikroskopik', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ), - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'C', - 'label' => 'Kesimpulan', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ) - ); - } - - $header_id = $rows[0]['header_id']; - $sql = "SELECT Other_PapSmearMaturasiID as xid, - Other_PapSmearMaturasiValue as value - FROM other_papsmearmaturasi - WHERE - Other_PapSmearMaturasiOther_PapSmearID = {$header_id} AND - Other_PapSmearMaturasiIsActive = 'Y' - "; - //echo $sql; - $dt_maturasi = $this->db_smartone->query($sql)->row_array(); - if (!$dt_maturasi) { - $maturasi = array('xid' => '0', 'value' => array('', '', '')); - } else { - $value = explode('/', $dt_maturasi['value']); - $maturasi = array('xid' => $dt_maturasi['xid'], 'value' => $value); - } - - $sql = "SELECT IFNULL(Other_PapSmearBahanID,0) as xid, - M_PapSmearBahanID as bahan_id, - M_PapSmearBahanName as name, - IF(ISNULL(Other_PapSmearBahanID),'N','Y') as selected - FROM m_papsmearbahan - LEFT JOIN other_papsmearbahan ON Other_PapSmearBahanM_PapSmearBahanID = M_PapSmearBahanID AND - Other_PapSmearBahanOther_PapSmearID = {$header_id} AND - Other_PapSmearBahanIsActive = 'Y' - WHERE - M_PapSmearBahanIsActive = 'Y' - ORDER BY M_PapSmearBahanID ASC - "; - //echo $sql; - $bahans = $this->db_smartone->query($sql)->result_array(); - - $sql = "SELECT IFNULL(Other_PapsmearCategoryID,0) as xid, - M_PapSmearCategoryID as category_id, - M_PapSmearCategoryName as name, - IF(ISNULL(Other_PapsmearCategoryID),'N','Y') as selected - FROM m_papsmearcategory - LEFT JOIN other_papsmearcategory ON Other_PapsmearCategoryM_PapSmearCategoryID = M_PapSmearCategoryID AND - Other_PapsmearCategoryOther_PapSmearID = {$header_id} AND - Other_PapsmearCategoryIsActive = 'Y' - WHERE - M_PapSmearCategoryIsActive = 'Y' - ORDER BY M_PapSmearCategoryID ASC - "; - //echo $sql; - $categories = $this->db_smartone->query($sql)->result_array(); - - $sql = "SELECT IFNULL(Other_PapSmearCheckID,0) as xid, - M_PapSmearCheckID as check_id, - M_PapSmearCheckLabel as name, - IF(ISNULL(Other_PapSmearCheckID),'N','Y') as selected, - Other_PapSmearCheckNote as note - FROM m_papsmearcheck - LEFT JOIN other_papsmearcheck ON Other_PapSmearCheckM_PapSmearCheckID = M_PapSmearCheckID AND - Other_PapSmearCheckOther_PapSmearID = {$header_id} AND - Other_PapSmearCheckIsActive = 'Y' - WHERE - M_PapSmearCheckIsActive = 'Y' - ORDER BY M_PapSmearCheckCode ASC - "; - $checks = $this->db_smartone->query($sql)->result_array(); - - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $rst = array('doctors' => $doctors, 'checks' => $checks, 'bahans' => $bahans, 'categories' => $categories, 'maturasi' => $maturasi, 'results' => $rows); - $this->sys_ok(["records" => $rst]); - } - - function saveresult_lcprep() - { - $prm = $this->sys_input; - $detail_id = $prm['detail_id']; - $doctor_id = $prm['doctor']; - $adekuasi = $prm['adekuasi']; - $kategoriumum = $prm['kategoriumum']; - $interpretasi = $prm['interpretasi']; - $results = $prm['results']; - $selected_lang = $prm['selected_lang']; - $other_results = $prm['other_results']; - - $userid = $this->sys_user['M_UserID']; - - $header_id = 0; - $sql = "SELECT * FROM other_lcprep WHERE Other_LcprepT_orderDetailID = ? AND Other_LcprepIsActive = 'Y'"; - $dt_header = $this->db_smartone->query($sql, array($detail_id))->row_array(); - if ($dt_header) { - $header_id = $dt_header['Other_LcprepID']; - } - if ($header_id == 0) { - $sql = "INSERT INTO other_lcprep( - Other_LcprepT_orderDetailID, - Other_LcprepM_DoctorID, - Other_LcprepUserID, - Other_LcprepCreated - ) - VALUES( - ?, - ?, - ?, - NOW() - )"; - //echo $sql; - $query = $this->db_smartone->query($sql, array($detail_id, $doctor_id, $userid)); - if(!$query){ - echo $this->db_smartone->last_query(); - exit; - } - $header_id = $this->db_smartone->insert_id(); - } else { - $sql = "UPDATE other_lcprep SET Other_LcprepM_DoctorID = ?, Other_LcprepUserID = ? WHERE Other_LcprepID = ?"; - $query = $this->db_smartone->query($sql, array($doctor_id, $userid, $header_id)); - if(!$query){ - echo $this->db_smartone->last_query(); - exit; - } - } - - - - if ($adekuasi) { - foreach ($adekuasi as $k => $v) { - $selected = $v['chex'] ? 'Y' : 'N'; - if (intval($v['xid'] == 0)) { - $sql = "UPDATE other_lcprepadekuasi SET Other_LcprepAdekuasiIsActive = 'N' - WHERE - Other_LcprepAdekuasiOther_LcprepID = ? AND - Other_LcprepAdekuasiIsActive = 'Y' AND - Other_LcprepAdekuasiLcprep_AdekuasiID = ?"; - $query = $this->db_smartone->query($sql, array($header_id, $v['id'])); - if(!$query){ - echo $this->db_smartone->last_query(); - exit; - } - $sql = "INSERT INTO other_lcprepadekuasi ( - Other_LcprepAdekuasiOther_LcprepID, - Other_LcprepAdekuasiLcprep_AdekuasiID, - Other_LcprepAdekuasiChex, - Other_LcprepAdekuasiUserID, - Other_LcprepAdekuasiCreated - ) - VALUES( - ?, - ?, - ?, - ?, - NOW() - )"; - $query = $this->db_smartone->query($sql, array($header_id, $v['id'], $selected, $userid)); - if(!$query){ - echo $this->db_smartone->last_query(); - exit; - } - //echo $sql; - } - if (intval($v['xid'] != 0)) { - - $sql = "UPDATE other_lcprepadekuasi SET - Other_LcprepAdekuasiChex = ?, - Other_LcprepAdekuasiUserID = ? - WHERE - Other_LcprepAdekuasiID = ? - "; - $query = $this->db_smartone->query($sql, array($selected, $userid, $v['xid'])); - if(!$query){ - echo $this->db_smartone->last_query(); - exit; - } - } - - //echo $sql; - } - } - - if ($kategoriumum) { - foreach ($kategoriumum as $k => $v) { - $selected = $v['chex'] ? 'Y' : 'N'; - if (intval($v['xid'] == 0)) { - $sql = "UPDATE other_lcprepkategoriumum SET Other_LcprepKategoriUmumIsActive = 'N' - WHERE - Other_LcprepKategoriUmumOther_LcprepID = ? AND - Other_LcprepKategoriUmumLcprep_KategoriUmumID = ? AND - Other_LcprepKategoriUmumIsActive = 'Y' - "; - $query = $this->db_smartone->query($sql, array($header_id, $v['id'])); - if(!$query){ - echo $this->db_smartone->last_query(); - exit; - } - $sql = "INSERT INTO other_lcprepkategoriumum ( - Other_LcprepKategoriUmumOther_LcprepID, - Other_LcprepKategoriUmumLcprep_KategoriUmumID, - Other_LcprepKategoriUmumChex, - Other_LcprepKategoriUmumUserID, - Other_LcprepKategoriUmumCreated - ) - VALUES( - ?, - ?, - ?, - ?, - NOW() - )"; - $query = $this->db_smartone->query($sql, array($header_id, $v['id'], $selected, $userid)); - if(!$query){ - echo $this->db_smartone->last_query(); - exit; - } - } - if (intval($v['xid'] != 0)) { - $sql = "UPDATE other_lcprepkategoriumum SET - Other_LcprepKategoriUmumChex = ?, - Other_LcprepKategoriUmumUserID = ? - WHERE - Other_LcprepKategoriUmumID = ? - "; - $query = $this->db_smartone->query($sql, array($selected, $userid, $v['xid'])); - if(!$query){ - echo $this->db_smartone->last_query(); - exit; - } - } - - //echo $sql; - } - } - - if (count($results) > 0 && intval($selected_lang) == 1) { - foreach ($results as $k => $v) { - if (intval($v['xid'] == 0)) { - $sql = "UPDATE other_lcprepdetails SET Other_LcprepDetailsIsActive = 'N' - WHERE - Other_LcprepDetailsOther_LcprepID = ? AND - Other_LcprepDetailsCode = ? AND - Other_LcprepDetailsIsActive = 'Y'"; - $query = $this->db_smartone->query($sql, array($header_id, $v['code'])); - if(!$query){ - echo $this->db_smartone->last_query(); - exit; - } - $sql = "INSERT INTO other_lcprepdetails ( - Other_LcprepDetailsOther_LcprepID, - Other_LcprepDetailsCode, - Other_LcprepDetailsLabel, - Other_LcprepDetailsResult, - Other_LcprepDetailsUserID, - Other_LcprepDetailsCreated - ) - VALUES( - ?, - ?, - ?, - ?, - ?, - NOW() - )"; - $query = $this->db_smartone->query($sql, array($header_id, $v['code'], $v['label'], $v['result'], $userid)); - if(!$query){ - echo $this->db_smartone->last_query(); - exit; - } - } - if (intval($v['xid'] != 0)) { - $sql = "UPDATE other_lcprepdetails SET - Other_LcprepDetailsCode = ?, - Other_LcprepDetailsLabel = ?, - Other_LcprepDetailsResult = ?, - Other_LcprepDetailsUserID = ? - WHERE - Other_LcprepDetailsID = ? - "; - $query = $this->db_smartone->query($sql, array($v['code'], $v['label'], $v['result'], $userid, $v['xid'])); - if(!$query){ - echo $this->db_smartone->last_query(); - exit; - } - } - //echo $sql; - } - } - - if (count($other_results) > 0 && intval($selected_lang) == 2) { - foreach ($other_results as $k => $v) { - if (intval($v['xid'] == 0)) { - $sql = "UPDATE other_lcprepdetails_lang SET Other_LcprepDetailsLangsIsActive = 'N' - WHERE - Other_LcprepDetailsLangsOther_LcprepID = ? AND - Other_LcprepDetailsLangsCode = ? AND - Other_LcprepDetailsLangsIsActive = 'Y'"; - $query = $this->db_smartone->query($sql, array($header_id, $v['code'])); - if(!$query){ - echo $this->db_smartone->last_query(); - exit; - } - //echo $this->db_smartone->last_query(); - $sql = "INSERT INTO other_lcprepdetails_lang ( - Other_LcprepDetailsLangsOther_LcprepID, - Other_LcprepDetailsLangsCode, - Other_LcprepDetailsLangsLabel, - Other_LcprepDetailsLangsResult, - Other_LcprepDetailsLangsCreatedUserID, - Other_LcprepDetailsLangsCreated - ) - VALUES( - ?, - ?, - ?, - ?, - ?, - NOW() - )"; - $query = $this->db_smartone->query($sql, array($header_id, $v['code'], $v['label'], $v['result'], $userid)); - if(!$query){ - echo $this->db_smartone->last_query(); - exit; - } - //echo $this->db_smartone->last_query(); - } - if (intval($v['xid'] != 0)) { - $sql = "UPDATE other_lcprepdetails_lang SET - Other_LcprepDetailsLangsCode = ?, - Other_LcprepDetailsLangsLabel = ?, - Other_LcprepDetailsLangsResult = ?, - Other_LcprepDetailsLangsUpdatedUserID = ?, - Other_LcprepDetailsLangsUpdated = NOW() - WHERE - Other_LcprepDetailsLangsID = ? - "; - $query = $this->db_smartone->query($sql, array($v['code'], $v['label'], $v['result'], $userid, $v['xid'])); - if(!$query){ - echo $this->db_smartone->last_query(); - exit; - } - } - //echo $sql; - } - } - - if ($interpretasi) { - foreach ($interpretasi as $k => $v) { - if (count($v['subgroups']) > 0) { - foreach ($v['subgroups'] as $ik => $iv) { - if (count($iv['childs']) > 0) { - foreach ($iv['childs'] as $iik => $iiv) { - if (intval($iiv['xid'] == 0)) { - $chex = $iiv['chex'] ? 'Y' : 'N'; - $sql = "UPDATE other_lcprepinterpretasi SET Other_LcprepInterpretasiIsActive = 'N' - WHERE - Other_LcprepInterpretasiOther_LcprepID = ? AND - Other_LcprepInterpretasiLcprep_InterpretasiID = ? AND - Other_LcprepInterpretasiIsActive = 'Y'"; - $query = $this->db_smartone->query($sql, array($header_id, $iiv['id'])); - if(!$query){ - echo $this->db_smartone->last_query(); - exit; - } - $sql = "INSERT INTO other_lcprepinterpretasi ( - Other_LcprepInterpretasiOther_LcprepID, - Other_LcprepInterpretasiLcprep_InterpretasiID, - Other_LcprepInterpretasiChex, - Other_LcprepInterpretasiValue, - Other_LcprepInterpretasiValueEng, - Other_LcprepInterpretasiUserID, - Other_LcprepInterpretasiCreated - ) - VALUES( - ?, - ?, - ?, - ?, - ?, - ?, - NOW() - )"; - $query = $this->db_smartone->query($sql, array($header_id, $iiv['id'], $chex, $iiv['value'], $iiv['value_en'], $userid)); - if(!$query){ - echo $this->db_smartone->last_query(); - exit; - } - } - - if (intval($iiv['xid'] != 0)) { - $chex = $iiv['chex'] ? 'Y' : 'N'; - $sql = "UPDATE other_lcprepinterpretasi SET - Other_LcprepInterpretasiChex = ?, - Other_LcprepInterpretasiValue = ?, - Other_LcprepInterpretasiValueEng = ?, - Other_LcprepInterpretasiUserID = ? - WHERE - Other_LcprepInterpretasiID = ? - "; - $query = $this->db_smartone->query($sql, array($chex, $iiv['value'], $iiv['value_en'], $userid, $iiv['xid'])); - if(!$query){ - echo $this->db_smartone->last_query(); - exit; - } - //echo $sql; - - } - } - } - } - } - //echo $sql; - } - } - - - $result = array("total" => 1, "records" => array(), "sql" => ''); - $this->sys_ok($result); - exit; - } - - function saveresult_papsmear() - { - $prm = $this->sys_input; - $detail_id = $prm['detail_id']; - $doctor_id = $prm['doctor']; - $checks = $prm['checks']; - $maturasi = $prm['maturasi']; - $bahans = $prm['bahans']; - $categories = $prm['categories']; - $results = $prm['results']; - - $userid = $this->sys_user['M_UserID']; - - $header_id = 0; - $sql = "SELECT * FROM other_papsmear WHERE Other_PapSmearT_OrderDetailID = {$detail_id} AND Other_PapSmearIsActive = 'Y'"; - $dt_header = $this->db_smartone->query($sql)->row_array(); - if ($dt_header) { - $header_id = $dt_header['Other_PapSmearID']; - } - if ($header_id == 0) { - $sql = "INSERT INTO other_papsmear( - Other_PapSmearT_OrderDetailID, - Other_PapSmearM_DoctorID, - Other_PapSmearUserID, - Other_PapSmearCreated - ) - VALUES( - {$detail_id}, - {$doctor_id}, - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } else { - $sql = "UPDATE other_papsmear SET Other_PapSmearM_DoctorID = {$doctor_id}, Other_PapSmearUserID = {$userid} WHERE Other_PapSmearID = {$header_id}"; - $this->db_smartone->query($sql); - } - - if ($checks) { - foreach ($checks as $k => $v) { - if (intval($v['xid']) == 0 && $v['selected'] === 'Y') { - $sql = "INSERT INTO other_papsmearcheck ( - Other_PapSmearCheckOther_PapSmearID, - Other_PapSmearCheckM_PapSmearCheckID, - Other_PapSmearCheckNote, - Other_PapSmearCheckUserID, - Other_PapSmearCheckCreated - ) - VALUES( - {$header_id}, - {$v['check_id']}, - '{$v['note']}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if (intval($v['xid']) != 0 && $v['selected'] === 'N') { - $sql = "UPDATE other_papsmearcheck SET - Other_PapSmearCheckIsActive = 'N', - Other_PapSmearCheckUserID = {$userid} - WHERE - Other_PapSmearCheckID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - if (intval($v['xid']) != 0 && $v['selected'] === 'Y') { - $sql = "UPDATE other_papsmearcheck SET - Other_PapSmearCheckNote = '{$v['note']}', - Other_PapSmearCheckUserID = {$userid} - WHERE - Other_PapSmearCheckID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - //echo $sql; - } - } - - if ($maturasi) { - if (intval($maturasi['xid']) == 0) { - $value = join("/", $maturasi['value']); - $sql = "INSERT INTO other_papsmearmaturasi ( - Other_PapSmearMaturasiOther_PapSmearID, - Other_PapSmearMaturasiValue, - Other_PapSmearMaturasiUserID, - Other_PapSmearMaturasiCreated - ) - VALUE( - {$header_id}, - '{$value}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - //echo $sql; - } - if (intval($maturasi['xid']) != 0) { - $value = join("/", $maturasi['value']); - $sql = "UPDATE other_papsmearmaturasi SET - Other_PapSmearMaturasiValue = '{$value}', - Other_PapSmearMaturasiUserID = {$userid} - WHERE - Other_PapSmearMaturasiID = {$maturasi['xid']}"; - // echo $sql; - $this->db_smartone->query($sql); - } - } - - if ($bahans) { - foreach ($bahans as $k => $v) { - if (intval($v['xid']) == 0 && $v['selected'] === 'Y') { - $sql = "INSERT INTO other_papsmearbahan ( - Other_PapSmearBahanOther_PapSmearID, - Other_PapSmearBahanM_PapSmearBahanID, - Other_PapSmearBahanUserID, - Other_PapSmearBahanCreated - ) - VALUES( - {$header_id}, - {$v['bahan_id']}, - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if (intval($v['xid']) != 0 && $v['selected'] === 'N') { - $sql = "UPDATE other_papsmearbahan SET - Other_PapSmearBahanIsActive = 'N', - Other_PapsmearCategoryUserID = {$userid} - WHERE - Other_PapSmearBahanID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - if (intval($v['xid']) != 0 && $v['selected'] === 'Y') { - $sql = "UPDATE other_papsmearbahan SET - Other_PapSmearBahanIsActive = 'Y', - Other_PapsmearCategoryUserID = {$userid} - WHERE - Other_PapSmearBahanID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - //echo $sql; - } - } - - if ($categories) { - foreach ($categories as $k => $v) { - if (intval($v['xid']) == 0 && $v['selected'] === 'Y') { - $sql = "INSERT INTO other_papsmearcategory ( - Other_PapsmearCategoryOther_PapSmearID, - Other_PapsmearCategoryM_PapSmearCategoryID, - Other_PapsmearCategoryUserID, - Other_PapsmearCategoryCreated - ) - VALUES( - {$header_id}, - {$v['category_id']}, - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if (intval($v['xid']) != 0 && $v['selected'] === 'N') { - $sql = "UPDATE other_papsmearcategory SET - Other_PapsmearCategoryIsActive = 'N', - Other_PapsmearCategoryUserID = {$userid} - WHERE - Other_PapsmearCategoryID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - //echo $sql; - if (intval($v['xid']) != 0 && $v['selected'] === 'Y') { - $sql = "UPDATE other_papsmearcategory SET - Other_PapsmearCategoryIsActive = 'Y', - Other_PapsmearCategoryUserID = {$userid} - WHERE - Other_PapsmearCategoryID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - } - } - - if ($results) { - foreach ($results as $k => $v) { - if (intval($v['xid']) == 0) { - $sql = "INSERT INTO other_papsmeardetails ( - Other_PapSmearDetailsOther_PapSmearID, - Other_PapSmearDetailsCode, - Other_PapSmearDetailsLabel, - Other_PapSmearDetailsResult, - Other_PapSmearDetailsUserID, - Other_PapSmearDetailsCreated - ) - VALUES( - {$header_id}, - '{$v['code']}', - '{$v['label']}', - '{$v['result']}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if (intval($v['xid']) != 0) { - $sql = "UPDATE other_papsmeardetails SET - Other_PapSmearDetailsCode = '{$v['code']}', - Other_PapSmearDetailsLabel = '{$v['label']}', - Other_PapSmearDetailsResult = '{$v['result']}', - Other_PapSmearDetailsUserID = {$userid} - WHERE - Other_PapSmearDetailsID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - //echo $sql; - } - } - - $result = array("total" => 1, "records" => array(), "sql" => ''); - $this->sys_ok($result); - exit; - } - - function saveresult_fna() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = $inp['doctor']; - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - if ($prm[0]['xid'] == '0') { - $sql = "INSERT INTO other_fna( - Other_FNAM_DoctorID, - Other_FNAT_OrderDetailID, - Other_FNAUserID, - Other_FNACreated - ) - VALUES( - {$doctor_id}, - {$prm[0]['orderdetail_id']}, - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } else { - $sql = "SELECT * FROM other_fna WHERE Other_FNAT_OrderDetailID = {$prm[0]['orderdetail_id']} AND Other_FNAIsActive = 'Y'"; - $data_header = $this->db_smartone->query($sql)->row_array(); - $header_id = $data_header['Other_FNAID']; - $sql = "UPDATE other_fna SET - Other_FNAM_DoctorID = {$doctor_id}, - Other_FNAUserID = {$userid} - WHERE - Other_FNAID = {$header_id}"; - $this->db_smartone->query($sql); - } - foreach ($prm as $k => $v) { - if ($v['xid'] == '0') { - $results = str_replace("'", "\\'", $v['result']); - $sql = "INSERT INTO other_fnadetails( - Other_FNADetailsOther_FNAID , - Other_FNADetailsCode, - Other_FNADetailsLabel, - Other_FNADetailsResult, - Other_FNADetailsCreated, - Other_FNADetailsUserID - ) - VALUES( - {$header_id}, - '{$v['code']}', - '{$v['label']}', - '{$results}', - NOW(), - {$userid} - )"; - $query = $this->db_smartone->query($sql); - } else { - $results = str_replace("'", "\\'", $v['result']); - $sql = "UPDATE other_fnadetails SET - Other_FNADetailsResult = '{$results}', - Other_FNADetailsUserID = {$userid} - WHERE - Other_FNADetailsID = {$v['xid']}"; - $query = $this->db_smartone->query($sql); - } - } - - $result = array("total" => 1, "records" => array(), "sql" => ''); - $this->sys_ok($result); - exit; - } - - function saveresult_patologianatomy() - { - - $inp = $this->sys_input; - $doctor_id = $inp['doctor']; - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - if ($inp['xid'] == '0') { - $sql = "INSERT INTO other_patologi_anatomy( - Other_PatologiAnatomyT_OrderDetailID, - Other_PatologiAnatomyM_DoctorID, - Other_PatologiAnatomyNoSediaan, - Other_PatologiAnatomyDiagnosaKlinis, - Other_PatologiAnatomyKeteranganKlinis, - Other_PatologiAnatomyLokasiOrgan, - Other_PatologiAnatomyMakroskopik, - Other_PatologiAnatomyMikroskopik, - Other_PatologiAnatomyKesimpulan, - Other_PatologiAnatomyUserID, - Other_PatologiAnatomyCreated - ) - VALUES( - {$inp['detail_id']}, - {$doctor_id}, - '{$inp['no_sediaan']}', - '{$inp['diagnosa']}', - '{$inp['klinis']}', - '{$inp['lokasi']}', - '{$inp['makroskopik']}', - '{$inp['mikroskopik']}', - '{$inp['kesimpulan']}', - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } else { - $sql = "UPDATE other_patologi_anatomy SET - Other_PatologiAnatomyM_DoctorID = ?, - Other_PatologiAnatomyNoSediaan = ?, - Other_PatologiAnatomyKeteranganKlinis = ?, - Other_PatologiAnatomyDiagnosaKlinis = ?, - Other_PatologiAnatomyLokasiOrgan = ?, - Other_PatologiAnatomyMakroskopik = ?, - Other_PatologiAnatomyMikroskopik = ?, - Other_PatologiAnatomyKesimpulan = ?, - Other_PatologiAnatomyUserID = ? - WHERE - Other_PatologiAnatomyT_OrderDetailID = ? AND Other_PatologiAnatomyIsActive = 'Y'"; - $this->db_smartone->query($sql, array( - $doctor_id, - $inp['no_sediaan'], - $inp['klinis'], - $inp['diagnosa'], - $inp['lokasi'], - $inp['makroskopik'], - $inp['mikroskopik'], - $inp['kesimpulan'], - $userid, - $inp['detail_id'] - )); - //echo $this->db_smartone->last_query(); - - } - - $inp_rst = array( - 'doctor_id' => $doctor_id, - 'no_sediaan' => $inp['no_sediaan'], - 'klinis' => $inp['klinis'], - 'diagnosa' => $inp['diagnosa'], - 'lokasi' => $inp['lokasi'], - 'makroskopik' => $inp['makroskopik'], - 'mikroskopik' => $inp['mikroskopik'], - 'kesimpulan' => $inp['kesimpulan'] - ); - $log_json = json_encode($inp_rst); - - $sql = "INSERT INTO log_other_patologianatomy ( - Log_OtherPatologiAnatomyT_OrderDetailID, - Log_OtherPatologiAnatomyDateTime, - Log_OtherPatologiAnatomySON, - Log_OtherPatologiAnatomyUserID - )VALUE( - {$inp['detail_id']}, - NOW(), - '{$log_json}', - {$userid} - )"; - $this->db_smartone->query($sql); - //echo $this->db_smartone->last_query(); - - $result = array("total" => 1, "records" => array(), "sql" => ''); - $this->sys_ok($result); - exit; - } - - function saveresult_cytologi() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = $inp['doctor']; - - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - if ($prm[0]['xid'] == '0') { - $sql = "INSERT INTO other_cytologi( - Other_CytologiT_OrderDetailID, - Other_CytologiM_DoctorID, - Other_CytologiUserID, - Other_CytologiCreated - ) - VALUES( - {$prm[0]['orderdetail_id']}, - {$doctor_id}, - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } else { - $sql = "SELECT * FROM other_cytologi WHERE Other_CytologiT_OrderDetailID = {$prm[0]['orderdetail_id']} AND Other_CytologiIsActive = 'Y'"; - $data_header = $this->db_smartone->query($sql)->row_array(); - $header_id = $data_header['Other_CytologiID']; - $sql = "UPDATE other_cytologi SET - Other_CytologiM_DoctorID = {$doctor_id}, - Other_CytologiUserID = {$userid} - WHERE - Other_CytologiID = {$header_id}"; - $this->db_smartone->query($sql); - } - foreach ($prm as $k => $v) { - if ($v['xid'] == '0') { - $results = str_replace("'", "\\'", $v['result']); - $sql = "INSERT INTO other_cytologidetails( - Other_CytologiDetailsOther_CytologiID , - Other_CytologiDetailsCode, - Other_CytologiDetailsLabel, - Other_CytologiDetailsResult, - Other_CytologiDetailsCreated, - Other_CytologiDetailsUserID - ) - VALUES( - {$header_id}, - '{$v['code']}', - '{$v['label']}', - '{$results}', - NOW(), - {$userid} - )"; - $query = $this->db_smartone->query($sql); - } else { - $results = str_replace("'", "\\'", $v['result']); - $sql = "UPDATE other_cytologidetails SET - Other_CytologiDetailsResult = '{$results}', - Other_CytologiDetailsUserID = {$userid} - WHERE - Other_CytologiDetailsID = {$v['xid']}"; - $query = $this->db_smartone->query($sql); - } - } - - $result = array("total" => 1, "records" => array(), "sql" => ''); - $this->sys_ok($result); - exit; - } - - function saveresult_mikro() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = $inp['doctor']; - $backteria_id = $inp['bacteria']; - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - - if ($inp['result_value'] != 'Negatif' && $inp['result_value'] != 'Positif') { - $prm['result_value'] = $prm['result_other']; - } else { - $prm['result_value'] = $inp['result_value']; - } - - if ($prm['xid'] == '0') { - $sql = "INSERT INTO other_mikro( - Other_MikroM_DoctorID, - Other_MikroResult, - Other_MikroT_BacteriaID, - Other_MikroT_OrderDetailID, - Other_MikroHasilBiakan, - Other_MikroSampleTypeName, - Other_MikroUserID, - Other_MikroCreated - ) - VALUES( - {$doctor_id}, - '{$prm['result_value']}', - {$backteria_id}, - {$prm['orderdetail_id']}, - '{$prm['hasil_biakan']}', - '{$prm['sample_name']}', - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } else { - $sql = "SELECT * FROM other_mikro WHERE Other_MikroT_OrderDetailID = {$prm['orderdetail_id']} AND Other_MikroIsActive = 'Y'"; - $data_header = $this->db_smartone->query($sql)->row_array(); - $header_id = $data_header['Other_MikroID']; - $sql = "UPDATE other_mikro SET - Other_MikroResult = '{$prm['result_value']}', - Other_MikroM_DoctorID = {$doctor_id}, - Other_MikroT_BacteriaID = {$backteria_id}, - Other_MikroHasilBiakan = '{$prm['hasil_biakan']}', - Other_MikroSampleTypeName = '{$prm['sample_name']}', - Other_MikroUserID = {$userid} - WHERE - Other_MikroID = {$header_id}"; - //echo $sql; - $this->db_smartone->query($sql); - } - - - - $sql = "UPDATE other_mikrodetails SET Other_MikroDetailsIsActive = 'N', Other_MikroDetailsUserID = 0 WHERE Other_MikroDetailsOther_MikroID = {$header_id}"; - $this->db_smartone->query($sql); - - $results = $prm['details']; - if ($inp['result_value'] == 'Positif') { - foreach ($results as $k => $v) { - if ($v['xid'] == '0') { - $sql = "INSERT INTO other_mikrodetails( - Other_MikroDetailsOther_MikroID , - Other_MikroDetailsT_AntibioticID, - Other_MikroDetailsValue, - Other_MikroDetailsNote, - Other_MikroDetailsCreated, - Other_MikroDetailsUserID - ) - VALUES( - {$header_id}, - '{$v['T_AntibioticID']}', - '{$v['value']}', - '{$v['note']}', - NOW(), - {$userid} - )"; - $query = $this->db_smartone->query($sql); - } else { - $sql = "UPDATE other_mikrodetails SET - Other_MikroDetailsT_AntibioticID = '{$v['T_AntibioticID']}', - Other_MikroDetailsValue = '{$v['value']}', - Other_MikroDetailsNote = '{$v['note']}', - Other_MikroDetailsIsActive = 'Y', - Other_MikroDetailsUserID = {$userid} - WHERE - Other_MikroDetailsID = {$v['xid']}"; - //echo $sql; - $query = $this->db_smartone->query($sql); - } - } - } - - - $result = array("total" => 1, "records" => array(), "sql" => ''); - $this->sys_ok($result); - exit; - } - - - function get_doctors_preparasi_sperma() - { - $prm = $this->sys_input; - // $id = $prm["id"]; - - $sql = " SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 10 AND - M_DoctorSOIsActive = 'Y' - ORDER BY M_DoctorName ASC"; - //echo $sql; - $query = $this->db_smartone->query($sql); - $rows = $query->result_array(); - $sql = " - SELECT '0' as id, 'Belum memilih metode' as name - UNION - SELECT M_MethodeSpermaID as id, M_MethodeSpermaName as name - FROM m_methodesperma - WHERE - M_MethodeSpermaIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $methodes = $this->db_smartone->query($sql)->result_array(); - - - $this->sys_ok(["records" => $rows, "methodes" => $methodes]); - } - - - function getpreparasispermaresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT other_preparasisperma.*, - Other_PreparasiSpermaID as xid, - Other_PreparasiSpermaT_OrderDetailID as orderdetail_id, - IFNULL(Other_PreparasiSpermaM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_PreparasiSpermaM_DoctorID) OR Other_PreparasiSpermaM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name, - IFNULL(M_MethodeSpermaID,0) as methode_id, - IFNULL(M_MethodeSpermaName,'') as methode_name - FROM other_preparasisperma - LEFT JOIN m_doctor ON Other_PreparasiSpermaM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - LEFT JOIN m_methodesperma ON Other_PreparasiSpermaM_MethodeSpermaID = M_MethodeSpermaID AND - M_MethodeSpermaIsActive = 'Y' - WHERE - Other_PreparasiSpermaT_OrderDetailID = {$id} AND Other_PreparasiSpermaIsActive = 'Y' - GROUP BY Other_PreparasiSpermaID"; - $query = $this->db_smartone->query($sql); - - if ($query) { - $rows = $query->row_array(); - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 10 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $sql = " - SELECT '0' as id, 'Belum memilih metode' as name - UNION - SELECT M_MethodeSpermaID as id, M_MethodeSpermaName as name - FROM m_methodesperma - WHERE - M_MethodeSpermaIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $methodes = $this->db_smartone->query($sql)->result_array(); - $images = array(); - $sql = "SELECT Other_PreparasiSpermaImgID as xid, - Other_PreparasiSpermaImgType as type, - CONCAT('/one-media/one-image-nonlab/',Other_PreparasiSpermaImgNewName) as image_url - FROM t_orderdetail - JOIN other_preparasisperma_img ON Other_PreparasiSpermaImgT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND - Other_PreparasiSpermaImgIsActive = 'Y' - WHERE - T_OrderDetailID = {$id} AND - T_OrderDetailIsActive = 'Y' - GROUP BY Other_PreparasiSpermaImgID"; - //echo $sql; - $images = $this->db_smartone->query($sql)->result_array(); - - $rst = array('doctors' => $doctors, 'methodes' => $methodes, 'results' => $rows, 'images' => $images); - $this->sys_ok(["records" => $rst]); - } else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - - function uploadimage_preparasi_sperma() - { - if (! $this->isLogin) { - $this->sys_error("Invalid Token"); - exit; - } - - $userid = $this->sys_user["M_UserID"]; - $data = []; - //print_r($_SERVER); - - $prm = $this->sys_input; - $orderid = $this->input->post('orderid'); - $type = $this->input->post('type'); - $labnumber = $this->input->post('labnumber'); - $sql = "UPDATE other_preparasisperma_img SET - Other_PreparasiSpermaImgIsActive = 'N', - Other_PreparasiSpermaImgUserID = {$userid} - WHERE - Other_PreparasiSpermaImgT_OrderHeaderID = {$orderid} AND - Other_PreparasiSpermaImgType = '{$type}'"; - //echo $sql; - $this->db_onedev->query($sql); - //$config['upload_path'] = 'assets/'; - - $path = '/home/one/project/one/one-media/one-image-nonlab/'; - //echo $path; - $config['upload_path'] = $path; - $config['allowed_types'] = 'jpg|jpeg|png|gif'; - - $config['max_size'] = '10000'; - $count = count($_FILES['files']['name']); - //echo $count; - $this->load->library('upload', $config); - - $error = []; - for ($i = 0; $i < $count; $i++) { - - - if (!empty($_FILES['files']['name'][$i])) { - - - - $_FILES['file']['name'] = $_FILES['files']['name'][$i]; - - $_FILES['file']['type'] = $_FILES['files']['type'][$i]; - - $_FILES['file']['tmp_name'] = $_FILES['files']['tmp_name'][$i]; - - $_FILES['file']['error'] = $_FILES['files']['error'][$i]; - - $_FILES['file']['size'] = $_FILES['files']['size'][$i]; - - - - $namex = $orderid . '-' . $labnumber . '-' . $this->generateRandomString(5); - //echo $namex; - - $config['file_name'] = $namex; - $this->upload->initialize($config); - //echo $config['file_name'] ; - - - - - - if ($this->upload->do_upload('file')) { - - $uploadData = $this->upload->data(); - - $filename = $uploadData['file_name']; - //echo $filename; - - - $sql = "INSERT INTO other_preparasisperma_img ( - Other_PreparasiSpermaImgT_OrderHeaderID, - Other_PreparasiSpermaImgType, - Other_PreparasiSpermaImgOldName, - Other_PreparasiSpermaImgNewName, - Other_PreparasiSpermaImgCreated, - Other_PreparasiSpermaImgUserID - ) - VALUES( - {$orderid}, - '{$type}', - '{$_FILES['files']['name'][$i]}', - '{$filename}', - NOW(), - {$userid} - - )"; - //echo $sql; - $this->db_onedev->query($sql); - $xlast_id = $this->db_onedev->insert_id(); - $data['totalFiles'][] = array('xid' => $xlast_id, 'type' => $type, 'image_url' => '/one-media/one-image-nonlab/' . $filename); - } else { - $error = array('error' => $this->upload->display_errors()); - } - } - } - - $result = array("total" => count($data['totalFiles']), "records" => $data['totalFiles'], 'errors' => $error); - $this->sys_ok($result); - } - - - function saveresult_preparasi_sperma() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = isset($inp['doctor']) ? $inp['doctor'] : 0; - $methode_id = isset($inp['methode']) ? $inp['methode'] : 0; - $orderdetail_id = $inp['orderdetailid']; - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - if ($prm['xid'] == '0') { - $sql = "INSERT INTO other_preparasisperma( - Other_PreparasiSpermaM_DoctorID, - Other_PreparasiSpermaT_OrderDetailID, - Other_PreparasiSpermaPreMotilitasA, - Other_PreparasiSpermaPreMotilitasB, - Other_PreparasiSpermaPreMotilitasC, - Other_PreparasiSpermaPreKonsentrasi, - Other_PreparasiSpermaPreKontaminan, - Other_PreparasiSpermaPostMotilitasA, - Other_PreparasiSpermaPostMotilitasB, - Other_PreparasiSpermaPostMotilitasC, - Other_PreparasiSpermaPostKonsentrasi, - Other_PreparasiSpermaPostKontaminan, - Other_PreparasiSpermaPreVolume, - Other_PreparasiSpermaPostVolume, - Other_PreparasiSpermaM_MethodeSpermaID, - Other_PreparasiSpermaNote, - Other_PreparasiSpermaUserID, - Other_PreparasiSpermaCreated - ) - VALUES( - {$doctor_id}, - {$orderdetail_id}, - '{$prm['Other_PreparasiSpermaPreMotilitasA']}', - '{$prm['Other_PreparasiSpermaPreMotilitasB']}', - '{$prm['Other_PreparasiSpermaPreMotilitasC']}', - '{$prm['Other_PreparasiSpermaPreKonsentrasi']}', - '{$prm['Other_PreparasiSpermaPreKontaminan']}', - '{$prm['Other_PreparasiSpermaPostMotilitasA']}', - '{$prm['Other_PreparasiSpermaPostMotilitasB']}', - '{$prm['Other_PreparasiSpermaPostMotilitasC']}', - '{$prm['Other_PreparasiSpermaPostKonsentrasi']}', - '{$prm['Other_PreparasiSpermaPostKontaminan']}', - '{$prm['Other_PreparasiSpermaPreVolume']}', - '{$prm['Other_PreparasiSpermaPostVolume']}', - '{$methode_id}', - '{$prm['Other_PreparasiSpermaNote']}', - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } else { - $sql = "SELECT * FROM other_preparasisperma WHERE Other_PreparasiSpermaT_OrderDetailID = {$orderdetail_id} AND Other_PreparasiSpermaIsActive = 'Y'"; - $data_header = $this->db_smartone->query($sql)->row_array(); - $header_id = $data_header['Other_PreparasiSpermaID']; - $sql = "UPDATE other_preparasisperma SET - Other_PreparasiSpermaM_DoctorID = {$doctor_id}, - Other_PreparasiSpermaPreMotilitasA = '{$prm['Other_PreparasiSpermaPreMotilitasA']}', - Other_PreparasiSpermaPreMotilitasB = '{$prm['Other_PreparasiSpermaPreMotilitasB']}', - Other_PreparasiSpermaPreMotilitasC = '{$prm['Other_PreparasiSpermaPreMotilitasC']}', - Other_PreparasiSpermaPreKonsentrasi = '{$prm['Other_PreparasiSpermaPreKonsentrasi']}', - Other_PreparasiSpermaPreKontaminan = '{$prm['Other_PreparasiSpermaPreKontaminan']}', - Other_PreparasiSpermaPostMotilitasA = '{$prm['Other_PreparasiSpermaPostMotilitasA']}', - Other_PreparasiSpermaPostMotilitasB = '{$prm['Other_PreparasiSpermaPostMotilitasB']}', - Other_PreparasiSpermaPostMotilitasC = '{$prm['Other_PreparasiSpermaPostMotilitasC']}', - Other_PreparasiSpermaPostKonsentrasi = '{$prm['Other_PreparasiSpermaPostKonsentrasi']}', - Other_PreparasiSpermaPostKontaminan = '{$prm['Other_PreparasiSpermaPostKontaminan']}', - Other_PreparasiSpermaPreVolume = '{$prm['Other_PreparasiSpermaPreVolume']}', - Other_PreparasiSpermaPostVolume = '{$prm['Other_PreparasiSpermaPostVolume']}', - Other_PreparasiSpermaM_MethodeSpermaID = '{$methode_id}', - Other_PreparasiSpermaNote = '{$prm['Other_PreparasiSpermaNote']}', - Other_PreparasiSpermaUserID = {$userid} - WHERE - Other_PreparasiSpermaID = {$header_id}"; - $this->db_smartone->query($sql); - } - - - $result = array("total" => 1, "records" => array(), "sql" => ''); - $this->sys_ok($result); - exit; - } - - function getdnafragmentasiresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT other_dnafragmentasi.*, - Other_DnaFragmentasiID as xid, - Other_DnaFragmentasiT_OrderDetailID as orderdetail_id, - IFNULL(Other_DnaFragmentasiM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_DnaFragmentasiM_DoctorID) OR Other_DnaFragmentasiM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name, - IFNULL(Other_DnaFragmentasiOther_DnaFragmentasiMethodeID,0) as methode_id, - IFNULL(Other_DnaFragmentasiMethodeName,'') as methode_name, - Other_DnaFragmentasiHaloLuas as halo_luas, - Other_DnaFragmentasiHaloSedang as halo_sedang, - Other_DnaFragmentasiHaloSempit as halo_sempit, - Other_DnaFragmentasiTanpaHalo as tanpa_halo, - Other_DnaFragmentasiDFI as dfi, - Other_DnaFragmentasiKesimpulan as kesimpulan, - Other_DnaFragmentasiCatatan as catatan - FROM other_dnafragmentasi - LEFT JOIN m_doctor ON Other_DnaFragmentasiM_DoctorID = M_DoctorID - LEFT JOIN other_dnafragmentasimethode ON Other_DnaFragmentasiOther_DnaFragmentasiMethodeID = Other_DnaFragmentasiMethodeID - WHERE - Other_DnaFragmentasiT_OrderDetailID = {$id} AND Other_DnaFragmentasiIsActive = 'Y' - GROUP BY Other_DnaFragmentasiID - LIMIT 1"; - //echo $sql; - $query = $this->db_smartone->query($sql); - - if ($query) { - $rows = $query->row_array(); - if (!$rows) { - $rows = array( - 'xid' => 0, - 'orderdetail_id' => $id, - 'doctor_id' => 0, - 'doctor_name' => '', - 'methode_id' => 0, - 'methode_name' => '', - 'halo_luas' => '', - 'halo_sedang' => '', - 'tanpa_halo' => '', - 'dfi' => '', - 'kesimpulan' => '', - 'catatan' => '' - ); - } - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID - WHERE - M_DoctorSONat_SubGroupID = 4 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - - $sql = " - SELECT '0' as id, 'Belum memilih metode' as name - UNION - SELECT Other_DnaFragmentasiMethodeID as id, Other_DnaFragmentasiMethodeName as name - FROM other_dnafragmentasimethode - WHERE - Other_DnaFragmentasiMethodeIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $methodes = $this->db_smartone->query($sql)->result_array(); - - - $rst = array('doctors' => $doctors, 'methodes' => $methodes, 'results' => $rows); - $this->sys_ok(["records" => $rst]); - } else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - function saveresult_dnafragmentasi() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = $inp['doctor']['id']; - $methode_id = $inp['methode']['id']; - $orderdetail_id = $inp['results']['orderdetail_id']; - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - if (intval($prm['xid']) == 0) { - $sql = "INSERT INTO other_dnafragmentasi( - Other_DnaFragmentasiT_OrderDetailID, - Other_DnaFragmentasiM_DoctorID, - Other_DnaFragmentasiOther_DnaFragmentasiMethodeID, - Other_DnaFragmentasiHaloLuas, - Other_DnaFragmentasiHaloSedang, - Other_DnaFragmentasiHaloSempit, - Other_DnaFragmentasiTanpaHalo, - Other_DnaFragmentasiDFI, - Other_DnaFragmentasiKesimpulan, - Other_DnaFragmentasiCatatan, - Other_DnaFragmentasiUserID, - Other_DnaFragmentasiLastUpdated - ) - VALUES( - {$orderdetail_id}, - {$doctor_id}, - {$methode_id}, - '{$prm['halo_luas']}', - '{$prm['halo_sedang']}', - '{$prm['halo_sempit']}', - '{$prm['tanpa_halo']}', - '{$prm['dfi']}', - '{$prm['kesimpulan']}', - '{$prm['catatan']}', - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } else { - $sql = "UPDATE other_dnafragmentasi SET - Other_DnaFragmentasiT_OrderDetailID = {$orderdetail_id}, - Other_DnaFragmentasiM_DoctorID = {$doctor_id}, - Other_DnaFragmentasiOther_DnaFragmentasiMethodeID = '{$methode_id}', - Other_DnaFragmentasiHaloLuas = '{$prm['halo_luas']}', - Other_DnaFragmentasiHaloSedang = '{$prm['halo_sedang']}', - Other_DnaFragmentasiHaloSempit = '{$prm['halo_sempit']}', - Other_DnaFragmentasiTanpaHalo = '{$prm['tanpa_halo']}', - Other_DnaFragmentasiDFI = '{$prm['dfi']}', - Other_DnaFragmentasiKesimpulan = '{$prm['kesimpulan']}', - Other_DnaFragmentasiCatatan = '{$prm['catatan']}', - Other_DnaFragmentasiLastUpdated = NOW(), - Other_DnaFragmentasiUserID = {$userid} - WHERE - Other_DnaFragmentasiID = {$prm['xid']}"; - //echo $sql; - $this->db_smartone->query($sql); - } - - - $result = array("total" => 1, "records" => array(), "sql" => ''); - $this->sys_ok($result); - exit; - } -} +db_smartone = $this->load->database("onedev", true); + $this->db_lab = $this->load->database('one_lab_log', TRUE); + $this->load->helper(array('form', 'url')); + } + function getMethodeID($natTestID) + { + $sql = "select M_MethodePriorityNat_MethodeID MethodeID, Nat_MethodeName + from + m_methode_priority + join nat_methode on Nat_MethodeID = M_MethodePriorityNat_MethodeID + and Nat_MethodeIsActive = 'Y' + join m_instrumentmethode on M_InstrumentMethodeNat_MethodeID = Nat_MethodeID and M_InstrumentMethodeIsActive = 'Y' + join nat_instrument on M_InstrumentMethodeNat_InstrumentID = Nat_InstrumentID + and Nat_InstrumentIsActive ='Y' + where M_MethodePriorityIsActive = 'Y' + and M_MethodePriorityNat_TestID = $natTestID + and M_MethodePriorityM_DayOfWeekID = dayofweek(now()) + order by M_MethodePriorityNumber desc + limit 0,1 "; + $qry = $this->db->query($sql); + if ($qry) { + $rows = $qry->result_array(); + if (count($rows) > 0) return array($rows[0]["MethodeID"], $rows[0]["Nat_MethodeName"]); + } + //2nd + $sql = "select + M_InstrumentMethodeNat_MethodeID MethodeID, Nat_MethodeName + from m_instrumentmethode + join nat_methode on M_InstrumentMethodeNat_MethodeID = Nat_MethodeID + and Nat_MethodeIsActive = 'Y' + join nat_instrument on M_InstrumentMethodeNat_InstrumentID = Nat_InstrumentID + and Nat_InstrumentIsActive ='Y' + where M_InstrumentMethodeNat_TestID = $natTestID + and M_InstrumentMethodeIsActive = 'Y' + order by M_InstrumentMethodePriority desc + limit 0,1"; + $qry = $this->db->query($sql); + if ($qry) { + $rows = $qry->result_array(); + if (count($rows) > 0) return array($rows[0]["MethodeID"], $rows[0]["Nat_MethodeName"]); + } + // + $sql = "select Nat_NormalValueNat_MethodeID MethodeID, Nat_MethodeName + from + nat_normalvalue + join nat_methode on Nat_NormalValueNat_MethodeID = Nat_MethodeID + and Nat_MethodeIsActive = 'Y' + where Nat_NormalValueNat_TestID = $natTestID + and Nat_NormalValueIsActive = 'Y' + order by Nat_NormalValueID + limit 0,1"; + $qry = $this->db->query($sql); + if ($qry) { + $rows = $qry->result_array(); + if (count($rows) > 0) return array($rows[0]["MethodeID"], $rows[0]["Nat_MethodeName"]); + } + return array(0, ""); + } + function get_normal_value($methodeID, $natTestID, $sexID, $ageInDay) + { + $this->load->library('ibl_sampling_normal'); + return $this->ibl_sampling_normal->get_normal_value_id($methodeID, $natTestID, $sexID, $ageInDay); + } + return 0; + } + function fn_fix_normal($order_id) + { + $sql = "select + T_OrderDetailID, M_PatientM_SexID, fn_global_age_count_day(M_PatientDOB, date(T_OrderHeaderDate)) Dob , + T_TestNat_TestID + from t_orderheader + join m_patient on T_OrderHeaderID = $order_id and T_OrderHeaderM_PatientID = M_PatientID + join t_orderdetail on T_OrderDetailT_OrderHeaderID = T_OrderHeaderID + and T_OrderDetailIsACtive = 'Y' + and ( T_OrderDetailNat_NormalValueID is null or T_OrderDetailNat_NormalValueID = 0 ) + join t_test on T_OrderDetailT_TestID = T_TestID and T_TestIsResult = 'Y' "; + $qry = $this->db->query($sql); + if (! $qry) { + return; + } + $rows = $qry->result_array(); + if (count($rows) == 0) return; + $sql_u = "update t_orderdetail + join nat_normalvalue on T_OrderDetailID = ? and Nat_NormalValueID = ? + set + T_OrderDetailNat_NormalValueID = Nat_NormalValueID, + T_OrderDetailNormalValueNote = Nat_NormalValueNote, + T_OrderDetailNormalValueDescription = Nat_NormalValueDescription, + T_OrderDetailMinValue = Nat_NormalValueMinValue, + T_OrderDetailMaxValue = Nat_NormalValueMaxValue, + T_OrderDetailMinValueInclusive = Nat_NormalValueMinValueInclusive, + T_OrderDetailMaxValueInclusive = Nat_NormalValueMaxValueInclusive, + T_OrderDetailNat_MethodeID = ?, + T_OrderdetailNat_MethodeName =?"; + + foreach ($rows as $r) { + $T_OrderDetailID = $r["T_OrderDetailID"]; + $sexID = $r["M_PatientM_SexID"]; + $ageInDay = $r["Dob"]; + $natTestID = $r["T_TestNat_TestID"]; + list($methodeID, $methodeName) = $this->getMethodeID($natTestID); + if ($methodeID == 0) continue; + $normalValueID = $this->get_normal_value($methodeID, $natTestID, $sexID, $ageInDay); + if ($normalValueID == 0) return; + $this->db->query($sql_u, array($T_OrderDetailID, $normalValueID, $methodeID, $methodeName)); + } + } + function update_order_sample($targetID, $sourceID) + { + $sql = "update t_ordersample target + join t_ordersample source on + target.T_OrderSampleID = ? + and target.T_OrderSampleWorklistReceive = 'N' + and source.T_OrderSampleID = ? + set + target.T_OrderSampleSampling = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSampling, source.T_OrderSampleSampling), + target.T_OrderSampleSamplingDate = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingDate, source.T_OrderSampleSamplingDate), + target.T_OrderSampleSamplingTime = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingTime, source.T_OrderSampleSamplingTime), + target.T_OrderSampleSamplingUserID = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingUserID, source.T_OrderSampleSamplingUserID), + + target.T_OrderSampleReceive = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceive, source.T_OrderSampleReceive), + target.T_OrderSampleReceiveDate = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveDate, source.T_OrderSampleReceiveDate), + target.T_OrderSampleReceiveTime = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveTime, source.T_OrderSampleReceiveTime), + target.T_OrderSampleReceiveUserID = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveUserID, source.T_OrderSampleReceiveUserID), + + target.T_OrderSampleVerification = if(target.T_OrderSampleVerification='Y',target.T_OrderSampleVerification, source.T_OrderSampleVerification), + target.T_OrderSampleVerificationDate =if(target.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationDate, source.T_OrderSampleVerificationDate), + target.T_OrderSampleVerificationTime =if(source.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationTime, source.T_OrderSampleVerificationTime), + target.T_OrderSampleVerificationUserID =if(source.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationUserID, source.T_OrderSampleVerificationUserID), + + target.T_OrderSampleProcessing = if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessing, source.T_OrderSampleProcessing), + target.T_OrderSampleProcessingDate= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingDate, source.T_OrderSampleProcessingDate), + target.T_OrderSampleProcessingTime= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingTime, source.T_OrderSampleProcessingTime), + target.T_OrderSampleProcessingUserID= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingUserID, source.T_OrderSampleProcessingUserID), + + target.T_OrderSampleReceiveHandling =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandling, source.T_OrderSampleReceiveHandling ), + target.T_OrderSampleReceiveHandlingDate =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingDate, source.T_OrderSampleReceiveHandlingDate), + target.T_OrderSampleReceiveHandlingTime =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingTime, source.T_OrderSampleReceiveHandlingTime), + target.T_OrderSampleReceiveHandlingUserID =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingUserID, source.T_OrderSampleReceiveHandlingUserID), + + target.T_OrderSampleHandling = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandling, source.T_OrderSampleHandling), + target.T_OrderSampleHandlingDate = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingDate, source.T_OrderSampleHandlingDate), + target.T_OrderSampleHandlingTime = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingTime, source.T_OrderSampleHandlingTime), + target.T_OrderSampleHandlingUserID = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingUserID, source.T_OrderSampleHandlingUserID), + + target.T_OrderSampleWorklistReceive = source.T_OrderSampleWorklistReceive, + target.T_OrderSampleWorklistReceiveDatetime = source.T_OrderSampleWorklistReceiveDateTime, + target.T_OrderSampleWorklistReceiveUserID = source.T_OrderSampleWorklistReceiveUserID + "; + $qry = $this->db->query($sql, array($targetID, $sourceID)); + if (! $qry) { + echo json_encode(array("status" => "ERR", "message" => print_r($this->db->error(), true))); + exit; + } + } + function fix_sample_serum($headerID) + { + //cari t_ordersample yg belum worklist receive dengan code 017% + $sql = "select T_OrderSampleID + from t_ordersample + join t_sampletype on + T_OrderSampleT_OrderHeaderID = ? + and T_OrderSampleWorklistReceive = 'N' + and T_OrderSampleIsActive = 'Y' + and T_OrderSampleT_SampleTypeID = T_SampletypeID + and T_SampleTypeCode like '017%' + "; + $qry = $this->db->query($sql, array($headerID)); + if (!$qry) { + echo json_encode(array("status" => "ERR", "message" => print_r($this->db->error(), true))); + exit; + } + $rows = $qry->result_array(); + if (count($rows) == 0) return; + //cari T_OrderSample yang sudah di receive yg terakhir + $sql = "select T_OrderSampleID + from t_ordersample + join t_sampletype on + T_OrderSampleT_OrderHeaderID = ? + and T_OrderSampleWorklistReceive = 'Y' + and T_OrderSampleIsActive = 'Y' + and T_OrderSampleT_SampleTypeID = T_SampletypeID + and T_SampleTypeCode like '017%' + order by T_OrderSampleWorklistReceiveDatetime desc + limit 0,1 + "; + $qry = $this->db->query($sql, array($headerID)); + if (!$qry) { + echo json_encode(array("status" => "ERR", "message" => print_r($this->db->error(), true))); + exit; + } + $rcv_rows = $qry->result_array(); + if (count($rcv_rows) == 0) return; + + //print_r($rows); + //print_r($rcv_rows); + $rcv_T_OrderSampleID = $rcv_rows[0]["T_OrderSampleID"]; + //ada yg belum di receive + foreach ($rows as $r) { + $T_OrderSampleID = $r["T_OrderSampleID"]; + $this->update_order_sample($T_OrderSampleID, $rcv_T_OrderSampleID); + } + } + public function search() + { + $prm = $this->sys_input; + $max_rst = 99; + + $id = $prm["order_id"]; + if ($id > 0) { + $this->fix_sample_serum($id); + $this->fn_fix_normal($id); + } + $lang = $this->lang_default_code; + $lang_id = isset($prm['lang_id']) ? $prm['lang_id'] : '0'; + + if ($lang_id != 0) { + $l = $this->db_smartone->where("Nat_LangID", $lang_id)->get("nat_lang")->row(); + $lang = $l->Nat_LangCode; + } + + //tambahan fajri + $sql = " UPDATE t_orderdetail + JOIN t_test ON T_OrderDetailT_TestID = T_TestID + SET T_OrderDetailT_TestIsResult = T_TestIsResult + WHERE + T_OrderDetailT_OrderHeaderID = {$id} AND + T_OrderDetailT_TestIsResult = '' AND + T_OrderDetailIsActive = 'Y'"; + $this->db_smartone->query($sql); + + $tot_count = 0; + $lq = ""; + $group_id = 0; + if (isset($prm['group_id'])) + $group_id = $prm['group_id']; + + if ($group_id != 0) { + $sql = "select distinct T_WorklistDetailNat_TestID Nat_TestID + from t_worklistdetailv2 + where T_WorklistDetailT_WorklistID = {$group_id}"; + $qry = $this->db_smartone->query($sql); + $rows = $qry->result_array(); + $nat_test_ids = "0"; + foreach ($rows as $r) { + $nat_test_ids .= ", " . $r["Nat_TestID"]; + } + $q_group = " ( $nat_test_ids ) "; + + $sql = " + SELECT a1.*, cOUNT(a2.T_OrderDetailID) level + FROM ( + SELECT IFNULL(y.T_OrderDetailT_TestID, x.T_OrderDetailT_TestID) t_testid, + IFNULL(y.T_OrderDetailT_TestName, y.T_OrderDetailT_TestName) t_testname, + y.T_OrderDetailResult result, y.T_OrderDetailResult result_old, y.T_OrderDetailNote note, y.T_OrderDetailNote note_old, + y.T_OrderDetailID id, + y.T_OrderDetailT_TestIsResult is_result, a.T_TestIsQuantitative is_quantitative, + y.T_OrderDetailResultFlag result_flag, + y.T_OrderDetailNat_NormalValueID normal_id, + y.T_OrderDetailNormalValueNote normal_note, y.T_OrderDetailNat_UnitName unit_name, + y.T_OrderdetailNat_MethodeID methode_id, y.T_OrderdetailNat_MethodeName methode_name, + a.T_TestNat_TestID nattest_id, a.T_TestID tx_id, count(T_ResultInstrumentID) as result_instrument_n, + y.T_OrderDetailVerification, T_OrderSampleReceive sample_receive, + T_OrderSampleProcessing sample_processing, T_OrderSampleWorklistReceive sample_worklist_receive, + IF(T_OrderDetailAddOnPreAnalytic = 'Y', T_OrderDetailAddOnPreAnalytic, PreAnalyticIsOk) pre_analytic, + T_OrderDetailAddOnPreAnalytic, + T_OrderHeaderID order_id, y.T_OrderDetailT_TestSasCode test_sas_code, + tx.T_TestSasCode, + T_OrderDetailAddOnResample `resample`, T_OrderDetailAddOnResampleStatus resample_status, + T_OrderDetailAddOnRef ref, y.T_OrderDetailVerification verification, y.T_OrderDetailValidation validation, + T_OrderPromiseDateTime, Group_ResultName as ResultGroupName + FROM t_orderdetail x + left join t_orderpromise on x.T_OrderDetailT_OrderPromiseID = T_OrderPromiseID + JOIN t_test tx ON x.T_OrderDetailT_TestID = T_TestID + JOIN t_test tcheck on tcheck.T_TestNat_TestID in {$q_group} + and ( tx.T_TestID = tcheck.T_TestID or tx.T_TestSasCode like concat(tcheck.T_TestSasCode,'%')) + JOIN group_resultdetail ON Group_ResultDetailT_TestID = x.T_OrderDetailT_TestID AND Group_ResultDetailIsActive = 'Y' + JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND Group_ResultResumeMcu = 'LAB' + LEFT JOIN t_orderdetail y ON x.T_OrderDetailT_TestSasCode LIKE CONCAT(y.T_OrderDetailT_TestSasCode, '%') + AND x.T_OrderDetailT_OrderHeaderID = y.T_OrderDetailT_OrderHeaderID + AND y.T_OrderDetailIsActive = 'Y' + LEFT JOIN t_orderdetailaddon ON x.T_OrderDetailID = T_OrderDetailAddOnT_OrderDetailID + JOIN t_orderheader ON y.T_OrderDetailT_OrderHeaderID = T_OrderHeaderID + LEFT JOIN t_test a ON y.T_OrderDetailT_TestID = a.T_TestID + AND a.T_TestIsNonLab = '' + LEFT JOIN (SELECT T_OrderSampleT_SampleTypeID, T_OrderSampleReceive, T_OrderSampleProcessing, T_OrderSampleWorklistReceive + FROM t_ordersample WHERE T_OrderSampleT_OrderHeaderID = {$id} + AND T_OrderSampleIsactive = 'Y' + GROUP BY T_OrderSampleT_SampleTypeID) os ON a.T_TestT_SampleTypeID = os.T_OrderSampleT_SampleTypeID + or os.T_OrderSampleT_SampleTypeID = fn_sampletype_from_local(a.T_TestNat_TestID) + + LEFT JOIN t_resultinstrument ON T_ResultInstrumentT_OrderDetailID = x.T_OrderDetailID + LEFT JOIN pre_analytic ON PreAnalyticNat_TestID = a.T_TestNat_TestID AND PreAnalyticDate = date(now()) and PreAnalyticIsActive = 'Y' + WHERE x.T_OrderDetailT_OrderHeaderID = {$id} + AND x.T_OrderDetailIsActive = 'Y' + GROUP BY y.T_OrderDetailT_TestID + ORDER BY y.T_OrderDetailT_TestSasCode ASC + ) a1 + + LEFT JOIN t_orderdetail a2 ON a2.T_OrderDetailT_OrderHeaderID = a1.order_id + AND a2.T_OrderDetailIsActive = 'Y' + AND a1.test_sas_code LIKE CONCAT(a2.T_OrderDetailT_testSasCode, '%') + GROUP BY a1.t_testid + order by a1.test_sas_code +"; + $query = $this->db_smartone->query($sql); + $lq = $this->db_smartone->last_query(); + } else { + $sql = " + SELECT a1.*, cOUNT(a2.T_OrderDetailID) level + FROM ( + SELECT IFNULL(y.T_OrderDetailT_TestID, x.T_OrderDetailT_TestID) t_testid, + IFNULL(y.T_OrderDetailT_TestName, y.T_OrderDetailT_TestName) t_testname, + y.T_OrderDetailResult result, y.T_OrderDetailResult result_old, y.T_OrderDetailNote note, y.T_OrderDetailNote note_old, + y.T_OrderDetailID id, + y.T_OrderDetailT_TestIsResult is_result, a.T_TestIsQuantitative is_quantitative, + y.T_OrderDetailResultFlag result_flag, + y.T_OrderDetailNat_NormalValueID normal_id, + y.T_OrderDetailNormalValueNote normal_note, y.T_OrderDetailNat_UnitName unit_name, + y.T_OrderdetailNat_MethodeID methode_id, y.T_OrderdetailNat_MethodeName methode_name, + a.T_TestNat_TestID nattest_id, a.T_TestID tx_id, count(T_ResultInstrumentID) as result_instrument_n, + y.T_OrderDetailVerification, T_OrderSampleReceive sample_receive, + T_OrderSampleProcessing sample_processing, T_OrderSampleWorklistReceive sample_worklist_receive, + IF(T_OrderDetailAddOnPreAnalytic = 'Y', T_OrderDetailAddOnPreAnalytic, PreAnalyticIsOk) pre_analytic, + T_OrderDetailAddOnPreAnalytic, + T_OrderHeaderID order_id, y.T_OrderDetailT_TestSasCode test_sas_code, + tx.T_TestSasCode, + T_OrderDetailAddOnResample `resample`, T_OrderDetailAddOnResampleStatus resample_status, + T_OrderDetailAddOnRef ref, y.T_OrderDetailVerification verification, y.T_OrderDetailValidation validation, + T_OrderPromiseDateTime , Group_ResultName as ResultGroupName + FROM t_orderdetail x + left join t_orderpromise on x.T_OrderDetailT_OrderPromiseID = T_OrderPromiseID + JOIN t_test tx ON x.T_OrderDetailT_TestID = T_TestID + JOIN group_resultdetail ON Group_ResultDetailT_TestID = x.T_OrderDetailT_TestID AND Group_ResultDetailIsActive = 'Y' + JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND Group_ResultResumeMcu = 'LAB' + LEFT JOIN t_orderdetail y ON x.T_OrderDetailT_TestSasCode LIKE CONCAT(y.T_OrderDetailT_TestSasCode, '%') + AND x.T_OrderDetailT_OrderHeaderID = y.T_OrderDetailT_OrderHeaderID + AND y.T_OrderDetailIsActive = 'Y' + + LEFT JOIN t_orderdetailaddon ON x.T_OrderDetailID = T_OrderDetailAddOnT_OrderDetailID + + JOIN t_orderheader ON y.T_OrderDetailT_OrderHeaderID = T_OrderHeaderID + LEFT JOIN t_test a ON y.T_OrderDetailT_TestID = a.T_TestID + AND a.T_TestIsNonLab = '' + LEFT JOIN (SELECT T_OrderSampleT_SampleTypeID, T_OrderSampleReceive, T_OrderSampleProcessing, T_OrderSampleWorklistReceive + FROM t_ordersample WHERE T_OrderSampleT_OrderHeaderID = {$id} + AND T_OrderSampleIsactive = 'Y' + GROUP BY T_OrderSampleT_SampleTypeID) os ON a.T_TestT_SampleTypeID = os.T_OrderSampleT_SampleTypeID + or os.T_OrderSampleT_SampleTypeID = fn_sampletype_from_local(a.T_TestNat_TestID) + + LEFT JOIN t_resultinstrument ON T_ResultInstrumentT_OrderDetailID = x.T_OrderDetailID + LEFT JOIN pre_analytic ON PreAnalyticNat_TestID = a.T_TestNat_TestID AND PreAnalyticDate = date(now()) and PreAnalyticIsActive = 'Y' + WHERE x.T_OrderDetailT_OrderHeaderID = {$id} + AND x.T_OrderDetailIsActive = 'Y' + GROUP BY y.T_OrderDetailT_TestID + ORDER BY y.T_OrderDetailT_TestSasCode ASC + ) a1 + + LEFT JOIN t_orderdetail a2 ON a2.T_OrderDetailT_OrderHeaderID = a1.order_id + AND a2.T_OrderDetailIsActive = 'Y' + AND a1.test_sas_code LIKE CONCAT(a2.T_OrderDetailT_testSasCode, '%') + GROUP BY a1.t_testid + order by a1.test_sas_code +"; + //echo $sql; + $query = $this->db_smartone->query($sql); + $lq = $this->db_smartone->last_query(); + } + // file_put_contents("/xtmp/re-query.sql",$lq); + + if ($query) { + $rst = []; + $rows = $query->result_array(); + + foreach ($rows as $k => $v) { + + if ($v['is_result'] == "Y" && $v['is_quantitative'] == "N") { + $v['template'] = []; + $x = $this->db_smartone->query("CALL sp_master_resulttemplate_get('{$v['t_testid']}')"); + $this->clean_mysqli_connection($this->db_smartone->conn_id); + if ($x) + $v['template'] = $x->result_array(); + } + + // IF Rujukan, by pas Pre Analytik + if ($v['ref'] == 'Y') + $v['pre_analytic'] = 'Y'; + if ($v["id"] == "885455") { + //sipe workaround + //$v["sample_receive"] = "Y"; + $v["sample_worklist_receive"] = "Y"; + } + $rst[] = $v; + } + + $result = array("total" => $tot_count, "records" => $rst, "total_display" => sizeof($rows), "q" => $lq); + $this->sys_ok($result); + } else { + $this->sys_error_db("RE Px rows", $this->db_smartone); + exit; + } + } + + public function save() + { + $prm = $this->sys_input; + $data = json_decode($prm["data"]); + $lang = $this->lang_default_code; + $lang_id = isset($prm['lang_id']) ? $prm['lang_id'] : '0'; + + if ($lang_id != 0) { + $l = $this->db_smartone->where("Nat_LangID", $lang_id)->get("nat_lang")->row(); + $lang = $l->Nat_LangCode; + } + + $sql_norm = "select T_OrderDetailMinValue, T_OrderDetailMaxValue, + T_OrderDetailMinValueInclusive, T_OrderDetailMaxValueInclusive, + Nat_TestFlagLow, Nat_TestFlagHigh + from t_orderdetail + join t_test on T_OrderDetailT_TestID = T_TestID + join nat_test on T_TestNat_TestID = Nat_TestID and T_TestIsActive = 'Y' + where T_OrderDetailID = ? "; + + $ids = []; + foreach ($data as $k => $v) { + if ($v->resultInstrumentID > 0) { + $sql_i = "select T_ResultInstrumentNat_NormalValueID normalValueID + from t_resultinstrument + where T_ResultInstrumentID = ?"; + $qry_i = $this->db_smartone->query($sql_i, array($v->resultInstrumentID)); + if ($qry_i) { + $rows_i = $qry_i->result_array(); + + if (count($rows_i) > 0) { + $sql_iu = "update t_orderdetail, nat_normalvalue , nat_methode + set T_OrderDetailMinValue = Nat_NormalValueMinValue, + T_OrderDetailMinValueInclusive = Nat_NormalValueMinValueInclusive, + T_OrderDetailMaxValue = Nat_NormalValueMaxValue , + T_OrderDetailMaxValueInclusive = Nat_NormalValueMaxValueInclusive, + T_OrderDetailNormalValueNote = Nat_NormalValueNote, + T_OrderDetailNormalValueDescription = Nat_NormalValueDescription, + T_OrderDetailNat_NormalValueID = Nat_NormalValueID, + T_OrderDetailNat_MethodeID = Nat_NormalValueNat_MethodeID, + T_OrderDetailNat_MethodeName = Nat_MethodeName + where T_OrderDetailID = ? and Nat_NormalValueID = ? + and Nat_NormalValueNat_MethodeID = Nat_MethodeID + "; + $this->db_smartone->query($sql_iu, array($v->id, $rows_i[0]["normalValueID"])); + //file_put_contents("/xtmp/update-nilai-normal", $this->db_smartone->last_query() . "\n", FILE_APPEND); + } + } + } + $y = $this->db_smartone->query("SELECT fn_process_sample_handling_perfect('{$v->order_id}', '{$v->test_id}') c") + ->row(); + $req_status = $y->c; + $qry_norm = $this->db_smartone->query($sql_norm, $v->id); + $result_flag = ""; + if ($qry_norm) { + $rows_norm = $qry_norm->result_array(); + if (count($rows_norm) > 0) { + $r = $rows_norm[0]; + if (is_numeric($v->result)) { + + if ($r["T_OrderDetailMinValueInclusive"] == "Y" && $v->result < $r["T_OrderDetailMinValue"]) { + $result_flag = $r["Nat_TestFlagLow"]; + } + if ($r["T_OrderDetailMinValueInclusive"] == "N" && $v->result <= $r["T_OrderDetailMinValue"]) { + $result_flag = $r["Nat_TestFlagLow"]; + } + if ($r["T_OrderDetailMaxValueInclusive"] == "Y" && $v->result > $r["T_OrderDetailMaxValue"]) { + $result_flag = $r["Nat_TestFlagHigh"]; + } + if ($r["T_OrderDetailMaxValueInclusive"] == "N" && $v->result >= $r["T_OrderDetailMaxValue"]) { + $result_flag = $r["Nat_TestFlagHigh"]; + } + } + } + } + if ($lang == $this->lang_default_code) { + $this->db_smartone->set('T_OrderDetailResult', $v->result) + ->set('T_OrderDetailResultFlag', $result_flag) + ->set('T_OrderDetailNote', $v->note) + ->set('T_OrderDetailReqStatus', $req_status) + ->where('T_OrderDetailID', $v->id) + ->update('t_orderdetail'); + } else { + $this->db_smartone->set('T_OrderDetailLangResult', $v->result) + ->set('T_OrderDetailLangNote', $v->note) + ->where('T_OrderDetailLangID', $v->id) + ->update('t_orderdetaillang'); + } + + + + $ids[] = $v->id; + + //log detail + + $sql = "SELECT COUNT(*) n FROM log_orderdetail WHERE Log_OrderDetailT_OrderDetailID = ? AND Log_OrderDetailResult = ? ORDER BY Log_OrderDetailID DESC LIMIT 1"; + $qry = $this->db_lab->query($sql, [$v->id, $v->result]); + if ($qry) { + $n = $qry->row(); + + if ($n->n == 0) { + $sql = "SELECT * FROM t_orderdetail WHERE T_OrderDetailID = ?"; + $qry_order = $this->db_smartone->query($sql, [$v->id]); + $dt_orderdetail = $qry_order->row(); + $dt_detail_log = json_encode($dt_orderdetail); + + $sql = "INSERT INTO log_orderdetail ( + Log_OrderDetailStatus, + Log_OrderDetailT_OrderDetailID, + Log_OrderDetailResult, + Log_OrderDetailJSON, + Log_OrderDetailCreated, + Log_OrderDetailUserID + ) + VALUES (?,?, ?, ?, NOW(), ?)"; + $this->db_lab->query($sql, ['RESULTENTRY',$v->id, $v->result, $dt_detail_log, $this->sys_user['M_UserID']]); + //echo $this->db_lab->last_query(); + //exit(); + } + } + } + + // LOG Process + $order = $this->db_smartone->select('T_OrderDetailT_OrderHeaderID id, T_OrderHeaderLabNumber lab_number', false) + ->join('t_orderheader', 'T_OrderHeaderID = T_OrderDetailT_OrderHeaderID') + ->where('T_OrderDetailID', $data[0]->id) + ->get('t_orderdetail') + ->row(); + + $dblog = $this->db_lab; + $dblog->set('Log_ProcessCode', 'PROCESS.Result.Entry') + ->set('Log_ProcessOrderID', $order->id) + ->set('Log_ProcessOrderNumber', $order->lab_number) + ->set('Log_ProcessJson', json_encode($data)) + ->set('Log_ProcessUserID', $this->sys_user['M_UserID']) + ->insert('log_process'); + // END OF Log Process + //auto calculation + $this->load->library("Resultcalc"); + $rows = $this->resultcalc->auto($order->id); + + try { + foreach ($ids as $id) { + $this->db_smartone->query("call sp_set_normal_value_flag($id)"); + $this->clean_mysqli_connection($this->db_smartone->conn_id); + } + } catch (Exception $e) { + } + + $this->sys_ok($ids); + } + + public function save_template() + { + $prm = $this->sys_input; + + $n = $this->db_smartone->select("COUNT(T_ResultTemplateID) n") + ->where("T_ResultTemplateT_TestID", $prm['test_id']) + ->where("T_ResultTemplateIsActive", "Y") + ->where("T_ResultTemplateValue", $prm['value']) + ->get('t_resulttemplate') + ->row(); + if ($n->n > 0) { + $this->sys_error_db("Insert Result Template", $this->db_smartone); + return; + } + + $r = $this->db_smartone->set("T_ResultTemplateT_TestID", $prm['test_id']) + ->set("T_ResultTemplateValue", $prm['value']) + ->insert('t_resulttemplate'); + if ($r) { + $template = []; + $x = $this->db_smartone->query("CALL sp_master_resulttemplate_get('{$prm['test_id']}')"); + $this->clean_mysqli_connection($this->db_smartone->conn_id); + if ($x) + $template = $x->result_array(); + + $this->sys_ok($template); + } + } + + public function export() + { + $prm = $this->sys_input; + + $sql = "CALL sp_process_result_lang(?, ?, ?, ?)"; + $query = $this->db_smartone->query($sql, [$prm['order_id'], $prm['lang_id'], $prm['is_si'], $this->sys_user['M_UserID']]); + if ($query) { + $r = $query->row(); + if ($r->status == "OK") { + $this->sys_ok($r->data); + return; + } + + $this->sys_error_db("Message : " . $r->message, $this->db_smartone); + } else { + $this->sys_error_db("Lang Result", $this->db_smartone); + return; + } + } + + public function search_group() + { + $prm = $this->sys_input; + $max_rst = 100; + + // QUERY TOTAL + $sql = "select count(*) total + from t_worklist + where T_WorklistIsActive = 'Y' + order by T_WorklistName ASC"; + $query = $this->db_smartone->query($sql); + + if ($query) { + $tot_count = $query->result_array()[0]["total"]; + } else { + $this->sys_error_db("worklist count", $this->db_smartone); + exit; + } + + $sql = "select T_WorklistID group_id, T_WorklistName group_name + from t_worklist + where T_WorklistIsActive = 'Y' + order by T_WorklistName ASC + limit 0, {$max_rst}"; + $query = $this->db_smartone->query($sql); + + if ($query) { + $rows = $query->result_array(); + foreach ($rows as $k => $v) + $rows[$k]['data'] = json_decode($v['data']); + $result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows), "q" => $this->db_smartone->last_query()); + $this->sys_ok($result); + } else { + $this->sys_error_db("worklist rows", $this->db_smartone); + exit; + } + } + + public function search_rerun() + { + $prm = $this->sys_input; + $id = $prm["detail_id"]; + + $sql = "CALL sp_process_result_rerun(?)"; + $query = $this->db_smartone->query($sql, [$id]); + + if ($query) { + $rows = $query->result_array(); + $this->sys_ok(["records" => $rows]); + } else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + + + function getdoctorsfna() + { + $prm = $this->sys_input; + // $id = $prm["id"]; + + $sql = " SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY M_DoctorName ASC"; + //echo $sql; + $query = $this->db_smartone->query($sql); + + if ($query) { + $rows = $query->result_array(); + $this->sys_ok(["records" => $rows]); + } else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + function getfnaresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT Other_FNADetailsID as xid, + Other_FNAT_OrderDetailID as orderdetail_id, + Other_FNADetailsCode as code, + Other_FNADetailsLabel as label, + Other_FNADetailsResult as result, + IFNULL(Other_FNAM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_FNAM_DoctorID) OR Other_FNAM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_fna + JOIN other_fnadetails ON Other_FNADetailsOther_FNAID = Other_FNAID AND Other_FNADetailsIsActive = 'Y' + LEFT JOIN m_doctor ON Other_FNAM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_FNAT_OrderDetailID = {$id} AND Other_FNAIsActive = 'Y' + GROUP BY Other_FNADetailsID + ORDER BY Other_FNADetailsCode ASC"; + $query = $this->db_smartone->query($sql); + + if ($query) { + $rows = $query->result_array(); + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $images = array(); + $sql = "SELECT So_ImageUploadID as xid, + CONCAT('/one-media/one-image-nonlab/',So_ImageUploadNewName) as image_url + FROM t_orderdetail + JOIN so_imageupload ON So_ImageUploadT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND + So_ImageUploadIsActive = 'Y' + WHERE + T_OrderDetailID = {$id} AND + T_OrderDetailIsActive = 'Y' + GROUP BY So_ImageUploadID"; + $images = $this->db_smartone->query($sql)->result_array(); + + $rst = array('doctors' => $doctors, 'results' => $rows, 'images' => $images); + $this->sys_ok(["records" => $rst]); + } else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + function getpatologianatomyresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT Other_PatologiAnatomyID as xid, + Other_PatologiAnatomyT_OrderDetailID as orderdetail_id, + Other_PatologiAnatomyNoSediaan as no_sediaan, + Other_PatologiAnatomyDiagnosaKlinis as diagnosa, + Other_PatologiAnatomyKeteranganKlinis as klinis, + Other_PatologiAnatomyLokasiOrgan as lokasi, + Other_PatologiAnatomyMakroskopik as makroskopik, + Other_PatologiAnatomyMikroskopik as mikroskopik, + Other_PatologiAnatomyKesimpulan as kesimpulan, + IFNULL(Other_PatologiAnatomyM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_PatologiAnatomyM_DoctorID) OR Other_PatologiAnatomyM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_patologi_anatomy + LEFT JOIN m_doctor ON Other_PatologiAnatomyM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_PatologiAnatomyT_OrderDetailID = {$id} AND Other_PatologiAnatomyIsActive = 'Y' + GROUP BY Other_PatologiAnatomyID + ORDER BY Other_PatologiAnatomyID ASC + LIMIT 1"; + $query = $this->db_smartone->query($sql); + + if ($query) { + $rows = $query->row_array(); + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + + $sql = "SELECT So_ImageUploadPatologyAnatomyID as xid, + CONCAT('/one-media/one-image-nonlab/',So_ImageUploadPatologyAnatomyNewName) as image_url, + So_ImageUploadPatologyAnatomyType as type + FROM t_orderdetail + JOIN so_imageupload_patology_anatomy ON So_ImageUploadPatologyAnatomyT_OrderHeaderID= T_OrderDetailT_OrderHeaderID AND + So_ImageUploadPatologyAnatomyIsActive= 'Y' + WHERE + T_OrderDetailID = {$id} AND + T_OrderDetailIsActive = 'Y' + GROUP BY So_ImageUploadPatologyAnatomyID"; + $images = $this->db_smartone->query($sql)->result_array(); + $mikro = []; + $makro = []; + + foreach ($images as $key => $value) { + + if ($value['type'] == 'mikro') { + $mikro[] = $value; + } + if ($value['type'] == 'makro') { + $makro[] = $value; + } + } + + $rst = array('doctors' => $doctors, 'result' => $rows, "mikro" => $mikro, "makro" => $makro); + $this->sys_ok(["records" => $rst]); + } else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + + + + function uploadimage() + { + if (! $this->isLogin) { + $this->sys_error("Invalid Token"); + exit; + } + + $userid = $this->sys_user["M_UserID"]; + $data = []; + //print_r($_SERVER); + + $prm = $this->sys_input; + $orderid = $this->input->post('orderid'); + $labnumber = $this->input->post('labnumber'); + $sql = "UPDATE so_imageupload SET + So_ImageUploadIsActive = 'N', + So_ImageUploadUserID = {$userid} + WHERE + So_ImageUploadT_OrderHeaderID = {$orderid}"; + //echo $sql; + $this->db_onedev->query($sql); + //$config['upload_path'] = 'assets/'; + + $path = '/home/one/project/one/one-media/one-image-nonlab/'; + //echo $path; + $config['upload_path'] = $path; + $config['allowed_types'] = 'jpg|jpeg|png|gif'; + + $config['max_size'] = '10000'; + $count = count($_FILES['files']['name']); + //echo $count; + $this->load->library('upload', $config); + + $error = []; + for ($i = 0; $i < $count; $i++) { + + + if (!empty($_FILES['files']['name'][$i])) { + + + + $_FILES['file']['name'] = $_FILES['files']['name'][$i]; + + $_FILES['file']['type'] = $_FILES['files']['type'][$i]; + + $_FILES['file']['tmp_name'] = $_FILES['files']['tmp_name'][$i]; + + $_FILES['file']['error'] = $_FILES['files']['error'][$i]; + + $_FILES['file']['size'] = $_FILES['files']['size'][$i]; + + + + $namex = $orderid . '-' . $labnumber . '-' . $this->generateRandomString(5); + //echo $namex; + + $config['file_name'] = $namex; + $this->upload->initialize($config); + //echo $config['file_name'] ; + + + + + + if ($this->upload->do_upload('file')) { + + $uploadData = $this->upload->data(); + + $filename = $uploadData['file_name']; + //echo $filename; + + + $sql = "INSERT INTO so_imageupload ( + So_ImageUploadT_OrderHeaderID, + So_ImageUploadT_OrderHeaderLabNumber, + So_ImageUploadT_SampleTypeID, + So_ImageUploadOldName, + So_ImageUploadNewName, + So_ImageUploadCreated, + So_ImageUploadUserID + ) + VALUES( + {$orderid}, + '{$labnumber}', + '150', + '{$_FILES['files']['name'][$i]}', + '{$filename}', + NOW(), + {$userid} + + )"; + //echo $sql; + $this->db_onedev->query($sql); + $xlast_id = $this->db_onedev->insert_id(); + $data['totalFiles'][] = array('xid' => $xlast_id, 'image_url' => '/one-media/one-image-nonlab/' . $filename); + } else { + $error = array('error' => $this->upload->display_errors()); + } + } + } + + $result = array("total" => count($data['totalFiles']), "records" => $data['totalFiles'], 'errors' => $error); + $this->sys_ok($result); + } + function uploadimagePatologiAnatomi() + { + if (! $this->isLogin) { + $this->sys_error("Invalid Token"); + exit; + } + + $userid = $this->sys_user["M_UserID"]; + $data = []; + //print_r($_SERVER); + + $prm = $this->sys_input; + $orderid = $this->input->post('orderid'); + $type = $this->input->post('type'); + $labnumber = $this->input->post('labnumber'); + $sql = "UPDATE so_imageupload_patology_anatomy SET + So_ImageUploadPatologyAnatomyIsActive = 'N', + So_ImageUploadPatologyAnatomyUserID = {$userid} + WHERE + So_ImageUploadPatologyAnatomyT_OrderHeaderID = {$orderid} + AND So_ImageUploadPatologyAnatomyType = '{$type}'"; + //echo $sql; + $qry = $this->db_onedev->query($sql); + $last_qry = $this->db_onedev->last_query(); + if (!$qry) { + $message = $this->db_onedev->error(); + $message['last_qry'] = $last_qry; + $this->sys_error_db($message); + exit; + } + //$config['upload_path'] = 'assets/'; + + $path = '/home/one/project/one/one-media/one-image-nonlab/'; + //echo $path; + $config['upload_path'] = $path; + $config['allowed_types'] = 'jpg|jpeg|png|gif'; + + $config['max_size'] = '10000'; + $count = count($_FILES['files']['name']); + //echo $count; + $this->load->library('upload', $config); + + $error = []; + for ($i = 0; $i < $count; $i++) { + + + if (!empty($_FILES['files']['name'][$i])) { + + + + $_FILES['file']['name'] = $_FILES['files']['name'][$i]; + + $_FILES['file']['type'] = $_FILES['files']['type'][$i]; + + $_FILES['file']['tmp_name'] = $_FILES['files']['tmp_name'][$i]; + + $_FILES['file']['error'] = $_FILES['files']['error'][$i]; + + $_FILES['file']['size'] = $_FILES['files']['size'][$i]; + + + + $namex = $orderid . '-' . $labnumber . '-' . $this->generateRandomString(5); + //echo $namex; + + $config['file_name'] = $namex; + $this->upload->initialize($config); + //echo $config['file_name'] ; + + + + + + if ($this->upload->do_upload('file')) { + + $uploadData = $this->upload->data(); + + $filename = $uploadData['file_name']; + //echo $filename; + + + $sql = "INSERT INTO so_imageupload_patology_anatomy ( + So_ImageUploadPatologyAnatomyT_OrderHeaderID, + So_ImageUploadPatologyAnatomyT_OrderHeaderLabNumber, + So_ImageUploadPatologyAnatomyT_SampleTypeID, + So_ImageUploadPatologyAnatomyOldName, + So_ImageUploadPatologyAnatomyNewName, + So_ImageUploadPatologyAnatomyCreated, + So_ImageUploadPatologyAnatomyUserID, + So_ImageUploadPatologyAnatomyType + ) + VALUES( + {$orderid}, + '{$labnumber}', + '145', + '{$_FILES['files']['name'][$i]}', + '{$filename}', + NOW(), + {$userid}, + '{$type}' + + )"; + //echo $sql; + $qry = $this->db_onedev->query($sql); + $last_qry = $this->db_onedev->last_query(); + if (!$qry) { + $message = $this->db_onedev->error(); + $message['last_qry'] = $last_qry; + $this->sys_error_db($message); + exit; + } + $xlast_id = $this->db_onedev->insert_id(); + $data['totalFiles'][] = array('xid' => $xlast_id, 'image_url' => '/one-media/one-image-nonlab/' . $filename); + } else { + $error = array('error' => $this->upload->display_errors()); + } + } + } + + $result = array("total" => count($data['totalFiles']), "records" => $data['totalFiles'], 'errors' => $error); + $this->sys_ok($result); + } + + + function generateRandomString($length = 10) + { + $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; + $charactersLength = strlen($characters); + $randomString = ''; + for ($i = 0; $i < $length; $i++) { + $randomString .= $characters[rand(0, $charactersLength - 1)]; + } + return $randomString; + } + + function getcytologiresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT Other_CytologiDetailsID as xid, + Other_CytologiT_OrderDetailID as orderdetail_id, + Other_CytologiDetailsCode as code, + Other_CytologiDetailsLabel as label, + Other_CytologiDetailsResult as result, + IFNULL(Other_CytologiM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_CytologiM_DoctorID) OR Other_CytologiM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_cytologi + JOIN other_cytologidetails ON Other_CytologiDetailsOther_CytologiID = Other_CytologiID AND Other_CytologiDetailsIsActive = 'Y' + LEFT JOIN m_doctor ON Other_CytologiM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_CytologiT_OrderDetailID = {$id} AND Other_CytologiIsActive = 'Y' + GROUP BY Other_CytologiDetailsID + ORDER BY Other_CytologiDetailsCode ASC"; + //echo $sql; + $query = $this->db_smartone->query($sql); + + if ($query) { + $rows = $query->result_array(); + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $rst = array('doctors' => $doctors, 'results' => $rows); + $this->sys_ok(["records" => $rst]); + } else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + function getmikroresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT + Other_MikroID as xid, + Other_MikroHasilBiakan as hasil_biakan, + Other_MikroSampleTypeName as sample_name, + Other_MikroT_OrderDetailID as orderdetail_id, + Other_MikroResult as result_value, + '' as result_other, + IFNULL(T_BacteriaID,0) as T_BacteriaID, + IFNULL(T_BacteriaName,'') as T_BacteriaName, + '' as details, + IFNULL(Other_MikroM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_MikroM_DoctorID) OR Other_MikroM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_mikro + LEFT JOIN t_bacteria ON Other_MikroT_BacteriaID = T_BacteriaID + LEFT JOIN m_doctor ON Other_MikroM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_MikroT_OrderDetailID = {$id} AND Other_MikroIsActive = 'Y' + GROUP BY Other_MikroID"; + //echo $sql; + $query = $this->db_smartone->query($sql); + + if ($query) { + $row = $query->row_array(); + if ($row) { + if ($row['result_value'] != 'Positif' && $row['result_value'] != 'Negatif') { + $row['result_other'] = $row['result_value']; + $row['result_value'] = 'other'; + } + $sql = "SELECT '' as xno, + Other_MikroDetailsID as xid, + Other_MikroDetailsValue as value, + IF(Other_MikroDetailsNote = 'R','Y','N') as chx_r, + IF(Other_MikroDetailsNote = 'I','Y','N') as chx_i, + IF(Other_MikroDetailsNote = 'S','Y','N') as chx_s, + Other_MikroDetailsNote as note, + t_antibiotic.* + FROM other_mikrodetails + LEFT JOIN t_antibiotic ON Other_MikroDetailsT_AntibioticID = T_AntibioticID + WHERE + Other_MikroDetailsOther_MikroID = {$row['xid']} AND Other_MikroDetailsIsActive = 'Y' + GROUP BY Other_MikroDetailsID + ORDER BY T_AntibioticName ASC"; + //echo $sql; + $details = $this->db_smartone->query($sql)->result_array(); + if ($details) { + foreach ($details as $k => $v) { + $details[$k]['xno'] = $k + 1; + } + } + $row['details'] = $details; + } else { + $row = array('xid' => '0', 'hasil_biakan' => '', 'result_value' => 'Negatif', 'sample_name' => '', 'orderdetail_id' => $id, 'T_BacteriaID' => '0', 'T_BacteriaName' => '0', 'details' => array(), 'doctor_id' => '0', 'doctor_name' => '0'); + } + } else { + $row = array('xid' => '0', 'hasil_biakan' => '', 'result_value' => 'Negatif', 'sample_name' => '', 'orderdetail_id' => $id, 'T_BacteriaID' => '0', 'T_BacteriaName' => '0', 'details' => array(), 'doctor_id' => '0', 'doctor_name' => '0'); + } + //print_r($row); + + + + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 7 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $sql = " + SELECT '0' as id, 'Belum memilih bakteria' as name + UNION + SELECT T_BacteriaID as id, T_BacteriaName as name + FROM t_bacteria + WHERE + T_BacteriaIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $bacteries = $this->db_smartone->query($sql)->result_array(); + $rst = array('doctors' => $doctors, 'bacteries' => $bacteries, 'results' => $row); + $this->sys_ok(["records" => $rst]); + } + function getantibiotics() + { + $prm = $this->sys_input; + $id = $prm["id"]; + $sql = " SELECT '' as xno, + 0 as xid, + '' as hasil_biakan, + '' as sample_name, + 0 as value, + 'Y' as chx_r, + 'N' as chx_i, + 'N' as chx_s, + 'R' as note, + t_antibiotic.* + FROM t_antibiotic + WHERE + T_AntibioticT_BacteriaID = {$prm['id']} AND T_AntibioticIsActive= 'Y' + ORDER BY T_AntibioticName ASC"; + //echo $sql; + $rows = $this->db_smartone->query($sql)->result_array(); + if (rows) { + foreach ($rows as $k => $v) { + $rows[$k]['xno'] = $k + 1; + } + } + + $this->sys_ok(["records" => $rows]); + } + function getlcprepresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = "SELECT T_OrderDetailVerification as verification, T_OrderDetailValidation as validation FROM t_orderdetail WHERE T_OrderDetailID = ?"; + $order = $this->db_smartone->query($sql, array($id))->row_array(); + + + $sql = " SELECT Other_LcprepDetailsID as xid, + Other_LcprepID as header_id, + Other_LcprepT_orderDetailID as orderdetail_id, + Other_LcprepDetailsCode as code, + Other_LcprepDetailsLabel as label, + Other_LcprepDetailsResult as result, + IFNULL(Other_LcprepM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_LcprepM_DoctorID) OR Other_LcprepM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_lcprep + JOIN other_lcprepdetails ON Other_LcprepDetailsOther_LcprepID = Other_LcprepID AND Other_LcprepDetailsIsActive = 'Y' + LEFT JOIN m_doctor ON Other_LcprepM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_LcprepT_orderDetailID = ? AND Other_LcprepIsActive = 'Y' + GROUP BY Other_LcprepDetailsOther_LcprepID, Other_LcprepDetailsCode + ORDER BY Other_LcprepDetailsCode ASC"; + //echo $sql; + $rows = $this->db_smartone->query($sql, array($id))->result_array(); + if (count($rows) == 0) { + $rows = array( + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'A', + 'label' => 'DESKRIPSI', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ), + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'B', + 'label' => 'KESIMPULAN', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ) + ); + } + + $other_rows = array(); + $langs = array(array('id' => 1, 'name' => 'Bahasa Indonesia')); + $selected_lang = array(array('id' => 1, 'name' => 'Bahasa Indonesia')); + $sql = "SELECT T_OrderHeaderAddOnSecondM_LangID as lang_id, + M_LangName as lang_name + FROM t_orderdetail + JOIN t_orderheader ON T_OrderDetailT_OrderHeaderID = T_OrderHeaderID AND T_OrderHeaderIsActive = 'Y' + JOIN t_orderheaderaddon ON T_OrderHeaderAddonT_OrderHeaderID = T_OrderHeaderID AND T_OrderHeaderAddonIsActive = 'Y' + JOIN m_lang ON T_OrderHeaderAddOnSecondM_LangID = M_LangID AND M_LangIsActive = 'Y' + WHERE T_OrderDetailID = {$id} AND T_OrderDetailIsActive = 'Y'"; + + $other_lang = $this->db_smartone->query($sql)->result_array(); + if (count($other_lang) > 0) { + $langs[] = array('id' => $other_lang[0]['lang_id'], 'name' => $other_lang[0]['lang_name']); + $selected_lang = array('id' => $other_lang[0]['lang_id'], 'name' => $other_lang[0]['lang_name']); + + + $sql = " SELECT Other_LcprepDetailsLangsID as xid, + Other_LcprepID as header_id, + Other_LcprepT_orderDetailID as orderdetail_id, + Other_LcprepDetailsLangsCode as code, + Other_LcprepDetailsLangsLabel as label, + Other_LcprepDetailsLangsResult as result, + IFNULL(Other_LcprepM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_LcprepM_DoctorID) OR Other_LcprepM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_lcprep + JOIN other_lcprepdetails_lang ON Other_LcprepDetailsLangsOther_LcprepID = Other_LcprepID AND Other_LcprepDetailsLangsIsActive = 'Y' + LEFT JOIN m_doctor ON Other_LcprepM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_LcprepT_orderDetailID = {$id} AND Other_LcprepDetailsLangsIsActive = 'Y' + GROUP BY Other_LcprepDetailsLangsOther_LcprepID, Other_LcprepDetailsLangsCode + ORDER BY Other_LcprepDetailsLangsCode ASC"; + // echo $sql; + $other_rows = $this->db_smartone->query($sql)->result_array(); + if (count($other_rows) == 0) { + $other_rows = array( + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'AA', + 'label' => 'DESCRIPTION', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ), + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'BB', + 'label' => 'CONCLUSION', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ) + ); + } + } + + $header_id = $rows[0]['header_id']; + $sql = "SELECT IFNULL(Other_LcprepAdekuasiID,0) as xid, + Lcprep_AdekuasiID as id, + Lcprep_AdekuasiLabel as name, + Lcprep_AdekuasiLabel as name_en, + IF(ISNULL(Other_LcprepAdekuasiID),'N',Other_LcprepAdekuasiChex) as chex + FROM lcprep_adekuasi + LEFT JOIN other_lcprepadekuasi ON Other_LcprepAdekuasiLcprep_AdekuasiID = Lcprep_AdekuasiID AND + Other_LcprepAdekuasiOther_LcprepID = {$header_id} AND + Other_LcprepAdekuasiIsActive = 'Y' + WHERE + Lcprep_AdekuasiIsActive = 'Y' + GROUP BY Lcprep_AdekuasiID + ORDER BY Lcprep_AdekuasiOrder ASC + "; + //echo $sql; + $adeakuasi = $this->db_smartone->query($sql)->result_array(); + foreach ($adeakuasi as $kc => $vc) { + $adeakuasi[$kc]['chex'] = $vc['chex'] == 'N' ? false : true; + $adeakuasi[$kc]['name_en'] = $this->translate_word($vc['name']); + } + + $sql = "SELECT IFNULL(Other_LcprepKategoriUmumID,0) as xid, + Lcprep_KategoriUmumID as id, + Lcprep_KategoriUmumLabel as name, + Lcprep_KategoriUmumLabel as name_en, + IF(ISNULL(Other_LcprepKategoriUmumID),'N',Other_LcprepKategoriUmumChex) as chex + FROM lcprep_kategoriumum + LEFT JOIN other_lcprepkategoriumum ON Other_LcprepKategoriUmumLcprep_KategoriUmumID = Lcprep_KategoriUmumID AND + Other_LcprepKategoriUmumOther_LcprepID = {$header_id} AND + Other_LcprepKategoriUmumIsActive = 'Y' + WHERE + Lcprep_KategoriUmumIsActive = 'Y' + GROUP BY Lcprep_KategoriUmumID + "; + //echo $sql; + $kategoriumum = $this->db_smartone->query($sql)->result_array(); + foreach ($kategoriumum as $kc => $vc) { + $kategoriumum[$kc]['chex'] = $vc['chex'] == 'N' ? false : true; + $kategoriumum[$kc]['name_en'] = $this->translate_word($vc['name']); + } + + $sql = " + SELECT Lcprep_InterpretasiGroupID as group_id, + Lcprep_InterpretasiGroupName as group_name, + Lcprep_InterpretasiGroupName as group_name_en, + '' as subgroups + FROM lcprep_interpretasigroup + WHERE + Lcprep_InterpretasiGroupIsActive = 'Y' + "; + //echo $sql; + $interpretasi = $this->db_smartone->query($sql)->result_array(); + foreach ($interpretasi as $k => $v) { + $interpretasi[$k]['group_name_en'] = $this->translate_word($v['group_name']); + $subgroups = array(); + $sql = "SELECT Lcprep_InterpretasiSubgroupID as subgroup_id, + Lcprep_InterpretasiSubgroupName as subgroup_name, + Lcprep_InterpretasiSubgroupName as subgroup_name_en, + '' as childs + FROM lcprep_interpretasisubgroup + WHERE + Lcprep_InterpretasiSubgroupLcprep_InterpretasiGroupID = {$v['group_id']} AND Lcprep_InterpretasiSubgroupIsActive = 'Y'"; + //echo $sql; + $subgroups = $this->db_smartone->query($sql)->result_array(); + if (count($subgroups) > 0) { + foreach ($subgroups as $ki => $vi) { + $subgroups[$ki]['subgroup_name_en'] = $this->translate_word($vi['subgroup_name']); + $childs = array(); + + $sql = "SELECT IFNULL(Other_LcprepInterpretasiID,0) as xid, + IFNULL(Other_LcprepInterpretasiChex,'N') as chex, + IFNULL(Other_LcprepInterpretasiValue,'') as value, + IFNULL(Other_LcprepInterpretasiValueEng,'') as value_en, + Lcprep_InterpretasiID as id, + Lcprep_InterpretasiLcprep_InterpretasiSubgroupID as subgroup_id, + Lcprep_InterpretasiCode as code, + Lcprep_InterpretasiName as name, + Lcprep_InterpretasiName as name_en, + Lcprep_InterpretasiParentID as parent_id, + Lcprep_InterpretasiIsParent as is_parent, + Lcprep_InterpretasiHasResult as has_result, + Lcprep_InterpretasiTypeResult as type_result + FROM lcprep_interpretasi + LEFT JOIN other_lcprepinterpretasi ON Other_LcprepInterpretasiOther_LcprepID = {$header_id} AND + Other_LcprepInterpretasiLcprep_InterpretasiID = Lcprep_InterpretasiID AND + Other_LcprepInterpretasiIsActive = 'Y' + WHERE + Lcprep_InterpretasiLcprep_InterpretasiSubgroupID = {$vi['subgroup_id']} AND Lcprep_InterpretasiIsActive = 'Y' + GROUP BY Lcprep_InterpretasiID Order BY Lcprep_InterpretasiCode ASC"; + $childs = $this->db_smartone->query($sql)->result_array(); + if ($childs) { + foreach ($childs as $kc => $vc) { + $childs[$kc]['chex'] = $vc['chex'] == 'N' ? false : true; + $childs[$kc]['name_en'] = $this->translate_word($vc['name']); + } + } + $subgroups[$ki]['childs'] = $childs; + } + } + + $interpretasi[$k]['subgroups'] = $subgroups; + } + + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + + + + $rst = array('order' => $order, 'langs' => $langs, 'selected_lang' => $selected_lang, 'doctors' => $doctors, 'results' => $rows, 'other_results' => $other_rows, 'adekuasi' => $adeakuasi, 'kategoriumum' => $kategoriumum, 'interpretasi' => $interpretasi); + $this->sys_ok(["records" => $rst]); + } + + function translate_word($word) + { + $sql = "SELECT * + FROM translate_word + WHERE Translate_WordNat_LangID = '2' AND + BINARY Translate_WordFrom = '{$word}' AND + Translate_WordIsActive = 'Y' + LIMIT 1"; + $dt = $this->db_smartone->query($sql)->result_array(); + if (count($dt) > 0) { + return $dt[0]['Translate_WordTo']; + } else { + return $word; + } + } + + function getpapsmearresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT Other_PapSmearDetailsID as xid, + Other_PapSmearID as header_id, + Other_PapSmearT_OrderDetailID as orderdetail_id, + Other_PapSmearDetailsCode as code, + Other_PapSmearDetailsLabel as label, + Other_PapSmearDetailsResult as result, + IFNULL(Other_PapSmearM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_PapSmearM_DoctorID) OR Other_PapSmearM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_papsmear + JOIN other_papsmeardetails ON Other_PapSmearDetailsOther_PapSmearID = Other_PapSmearID AND Other_PapSmearDetailsIsActive = 'Y' + LEFT JOIN m_doctor ON Other_PapSmearM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_PapSmearT_OrderDetailID = {$id} AND Other_PapSmearIsActive = 'Y' + GROUP BY Other_PapSmearDetailsID + ORDER BY Other_PapSmearDetailsCode ASC"; + //echo $sql; + $rows = $this->db_smartone->query($sql)->result_array(); + if (!$rows) { + $rows = array( + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'A', + 'label' => 'Makroskopik', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ), + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'B', + 'label' => 'Mikroskopik', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ), + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'C', + 'label' => 'Kesimpulan', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ) + ); + } + + $header_id = $rows[0]['header_id']; + $sql = "SELECT Other_PapSmearMaturasiID as xid, + Other_PapSmearMaturasiValue as value + FROM other_papsmearmaturasi + WHERE + Other_PapSmearMaturasiOther_PapSmearID = {$header_id} AND + Other_PapSmearMaturasiIsActive = 'Y' + "; + //echo $sql; + $dt_maturasi = $this->db_smartone->query($sql)->row_array(); + if (!$dt_maturasi) { + $maturasi = array('xid' => '0', 'value' => array('', '', '')); + } else { + $value = explode('/', $dt_maturasi['value']); + $maturasi = array('xid' => $dt_maturasi['xid'], 'value' => $value); + } + + $sql = "SELECT IFNULL(Other_PapSmearBahanID,0) as xid, + M_PapSmearBahanID as bahan_id, + M_PapSmearBahanName as name, + IF(ISNULL(Other_PapSmearBahanID),'N','Y') as selected + FROM m_papsmearbahan + LEFT JOIN other_papsmearbahan ON Other_PapSmearBahanM_PapSmearBahanID = M_PapSmearBahanID AND + Other_PapSmearBahanOther_PapSmearID = {$header_id} AND + Other_PapSmearBahanIsActive = 'Y' + WHERE + M_PapSmearBahanIsActive = 'Y' + ORDER BY M_PapSmearBahanID ASC + "; + //echo $sql; + $bahans = $this->db_smartone->query($sql)->result_array(); + + $sql = "SELECT IFNULL(Other_PapsmearCategoryID,0) as xid, + M_PapSmearCategoryID as category_id, + M_PapSmearCategoryName as name, + IF(ISNULL(Other_PapsmearCategoryID),'N','Y') as selected + FROM m_papsmearcategory + LEFT JOIN other_papsmearcategory ON Other_PapsmearCategoryM_PapSmearCategoryID = M_PapSmearCategoryID AND + Other_PapsmearCategoryOther_PapSmearID = {$header_id} AND + Other_PapsmearCategoryIsActive = 'Y' + WHERE + M_PapSmearCategoryIsActive = 'Y' + ORDER BY M_PapSmearCategoryID ASC + "; + //echo $sql; + $categories = $this->db_smartone->query($sql)->result_array(); + + $sql = "SELECT IFNULL(Other_PapSmearCheckID,0) as xid, + M_PapSmearCheckID as check_id, + M_PapSmearCheckLabel as name, + IF(ISNULL(Other_PapSmearCheckID),'N','Y') as selected, + Other_PapSmearCheckNote as note + FROM m_papsmearcheck + LEFT JOIN other_papsmearcheck ON Other_PapSmearCheckM_PapSmearCheckID = M_PapSmearCheckID AND + Other_PapSmearCheckOther_PapSmearID = {$header_id} AND + Other_PapSmearCheckIsActive = 'Y' + WHERE + M_PapSmearCheckIsActive = 'Y' + ORDER BY M_PapSmearCheckCode ASC + "; + $checks = $this->db_smartone->query($sql)->result_array(); + + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $rst = array('doctors' => $doctors, 'checks' => $checks, 'bahans' => $bahans, 'categories' => $categories, 'maturasi' => $maturasi, 'results' => $rows); + $this->sys_ok(["records" => $rst]); + } + + function saveresult_lcprep() + { + $prm = $this->sys_input; + $detail_id = $prm['detail_id']; + $doctor_id = $prm['doctor']; + $adekuasi = $prm['adekuasi']; + $kategoriumum = $prm['kategoriumum']; + $interpretasi = $prm['interpretasi']; + $results = $prm['results']; + $selected_lang = $prm['selected_lang']; + $other_results = $prm['other_results']; + + $userid = $this->sys_user['M_UserID']; + + $header_id = 0; + $sql = "SELECT * FROM other_lcprep WHERE Other_LcprepT_orderDetailID = ? AND Other_LcprepIsActive = 'Y'"; + $dt_header = $this->db_smartone->query($sql, array($detail_id))->row_array(); + if ($dt_header) { + $header_id = $dt_header['Other_LcprepID']; + } + if ($header_id == 0) { + $sql = "INSERT INTO other_lcprep( + Other_LcprepT_orderDetailID, + Other_LcprepM_DoctorID, + Other_LcprepUserID, + Other_LcprepCreated + ) + VALUES( + ?, + ?, + ?, + NOW() + )"; + //echo $sql; + $query = $this->db_smartone->query($sql, array($detail_id, $doctor_id, $userid)); + if(!$query){ + echo $this->db_smartone->last_query(); + exit; + } + $header_id = $this->db_smartone->insert_id(); + } else { + $sql = "UPDATE other_lcprep SET Other_LcprepM_DoctorID = ?, Other_LcprepUserID = ? WHERE Other_LcprepID = ?"; + $query = $this->db_smartone->query($sql, array($doctor_id, $userid, $header_id)); + if(!$query){ + echo $this->db_smartone->last_query(); + exit; + } + } + + + + if ($adekuasi) { + foreach ($adekuasi as $k => $v) { + $selected = $v['chex'] ? 'Y' : 'N'; + if (intval($v['xid'] == 0)) { + $sql = "UPDATE other_lcprepadekuasi SET Other_LcprepAdekuasiIsActive = 'N' + WHERE + Other_LcprepAdekuasiOther_LcprepID = ? AND + Other_LcprepAdekuasiIsActive = 'Y' AND + Other_LcprepAdekuasiLcprep_AdekuasiID = ?"; + $query = $this->db_smartone->query($sql, array($header_id, $v['id'])); + if(!$query){ + echo $this->db_smartone->last_query(); + exit; + } + $sql = "INSERT INTO other_lcprepadekuasi ( + Other_LcprepAdekuasiOther_LcprepID, + Other_LcprepAdekuasiLcprep_AdekuasiID, + Other_LcprepAdekuasiChex, + Other_LcprepAdekuasiUserID, + Other_LcprepAdekuasiCreated + ) + VALUES( + ?, + ?, + ?, + ?, + NOW() + )"; + $query = $this->db_smartone->query($sql, array($header_id, $v['id'], $selected, $userid)); + if(!$query){ + echo $this->db_smartone->last_query(); + exit; + } + //echo $sql; + } + if (intval($v['xid'] != 0)) { + + $sql = "UPDATE other_lcprepadekuasi SET + Other_LcprepAdekuasiChex = ?, + Other_LcprepAdekuasiUserID = ? + WHERE + Other_LcprepAdekuasiID = ? + "; + $query = $this->db_smartone->query($sql, array($selected, $userid, $v['xid'])); + if(!$query){ + echo $this->db_smartone->last_query(); + exit; + } + } + + //echo $sql; + } + } + + if ($kategoriumum) { + foreach ($kategoriumum as $k => $v) { + $selected = $v['chex'] ? 'Y' : 'N'; + if (intval($v['xid'] == 0)) { + $sql = "UPDATE other_lcprepkategoriumum SET Other_LcprepKategoriUmumIsActive = 'N' + WHERE + Other_LcprepKategoriUmumOther_LcprepID = ? AND + Other_LcprepKategoriUmumLcprep_KategoriUmumID = ? AND + Other_LcprepKategoriUmumIsActive = 'Y' + "; + $query = $this->db_smartone->query($sql, array($header_id, $v['id'])); + if(!$query){ + echo $this->db_smartone->last_query(); + exit; + } + $sql = "INSERT INTO other_lcprepkategoriumum ( + Other_LcprepKategoriUmumOther_LcprepID, + Other_LcprepKategoriUmumLcprep_KategoriUmumID, + Other_LcprepKategoriUmumChex, + Other_LcprepKategoriUmumUserID, + Other_LcprepKategoriUmumCreated + ) + VALUES( + ?, + ?, + ?, + ?, + NOW() + )"; + $query = $this->db_smartone->query($sql, array($header_id, $v['id'], $selected, $userid)); + if(!$query){ + echo $this->db_smartone->last_query(); + exit; + } + } + if (intval($v['xid'] != 0)) { + $sql = "UPDATE other_lcprepkategoriumum SET + Other_LcprepKategoriUmumChex = ?, + Other_LcprepKategoriUmumUserID = ? + WHERE + Other_LcprepKategoriUmumID = ? + "; + $query = $this->db_smartone->query($sql, array($selected, $userid, $v['xid'])); + if(!$query){ + echo $this->db_smartone->last_query(); + exit; + } + } + + //echo $sql; + } + } + + if (count($results) > 0 && intval($selected_lang) == 1) { + foreach ($results as $k => $v) { + if (intval($v['xid'] == 0)) { + $sql = "UPDATE other_lcprepdetails SET Other_LcprepDetailsIsActive = 'N' + WHERE + Other_LcprepDetailsOther_LcprepID = ? AND + Other_LcprepDetailsCode = ? AND + Other_LcprepDetailsIsActive = 'Y'"; + $query = $this->db_smartone->query($sql, array($header_id, $v['code'])); + if(!$query){ + echo $this->db_smartone->last_query(); + exit; + } + $sql = "INSERT INTO other_lcprepdetails ( + Other_LcprepDetailsOther_LcprepID, + Other_LcprepDetailsCode, + Other_LcprepDetailsLabel, + Other_LcprepDetailsResult, + Other_LcprepDetailsUserID, + Other_LcprepDetailsCreated + ) + VALUES( + ?, + ?, + ?, + ?, + ?, + NOW() + )"; + $query = $this->db_smartone->query($sql, array($header_id, $v['code'], $v['label'], $v['result'], $userid)); + if(!$query){ + echo $this->db_smartone->last_query(); + exit; + } + } + if (intval($v['xid'] != 0)) { + $sql = "UPDATE other_lcprepdetails SET + Other_LcprepDetailsCode = ?, + Other_LcprepDetailsLabel = ?, + Other_LcprepDetailsResult = ?, + Other_LcprepDetailsUserID = ? + WHERE + Other_LcprepDetailsID = ? + "; + $query = $this->db_smartone->query($sql, array($v['code'], $v['label'], $v['result'], $userid, $v['xid'])); + if(!$query){ + echo $this->db_smartone->last_query(); + exit; + } + } + //echo $sql; + } + } + + if (count($other_results) > 0 && intval($selected_lang) == 2) { + foreach ($other_results as $k => $v) { + if (intval($v['xid'] == 0)) { + $sql = "UPDATE other_lcprepdetails_lang SET Other_LcprepDetailsLangsIsActive = 'N' + WHERE + Other_LcprepDetailsLangsOther_LcprepID = ? AND + Other_LcprepDetailsLangsCode = ? AND + Other_LcprepDetailsLangsIsActive = 'Y'"; + $query = $this->db_smartone->query($sql, array($header_id, $v['code'])); + if(!$query){ + echo $this->db_smartone->last_query(); + exit; + } + //echo $this->db_smartone->last_query(); + $sql = "INSERT INTO other_lcprepdetails_lang ( + Other_LcprepDetailsLangsOther_LcprepID, + Other_LcprepDetailsLangsCode, + Other_LcprepDetailsLangsLabel, + Other_LcprepDetailsLangsResult, + Other_LcprepDetailsLangsCreatedUserID, + Other_LcprepDetailsLangsCreated + ) + VALUES( + ?, + ?, + ?, + ?, + ?, + NOW() + )"; + $query = $this->db_smartone->query($sql, array($header_id, $v['code'], $v['label'], $v['result'], $userid)); + if(!$query){ + echo $this->db_smartone->last_query(); + exit; + } + //echo $this->db_smartone->last_query(); + } + if (intval($v['xid'] != 0)) { + $sql = "UPDATE other_lcprepdetails_lang SET + Other_LcprepDetailsLangsCode = ?, + Other_LcprepDetailsLangsLabel = ?, + Other_LcprepDetailsLangsResult = ?, + Other_LcprepDetailsLangsUpdatedUserID = ?, + Other_LcprepDetailsLangsUpdated = NOW() + WHERE + Other_LcprepDetailsLangsID = ? + "; + $query = $this->db_smartone->query($sql, array($v['code'], $v['label'], $v['result'], $userid, $v['xid'])); + if(!$query){ + echo $this->db_smartone->last_query(); + exit; + } + } + //echo $sql; + } + } + + if ($interpretasi) { + foreach ($interpretasi as $k => $v) { + if (count($v['subgroups']) > 0) { + foreach ($v['subgroups'] as $ik => $iv) { + if (count($iv['childs']) > 0) { + foreach ($iv['childs'] as $iik => $iiv) { + if (intval($iiv['xid'] == 0)) { + $chex = $iiv['chex'] ? 'Y' : 'N'; + $sql = "UPDATE other_lcprepinterpretasi SET Other_LcprepInterpretasiIsActive = 'N' + WHERE + Other_LcprepInterpretasiOther_LcprepID = ? AND + Other_LcprepInterpretasiLcprep_InterpretasiID = ? AND + Other_LcprepInterpretasiIsActive = 'Y'"; + $query = $this->db_smartone->query($sql, array($header_id, $iiv['id'])); + if(!$query){ + echo $this->db_smartone->last_query(); + exit; + } + $sql = "INSERT INTO other_lcprepinterpretasi ( + Other_LcprepInterpretasiOther_LcprepID, + Other_LcprepInterpretasiLcprep_InterpretasiID, + Other_LcprepInterpretasiChex, + Other_LcprepInterpretasiValue, + Other_LcprepInterpretasiValueEng, + Other_LcprepInterpretasiUserID, + Other_LcprepInterpretasiCreated + ) + VALUES( + ?, + ?, + ?, + ?, + ?, + ?, + NOW() + )"; + $query = $this->db_smartone->query($sql, array($header_id, $iiv['id'], $chex, $iiv['value'], $iiv['value_en'], $userid)); + if(!$query){ + echo $this->db_smartone->last_query(); + exit; + } + } + + if (intval($iiv['xid'] != 0)) { + $chex = $iiv['chex'] ? 'Y' : 'N'; + $sql = "UPDATE other_lcprepinterpretasi SET + Other_LcprepInterpretasiChex = ?, + Other_LcprepInterpretasiValue = ?, + Other_LcprepInterpretasiValueEng = ?, + Other_LcprepInterpretasiUserID = ? + WHERE + Other_LcprepInterpretasiID = ? + "; + $query = $this->db_smartone->query($sql, array($chex, $iiv['value'], $iiv['value_en'], $userid, $iiv['xid'])); + if(!$query){ + echo $this->db_smartone->last_query(); + exit; + } + //echo $sql; + + } + } + } + } + } + //echo $sql; + } + } + + + $result = array("total" => 1, "records" => array(), "sql" => ''); + $this->sys_ok($result); + exit; + } + + function saveresult_papsmear() + { + $prm = $this->sys_input; + $detail_id = $prm['detail_id']; + $doctor_id = $prm['doctor']; + $checks = $prm['checks']; + $maturasi = $prm['maturasi']; + $bahans = $prm['bahans']; + $categories = $prm['categories']; + $results = $prm['results']; + + $userid = $this->sys_user['M_UserID']; + + $header_id = 0; + $sql = "SELECT * FROM other_papsmear WHERE Other_PapSmearT_OrderDetailID = {$detail_id} AND Other_PapSmearIsActive = 'Y'"; + $dt_header = $this->db_smartone->query($sql)->row_array(); + if ($dt_header) { + $header_id = $dt_header['Other_PapSmearID']; + } + if ($header_id == 0) { + $sql = "INSERT INTO other_papsmear( + Other_PapSmearT_OrderDetailID, + Other_PapSmearM_DoctorID, + Other_PapSmearUserID, + Other_PapSmearCreated + ) + VALUES( + {$detail_id}, + {$doctor_id}, + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } else { + $sql = "UPDATE other_papsmear SET Other_PapSmearM_DoctorID = {$doctor_id}, Other_PapSmearUserID = {$userid} WHERE Other_PapSmearID = {$header_id}"; + $this->db_smartone->query($sql); + } + + if ($checks) { + foreach ($checks as $k => $v) { + if (intval($v['xid']) == 0 && $v['selected'] === 'Y') { + $sql = "INSERT INTO other_papsmearcheck ( + Other_PapSmearCheckOther_PapSmearID, + Other_PapSmearCheckM_PapSmearCheckID, + Other_PapSmearCheckNote, + Other_PapSmearCheckUserID, + Other_PapSmearCheckCreated + ) + VALUES( + {$header_id}, + {$v['check_id']}, + '{$v['note']}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if (intval($v['xid']) != 0 && $v['selected'] === 'N') { + $sql = "UPDATE other_papsmearcheck SET + Other_PapSmearCheckIsActive = 'N', + Other_PapSmearCheckUserID = {$userid} + WHERE + Other_PapSmearCheckID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + if (intval($v['xid']) != 0 && $v['selected'] === 'Y') { + $sql = "UPDATE other_papsmearcheck SET + Other_PapSmearCheckNote = '{$v['note']}', + Other_PapSmearCheckUserID = {$userid} + WHERE + Other_PapSmearCheckID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + //echo $sql; + } + } + + if ($maturasi) { + if (intval($maturasi['xid']) == 0) { + $value = join("/", $maturasi['value']); + $sql = "INSERT INTO other_papsmearmaturasi ( + Other_PapSmearMaturasiOther_PapSmearID, + Other_PapSmearMaturasiValue, + Other_PapSmearMaturasiUserID, + Other_PapSmearMaturasiCreated + ) + VALUE( + {$header_id}, + '{$value}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + //echo $sql; + } + if (intval($maturasi['xid']) != 0) { + $value = join("/", $maturasi['value']); + $sql = "UPDATE other_papsmearmaturasi SET + Other_PapSmearMaturasiValue = '{$value}', + Other_PapSmearMaturasiUserID = {$userid} + WHERE + Other_PapSmearMaturasiID = {$maturasi['xid']}"; + // echo $sql; + $this->db_smartone->query($sql); + } + } + + if ($bahans) { + foreach ($bahans as $k => $v) { + if (intval($v['xid']) == 0 && $v['selected'] === 'Y') { + $sql = "INSERT INTO other_papsmearbahan ( + Other_PapSmearBahanOther_PapSmearID, + Other_PapSmearBahanM_PapSmearBahanID, + Other_PapSmearBahanUserID, + Other_PapSmearBahanCreated + ) + VALUES( + {$header_id}, + {$v['bahan_id']}, + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if (intval($v['xid']) != 0 && $v['selected'] === 'N') { + $sql = "UPDATE other_papsmearbahan SET + Other_PapSmearBahanIsActive = 'N', + Other_PapsmearCategoryUserID = {$userid} + WHERE + Other_PapSmearBahanID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + if (intval($v['xid']) != 0 && $v['selected'] === 'Y') { + $sql = "UPDATE other_papsmearbahan SET + Other_PapSmearBahanIsActive = 'Y', + Other_PapsmearCategoryUserID = {$userid} + WHERE + Other_PapSmearBahanID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + //echo $sql; + } + } + + if ($categories) { + foreach ($categories as $k => $v) { + if (intval($v['xid']) == 0 && $v['selected'] === 'Y') { + $sql = "INSERT INTO other_papsmearcategory ( + Other_PapsmearCategoryOther_PapSmearID, + Other_PapsmearCategoryM_PapSmearCategoryID, + Other_PapsmearCategoryUserID, + Other_PapsmearCategoryCreated + ) + VALUES( + {$header_id}, + {$v['category_id']}, + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if (intval($v['xid']) != 0 && $v['selected'] === 'N') { + $sql = "UPDATE other_papsmearcategory SET + Other_PapsmearCategoryIsActive = 'N', + Other_PapsmearCategoryUserID = {$userid} + WHERE + Other_PapsmearCategoryID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + //echo $sql; + if (intval($v['xid']) != 0 && $v['selected'] === 'Y') { + $sql = "UPDATE other_papsmearcategory SET + Other_PapsmearCategoryIsActive = 'Y', + Other_PapsmearCategoryUserID = {$userid} + WHERE + Other_PapsmearCategoryID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + } + } + + if ($results) { + foreach ($results as $k => $v) { + if (intval($v['xid']) == 0) { + $sql = "INSERT INTO other_papsmeardetails ( + Other_PapSmearDetailsOther_PapSmearID, + Other_PapSmearDetailsCode, + Other_PapSmearDetailsLabel, + Other_PapSmearDetailsResult, + Other_PapSmearDetailsUserID, + Other_PapSmearDetailsCreated + ) + VALUES( + {$header_id}, + '{$v['code']}', + '{$v['label']}', + '{$v['result']}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if (intval($v['xid']) != 0) { + $sql = "UPDATE other_papsmeardetails SET + Other_PapSmearDetailsCode = '{$v['code']}', + Other_PapSmearDetailsLabel = '{$v['label']}', + Other_PapSmearDetailsResult = '{$v['result']}', + Other_PapSmearDetailsUserID = {$userid} + WHERE + Other_PapSmearDetailsID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + //echo $sql; + } + } + + $result = array("total" => 1, "records" => array(), "sql" => ''); + $this->sys_ok($result); + exit; + } + + function saveresult_fna() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = $inp['doctor']; + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + if ($prm[0]['xid'] == '0') { + $sql = "INSERT INTO other_fna( + Other_FNAM_DoctorID, + Other_FNAT_OrderDetailID, + Other_FNAUserID, + Other_FNACreated + ) + VALUES( + {$doctor_id}, + {$prm[0]['orderdetail_id']}, + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } else { + $sql = "SELECT * FROM other_fna WHERE Other_FNAT_OrderDetailID = {$prm[0]['orderdetail_id']} AND Other_FNAIsActive = 'Y'"; + $data_header = $this->db_smartone->query($sql)->row_array(); + $header_id = $data_header['Other_FNAID']; + $sql = "UPDATE other_fna SET + Other_FNAM_DoctorID = {$doctor_id}, + Other_FNAUserID = {$userid} + WHERE + Other_FNAID = {$header_id}"; + $this->db_smartone->query($sql); + } + foreach ($prm as $k => $v) { + if ($v['xid'] == '0') { + $results = str_replace("'", "\\'", $v['result']); + $sql = "INSERT INTO other_fnadetails( + Other_FNADetailsOther_FNAID , + Other_FNADetailsCode, + Other_FNADetailsLabel, + Other_FNADetailsResult, + Other_FNADetailsCreated, + Other_FNADetailsUserID + ) + VALUES( + {$header_id}, + '{$v['code']}', + '{$v['label']}', + '{$results}', + NOW(), + {$userid} + )"; + $query = $this->db_smartone->query($sql); + } else { + $results = str_replace("'", "\\'", $v['result']); + $sql = "UPDATE other_fnadetails SET + Other_FNADetailsResult = '{$results}', + Other_FNADetailsUserID = {$userid} + WHERE + Other_FNADetailsID = {$v['xid']}"; + $query = $this->db_smartone->query($sql); + } + } + + $result = array("total" => 1, "records" => array(), "sql" => ''); + $this->sys_ok($result); + exit; + } + + function saveresult_patologianatomy() + { + + $inp = $this->sys_input; + $doctor_id = $inp['doctor']; + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + if ($inp['xid'] == '0') { + $sql = "INSERT INTO other_patologi_anatomy( + Other_PatologiAnatomyT_OrderDetailID, + Other_PatologiAnatomyM_DoctorID, + Other_PatologiAnatomyNoSediaan, + Other_PatologiAnatomyDiagnosaKlinis, + Other_PatologiAnatomyKeteranganKlinis, + Other_PatologiAnatomyLokasiOrgan, + Other_PatologiAnatomyMakroskopik, + Other_PatologiAnatomyMikroskopik, + Other_PatologiAnatomyKesimpulan, + Other_PatologiAnatomyUserID, + Other_PatologiAnatomyCreated + ) + VALUES( + {$inp['detail_id']}, + {$doctor_id}, + '{$inp['no_sediaan']}', + '{$inp['diagnosa']}', + '{$inp['klinis']}', + '{$inp['lokasi']}', + '{$inp['makroskopik']}', + '{$inp['mikroskopik']}', + '{$inp['kesimpulan']}', + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } else { + $sql = "UPDATE other_patologi_anatomy SET + Other_PatologiAnatomyM_DoctorID = ?, + Other_PatologiAnatomyNoSediaan = ?, + Other_PatologiAnatomyKeteranganKlinis = ?, + Other_PatologiAnatomyDiagnosaKlinis = ?, + Other_PatologiAnatomyLokasiOrgan = ?, + Other_PatologiAnatomyMakroskopik = ?, + Other_PatologiAnatomyMikroskopik = ?, + Other_PatologiAnatomyKesimpulan = ?, + Other_PatologiAnatomyUserID = ? + WHERE + Other_PatologiAnatomyT_OrderDetailID = ? AND Other_PatologiAnatomyIsActive = 'Y'"; + $this->db_smartone->query($sql, array( + $doctor_id, + $inp['no_sediaan'], + $inp['klinis'], + $inp['diagnosa'], + $inp['lokasi'], + $inp['makroskopik'], + $inp['mikroskopik'], + $inp['kesimpulan'], + $userid, + $inp['detail_id'] + )); + //echo $this->db_smartone->last_query(); + + } + + $inp_rst = array( + 'doctor_id' => $doctor_id, + 'no_sediaan' => $inp['no_sediaan'], + 'klinis' => $inp['klinis'], + 'diagnosa' => $inp['diagnosa'], + 'lokasi' => $inp['lokasi'], + 'makroskopik' => $inp['makroskopik'], + 'mikroskopik' => $inp['mikroskopik'], + 'kesimpulan' => $inp['kesimpulan'] + ); + $log_json = json_encode($inp_rst); + + $sql = "INSERT INTO log_other_patologianatomy ( + Log_OtherPatologiAnatomyT_OrderDetailID, + Log_OtherPatologiAnatomyDateTime, + Log_OtherPatologiAnatomySON, + Log_OtherPatologiAnatomyUserID + )VALUE( + {$inp['detail_id']}, + NOW(), + '{$log_json}', + {$userid} + )"; + $this->db_smartone->query($sql); + //echo $this->db_smartone->last_query(); + + $result = array("total" => 1, "records" => array(), "sql" => ''); + $this->sys_ok($result); + exit; + } + + function saveresult_cytologi() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = $inp['doctor']; + + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + if ($prm[0]['xid'] == '0') { + $sql = "INSERT INTO other_cytologi( + Other_CytologiT_OrderDetailID, + Other_CytologiM_DoctorID, + Other_CytologiUserID, + Other_CytologiCreated + ) + VALUES( + {$prm[0]['orderdetail_id']}, + {$doctor_id}, + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } else { + $sql = "SELECT * FROM other_cytologi WHERE Other_CytologiT_OrderDetailID = {$prm[0]['orderdetail_id']} AND Other_CytologiIsActive = 'Y'"; + $data_header = $this->db_smartone->query($sql)->row_array(); + $header_id = $data_header['Other_CytologiID']; + $sql = "UPDATE other_cytologi SET + Other_CytologiM_DoctorID = {$doctor_id}, + Other_CytologiUserID = {$userid} + WHERE + Other_CytologiID = {$header_id}"; + $this->db_smartone->query($sql); + } + foreach ($prm as $k => $v) { + if ($v['xid'] == '0') { + $results = str_replace("'", "\\'", $v['result']); + $sql = "INSERT INTO other_cytologidetails( + Other_CytologiDetailsOther_CytologiID , + Other_CytologiDetailsCode, + Other_CytologiDetailsLabel, + Other_CytologiDetailsResult, + Other_CytologiDetailsCreated, + Other_CytologiDetailsUserID + ) + VALUES( + {$header_id}, + '{$v['code']}', + '{$v['label']}', + '{$results}', + NOW(), + {$userid} + )"; + $query = $this->db_smartone->query($sql); + } else { + $results = str_replace("'", "\\'", $v['result']); + $sql = "UPDATE other_cytologidetails SET + Other_CytologiDetailsResult = '{$results}', + Other_CytologiDetailsUserID = {$userid} + WHERE + Other_CytologiDetailsID = {$v['xid']}"; + $query = $this->db_smartone->query($sql); + } + } + + $result = array("total" => 1, "records" => array(), "sql" => ''); + $this->sys_ok($result); + exit; + } + + function saveresult_mikro() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = $inp['doctor']; + $backteria_id = $inp['bacteria']; + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + + if ($inp['result_value'] != 'Negatif' && $inp['result_value'] != 'Positif') { + $prm['result_value'] = $prm['result_other']; + } else { + $prm['result_value'] = $inp['result_value']; + } + + if ($prm['xid'] == '0') { + $sql = "INSERT INTO other_mikro( + Other_MikroM_DoctorID, + Other_MikroResult, + Other_MikroT_BacteriaID, + Other_MikroT_OrderDetailID, + Other_MikroHasilBiakan, + Other_MikroSampleTypeName, + Other_MikroUserID, + Other_MikroCreated + ) + VALUES( + {$doctor_id}, + '{$prm['result_value']}', + {$backteria_id}, + {$prm['orderdetail_id']}, + '{$prm['hasil_biakan']}', + '{$prm['sample_name']}', + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } else { + $sql = "SELECT * FROM other_mikro WHERE Other_MikroT_OrderDetailID = {$prm['orderdetail_id']} AND Other_MikroIsActive = 'Y'"; + $data_header = $this->db_smartone->query($sql)->row_array(); + $header_id = $data_header['Other_MikroID']; + $sql = "UPDATE other_mikro SET + Other_MikroResult = '{$prm['result_value']}', + Other_MikroM_DoctorID = {$doctor_id}, + Other_MikroT_BacteriaID = {$backteria_id}, + Other_MikroHasilBiakan = '{$prm['hasil_biakan']}', + Other_MikroSampleTypeName = '{$prm['sample_name']}', + Other_MikroUserID = {$userid} + WHERE + Other_MikroID = {$header_id}"; + //echo $sql; + $this->db_smartone->query($sql); + } + + + + $sql = "UPDATE other_mikrodetails SET Other_MikroDetailsIsActive = 'N', Other_MikroDetailsUserID = 0 WHERE Other_MikroDetailsOther_MikroID = {$header_id}"; + $this->db_smartone->query($sql); + + $results = $prm['details']; + if ($inp['result_value'] == 'Positif') { + foreach ($results as $k => $v) { + if ($v['xid'] == '0') { + $sql = "INSERT INTO other_mikrodetails( + Other_MikroDetailsOther_MikroID , + Other_MikroDetailsT_AntibioticID, + Other_MikroDetailsValue, + Other_MikroDetailsNote, + Other_MikroDetailsCreated, + Other_MikroDetailsUserID + ) + VALUES( + {$header_id}, + '{$v['T_AntibioticID']}', + '{$v['value']}', + '{$v['note']}', + NOW(), + {$userid} + )"; + $query = $this->db_smartone->query($sql); + } else { + $sql = "UPDATE other_mikrodetails SET + Other_MikroDetailsT_AntibioticID = '{$v['T_AntibioticID']}', + Other_MikroDetailsValue = '{$v['value']}', + Other_MikroDetailsNote = '{$v['note']}', + Other_MikroDetailsIsActive = 'Y', + Other_MikroDetailsUserID = {$userid} + WHERE + Other_MikroDetailsID = {$v['xid']}"; + //echo $sql; + $query = $this->db_smartone->query($sql); + } + } + } + + + $result = array("total" => 1, "records" => array(), "sql" => ''); + $this->sys_ok($result); + exit; + } + + + function get_doctors_preparasi_sperma() + { + $prm = $this->sys_input; + // $id = $prm["id"]; + + $sql = " SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 10 AND + M_DoctorSOIsActive = 'Y' + ORDER BY M_DoctorName ASC"; + //echo $sql; + $query = $this->db_smartone->query($sql); + $rows = $query->result_array(); + $sql = " + SELECT '0' as id, 'Belum memilih metode' as name + UNION + SELECT M_MethodeSpermaID as id, M_MethodeSpermaName as name + FROM m_methodesperma + WHERE + M_MethodeSpermaIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $methodes = $this->db_smartone->query($sql)->result_array(); + + + $this->sys_ok(["records" => $rows, "methodes" => $methodes]); + } + + + function getpreparasispermaresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT other_preparasisperma.*, + Other_PreparasiSpermaID as xid, + Other_PreparasiSpermaT_OrderDetailID as orderdetail_id, + IFNULL(Other_PreparasiSpermaM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_PreparasiSpermaM_DoctorID) OR Other_PreparasiSpermaM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name, + IFNULL(M_MethodeSpermaID,0) as methode_id, + IFNULL(M_MethodeSpermaName,'') as methode_name + FROM other_preparasisperma + LEFT JOIN m_doctor ON Other_PreparasiSpermaM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + LEFT JOIN m_methodesperma ON Other_PreparasiSpermaM_MethodeSpermaID = M_MethodeSpermaID AND + M_MethodeSpermaIsActive = 'Y' + WHERE + Other_PreparasiSpermaT_OrderDetailID = {$id} AND Other_PreparasiSpermaIsActive = 'Y' + GROUP BY Other_PreparasiSpermaID"; + $query = $this->db_smartone->query($sql); + + if ($query) { + $rows = $query->row_array(); + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 10 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $sql = " + SELECT '0' as id, 'Belum memilih metode' as name + UNION + SELECT M_MethodeSpermaID as id, M_MethodeSpermaName as name + FROM m_methodesperma + WHERE + M_MethodeSpermaIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $methodes = $this->db_smartone->query($sql)->result_array(); + $images = array(); + $sql = "SELECT Other_PreparasiSpermaImgID as xid, + Other_PreparasiSpermaImgType as type, + CONCAT('/one-media/one-image-nonlab/',Other_PreparasiSpermaImgNewName) as image_url + FROM t_orderdetail + JOIN other_preparasisperma_img ON Other_PreparasiSpermaImgT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND + Other_PreparasiSpermaImgIsActive = 'Y' + WHERE + T_OrderDetailID = {$id} AND + T_OrderDetailIsActive = 'Y' + GROUP BY Other_PreparasiSpermaImgID"; + //echo $sql; + $images = $this->db_smartone->query($sql)->result_array(); + + $rst = array('doctors' => $doctors, 'methodes' => $methodes, 'results' => $rows, 'images' => $images); + $this->sys_ok(["records" => $rst]); + } else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + + function uploadimage_preparasi_sperma() + { + if (! $this->isLogin) { + $this->sys_error("Invalid Token"); + exit; + } + + $userid = $this->sys_user["M_UserID"]; + $data = []; + //print_r($_SERVER); + + $prm = $this->sys_input; + $orderid = $this->input->post('orderid'); + $type = $this->input->post('type'); + $labnumber = $this->input->post('labnumber'); + $sql = "UPDATE other_preparasisperma_img SET + Other_PreparasiSpermaImgIsActive = 'N', + Other_PreparasiSpermaImgUserID = {$userid} + WHERE + Other_PreparasiSpermaImgT_OrderHeaderID = {$orderid} AND + Other_PreparasiSpermaImgType = '{$type}'"; + //echo $sql; + $this->db_onedev->query($sql); + //$config['upload_path'] = 'assets/'; + + $path = '/home/one/project/one/one-media/one-image-nonlab/'; + //echo $path; + $config['upload_path'] = $path; + $config['allowed_types'] = 'jpg|jpeg|png|gif'; + + $config['max_size'] = '10000'; + $count = count($_FILES['files']['name']); + //echo $count; + $this->load->library('upload', $config); + + $error = []; + for ($i = 0; $i < $count; $i++) { + + + if (!empty($_FILES['files']['name'][$i])) { + + + + $_FILES['file']['name'] = $_FILES['files']['name'][$i]; + + $_FILES['file']['type'] = $_FILES['files']['type'][$i]; + + $_FILES['file']['tmp_name'] = $_FILES['files']['tmp_name'][$i]; + + $_FILES['file']['error'] = $_FILES['files']['error'][$i]; + + $_FILES['file']['size'] = $_FILES['files']['size'][$i]; + + + + $namex = $orderid . '-' . $labnumber . '-' . $this->generateRandomString(5); + //echo $namex; + + $config['file_name'] = $namex; + $this->upload->initialize($config); + //echo $config['file_name'] ; + + + + + + if ($this->upload->do_upload('file')) { + + $uploadData = $this->upload->data(); + + $filename = $uploadData['file_name']; + //echo $filename; + + + $sql = "INSERT INTO other_preparasisperma_img ( + Other_PreparasiSpermaImgT_OrderHeaderID, + Other_PreparasiSpermaImgType, + Other_PreparasiSpermaImgOldName, + Other_PreparasiSpermaImgNewName, + Other_PreparasiSpermaImgCreated, + Other_PreparasiSpermaImgUserID + ) + VALUES( + {$orderid}, + '{$type}', + '{$_FILES['files']['name'][$i]}', + '{$filename}', + NOW(), + {$userid} + + )"; + //echo $sql; + $this->db_onedev->query($sql); + $xlast_id = $this->db_onedev->insert_id(); + $data['totalFiles'][] = array('xid' => $xlast_id, 'type' => $type, 'image_url' => '/one-media/one-image-nonlab/' . $filename); + } else { + $error = array('error' => $this->upload->display_errors()); + } + } + } + + $result = array("total" => count($data['totalFiles']), "records" => $data['totalFiles'], 'errors' => $error); + $this->sys_ok($result); + } + + + function saveresult_preparasi_sperma() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = isset($inp['doctor']) ? $inp['doctor'] : 0; + $methode_id = isset($inp['methode']) ? $inp['methode'] : 0; + $orderdetail_id = $inp['orderdetailid']; + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + if ($prm['xid'] == '0') { + $sql = "INSERT INTO other_preparasisperma( + Other_PreparasiSpermaM_DoctorID, + Other_PreparasiSpermaT_OrderDetailID, + Other_PreparasiSpermaPreMotilitasA, + Other_PreparasiSpermaPreMotilitasB, + Other_PreparasiSpermaPreMotilitasC, + Other_PreparasiSpermaPreKonsentrasi, + Other_PreparasiSpermaPreKontaminan, + Other_PreparasiSpermaPostMotilitasA, + Other_PreparasiSpermaPostMotilitasB, + Other_PreparasiSpermaPostMotilitasC, + Other_PreparasiSpermaPostKonsentrasi, + Other_PreparasiSpermaPostKontaminan, + Other_PreparasiSpermaPreVolume, + Other_PreparasiSpermaPostVolume, + Other_PreparasiSpermaM_MethodeSpermaID, + Other_PreparasiSpermaNote, + Other_PreparasiSpermaUserID, + Other_PreparasiSpermaCreated + ) + VALUES( + {$doctor_id}, + {$orderdetail_id}, + '{$prm['Other_PreparasiSpermaPreMotilitasA']}', + '{$prm['Other_PreparasiSpermaPreMotilitasB']}', + '{$prm['Other_PreparasiSpermaPreMotilitasC']}', + '{$prm['Other_PreparasiSpermaPreKonsentrasi']}', + '{$prm['Other_PreparasiSpermaPreKontaminan']}', + '{$prm['Other_PreparasiSpermaPostMotilitasA']}', + '{$prm['Other_PreparasiSpermaPostMotilitasB']}', + '{$prm['Other_PreparasiSpermaPostMotilitasC']}', + '{$prm['Other_PreparasiSpermaPostKonsentrasi']}', + '{$prm['Other_PreparasiSpermaPostKontaminan']}', + '{$prm['Other_PreparasiSpermaPreVolume']}', + '{$prm['Other_PreparasiSpermaPostVolume']}', + '{$methode_id}', + '{$prm['Other_PreparasiSpermaNote']}', + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } else { + $sql = "SELECT * FROM other_preparasisperma WHERE Other_PreparasiSpermaT_OrderDetailID = {$orderdetail_id} AND Other_PreparasiSpermaIsActive = 'Y'"; + $data_header = $this->db_smartone->query($sql)->row_array(); + $header_id = $data_header['Other_PreparasiSpermaID']; + $sql = "UPDATE other_preparasisperma SET + Other_PreparasiSpermaM_DoctorID = {$doctor_id}, + Other_PreparasiSpermaPreMotilitasA = '{$prm['Other_PreparasiSpermaPreMotilitasA']}', + Other_PreparasiSpermaPreMotilitasB = '{$prm['Other_PreparasiSpermaPreMotilitasB']}', + Other_PreparasiSpermaPreMotilitasC = '{$prm['Other_PreparasiSpermaPreMotilitasC']}', + Other_PreparasiSpermaPreKonsentrasi = '{$prm['Other_PreparasiSpermaPreKonsentrasi']}', + Other_PreparasiSpermaPreKontaminan = '{$prm['Other_PreparasiSpermaPreKontaminan']}', + Other_PreparasiSpermaPostMotilitasA = '{$prm['Other_PreparasiSpermaPostMotilitasA']}', + Other_PreparasiSpermaPostMotilitasB = '{$prm['Other_PreparasiSpermaPostMotilitasB']}', + Other_PreparasiSpermaPostMotilitasC = '{$prm['Other_PreparasiSpermaPostMotilitasC']}', + Other_PreparasiSpermaPostKonsentrasi = '{$prm['Other_PreparasiSpermaPostKonsentrasi']}', + Other_PreparasiSpermaPostKontaminan = '{$prm['Other_PreparasiSpermaPostKontaminan']}', + Other_PreparasiSpermaPreVolume = '{$prm['Other_PreparasiSpermaPreVolume']}', + Other_PreparasiSpermaPostVolume = '{$prm['Other_PreparasiSpermaPostVolume']}', + Other_PreparasiSpermaM_MethodeSpermaID = '{$methode_id}', + Other_PreparasiSpermaNote = '{$prm['Other_PreparasiSpermaNote']}', + Other_PreparasiSpermaUserID = {$userid} + WHERE + Other_PreparasiSpermaID = {$header_id}"; + $this->db_smartone->query($sql); + } + + + $result = array("total" => 1, "records" => array(), "sql" => ''); + $this->sys_ok($result); + exit; + } + + function getdnafragmentasiresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT other_dnafragmentasi.*, + Other_DnaFragmentasiID as xid, + Other_DnaFragmentasiT_OrderDetailID as orderdetail_id, + IFNULL(Other_DnaFragmentasiM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_DnaFragmentasiM_DoctorID) OR Other_DnaFragmentasiM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name, + IFNULL(Other_DnaFragmentasiOther_DnaFragmentasiMethodeID,0) as methode_id, + IFNULL(Other_DnaFragmentasiMethodeName,'') as methode_name, + Other_DnaFragmentasiHaloLuas as halo_luas, + Other_DnaFragmentasiHaloSedang as halo_sedang, + Other_DnaFragmentasiHaloSempit as halo_sempit, + Other_DnaFragmentasiTanpaHalo as tanpa_halo, + Other_DnaFragmentasiDFI as dfi, + Other_DnaFragmentasiKesimpulan as kesimpulan, + Other_DnaFragmentasiCatatan as catatan + FROM other_dnafragmentasi + LEFT JOIN m_doctor ON Other_DnaFragmentasiM_DoctorID = M_DoctorID + LEFT JOIN other_dnafragmentasimethode ON Other_DnaFragmentasiOther_DnaFragmentasiMethodeID = Other_DnaFragmentasiMethodeID + WHERE + Other_DnaFragmentasiT_OrderDetailID = {$id} AND Other_DnaFragmentasiIsActive = 'Y' + GROUP BY Other_DnaFragmentasiID + LIMIT 1"; + //echo $sql; + $query = $this->db_smartone->query($sql); + + if ($query) { + $rows = $query->row_array(); + if (!$rows) { + $rows = array( + 'xid' => 0, + 'orderdetail_id' => $id, + 'doctor_id' => 0, + 'doctor_name' => '', + 'methode_id' => 0, + 'methode_name' => '', + 'halo_luas' => '', + 'halo_sedang' => '', + 'tanpa_halo' => '', + 'dfi' => '', + 'kesimpulan' => '', + 'catatan' => '' + ); + } + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID + WHERE + M_DoctorSONat_SubGroupID = 4 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + + $sql = " + SELECT '0' as id, 'Belum memilih metode' as name + UNION + SELECT Other_DnaFragmentasiMethodeID as id, Other_DnaFragmentasiMethodeName as name + FROM other_dnafragmentasimethode + WHERE + Other_DnaFragmentasiMethodeIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $methodes = $this->db_smartone->query($sql)->result_array(); + + + $rst = array('doctors' => $doctors, 'methodes' => $methodes, 'results' => $rows); + $this->sys_ok(["records" => $rst]); + } else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + function saveresult_dnafragmentasi() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = $inp['doctor']['id']; + $methode_id = $inp['methode']['id']; + $orderdetail_id = $inp['results']['orderdetail_id']; + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + if (intval($prm['xid']) == 0) { + $sql = "INSERT INTO other_dnafragmentasi( + Other_DnaFragmentasiT_OrderDetailID, + Other_DnaFragmentasiM_DoctorID, + Other_DnaFragmentasiOther_DnaFragmentasiMethodeID, + Other_DnaFragmentasiHaloLuas, + Other_DnaFragmentasiHaloSedang, + Other_DnaFragmentasiHaloSempit, + Other_DnaFragmentasiTanpaHalo, + Other_DnaFragmentasiDFI, + Other_DnaFragmentasiKesimpulan, + Other_DnaFragmentasiCatatan, + Other_DnaFragmentasiUserID, + Other_DnaFragmentasiLastUpdated + ) + VALUES( + {$orderdetail_id}, + {$doctor_id}, + {$methode_id}, + '{$prm['halo_luas']}', + '{$prm['halo_sedang']}', + '{$prm['halo_sempit']}', + '{$prm['tanpa_halo']}', + '{$prm['dfi']}', + '{$prm['kesimpulan']}', + '{$prm['catatan']}', + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } else { + $sql = "UPDATE other_dnafragmentasi SET + Other_DnaFragmentasiT_OrderDetailID = {$orderdetail_id}, + Other_DnaFragmentasiM_DoctorID = {$doctor_id}, + Other_DnaFragmentasiOther_DnaFragmentasiMethodeID = '{$methode_id}', + Other_DnaFragmentasiHaloLuas = '{$prm['halo_luas']}', + Other_DnaFragmentasiHaloSedang = '{$prm['halo_sedang']}', + Other_DnaFragmentasiHaloSempit = '{$prm['halo_sempit']}', + Other_DnaFragmentasiTanpaHalo = '{$prm['tanpa_halo']}', + Other_DnaFragmentasiDFI = '{$prm['dfi']}', + Other_DnaFragmentasiKesimpulan = '{$prm['kesimpulan']}', + Other_DnaFragmentasiCatatan = '{$prm['catatan']}', + Other_DnaFragmentasiLastUpdated = NOW(), + Other_DnaFragmentasiUserID = {$userid} + WHERE + Other_DnaFragmentasiID = {$prm['xid']}"; + //echo $sql; + $this->db_smartone->query($sql); + } + + + $result = array("total" => 1, "records" => array(), "sql" => ''); + $this->sys_ok($result); + exit; + } +} diff --git a/application/controllers/mockup/process/resultentry-westone/9/Re_px.php b/application/controllers/mockup/process/resultentry-westone/9/Re_px.php index 08699539..885cc9a6 100644 --- a/application/controllers/mockup/process/resultentry-westone/9/Re_px.php +++ b/application/controllers/mockup/process/resultentry-westone/9/Re_px.php @@ -69,13 +69,8 @@ class Re_px extends MY_Controller return array(0,""); } function get_normal_value($methodeID, $natTestID, $sexID, $ageInDay ) { - $sql = "select fn_sampling_get_normal($methodeID, $natTestID, $sexID, $ageInDay) as normalValueID"; - $qry = $this->db->query($sql); - if ($qry) { - $rows = $qry->result_array(); - if (count($rows) > 0 ) return $rows[0]["normalValueID"]; - } - return 0; + $this->load->library('ibl_sampling_normal'); + return $this->ibl_sampling_normal->get_normal_value_id($methodeID, $natTestID, $sexID, $ageInDay); } function fn_fix_normal($order_id) { $sql = "select diff --git a/application/controllers/mockup/process/resultentry-westone/Re_px.php b/application/controllers/mockup/process/resultentry-westone/Re_px.php index ae3abcaf..cf16ddfb 100644 --- a/application/controllers/mockup/process/resultentry-westone/Re_px.php +++ b/application/controllers/mockup/process/resultentry-westone/Re_px.php @@ -1,2986 +1,2983 @@ -db_smartone = $this->load->database("onedev", true); - $this->db_lab = $this->load->database('one_lab_log', TRUE); - $this->load->helper(array('form', 'url')); - } - function getMethodeID($natTestID) - { - $sql = "select M_MethodePriorityNat_MethodeID MethodeID, Nat_MethodeName - from - m_methode_priority - join nat_methode on Nat_MethodeID = M_MethodePriorityNat_MethodeID - and Nat_MethodeIsActive = 'Y' - join m_instrumentmethode on M_InstrumentMethodeNat_MethodeID = Nat_MethodeID and M_InstrumentMethodeIsActive = 'Y' - join nat_instrument on M_InstrumentMethodeNat_InstrumentID = Nat_InstrumentID - and Nat_InstrumentIsActive ='Y' - where M_MethodePriorityIsActive = 'Y' - and M_MethodePriorityNat_TestID = $natTestID - and M_MethodePriorityM_DayOfWeekID = dayofweek(now()) - order by M_MethodePriorityNumber desc - limit 0,1 "; - $qry = $this->db->query($sql); - if ($qry) { - $rows = $qry->result_array(); - if (count($rows) > 0) return array($rows[0]["MethodeID"], $rows[0]["Nat_MethodeName"]); - } - //2nd - $sql = "select - M_InstrumentMethodeNat_MethodeID MethodeID, Nat_MethodeName - from m_instrumentmethode - join nat_methode on M_InstrumentMethodeNat_MethodeID = Nat_MethodeID - and Nat_MethodeIsActive = 'Y' - join nat_instrument on M_InstrumentMethodeNat_InstrumentID = Nat_InstrumentID - and Nat_InstrumentIsActive ='Y' - where M_InstrumentMethodeNat_TestID = $natTestID - and M_InstrumentMethodeIsActive = 'Y' - order by M_InstrumentMethodePriority desc - limit 0,1"; - $qry = $this->db->query($sql); - if ($qry) { - $rows = $qry->result_array(); - if (count($rows) > 0) return array($rows[0]["MethodeID"], $rows[0]["Nat_MethodeName"]); - } - // - $sql = "select Nat_NormalValueNat_MethodeID MethodeID, Nat_MethodeName - from - nat_normalvalue - join nat_methode on Nat_NormalValueNat_MethodeID = Nat_MethodeID - and Nat_MethodeIsActive = 'Y' - where Nat_NormalValueNat_TestID = $natTestID - and Nat_NormalValueIsActive = 'Y' - order by Nat_NormalValueID - limit 0,1"; - $qry = $this->db->query($sql); - if ($qry) { - $rows = $qry->result_array(); - if (count($rows) > 0) return array($rows[0]["MethodeID"], $rows[0]["Nat_MethodeName"]); - } - return array(0, ""); - } - function get_normal_value($methodeID, $natTestID, $sexID, $ageInDay) - { - $sql = "select fn_sampling_get_normal($methodeID, $natTestID, $sexID, $ageInDay) as normalValueID"; - $qry = $this->db->query($sql); - if ($qry) { - $rows = $qry->result_array(); - if (count($rows) > 0) return $rows[0]["normalValueID"]; - } - return 0; - } - function fn_fix_normal($order_id) - { - $sql = "select - T_OrderDetailID, M_PatientM_SexID, fn_global_age_count_day(M_PatientDOB, date(T_OrderHeaderDate)) Dob , - T_TestNat_TestID - from t_orderheader - join m_patient on T_OrderHeaderID = $order_id and T_OrderHeaderM_PatientID = M_PatientID - join t_orderdetail on T_OrderDetailT_OrderHeaderID = T_OrderHeaderID - and T_OrderDetailIsACtive = 'Y' - and ( T_OrderDetailNat_NormalValueID is null or T_OrderDetailNat_NormalValueID = 0 ) - join t_test on T_OrderDetailT_TestID = T_TestID and T_TestIsResult = 'Y' "; - $qry = $this->db->query($sql); - if (! $qry) { - return; - } - $rows = $qry->result_array(); - if (count($rows) == 0) return; - $sql_u = "update t_orderdetail - join nat_normalvalue on T_OrderDetailID = ? and Nat_NormalValueID = ? - set - T_OrderDetailNat_NormalValueID = Nat_NormalValueID, - T_OrderDetailNormalValueNote = Nat_NormalValueNote, - T_OrderDetailNormalValueDescription = Nat_NormalValueDescription, - T_OrderDetailMinValue = Nat_NormalValueMinValue, - T_OrderDetailMaxValue = Nat_NormalValueMaxValue, - T_OrderDetailMinValueInclusive = Nat_NormalValueMinValueInclusive, - T_OrderDetailMaxValueInclusive = Nat_NormalValueMaxValueInclusive, - T_OrderDetailNat_MethodeID = ?, - T_OrderdetailNat_MethodeName =?"; - - foreach ($rows as $r) { - $T_OrderDetailID = $r["T_OrderDetailID"]; - $sexID = $r["M_PatientM_SexID"]; - $ageInDay = $r["Dob"]; - $natTestID = $r["T_TestNat_TestID"]; - list($methodeID, $methodeName) = $this->getMethodeID($natTestID); - if ($methodeID == 0) continue; - $normalValueID = $this->get_normal_value($methodeID, $natTestID, $sexID, $ageInDay); - if ($normalValueID == 0) return; - $this->db->query($sql_u, array($T_OrderDetailID, $normalValueID, $methodeID, $methodeName)); - } - } - function update_order_sample($targetID, $sourceID) - { - $sql = "update t_ordersample target - join t_ordersample source on - target.T_OrderSampleID = ? - and target.T_OrderSampleWorklistReceive = 'N' - and source.T_OrderSampleID = ? - set - target.T_OrderSampleSampling = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSampling, source.T_OrderSampleSampling), - target.T_OrderSampleSamplingDate = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingDate, source.T_OrderSampleSamplingDate), - target.T_OrderSampleSamplingTime = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingTime, source.T_OrderSampleSamplingTime), - target.T_OrderSampleSamplingUserID = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingUserID, source.T_OrderSampleSamplingUserID), - - target.T_OrderSampleReceive = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceive, source.T_OrderSampleReceive), - target.T_OrderSampleReceiveDate = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveDate, source.T_OrderSampleReceiveDate), - target.T_OrderSampleReceiveTime = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveTime, source.T_OrderSampleReceiveTime), - target.T_OrderSampleReceiveUserID = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveUserID, source.T_OrderSampleReceiveUserID), - - target.T_OrderSampleVerification = if(target.T_OrderSampleVerification='Y',target.T_OrderSampleVerification, source.T_OrderSampleVerification), - target.T_OrderSampleVerificationDate =if(target.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationDate, source.T_OrderSampleVerificationDate), - target.T_OrderSampleVerificationTime =if(source.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationTime, source.T_OrderSampleVerificationTime), - target.T_OrderSampleVerificationUserID =if(source.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationUserID, source.T_OrderSampleVerificationUserID), - - target.T_OrderSampleProcessing = if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessing, source.T_OrderSampleProcessing), - target.T_OrderSampleProcessingDate= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingDate, source.T_OrderSampleProcessingDate), - target.T_OrderSampleProcessingTime= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingTime, source.T_OrderSampleProcessingTime), - target.T_OrderSampleProcessingUserID= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingUserID, source.T_OrderSampleProcessingUserID), - - target.T_OrderSampleReceiveHandling =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandling, source.T_OrderSampleReceiveHandling ), - target.T_OrderSampleReceiveHandlingDate =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingDate, source.T_OrderSampleReceiveHandlingDate), - target.T_OrderSampleReceiveHandlingTime =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingTime, source.T_OrderSampleReceiveHandlingTime), - target.T_OrderSampleReceiveHandlingUserID =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingUserID, source.T_OrderSampleReceiveHandlingUserID), - - target.T_OrderSampleHandling = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandling, source.T_OrderSampleHandling), - target.T_OrderSampleHandlingDate = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingDate, source.T_OrderSampleHandlingDate), - target.T_OrderSampleHandlingTime = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingTime, source.T_OrderSampleHandlingTime), - target.T_OrderSampleHandlingUserID = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingUserID, source.T_OrderSampleHandlingUserID), - - target.T_OrderSampleWorklistReceive = source.T_OrderSampleWorklistReceive, - target.T_OrderSampleWorklistReceiveDatetime = source.T_OrderSampleWorklistReceiveDateTime, - target.T_OrderSampleWorklistReceiveUserID = source.T_OrderSampleWorklistReceiveUserID - "; - $qry = $this->db->query($sql, array($targetID, $sourceID)); - if (! $qry) { - echo json_encode(array("status" => "ERR", "message" => print_r($this->db->error(), true))); - exit; - } - } - function fix_sample_serum($headerID) - { - //cari t_ordersample yg belum worklist receive dengan code 017% - $sql = "select T_OrderSampleID - from t_ordersample - join t_sampletype on - T_OrderSampleT_OrderHeaderID = ? - and T_OrderSampleWorklistReceive = 'N' - and T_OrderSampleIsActive = 'Y' - and T_OrderSampleT_SampleTypeID = T_SampletypeID - and T_SampleTypeCode like '017%' - "; - $qry = $this->db->query($sql, array($headerID)); - if (!$qry) { - echo json_encode(array("status" => "ERR", "message" => print_r($this->db->error(), true))); - exit; - } - $rows = $qry->result_array(); - if (count($rows) == 0) return; - //cari T_OrderSample yang sudah di receive yg terakhir - $sql = "select T_OrderSampleID - from t_ordersample - join t_sampletype on - T_OrderSampleT_OrderHeaderID = ? - and T_OrderSampleWorklistReceive = 'Y' - and T_OrderSampleIsActive = 'Y' - and T_OrderSampleT_SampleTypeID = T_SampletypeID - and T_SampleTypeCode like '017%' - order by T_OrderSampleWorklistReceiveDatetime desc - limit 0,1 - "; - $qry = $this->db->query($sql, array($headerID)); - if (!$qry) { - echo json_encode(array("status" => "ERR", "message" => print_r($this->db->error(), true))); - exit; - } - $rcv_rows = $qry->result_array(); - if (count($rcv_rows) == 0) return; - - //print_r($rows); - //print_r($rcv_rows); - $rcv_T_OrderSampleID = $rcv_rows[0]["T_OrderSampleID"]; - //ada yg belum di receive - foreach ($rows as $r) { - $T_OrderSampleID = $r["T_OrderSampleID"]; - $this->update_order_sample($T_OrderSampleID, $rcv_T_OrderSampleID); - } - } - public function search() - { - $prm = $this->sys_input; - $max_rst = 99; - - $id = $prm["order_id"]; - if ($id > 0) { - $this->fix_sample_serum($id); - $this->fn_fix_normal($id); - } - $lang = $this->lang_default_code; - $lang_id = isset($prm['lang_id']) ? $prm['lang_id'] : '0'; - - if ($lang_id != 0) { - $l = $this->db_smartone->where("Nat_LangID", $lang_id)->get("nat_lang")->row(); - $lang = $l->Nat_LangCode; - } - - //tambahan fajri - $sql = " UPDATE t_orderdetail - JOIN t_test ON T_OrderDetailT_TestID = T_TestID - SET T_OrderDetailT_TestIsResult = T_TestIsResult - WHERE - T_OrderDetailT_OrderHeaderID = {$id} AND - T_OrderDetailT_TestIsResult = '' AND - T_OrderDetailIsActive = 'Y'"; - $this->db_smartone->query($sql); - - $tot_count = 0; - $lq = ""; - $group_id = 0; - if (isset($prm['group_id'])) - $group_id = $prm['group_id']; - - if ($group_id != 0) { - $sql = "select distinct T_WorklistDetailNat_TestID Nat_TestID - from t_worklistdetailv2 - where T_WorklistDetailT_WorklistID = {$group_id}"; - $qry = $this->db_smartone->query($sql); - $rows = $qry->result_array(); - $nat_test_ids = "0"; - foreach ($rows as $r) { - $nat_test_ids .= ", " . $r["Nat_TestID"]; - } - $q_group = " ( $nat_test_ids ) "; - - $sql = " - SELECT a1.*, cOUNT(a2.T_OrderDetailID) level - FROM ( - SELECT IFNULL(y.T_OrderDetailT_TestID, x.T_OrderDetailT_TestID) t_testid, - IFNULL(y.T_OrderDetailT_TestName, y.T_OrderDetailT_TestName) t_testname, - y.T_OrderDetailResult result, y.T_OrderDetailResult result_old, y.T_OrderDetailNote note, y.T_OrderDetailNote note_old, - y.T_OrderDetailID id, - y.T_OrderDetailT_TestIsResult is_result, a.T_TestIsQuantitative is_quantitative, - y.T_OrderDetailResultFlag result_flag, - y.T_OrderDetailNat_NormalValueID normal_id, - y.T_OrderDetailNormalValueNote normal_note, y.T_OrderDetailNat_UnitName unit_name, - y.T_OrderdetailNat_MethodeID methode_id, y.T_OrderdetailNat_MethodeName methode_name, - a.T_TestNat_TestID nattest_id, a.T_TestID tx_id, count(T_ResultInstrumentID) as result_instrument_n, - y.T_OrderDetailVerification, T_OrderSampleReceive sample_receive, - T_OrderSampleProcessing sample_processing, T_OrderSampleWorklistReceive sample_worklist_receive, - IF(T_OrderDetailAddOnPreAnalytic = 'Y', T_OrderDetailAddOnPreAnalytic, PreAnalyticIsOk) pre_analytic, - T_OrderDetailAddOnPreAnalytic, - T_OrderHeaderID order_id, y.T_OrderDetailT_TestSasCode test_sas_code, - tx.T_TestSasCode, - T_OrderDetailAddOnResample `resample`, T_OrderDetailAddOnResampleStatus resample_status, - T_OrderDetailAddOnRef ref, y.T_OrderDetailVerification verification, y.T_OrderDetailValidation validation, - T_OrderPromiseDateTime, Group_ResultName as ResultGroupName - FROM t_orderdetail x - left join t_orderpromise on x.T_OrderDetailT_OrderPromiseID = T_OrderPromiseID - JOIN t_test tx ON x.T_OrderDetailT_TestID = T_TestID - JOIN t_test tcheck on tcheck.T_TestNat_TestID in {$q_group} - and ( tx.T_TestID = tcheck.T_TestID or tx.T_TestSasCode like concat(tcheck.T_TestSasCode,'%')) - JOIN group_resultdetail ON Group_ResultDetailT_TestID = x.T_OrderDetailT_TestID AND Group_ResultDetailIsActive = 'Y' - JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND Group_ResultResumeMcu = 'LAB' - LEFT JOIN t_orderdetail y ON x.T_OrderDetailT_TestSasCode LIKE CONCAT(y.T_OrderDetailT_TestSasCode, '%') - AND x.T_OrderDetailT_OrderHeaderID = y.T_OrderDetailT_OrderHeaderID - AND y.T_OrderDetailIsActive = 'Y' - LEFT JOIN t_orderdetailaddon ON x.T_OrderDetailID = T_OrderDetailAddOnT_OrderDetailID - JOIN t_orderheader ON y.T_OrderDetailT_OrderHeaderID = T_OrderHeaderID - LEFT JOIN t_test a ON y.T_OrderDetailT_TestID = a.T_TestID - AND a.T_TestIsNonLab = '' - LEFT JOIN (SELECT T_OrderSampleT_SampleTypeID, T_OrderSampleReceive, T_OrderSampleProcessing, T_OrderSampleWorklistReceive - FROM t_ordersample WHERE T_OrderSampleT_OrderHeaderID = {$id} - AND T_OrderSampleIsactive = 'Y' - GROUP BY T_OrderSampleT_SampleTypeID) os ON a.T_TestT_SampleTypeID = os.T_OrderSampleT_SampleTypeID - or os.T_OrderSampleT_SampleTypeID = fn_sampletype_from_local(a.T_TestNat_TestID) - - LEFT JOIN t_resultinstrument ON T_ResultInstrumentT_OrderDetailID = x.T_OrderDetailID - LEFT JOIN pre_analytic ON PreAnalyticNat_TestID = a.T_TestNat_TestID AND PreAnalyticDate = date(now()) and PreAnalyticIsActive = 'Y' - WHERE x.T_OrderDetailT_OrderHeaderID = {$id} - AND x.T_OrderDetailIsActive = 'Y' - GROUP BY y.T_OrderDetailT_TestID - ORDER BY y.T_OrderDetailT_TestSasCode ASC - ) a1 - - LEFT JOIN t_orderdetail a2 ON a2.T_OrderDetailT_OrderHeaderID = a1.order_id - AND a2.T_OrderDetailIsActive = 'Y' - AND a1.test_sas_code LIKE CONCAT(a2.T_OrderDetailT_testSasCode, '%') - GROUP BY a1.t_testid - order by a1.test_sas_code -"; - $query = $this->db_smartone->query($sql); - $lq = $this->db_smartone->last_query(); - } else { - $sql = " - SELECT a1.*, cOUNT(a2.T_OrderDetailID) level - FROM ( - SELECT IFNULL(y.T_OrderDetailT_TestID, x.T_OrderDetailT_TestID) t_testid, - IFNULL(y.T_OrderDetailT_TestName, y.T_OrderDetailT_TestName) t_testname, - y.T_OrderDetailResult result, y.T_OrderDetailResult result_old, y.T_OrderDetailNote note, y.T_OrderDetailNote note_old, - y.T_OrderDetailID id, - y.T_OrderDetailT_TestIsResult is_result, a.T_TestIsQuantitative is_quantitative, - y.T_OrderDetailResultFlag result_flag, - y.T_OrderDetailNat_NormalValueID normal_id, - y.T_OrderDetailNormalValueNote normal_note, y.T_OrderDetailNat_UnitName unit_name, - y.T_OrderdetailNat_MethodeID methode_id, y.T_OrderdetailNat_MethodeName methode_name, - a.T_TestNat_TestID nattest_id, a.T_TestID tx_id, count(T_ResultInstrumentID) as result_instrument_n, - y.T_OrderDetailVerification, T_OrderSampleReceive sample_receive, - T_OrderSampleProcessing sample_processing, T_OrderSampleWorklistReceive sample_worklist_receive, - IF(T_OrderDetailAddOnPreAnalytic = 'Y', T_OrderDetailAddOnPreAnalytic, PreAnalyticIsOk) pre_analytic, - T_OrderDetailAddOnPreAnalytic, - T_OrderHeaderID order_id, y.T_OrderDetailT_TestSasCode test_sas_code, - tx.T_TestSasCode, - T_OrderDetailAddOnResample `resample`, T_OrderDetailAddOnResampleStatus resample_status, - T_OrderDetailAddOnRef ref, y.T_OrderDetailVerification verification, y.T_OrderDetailValidation validation, - T_OrderPromiseDateTime , Group_ResultName as ResultGroupName - FROM t_orderdetail x - left join t_orderpromise on x.T_OrderDetailT_OrderPromiseID = T_OrderPromiseID - JOIN t_test tx ON x.T_OrderDetailT_TestID = T_TestID - JOIN group_resultdetail ON Group_ResultDetailT_TestID = x.T_OrderDetailT_TestID AND Group_ResultDetailIsActive = 'Y' - JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND Group_ResultResumeMcu = 'LAB' - LEFT JOIN t_orderdetail y ON x.T_OrderDetailT_TestSasCode LIKE CONCAT(y.T_OrderDetailT_TestSasCode, '%') - AND x.T_OrderDetailT_OrderHeaderID = y.T_OrderDetailT_OrderHeaderID - AND y.T_OrderDetailIsActive = 'Y' - - LEFT JOIN t_orderdetailaddon ON x.T_OrderDetailID = T_OrderDetailAddOnT_OrderDetailID - - JOIN t_orderheader ON y.T_OrderDetailT_OrderHeaderID = T_OrderHeaderID - LEFT JOIN t_test a ON y.T_OrderDetailT_TestID = a.T_TestID - AND a.T_TestIsNonLab = '' - LEFT JOIN (SELECT T_OrderSampleT_SampleTypeID, T_OrderSampleReceive, T_OrderSampleProcessing, T_OrderSampleWorklistReceive - FROM t_ordersample WHERE T_OrderSampleT_OrderHeaderID = {$id} - AND T_OrderSampleIsactive = 'Y' - GROUP BY T_OrderSampleT_SampleTypeID) os ON a.T_TestT_SampleTypeID = os.T_OrderSampleT_SampleTypeID - or os.T_OrderSampleT_SampleTypeID = fn_sampletype_from_local(a.T_TestNat_TestID) - - LEFT JOIN t_resultinstrument ON T_ResultInstrumentT_OrderDetailID = x.T_OrderDetailID - LEFT JOIN pre_analytic ON PreAnalyticNat_TestID = a.T_TestNat_TestID AND PreAnalyticDate = date(now()) and PreAnalyticIsActive = 'Y' - WHERE x.T_OrderDetailT_OrderHeaderID = {$id} - AND x.T_OrderDetailIsActive = 'Y' - GROUP BY y.T_OrderDetailT_TestID - ORDER BY y.T_OrderDetailT_TestSasCode ASC - ) a1 - - LEFT JOIN t_orderdetail a2 ON a2.T_OrderDetailT_OrderHeaderID = a1.order_id - AND a2.T_OrderDetailIsActive = 'Y' - AND a1.test_sas_code LIKE CONCAT(a2.T_OrderDetailT_testSasCode, '%') - GROUP BY a1.t_testid - order by a1.test_sas_code -"; - //echo $sql; - $query = $this->db_smartone->query($sql); - $lq = $this->db_smartone->last_query(); - } - // file_put_contents("/xtmp/re-query.sql",$lq); - - if ($query) { - $rst = []; - $rows = $query->result_array(); - - foreach ($rows as $k => $v) { - - if ($v['is_result'] == "Y" && $v['is_quantitative'] == "N") { - $v['template'] = []; - $x = $this->db_smartone->query("CALL sp_master_resulttemplate_get('{$v['t_testid']}')"); - $this->clean_mysqli_connection($this->db_smartone->conn_id); - if ($x) - $v['template'] = $x->result_array(); - } - - // IF Rujukan, by pas Pre Analytik - if ($v['ref'] == 'Y') - $v['pre_analytic'] = 'Y'; - if ($v["id"] == "885455") { - //sipe workaround - //$v["sample_receive"] = "Y"; - $v["sample_worklist_receive"] = "Y"; - } - $rst[] = $v; - } - - $result = array("total" => $tot_count, "records" => $rst, "total_display" => sizeof($rows), "q" => $lq); - $this->sys_ok($result); - } else { - $this->sys_error_db("RE Px rows", $this->db_smartone); - exit; - } - } - - public function save() - { - $prm = $this->sys_input; - $data = json_decode($prm["data"]); - $lang = $this->lang_default_code; - $lang_id = isset($prm['lang_id']) ? $prm['lang_id'] : '0'; - - if ($lang_id != 0) { - $l = $this->db_smartone->where("Nat_LangID", $lang_id)->get("nat_lang")->row(); - $lang = $l->Nat_LangCode; - } - - $sql_norm = "select T_OrderDetailMinValue, T_OrderDetailMaxValue, - T_OrderDetailMinValueInclusive, T_OrderDetailMaxValueInclusive, - Nat_TestFlagLow, Nat_TestFlagHigh - from t_orderdetail - join t_test on T_OrderDetailT_TestID = T_TestID - join nat_test on T_TestNat_TestID = Nat_TestID and T_TestIsActive = 'Y' - where T_OrderDetailID = ? "; - - $ids = []; - foreach ($data as $k => $v) { - if ($v->resultInstrumentID > 0) { - $sql_i = "select T_ResultInstrumentNat_NormalValueID normalValueID - from t_resultinstrument - where T_ResultInstrumentID = ?"; - $qry_i = $this->db_smartone->query($sql_i, array($v->resultInstrumentID)); - if ($qry_i) { - $rows_i = $qry_i->result_array(); - - if (count($rows_i) > 0) { - $sql_iu = "update t_orderdetail, nat_normalvalue , nat_methode - set T_OrderDetailMinValue = Nat_NormalValueMinValue, - T_OrderDetailMinValueInclusive = Nat_NormalValueMinValueInclusive, - T_OrderDetailMaxValue = Nat_NormalValueMaxValue , - T_OrderDetailMaxValueInclusive = Nat_NormalValueMaxValueInclusive, - T_OrderDetailNormalValueNote = Nat_NormalValueNote, - T_OrderDetailNormalValueDescription = Nat_NormalValueDescription, - T_OrderDetailNat_NormalValueID = Nat_NormalValueID, - T_OrderDetailNat_MethodeID = Nat_NormalValueNat_MethodeID, - T_OrderDetailNat_MethodeName = Nat_MethodeName - where T_OrderDetailID = ? and Nat_NormalValueID = ? - and Nat_NormalValueNat_MethodeID = Nat_MethodeID - "; - $this->db_smartone->query($sql_iu, array($v->id, $rows_i[0]["normalValueID"])); - //file_put_contents("/xtmp/update-nilai-normal", $this->db_smartone->last_query() . "\n", FILE_APPEND); - } - } - } - $y = $this->db_smartone->query("SELECT fn_process_sample_handling_perfect('{$v->order_id}', '{$v->test_id}') c") - ->row(); - $req_status = $y->c; - $qry_norm = $this->db_smartone->query($sql_norm, $v->id); - $result_flag = ""; - if ($qry_norm) { - $rows_norm = $qry_norm->result_array(); - if (count($rows_norm) > 0) { - $r = $rows_norm[0]; - if (is_numeric($v->result)) { - - if ($r["T_OrderDetailMinValueInclusive"] == "Y" && $v->result < $r["T_OrderDetailMinValue"]) { - $result_flag = $r["Nat_TestFlagLow"]; - } - if ($r["T_OrderDetailMinValueInclusive"] == "N" && $v->result <= $r["T_OrderDetailMinValue"]) { - $result_flag = $r["Nat_TestFlagLow"]; - } - if ($r["T_OrderDetailMaxValueInclusive"] == "Y" && $v->result > $r["T_OrderDetailMaxValue"]) { - $result_flag = $r["Nat_TestFlagHigh"]; - } - if ($r["T_OrderDetailMaxValueInclusive"] == "N" && $v->result >= $r["T_OrderDetailMaxValue"]) { - $result_flag = $r["Nat_TestFlagHigh"]; - } - } - } - } - if ($lang == $this->lang_default_code) { - $this->db_smartone->set('T_OrderDetailResult', $v->result) - ->set('T_OrderDetailResultFlag', $result_flag) - ->set('T_OrderDetailNote', $v->note) - ->set('T_OrderDetailReqStatus', $req_status) - ->where('T_OrderDetailID', $v->id) - ->update('t_orderdetail'); - } else { - $this->db_smartone->set('T_OrderDetailLangResult', $v->result) - ->set('T_OrderDetailLangNote', $v->note) - ->where('T_OrderDetailLangID', $v->id) - ->update('t_orderdetaillang'); - } - - - - $ids[] = $v->id; - - //log detail - - $sql = "SELECT COUNT(*) n FROM log_orderdetail WHERE Log_OrderDetailT_OrderDetailID = ? AND Log_OrderDetailResult = ? ORDER BY Log_OrderDetailID DESC LIMIT 1"; - $qry = $this->db_lab->query($sql, [$v->id, $v->result]); - if ($qry) { - $n = $qry->row(); - - if ($n->n == 0) { - $sql = "SELECT * FROM t_orderdetail WHERE T_OrderDetailID = ?"; - $qry_order = $this->db_smartone->query($sql, [$v->id]); - $dt_orderdetail = $qry_order->row(); - $dt_detail_log = json_encode($dt_orderdetail); - - $sql = "INSERT INTO log_orderdetail ( - Log_OrderDetailStatus, - Log_OrderDetailT_OrderDetailID, - Log_OrderDetailResult, - Log_OrderDetailJSON, - Log_OrderDetailCreated, - Log_OrderDetailUserID - ) - VALUES (?,?, ?, ?, NOW(), ?)"; - $this->db_lab->query($sql, ['RESULTENTRY',$v->id, $v->result, $dt_detail_log, $this->sys_user['M_UserID']]); - //echo $this->db_lab->last_query(); - //exit(); - } - } - } - - // LOG Process - $order = $this->db_smartone->select('T_OrderDetailT_OrderHeaderID id, T_OrderHeaderLabNumber lab_number', false) - ->join('t_orderheader', 'T_OrderHeaderID = T_OrderDetailT_OrderHeaderID') - ->where('T_OrderDetailID', $data[0]->id) - ->get('t_orderdetail') - ->row(); - - $dblog = $this->db_lab; - $dblog->set('Log_ProcessCode', 'PROCESS.Result.Entry') - ->set('Log_ProcessOrderID', $order->id) - ->set('Log_ProcessOrderNumber', $order->lab_number) - ->set('Log_ProcessJson', json_encode($data)) - ->set('Log_ProcessUserID', $this->sys_user['M_UserID']) - ->insert('log_process'); - // END OF Log Process - //auto calculation - $this->load->library("Resultcalc"); - $rows = $this->resultcalc->auto($order->id); - - try { - foreach ($ids as $id) { - $this->db_smartone->query("call sp_set_normal_value_flag($id)"); - $this->clean_mysqli_connection($this->db_smartone->conn_id); - } - } catch (Exception $e) { - } - - $this->sys_ok($ids); - } - - public function save_template() - { - $prm = $this->sys_input; - - $n = $this->db_smartone->select("COUNT(T_ResultTemplateID) n") - ->where("T_ResultTemplateT_TestID", $prm['test_id']) - ->where("T_ResultTemplateIsActive", "Y") - ->where("T_ResultTemplateValue", $prm['value']) - ->get('t_resulttemplate') - ->row(); - if ($n->n > 0) { - $this->sys_error_db("Insert Result Template", $this->db_smartone); - return; - } - - $r = $this->db_smartone->set("T_ResultTemplateT_TestID", $prm['test_id']) - ->set("T_ResultTemplateValue", $prm['value']) - ->insert('t_resulttemplate'); - if ($r) { - $template = []; - $x = $this->db_smartone->query("CALL sp_master_resulttemplate_get('{$prm['test_id']}')"); - $this->clean_mysqli_connection($this->db_smartone->conn_id); - if ($x) - $template = $x->result_array(); - - $this->sys_ok($template); - } - } - - public function export() - { - $prm = $this->sys_input; - - $sql = "CALL sp_process_result_lang(?, ?, ?, ?)"; - $query = $this->db_smartone->query($sql, [$prm['order_id'], $prm['lang_id'], $prm['is_si'], $this->sys_user['M_UserID']]); - if ($query) { - $r = $query->row(); - if ($r->status == "OK") { - $this->sys_ok($r->data); - return; - } - - $this->sys_error_db("Message : " . $r->message, $this->db_smartone); - } else { - $this->sys_error_db("Lang Result", $this->db_smartone); - return; - } - } - - public function search_group() - { - $prm = $this->sys_input; - $max_rst = 100; - - // QUERY TOTAL - $sql = "select count(*) total - from t_worklist - where T_WorklistIsActive = 'Y' - order by T_WorklistName ASC"; - $query = $this->db_smartone->query($sql); - - if ($query) { - $tot_count = $query->result_array()[0]["total"]; - } else { - $this->sys_error_db("worklist count", $this->db_smartone); - exit; - } - - $sql = "select T_WorklistID group_id, T_WorklistName group_name - from t_worklist - where T_WorklistIsActive = 'Y' - order by T_WorklistName ASC - limit 0, {$max_rst}"; - $query = $this->db_smartone->query($sql); - - if ($query) { - $rows = $query->result_array(); - foreach ($rows as $k => $v) - $rows[$k]['data'] = json_decode($v['data']); - $result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows), "q" => $this->db_smartone->last_query()); - $this->sys_ok($result); - } else { - $this->sys_error_db("worklist rows", $this->db_smartone); - exit; - } - } - - public function search_rerun() - { - $prm = $this->sys_input; - $id = $prm["detail_id"]; - - $sql = "CALL sp_process_result_rerun(?)"; - $query = $this->db_smartone->query($sql, [$id]); - - if ($query) { - $rows = $query->result_array(); - $this->sys_ok(["records" => $rows]); - } else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - - - function getdoctorsfna() - { - $prm = $this->sys_input; - // $id = $prm["id"]; - - $sql = " SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY M_DoctorName ASC"; - //echo $sql; - $query = $this->db_smartone->query($sql); - - if ($query) { - $rows = $query->result_array(); - $this->sys_ok(["records" => $rows]); - } else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - function getfnaresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT Other_FNADetailsID as xid, - Other_FNAT_OrderDetailID as orderdetail_id, - Other_FNADetailsCode as code, - Other_FNADetailsLabel as label, - Other_FNADetailsResult as result, - IFNULL(Other_FNAM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_FNAM_DoctorID) OR Other_FNAM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_fna - JOIN other_fnadetails ON Other_FNADetailsOther_FNAID = Other_FNAID AND Other_FNADetailsIsActive = 'Y' - LEFT JOIN m_doctor ON Other_FNAM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_FNAT_OrderDetailID = {$id} AND Other_FNAIsActive = 'Y' - GROUP BY Other_FNADetailsID - ORDER BY Other_FNADetailsCode ASC"; - $query = $this->db_smartone->query($sql); - - if ($query) { - $rows = $query->result_array(); - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $images = array(); - $sql = "SELECT So_ImageUploadID as xid, - CONCAT('/one-media/one-image-nonlab/',So_ImageUploadNewName) as image_url - FROM t_orderdetail - JOIN so_imageupload ON So_ImageUploadT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND - So_ImageUploadIsActive = 'Y' - WHERE - T_OrderDetailID = {$id} AND - T_OrderDetailIsActive = 'Y' - GROUP BY So_ImageUploadID"; - $images = $this->db_smartone->query($sql)->result_array(); - - $rst = array('doctors' => $doctors, 'results' => $rows, 'images' => $images); - $this->sys_ok(["records" => $rst]); - } else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - function getpatologianatomyresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT Other_PatologiAnatomyID as xid, - Other_PatologiAnatomyT_OrderDetailID as orderdetail_id, - Other_PatologiAnatomyNoSediaan as no_sediaan, - Other_PatologiAnatomyDiagnosaKlinis as diagnosa, - Other_PatologiAnatomyKeteranganKlinis as klinis, - Other_PatologiAnatomyLokasiOrgan as lokasi, - Other_PatologiAnatomyMakroskopik as makroskopik, - Other_PatologiAnatomyMikroskopik as mikroskopik, - Other_PatologiAnatomyKesimpulan as kesimpulan, - IFNULL(Other_PatologiAnatomyM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_PatologiAnatomyM_DoctorID) OR Other_PatologiAnatomyM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_patologi_anatomy - LEFT JOIN m_doctor ON Other_PatologiAnatomyM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_PatologiAnatomyT_OrderDetailID = {$id} AND Other_PatologiAnatomyIsActive = 'Y' - GROUP BY Other_PatologiAnatomyID - ORDER BY Other_PatologiAnatomyID ASC - LIMIT 1"; - $query = $this->db_smartone->query($sql); - - if ($query) { - $rows = $query->row_array(); - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - - $sql = "SELECT So_ImageUploadPatologyAnatomyID as xid, - CONCAT('/one-media/one-image-nonlab/',So_ImageUploadPatologyAnatomyNewName) as image_url, - So_ImageUploadPatologyAnatomyType as type - FROM t_orderdetail - JOIN so_imageupload_patology_anatomy ON So_ImageUploadPatologyAnatomyT_OrderHeaderID= T_OrderDetailT_OrderHeaderID AND - So_ImageUploadPatologyAnatomyIsActive= 'Y' - WHERE - T_OrderDetailID = {$id} AND - T_OrderDetailIsActive = 'Y' - GROUP BY So_ImageUploadPatologyAnatomyID"; - $images = $this->db_smartone->query($sql)->result_array(); - $mikro = []; - $makro = []; - - foreach ($images as $key => $value) { - - if ($value['type'] == 'mikro') { - $mikro[] = $value; - } - if ($value['type'] == 'makro') { - $makro[] = $value; - } - } - - $rst = array('doctors' => $doctors, 'result' => $rows, "mikro" => $mikro, "makro" => $makro); - $this->sys_ok(["records" => $rst]); - } else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - - - - function uploadimage() - { - if (! $this->isLogin) { - $this->sys_error("Invalid Token"); - exit; - } - - $userid = $this->sys_user["M_UserID"]; - $data = []; - //print_r($_SERVER); - - $prm = $this->sys_input; - $orderid = $this->input->post('orderid'); - $labnumber = $this->input->post('labnumber'); - $sql = "UPDATE so_imageupload SET - So_ImageUploadIsActive = 'N', - So_ImageUploadUserID = {$userid} - WHERE - So_ImageUploadT_OrderHeaderID = {$orderid}"; - //echo $sql; - $this->db_onedev->query($sql); - //$config['upload_path'] = 'assets/'; - - $path = '/home/one/project/one/one-media/one-image-nonlab/'; - //echo $path; - $config['upload_path'] = $path; - $config['allowed_types'] = 'jpg|jpeg|png|gif'; - - $config['max_size'] = '10000'; - $count = count($_FILES['files']['name']); - //echo $count; - $this->load->library('upload', $config); - - $error = []; - for ($i = 0; $i < $count; $i++) { - - - if (!empty($_FILES['files']['name'][$i])) { - - - - $_FILES['file']['name'] = $_FILES['files']['name'][$i]; - - $_FILES['file']['type'] = $_FILES['files']['type'][$i]; - - $_FILES['file']['tmp_name'] = $_FILES['files']['tmp_name'][$i]; - - $_FILES['file']['error'] = $_FILES['files']['error'][$i]; - - $_FILES['file']['size'] = $_FILES['files']['size'][$i]; - - - - $namex = $orderid . '-' . $labnumber . '-' . $this->generateRandomString(5); - //echo $namex; - - $config['file_name'] = $namex; - $this->upload->initialize($config); - //echo $config['file_name'] ; - - - - - - if ($this->upload->do_upload('file')) { - - $uploadData = $this->upload->data(); - - $filename = $uploadData['file_name']; - //echo $filename; - - - $sql = "INSERT INTO so_imageupload ( - So_ImageUploadT_OrderHeaderID, - So_ImageUploadT_OrderHeaderLabNumber, - So_ImageUploadT_SampleTypeID, - So_ImageUploadOldName, - So_ImageUploadNewName, - So_ImageUploadCreated, - So_ImageUploadUserID - ) - VALUES( - {$orderid}, - '{$labnumber}', - '150', - '{$_FILES['files']['name'][$i]}', - '{$filename}', - NOW(), - {$userid} - - )"; - //echo $sql; - $this->db_onedev->query($sql); - $xlast_id = $this->db_onedev->insert_id(); - $data['totalFiles'][] = array('xid' => $xlast_id, 'image_url' => '/one-media/one-image-nonlab/' . $filename); - } else { - $error = array('error' => $this->upload->display_errors()); - } - } - } - - $result = array("total" => count($data['totalFiles']), "records" => $data['totalFiles'], 'errors' => $error); - $this->sys_ok($result); - } - function uploadimagePatologiAnatomi() - { - if (! $this->isLogin) { - $this->sys_error("Invalid Token"); - exit; - } - - $userid = $this->sys_user["M_UserID"]; - $data = []; - //print_r($_SERVER); - - $prm = $this->sys_input; - $orderid = $this->input->post('orderid'); - $type = $this->input->post('type'); - $labnumber = $this->input->post('labnumber'); - $sql = "UPDATE so_imageupload_patology_anatomy SET - So_ImageUploadPatologyAnatomyIsActive = 'N', - So_ImageUploadPatologyAnatomyUserID = {$userid} - WHERE - So_ImageUploadPatologyAnatomyT_OrderHeaderID = {$orderid} - AND So_ImageUploadPatologyAnatomyType = '{$type}'"; - //echo $sql; - $qry = $this->db_onedev->query($sql); - $last_qry = $this->db_onedev->last_query(); - if (!$qry) { - $message = $this->db_onedev->error(); - $message['last_qry'] = $last_qry; - $this->sys_error_db($message); - exit; - } - //$config['upload_path'] = 'assets/'; - - $path = '/home/one/project/one/one-media/one-image-nonlab/'; - //echo $path; - $config['upload_path'] = $path; - $config['allowed_types'] = 'jpg|jpeg|png|gif'; - - $config['max_size'] = '10000'; - $count = count($_FILES['files']['name']); - //echo $count; - $this->load->library('upload', $config); - - $error = []; - for ($i = 0; $i < $count; $i++) { - - - if (!empty($_FILES['files']['name'][$i])) { - - - - $_FILES['file']['name'] = $_FILES['files']['name'][$i]; - - $_FILES['file']['type'] = $_FILES['files']['type'][$i]; - - $_FILES['file']['tmp_name'] = $_FILES['files']['tmp_name'][$i]; - - $_FILES['file']['error'] = $_FILES['files']['error'][$i]; - - $_FILES['file']['size'] = $_FILES['files']['size'][$i]; - - - - $namex = $orderid . '-' . $labnumber . '-' . $this->generateRandomString(5); - //echo $namex; - - $config['file_name'] = $namex; - $this->upload->initialize($config); - //echo $config['file_name'] ; - - - - - - if ($this->upload->do_upload('file')) { - - $uploadData = $this->upload->data(); - - $filename = $uploadData['file_name']; - //echo $filename; - - - $sql = "INSERT INTO so_imageupload_patology_anatomy ( - So_ImageUploadPatologyAnatomyT_OrderHeaderID, - So_ImageUploadPatologyAnatomyT_OrderHeaderLabNumber, - So_ImageUploadPatologyAnatomyT_SampleTypeID, - So_ImageUploadPatologyAnatomyOldName, - So_ImageUploadPatologyAnatomyNewName, - So_ImageUploadPatologyAnatomyCreated, - So_ImageUploadPatologyAnatomyUserID, - So_ImageUploadPatologyAnatomyType - ) - VALUES( - {$orderid}, - '{$labnumber}', - '145', - '{$_FILES['files']['name'][$i]}', - '{$filename}', - NOW(), - {$userid}, - '{$type}' - - )"; - //echo $sql; - $qry = $this->db_onedev->query($sql); - $last_qry = $this->db_onedev->last_query(); - if (!$qry) { - $message = $this->db_onedev->error(); - $message['last_qry'] = $last_qry; - $this->sys_error_db($message); - exit; - } - $xlast_id = $this->db_onedev->insert_id(); - $data['totalFiles'][] = array('xid' => $xlast_id, 'image_url' => '/one-media/one-image-nonlab/' . $filename); - } else { - $error = array('error' => $this->upload->display_errors()); - } - } - } - - $result = array("total" => count($data['totalFiles']), "records" => $data['totalFiles'], 'errors' => $error); - $this->sys_ok($result); - } - - - function generateRandomString($length = 10) - { - $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; - $charactersLength = strlen($characters); - $randomString = ''; - for ($i = 0; $i < $length; $i++) { - $randomString .= $characters[rand(0, $charactersLength - 1)]; - } - return $randomString; - } - - function getcytologiresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT Other_CytologiDetailsID as xid, - Other_CytologiT_OrderDetailID as orderdetail_id, - Other_CytologiDetailsCode as code, - Other_CytologiDetailsLabel as label, - Other_CytologiDetailsResult as result, - IFNULL(Other_CytologiM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_CytologiM_DoctorID) OR Other_CytologiM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_cytologi - JOIN other_cytologidetails ON Other_CytologiDetailsOther_CytologiID = Other_CytologiID AND Other_CytologiDetailsIsActive = 'Y' - LEFT JOIN m_doctor ON Other_CytologiM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_CytologiT_OrderDetailID = {$id} AND Other_CytologiIsActive = 'Y' - GROUP BY Other_CytologiDetailsID - ORDER BY Other_CytologiDetailsCode ASC"; - //echo $sql; - $query = $this->db_smartone->query($sql); - - if ($query) { - $rows = $query->result_array(); - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $rst = array('doctors' => $doctors, 'results' => $rows); - $this->sys_ok(["records" => $rst]); - } else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - function getmikroresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT - Other_MikroID as xid, - Other_MikroHasilBiakan as hasil_biakan, - Other_MikroSampleTypeName as sample_name, - Other_MikroT_OrderDetailID as orderdetail_id, - Other_MikroResult as result_value, - '' as result_other, - IFNULL(T_BacteriaID,0) as T_BacteriaID, - IFNULL(T_BacteriaName,'') as T_BacteriaName, - '' as details, - IFNULL(Other_MikroM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_MikroM_DoctorID) OR Other_MikroM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_mikro - LEFT JOIN t_bacteria ON Other_MikroT_BacteriaID = T_BacteriaID - LEFT JOIN m_doctor ON Other_MikroM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_MikroT_OrderDetailID = {$id} AND Other_MikroIsActive = 'Y' - GROUP BY Other_MikroID"; - //echo $sql; - $query = $this->db_smartone->query($sql); - - if ($query) { - $row = $query->row_array(); - if ($row) { - if ($row['result_value'] != 'Positif' && $row['result_value'] != 'Negatif') { - $row['result_other'] = $row['result_value']; - $row['result_value'] = 'other'; - } - $sql = "SELECT '' as xno, - Other_MikroDetailsID as xid, - Other_MikroDetailsValue as value, - IF(Other_MikroDetailsNote = 'R','Y','N') as chx_r, - IF(Other_MikroDetailsNote = 'I','Y','N') as chx_i, - IF(Other_MikroDetailsNote = 'S','Y','N') as chx_s, - Other_MikroDetailsNote as note, - t_antibiotic.* - FROM other_mikrodetails - LEFT JOIN t_antibiotic ON Other_MikroDetailsT_AntibioticID = T_AntibioticID - WHERE - Other_MikroDetailsOther_MikroID = {$row['xid']} AND Other_MikroDetailsIsActive = 'Y' - GROUP BY Other_MikroDetailsID - ORDER BY T_AntibioticName ASC"; - //echo $sql; - $details = $this->db_smartone->query($sql)->result_array(); - if ($details) { - foreach ($details as $k => $v) { - $details[$k]['xno'] = $k + 1; - } - } - $row['details'] = $details; - } else { - $row = array('xid' => '0', 'hasil_biakan' => '', 'result_value' => 'Negatif', 'sample_name' => '', 'orderdetail_id' => $id, 'T_BacteriaID' => '0', 'T_BacteriaName' => '0', 'details' => array(), 'doctor_id' => '0', 'doctor_name' => '0'); - } - } else { - $row = array('xid' => '0', 'hasil_biakan' => '', 'result_value' => 'Negatif', 'sample_name' => '', 'orderdetail_id' => $id, 'T_BacteriaID' => '0', 'T_BacteriaName' => '0', 'details' => array(), 'doctor_id' => '0', 'doctor_name' => '0'); - } - //print_r($row); - - - - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 7 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $sql = " - SELECT '0' as id, 'Belum memilih bakteria' as name - UNION - SELECT T_BacteriaID as id, T_BacteriaName as name - FROM t_bacteria - WHERE - T_BacteriaIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $bacteries = $this->db_smartone->query($sql)->result_array(); - $rst = array('doctors' => $doctors, 'bacteries' => $bacteries, 'results' => $row); - $this->sys_ok(["records" => $rst]); - } - function getantibiotics() - { - $prm = $this->sys_input; - $id = $prm["id"]; - $sql = " SELECT '' as xno, - 0 as xid, - '' as hasil_biakan, - '' as sample_name, - 0 as value, - 'Y' as chx_r, - 'N' as chx_i, - 'N' as chx_s, - 'R' as note, - t_antibiotic.* - FROM t_antibiotic - WHERE - T_AntibioticT_BacteriaID = {$prm['id']} AND T_AntibioticIsActive= 'Y' - ORDER BY T_AntibioticName ASC"; - //echo $sql; - $rows = $this->db_smartone->query($sql)->result_array(); - if (rows) { - foreach ($rows as $k => $v) { - $rows[$k]['xno'] = $k + 1; - } - } - - $this->sys_ok(["records" => $rows]); - } - function getlcprepresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = "SELECT T_OrderDetailVerification as verification, T_OrderDetailValidation as validation FROM t_orderdetail WHERE T_OrderDetailID = ?"; - $order = $this->db_smartone->query($sql, array($id))->row_array(); - - - $sql = " SELECT Other_LcprepDetailsID as xid, - Other_LcprepID as header_id, - Other_LcprepT_orderDetailID as orderdetail_id, - Other_LcprepDetailsCode as code, - Other_LcprepDetailsLabel as label, - Other_LcprepDetailsResult as result, - IFNULL(Other_LcprepM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_LcprepM_DoctorID) OR Other_LcprepM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_lcprep - JOIN other_lcprepdetails ON Other_LcprepDetailsOther_LcprepID = Other_LcprepID AND Other_LcprepDetailsIsActive = 'Y' - LEFT JOIN m_doctor ON Other_LcprepM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_LcprepT_orderDetailID = ? AND Other_LcprepIsActive = 'Y' - GROUP BY Other_LcprepDetailsOther_LcprepID, Other_LcprepDetailsCode - ORDER BY Other_LcprepDetailsCode ASC"; - //echo $sql; - $rows = $this->db_smartone->query($sql, array($id))->result_array(); - if (count($rows) == 0) { - $rows = array( - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'A', - 'label' => 'DESKRIPSI', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ), - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'B', - 'label' => 'KESIMPULAN', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ) - ); - } - - $other_rows = array(); - $langs = array(array('id' => 1, 'name' => 'Bahasa Indonesia')); - $selected_lang = array(array('id' => 1, 'name' => 'Bahasa Indonesia')); - $sql = "SELECT T_OrderHeaderAddOnSecondM_LangID as lang_id, - M_LangName as lang_name - FROM t_orderdetail - JOIN t_orderheader ON T_OrderDetailT_OrderHeaderID = T_OrderHeaderID AND T_OrderHeaderIsActive = 'Y' - JOIN t_orderheaderaddon ON T_OrderHeaderAddonT_OrderHeaderID = T_OrderHeaderID AND T_OrderHeaderAddonIsActive = 'Y' - JOIN m_lang ON T_OrderHeaderAddOnSecondM_LangID = M_LangID AND M_LangIsActive = 'Y' - WHERE T_OrderDetailID = {$id} AND T_OrderDetailIsActive = 'Y'"; - - $other_lang = $this->db_smartone->query($sql)->result_array(); - if (count($other_lang) > 0) { - $langs[] = array('id' => $other_lang[0]['lang_id'], 'name' => $other_lang[0]['lang_name']); - $selected_lang = array('id' => $other_lang[0]['lang_id'], 'name' => $other_lang[0]['lang_name']); - - - $sql = " SELECT Other_LcprepDetailsLangsID as xid, - Other_LcprepID as header_id, - Other_LcprepT_orderDetailID as orderdetail_id, - Other_LcprepDetailsLangsCode as code, - Other_LcprepDetailsLangsLabel as label, - Other_LcprepDetailsLangsResult as result, - IFNULL(Other_LcprepM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_LcprepM_DoctorID) OR Other_LcprepM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_lcprep - JOIN other_lcprepdetails_lang ON Other_LcprepDetailsLangsOther_LcprepID = Other_LcprepID AND Other_LcprepDetailsLangsIsActive = 'Y' - LEFT JOIN m_doctor ON Other_LcprepM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_LcprepT_orderDetailID = {$id} AND Other_LcprepDetailsLangsIsActive = 'Y' - GROUP BY Other_LcprepDetailsLangsOther_LcprepID, Other_LcprepDetailsLangsCode - ORDER BY Other_LcprepDetailsLangsCode ASC"; - // echo $sql; - $other_rows = $this->db_smartone->query($sql)->result_array(); - if (count($other_rows) == 0) { - $other_rows = array( - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'AA', - 'label' => 'DESCRIPTION', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ), - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'BB', - 'label' => 'CONCLUSION', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ) - ); - } - } - - $header_id = $rows[0]['header_id']; - $sql = "SELECT IFNULL(Other_LcprepAdekuasiID,0) as xid, - Lcprep_AdekuasiID as id, - Lcprep_AdekuasiLabel as name, - Lcprep_AdekuasiLabel as name_en, - IF(ISNULL(Other_LcprepAdekuasiID),'N',Other_LcprepAdekuasiChex) as chex - FROM lcprep_adekuasi - LEFT JOIN other_lcprepadekuasi ON Other_LcprepAdekuasiLcprep_AdekuasiID = Lcprep_AdekuasiID AND - Other_LcprepAdekuasiOther_LcprepID = {$header_id} AND - Other_LcprepAdekuasiIsActive = 'Y' - WHERE - Lcprep_AdekuasiIsActive = 'Y' - GROUP BY Lcprep_AdekuasiID - ORDER BY Lcprep_AdekuasiOrder ASC - "; - //echo $sql; - $adeakuasi = $this->db_smartone->query($sql)->result_array(); - foreach ($adeakuasi as $kc => $vc) { - $adeakuasi[$kc]['chex'] = $vc['chex'] == 'N' ? false : true; - $adeakuasi[$kc]['name_en'] = $this->translate_word($vc['name']); - } - - $sql = "SELECT IFNULL(Other_LcprepKategoriUmumID,0) as xid, - Lcprep_KategoriUmumID as id, - Lcprep_KategoriUmumLabel as name, - Lcprep_KategoriUmumLabel as name_en, - IF(ISNULL(Other_LcprepKategoriUmumID),'N',Other_LcprepKategoriUmumChex) as chex - FROM lcprep_kategoriumum - LEFT JOIN other_lcprepkategoriumum ON Other_LcprepKategoriUmumLcprep_KategoriUmumID = Lcprep_KategoriUmumID AND - Other_LcprepKategoriUmumOther_LcprepID = {$header_id} AND - Other_LcprepKategoriUmumIsActive = 'Y' - WHERE - Lcprep_KategoriUmumIsActive = 'Y' - GROUP BY Lcprep_KategoriUmumID - "; - //echo $sql; - $kategoriumum = $this->db_smartone->query($sql)->result_array(); - foreach ($kategoriumum as $kc => $vc) { - $kategoriumum[$kc]['chex'] = $vc['chex'] == 'N' ? false : true; - $kategoriumum[$kc]['name_en'] = $this->translate_word($vc['name']); - } - - $sql = " - SELECT Lcprep_InterpretasiGroupID as group_id, - Lcprep_InterpretasiGroupName as group_name, - Lcprep_InterpretasiGroupName as group_name_en, - '' as subgroups - FROM lcprep_interpretasigroup - WHERE - Lcprep_InterpretasiGroupIsActive = 'Y' - "; - //echo $sql; - $interpretasi = $this->db_smartone->query($sql)->result_array(); - foreach ($interpretasi as $k => $v) { - $interpretasi[$k]['group_name_en'] = $this->translate_word($v['group_name']); - $subgroups = array(); - $sql = "SELECT Lcprep_InterpretasiSubgroupID as subgroup_id, - Lcprep_InterpretasiSubgroupName as subgroup_name, - Lcprep_InterpretasiSubgroupName as subgroup_name_en, - '' as childs - FROM lcprep_interpretasisubgroup - WHERE - Lcprep_InterpretasiSubgroupLcprep_InterpretasiGroupID = {$v['group_id']} AND Lcprep_InterpretasiSubgroupIsActive = 'Y'"; - //echo $sql; - $subgroups = $this->db_smartone->query($sql)->result_array(); - if (count($subgroups) > 0) { - foreach ($subgroups as $ki => $vi) { - $subgroups[$ki]['subgroup_name_en'] = $this->translate_word($vi['subgroup_name']); - $childs = array(); - - $sql = "SELECT IFNULL(Other_LcprepInterpretasiID,0) as xid, - IFNULL(Other_LcprepInterpretasiChex,'N') as chex, - IFNULL(Other_LcprepInterpretasiValue,'') as value, - IFNULL(Other_LcprepInterpretasiValueEng,'') as value_en, - Lcprep_InterpretasiID as id, - Lcprep_InterpretasiLcprep_InterpretasiSubgroupID as subgroup_id, - Lcprep_InterpretasiCode as code, - Lcprep_InterpretasiName as name, - Lcprep_InterpretasiName as name_en, - Lcprep_InterpretasiParentID as parent_id, - Lcprep_InterpretasiIsParent as is_parent, - Lcprep_InterpretasiHasResult as has_result, - Lcprep_InterpretasiTypeResult as type_result - FROM lcprep_interpretasi - LEFT JOIN other_lcprepinterpretasi ON Other_LcprepInterpretasiOther_LcprepID = {$header_id} AND - Other_LcprepInterpretasiLcprep_InterpretasiID = Lcprep_InterpretasiID AND - Other_LcprepInterpretasiIsActive = 'Y' - WHERE - Lcprep_InterpretasiLcprep_InterpretasiSubgroupID = {$vi['subgroup_id']} AND Lcprep_InterpretasiIsActive = 'Y' - GROUP BY Lcprep_InterpretasiID Order BY Lcprep_InterpretasiCode ASC"; - $childs = $this->db_smartone->query($sql)->result_array(); - if ($childs) { - foreach ($childs as $kc => $vc) { - $childs[$kc]['chex'] = $vc['chex'] == 'N' ? false : true; - $childs[$kc]['name_en'] = $this->translate_word($vc['name']); - } - } - $subgroups[$ki]['childs'] = $childs; - } - } - - $interpretasi[$k]['subgroups'] = $subgroups; - } - - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - - - - $rst = array('order' => $order, 'langs' => $langs, 'selected_lang' => $selected_lang, 'doctors' => $doctors, 'results' => $rows, 'other_results' => $other_rows, 'adekuasi' => $adeakuasi, 'kategoriumum' => $kategoriumum, 'interpretasi' => $interpretasi); - $this->sys_ok(["records" => $rst]); - } - - function translate_word($word) - { - $sql = "SELECT * - FROM translate_word - WHERE Translate_WordNat_LangID = '2' AND - BINARY Translate_WordFrom = '{$word}' AND - Translate_WordIsActive = 'Y' - LIMIT 1"; - $dt = $this->db_smartone->query($sql)->result_array(); - if (count($dt) > 0) { - return $dt[0]['Translate_WordTo']; - } else { - return $word; - } - } - - function getpapsmearresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT Other_PapSmearDetailsID as xid, - Other_PapSmearID as header_id, - Other_PapSmearT_OrderDetailID as orderdetail_id, - Other_PapSmearDetailsCode as code, - Other_PapSmearDetailsLabel as label, - Other_PapSmearDetailsResult as result, - IFNULL(Other_PapSmearM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_PapSmearM_DoctorID) OR Other_PapSmearM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_papsmear - JOIN other_papsmeardetails ON Other_PapSmearDetailsOther_PapSmearID = Other_PapSmearID AND Other_PapSmearDetailsIsActive = 'Y' - LEFT JOIN m_doctor ON Other_PapSmearM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_PapSmearT_OrderDetailID = {$id} AND Other_PapSmearIsActive = 'Y' - GROUP BY Other_PapSmearDetailsID - ORDER BY Other_PapSmearDetailsCode ASC"; - //echo $sql; - $rows = $this->db_smartone->query($sql)->result_array(); - if (!$rows) { - $rows = array( - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'A', - 'label' => 'Makroskopik', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ), - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'B', - 'label' => 'Mikroskopik', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ), - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'C', - 'label' => 'Kesimpulan', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ) - ); - } - - $header_id = $rows[0]['header_id']; - $sql = "SELECT Other_PapSmearMaturasiID as xid, - Other_PapSmearMaturasiValue as value - FROM other_papsmearmaturasi - WHERE - Other_PapSmearMaturasiOther_PapSmearID = {$header_id} AND - Other_PapSmearMaturasiIsActive = 'Y' - "; - //echo $sql; - $dt_maturasi = $this->db_smartone->query($sql)->row_array(); - if (!$dt_maturasi) { - $maturasi = array('xid' => '0', 'value' => array('', '', '')); - } else { - $value = explode('/', $dt_maturasi['value']); - $maturasi = array('xid' => $dt_maturasi['xid'], 'value' => $value); - } - - $sql = "SELECT IFNULL(Other_PapSmearBahanID,0) as xid, - M_PapSmearBahanID as bahan_id, - M_PapSmearBahanName as name, - IF(ISNULL(Other_PapSmearBahanID),'N','Y') as selected - FROM m_papsmearbahan - LEFT JOIN other_papsmearbahan ON Other_PapSmearBahanM_PapSmearBahanID = M_PapSmearBahanID AND - Other_PapSmearBahanOther_PapSmearID = {$header_id} AND - Other_PapSmearBahanIsActive = 'Y' - WHERE - M_PapSmearBahanIsActive = 'Y' - ORDER BY M_PapSmearBahanID ASC - "; - //echo $sql; - $bahans = $this->db_smartone->query($sql)->result_array(); - - $sql = "SELECT IFNULL(Other_PapsmearCategoryID,0) as xid, - M_PapSmearCategoryID as category_id, - M_PapSmearCategoryName as name, - IF(ISNULL(Other_PapsmearCategoryID),'N','Y') as selected - FROM m_papsmearcategory - LEFT JOIN other_papsmearcategory ON Other_PapsmearCategoryM_PapSmearCategoryID = M_PapSmearCategoryID AND - Other_PapsmearCategoryOther_PapSmearID = {$header_id} AND - Other_PapsmearCategoryIsActive = 'Y' - WHERE - M_PapSmearCategoryIsActive = 'Y' - ORDER BY M_PapSmearCategoryID ASC - "; - //echo $sql; - $categories = $this->db_smartone->query($sql)->result_array(); - - $sql = "SELECT IFNULL(Other_PapSmearCheckID,0) as xid, - M_PapSmearCheckID as check_id, - M_PapSmearCheckLabel as name, - IF(ISNULL(Other_PapSmearCheckID),'N','Y') as selected, - Other_PapSmearCheckNote as note - FROM m_papsmearcheck - LEFT JOIN other_papsmearcheck ON Other_PapSmearCheckM_PapSmearCheckID = M_PapSmearCheckID AND - Other_PapSmearCheckOther_PapSmearID = {$header_id} AND - Other_PapSmearCheckIsActive = 'Y' - WHERE - M_PapSmearCheckIsActive = 'Y' - ORDER BY M_PapSmearCheckCode ASC - "; - $checks = $this->db_smartone->query($sql)->result_array(); - - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $rst = array('doctors' => $doctors, 'checks' => $checks, 'bahans' => $bahans, 'categories' => $categories, 'maturasi' => $maturasi, 'results' => $rows); - $this->sys_ok(["records" => $rst]); - } - - function saveresult_lcprep() - { - $prm = $this->sys_input; - $detail_id = $prm['detail_id']; - $doctor_id = $prm['doctor']; - $adekuasi = $prm['adekuasi']; - $kategoriumum = $prm['kategoriumum']; - $interpretasi = $prm['interpretasi']; - $results = $prm['results']; - $selected_lang = $prm['selected_lang']; - $other_results = $prm['other_results']; - - $userid = $this->sys_user['M_UserID']; - - $header_id = 0; - $sql = "SELECT * FROM other_lcprep WHERE Other_LcprepT_orderDetailID = ? AND Other_LcprepIsActive = 'Y'"; - $dt_header = $this->db_smartone->query($sql, array($detail_id))->row_array(); - if ($dt_header) { - $header_id = $dt_header['Other_LcprepID']; - } - if ($header_id == 0) { - $sql = "INSERT INTO other_lcprep( - Other_LcprepT_orderDetailID, - Other_LcprepM_DoctorID, - Other_LcprepUserID, - Other_LcprepCreated - ) - VALUES( - ?, - ?, - ?, - NOW() - )"; - //echo $sql; - $query = $this->db_smartone->query($sql, array($detail_id, $doctor_id, $userid)); - if(!$query){ - echo $this->db_smartone->last_query(); - exit; - } - $header_id = $this->db_smartone->insert_id(); - } else { - $sql = "UPDATE other_lcprep SET Other_LcprepM_DoctorID = ?, Other_LcprepUserID = ? WHERE Other_LcprepID = ?"; - $query = $this->db_smartone->query($sql, array($doctor_id, $userid, $header_id)); - if(!$query){ - echo $this->db_smartone->last_query(); - exit; - } - } - - - - if ($adekuasi) { - foreach ($adekuasi as $k => $v) { - $selected = $v['chex'] ? 'Y' : 'N'; - if (intval($v['xid'] == 0)) { - $sql = "UPDATE other_lcprepadekuasi SET Other_LcprepAdekuasiIsActive = 'N' - WHERE - Other_LcprepAdekuasiOther_LcprepID = ? AND - Other_LcprepAdekuasiIsActive = 'Y' AND - Other_LcprepAdekuasiLcprep_AdekuasiID = ?"; - $query = $this->db_smartone->query($sql, array($header_id, $v['id'])); - if(!$query){ - echo $this->db_smartone->last_query(); - exit; - } - $sql = "INSERT INTO other_lcprepadekuasi ( - Other_LcprepAdekuasiOther_LcprepID, - Other_LcprepAdekuasiLcprep_AdekuasiID, - Other_LcprepAdekuasiChex, - Other_LcprepAdekuasiUserID, - Other_LcprepAdekuasiCreated - ) - VALUES( - ?, - ?, - ?, - ?, - NOW() - )"; - $query = $this->db_smartone->query($sql, array($header_id, $v['id'], $selected, $userid)); - if(!$query){ - echo $this->db_smartone->last_query(); - exit; - } - //echo $sql; - } - if (intval($v['xid'] != 0)) { - - $sql = "UPDATE other_lcprepadekuasi SET - Other_LcprepAdekuasiChex = ?, - Other_LcprepAdekuasiUserID = ? - WHERE - Other_LcprepAdekuasiID = ? - "; - $query = $this->db_smartone->query($sql, array($selected, $userid, $v['xid'])); - if(!$query){ - echo $this->db_smartone->last_query(); - exit; - } - } - - //echo $sql; - } - } - - if ($kategoriumum) { - foreach ($kategoriumum as $k => $v) { - $selected = $v['chex'] ? 'Y' : 'N'; - if (intval($v['xid'] == 0)) { - $sql = "UPDATE other_lcprepkategoriumum SET Other_LcprepKategoriUmumIsActive = 'N' - WHERE - Other_LcprepKategoriUmumOther_LcprepID = ? AND - Other_LcprepKategoriUmumLcprep_KategoriUmumID = ? AND - Other_LcprepKategoriUmumIsActive = 'Y' - "; - $query = $this->db_smartone->query($sql, array($header_id, $v['id'])); - if(!$query){ - echo $this->db_smartone->last_query(); - exit; - } - $sql = "INSERT INTO other_lcprepkategoriumum ( - Other_LcprepKategoriUmumOther_LcprepID, - Other_LcprepKategoriUmumLcprep_KategoriUmumID, - Other_LcprepKategoriUmumChex, - Other_LcprepKategoriUmumUserID, - Other_LcprepKategoriUmumCreated - ) - VALUES( - ?, - ?, - ?, - ?, - NOW() - )"; - $query = $this->db_smartone->query($sql, array($header_id, $v['id'], $selected, $userid)); - if(!$query){ - echo $this->db_smartone->last_query(); - exit; - } - } - if (intval($v['xid'] != 0)) { - $sql = "UPDATE other_lcprepkategoriumum SET - Other_LcprepKategoriUmumChex = ?, - Other_LcprepKategoriUmumUserID = ? - WHERE - Other_LcprepKategoriUmumID = ? - "; - $query = $this->db_smartone->query($sql, array($selected, $userid, $v['xid'])); - if(!$query){ - echo $this->db_smartone->last_query(); - exit; - } - } - - //echo $sql; - } - } - - if (count($results) > 0 && intval($selected_lang) == 1) { - foreach ($results as $k => $v) { - if (intval($v['xid'] == 0)) { - $sql = "UPDATE other_lcprepdetails SET Other_LcprepDetailsIsActive = 'N' - WHERE - Other_LcprepDetailsOther_LcprepID = ? AND - Other_LcprepDetailsCode = ? AND - Other_LcprepDetailsIsActive = 'Y'"; - $query = $this->db_smartone->query($sql, array($header_id, $v['code'])); - if(!$query){ - echo $this->db_smartone->last_query(); - exit; - } - $sql = "INSERT INTO other_lcprepdetails ( - Other_LcprepDetailsOther_LcprepID, - Other_LcprepDetailsCode, - Other_LcprepDetailsLabel, - Other_LcprepDetailsResult, - Other_LcprepDetailsUserID, - Other_LcprepDetailsCreated - ) - VALUES( - ?, - ?, - ?, - ?, - ?, - NOW() - )"; - $query = $this->db_smartone->query($sql, array($header_id, $v['code'], $v['label'], $v['result'], $userid)); - if(!$query){ - echo $this->db_smartone->last_query(); - exit; - } - } - if (intval($v['xid'] != 0)) { - $sql = "UPDATE other_lcprepdetails SET - Other_LcprepDetailsCode = ?, - Other_LcprepDetailsLabel = ?, - Other_LcprepDetailsResult = ?, - Other_LcprepDetailsUserID = ? - WHERE - Other_LcprepDetailsID = ? - "; - $query = $this->db_smartone->query($sql, array($v['code'], $v['label'], $v['result'], $userid, $v['xid'])); - if(!$query){ - echo $this->db_smartone->last_query(); - exit; - } - } - //echo $sql; - } - } - - if (count($other_results) > 0 && intval($selected_lang) == 2) { - foreach ($other_results as $k => $v) { - if (intval($v['xid'] == 0)) { - $sql = "UPDATE other_lcprepdetails_lang SET Other_LcprepDetailsLangsIsActive = 'N' - WHERE - Other_LcprepDetailsLangsOther_LcprepID = ? AND - Other_LcprepDetailsLangsCode = ? AND - Other_LcprepDetailsLangsIsActive = 'Y'"; - $query = $this->db_smartone->query($sql, array($header_id, $v['code'])); - if(!$query){ - echo $this->db_smartone->last_query(); - exit; - } - //echo $this->db_smartone->last_query(); - $sql = "INSERT INTO other_lcprepdetails_lang ( - Other_LcprepDetailsLangsOther_LcprepID, - Other_LcprepDetailsLangsCode, - Other_LcprepDetailsLangsLabel, - Other_LcprepDetailsLangsResult, - Other_LcprepDetailsLangsCreatedUserID, - Other_LcprepDetailsLangsCreated - ) - VALUES( - ?, - ?, - ?, - ?, - ?, - NOW() - )"; - $query = $this->db_smartone->query($sql, array($header_id, $v['code'], $v['label'], $v['result'], $userid)); - if(!$query){ - echo $this->db_smartone->last_query(); - exit; - } - //echo $this->db_smartone->last_query(); - } - if (intval($v['xid'] != 0)) { - $sql = "UPDATE other_lcprepdetails_lang SET - Other_LcprepDetailsLangsCode = ?, - Other_LcprepDetailsLangsLabel = ?, - Other_LcprepDetailsLangsResult = ?, - Other_LcprepDetailsLangsUpdatedUserID = ?, - Other_LcprepDetailsLangsUpdated = NOW() - WHERE - Other_LcprepDetailsLangsID = ? - "; - $query = $this->db_smartone->query($sql, array($v['code'], $v['label'], $v['result'], $userid, $v['xid'])); - if(!$query){ - echo $this->db_smartone->last_query(); - exit; - } - } - //echo $sql; - } - } - - if ($interpretasi) { - foreach ($interpretasi as $k => $v) { - if (count($v['subgroups']) > 0) { - foreach ($v['subgroups'] as $ik => $iv) { - if (count($iv['childs']) > 0) { - foreach ($iv['childs'] as $iik => $iiv) { - if (intval($iiv['xid'] == 0)) { - $chex = $iiv['chex'] ? 'Y' : 'N'; - $sql = "UPDATE other_lcprepinterpretasi SET Other_LcprepInterpretasiIsActive = 'N' - WHERE - Other_LcprepInterpretasiOther_LcprepID = ? AND - Other_LcprepInterpretasiLcprep_InterpretasiID = ? AND - Other_LcprepInterpretasiIsActive = 'Y'"; - $query = $this->db_smartone->query($sql, array($header_id, $iiv['id'])); - if(!$query){ - echo $this->db_smartone->last_query(); - exit; - } - $sql = "INSERT INTO other_lcprepinterpretasi ( - Other_LcprepInterpretasiOther_LcprepID, - Other_LcprepInterpretasiLcprep_InterpretasiID, - Other_LcprepInterpretasiChex, - Other_LcprepInterpretasiValue, - Other_LcprepInterpretasiValueEng, - Other_LcprepInterpretasiUserID, - Other_LcprepInterpretasiCreated - ) - VALUES( - ?, - ?, - ?, - ?, - ?, - ?, - NOW() - )"; - $query = $this->db_smartone->query($sql, array($header_id, $iiv['id'], $chex, $iiv['value'], $iiv['value_en'], $userid)); - if(!$query){ - echo $this->db_smartone->last_query(); - exit; - } - } - - if (intval($iiv['xid'] != 0)) { - $chex = $iiv['chex'] ? 'Y' : 'N'; - $sql = "UPDATE other_lcprepinterpretasi SET - Other_LcprepInterpretasiChex = ?, - Other_LcprepInterpretasiValue = ?, - Other_LcprepInterpretasiValueEng = ?, - Other_LcprepInterpretasiUserID = ? - WHERE - Other_LcprepInterpretasiID = ? - "; - $query = $this->db_smartone->query($sql, array($chex, $iiv['value'], $iiv['value_en'], $userid, $iiv['xid'])); - if(!$query){ - echo $this->db_smartone->last_query(); - exit; - } - //echo $sql; - - } - } - } - } - } - //echo $sql; - } - } - - - $result = array("total" => 1, "records" => array(), "sql" => ''); - $this->sys_ok($result); - exit; - } - - function saveresult_papsmear() - { - $prm = $this->sys_input; - $detail_id = $prm['detail_id']; - $doctor_id = $prm['doctor']; - $checks = $prm['checks']; - $maturasi = $prm['maturasi']; - $bahans = $prm['bahans']; - $categories = $prm['categories']; - $results = $prm['results']; - - $userid = $this->sys_user['M_UserID']; - - $header_id = 0; - $sql = "SELECT * FROM other_papsmear WHERE Other_PapSmearT_OrderDetailID = {$detail_id} AND Other_PapSmearIsActive = 'Y'"; - $dt_header = $this->db_smartone->query($sql)->row_array(); - if ($dt_header) { - $header_id = $dt_header['Other_PapSmearID']; - } - if ($header_id == 0) { - $sql = "INSERT INTO other_papsmear( - Other_PapSmearT_OrderDetailID, - Other_PapSmearM_DoctorID, - Other_PapSmearUserID, - Other_PapSmearCreated - ) - VALUES( - {$detail_id}, - {$doctor_id}, - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } else { - $sql = "UPDATE other_papsmear SET Other_PapSmearM_DoctorID = {$doctor_id}, Other_PapSmearUserID = {$userid} WHERE Other_PapSmearID = {$header_id}"; - $this->db_smartone->query($sql); - } - - if ($checks) { - foreach ($checks as $k => $v) { - if (intval($v['xid']) == 0 && $v['selected'] === 'Y') { - $sql = "INSERT INTO other_papsmearcheck ( - Other_PapSmearCheckOther_PapSmearID, - Other_PapSmearCheckM_PapSmearCheckID, - Other_PapSmearCheckNote, - Other_PapSmearCheckUserID, - Other_PapSmearCheckCreated - ) - VALUES( - {$header_id}, - {$v['check_id']}, - '{$v['note']}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if (intval($v['xid']) != 0 && $v['selected'] === 'N') { - $sql = "UPDATE other_papsmearcheck SET - Other_PapSmearCheckIsActive = 'N', - Other_PapSmearCheckUserID = {$userid} - WHERE - Other_PapSmearCheckID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - if (intval($v['xid']) != 0 && $v['selected'] === 'Y') { - $sql = "UPDATE other_papsmearcheck SET - Other_PapSmearCheckNote = '{$v['note']}', - Other_PapSmearCheckUserID = {$userid} - WHERE - Other_PapSmearCheckID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - //echo $sql; - } - } - - if ($maturasi) { - if (intval($maturasi['xid']) == 0) { - $value = join("/", $maturasi['value']); - $sql = "INSERT INTO other_papsmearmaturasi ( - Other_PapSmearMaturasiOther_PapSmearID, - Other_PapSmearMaturasiValue, - Other_PapSmearMaturasiUserID, - Other_PapSmearMaturasiCreated - ) - VALUE( - {$header_id}, - '{$value}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - //echo $sql; - } - if (intval($maturasi['xid']) != 0) { - $value = join("/", $maturasi['value']); - $sql = "UPDATE other_papsmearmaturasi SET - Other_PapSmearMaturasiValue = '{$value}', - Other_PapSmearMaturasiUserID = {$userid} - WHERE - Other_PapSmearMaturasiID = {$maturasi['xid']}"; - // echo $sql; - $this->db_smartone->query($sql); - } - } - - if ($bahans) { - foreach ($bahans as $k => $v) { - if (intval($v['xid']) == 0 && $v['selected'] === 'Y') { - $sql = "INSERT INTO other_papsmearbahan ( - Other_PapSmearBahanOther_PapSmearID, - Other_PapSmearBahanM_PapSmearBahanID, - Other_PapSmearBahanUserID, - Other_PapSmearBahanCreated - ) - VALUES( - {$header_id}, - {$v['bahan_id']}, - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if (intval($v['xid']) != 0 && $v['selected'] === 'N') { - $sql = "UPDATE other_papsmearbahan SET - Other_PapSmearBahanIsActive = 'N', - Other_PapsmearCategoryUserID = {$userid} - WHERE - Other_PapSmearBahanID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - if (intval($v['xid']) != 0 && $v['selected'] === 'Y') { - $sql = "UPDATE other_papsmearbahan SET - Other_PapSmearBahanIsActive = 'Y', - Other_PapsmearCategoryUserID = {$userid} - WHERE - Other_PapSmearBahanID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - //echo $sql; - } - } - - if ($categories) { - foreach ($categories as $k => $v) { - if (intval($v['xid']) == 0 && $v['selected'] === 'Y') { - $sql = "INSERT INTO other_papsmearcategory ( - Other_PapsmearCategoryOther_PapSmearID, - Other_PapsmearCategoryM_PapSmearCategoryID, - Other_PapsmearCategoryUserID, - Other_PapsmearCategoryCreated - ) - VALUES( - {$header_id}, - {$v['category_id']}, - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if (intval($v['xid']) != 0 && $v['selected'] === 'N') { - $sql = "UPDATE other_papsmearcategory SET - Other_PapsmearCategoryIsActive = 'N', - Other_PapsmearCategoryUserID = {$userid} - WHERE - Other_PapsmearCategoryID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - //echo $sql; - if (intval($v['xid']) != 0 && $v['selected'] === 'Y') { - $sql = "UPDATE other_papsmearcategory SET - Other_PapsmearCategoryIsActive = 'Y', - Other_PapsmearCategoryUserID = {$userid} - WHERE - Other_PapsmearCategoryID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - } - } - - if ($results) { - foreach ($results as $k => $v) { - if (intval($v['xid']) == 0) { - $sql = "INSERT INTO other_papsmeardetails ( - Other_PapSmearDetailsOther_PapSmearID, - Other_PapSmearDetailsCode, - Other_PapSmearDetailsLabel, - Other_PapSmearDetailsResult, - Other_PapSmearDetailsUserID, - Other_PapSmearDetailsCreated - ) - VALUES( - {$header_id}, - '{$v['code']}', - '{$v['label']}', - '{$v['result']}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if (intval($v['xid']) != 0) { - $sql = "UPDATE other_papsmeardetails SET - Other_PapSmearDetailsCode = '{$v['code']}', - Other_PapSmearDetailsLabel = '{$v['label']}', - Other_PapSmearDetailsResult = '{$v['result']}', - Other_PapSmearDetailsUserID = {$userid} - WHERE - Other_PapSmearDetailsID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - //echo $sql; - } - } - - $result = array("total" => 1, "records" => array(), "sql" => ''); - $this->sys_ok($result); - exit; - } - - function saveresult_fna() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = $inp['doctor']; - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - if ($prm[0]['xid'] == '0') { - $sql = "INSERT INTO other_fna( - Other_FNAM_DoctorID, - Other_FNAT_OrderDetailID, - Other_FNAUserID, - Other_FNACreated - ) - VALUES( - {$doctor_id}, - {$prm[0]['orderdetail_id']}, - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } else { - $sql = "SELECT * FROM other_fna WHERE Other_FNAT_OrderDetailID = {$prm[0]['orderdetail_id']} AND Other_FNAIsActive = 'Y'"; - $data_header = $this->db_smartone->query($sql)->row_array(); - $header_id = $data_header['Other_FNAID']; - $sql = "UPDATE other_fna SET - Other_FNAM_DoctorID = {$doctor_id}, - Other_FNAUserID = {$userid} - WHERE - Other_FNAID = {$header_id}"; - $this->db_smartone->query($sql); - } - foreach ($prm as $k => $v) { - if ($v['xid'] == '0') { - $results = str_replace("'", "\\'", $v['result']); - $sql = "INSERT INTO other_fnadetails( - Other_FNADetailsOther_FNAID , - Other_FNADetailsCode, - Other_FNADetailsLabel, - Other_FNADetailsResult, - Other_FNADetailsCreated, - Other_FNADetailsUserID - ) - VALUES( - {$header_id}, - '{$v['code']}', - '{$v['label']}', - '{$results}', - NOW(), - {$userid} - )"; - $query = $this->db_smartone->query($sql); - } else { - $results = str_replace("'", "\\'", $v['result']); - $sql = "UPDATE other_fnadetails SET - Other_FNADetailsResult = '{$results}', - Other_FNADetailsUserID = {$userid} - WHERE - Other_FNADetailsID = {$v['xid']}"; - $query = $this->db_smartone->query($sql); - } - } - - $result = array("total" => 1, "records" => array(), "sql" => ''); - $this->sys_ok($result); - exit; - } - - function saveresult_patologianatomy() - { - - $inp = $this->sys_input; - $doctor_id = $inp['doctor']; - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - if ($inp['xid'] == '0') { - $sql = "INSERT INTO other_patologi_anatomy( - Other_PatologiAnatomyT_OrderDetailID, - Other_PatologiAnatomyM_DoctorID, - Other_PatologiAnatomyNoSediaan, - Other_PatologiAnatomyDiagnosaKlinis, - Other_PatologiAnatomyKeteranganKlinis, - Other_PatologiAnatomyLokasiOrgan, - Other_PatologiAnatomyMakroskopik, - Other_PatologiAnatomyMikroskopik, - Other_PatologiAnatomyKesimpulan, - Other_PatologiAnatomyUserID, - Other_PatologiAnatomyCreated - ) - VALUES( - {$inp['detail_id']}, - {$doctor_id}, - '{$inp['no_sediaan']}', - '{$inp['diagnosa']}', - '{$inp['klinis']}', - '{$inp['lokasi']}', - '{$inp['makroskopik']}', - '{$inp['mikroskopik']}', - '{$inp['kesimpulan']}', - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } else { - $sql = "UPDATE other_patologi_anatomy SET - Other_PatologiAnatomyM_DoctorID = ?, - Other_PatologiAnatomyNoSediaan = ?, - Other_PatologiAnatomyKeteranganKlinis = ?, - Other_PatologiAnatomyDiagnosaKlinis = ?, - Other_PatologiAnatomyLokasiOrgan = ?, - Other_PatologiAnatomyMakroskopik = ?, - Other_PatologiAnatomyMikroskopik = ?, - Other_PatologiAnatomyKesimpulan = ?, - Other_PatologiAnatomyUserID = ? - WHERE - Other_PatologiAnatomyT_OrderDetailID = ? AND Other_PatologiAnatomyIsActive = 'Y'"; - $this->db_smartone->query($sql, array( - $doctor_id, - $inp['no_sediaan'], - $inp['klinis'], - $inp['diagnosa'], - $inp['lokasi'], - $inp['makroskopik'], - $inp['mikroskopik'], - $inp['kesimpulan'], - $userid, - $inp['detail_id'] - )); - //echo $this->db_smartone->last_query(); - - } - - $inp_rst = array( - 'doctor_id' => $doctor_id, - 'no_sediaan' => $inp['no_sediaan'], - 'klinis' => $inp['klinis'], - 'diagnosa' => $inp['diagnosa'], - 'lokasi' => $inp['lokasi'], - 'makroskopik' => $inp['makroskopik'], - 'mikroskopik' => $inp['mikroskopik'], - 'kesimpulan' => $inp['kesimpulan'] - ); - $log_json = json_encode($inp_rst); - - $sql = "INSERT INTO log_other_patologianatomy ( - Log_OtherPatologiAnatomyT_OrderDetailID, - Log_OtherPatologiAnatomyDateTime, - Log_OtherPatologiAnatomySON, - Log_OtherPatologiAnatomyUserID - )VALUE( - {$inp['detail_id']}, - NOW(), - '{$log_json}', - {$userid} - )"; - $this->db_smartone->query($sql); - //echo $this->db_smartone->last_query(); - - $result = array("total" => 1, "records" => array(), "sql" => ''); - $this->sys_ok($result); - exit; - } - - function saveresult_cytologi() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = $inp['doctor']; - - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - if ($prm[0]['xid'] == '0') { - $sql = "INSERT INTO other_cytologi( - Other_CytologiT_OrderDetailID, - Other_CytologiM_DoctorID, - Other_CytologiUserID, - Other_CytologiCreated - ) - VALUES( - {$prm[0]['orderdetail_id']}, - {$doctor_id}, - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } else { - $sql = "SELECT * FROM other_cytologi WHERE Other_CytologiT_OrderDetailID = {$prm[0]['orderdetail_id']} AND Other_CytologiIsActive = 'Y'"; - $data_header = $this->db_smartone->query($sql)->row_array(); - $header_id = $data_header['Other_CytologiID']; - $sql = "UPDATE other_cytologi SET - Other_CytologiM_DoctorID = {$doctor_id}, - Other_CytologiUserID = {$userid} - WHERE - Other_CytologiID = {$header_id}"; - $this->db_smartone->query($sql); - } - foreach ($prm as $k => $v) { - if ($v['xid'] == '0') { - $results = str_replace("'", "\\'", $v['result']); - $sql = "INSERT INTO other_cytologidetails( - Other_CytologiDetailsOther_CytologiID , - Other_CytologiDetailsCode, - Other_CytologiDetailsLabel, - Other_CytologiDetailsResult, - Other_CytologiDetailsCreated, - Other_CytologiDetailsUserID - ) - VALUES( - {$header_id}, - '{$v['code']}', - '{$v['label']}', - '{$results}', - NOW(), - {$userid} - )"; - $query = $this->db_smartone->query($sql); - } else { - $results = str_replace("'", "\\'", $v['result']); - $sql = "UPDATE other_cytologidetails SET - Other_CytologiDetailsResult = '{$results}', - Other_CytologiDetailsUserID = {$userid} - WHERE - Other_CytologiDetailsID = {$v['xid']}"; - $query = $this->db_smartone->query($sql); - } - } - - $result = array("total" => 1, "records" => array(), "sql" => ''); - $this->sys_ok($result); - exit; - } - - function saveresult_mikro() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = $inp['doctor']; - $backteria_id = $inp['bacteria']; - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - - if ($inp['result_value'] != 'Negatif' && $inp['result_value'] != 'Positif') { - $prm['result_value'] = $prm['result_other']; - } else { - $prm['result_value'] = $inp['result_value']; - } - - if ($prm['xid'] == '0') { - $sql = "INSERT INTO other_mikro( - Other_MikroM_DoctorID, - Other_MikroResult, - Other_MikroT_BacteriaID, - Other_MikroT_OrderDetailID, - Other_MikroHasilBiakan, - Other_MikroSampleTypeName, - Other_MikroUserID, - Other_MikroCreated - ) - VALUES( - {$doctor_id}, - '{$prm['result_value']}', - {$backteria_id}, - {$prm['orderdetail_id']}, - '{$prm['hasil_biakan']}', - '{$prm['sample_name']}', - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } else { - $sql = "SELECT * FROM other_mikro WHERE Other_MikroT_OrderDetailID = {$prm['orderdetail_id']} AND Other_MikroIsActive = 'Y'"; - $data_header = $this->db_smartone->query($sql)->row_array(); - $header_id = $data_header['Other_MikroID']; - $sql = "UPDATE other_mikro SET - Other_MikroResult = '{$prm['result_value']}', - Other_MikroM_DoctorID = {$doctor_id}, - Other_MikroT_BacteriaID = {$backteria_id}, - Other_MikroHasilBiakan = '{$prm['hasil_biakan']}', - Other_MikroSampleTypeName = '{$prm['sample_name']}', - Other_MikroUserID = {$userid} - WHERE - Other_MikroID = {$header_id}"; - //echo $sql; - $this->db_smartone->query($sql); - } - - - - $sql = "UPDATE other_mikrodetails SET Other_MikroDetailsIsActive = 'N', Other_MikroDetailsUserID = 0 WHERE Other_MikroDetailsOther_MikroID = {$header_id}"; - $this->db_smartone->query($sql); - - $results = $prm['details']; - if ($inp['result_value'] == 'Positif') { - foreach ($results as $k => $v) { - if ($v['xid'] == '0') { - $sql = "INSERT INTO other_mikrodetails( - Other_MikroDetailsOther_MikroID , - Other_MikroDetailsT_AntibioticID, - Other_MikroDetailsValue, - Other_MikroDetailsNote, - Other_MikroDetailsCreated, - Other_MikroDetailsUserID - ) - VALUES( - {$header_id}, - '{$v['T_AntibioticID']}', - '{$v['value']}', - '{$v['note']}', - NOW(), - {$userid} - )"; - $query = $this->db_smartone->query($sql); - } else { - $sql = "UPDATE other_mikrodetails SET - Other_MikroDetailsT_AntibioticID = '{$v['T_AntibioticID']}', - Other_MikroDetailsValue = '{$v['value']}', - Other_MikroDetailsNote = '{$v['note']}', - Other_MikroDetailsIsActive = 'Y', - Other_MikroDetailsUserID = {$userid} - WHERE - Other_MikroDetailsID = {$v['xid']}"; - //echo $sql; - $query = $this->db_smartone->query($sql); - } - } - } - - - $result = array("total" => 1, "records" => array(), "sql" => ''); - $this->sys_ok($result); - exit; - } - - - function get_doctors_preparasi_sperma() - { - $prm = $this->sys_input; - // $id = $prm["id"]; - - $sql = " SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 10 AND - M_DoctorSOIsActive = 'Y' - ORDER BY M_DoctorName ASC"; - //echo $sql; - $query = $this->db_smartone->query($sql); - $rows = $query->result_array(); - $sql = " - SELECT '0' as id, 'Belum memilih metode' as name - UNION - SELECT M_MethodeSpermaID as id, M_MethodeSpermaName as name - FROM m_methodesperma - WHERE - M_MethodeSpermaIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $methodes = $this->db_smartone->query($sql)->result_array(); - - - $this->sys_ok(["records" => $rows, "methodes" => $methodes]); - } - - - function getpreparasispermaresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT other_preparasisperma.*, - Other_PreparasiSpermaID as xid, - Other_PreparasiSpermaT_OrderDetailID as orderdetail_id, - IFNULL(Other_PreparasiSpermaM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_PreparasiSpermaM_DoctorID) OR Other_PreparasiSpermaM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name, - IFNULL(M_MethodeSpermaID,0) as methode_id, - IFNULL(M_MethodeSpermaName,'') as methode_name - FROM other_preparasisperma - LEFT JOIN m_doctor ON Other_PreparasiSpermaM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - LEFT JOIN m_methodesperma ON Other_PreparasiSpermaM_MethodeSpermaID = M_MethodeSpermaID AND - M_MethodeSpermaIsActive = 'Y' - WHERE - Other_PreparasiSpermaT_OrderDetailID = {$id} AND Other_PreparasiSpermaIsActive = 'Y' - GROUP BY Other_PreparasiSpermaID"; - $query = $this->db_smartone->query($sql); - - if ($query) { - $rows = $query->row_array(); - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 10 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $sql = " - SELECT '0' as id, 'Belum memilih metode' as name - UNION - SELECT M_MethodeSpermaID as id, M_MethodeSpermaName as name - FROM m_methodesperma - WHERE - M_MethodeSpermaIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $methodes = $this->db_smartone->query($sql)->result_array(); - $images = array(); - $sql = "SELECT Other_PreparasiSpermaImgID as xid, - Other_PreparasiSpermaImgType as type, - CONCAT('/one-media/one-image-nonlab/',Other_PreparasiSpermaImgNewName) as image_url - FROM t_orderdetail - JOIN other_preparasisperma_img ON Other_PreparasiSpermaImgT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND - Other_PreparasiSpermaImgIsActive = 'Y' - WHERE - T_OrderDetailID = {$id} AND - T_OrderDetailIsActive = 'Y' - GROUP BY Other_PreparasiSpermaImgID"; - //echo $sql; - $images = $this->db_smartone->query($sql)->result_array(); - - $rst = array('doctors' => $doctors, 'methodes' => $methodes, 'results' => $rows, 'images' => $images); - $this->sys_ok(["records" => $rst]); - } else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - - function uploadimage_preparasi_sperma() - { - if (! $this->isLogin) { - $this->sys_error("Invalid Token"); - exit; - } - - $userid = $this->sys_user["M_UserID"]; - $data = []; - //print_r($_SERVER); - - $prm = $this->sys_input; - $orderid = $this->input->post('orderid'); - $type = $this->input->post('type'); - $labnumber = $this->input->post('labnumber'); - $sql = "UPDATE other_preparasisperma_img SET - Other_PreparasiSpermaImgIsActive = 'N', - Other_PreparasiSpermaImgUserID = {$userid} - WHERE - Other_PreparasiSpermaImgT_OrderHeaderID = {$orderid} AND - Other_PreparasiSpermaImgType = '{$type}'"; - //echo $sql; - $this->db_onedev->query($sql); - //$config['upload_path'] = 'assets/'; - - $path = '/home/one/project/one/one-media/one-image-nonlab/'; - //echo $path; - $config['upload_path'] = $path; - $config['allowed_types'] = 'jpg|jpeg|png|gif'; - - $config['max_size'] = '10000'; - $count = count($_FILES['files']['name']); - //echo $count; - $this->load->library('upload', $config); - - $error = []; - for ($i = 0; $i < $count; $i++) { - - - if (!empty($_FILES['files']['name'][$i])) { - - - - $_FILES['file']['name'] = $_FILES['files']['name'][$i]; - - $_FILES['file']['type'] = $_FILES['files']['type'][$i]; - - $_FILES['file']['tmp_name'] = $_FILES['files']['tmp_name'][$i]; - - $_FILES['file']['error'] = $_FILES['files']['error'][$i]; - - $_FILES['file']['size'] = $_FILES['files']['size'][$i]; - - - - $namex = $orderid . '-' . $labnumber . '-' . $this->generateRandomString(5); - //echo $namex; - - $config['file_name'] = $namex; - $this->upload->initialize($config); - //echo $config['file_name'] ; - - - - - - if ($this->upload->do_upload('file')) { - - $uploadData = $this->upload->data(); - - $filename = $uploadData['file_name']; - //echo $filename; - - - $sql = "INSERT INTO other_preparasisperma_img ( - Other_PreparasiSpermaImgT_OrderHeaderID, - Other_PreparasiSpermaImgType, - Other_PreparasiSpermaImgOldName, - Other_PreparasiSpermaImgNewName, - Other_PreparasiSpermaImgCreated, - Other_PreparasiSpermaImgUserID - ) - VALUES( - {$orderid}, - '{$type}', - '{$_FILES['files']['name'][$i]}', - '{$filename}', - NOW(), - {$userid} - - )"; - //echo $sql; - $this->db_onedev->query($sql); - $xlast_id = $this->db_onedev->insert_id(); - $data['totalFiles'][] = array('xid' => $xlast_id, 'type' => $type, 'image_url' => '/one-media/one-image-nonlab/' . $filename); - } else { - $error = array('error' => $this->upload->display_errors()); - } - } - } - - $result = array("total" => count($data['totalFiles']), "records" => $data['totalFiles'], 'errors' => $error); - $this->sys_ok($result); - } - - - function saveresult_preparasi_sperma() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = isset($inp['doctor']) ? $inp['doctor'] : 0; - $methode_id = isset($inp['methode']) ? $inp['methode'] : 0; - $orderdetail_id = $inp['orderdetailid']; - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - if ($prm['xid'] == '0') { - $sql = "INSERT INTO other_preparasisperma( - Other_PreparasiSpermaM_DoctorID, - Other_PreparasiSpermaT_OrderDetailID, - Other_PreparasiSpermaPreMotilitasA, - Other_PreparasiSpermaPreMotilitasB, - Other_PreparasiSpermaPreMotilitasC, - Other_PreparasiSpermaPreKonsentrasi, - Other_PreparasiSpermaPreKontaminan, - Other_PreparasiSpermaPostMotilitasA, - Other_PreparasiSpermaPostMotilitasB, - Other_PreparasiSpermaPostMotilitasC, - Other_PreparasiSpermaPostKonsentrasi, - Other_PreparasiSpermaPostKontaminan, - Other_PreparasiSpermaPreVolume, - Other_PreparasiSpermaPostVolume, - Other_PreparasiSpermaM_MethodeSpermaID, - Other_PreparasiSpermaNote, - Other_PreparasiSpermaUserID, - Other_PreparasiSpermaCreated - ) - VALUES( - {$doctor_id}, - {$orderdetail_id}, - '{$prm['Other_PreparasiSpermaPreMotilitasA']}', - '{$prm['Other_PreparasiSpermaPreMotilitasB']}', - '{$prm['Other_PreparasiSpermaPreMotilitasC']}', - '{$prm['Other_PreparasiSpermaPreKonsentrasi']}', - '{$prm['Other_PreparasiSpermaPreKontaminan']}', - '{$prm['Other_PreparasiSpermaPostMotilitasA']}', - '{$prm['Other_PreparasiSpermaPostMotilitasB']}', - '{$prm['Other_PreparasiSpermaPostMotilitasC']}', - '{$prm['Other_PreparasiSpermaPostKonsentrasi']}', - '{$prm['Other_PreparasiSpermaPostKontaminan']}', - '{$prm['Other_PreparasiSpermaPreVolume']}', - '{$prm['Other_PreparasiSpermaPostVolume']}', - '{$methode_id}', - '{$prm['Other_PreparasiSpermaNote']}', - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } else { - $sql = "SELECT * FROM other_preparasisperma WHERE Other_PreparasiSpermaT_OrderDetailID = {$orderdetail_id} AND Other_PreparasiSpermaIsActive = 'Y'"; - $data_header = $this->db_smartone->query($sql)->row_array(); - $header_id = $data_header['Other_PreparasiSpermaID']; - $sql = "UPDATE other_preparasisperma SET - Other_PreparasiSpermaM_DoctorID = {$doctor_id}, - Other_PreparasiSpermaPreMotilitasA = '{$prm['Other_PreparasiSpermaPreMotilitasA']}', - Other_PreparasiSpermaPreMotilitasB = '{$prm['Other_PreparasiSpermaPreMotilitasB']}', - Other_PreparasiSpermaPreMotilitasC = '{$prm['Other_PreparasiSpermaPreMotilitasC']}', - Other_PreparasiSpermaPreKonsentrasi = '{$prm['Other_PreparasiSpermaPreKonsentrasi']}', - Other_PreparasiSpermaPreKontaminan = '{$prm['Other_PreparasiSpermaPreKontaminan']}', - Other_PreparasiSpermaPostMotilitasA = '{$prm['Other_PreparasiSpermaPostMotilitasA']}', - Other_PreparasiSpermaPostMotilitasB = '{$prm['Other_PreparasiSpermaPostMotilitasB']}', - Other_PreparasiSpermaPostMotilitasC = '{$prm['Other_PreparasiSpermaPostMotilitasC']}', - Other_PreparasiSpermaPostKonsentrasi = '{$prm['Other_PreparasiSpermaPostKonsentrasi']}', - Other_PreparasiSpermaPostKontaminan = '{$prm['Other_PreparasiSpermaPostKontaminan']}', - Other_PreparasiSpermaPreVolume = '{$prm['Other_PreparasiSpermaPreVolume']}', - Other_PreparasiSpermaPostVolume = '{$prm['Other_PreparasiSpermaPostVolume']}', - Other_PreparasiSpermaM_MethodeSpermaID = '{$methode_id}', - Other_PreparasiSpermaNote = '{$prm['Other_PreparasiSpermaNote']}', - Other_PreparasiSpermaUserID = {$userid} - WHERE - Other_PreparasiSpermaID = {$header_id}"; - $this->db_smartone->query($sql); - } - - - $result = array("total" => 1, "records" => array(), "sql" => ''); - $this->sys_ok($result); - exit; - } - - function getdnafragmentasiresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT other_dnafragmentasi.*, - Other_DnaFragmentasiID as xid, - Other_DnaFragmentasiT_OrderDetailID as orderdetail_id, - IFNULL(Other_DnaFragmentasiM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_DnaFragmentasiM_DoctorID) OR Other_DnaFragmentasiM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name, - IFNULL(Other_DnaFragmentasiOther_DnaFragmentasiMethodeID,0) as methode_id, - IFNULL(Other_DnaFragmentasiMethodeName,'') as methode_name, - Other_DnaFragmentasiHaloLuas as halo_luas, - Other_DnaFragmentasiHaloSedang as halo_sedang, - Other_DnaFragmentasiHaloSempit as halo_sempit, - Other_DnaFragmentasiTanpaHalo as tanpa_halo, - Other_DnaFragmentasiDFI as dfi, - Other_DnaFragmentasiKesimpulan as kesimpulan, - Other_DnaFragmentasiCatatan as catatan - FROM other_dnafragmentasi - LEFT JOIN m_doctor ON Other_DnaFragmentasiM_DoctorID = M_DoctorID - LEFT JOIN other_dnafragmentasimethode ON Other_DnaFragmentasiOther_DnaFragmentasiMethodeID = Other_DnaFragmentasiMethodeID - WHERE - Other_DnaFragmentasiT_OrderDetailID = {$id} AND Other_DnaFragmentasiIsActive = 'Y' - GROUP BY Other_DnaFragmentasiID - LIMIT 1"; - //echo $sql; - $query = $this->db_smartone->query($sql); - - if ($query) { - $rows = $query->row_array(); - if (!$rows) { - $rows = array( - 'xid' => 0, - 'orderdetail_id' => $id, - 'doctor_id' => 0, - 'doctor_name' => '', - 'methode_id' => 0, - 'methode_name' => '', - 'halo_luas' => '', - 'halo_sedang' => '', - 'tanpa_halo' => '', - 'dfi' => '', - 'kesimpulan' => '', - 'catatan' => '' - ); - } - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID - WHERE - M_DoctorSONat_SubGroupID = 4 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - - $sql = " - SELECT '0' as id, 'Belum memilih metode' as name - UNION - SELECT Other_DnaFragmentasiMethodeID as id, Other_DnaFragmentasiMethodeName as name - FROM other_dnafragmentasimethode - WHERE - Other_DnaFragmentasiMethodeIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $methodes = $this->db_smartone->query($sql)->result_array(); - - - $rst = array('doctors' => $doctors, 'methodes' => $methodes, 'results' => $rows); - $this->sys_ok(["records" => $rst]); - } else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - function saveresult_dnafragmentasi() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = $inp['doctor']['id']; - $methode_id = $inp['methode']['id']; - $orderdetail_id = $inp['results']['orderdetail_id']; - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - if (intval($prm['xid']) == 0) { - $sql = "INSERT INTO other_dnafragmentasi( - Other_DnaFragmentasiT_OrderDetailID, - Other_DnaFragmentasiM_DoctorID, - Other_DnaFragmentasiOther_DnaFragmentasiMethodeID, - Other_DnaFragmentasiHaloLuas, - Other_DnaFragmentasiHaloSedang, - Other_DnaFragmentasiHaloSempit, - Other_DnaFragmentasiTanpaHalo, - Other_DnaFragmentasiDFI, - Other_DnaFragmentasiKesimpulan, - Other_DnaFragmentasiCatatan, - Other_DnaFragmentasiUserID, - Other_DnaFragmentasiLastUpdated - ) - VALUES( - {$orderdetail_id}, - {$doctor_id}, - {$methode_id}, - '{$prm['halo_luas']}', - '{$prm['halo_sedang']}', - '{$prm['halo_sempit']}', - '{$prm['tanpa_halo']}', - '{$prm['dfi']}', - '{$prm['kesimpulan']}', - '{$prm['catatan']}', - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } else { - $sql = "UPDATE other_dnafragmentasi SET - Other_DnaFragmentasiT_OrderDetailID = {$orderdetail_id}, - Other_DnaFragmentasiM_DoctorID = {$doctor_id}, - Other_DnaFragmentasiOther_DnaFragmentasiMethodeID = '{$methode_id}', - Other_DnaFragmentasiHaloLuas = '{$prm['halo_luas']}', - Other_DnaFragmentasiHaloSedang = '{$prm['halo_sedang']}', - Other_DnaFragmentasiHaloSempit = '{$prm['halo_sempit']}', - Other_DnaFragmentasiTanpaHalo = '{$prm['tanpa_halo']}', - Other_DnaFragmentasiDFI = '{$prm['dfi']}', - Other_DnaFragmentasiKesimpulan = '{$prm['kesimpulan']}', - Other_DnaFragmentasiCatatan = '{$prm['catatan']}', - Other_DnaFragmentasiLastUpdated = NOW(), - Other_DnaFragmentasiUserID = {$userid} - WHERE - Other_DnaFragmentasiID = {$prm['xid']}"; - //echo $sql; - $this->db_smartone->query($sql); - } - - - $result = array("total" => 1, "records" => array(), "sql" => ''); - $this->sys_ok($result); - exit; - } -} +db_smartone = $this->load->database("onedev", true); + $this->db_lab = $this->load->database('one_lab_log', TRUE); + $this->load->helper(array('form', 'url')); + } + function getMethodeID($natTestID) + { + $sql = "select M_MethodePriorityNat_MethodeID MethodeID, Nat_MethodeName + from + m_methode_priority + join nat_methode on Nat_MethodeID = M_MethodePriorityNat_MethodeID + and Nat_MethodeIsActive = 'Y' + join m_instrumentmethode on M_InstrumentMethodeNat_MethodeID = Nat_MethodeID and M_InstrumentMethodeIsActive = 'Y' + join nat_instrument on M_InstrumentMethodeNat_InstrumentID = Nat_InstrumentID + and Nat_InstrumentIsActive ='Y' + where M_MethodePriorityIsActive = 'Y' + and M_MethodePriorityNat_TestID = $natTestID + and M_MethodePriorityM_DayOfWeekID = dayofweek(now()) + order by M_MethodePriorityNumber desc + limit 0,1 "; + $qry = $this->db->query($sql); + if ($qry) { + $rows = $qry->result_array(); + if (count($rows) > 0) return array($rows[0]["MethodeID"], $rows[0]["Nat_MethodeName"]); + } + //2nd + $sql = "select + M_InstrumentMethodeNat_MethodeID MethodeID, Nat_MethodeName + from m_instrumentmethode + join nat_methode on M_InstrumentMethodeNat_MethodeID = Nat_MethodeID + and Nat_MethodeIsActive = 'Y' + join nat_instrument on M_InstrumentMethodeNat_InstrumentID = Nat_InstrumentID + and Nat_InstrumentIsActive ='Y' + where M_InstrumentMethodeNat_TestID = $natTestID + and M_InstrumentMethodeIsActive = 'Y' + order by M_InstrumentMethodePriority desc + limit 0,1"; + $qry = $this->db->query($sql); + if ($qry) { + $rows = $qry->result_array(); + if (count($rows) > 0) return array($rows[0]["MethodeID"], $rows[0]["Nat_MethodeName"]); + } + // + $sql = "select Nat_NormalValueNat_MethodeID MethodeID, Nat_MethodeName + from + nat_normalvalue + join nat_methode on Nat_NormalValueNat_MethodeID = Nat_MethodeID + and Nat_MethodeIsActive = 'Y' + where Nat_NormalValueNat_TestID = $natTestID + and Nat_NormalValueIsActive = 'Y' + order by Nat_NormalValueID + limit 0,1"; + $qry = $this->db->query($sql); + if ($qry) { + $rows = $qry->result_array(); + if (count($rows) > 0) return array($rows[0]["MethodeID"], $rows[0]["Nat_MethodeName"]); + } + return array(0, ""); + } + function get_normal_value($methodeID, $natTestID, $sexID, $ageInDay) + { + $this->load->library('ibl_sampling_normal'); + return $this->ibl_sampling_normal->get_normal_value_id($methodeID, $natTestID, $sexID, $ageInDay); + } + return 0; + } + function fn_fix_normal($order_id) + { + $sql = "select + T_OrderDetailID, M_PatientM_SexID, fn_global_age_count_day(M_PatientDOB, date(T_OrderHeaderDate)) Dob , + T_TestNat_TestID + from t_orderheader + join m_patient on T_OrderHeaderID = $order_id and T_OrderHeaderM_PatientID = M_PatientID + join t_orderdetail on T_OrderDetailT_OrderHeaderID = T_OrderHeaderID + and T_OrderDetailIsACtive = 'Y' + and ( T_OrderDetailNat_NormalValueID is null or T_OrderDetailNat_NormalValueID = 0 ) + join t_test on T_OrderDetailT_TestID = T_TestID and T_TestIsResult = 'Y' "; + $qry = $this->db->query($sql); + if (! $qry) { + return; + } + $rows = $qry->result_array(); + if (count($rows) == 0) return; + $sql_u = "update t_orderdetail + join nat_normalvalue on T_OrderDetailID = ? and Nat_NormalValueID = ? + set + T_OrderDetailNat_NormalValueID = Nat_NormalValueID, + T_OrderDetailNormalValueNote = Nat_NormalValueNote, + T_OrderDetailNormalValueDescription = Nat_NormalValueDescription, + T_OrderDetailMinValue = Nat_NormalValueMinValue, + T_OrderDetailMaxValue = Nat_NormalValueMaxValue, + T_OrderDetailMinValueInclusive = Nat_NormalValueMinValueInclusive, + T_OrderDetailMaxValueInclusive = Nat_NormalValueMaxValueInclusive, + T_OrderDetailNat_MethodeID = ?, + T_OrderdetailNat_MethodeName =?"; + + foreach ($rows as $r) { + $T_OrderDetailID = $r["T_OrderDetailID"]; + $sexID = $r["M_PatientM_SexID"]; + $ageInDay = $r["Dob"]; + $natTestID = $r["T_TestNat_TestID"]; + list($methodeID, $methodeName) = $this->getMethodeID($natTestID); + if ($methodeID == 0) continue; + $normalValueID = $this->get_normal_value($methodeID, $natTestID, $sexID, $ageInDay); + if ($normalValueID == 0) return; + $this->db->query($sql_u, array($T_OrderDetailID, $normalValueID, $methodeID, $methodeName)); + } + } + function update_order_sample($targetID, $sourceID) + { + $sql = "update t_ordersample target + join t_ordersample source on + target.T_OrderSampleID = ? + and target.T_OrderSampleWorklistReceive = 'N' + and source.T_OrderSampleID = ? + set + target.T_OrderSampleSampling = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSampling, source.T_OrderSampleSampling), + target.T_OrderSampleSamplingDate = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingDate, source.T_OrderSampleSamplingDate), + target.T_OrderSampleSamplingTime = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingTime, source.T_OrderSampleSamplingTime), + target.T_OrderSampleSamplingUserID = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingUserID, source.T_OrderSampleSamplingUserID), + + target.T_OrderSampleReceive = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceive, source.T_OrderSampleReceive), + target.T_OrderSampleReceiveDate = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveDate, source.T_OrderSampleReceiveDate), + target.T_OrderSampleReceiveTime = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveTime, source.T_OrderSampleReceiveTime), + target.T_OrderSampleReceiveUserID = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveUserID, source.T_OrderSampleReceiveUserID), + + target.T_OrderSampleVerification = if(target.T_OrderSampleVerification='Y',target.T_OrderSampleVerification, source.T_OrderSampleVerification), + target.T_OrderSampleVerificationDate =if(target.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationDate, source.T_OrderSampleVerificationDate), + target.T_OrderSampleVerificationTime =if(source.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationTime, source.T_OrderSampleVerificationTime), + target.T_OrderSampleVerificationUserID =if(source.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationUserID, source.T_OrderSampleVerificationUserID), + + target.T_OrderSampleProcessing = if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessing, source.T_OrderSampleProcessing), + target.T_OrderSampleProcessingDate= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingDate, source.T_OrderSampleProcessingDate), + target.T_OrderSampleProcessingTime= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingTime, source.T_OrderSampleProcessingTime), + target.T_OrderSampleProcessingUserID= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingUserID, source.T_OrderSampleProcessingUserID), + + target.T_OrderSampleReceiveHandling =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandling, source.T_OrderSampleReceiveHandling ), + target.T_OrderSampleReceiveHandlingDate =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingDate, source.T_OrderSampleReceiveHandlingDate), + target.T_OrderSampleReceiveHandlingTime =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingTime, source.T_OrderSampleReceiveHandlingTime), + target.T_OrderSampleReceiveHandlingUserID =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingUserID, source.T_OrderSampleReceiveHandlingUserID), + + target.T_OrderSampleHandling = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandling, source.T_OrderSampleHandling), + target.T_OrderSampleHandlingDate = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingDate, source.T_OrderSampleHandlingDate), + target.T_OrderSampleHandlingTime = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingTime, source.T_OrderSampleHandlingTime), + target.T_OrderSampleHandlingUserID = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingUserID, source.T_OrderSampleHandlingUserID), + + target.T_OrderSampleWorklistReceive = source.T_OrderSampleWorklistReceive, + target.T_OrderSampleWorklistReceiveDatetime = source.T_OrderSampleWorklistReceiveDateTime, + target.T_OrderSampleWorklistReceiveUserID = source.T_OrderSampleWorklistReceiveUserID + "; + $qry = $this->db->query($sql, array($targetID, $sourceID)); + if (! $qry) { + echo json_encode(array("status" => "ERR", "message" => print_r($this->db->error(), true))); + exit; + } + } + function fix_sample_serum($headerID) + { + //cari t_ordersample yg belum worklist receive dengan code 017% + $sql = "select T_OrderSampleID + from t_ordersample + join t_sampletype on + T_OrderSampleT_OrderHeaderID = ? + and T_OrderSampleWorklistReceive = 'N' + and T_OrderSampleIsActive = 'Y' + and T_OrderSampleT_SampleTypeID = T_SampletypeID + and T_SampleTypeCode like '017%' + "; + $qry = $this->db->query($sql, array($headerID)); + if (!$qry) { + echo json_encode(array("status" => "ERR", "message" => print_r($this->db->error(), true))); + exit; + } + $rows = $qry->result_array(); + if (count($rows) == 0) return; + //cari T_OrderSample yang sudah di receive yg terakhir + $sql = "select T_OrderSampleID + from t_ordersample + join t_sampletype on + T_OrderSampleT_OrderHeaderID = ? + and T_OrderSampleWorklistReceive = 'Y' + and T_OrderSampleIsActive = 'Y' + and T_OrderSampleT_SampleTypeID = T_SampletypeID + and T_SampleTypeCode like '017%' + order by T_OrderSampleWorklistReceiveDatetime desc + limit 0,1 + "; + $qry = $this->db->query($sql, array($headerID)); + if (!$qry) { + echo json_encode(array("status" => "ERR", "message" => print_r($this->db->error(), true))); + exit; + } + $rcv_rows = $qry->result_array(); + if (count($rcv_rows) == 0) return; + + //print_r($rows); + //print_r($rcv_rows); + $rcv_T_OrderSampleID = $rcv_rows[0]["T_OrderSampleID"]; + //ada yg belum di receive + foreach ($rows as $r) { + $T_OrderSampleID = $r["T_OrderSampleID"]; + $this->update_order_sample($T_OrderSampleID, $rcv_T_OrderSampleID); + } + } + public function search() + { + $prm = $this->sys_input; + $max_rst = 99; + + $id = $prm["order_id"]; + if ($id > 0) { + $this->fix_sample_serum($id); + $this->fn_fix_normal($id); + } + $lang = $this->lang_default_code; + $lang_id = isset($prm['lang_id']) ? $prm['lang_id'] : '0'; + + if ($lang_id != 0) { + $l = $this->db_smartone->where("Nat_LangID", $lang_id)->get("nat_lang")->row(); + $lang = $l->Nat_LangCode; + } + + //tambahan fajri + $sql = " UPDATE t_orderdetail + JOIN t_test ON T_OrderDetailT_TestID = T_TestID + SET T_OrderDetailT_TestIsResult = T_TestIsResult + WHERE + T_OrderDetailT_OrderHeaderID = {$id} AND + T_OrderDetailT_TestIsResult = '' AND + T_OrderDetailIsActive = 'Y'"; + $this->db_smartone->query($sql); + + $tot_count = 0; + $lq = ""; + $group_id = 0; + if (isset($prm['group_id'])) + $group_id = $prm['group_id']; + + if ($group_id != 0) { + $sql = "select distinct T_WorklistDetailNat_TestID Nat_TestID + from t_worklistdetailv2 + where T_WorklistDetailT_WorklistID = {$group_id}"; + $qry = $this->db_smartone->query($sql); + $rows = $qry->result_array(); + $nat_test_ids = "0"; + foreach ($rows as $r) { + $nat_test_ids .= ", " . $r["Nat_TestID"]; + } + $q_group = " ( $nat_test_ids ) "; + + $sql = " + SELECT a1.*, cOUNT(a2.T_OrderDetailID) level + FROM ( + SELECT IFNULL(y.T_OrderDetailT_TestID, x.T_OrderDetailT_TestID) t_testid, + IFNULL(y.T_OrderDetailT_TestName, y.T_OrderDetailT_TestName) t_testname, + y.T_OrderDetailResult result, y.T_OrderDetailResult result_old, y.T_OrderDetailNote note, y.T_OrderDetailNote note_old, + y.T_OrderDetailID id, + y.T_OrderDetailT_TestIsResult is_result, a.T_TestIsQuantitative is_quantitative, + y.T_OrderDetailResultFlag result_flag, + y.T_OrderDetailNat_NormalValueID normal_id, + y.T_OrderDetailNormalValueNote normal_note, y.T_OrderDetailNat_UnitName unit_name, + y.T_OrderdetailNat_MethodeID methode_id, y.T_OrderdetailNat_MethodeName methode_name, + a.T_TestNat_TestID nattest_id, a.T_TestID tx_id, count(T_ResultInstrumentID) as result_instrument_n, + y.T_OrderDetailVerification, T_OrderSampleReceive sample_receive, + T_OrderSampleProcessing sample_processing, T_OrderSampleWorklistReceive sample_worklist_receive, + IF(T_OrderDetailAddOnPreAnalytic = 'Y', T_OrderDetailAddOnPreAnalytic, PreAnalyticIsOk) pre_analytic, + T_OrderDetailAddOnPreAnalytic, + T_OrderHeaderID order_id, y.T_OrderDetailT_TestSasCode test_sas_code, + tx.T_TestSasCode, + T_OrderDetailAddOnResample `resample`, T_OrderDetailAddOnResampleStatus resample_status, + T_OrderDetailAddOnRef ref, y.T_OrderDetailVerification verification, y.T_OrderDetailValidation validation, + T_OrderPromiseDateTime, Group_ResultName as ResultGroupName + FROM t_orderdetail x + left join t_orderpromise on x.T_OrderDetailT_OrderPromiseID = T_OrderPromiseID + JOIN t_test tx ON x.T_OrderDetailT_TestID = T_TestID + JOIN t_test tcheck on tcheck.T_TestNat_TestID in {$q_group} + and ( tx.T_TestID = tcheck.T_TestID or tx.T_TestSasCode like concat(tcheck.T_TestSasCode,'%')) + JOIN group_resultdetail ON Group_ResultDetailT_TestID = x.T_OrderDetailT_TestID AND Group_ResultDetailIsActive = 'Y' + JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND Group_ResultResumeMcu = 'LAB' + LEFT JOIN t_orderdetail y ON x.T_OrderDetailT_TestSasCode LIKE CONCAT(y.T_OrderDetailT_TestSasCode, '%') + AND x.T_OrderDetailT_OrderHeaderID = y.T_OrderDetailT_OrderHeaderID + AND y.T_OrderDetailIsActive = 'Y' + LEFT JOIN t_orderdetailaddon ON x.T_OrderDetailID = T_OrderDetailAddOnT_OrderDetailID + JOIN t_orderheader ON y.T_OrderDetailT_OrderHeaderID = T_OrderHeaderID + LEFT JOIN t_test a ON y.T_OrderDetailT_TestID = a.T_TestID + AND a.T_TestIsNonLab = '' + LEFT JOIN (SELECT T_OrderSampleT_SampleTypeID, T_OrderSampleReceive, T_OrderSampleProcessing, T_OrderSampleWorklistReceive + FROM t_ordersample WHERE T_OrderSampleT_OrderHeaderID = {$id} + AND T_OrderSampleIsactive = 'Y' + GROUP BY T_OrderSampleT_SampleTypeID) os ON a.T_TestT_SampleTypeID = os.T_OrderSampleT_SampleTypeID + or os.T_OrderSampleT_SampleTypeID = fn_sampletype_from_local(a.T_TestNat_TestID) + + LEFT JOIN t_resultinstrument ON T_ResultInstrumentT_OrderDetailID = x.T_OrderDetailID + LEFT JOIN pre_analytic ON PreAnalyticNat_TestID = a.T_TestNat_TestID AND PreAnalyticDate = date(now()) and PreAnalyticIsActive = 'Y' + WHERE x.T_OrderDetailT_OrderHeaderID = {$id} + AND x.T_OrderDetailIsActive = 'Y' + GROUP BY y.T_OrderDetailT_TestID + ORDER BY y.T_OrderDetailT_TestSasCode ASC + ) a1 + + LEFT JOIN t_orderdetail a2 ON a2.T_OrderDetailT_OrderHeaderID = a1.order_id + AND a2.T_OrderDetailIsActive = 'Y' + AND a1.test_sas_code LIKE CONCAT(a2.T_OrderDetailT_testSasCode, '%') + GROUP BY a1.t_testid + order by a1.test_sas_code +"; + $query = $this->db_smartone->query($sql); + $lq = $this->db_smartone->last_query(); + } else { + $sql = " + SELECT a1.*, cOUNT(a2.T_OrderDetailID) level + FROM ( + SELECT IFNULL(y.T_OrderDetailT_TestID, x.T_OrderDetailT_TestID) t_testid, + IFNULL(y.T_OrderDetailT_TestName, y.T_OrderDetailT_TestName) t_testname, + y.T_OrderDetailResult result, y.T_OrderDetailResult result_old, y.T_OrderDetailNote note, y.T_OrderDetailNote note_old, + y.T_OrderDetailID id, + y.T_OrderDetailT_TestIsResult is_result, a.T_TestIsQuantitative is_quantitative, + y.T_OrderDetailResultFlag result_flag, + y.T_OrderDetailNat_NormalValueID normal_id, + y.T_OrderDetailNormalValueNote normal_note, y.T_OrderDetailNat_UnitName unit_name, + y.T_OrderdetailNat_MethodeID methode_id, y.T_OrderdetailNat_MethodeName methode_name, + a.T_TestNat_TestID nattest_id, a.T_TestID tx_id, count(T_ResultInstrumentID) as result_instrument_n, + y.T_OrderDetailVerification, T_OrderSampleReceive sample_receive, + T_OrderSampleProcessing sample_processing, T_OrderSampleWorklistReceive sample_worklist_receive, + IF(T_OrderDetailAddOnPreAnalytic = 'Y', T_OrderDetailAddOnPreAnalytic, PreAnalyticIsOk) pre_analytic, + T_OrderDetailAddOnPreAnalytic, + T_OrderHeaderID order_id, y.T_OrderDetailT_TestSasCode test_sas_code, + tx.T_TestSasCode, + T_OrderDetailAddOnResample `resample`, T_OrderDetailAddOnResampleStatus resample_status, + T_OrderDetailAddOnRef ref, y.T_OrderDetailVerification verification, y.T_OrderDetailValidation validation, + T_OrderPromiseDateTime , Group_ResultName as ResultGroupName + FROM t_orderdetail x + left join t_orderpromise on x.T_OrderDetailT_OrderPromiseID = T_OrderPromiseID + JOIN t_test tx ON x.T_OrderDetailT_TestID = T_TestID + JOIN group_resultdetail ON Group_ResultDetailT_TestID = x.T_OrderDetailT_TestID AND Group_ResultDetailIsActive = 'Y' + JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND Group_ResultResumeMcu = 'LAB' + LEFT JOIN t_orderdetail y ON x.T_OrderDetailT_TestSasCode LIKE CONCAT(y.T_OrderDetailT_TestSasCode, '%') + AND x.T_OrderDetailT_OrderHeaderID = y.T_OrderDetailT_OrderHeaderID + AND y.T_OrderDetailIsActive = 'Y' + + LEFT JOIN t_orderdetailaddon ON x.T_OrderDetailID = T_OrderDetailAddOnT_OrderDetailID + + JOIN t_orderheader ON y.T_OrderDetailT_OrderHeaderID = T_OrderHeaderID + LEFT JOIN t_test a ON y.T_OrderDetailT_TestID = a.T_TestID + AND a.T_TestIsNonLab = '' + LEFT JOIN (SELECT T_OrderSampleT_SampleTypeID, T_OrderSampleReceive, T_OrderSampleProcessing, T_OrderSampleWorklistReceive + FROM t_ordersample WHERE T_OrderSampleT_OrderHeaderID = {$id} + AND T_OrderSampleIsactive = 'Y' + GROUP BY T_OrderSampleT_SampleTypeID) os ON a.T_TestT_SampleTypeID = os.T_OrderSampleT_SampleTypeID + or os.T_OrderSampleT_SampleTypeID = fn_sampletype_from_local(a.T_TestNat_TestID) + + LEFT JOIN t_resultinstrument ON T_ResultInstrumentT_OrderDetailID = x.T_OrderDetailID + LEFT JOIN pre_analytic ON PreAnalyticNat_TestID = a.T_TestNat_TestID AND PreAnalyticDate = date(now()) and PreAnalyticIsActive = 'Y' + WHERE x.T_OrderDetailT_OrderHeaderID = {$id} + AND x.T_OrderDetailIsActive = 'Y' + GROUP BY y.T_OrderDetailT_TestID + ORDER BY y.T_OrderDetailT_TestSasCode ASC + ) a1 + + LEFT JOIN t_orderdetail a2 ON a2.T_OrderDetailT_OrderHeaderID = a1.order_id + AND a2.T_OrderDetailIsActive = 'Y' + AND a1.test_sas_code LIKE CONCAT(a2.T_OrderDetailT_testSasCode, '%') + GROUP BY a1.t_testid + order by a1.test_sas_code +"; + //echo $sql; + $query = $this->db_smartone->query($sql); + $lq = $this->db_smartone->last_query(); + } + // file_put_contents("/xtmp/re-query.sql",$lq); + + if ($query) { + $rst = []; + $rows = $query->result_array(); + + foreach ($rows as $k => $v) { + + if ($v['is_result'] == "Y" && $v['is_quantitative'] == "N") { + $v['template'] = []; + $x = $this->db_smartone->query("CALL sp_master_resulttemplate_get('{$v['t_testid']}')"); + $this->clean_mysqli_connection($this->db_smartone->conn_id); + if ($x) + $v['template'] = $x->result_array(); + } + + // IF Rujukan, by pas Pre Analytik + if ($v['ref'] == 'Y') + $v['pre_analytic'] = 'Y'; + if ($v["id"] == "885455") { + //sipe workaround + //$v["sample_receive"] = "Y"; + $v["sample_worklist_receive"] = "Y"; + } + $rst[] = $v; + } + + $result = array("total" => $tot_count, "records" => $rst, "total_display" => sizeof($rows), "q" => $lq); + $this->sys_ok($result); + } else { + $this->sys_error_db("RE Px rows", $this->db_smartone); + exit; + } + } + + public function save() + { + $prm = $this->sys_input; + $data = json_decode($prm["data"]); + $lang = $this->lang_default_code; + $lang_id = isset($prm['lang_id']) ? $prm['lang_id'] : '0'; + + if ($lang_id != 0) { + $l = $this->db_smartone->where("Nat_LangID", $lang_id)->get("nat_lang")->row(); + $lang = $l->Nat_LangCode; + } + + $sql_norm = "select T_OrderDetailMinValue, T_OrderDetailMaxValue, + T_OrderDetailMinValueInclusive, T_OrderDetailMaxValueInclusive, + Nat_TestFlagLow, Nat_TestFlagHigh + from t_orderdetail + join t_test on T_OrderDetailT_TestID = T_TestID + join nat_test on T_TestNat_TestID = Nat_TestID and T_TestIsActive = 'Y' + where T_OrderDetailID = ? "; + + $ids = []; + foreach ($data as $k => $v) { + if ($v->resultInstrumentID > 0) { + $sql_i = "select T_ResultInstrumentNat_NormalValueID normalValueID + from t_resultinstrument + where T_ResultInstrumentID = ?"; + $qry_i = $this->db_smartone->query($sql_i, array($v->resultInstrumentID)); + if ($qry_i) { + $rows_i = $qry_i->result_array(); + + if (count($rows_i) > 0) { + $sql_iu = "update t_orderdetail, nat_normalvalue , nat_methode + set T_OrderDetailMinValue = Nat_NormalValueMinValue, + T_OrderDetailMinValueInclusive = Nat_NormalValueMinValueInclusive, + T_OrderDetailMaxValue = Nat_NormalValueMaxValue , + T_OrderDetailMaxValueInclusive = Nat_NormalValueMaxValueInclusive, + T_OrderDetailNormalValueNote = Nat_NormalValueNote, + T_OrderDetailNormalValueDescription = Nat_NormalValueDescription, + T_OrderDetailNat_NormalValueID = Nat_NormalValueID, + T_OrderDetailNat_MethodeID = Nat_NormalValueNat_MethodeID, + T_OrderDetailNat_MethodeName = Nat_MethodeName + where T_OrderDetailID = ? and Nat_NormalValueID = ? + and Nat_NormalValueNat_MethodeID = Nat_MethodeID + "; + $this->db_smartone->query($sql_iu, array($v->id, $rows_i[0]["normalValueID"])); + //file_put_contents("/xtmp/update-nilai-normal", $this->db_smartone->last_query() . "\n", FILE_APPEND); + } + } + } + $y = $this->db_smartone->query("SELECT fn_process_sample_handling_perfect('{$v->order_id}', '{$v->test_id}') c") + ->row(); + $req_status = $y->c; + $qry_norm = $this->db_smartone->query($sql_norm, $v->id); + $result_flag = ""; + if ($qry_norm) { + $rows_norm = $qry_norm->result_array(); + if (count($rows_norm) > 0) { + $r = $rows_norm[0]; + if (is_numeric($v->result)) { + + if ($r["T_OrderDetailMinValueInclusive"] == "Y" && $v->result < $r["T_OrderDetailMinValue"]) { + $result_flag = $r["Nat_TestFlagLow"]; + } + if ($r["T_OrderDetailMinValueInclusive"] == "N" && $v->result <= $r["T_OrderDetailMinValue"]) { + $result_flag = $r["Nat_TestFlagLow"]; + } + if ($r["T_OrderDetailMaxValueInclusive"] == "Y" && $v->result > $r["T_OrderDetailMaxValue"]) { + $result_flag = $r["Nat_TestFlagHigh"]; + } + if ($r["T_OrderDetailMaxValueInclusive"] == "N" && $v->result >= $r["T_OrderDetailMaxValue"]) { + $result_flag = $r["Nat_TestFlagHigh"]; + } + } + } + } + if ($lang == $this->lang_default_code) { + $this->db_smartone->set('T_OrderDetailResult', $v->result) + ->set('T_OrderDetailResultFlag', $result_flag) + ->set('T_OrderDetailNote', $v->note) + ->set('T_OrderDetailReqStatus', $req_status) + ->where('T_OrderDetailID', $v->id) + ->update('t_orderdetail'); + } else { + $this->db_smartone->set('T_OrderDetailLangResult', $v->result) + ->set('T_OrderDetailLangNote', $v->note) + ->where('T_OrderDetailLangID', $v->id) + ->update('t_orderdetaillang'); + } + + + + $ids[] = $v->id; + + //log detail + + $sql = "SELECT COUNT(*) n FROM log_orderdetail WHERE Log_OrderDetailT_OrderDetailID = ? AND Log_OrderDetailResult = ? ORDER BY Log_OrderDetailID DESC LIMIT 1"; + $qry = $this->db_lab->query($sql, [$v->id, $v->result]); + if ($qry) { + $n = $qry->row(); + + if ($n->n == 0) { + $sql = "SELECT * FROM t_orderdetail WHERE T_OrderDetailID = ?"; + $qry_order = $this->db_smartone->query($sql, [$v->id]); + $dt_orderdetail = $qry_order->row(); + $dt_detail_log = json_encode($dt_orderdetail); + + $sql = "INSERT INTO log_orderdetail ( + Log_OrderDetailStatus, + Log_OrderDetailT_OrderDetailID, + Log_OrderDetailResult, + Log_OrderDetailJSON, + Log_OrderDetailCreated, + Log_OrderDetailUserID + ) + VALUES (?,?, ?, ?, NOW(), ?)"; + $this->db_lab->query($sql, ['RESULTENTRY',$v->id, $v->result, $dt_detail_log, $this->sys_user['M_UserID']]); + //echo $this->db_lab->last_query(); + //exit(); + } + } + } + + // LOG Process + $order = $this->db_smartone->select('T_OrderDetailT_OrderHeaderID id, T_OrderHeaderLabNumber lab_number', false) + ->join('t_orderheader', 'T_OrderHeaderID = T_OrderDetailT_OrderHeaderID') + ->where('T_OrderDetailID', $data[0]->id) + ->get('t_orderdetail') + ->row(); + + $dblog = $this->db_lab; + $dblog->set('Log_ProcessCode', 'PROCESS.Result.Entry') + ->set('Log_ProcessOrderID', $order->id) + ->set('Log_ProcessOrderNumber', $order->lab_number) + ->set('Log_ProcessJson', json_encode($data)) + ->set('Log_ProcessUserID', $this->sys_user['M_UserID']) + ->insert('log_process'); + // END OF Log Process + //auto calculation + $this->load->library("Resultcalc"); + $rows = $this->resultcalc->auto($order->id); + + try { + foreach ($ids as $id) { + $this->db_smartone->query("call sp_set_normal_value_flag($id)"); + $this->clean_mysqli_connection($this->db_smartone->conn_id); + } + } catch (Exception $e) { + } + + $this->sys_ok($ids); + } + + public function save_template() + { + $prm = $this->sys_input; + + $n = $this->db_smartone->select("COUNT(T_ResultTemplateID) n") + ->where("T_ResultTemplateT_TestID", $prm['test_id']) + ->where("T_ResultTemplateIsActive", "Y") + ->where("T_ResultTemplateValue", $prm['value']) + ->get('t_resulttemplate') + ->row(); + if ($n->n > 0) { + $this->sys_error_db("Insert Result Template", $this->db_smartone); + return; + } + + $r = $this->db_smartone->set("T_ResultTemplateT_TestID", $prm['test_id']) + ->set("T_ResultTemplateValue", $prm['value']) + ->insert('t_resulttemplate'); + if ($r) { + $template = []; + $x = $this->db_smartone->query("CALL sp_master_resulttemplate_get('{$prm['test_id']}')"); + $this->clean_mysqli_connection($this->db_smartone->conn_id); + if ($x) + $template = $x->result_array(); + + $this->sys_ok($template); + } + } + + public function export() + { + $prm = $this->sys_input; + + $sql = "CALL sp_process_result_lang(?, ?, ?, ?)"; + $query = $this->db_smartone->query($sql, [$prm['order_id'], $prm['lang_id'], $prm['is_si'], $this->sys_user['M_UserID']]); + if ($query) { + $r = $query->row(); + if ($r->status == "OK") { + $this->sys_ok($r->data); + return; + } + + $this->sys_error_db("Message : " . $r->message, $this->db_smartone); + } else { + $this->sys_error_db("Lang Result", $this->db_smartone); + return; + } + } + + public function search_group() + { + $prm = $this->sys_input; + $max_rst = 100; + + // QUERY TOTAL + $sql = "select count(*) total + from t_worklist + where T_WorklistIsActive = 'Y' + order by T_WorklistName ASC"; + $query = $this->db_smartone->query($sql); + + if ($query) { + $tot_count = $query->result_array()[0]["total"]; + } else { + $this->sys_error_db("worklist count", $this->db_smartone); + exit; + } + + $sql = "select T_WorklistID group_id, T_WorklistName group_name + from t_worklist + where T_WorklistIsActive = 'Y' + order by T_WorklistName ASC + limit 0, {$max_rst}"; + $query = $this->db_smartone->query($sql); + + if ($query) { + $rows = $query->result_array(); + foreach ($rows as $k => $v) + $rows[$k]['data'] = json_decode($v['data']); + $result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows), "q" => $this->db_smartone->last_query()); + $this->sys_ok($result); + } else { + $this->sys_error_db("worklist rows", $this->db_smartone); + exit; + } + } + + public function search_rerun() + { + $prm = $this->sys_input; + $id = $prm["detail_id"]; + + $sql = "CALL sp_process_result_rerun(?)"; + $query = $this->db_smartone->query($sql, [$id]); + + if ($query) { + $rows = $query->result_array(); + $this->sys_ok(["records" => $rows]); + } else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + + + function getdoctorsfna() + { + $prm = $this->sys_input; + // $id = $prm["id"]; + + $sql = " SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY M_DoctorName ASC"; + //echo $sql; + $query = $this->db_smartone->query($sql); + + if ($query) { + $rows = $query->result_array(); + $this->sys_ok(["records" => $rows]); + } else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + function getfnaresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT Other_FNADetailsID as xid, + Other_FNAT_OrderDetailID as orderdetail_id, + Other_FNADetailsCode as code, + Other_FNADetailsLabel as label, + Other_FNADetailsResult as result, + IFNULL(Other_FNAM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_FNAM_DoctorID) OR Other_FNAM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_fna + JOIN other_fnadetails ON Other_FNADetailsOther_FNAID = Other_FNAID AND Other_FNADetailsIsActive = 'Y' + LEFT JOIN m_doctor ON Other_FNAM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_FNAT_OrderDetailID = {$id} AND Other_FNAIsActive = 'Y' + GROUP BY Other_FNADetailsID + ORDER BY Other_FNADetailsCode ASC"; + $query = $this->db_smartone->query($sql); + + if ($query) { + $rows = $query->result_array(); + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $images = array(); + $sql = "SELECT So_ImageUploadID as xid, + CONCAT('/one-media/one-image-nonlab/',So_ImageUploadNewName) as image_url + FROM t_orderdetail + JOIN so_imageupload ON So_ImageUploadT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND + So_ImageUploadIsActive = 'Y' + WHERE + T_OrderDetailID = {$id} AND + T_OrderDetailIsActive = 'Y' + GROUP BY So_ImageUploadID"; + $images = $this->db_smartone->query($sql)->result_array(); + + $rst = array('doctors' => $doctors, 'results' => $rows, 'images' => $images); + $this->sys_ok(["records" => $rst]); + } else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + function getpatologianatomyresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT Other_PatologiAnatomyID as xid, + Other_PatologiAnatomyT_OrderDetailID as orderdetail_id, + Other_PatologiAnatomyNoSediaan as no_sediaan, + Other_PatologiAnatomyDiagnosaKlinis as diagnosa, + Other_PatologiAnatomyKeteranganKlinis as klinis, + Other_PatologiAnatomyLokasiOrgan as lokasi, + Other_PatologiAnatomyMakroskopik as makroskopik, + Other_PatologiAnatomyMikroskopik as mikroskopik, + Other_PatologiAnatomyKesimpulan as kesimpulan, + IFNULL(Other_PatologiAnatomyM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_PatologiAnatomyM_DoctorID) OR Other_PatologiAnatomyM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_patologi_anatomy + LEFT JOIN m_doctor ON Other_PatologiAnatomyM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_PatologiAnatomyT_OrderDetailID = {$id} AND Other_PatologiAnatomyIsActive = 'Y' + GROUP BY Other_PatologiAnatomyID + ORDER BY Other_PatologiAnatomyID ASC + LIMIT 1"; + $query = $this->db_smartone->query($sql); + + if ($query) { + $rows = $query->row_array(); + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + + $sql = "SELECT So_ImageUploadPatologyAnatomyID as xid, + CONCAT('/one-media/one-image-nonlab/',So_ImageUploadPatologyAnatomyNewName) as image_url, + So_ImageUploadPatologyAnatomyType as type + FROM t_orderdetail + JOIN so_imageupload_patology_anatomy ON So_ImageUploadPatologyAnatomyT_OrderHeaderID= T_OrderDetailT_OrderHeaderID AND + So_ImageUploadPatologyAnatomyIsActive= 'Y' + WHERE + T_OrderDetailID = {$id} AND + T_OrderDetailIsActive = 'Y' + GROUP BY So_ImageUploadPatologyAnatomyID"; + $images = $this->db_smartone->query($sql)->result_array(); + $mikro = []; + $makro = []; + + foreach ($images as $key => $value) { + + if ($value['type'] == 'mikro') { + $mikro[] = $value; + } + if ($value['type'] == 'makro') { + $makro[] = $value; + } + } + + $rst = array('doctors' => $doctors, 'result' => $rows, "mikro" => $mikro, "makro" => $makro); + $this->sys_ok(["records" => $rst]); + } else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + + + + function uploadimage() + { + if (! $this->isLogin) { + $this->sys_error("Invalid Token"); + exit; + } + + $userid = $this->sys_user["M_UserID"]; + $data = []; + //print_r($_SERVER); + + $prm = $this->sys_input; + $orderid = $this->input->post('orderid'); + $labnumber = $this->input->post('labnumber'); + $sql = "UPDATE so_imageupload SET + So_ImageUploadIsActive = 'N', + So_ImageUploadUserID = {$userid} + WHERE + So_ImageUploadT_OrderHeaderID = {$orderid}"; + //echo $sql; + $this->db_onedev->query($sql); + //$config['upload_path'] = 'assets/'; + + $path = '/home/one/project/one/one-media/one-image-nonlab/'; + //echo $path; + $config['upload_path'] = $path; + $config['allowed_types'] = 'jpg|jpeg|png|gif'; + + $config['max_size'] = '10000'; + $count = count($_FILES['files']['name']); + //echo $count; + $this->load->library('upload', $config); + + $error = []; + for ($i = 0; $i < $count; $i++) { + + + if (!empty($_FILES['files']['name'][$i])) { + + + + $_FILES['file']['name'] = $_FILES['files']['name'][$i]; + + $_FILES['file']['type'] = $_FILES['files']['type'][$i]; + + $_FILES['file']['tmp_name'] = $_FILES['files']['tmp_name'][$i]; + + $_FILES['file']['error'] = $_FILES['files']['error'][$i]; + + $_FILES['file']['size'] = $_FILES['files']['size'][$i]; + + + + $namex = $orderid . '-' . $labnumber . '-' . $this->generateRandomString(5); + //echo $namex; + + $config['file_name'] = $namex; + $this->upload->initialize($config); + //echo $config['file_name'] ; + + + + + + if ($this->upload->do_upload('file')) { + + $uploadData = $this->upload->data(); + + $filename = $uploadData['file_name']; + //echo $filename; + + + $sql = "INSERT INTO so_imageupload ( + So_ImageUploadT_OrderHeaderID, + So_ImageUploadT_OrderHeaderLabNumber, + So_ImageUploadT_SampleTypeID, + So_ImageUploadOldName, + So_ImageUploadNewName, + So_ImageUploadCreated, + So_ImageUploadUserID + ) + VALUES( + {$orderid}, + '{$labnumber}', + '150', + '{$_FILES['files']['name'][$i]}', + '{$filename}', + NOW(), + {$userid} + + )"; + //echo $sql; + $this->db_onedev->query($sql); + $xlast_id = $this->db_onedev->insert_id(); + $data['totalFiles'][] = array('xid' => $xlast_id, 'image_url' => '/one-media/one-image-nonlab/' . $filename); + } else { + $error = array('error' => $this->upload->display_errors()); + } + } + } + + $result = array("total" => count($data['totalFiles']), "records" => $data['totalFiles'], 'errors' => $error); + $this->sys_ok($result); + } + function uploadimagePatologiAnatomi() + { + if (! $this->isLogin) { + $this->sys_error("Invalid Token"); + exit; + } + + $userid = $this->sys_user["M_UserID"]; + $data = []; + //print_r($_SERVER); + + $prm = $this->sys_input; + $orderid = $this->input->post('orderid'); + $type = $this->input->post('type'); + $labnumber = $this->input->post('labnumber'); + $sql = "UPDATE so_imageupload_patology_anatomy SET + So_ImageUploadPatologyAnatomyIsActive = 'N', + So_ImageUploadPatologyAnatomyUserID = {$userid} + WHERE + So_ImageUploadPatologyAnatomyT_OrderHeaderID = {$orderid} + AND So_ImageUploadPatologyAnatomyType = '{$type}'"; + //echo $sql; + $qry = $this->db_onedev->query($sql); + $last_qry = $this->db_onedev->last_query(); + if (!$qry) { + $message = $this->db_onedev->error(); + $message['last_qry'] = $last_qry; + $this->sys_error_db($message); + exit; + } + //$config['upload_path'] = 'assets/'; + + $path = '/home/one/project/one/one-media/one-image-nonlab/'; + //echo $path; + $config['upload_path'] = $path; + $config['allowed_types'] = 'jpg|jpeg|png|gif'; + + $config['max_size'] = '10000'; + $count = count($_FILES['files']['name']); + //echo $count; + $this->load->library('upload', $config); + + $error = []; + for ($i = 0; $i < $count; $i++) { + + + if (!empty($_FILES['files']['name'][$i])) { + + + + $_FILES['file']['name'] = $_FILES['files']['name'][$i]; + + $_FILES['file']['type'] = $_FILES['files']['type'][$i]; + + $_FILES['file']['tmp_name'] = $_FILES['files']['tmp_name'][$i]; + + $_FILES['file']['error'] = $_FILES['files']['error'][$i]; + + $_FILES['file']['size'] = $_FILES['files']['size'][$i]; + + + + $namex = $orderid . '-' . $labnumber . '-' . $this->generateRandomString(5); + //echo $namex; + + $config['file_name'] = $namex; + $this->upload->initialize($config); + //echo $config['file_name'] ; + + + + + + if ($this->upload->do_upload('file')) { + + $uploadData = $this->upload->data(); + + $filename = $uploadData['file_name']; + //echo $filename; + + + $sql = "INSERT INTO so_imageupload_patology_anatomy ( + So_ImageUploadPatologyAnatomyT_OrderHeaderID, + So_ImageUploadPatologyAnatomyT_OrderHeaderLabNumber, + So_ImageUploadPatologyAnatomyT_SampleTypeID, + So_ImageUploadPatologyAnatomyOldName, + So_ImageUploadPatologyAnatomyNewName, + So_ImageUploadPatologyAnatomyCreated, + So_ImageUploadPatologyAnatomyUserID, + So_ImageUploadPatologyAnatomyType + ) + VALUES( + {$orderid}, + '{$labnumber}', + '145', + '{$_FILES['files']['name'][$i]}', + '{$filename}', + NOW(), + {$userid}, + '{$type}' + + )"; + //echo $sql; + $qry = $this->db_onedev->query($sql); + $last_qry = $this->db_onedev->last_query(); + if (!$qry) { + $message = $this->db_onedev->error(); + $message['last_qry'] = $last_qry; + $this->sys_error_db($message); + exit; + } + $xlast_id = $this->db_onedev->insert_id(); + $data['totalFiles'][] = array('xid' => $xlast_id, 'image_url' => '/one-media/one-image-nonlab/' . $filename); + } else { + $error = array('error' => $this->upload->display_errors()); + } + } + } + + $result = array("total" => count($data['totalFiles']), "records" => $data['totalFiles'], 'errors' => $error); + $this->sys_ok($result); + } + + + function generateRandomString($length = 10) + { + $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; + $charactersLength = strlen($characters); + $randomString = ''; + for ($i = 0; $i < $length; $i++) { + $randomString .= $characters[rand(0, $charactersLength - 1)]; + } + return $randomString; + } + + function getcytologiresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT Other_CytologiDetailsID as xid, + Other_CytologiT_OrderDetailID as orderdetail_id, + Other_CytologiDetailsCode as code, + Other_CytologiDetailsLabel as label, + Other_CytologiDetailsResult as result, + IFNULL(Other_CytologiM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_CytologiM_DoctorID) OR Other_CytologiM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_cytologi + JOIN other_cytologidetails ON Other_CytologiDetailsOther_CytologiID = Other_CytologiID AND Other_CytologiDetailsIsActive = 'Y' + LEFT JOIN m_doctor ON Other_CytologiM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_CytologiT_OrderDetailID = {$id} AND Other_CytologiIsActive = 'Y' + GROUP BY Other_CytologiDetailsID + ORDER BY Other_CytologiDetailsCode ASC"; + //echo $sql; + $query = $this->db_smartone->query($sql); + + if ($query) { + $rows = $query->result_array(); + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $rst = array('doctors' => $doctors, 'results' => $rows); + $this->sys_ok(["records" => $rst]); + } else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + function getmikroresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT + Other_MikroID as xid, + Other_MikroHasilBiakan as hasil_biakan, + Other_MikroSampleTypeName as sample_name, + Other_MikroT_OrderDetailID as orderdetail_id, + Other_MikroResult as result_value, + '' as result_other, + IFNULL(T_BacteriaID,0) as T_BacteriaID, + IFNULL(T_BacteriaName,'') as T_BacteriaName, + '' as details, + IFNULL(Other_MikroM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_MikroM_DoctorID) OR Other_MikroM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_mikro + LEFT JOIN t_bacteria ON Other_MikroT_BacteriaID = T_BacteriaID + LEFT JOIN m_doctor ON Other_MikroM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_MikroT_OrderDetailID = {$id} AND Other_MikroIsActive = 'Y' + GROUP BY Other_MikroID"; + //echo $sql; + $query = $this->db_smartone->query($sql); + + if ($query) { + $row = $query->row_array(); + if ($row) { + if ($row['result_value'] != 'Positif' && $row['result_value'] != 'Negatif') { + $row['result_other'] = $row['result_value']; + $row['result_value'] = 'other'; + } + $sql = "SELECT '' as xno, + Other_MikroDetailsID as xid, + Other_MikroDetailsValue as value, + IF(Other_MikroDetailsNote = 'R','Y','N') as chx_r, + IF(Other_MikroDetailsNote = 'I','Y','N') as chx_i, + IF(Other_MikroDetailsNote = 'S','Y','N') as chx_s, + Other_MikroDetailsNote as note, + t_antibiotic.* + FROM other_mikrodetails + LEFT JOIN t_antibiotic ON Other_MikroDetailsT_AntibioticID = T_AntibioticID + WHERE + Other_MikroDetailsOther_MikroID = {$row['xid']} AND Other_MikroDetailsIsActive = 'Y' + GROUP BY Other_MikroDetailsID + ORDER BY T_AntibioticName ASC"; + //echo $sql; + $details = $this->db_smartone->query($sql)->result_array(); + if ($details) { + foreach ($details as $k => $v) { + $details[$k]['xno'] = $k + 1; + } + } + $row['details'] = $details; + } else { + $row = array('xid' => '0', 'hasil_biakan' => '', 'result_value' => 'Negatif', 'sample_name' => '', 'orderdetail_id' => $id, 'T_BacteriaID' => '0', 'T_BacteriaName' => '0', 'details' => array(), 'doctor_id' => '0', 'doctor_name' => '0'); + } + } else { + $row = array('xid' => '0', 'hasil_biakan' => '', 'result_value' => 'Negatif', 'sample_name' => '', 'orderdetail_id' => $id, 'T_BacteriaID' => '0', 'T_BacteriaName' => '0', 'details' => array(), 'doctor_id' => '0', 'doctor_name' => '0'); + } + //print_r($row); + + + + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 7 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $sql = " + SELECT '0' as id, 'Belum memilih bakteria' as name + UNION + SELECT T_BacteriaID as id, T_BacteriaName as name + FROM t_bacteria + WHERE + T_BacteriaIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $bacteries = $this->db_smartone->query($sql)->result_array(); + $rst = array('doctors' => $doctors, 'bacteries' => $bacteries, 'results' => $row); + $this->sys_ok(["records" => $rst]); + } + function getantibiotics() + { + $prm = $this->sys_input; + $id = $prm["id"]; + $sql = " SELECT '' as xno, + 0 as xid, + '' as hasil_biakan, + '' as sample_name, + 0 as value, + 'Y' as chx_r, + 'N' as chx_i, + 'N' as chx_s, + 'R' as note, + t_antibiotic.* + FROM t_antibiotic + WHERE + T_AntibioticT_BacteriaID = {$prm['id']} AND T_AntibioticIsActive= 'Y' + ORDER BY T_AntibioticName ASC"; + //echo $sql; + $rows = $this->db_smartone->query($sql)->result_array(); + if (rows) { + foreach ($rows as $k => $v) { + $rows[$k]['xno'] = $k + 1; + } + } + + $this->sys_ok(["records" => $rows]); + } + function getlcprepresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = "SELECT T_OrderDetailVerification as verification, T_OrderDetailValidation as validation FROM t_orderdetail WHERE T_OrderDetailID = ?"; + $order = $this->db_smartone->query($sql, array($id))->row_array(); + + + $sql = " SELECT Other_LcprepDetailsID as xid, + Other_LcprepID as header_id, + Other_LcprepT_orderDetailID as orderdetail_id, + Other_LcprepDetailsCode as code, + Other_LcprepDetailsLabel as label, + Other_LcprepDetailsResult as result, + IFNULL(Other_LcprepM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_LcprepM_DoctorID) OR Other_LcprepM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_lcprep + JOIN other_lcprepdetails ON Other_LcprepDetailsOther_LcprepID = Other_LcprepID AND Other_LcprepDetailsIsActive = 'Y' + LEFT JOIN m_doctor ON Other_LcprepM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_LcprepT_orderDetailID = ? AND Other_LcprepIsActive = 'Y' + GROUP BY Other_LcprepDetailsOther_LcprepID, Other_LcprepDetailsCode + ORDER BY Other_LcprepDetailsCode ASC"; + //echo $sql; + $rows = $this->db_smartone->query($sql, array($id))->result_array(); + if (count($rows) == 0) { + $rows = array( + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'A', + 'label' => 'DESKRIPSI', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ), + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'B', + 'label' => 'KESIMPULAN', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ) + ); + } + + $other_rows = array(); + $langs = array(array('id' => 1, 'name' => 'Bahasa Indonesia')); + $selected_lang = array(array('id' => 1, 'name' => 'Bahasa Indonesia')); + $sql = "SELECT T_OrderHeaderAddOnSecondM_LangID as lang_id, + M_LangName as lang_name + FROM t_orderdetail + JOIN t_orderheader ON T_OrderDetailT_OrderHeaderID = T_OrderHeaderID AND T_OrderHeaderIsActive = 'Y' + JOIN t_orderheaderaddon ON T_OrderHeaderAddonT_OrderHeaderID = T_OrderHeaderID AND T_OrderHeaderAddonIsActive = 'Y' + JOIN m_lang ON T_OrderHeaderAddOnSecondM_LangID = M_LangID AND M_LangIsActive = 'Y' + WHERE T_OrderDetailID = {$id} AND T_OrderDetailIsActive = 'Y'"; + + $other_lang = $this->db_smartone->query($sql)->result_array(); + if (count($other_lang) > 0) { + $langs[] = array('id' => $other_lang[0]['lang_id'], 'name' => $other_lang[0]['lang_name']); + $selected_lang = array('id' => $other_lang[0]['lang_id'], 'name' => $other_lang[0]['lang_name']); + + + $sql = " SELECT Other_LcprepDetailsLangsID as xid, + Other_LcprepID as header_id, + Other_LcprepT_orderDetailID as orderdetail_id, + Other_LcprepDetailsLangsCode as code, + Other_LcprepDetailsLangsLabel as label, + Other_LcprepDetailsLangsResult as result, + IFNULL(Other_LcprepM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_LcprepM_DoctorID) OR Other_LcprepM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_lcprep + JOIN other_lcprepdetails_lang ON Other_LcprepDetailsLangsOther_LcprepID = Other_LcprepID AND Other_LcprepDetailsLangsIsActive = 'Y' + LEFT JOIN m_doctor ON Other_LcprepM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_LcprepT_orderDetailID = {$id} AND Other_LcprepDetailsLangsIsActive = 'Y' + GROUP BY Other_LcprepDetailsLangsOther_LcprepID, Other_LcprepDetailsLangsCode + ORDER BY Other_LcprepDetailsLangsCode ASC"; + // echo $sql; + $other_rows = $this->db_smartone->query($sql)->result_array(); + if (count($other_rows) == 0) { + $other_rows = array( + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'AA', + 'label' => 'DESCRIPTION', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ), + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'BB', + 'label' => 'CONCLUSION', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ) + ); + } + } + + $header_id = $rows[0]['header_id']; + $sql = "SELECT IFNULL(Other_LcprepAdekuasiID,0) as xid, + Lcprep_AdekuasiID as id, + Lcprep_AdekuasiLabel as name, + Lcprep_AdekuasiLabel as name_en, + IF(ISNULL(Other_LcprepAdekuasiID),'N',Other_LcprepAdekuasiChex) as chex + FROM lcprep_adekuasi + LEFT JOIN other_lcprepadekuasi ON Other_LcprepAdekuasiLcprep_AdekuasiID = Lcprep_AdekuasiID AND + Other_LcprepAdekuasiOther_LcprepID = {$header_id} AND + Other_LcprepAdekuasiIsActive = 'Y' + WHERE + Lcprep_AdekuasiIsActive = 'Y' + GROUP BY Lcprep_AdekuasiID + ORDER BY Lcprep_AdekuasiOrder ASC + "; + //echo $sql; + $adeakuasi = $this->db_smartone->query($sql)->result_array(); + foreach ($adeakuasi as $kc => $vc) { + $adeakuasi[$kc]['chex'] = $vc['chex'] == 'N' ? false : true; + $adeakuasi[$kc]['name_en'] = $this->translate_word($vc['name']); + } + + $sql = "SELECT IFNULL(Other_LcprepKategoriUmumID,0) as xid, + Lcprep_KategoriUmumID as id, + Lcprep_KategoriUmumLabel as name, + Lcprep_KategoriUmumLabel as name_en, + IF(ISNULL(Other_LcprepKategoriUmumID),'N',Other_LcprepKategoriUmumChex) as chex + FROM lcprep_kategoriumum + LEFT JOIN other_lcprepkategoriumum ON Other_LcprepKategoriUmumLcprep_KategoriUmumID = Lcprep_KategoriUmumID AND + Other_LcprepKategoriUmumOther_LcprepID = {$header_id} AND + Other_LcprepKategoriUmumIsActive = 'Y' + WHERE + Lcprep_KategoriUmumIsActive = 'Y' + GROUP BY Lcprep_KategoriUmumID + "; + //echo $sql; + $kategoriumum = $this->db_smartone->query($sql)->result_array(); + foreach ($kategoriumum as $kc => $vc) { + $kategoriumum[$kc]['chex'] = $vc['chex'] == 'N' ? false : true; + $kategoriumum[$kc]['name_en'] = $this->translate_word($vc['name']); + } + + $sql = " + SELECT Lcprep_InterpretasiGroupID as group_id, + Lcprep_InterpretasiGroupName as group_name, + Lcprep_InterpretasiGroupName as group_name_en, + '' as subgroups + FROM lcprep_interpretasigroup + WHERE + Lcprep_InterpretasiGroupIsActive = 'Y' + "; + //echo $sql; + $interpretasi = $this->db_smartone->query($sql)->result_array(); + foreach ($interpretasi as $k => $v) { + $interpretasi[$k]['group_name_en'] = $this->translate_word($v['group_name']); + $subgroups = array(); + $sql = "SELECT Lcprep_InterpretasiSubgroupID as subgroup_id, + Lcprep_InterpretasiSubgroupName as subgroup_name, + Lcprep_InterpretasiSubgroupName as subgroup_name_en, + '' as childs + FROM lcprep_interpretasisubgroup + WHERE + Lcprep_InterpretasiSubgroupLcprep_InterpretasiGroupID = {$v['group_id']} AND Lcprep_InterpretasiSubgroupIsActive = 'Y'"; + //echo $sql; + $subgroups = $this->db_smartone->query($sql)->result_array(); + if (count($subgroups) > 0) { + foreach ($subgroups as $ki => $vi) { + $subgroups[$ki]['subgroup_name_en'] = $this->translate_word($vi['subgroup_name']); + $childs = array(); + + $sql = "SELECT IFNULL(Other_LcprepInterpretasiID,0) as xid, + IFNULL(Other_LcprepInterpretasiChex,'N') as chex, + IFNULL(Other_LcprepInterpretasiValue,'') as value, + IFNULL(Other_LcprepInterpretasiValueEng,'') as value_en, + Lcprep_InterpretasiID as id, + Lcprep_InterpretasiLcprep_InterpretasiSubgroupID as subgroup_id, + Lcprep_InterpretasiCode as code, + Lcprep_InterpretasiName as name, + Lcprep_InterpretasiName as name_en, + Lcprep_InterpretasiParentID as parent_id, + Lcprep_InterpretasiIsParent as is_parent, + Lcprep_InterpretasiHasResult as has_result, + Lcprep_InterpretasiTypeResult as type_result + FROM lcprep_interpretasi + LEFT JOIN other_lcprepinterpretasi ON Other_LcprepInterpretasiOther_LcprepID = {$header_id} AND + Other_LcprepInterpretasiLcprep_InterpretasiID = Lcprep_InterpretasiID AND + Other_LcprepInterpretasiIsActive = 'Y' + WHERE + Lcprep_InterpretasiLcprep_InterpretasiSubgroupID = {$vi['subgroup_id']} AND Lcprep_InterpretasiIsActive = 'Y' + GROUP BY Lcprep_InterpretasiID Order BY Lcprep_InterpretasiCode ASC"; + $childs = $this->db_smartone->query($sql)->result_array(); + if ($childs) { + foreach ($childs as $kc => $vc) { + $childs[$kc]['chex'] = $vc['chex'] == 'N' ? false : true; + $childs[$kc]['name_en'] = $this->translate_word($vc['name']); + } + } + $subgroups[$ki]['childs'] = $childs; + } + } + + $interpretasi[$k]['subgroups'] = $subgroups; + } + + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + + + + $rst = array('order' => $order, 'langs' => $langs, 'selected_lang' => $selected_lang, 'doctors' => $doctors, 'results' => $rows, 'other_results' => $other_rows, 'adekuasi' => $adeakuasi, 'kategoriumum' => $kategoriumum, 'interpretasi' => $interpretasi); + $this->sys_ok(["records" => $rst]); + } + + function translate_word($word) + { + $sql = "SELECT * + FROM translate_word + WHERE Translate_WordNat_LangID = '2' AND + BINARY Translate_WordFrom = '{$word}' AND + Translate_WordIsActive = 'Y' + LIMIT 1"; + $dt = $this->db_smartone->query($sql)->result_array(); + if (count($dt) > 0) { + return $dt[0]['Translate_WordTo']; + } else { + return $word; + } + } + + function getpapsmearresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT Other_PapSmearDetailsID as xid, + Other_PapSmearID as header_id, + Other_PapSmearT_OrderDetailID as orderdetail_id, + Other_PapSmearDetailsCode as code, + Other_PapSmearDetailsLabel as label, + Other_PapSmearDetailsResult as result, + IFNULL(Other_PapSmearM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_PapSmearM_DoctorID) OR Other_PapSmearM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_papsmear + JOIN other_papsmeardetails ON Other_PapSmearDetailsOther_PapSmearID = Other_PapSmearID AND Other_PapSmearDetailsIsActive = 'Y' + LEFT JOIN m_doctor ON Other_PapSmearM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_PapSmearT_OrderDetailID = {$id} AND Other_PapSmearIsActive = 'Y' + GROUP BY Other_PapSmearDetailsID + ORDER BY Other_PapSmearDetailsCode ASC"; + //echo $sql; + $rows = $this->db_smartone->query($sql)->result_array(); + if (!$rows) { + $rows = array( + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'A', + 'label' => 'Makroskopik', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ), + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'B', + 'label' => 'Mikroskopik', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ), + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'C', + 'label' => 'Kesimpulan', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ) + ); + } + + $header_id = $rows[0]['header_id']; + $sql = "SELECT Other_PapSmearMaturasiID as xid, + Other_PapSmearMaturasiValue as value + FROM other_papsmearmaturasi + WHERE + Other_PapSmearMaturasiOther_PapSmearID = {$header_id} AND + Other_PapSmearMaturasiIsActive = 'Y' + "; + //echo $sql; + $dt_maturasi = $this->db_smartone->query($sql)->row_array(); + if (!$dt_maturasi) { + $maturasi = array('xid' => '0', 'value' => array('', '', '')); + } else { + $value = explode('/', $dt_maturasi['value']); + $maturasi = array('xid' => $dt_maturasi['xid'], 'value' => $value); + } + + $sql = "SELECT IFNULL(Other_PapSmearBahanID,0) as xid, + M_PapSmearBahanID as bahan_id, + M_PapSmearBahanName as name, + IF(ISNULL(Other_PapSmearBahanID),'N','Y') as selected + FROM m_papsmearbahan + LEFT JOIN other_papsmearbahan ON Other_PapSmearBahanM_PapSmearBahanID = M_PapSmearBahanID AND + Other_PapSmearBahanOther_PapSmearID = {$header_id} AND + Other_PapSmearBahanIsActive = 'Y' + WHERE + M_PapSmearBahanIsActive = 'Y' + ORDER BY M_PapSmearBahanID ASC + "; + //echo $sql; + $bahans = $this->db_smartone->query($sql)->result_array(); + + $sql = "SELECT IFNULL(Other_PapsmearCategoryID,0) as xid, + M_PapSmearCategoryID as category_id, + M_PapSmearCategoryName as name, + IF(ISNULL(Other_PapsmearCategoryID),'N','Y') as selected + FROM m_papsmearcategory + LEFT JOIN other_papsmearcategory ON Other_PapsmearCategoryM_PapSmearCategoryID = M_PapSmearCategoryID AND + Other_PapsmearCategoryOther_PapSmearID = {$header_id} AND + Other_PapsmearCategoryIsActive = 'Y' + WHERE + M_PapSmearCategoryIsActive = 'Y' + ORDER BY M_PapSmearCategoryID ASC + "; + //echo $sql; + $categories = $this->db_smartone->query($sql)->result_array(); + + $sql = "SELECT IFNULL(Other_PapSmearCheckID,0) as xid, + M_PapSmearCheckID as check_id, + M_PapSmearCheckLabel as name, + IF(ISNULL(Other_PapSmearCheckID),'N','Y') as selected, + Other_PapSmearCheckNote as note + FROM m_papsmearcheck + LEFT JOIN other_papsmearcheck ON Other_PapSmearCheckM_PapSmearCheckID = M_PapSmearCheckID AND + Other_PapSmearCheckOther_PapSmearID = {$header_id} AND + Other_PapSmearCheckIsActive = 'Y' + WHERE + M_PapSmearCheckIsActive = 'Y' + ORDER BY M_PapSmearCheckCode ASC + "; + $checks = $this->db_smartone->query($sql)->result_array(); + + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $rst = array('doctors' => $doctors, 'checks' => $checks, 'bahans' => $bahans, 'categories' => $categories, 'maturasi' => $maturasi, 'results' => $rows); + $this->sys_ok(["records" => $rst]); + } + + function saveresult_lcprep() + { + $prm = $this->sys_input; + $detail_id = $prm['detail_id']; + $doctor_id = $prm['doctor']; + $adekuasi = $prm['adekuasi']; + $kategoriumum = $prm['kategoriumum']; + $interpretasi = $prm['interpretasi']; + $results = $prm['results']; + $selected_lang = $prm['selected_lang']; + $other_results = $prm['other_results']; + + $userid = $this->sys_user['M_UserID']; + + $header_id = 0; + $sql = "SELECT * FROM other_lcprep WHERE Other_LcprepT_orderDetailID = ? AND Other_LcprepIsActive = 'Y'"; + $dt_header = $this->db_smartone->query($sql, array($detail_id))->row_array(); + if ($dt_header) { + $header_id = $dt_header['Other_LcprepID']; + } + if ($header_id == 0) { + $sql = "INSERT INTO other_lcprep( + Other_LcprepT_orderDetailID, + Other_LcprepM_DoctorID, + Other_LcprepUserID, + Other_LcprepCreated + ) + VALUES( + ?, + ?, + ?, + NOW() + )"; + //echo $sql; + $query = $this->db_smartone->query($sql, array($detail_id, $doctor_id, $userid)); + if(!$query){ + echo $this->db_smartone->last_query(); + exit; + } + $header_id = $this->db_smartone->insert_id(); + } else { + $sql = "UPDATE other_lcprep SET Other_LcprepM_DoctorID = ?, Other_LcprepUserID = ? WHERE Other_LcprepID = ?"; + $query = $this->db_smartone->query($sql, array($doctor_id, $userid, $header_id)); + if(!$query){ + echo $this->db_smartone->last_query(); + exit; + } + } + + + + if ($adekuasi) { + foreach ($adekuasi as $k => $v) { + $selected = $v['chex'] ? 'Y' : 'N'; + if (intval($v['xid'] == 0)) { + $sql = "UPDATE other_lcprepadekuasi SET Other_LcprepAdekuasiIsActive = 'N' + WHERE + Other_LcprepAdekuasiOther_LcprepID = ? AND + Other_LcprepAdekuasiIsActive = 'Y' AND + Other_LcprepAdekuasiLcprep_AdekuasiID = ?"; + $query = $this->db_smartone->query($sql, array($header_id, $v['id'])); + if(!$query){ + echo $this->db_smartone->last_query(); + exit; + } + $sql = "INSERT INTO other_lcprepadekuasi ( + Other_LcprepAdekuasiOther_LcprepID, + Other_LcprepAdekuasiLcprep_AdekuasiID, + Other_LcprepAdekuasiChex, + Other_LcprepAdekuasiUserID, + Other_LcprepAdekuasiCreated + ) + VALUES( + ?, + ?, + ?, + ?, + NOW() + )"; + $query = $this->db_smartone->query($sql, array($header_id, $v['id'], $selected, $userid)); + if(!$query){ + echo $this->db_smartone->last_query(); + exit; + } + //echo $sql; + } + if (intval($v['xid'] != 0)) { + + $sql = "UPDATE other_lcprepadekuasi SET + Other_LcprepAdekuasiChex = ?, + Other_LcprepAdekuasiUserID = ? + WHERE + Other_LcprepAdekuasiID = ? + "; + $query = $this->db_smartone->query($sql, array($selected, $userid, $v['xid'])); + if(!$query){ + echo $this->db_smartone->last_query(); + exit; + } + } + + //echo $sql; + } + } + + if ($kategoriumum) { + foreach ($kategoriumum as $k => $v) { + $selected = $v['chex'] ? 'Y' : 'N'; + if (intval($v['xid'] == 0)) { + $sql = "UPDATE other_lcprepkategoriumum SET Other_LcprepKategoriUmumIsActive = 'N' + WHERE + Other_LcprepKategoriUmumOther_LcprepID = ? AND + Other_LcprepKategoriUmumLcprep_KategoriUmumID = ? AND + Other_LcprepKategoriUmumIsActive = 'Y' + "; + $query = $this->db_smartone->query($sql, array($header_id, $v['id'])); + if(!$query){ + echo $this->db_smartone->last_query(); + exit; + } + $sql = "INSERT INTO other_lcprepkategoriumum ( + Other_LcprepKategoriUmumOther_LcprepID, + Other_LcprepKategoriUmumLcprep_KategoriUmumID, + Other_LcprepKategoriUmumChex, + Other_LcprepKategoriUmumUserID, + Other_LcprepKategoriUmumCreated + ) + VALUES( + ?, + ?, + ?, + ?, + NOW() + )"; + $query = $this->db_smartone->query($sql, array($header_id, $v['id'], $selected, $userid)); + if(!$query){ + echo $this->db_smartone->last_query(); + exit; + } + } + if (intval($v['xid'] != 0)) { + $sql = "UPDATE other_lcprepkategoriumum SET + Other_LcprepKategoriUmumChex = ?, + Other_LcprepKategoriUmumUserID = ? + WHERE + Other_LcprepKategoriUmumID = ? + "; + $query = $this->db_smartone->query($sql, array($selected, $userid, $v['xid'])); + if(!$query){ + echo $this->db_smartone->last_query(); + exit; + } + } + + //echo $sql; + } + } + + if (count($results) > 0 && intval($selected_lang) == 1) { + foreach ($results as $k => $v) { + if (intval($v['xid'] == 0)) { + $sql = "UPDATE other_lcprepdetails SET Other_LcprepDetailsIsActive = 'N' + WHERE + Other_LcprepDetailsOther_LcprepID = ? AND + Other_LcprepDetailsCode = ? AND + Other_LcprepDetailsIsActive = 'Y'"; + $query = $this->db_smartone->query($sql, array($header_id, $v['code'])); + if(!$query){ + echo $this->db_smartone->last_query(); + exit; + } + $sql = "INSERT INTO other_lcprepdetails ( + Other_LcprepDetailsOther_LcprepID, + Other_LcprepDetailsCode, + Other_LcprepDetailsLabel, + Other_LcprepDetailsResult, + Other_LcprepDetailsUserID, + Other_LcprepDetailsCreated + ) + VALUES( + ?, + ?, + ?, + ?, + ?, + NOW() + )"; + $query = $this->db_smartone->query($sql, array($header_id, $v['code'], $v['label'], $v['result'], $userid)); + if(!$query){ + echo $this->db_smartone->last_query(); + exit; + } + } + if (intval($v['xid'] != 0)) { + $sql = "UPDATE other_lcprepdetails SET + Other_LcprepDetailsCode = ?, + Other_LcprepDetailsLabel = ?, + Other_LcprepDetailsResult = ?, + Other_LcprepDetailsUserID = ? + WHERE + Other_LcprepDetailsID = ? + "; + $query = $this->db_smartone->query($sql, array($v['code'], $v['label'], $v['result'], $userid, $v['xid'])); + if(!$query){ + echo $this->db_smartone->last_query(); + exit; + } + } + //echo $sql; + } + } + + if (count($other_results) > 0 && intval($selected_lang) == 2) { + foreach ($other_results as $k => $v) { + if (intval($v['xid'] == 0)) { + $sql = "UPDATE other_lcprepdetails_lang SET Other_LcprepDetailsLangsIsActive = 'N' + WHERE + Other_LcprepDetailsLangsOther_LcprepID = ? AND + Other_LcprepDetailsLangsCode = ? AND + Other_LcprepDetailsLangsIsActive = 'Y'"; + $query = $this->db_smartone->query($sql, array($header_id, $v['code'])); + if(!$query){ + echo $this->db_smartone->last_query(); + exit; + } + //echo $this->db_smartone->last_query(); + $sql = "INSERT INTO other_lcprepdetails_lang ( + Other_LcprepDetailsLangsOther_LcprepID, + Other_LcprepDetailsLangsCode, + Other_LcprepDetailsLangsLabel, + Other_LcprepDetailsLangsResult, + Other_LcprepDetailsLangsCreatedUserID, + Other_LcprepDetailsLangsCreated + ) + VALUES( + ?, + ?, + ?, + ?, + ?, + NOW() + )"; + $query = $this->db_smartone->query($sql, array($header_id, $v['code'], $v['label'], $v['result'], $userid)); + if(!$query){ + echo $this->db_smartone->last_query(); + exit; + } + //echo $this->db_smartone->last_query(); + } + if (intval($v['xid'] != 0)) { + $sql = "UPDATE other_lcprepdetails_lang SET + Other_LcprepDetailsLangsCode = ?, + Other_LcprepDetailsLangsLabel = ?, + Other_LcprepDetailsLangsResult = ?, + Other_LcprepDetailsLangsUpdatedUserID = ?, + Other_LcprepDetailsLangsUpdated = NOW() + WHERE + Other_LcprepDetailsLangsID = ? + "; + $query = $this->db_smartone->query($sql, array($v['code'], $v['label'], $v['result'], $userid, $v['xid'])); + if(!$query){ + echo $this->db_smartone->last_query(); + exit; + } + } + //echo $sql; + } + } + + if ($interpretasi) { + foreach ($interpretasi as $k => $v) { + if (count($v['subgroups']) > 0) { + foreach ($v['subgroups'] as $ik => $iv) { + if (count($iv['childs']) > 0) { + foreach ($iv['childs'] as $iik => $iiv) { + if (intval($iiv['xid'] == 0)) { + $chex = $iiv['chex'] ? 'Y' : 'N'; + $sql = "UPDATE other_lcprepinterpretasi SET Other_LcprepInterpretasiIsActive = 'N' + WHERE + Other_LcprepInterpretasiOther_LcprepID = ? AND + Other_LcprepInterpretasiLcprep_InterpretasiID = ? AND + Other_LcprepInterpretasiIsActive = 'Y'"; + $query = $this->db_smartone->query($sql, array($header_id, $iiv['id'])); + if(!$query){ + echo $this->db_smartone->last_query(); + exit; + } + $sql = "INSERT INTO other_lcprepinterpretasi ( + Other_LcprepInterpretasiOther_LcprepID, + Other_LcprepInterpretasiLcprep_InterpretasiID, + Other_LcprepInterpretasiChex, + Other_LcprepInterpretasiValue, + Other_LcprepInterpretasiValueEng, + Other_LcprepInterpretasiUserID, + Other_LcprepInterpretasiCreated + ) + VALUES( + ?, + ?, + ?, + ?, + ?, + ?, + NOW() + )"; + $query = $this->db_smartone->query($sql, array($header_id, $iiv['id'], $chex, $iiv['value'], $iiv['value_en'], $userid)); + if(!$query){ + echo $this->db_smartone->last_query(); + exit; + } + } + + if (intval($iiv['xid'] != 0)) { + $chex = $iiv['chex'] ? 'Y' : 'N'; + $sql = "UPDATE other_lcprepinterpretasi SET + Other_LcprepInterpretasiChex = ?, + Other_LcprepInterpretasiValue = ?, + Other_LcprepInterpretasiValueEng = ?, + Other_LcprepInterpretasiUserID = ? + WHERE + Other_LcprepInterpretasiID = ? + "; + $query = $this->db_smartone->query($sql, array($chex, $iiv['value'], $iiv['value_en'], $userid, $iiv['xid'])); + if(!$query){ + echo $this->db_smartone->last_query(); + exit; + } + //echo $sql; + + } + } + } + } + } + //echo $sql; + } + } + + + $result = array("total" => 1, "records" => array(), "sql" => ''); + $this->sys_ok($result); + exit; + } + + function saveresult_papsmear() + { + $prm = $this->sys_input; + $detail_id = $prm['detail_id']; + $doctor_id = $prm['doctor']; + $checks = $prm['checks']; + $maturasi = $prm['maturasi']; + $bahans = $prm['bahans']; + $categories = $prm['categories']; + $results = $prm['results']; + + $userid = $this->sys_user['M_UserID']; + + $header_id = 0; + $sql = "SELECT * FROM other_papsmear WHERE Other_PapSmearT_OrderDetailID = {$detail_id} AND Other_PapSmearIsActive = 'Y'"; + $dt_header = $this->db_smartone->query($sql)->row_array(); + if ($dt_header) { + $header_id = $dt_header['Other_PapSmearID']; + } + if ($header_id == 0) { + $sql = "INSERT INTO other_papsmear( + Other_PapSmearT_OrderDetailID, + Other_PapSmearM_DoctorID, + Other_PapSmearUserID, + Other_PapSmearCreated + ) + VALUES( + {$detail_id}, + {$doctor_id}, + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } else { + $sql = "UPDATE other_papsmear SET Other_PapSmearM_DoctorID = {$doctor_id}, Other_PapSmearUserID = {$userid} WHERE Other_PapSmearID = {$header_id}"; + $this->db_smartone->query($sql); + } + + if ($checks) { + foreach ($checks as $k => $v) { + if (intval($v['xid']) == 0 && $v['selected'] === 'Y') { + $sql = "INSERT INTO other_papsmearcheck ( + Other_PapSmearCheckOther_PapSmearID, + Other_PapSmearCheckM_PapSmearCheckID, + Other_PapSmearCheckNote, + Other_PapSmearCheckUserID, + Other_PapSmearCheckCreated + ) + VALUES( + {$header_id}, + {$v['check_id']}, + '{$v['note']}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if (intval($v['xid']) != 0 && $v['selected'] === 'N') { + $sql = "UPDATE other_papsmearcheck SET + Other_PapSmearCheckIsActive = 'N', + Other_PapSmearCheckUserID = {$userid} + WHERE + Other_PapSmearCheckID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + if (intval($v['xid']) != 0 && $v['selected'] === 'Y') { + $sql = "UPDATE other_papsmearcheck SET + Other_PapSmearCheckNote = '{$v['note']}', + Other_PapSmearCheckUserID = {$userid} + WHERE + Other_PapSmearCheckID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + //echo $sql; + } + } + + if ($maturasi) { + if (intval($maturasi['xid']) == 0) { + $value = join("/", $maturasi['value']); + $sql = "INSERT INTO other_papsmearmaturasi ( + Other_PapSmearMaturasiOther_PapSmearID, + Other_PapSmearMaturasiValue, + Other_PapSmearMaturasiUserID, + Other_PapSmearMaturasiCreated + ) + VALUE( + {$header_id}, + '{$value}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + //echo $sql; + } + if (intval($maturasi['xid']) != 0) { + $value = join("/", $maturasi['value']); + $sql = "UPDATE other_papsmearmaturasi SET + Other_PapSmearMaturasiValue = '{$value}', + Other_PapSmearMaturasiUserID = {$userid} + WHERE + Other_PapSmearMaturasiID = {$maturasi['xid']}"; + // echo $sql; + $this->db_smartone->query($sql); + } + } + + if ($bahans) { + foreach ($bahans as $k => $v) { + if (intval($v['xid']) == 0 && $v['selected'] === 'Y') { + $sql = "INSERT INTO other_papsmearbahan ( + Other_PapSmearBahanOther_PapSmearID, + Other_PapSmearBahanM_PapSmearBahanID, + Other_PapSmearBahanUserID, + Other_PapSmearBahanCreated + ) + VALUES( + {$header_id}, + {$v['bahan_id']}, + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if (intval($v['xid']) != 0 && $v['selected'] === 'N') { + $sql = "UPDATE other_papsmearbahan SET + Other_PapSmearBahanIsActive = 'N', + Other_PapsmearCategoryUserID = {$userid} + WHERE + Other_PapSmearBahanID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + if (intval($v['xid']) != 0 && $v['selected'] === 'Y') { + $sql = "UPDATE other_papsmearbahan SET + Other_PapSmearBahanIsActive = 'Y', + Other_PapsmearCategoryUserID = {$userid} + WHERE + Other_PapSmearBahanID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + //echo $sql; + } + } + + if ($categories) { + foreach ($categories as $k => $v) { + if (intval($v['xid']) == 0 && $v['selected'] === 'Y') { + $sql = "INSERT INTO other_papsmearcategory ( + Other_PapsmearCategoryOther_PapSmearID, + Other_PapsmearCategoryM_PapSmearCategoryID, + Other_PapsmearCategoryUserID, + Other_PapsmearCategoryCreated + ) + VALUES( + {$header_id}, + {$v['category_id']}, + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if (intval($v['xid']) != 0 && $v['selected'] === 'N') { + $sql = "UPDATE other_papsmearcategory SET + Other_PapsmearCategoryIsActive = 'N', + Other_PapsmearCategoryUserID = {$userid} + WHERE + Other_PapsmearCategoryID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + //echo $sql; + if (intval($v['xid']) != 0 && $v['selected'] === 'Y') { + $sql = "UPDATE other_papsmearcategory SET + Other_PapsmearCategoryIsActive = 'Y', + Other_PapsmearCategoryUserID = {$userid} + WHERE + Other_PapsmearCategoryID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + } + } + + if ($results) { + foreach ($results as $k => $v) { + if (intval($v['xid']) == 0) { + $sql = "INSERT INTO other_papsmeardetails ( + Other_PapSmearDetailsOther_PapSmearID, + Other_PapSmearDetailsCode, + Other_PapSmearDetailsLabel, + Other_PapSmearDetailsResult, + Other_PapSmearDetailsUserID, + Other_PapSmearDetailsCreated + ) + VALUES( + {$header_id}, + '{$v['code']}', + '{$v['label']}', + '{$v['result']}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if (intval($v['xid']) != 0) { + $sql = "UPDATE other_papsmeardetails SET + Other_PapSmearDetailsCode = '{$v['code']}', + Other_PapSmearDetailsLabel = '{$v['label']}', + Other_PapSmearDetailsResult = '{$v['result']}', + Other_PapSmearDetailsUserID = {$userid} + WHERE + Other_PapSmearDetailsID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + //echo $sql; + } + } + + $result = array("total" => 1, "records" => array(), "sql" => ''); + $this->sys_ok($result); + exit; + } + + function saveresult_fna() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = $inp['doctor']; + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + if ($prm[0]['xid'] == '0') { + $sql = "INSERT INTO other_fna( + Other_FNAM_DoctorID, + Other_FNAT_OrderDetailID, + Other_FNAUserID, + Other_FNACreated + ) + VALUES( + {$doctor_id}, + {$prm[0]['orderdetail_id']}, + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } else { + $sql = "SELECT * FROM other_fna WHERE Other_FNAT_OrderDetailID = {$prm[0]['orderdetail_id']} AND Other_FNAIsActive = 'Y'"; + $data_header = $this->db_smartone->query($sql)->row_array(); + $header_id = $data_header['Other_FNAID']; + $sql = "UPDATE other_fna SET + Other_FNAM_DoctorID = {$doctor_id}, + Other_FNAUserID = {$userid} + WHERE + Other_FNAID = {$header_id}"; + $this->db_smartone->query($sql); + } + foreach ($prm as $k => $v) { + if ($v['xid'] == '0') { + $results = str_replace("'", "\\'", $v['result']); + $sql = "INSERT INTO other_fnadetails( + Other_FNADetailsOther_FNAID , + Other_FNADetailsCode, + Other_FNADetailsLabel, + Other_FNADetailsResult, + Other_FNADetailsCreated, + Other_FNADetailsUserID + ) + VALUES( + {$header_id}, + '{$v['code']}', + '{$v['label']}', + '{$results}', + NOW(), + {$userid} + )"; + $query = $this->db_smartone->query($sql); + } else { + $results = str_replace("'", "\\'", $v['result']); + $sql = "UPDATE other_fnadetails SET + Other_FNADetailsResult = '{$results}', + Other_FNADetailsUserID = {$userid} + WHERE + Other_FNADetailsID = {$v['xid']}"; + $query = $this->db_smartone->query($sql); + } + } + + $result = array("total" => 1, "records" => array(), "sql" => ''); + $this->sys_ok($result); + exit; + } + + function saveresult_patologianatomy() + { + + $inp = $this->sys_input; + $doctor_id = $inp['doctor']; + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + if ($inp['xid'] == '0') { + $sql = "INSERT INTO other_patologi_anatomy( + Other_PatologiAnatomyT_OrderDetailID, + Other_PatologiAnatomyM_DoctorID, + Other_PatologiAnatomyNoSediaan, + Other_PatologiAnatomyDiagnosaKlinis, + Other_PatologiAnatomyKeteranganKlinis, + Other_PatologiAnatomyLokasiOrgan, + Other_PatologiAnatomyMakroskopik, + Other_PatologiAnatomyMikroskopik, + Other_PatologiAnatomyKesimpulan, + Other_PatologiAnatomyUserID, + Other_PatologiAnatomyCreated + ) + VALUES( + {$inp['detail_id']}, + {$doctor_id}, + '{$inp['no_sediaan']}', + '{$inp['diagnosa']}', + '{$inp['klinis']}', + '{$inp['lokasi']}', + '{$inp['makroskopik']}', + '{$inp['mikroskopik']}', + '{$inp['kesimpulan']}', + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } else { + $sql = "UPDATE other_patologi_anatomy SET + Other_PatologiAnatomyM_DoctorID = ?, + Other_PatologiAnatomyNoSediaan = ?, + Other_PatologiAnatomyKeteranganKlinis = ?, + Other_PatologiAnatomyDiagnosaKlinis = ?, + Other_PatologiAnatomyLokasiOrgan = ?, + Other_PatologiAnatomyMakroskopik = ?, + Other_PatologiAnatomyMikroskopik = ?, + Other_PatologiAnatomyKesimpulan = ?, + Other_PatologiAnatomyUserID = ? + WHERE + Other_PatologiAnatomyT_OrderDetailID = ? AND Other_PatologiAnatomyIsActive = 'Y'"; + $this->db_smartone->query($sql, array( + $doctor_id, + $inp['no_sediaan'], + $inp['klinis'], + $inp['diagnosa'], + $inp['lokasi'], + $inp['makroskopik'], + $inp['mikroskopik'], + $inp['kesimpulan'], + $userid, + $inp['detail_id'] + )); + //echo $this->db_smartone->last_query(); + + } + + $inp_rst = array( + 'doctor_id' => $doctor_id, + 'no_sediaan' => $inp['no_sediaan'], + 'klinis' => $inp['klinis'], + 'diagnosa' => $inp['diagnosa'], + 'lokasi' => $inp['lokasi'], + 'makroskopik' => $inp['makroskopik'], + 'mikroskopik' => $inp['mikroskopik'], + 'kesimpulan' => $inp['kesimpulan'] + ); + $log_json = json_encode($inp_rst); + + $sql = "INSERT INTO log_other_patologianatomy ( + Log_OtherPatologiAnatomyT_OrderDetailID, + Log_OtherPatologiAnatomyDateTime, + Log_OtherPatologiAnatomySON, + Log_OtherPatologiAnatomyUserID + )VALUE( + {$inp['detail_id']}, + NOW(), + '{$log_json}', + {$userid} + )"; + $this->db_smartone->query($sql); + //echo $this->db_smartone->last_query(); + + $result = array("total" => 1, "records" => array(), "sql" => ''); + $this->sys_ok($result); + exit; + } + + function saveresult_cytologi() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = $inp['doctor']; + + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + if ($prm[0]['xid'] == '0') { + $sql = "INSERT INTO other_cytologi( + Other_CytologiT_OrderDetailID, + Other_CytologiM_DoctorID, + Other_CytologiUserID, + Other_CytologiCreated + ) + VALUES( + {$prm[0]['orderdetail_id']}, + {$doctor_id}, + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } else { + $sql = "SELECT * FROM other_cytologi WHERE Other_CytologiT_OrderDetailID = {$prm[0]['orderdetail_id']} AND Other_CytologiIsActive = 'Y'"; + $data_header = $this->db_smartone->query($sql)->row_array(); + $header_id = $data_header['Other_CytologiID']; + $sql = "UPDATE other_cytologi SET + Other_CytologiM_DoctorID = {$doctor_id}, + Other_CytologiUserID = {$userid} + WHERE + Other_CytologiID = {$header_id}"; + $this->db_smartone->query($sql); + } + foreach ($prm as $k => $v) { + if ($v['xid'] == '0') { + $results = str_replace("'", "\\'", $v['result']); + $sql = "INSERT INTO other_cytologidetails( + Other_CytologiDetailsOther_CytologiID , + Other_CytologiDetailsCode, + Other_CytologiDetailsLabel, + Other_CytologiDetailsResult, + Other_CytologiDetailsCreated, + Other_CytologiDetailsUserID + ) + VALUES( + {$header_id}, + '{$v['code']}', + '{$v['label']}', + '{$results}', + NOW(), + {$userid} + )"; + $query = $this->db_smartone->query($sql); + } else { + $results = str_replace("'", "\\'", $v['result']); + $sql = "UPDATE other_cytologidetails SET + Other_CytologiDetailsResult = '{$results}', + Other_CytologiDetailsUserID = {$userid} + WHERE + Other_CytologiDetailsID = {$v['xid']}"; + $query = $this->db_smartone->query($sql); + } + } + + $result = array("total" => 1, "records" => array(), "sql" => ''); + $this->sys_ok($result); + exit; + } + + function saveresult_mikro() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = $inp['doctor']; + $backteria_id = $inp['bacteria']; + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + + if ($inp['result_value'] != 'Negatif' && $inp['result_value'] != 'Positif') { + $prm['result_value'] = $prm['result_other']; + } else { + $prm['result_value'] = $inp['result_value']; + } + + if ($prm['xid'] == '0') { + $sql = "INSERT INTO other_mikro( + Other_MikroM_DoctorID, + Other_MikroResult, + Other_MikroT_BacteriaID, + Other_MikroT_OrderDetailID, + Other_MikroHasilBiakan, + Other_MikroSampleTypeName, + Other_MikroUserID, + Other_MikroCreated + ) + VALUES( + {$doctor_id}, + '{$prm['result_value']}', + {$backteria_id}, + {$prm['orderdetail_id']}, + '{$prm['hasil_biakan']}', + '{$prm['sample_name']}', + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } else { + $sql = "SELECT * FROM other_mikro WHERE Other_MikroT_OrderDetailID = {$prm['orderdetail_id']} AND Other_MikroIsActive = 'Y'"; + $data_header = $this->db_smartone->query($sql)->row_array(); + $header_id = $data_header['Other_MikroID']; + $sql = "UPDATE other_mikro SET + Other_MikroResult = '{$prm['result_value']}', + Other_MikroM_DoctorID = {$doctor_id}, + Other_MikroT_BacteriaID = {$backteria_id}, + Other_MikroHasilBiakan = '{$prm['hasil_biakan']}', + Other_MikroSampleTypeName = '{$prm['sample_name']}', + Other_MikroUserID = {$userid} + WHERE + Other_MikroID = {$header_id}"; + //echo $sql; + $this->db_smartone->query($sql); + } + + + + $sql = "UPDATE other_mikrodetails SET Other_MikroDetailsIsActive = 'N', Other_MikroDetailsUserID = 0 WHERE Other_MikroDetailsOther_MikroID = {$header_id}"; + $this->db_smartone->query($sql); + + $results = $prm['details']; + if ($inp['result_value'] == 'Positif') { + foreach ($results as $k => $v) { + if ($v['xid'] == '0') { + $sql = "INSERT INTO other_mikrodetails( + Other_MikroDetailsOther_MikroID , + Other_MikroDetailsT_AntibioticID, + Other_MikroDetailsValue, + Other_MikroDetailsNote, + Other_MikroDetailsCreated, + Other_MikroDetailsUserID + ) + VALUES( + {$header_id}, + '{$v['T_AntibioticID']}', + '{$v['value']}', + '{$v['note']}', + NOW(), + {$userid} + )"; + $query = $this->db_smartone->query($sql); + } else { + $sql = "UPDATE other_mikrodetails SET + Other_MikroDetailsT_AntibioticID = '{$v['T_AntibioticID']}', + Other_MikroDetailsValue = '{$v['value']}', + Other_MikroDetailsNote = '{$v['note']}', + Other_MikroDetailsIsActive = 'Y', + Other_MikroDetailsUserID = {$userid} + WHERE + Other_MikroDetailsID = {$v['xid']}"; + //echo $sql; + $query = $this->db_smartone->query($sql); + } + } + } + + + $result = array("total" => 1, "records" => array(), "sql" => ''); + $this->sys_ok($result); + exit; + } + + + function get_doctors_preparasi_sperma() + { + $prm = $this->sys_input; + // $id = $prm["id"]; + + $sql = " SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 10 AND + M_DoctorSOIsActive = 'Y' + ORDER BY M_DoctorName ASC"; + //echo $sql; + $query = $this->db_smartone->query($sql); + $rows = $query->result_array(); + $sql = " + SELECT '0' as id, 'Belum memilih metode' as name + UNION + SELECT M_MethodeSpermaID as id, M_MethodeSpermaName as name + FROM m_methodesperma + WHERE + M_MethodeSpermaIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $methodes = $this->db_smartone->query($sql)->result_array(); + + + $this->sys_ok(["records" => $rows, "methodes" => $methodes]); + } + + + function getpreparasispermaresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT other_preparasisperma.*, + Other_PreparasiSpermaID as xid, + Other_PreparasiSpermaT_OrderDetailID as orderdetail_id, + IFNULL(Other_PreparasiSpermaM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_PreparasiSpermaM_DoctorID) OR Other_PreparasiSpermaM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name, + IFNULL(M_MethodeSpermaID,0) as methode_id, + IFNULL(M_MethodeSpermaName,'') as methode_name + FROM other_preparasisperma + LEFT JOIN m_doctor ON Other_PreparasiSpermaM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + LEFT JOIN m_methodesperma ON Other_PreparasiSpermaM_MethodeSpermaID = M_MethodeSpermaID AND + M_MethodeSpermaIsActive = 'Y' + WHERE + Other_PreparasiSpermaT_OrderDetailID = {$id} AND Other_PreparasiSpermaIsActive = 'Y' + GROUP BY Other_PreparasiSpermaID"; + $query = $this->db_smartone->query($sql); + + if ($query) { + $rows = $query->row_array(); + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 10 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $sql = " + SELECT '0' as id, 'Belum memilih metode' as name + UNION + SELECT M_MethodeSpermaID as id, M_MethodeSpermaName as name + FROM m_methodesperma + WHERE + M_MethodeSpermaIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $methodes = $this->db_smartone->query($sql)->result_array(); + $images = array(); + $sql = "SELECT Other_PreparasiSpermaImgID as xid, + Other_PreparasiSpermaImgType as type, + CONCAT('/one-media/one-image-nonlab/',Other_PreparasiSpermaImgNewName) as image_url + FROM t_orderdetail + JOIN other_preparasisperma_img ON Other_PreparasiSpermaImgT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND + Other_PreparasiSpermaImgIsActive = 'Y' + WHERE + T_OrderDetailID = {$id} AND + T_OrderDetailIsActive = 'Y' + GROUP BY Other_PreparasiSpermaImgID"; + //echo $sql; + $images = $this->db_smartone->query($sql)->result_array(); + + $rst = array('doctors' => $doctors, 'methodes' => $methodes, 'results' => $rows, 'images' => $images); + $this->sys_ok(["records" => $rst]); + } else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + + function uploadimage_preparasi_sperma() + { + if (! $this->isLogin) { + $this->sys_error("Invalid Token"); + exit; + } + + $userid = $this->sys_user["M_UserID"]; + $data = []; + //print_r($_SERVER); + + $prm = $this->sys_input; + $orderid = $this->input->post('orderid'); + $type = $this->input->post('type'); + $labnumber = $this->input->post('labnumber'); + $sql = "UPDATE other_preparasisperma_img SET + Other_PreparasiSpermaImgIsActive = 'N', + Other_PreparasiSpermaImgUserID = {$userid} + WHERE + Other_PreparasiSpermaImgT_OrderHeaderID = {$orderid} AND + Other_PreparasiSpermaImgType = '{$type}'"; + //echo $sql; + $this->db_onedev->query($sql); + //$config['upload_path'] = 'assets/'; + + $path = '/home/one/project/one/one-media/one-image-nonlab/'; + //echo $path; + $config['upload_path'] = $path; + $config['allowed_types'] = 'jpg|jpeg|png|gif'; + + $config['max_size'] = '10000'; + $count = count($_FILES['files']['name']); + //echo $count; + $this->load->library('upload', $config); + + $error = []; + for ($i = 0; $i < $count; $i++) { + + + if (!empty($_FILES['files']['name'][$i])) { + + + + $_FILES['file']['name'] = $_FILES['files']['name'][$i]; + + $_FILES['file']['type'] = $_FILES['files']['type'][$i]; + + $_FILES['file']['tmp_name'] = $_FILES['files']['tmp_name'][$i]; + + $_FILES['file']['error'] = $_FILES['files']['error'][$i]; + + $_FILES['file']['size'] = $_FILES['files']['size'][$i]; + + + + $namex = $orderid . '-' . $labnumber . '-' . $this->generateRandomString(5); + //echo $namex; + + $config['file_name'] = $namex; + $this->upload->initialize($config); + //echo $config['file_name'] ; + + + + + + if ($this->upload->do_upload('file')) { + + $uploadData = $this->upload->data(); + + $filename = $uploadData['file_name']; + //echo $filename; + + + $sql = "INSERT INTO other_preparasisperma_img ( + Other_PreparasiSpermaImgT_OrderHeaderID, + Other_PreparasiSpermaImgType, + Other_PreparasiSpermaImgOldName, + Other_PreparasiSpermaImgNewName, + Other_PreparasiSpermaImgCreated, + Other_PreparasiSpermaImgUserID + ) + VALUES( + {$orderid}, + '{$type}', + '{$_FILES['files']['name'][$i]}', + '{$filename}', + NOW(), + {$userid} + + )"; + //echo $sql; + $this->db_onedev->query($sql); + $xlast_id = $this->db_onedev->insert_id(); + $data['totalFiles'][] = array('xid' => $xlast_id, 'type' => $type, 'image_url' => '/one-media/one-image-nonlab/' . $filename); + } else { + $error = array('error' => $this->upload->display_errors()); + } + } + } + + $result = array("total" => count($data['totalFiles']), "records" => $data['totalFiles'], 'errors' => $error); + $this->sys_ok($result); + } + + + function saveresult_preparasi_sperma() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = isset($inp['doctor']) ? $inp['doctor'] : 0; + $methode_id = isset($inp['methode']) ? $inp['methode'] : 0; + $orderdetail_id = $inp['orderdetailid']; + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + if ($prm['xid'] == '0') { + $sql = "INSERT INTO other_preparasisperma( + Other_PreparasiSpermaM_DoctorID, + Other_PreparasiSpermaT_OrderDetailID, + Other_PreparasiSpermaPreMotilitasA, + Other_PreparasiSpermaPreMotilitasB, + Other_PreparasiSpermaPreMotilitasC, + Other_PreparasiSpermaPreKonsentrasi, + Other_PreparasiSpermaPreKontaminan, + Other_PreparasiSpermaPostMotilitasA, + Other_PreparasiSpermaPostMotilitasB, + Other_PreparasiSpermaPostMotilitasC, + Other_PreparasiSpermaPostKonsentrasi, + Other_PreparasiSpermaPostKontaminan, + Other_PreparasiSpermaPreVolume, + Other_PreparasiSpermaPostVolume, + Other_PreparasiSpermaM_MethodeSpermaID, + Other_PreparasiSpermaNote, + Other_PreparasiSpermaUserID, + Other_PreparasiSpermaCreated + ) + VALUES( + {$doctor_id}, + {$orderdetail_id}, + '{$prm['Other_PreparasiSpermaPreMotilitasA']}', + '{$prm['Other_PreparasiSpermaPreMotilitasB']}', + '{$prm['Other_PreparasiSpermaPreMotilitasC']}', + '{$prm['Other_PreparasiSpermaPreKonsentrasi']}', + '{$prm['Other_PreparasiSpermaPreKontaminan']}', + '{$prm['Other_PreparasiSpermaPostMotilitasA']}', + '{$prm['Other_PreparasiSpermaPostMotilitasB']}', + '{$prm['Other_PreparasiSpermaPostMotilitasC']}', + '{$prm['Other_PreparasiSpermaPostKonsentrasi']}', + '{$prm['Other_PreparasiSpermaPostKontaminan']}', + '{$prm['Other_PreparasiSpermaPreVolume']}', + '{$prm['Other_PreparasiSpermaPostVolume']}', + '{$methode_id}', + '{$prm['Other_PreparasiSpermaNote']}', + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } else { + $sql = "SELECT * FROM other_preparasisperma WHERE Other_PreparasiSpermaT_OrderDetailID = {$orderdetail_id} AND Other_PreparasiSpermaIsActive = 'Y'"; + $data_header = $this->db_smartone->query($sql)->row_array(); + $header_id = $data_header['Other_PreparasiSpermaID']; + $sql = "UPDATE other_preparasisperma SET + Other_PreparasiSpermaM_DoctorID = {$doctor_id}, + Other_PreparasiSpermaPreMotilitasA = '{$prm['Other_PreparasiSpermaPreMotilitasA']}', + Other_PreparasiSpermaPreMotilitasB = '{$prm['Other_PreparasiSpermaPreMotilitasB']}', + Other_PreparasiSpermaPreMotilitasC = '{$prm['Other_PreparasiSpermaPreMotilitasC']}', + Other_PreparasiSpermaPreKonsentrasi = '{$prm['Other_PreparasiSpermaPreKonsentrasi']}', + Other_PreparasiSpermaPreKontaminan = '{$prm['Other_PreparasiSpermaPreKontaminan']}', + Other_PreparasiSpermaPostMotilitasA = '{$prm['Other_PreparasiSpermaPostMotilitasA']}', + Other_PreparasiSpermaPostMotilitasB = '{$prm['Other_PreparasiSpermaPostMotilitasB']}', + Other_PreparasiSpermaPostMotilitasC = '{$prm['Other_PreparasiSpermaPostMotilitasC']}', + Other_PreparasiSpermaPostKonsentrasi = '{$prm['Other_PreparasiSpermaPostKonsentrasi']}', + Other_PreparasiSpermaPostKontaminan = '{$prm['Other_PreparasiSpermaPostKontaminan']}', + Other_PreparasiSpermaPreVolume = '{$prm['Other_PreparasiSpermaPreVolume']}', + Other_PreparasiSpermaPostVolume = '{$prm['Other_PreparasiSpermaPostVolume']}', + Other_PreparasiSpermaM_MethodeSpermaID = '{$methode_id}', + Other_PreparasiSpermaNote = '{$prm['Other_PreparasiSpermaNote']}', + Other_PreparasiSpermaUserID = {$userid} + WHERE + Other_PreparasiSpermaID = {$header_id}"; + $this->db_smartone->query($sql); + } + + + $result = array("total" => 1, "records" => array(), "sql" => ''); + $this->sys_ok($result); + exit; + } + + function getdnafragmentasiresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT other_dnafragmentasi.*, + Other_DnaFragmentasiID as xid, + Other_DnaFragmentasiT_OrderDetailID as orderdetail_id, + IFNULL(Other_DnaFragmentasiM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_DnaFragmentasiM_DoctorID) OR Other_DnaFragmentasiM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name, + IFNULL(Other_DnaFragmentasiOther_DnaFragmentasiMethodeID,0) as methode_id, + IFNULL(Other_DnaFragmentasiMethodeName,'') as methode_name, + Other_DnaFragmentasiHaloLuas as halo_luas, + Other_DnaFragmentasiHaloSedang as halo_sedang, + Other_DnaFragmentasiHaloSempit as halo_sempit, + Other_DnaFragmentasiTanpaHalo as tanpa_halo, + Other_DnaFragmentasiDFI as dfi, + Other_DnaFragmentasiKesimpulan as kesimpulan, + Other_DnaFragmentasiCatatan as catatan + FROM other_dnafragmentasi + LEFT JOIN m_doctor ON Other_DnaFragmentasiM_DoctorID = M_DoctorID + LEFT JOIN other_dnafragmentasimethode ON Other_DnaFragmentasiOther_DnaFragmentasiMethodeID = Other_DnaFragmentasiMethodeID + WHERE + Other_DnaFragmentasiT_OrderDetailID = {$id} AND Other_DnaFragmentasiIsActive = 'Y' + GROUP BY Other_DnaFragmentasiID + LIMIT 1"; + //echo $sql; + $query = $this->db_smartone->query($sql); + + if ($query) { + $rows = $query->row_array(); + if (!$rows) { + $rows = array( + 'xid' => 0, + 'orderdetail_id' => $id, + 'doctor_id' => 0, + 'doctor_name' => '', + 'methode_id' => 0, + 'methode_name' => '', + 'halo_luas' => '', + 'halo_sedang' => '', + 'tanpa_halo' => '', + 'dfi' => '', + 'kesimpulan' => '', + 'catatan' => '' + ); + } + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID + WHERE + M_DoctorSONat_SubGroupID = 4 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + + $sql = " + SELECT '0' as id, 'Belum memilih metode' as name + UNION + SELECT Other_DnaFragmentasiMethodeID as id, Other_DnaFragmentasiMethodeName as name + FROM other_dnafragmentasimethode + WHERE + Other_DnaFragmentasiMethodeIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $methodes = $this->db_smartone->query($sql)->result_array(); + + + $rst = array('doctors' => $doctors, 'methodes' => $methodes, 'results' => $rows); + $this->sys_ok(["records" => $rst]); + } else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + function saveresult_dnafragmentasi() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = $inp['doctor']['id']; + $methode_id = $inp['methode']['id']; + $orderdetail_id = $inp['results']['orderdetail_id']; + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + if (intval($prm['xid']) == 0) { + $sql = "INSERT INTO other_dnafragmentasi( + Other_DnaFragmentasiT_OrderDetailID, + Other_DnaFragmentasiM_DoctorID, + Other_DnaFragmentasiOther_DnaFragmentasiMethodeID, + Other_DnaFragmentasiHaloLuas, + Other_DnaFragmentasiHaloSedang, + Other_DnaFragmentasiHaloSempit, + Other_DnaFragmentasiTanpaHalo, + Other_DnaFragmentasiDFI, + Other_DnaFragmentasiKesimpulan, + Other_DnaFragmentasiCatatan, + Other_DnaFragmentasiUserID, + Other_DnaFragmentasiLastUpdated + ) + VALUES( + {$orderdetail_id}, + {$doctor_id}, + {$methode_id}, + '{$prm['halo_luas']}', + '{$prm['halo_sedang']}', + '{$prm['halo_sempit']}', + '{$prm['tanpa_halo']}', + '{$prm['dfi']}', + '{$prm['kesimpulan']}', + '{$prm['catatan']}', + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } else { + $sql = "UPDATE other_dnafragmentasi SET + Other_DnaFragmentasiT_OrderDetailID = {$orderdetail_id}, + Other_DnaFragmentasiM_DoctorID = {$doctor_id}, + Other_DnaFragmentasiOther_DnaFragmentasiMethodeID = '{$methode_id}', + Other_DnaFragmentasiHaloLuas = '{$prm['halo_luas']}', + Other_DnaFragmentasiHaloSedang = '{$prm['halo_sedang']}', + Other_DnaFragmentasiHaloSempit = '{$prm['halo_sempit']}', + Other_DnaFragmentasiTanpaHalo = '{$prm['tanpa_halo']}', + Other_DnaFragmentasiDFI = '{$prm['dfi']}', + Other_DnaFragmentasiKesimpulan = '{$prm['kesimpulan']}', + Other_DnaFragmentasiCatatan = '{$prm['catatan']}', + Other_DnaFragmentasiLastUpdated = NOW(), + Other_DnaFragmentasiUserID = {$userid} + WHERE + Other_DnaFragmentasiID = {$prm['xid']}"; + //echo $sql; + $this->db_smartone->query($sql); + } + + + $result = array("total" => 1, "records" => array(), "sql" => ''); + $this->sys_ok($result); + exit; + } +} diff --git a/application/controllers/mockup/process/resultvalidation-v20/Re_px.php b/application/controllers/mockup/process/resultvalidation-v20/Re_px.php index d2c44b96..df562286 100644 --- a/application/controllers/mockup/process/resultvalidation-v20/Re_px.php +++ b/application/controllers/mockup/process/resultvalidation-v20/Re_px.php @@ -1,2495 +1,2492 @@ -db_smartone = $this->load->database("onedev", true); - $this->load->helper(array('form', 'url')); - } - function getMethodeID($natTestID) { - $sql = "select M_MethodePriorityNat_MethodeID MethodeID, Nat_MethodeName - from - m_methode_priority - join nat_methode on Nat_MethodeID = M_MethodePriorityNat_MethodeID - and Nat_MethodeIsActive = 'Y' - join m_instrumentmethode on M_InstrumentMethodeNat_MethodeID = Nat_MethodeID and M_InstrumentMethodeIsActive = 'Y' - join nat_instrument on M_InstrumentMethodeNat_InstrumentID = Nat_InstrumentID - and Nat_InstrumentIsActive ='Y' - where M_MethodePriorityIsActive = 'Y' - and M_MethodePriorityNat_TestID = $natTestID - and M_MethodePriorityM_DayOfWeekID = dayofweek(now()) - order by M_MethodePriorityNumber desc - limit 0,1 "; - $qry = $this->db->query($sql); - if ($qry) { - $rows = $qry->result_array(); - if (count($rows) > 0 ) return array($rows[0]["MethodeID"],$rows[0]["Nat_MethodeName"]); - } - //2nd - $sql= "select - M_InstrumentMethodeNat_MethodeID MethodeID, Nat_MethodeName - from m_instrumentmethode - join nat_methode on M_InstrumentMethodeNat_MethodeID = Nat_MethodeID - and Nat_MethodeIsActive = 'Y' - join nat_instrument on M_InstrumentMethodeNat_InstrumentID = Nat_InstrumentID - and Nat_InstrumentIsActive ='Y' - where M_InstrumentMethodeNat_TestID = $natTestID - and M_InstrumentMethodeIsActive = 'Y' - order by M_InstrumentMethodePriority desc - limit 0,1"; - $qry = $this->db->query($sql); - if ($qry) { - $rows = $qry->result_array(); - if (count($rows) > 0 ) return array($rows[0]["MethodeID"],$rows[0]["Nat_MethodeName"]); - } - // - $sql = "select Nat_NormalValueNat_MethodeID MethodeID, Nat_MethodeName - from - nat_normalvalue - join nat_methode on Nat_NormalValueNat_MethodeID = Nat_MethodeID - and Nat_MethodeIsActive = 'Y' - where Nat_NormalValueNat_TestID = $natTestID - and Nat_NormalValueIsActive = 'Y' - order by Nat_NormalValueID - limit 0,1"; - $qry = $this->db->query($sql); - if ($qry) { - $rows = $qry->result_array(); - if (count($rows) > 0 ) return array($rows[0]["MethodeID"],$rows[0]["Nat_MethodeName"]); - } - return array(0,""); - } - function get_normal_value($methodeID, $natTestID, $sexID, $ageInDay ) { - $sql = "select fn_sampling_get_normal($methodeID, $natTestID, $sexID, $ageInDay) as normalValueID"; - $qry = $this->db->query($sql); - if ($qry) { - $rows = $qry->result_array(); - if (count($rows) > 0 ) return $rows[0]["normalValueID"]; - } - return 0; - } - function fn_fix_normal($order_id) { - $sql = "select - T_OrderDetailID, M_PatientM_SexID, fn_global_age_count_day(M_PatientDOB, date(T_OrderHeaderDate)) Dob , - T_TestNat_TestID - from t_orderheader - join m_patient on T_OrderHeaderID = $order_id and T_OrderHeaderM_PatientID = M_PatientID - join t_orderdetail on T_OrderDetailT_OrderHeaderID = T_OrderHeaderID - and T_OrderDetailIsACtive = 'Y' - and ( T_OrderDetailNat_NormalValueID is null or T_OrderDetailNat_NormalValueID = 0 ) - join t_test on T_OrderDetailT_TestID = T_TestID and T_TestIsResult = 'Y' "; - $qry = $this->db->query($sql); - if(! $qry) { - return; - } - $rows = $qry->result_array(); - if(count($rows) == 0 ) return; - $sql_u = "update t_orderdetail - join nat_normalvalue on T_OrderDetailID = ? and Nat_NormalValueID = ? - set - T_OrderDetailNat_NormalValueID = Nat_NormalValueID, - T_OrderDetailNormalValueNote = Nat_NormalValueNote, - T_OrderDetailNormalValueDescription = Nat_NormalValueDescription, - T_OrderDetailMinValue = Nat_NormalValueMinValue, - T_OrderDetailMaxValue = Nat_NormalValueMaxValue, - T_OrderDetailMinValueInclusive = Nat_NormalValueMinValueInclusive, - T_OrderDetailMaxValueInclusive = Nat_NormalValueMaxValueInclusive, - T_OrderDetailNat_MethodeID = ?, - T_OrderdetailNat_MethodeName =?"; - - foreach($rows as $r) { - $T_OrderDetailID = $r["T_OrderDetailID"]; - $sexID = $r["M_PatientM_SexID"]; - $ageInDay = $r["Dob"]; - $natTestID = $r["T_TestNat_TestID"]; - list($methodeID,$methodeName) = $this->getMethodeID($natTestID); - if ($methodeID == 0 ) continue; - $normalValueID = $this->get_normal_value($methodeID, $natTestID, $sexID, $ageInDay); - if ($normalValueID == 0) return; - $this->db->query($sql_u, array($T_OrderDetailID, $normalValueID, $methodeID, $methodeName)); - } - } - function update_order_sample($targetID, $sourceID) { - $sql = "update t_ordersample target - join t_ordersample source on - target.T_OrderSampleID = ? - and target.T_OrderSampleWorklistReceive = 'N' - and source.T_OrderSampleID = ? - set - target.T_OrderSampleSampling = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSampling, source.T_OrderSampleSampling), - target.T_OrderSampleSamplingDate = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingDate, source.T_OrderSampleSamplingDate), - target.T_OrderSampleSamplingTime = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingTime, source.T_OrderSampleSamplingTime), - target.T_OrderSampleSamplingUserID = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingUserID, source.T_OrderSampleSamplingUserID), - - target.T_OrderSampleReceive = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceive, source.T_OrderSampleReceive), - target.T_OrderSampleReceiveDate = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveDate, source.T_OrderSampleReceiveDate), - target.T_OrderSampleReceiveTime = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveTime, source.T_OrderSampleReceiveTime), - target.T_OrderSampleReceiveUserID = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveUserID, source.T_OrderSampleReceiveUserID), - - target.T_OrderSampleVerification = if(target.T_OrderSampleVerification='Y',target.T_OrderSampleVerification, source.T_OrderSampleVerification), - target.T_OrderSampleVerificationDate =if(target.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationDate, source.T_OrderSampleVerificationDate), - target.T_OrderSampleVerificationTime =if(source.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationTime, source.T_OrderSampleVerificationTime), - target.T_OrderSampleVerificationUserID =if(source.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationUserID, source.T_OrderSampleVerificationUserID), - - target.T_OrderSampleProcessing = if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessing, source.T_OrderSampleProcessing), - target.T_OrderSampleProcessingDate= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingDate, source.T_OrderSampleProcessingDate), - target.T_OrderSampleProcessingTime= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingTime, source.T_OrderSampleProcessingTime), - target.T_OrderSampleProcessingUserID= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingUserID, source.T_OrderSampleProcessingUserID), - - target.T_OrderSampleReceiveHandling =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandling, source.T_OrderSampleReceiveHandling ), - target.T_OrderSampleReceiveHandlingDate =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingDate, source.T_OrderSampleReceiveHandlingDate), - target.T_OrderSampleReceiveHandlingTime =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingTime, source.T_OrderSampleReceiveHandlingTime), - target.T_OrderSampleReceiveHandlingUserID =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingUserID, source.T_OrderSampleReceiveHandlingUserID), - - target.T_OrderSampleHandling = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandling, source.T_OrderSampleHandling), - target.T_OrderSampleHandlingDate = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingDate, source.T_OrderSampleHandlingDate), - target.T_OrderSampleHandlingTime = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingTime, source.T_OrderSampleHandlingTime), - target.T_OrderSampleHandlingUserID = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingUserID, source.T_OrderSampleHandlingUserID), - - target.T_OrderSampleWorklistReceive = source.T_OrderSampleWorklistReceive, - target.T_OrderSampleWorklistReceiveDatetime = source.T_OrderSampleWorklistReceiveDateTime, - target.T_OrderSampleWorklistReceiveUserID = source.T_OrderSampleWorklistReceiveUserID - "; - $qry = $this->db->query($sql,array($targetID,$sourceID)); - if(! $qry ) { - echo json_encode(array( "status" => "ERR" , "message" => print_r($this->db->error(),true))); - exit; - } - } - function fix_sample_serum($headerID) { - //cari t_ordersample yg belum worklist receive dengan code 017% - $sql = "select T_OrderSampleID - from t_ordersample - join t_sampletype on - T_OrderSampleT_OrderHeaderID = ? - and T_OrderSampleWorklistReceive = 'N' - and T_OrderSampleIsActive = 'Y' - and T_OrderSampleT_SampleTypeID = T_SampletypeID - and T_SampleTypeCode like '017%' - "; - $qry = $this->db->query($sql, array($headerID)); - if(!$qry) { - echo json_encode(array( "status" => "ERR" , "message" => print_r($this->db->error(),true))); - exit; - } - $rows = $qry->result_array(); - if (count($rows) == 0 ) return; - //cari T_OrderSample yang sudah di receive yg terakhir - $sql = "select T_OrderSampleID - from t_ordersample - join t_sampletype on - T_OrderSampleT_OrderHeaderID = ? - and T_OrderSampleWorklistReceive = 'Y' - and T_OrderSampleIsActive = 'Y' - and T_OrderSampleT_SampleTypeID = T_SampletypeID - and T_SampleTypeCode like '017%' - order by T_OrderSampleWorklistReceiveDatetime desc - limit 0,1 - "; - $qry = $this->db->query($sql, array($headerID)); - if(!$qry) { - echo json_encode(array( "status" => "ERR" , "message" => print_r($this->db->error(),true))); - exit; - } - $rcv_rows = $qry->result_array(); - if (count($rcv_rows) == 0 ) return; - - //print_r($rows); - //print_r($rcv_rows); - $rcv_T_OrderSampleID = $rcv_rows[0]["T_OrderSampleID"]; - //ada yg belum di receive - foreach($rows as $r) { - $T_OrderSampleID = $r["T_OrderSampleID"]; - $this->update_order_sample($T_OrderSampleID,$rcv_T_OrderSampleID); - } - } - public function search() - { - $prm = $this->sys_input; - $max_rst = 99; - - $id = $prm["order_id"]; - if ($id > 0 ) { - $this->fix_sample_serum($id); - $this->fn_fix_normal($id); - } - $lang = $this->lang_default_code; - $lang_id = isset($prm['lang_id']) ? $prm['lang_id'] : '0'; - - if ($lang_id != 0) - { - $l = $this->db_smartone->where("Nat_LangID", $lang_id)->get("nat_lang")->row(); - $lang = $l->Nat_LangCode; - } - - //tambahan fajri - $sql = " UPDATE t_orderdetail - JOIN t_test ON T_OrderDetailT_TestID = T_TestID - SET T_OrderDetailT_TestIsResult = T_TestIsResult - WHERE - T_OrderDetailT_OrderHeaderID = {$id} AND - T_OrderDetailT_TestIsResult = '' AND - T_OrderDetailIsActive = 'Y'"; - $this->db_smartone->query($sql); - - $tot_count = 0; - $lq = ""; - $group_id = 0; - if (isset($prm['group_id'])) - $group_id = $prm['group_id']; - - if ($group_id != 0) - { - $sql = "select distinct T_WorklistDetailNat_TestID Nat_TestID - from t_worklistdetailv2 - where T_WorklistDetailT_WorklistID = {$group_id}"; - $qry = $this->db_smartone->query($sql); - $rows = $qry->result_array(); - $nat_test_ids = "0"; - foreach($rows as $r) { - $nat_test_ids .= ", " . $r["Nat_TestID"]; - } - $q_group = " ( $nat_test_ids ) "; - - $sql = " - SELECT a1.*, cOUNT(a2.T_OrderDetailID) level - FROM ( - SELECT IFNULL(y.T_OrderDetailT_TestID, x.T_OrderDetailT_TestID) t_testid, - IFNULL(y.T_OrderDetailT_TestName, y.T_OrderDetailT_TestName) t_testname, - y.T_OrderDetailResult result, y.T_OrderDetailResult result_old, y.T_OrderDetailNote note, y.T_OrderDetailNote note_old, - y.T_OrderDetailID id, - y.T_OrderDetailT_TestIsResult is_result, a.T_TestIsQuantitative is_quantitative, - y.T_OrderDetailResultFlag result_flag, - y.T_OrderDetailNat_NormalValueID normal_id, - y.T_OrderDetailNormalValueNote normal_note, y.T_OrderDetailNat_UnitName unit_name, - y.T_OrderdetailNat_MethodeID methode_id, y.T_OrderdetailNat_MethodeName methode_name, - a.T_TestNat_TestID nattest_id, a.T_TestID tx_id, count(T_ResultInstrumentID) as result_instrument_n, - y.T_OrderDetailVerification, T_OrderSampleReceive sample_receive, - T_OrderSampleProcessing sample_processing, T_OrderSampleWorklistReceive sample_worklist_receive, - IF(T_OrderDetailAddOnPreAnalytic = 'Y', T_OrderDetailAddOnPreAnalytic, PreAnalyticIsOk) pre_analytic, - T_OrderDetailAddOnPreAnalytic, - T_OrderHeaderID order_id, y.T_OrderDetailT_TestSasCode test_sas_code, - tx.T_TestSasCode, - T_OrderDetailAddOnResample `resample`, T_OrderDetailAddOnResampleStatus resample_status, - T_OrderDetailAddOnRef ref, y.T_OrderDetailVerification verification, y.T_OrderDetailValidation validation, - T_OrderPromiseDateTime, Group_ResultName as ResultGroupName - FROM t_orderdetail x - left join t_orderpromise on x.T_OrderDetailT_OrderPromiseID = T_OrderPromiseID - JOIN t_test tx ON x.T_OrderDetailT_TestID = T_TestID - JOIN t_test tcheck on tcheck.T_TestNat_TestID in {$q_group} - and ( tx.T_TestID = tcheck.T_TestID or tx.T_TestSasCode like concat(tcheck.T_TestSasCode,'%')) - LEFT JOIN group_resultdetail ON Group_ResultDetailT_TestID = x.T_OrderDetailT_TestID AND Group_ResultDetailIsActive = 'Y' - LEFT JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND Group_ResultFlagNonLab = 'N' - LEFT JOIN t_orderdetail y ON x.T_OrderDetailT_TestSasCode LIKE CONCAT(y.T_OrderDetailT_TestSasCode, '%') - AND x.T_OrderDetailT_OrderHeaderID = y.T_OrderDetailT_OrderHeaderID - AND y.T_OrderDetailIsActive = 'Y' - LEFT JOIN t_orderdetailaddon ON x.T_OrderDetailID = T_OrderDetailAddOnT_OrderDetailID - JOIN t_orderheader ON y.T_OrderDetailT_OrderHeaderID = T_OrderHeaderID - LEFT JOIN t_test a ON y.T_OrderDetailT_TestID = a.T_TestID - AND a.T_TestIsNonLab = '' - LEFT JOIN (SELECT T_OrderSampleT_SampleTypeID, T_OrderSampleReceive, T_OrderSampleProcessing, T_OrderSampleWorklistReceive - FROM t_ordersample WHERE T_OrderSampleT_OrderHeaderID = {$id} - AND T_OrderSampleIsactive = 'Y' - GROUP BY T_OrderSampleT_SampleTypeID) os ON a.T_TestT_SampleTypeID = os.T_OrderSampleT_SampleTypeID - or os.T_OrderSampleT_SampleTypeID = fn_sampletype_from_local(a.T_TestNat_TestID) - - LEFT JOIN t_resultinstrument ON T_ResultInstrumentT_OrderDetailID = x.T_OrderDetailID - LEFT JOIN pre_analytic ON PreAnalyticNat_TestID = a.T_TestNat_TestID AND PreAnalyticDate = date(now()) and PreAnalyticIsActive = 'Y' - WHERE x.T_OrderDetailT_OrderHeaderID = {$id} - AND x.T_OrderDetailIsActive = 'Y' - GROUP BY y.T_OrderDetailT_TestID - ORDER BY y.T_OrderDetailT_TestSasCode ASC - ) a1 - - LEFT JOIN t_orderdetail a2 ON a2.T_OrderDetailT_OrderHeaderID = a1.order_id - AND a2.T_OrderDetailIsActive = 'Y' - AND a1.test_sas_code LIKE CONCAT(a2.T_OrderDetailT_testSasCode, '%') - GROUP BY a1.t_testid - order by a1.test_sas_code -"; - $query = $this->db_smartone->query($sql); - $lq = $this->db_smartone->last_query(); - } - else - { - $sql = " - SELECT a1.*, cOUNT(a2.T_OrderDetailID) level - FROM ( - SELECT IFNULL(y.T_OrderDetailT_TestID, x.T_OrderDetailT_TestID) t_testid, - IFNULL(y.T_OrderDetailT_TestName, y.T_OrderDetailT_TestName) t_testname, - y.T_OrderDetailResult result, y.T_OrderDetailResult result_old, y.T_OrderDetailNote note, y.T_OrderDetailNote note_old, - y.T_OrderDetailID id, - y.T_OrderDetailT_TestIsResult is_result, a.T_TestIsQuantitative is_quantitative, - y.T_OrderDetailResultFlag result_flag, - y.T_OrderDetailNat_NormalValueID normal_id, - y.T_OrderDetailNormalValueNote normal_note, y.T_OrderDetailNat_UnitName unit_name, - y.T_OrderdetailNat_MethodeID methode_id, y.T_OrderdetailNat_MethodeName methode_name, - a.T_TestNat_TestID nattest_id, a.T_TestID tx_id, count(T_ResultInstrumentID) as result_instrument_n, - y.T_OrderDetailVerification, T_OrderSampleReceive sample_receive, - T_OrderSampleProcessing sample_processing, T_OrderSampleWorklistReceive sample_worklist_receive, - IF(T_OrderDetailAddOnPreAnalytic = 'Y', T_OrderDetailAddOnPreAnalytic, PreAnalyticIsOk) pre_analytic, - T_OrderDetailAddOnPreAnalytic, - T_OrderHeaderID order_id, y.T_OrderDetailT_TestSasCode test_sas_code, - tx.T_TestSasCode, - T_OrderDetailAddOnResample `resample`, T_OrderDetailAddOnResampleStatus resample_status, - T_OrderDetailAddOnRef ref, y.T_OrderDetailVerification verification, y.T_OrderDetailValidation validation, - T_OrderPromiseDateTime , Group_ResultName as ResultGroupName - FROM t_orderdetail x - left join t_orderpromise on x.T_OrderDetailT_OrderPromiseID = T_OrderPromiseID - JOIN t_test tx ON x.T_OrderDetailT_TestID = T_TestID - LEFT JOIN group_resultdetail ON Group_ResultDetailT_TestID = x.T_OrderDetailT_TestID AND Group_ResultDetailIsActive = 'Y' - LEFT JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND Group_ResultFlagNonLab = 'N' - LEFT JOIN t_orderdetail y ON x.T_OrderDetailT_TestSasCode LIKE CONCAT(y.T_OrderDetailT_TestSasCode, '%') - AND x.T_OrderDetailT_OrderHeaderID = y.T_OrderDetailT_OrderHeaderID - AND y.T_OrderDetailIsActive = 'Y' - - LEFT JOIN t_orderdetailaddon ON x.T_OrderDetailID = T_OrderDetailAddOnT_OrderDetailID - - JOIN t_orderheader ON y.T_OrderDetailT_OrderHeaderID = T_OrderHeaderID - LEFT JOIN t_test a ON y.T_OrderDetailT_TestID = a.T_TestID - AND a.T_TestIsNonLab = '' - LEFT JOIN (SELECT T_OrderSampleT_SampleTypeID, T_OrderSampleReceive, T_OrderSampleProcessing, T_OrderSampleWorklistReceive - FROM t_ordersample WHERE T_OrderSampleT_OrderHeaderID = {$id} - AND T_OrderSampleIsactive = 'Y' - GROUP BY T_OrderSampleT_SampleTypeID) os ON a.T_TestT_SampleTypeID = os.T_OrderSampleT_SampleTypeID - or os.T_OrderSampleT_SampleTypeID = fn_sampletype_from_local(a.T_TestNat_TestID) - - LEFT JOIN t_resultinstrument ON T_ResultInstrumentT_OrderDetailID = x.T_OrderDetailID - LEFT JOIN pre_analytic ON PreAnalyticNat_TestID = a.T_TestNat_TestID AND PreAnalyticDate = date(now()) and PreAnalyticIsActive = 'Y' - WHERE x.T_OrderDetailT_OrderHeaderID = {$id} - AND x.T_OrderDetailIsActive = 'Y' - GROUP BY y.T_OrderDetailT_TestID - ORDER BY y.T_OrderDetailT_TestSasCode ASC - ) a1 - - LEFT JOIN t_orderdetail a2 ON a2.T_OrderDetailT_OrderHeaderID = a1.order_id - AND a2.T_OrderDetailIsActive = 'Y' - AND a1.test_sas_code LIKE CONCAT(a2.T_OrderDetailT_testSasCode, '%') - GROUP BY a1.t_testid - order by a1.test_sas_code -"; -//echo $sql; - $query = $this->db_smartone->query($sql); - $lq = $this->db_smartone->last_query(); - } - // file_put_contents("/xtmp/re-query.sql",$lq); - - if ($query) { - $rst = []; - $rows = $query->result_array(); - - foreach($rows as $k => $v) - { - - if ($v['is_result'] == "Y" && $v['is_quantitative'] == "N") - { - $v['template'] = []; - $x = $this->db_smartone->query("CALL sp_master_resulttemplate_get('{$v['t_testid']}')"); - $this->clean_mysqli_connection($this->db_smartone->conn_id); - if ($x) - $v['template'] = $x->result_array(); - } - - // IF Rujukan, by pas Pre Analytik - if ($v['ref'] == 'Y') - $v['pre_analytic'] = 'Y'; - if ($v["id"] == "885455" ) - { - //sipe workaround - //$v["sample_receive"] = "Y"; - $v["sample_worklist_receive"] = "Y"; - } - $rst[] = $v; - } - - $result = array("total" => $tot_count, "records" => $rst, "total_display" => sizeof($rows), "q" => $lq); - $this->sys_ok($result); - } - else { - $this->sys_error_db("RE Px rows", $this->db_smartone); - exit; - } - } - - public function save() - { - $prm = $this->sys_input; - $data = json_decode($prm["data"]); - $lang = $this->lang_default_code; - $lang_id = isset($prm['lang_id']) ? $prm['lang_id'] : '0'; - - if ($lang_id != 0) - { - $l = $this->db_smartone->where("Nat_LangID", $lang_id)->get("nat_lang")->row(); - $lang = $l->Nat_LangCode; - } - - $sql_norm = "select T_OrderDetailMinValue, T_OrderDetailMaxValue, - T_OrderDetailMinValueInclusive, T_OrderDetailMaxValueInclusive, - Nat_TestFlagLow, Nat_TestFlagHigh - from t_orderdetail - join t_test on T_OrderDetailT_TestID = T_TestID - join nat_test on T_TestNat_TestID = Nat_TestID and T_TestIsActive = 'Y' - where T_OrderDetailID = ? "; - - $ids = []; - foreach ($data as $k => $v) - { - if ( $v->resultInstrumentID > 0 ) { - $sql_i = "select T_ResultInstrumentNat_NormalValueID normalValueID - from t_resultinstrument - where T_ResultInstrumentID = ?"; - $qry_i = $this->db_smartone->query($sql_i, array($v->resultInstrumentID)); - if ($qry_i) { - $rows_i = $qry_i->result_array(); - - if (count($rows_i) > 0 ) { - $sql_iu = "update t_orderdetail, nat_normalvalue , nat_methode - set T_OrderDetailMinValue = Nat_NormalValueMinValue, - T_OrderDetailMinValueInclusive = Nat_NormalValueMinValueInclusive, - T_OrderDetailMaxValue = Nat_NormalValueMaxValue , - T_OrderDetailMaxValueInclusive = Nat_NormalValueMaxValueInclusive, - T_OrderDetailNormalValueNote = Nat_NormalValueNote, - T_OrderDetailNormalValueDescription = Nat_NormalValueDescription, - T_OrderDetailNat_NormalValueID = Nat_NormalValueID, - T_OrderDetailNat_MethodeID = Nat_NormalValueNat_MethodeID, - T_OrderDetailNat_MethodeName = Nat_MethodeName - where T_OrderDetailID = ? and Nat_NormalValueID = ? - and Nat_NormalValueNat_MethodeID = Nat_MethodeID - "; - $this->db_smartone->query($sql_iu, array($v->id, $rows_i[0]["normalValueID"])); - //file_put_contents("/xtmp/update-nilai-normal", $this->db_smartone->last_query() . "\n", FILE_APPEND); - } - } - } - $y = $this->db_smartone->query("SELECT fn_process_sample_handling_perfect('{$v->order_id}', '{$v->test_id}') c") - ->row(); - $req_status = $y->c; - $qry_norm = $this->db_smartone->query($sql_norm,$v->id); - $result_flag = ""; - if ($qry_norm) { - $rows_norm = $qry_norm->result_array(); - if (count($rows_norm) > 0 ) { - $r = $rows_norm[0]; - if (is_numeric($v->result)) { - - if ( $r["T_OrderDetailMinValueInclusive"] == "Y" && $v->result < $r["T_OrderDetailMinValue"] ) { - $result_flag = $r["Nat_TestFlagLow"]; - } - if ( $r["T_OrderDetailMinValueInclusive"] == "N" && $v->result <= $r["T_OrderDetailMinValue"] ) { - $result_flag = $r["Nat_TestFlagLow"]; - } - if ( $r["T_OrderDetailMaxValueInclusive"] == "Y" && $v->result > $r["T_OrderDetailMaxValue"] ) { - $result_flag = $r["Nat_TestFlagHigh"]; - } - if ( $r["T_OrderDetailMaxValueInclusive"] == "N" && $v->result >= $r["T_OrderDetailMaxValue"] ) { - $result_flag = $r["Nat_TestFlagHigh"]; - } - } - } - } - if ($lang == $this->lang_default_code) - { - $this->db_smartone->set('T_OrderDetailResult', $v->result) - ->set('T_OrderDetailResultFlag', $result_flag) - ->set('T_OrderDetailNote', $v->note) - ->set('T_OrderDetailReqStatus', $req_status) - ->where('T_OrderDetailID', $v->id) - ->update('t_orderdetail'); - } - else - { - $this->db_smartone->set('T_OrderDetailLangResult', $v->result) - ->set('T_OrderDetailLangNote', $v->note) - ->where('T_OrderDetailLangID', $v->id) - ->update('t_orderdetaillang'); - } - - $ids[] = $v->id; - } - - // LOG Process - $order = $this->db_smartone->select('T_OrderDetailT_OrderHeaderID id, T_OrderHeaderLabNumber lab_number', false) - ->join('t_orderheader', 'T_OrderHeaderID = T_OrderDetailT_OrderHeaderID') - ->where('T_OrderDetailID', $data[0]->id) - ->get('t_orderdetail') - ->row(); - - $dblog = $this->load->database("onelog", true); - $dblog->set('Log_ProcessCode', 'PROCESS.Result.Entry') - ->set('Log_ProcessOrderID', $order->id) - ->set('Log_ProcessOrderNumber', $order->lab_number) - ->set('Log_ProcessJson', json_encode($data)) - ->set('Log_ProcessUserID', $this->sys_user['M_UserID']) - ->insert('log_process'); - // END OF Log Process - //auto calculation - $this->load->library("Resultcalc"); - $rows = $this->resultcalc->auto($order->id); - - try { - foreach($ids as $id ) { - $this->db_smartone->query("call sp_set_normal_value_flag($id)"); - $this->clean_mysqli_connection($this->db_smartone->conn_id); - } - } catch(Exception $e) { - } - - $this->sys_ok($ids); - } - - public function save_template() - { - $prm = $this->sys_input; - - $n = $this->db_smartone->select("COUNT(T_ResultTemplateID) n") - ->where("T_ResultTemplateT_TestID", $prm['test_id']) - ->where("T_ResultTemplateIsActive", "Y") - ->where("T_ResultTemplateValue", $prm['value']) - ->get('t_resulttemplate') - ->row(); - if ($n->n > 0) - { - $this->sys_error_db("Insert Result Template", $this->db_smartone); - return; - } - - $r = $this->db_smartone->set("T_ResultTemplateT_TestID", $prm['test_id']) - ->set("T_ResultTemplateValue", $prm['value']) - ->insert('t_resulttemplate'); - if ($r) - { - $template = []; - $x = $this->db_smartone->query("CALL sp_master_resulttemplate_get('{$prm['test_id']}')"); - $this->clean_mysqli_connection($this->db_smartone->conn_id); - if ($x) - $template = $x->result_array(); - - $this->sys_ok($template); - } - } - - public function export() - { - $prm = $this->sys_input; - - $sql = "CALL sp_process_result_lang(?, ?, ?, ?)"; - $query = $this->db_smartone->query($sql, [$prm['order_id'], $prm['lang_id'], $prm['is_si'], $this->sys_user['M_UserID']]); - if ($query) - { - $r = $query->row(); - if ($r->status == "OK") - { - $this->sys_ok($r->data); - return; - } - - $this->sys_error_db("Message : " . $r->message, $this->db_smartone); - } - else - { - $this->sys_error_db("Lang Result", $this->db_smartone); - return; - } - } - - public function search_group() - { - $prm = $this->sys_input; - $max_rst = 100; - - // QUERY TOTAL - $sql = "select count(*) total - from t_worklist - where T_WorklistIsActive = 'Y' - order by T_WorklistName ASC"; - $query = $this->db_smartone->query($sql); - - if ($query) { - $tot_count = $query->result_array()[0]["total"]; - } - else { - $this->sys_error_db("worklist count", $this->db_smartone); - exit; - } - - $sql = "select T_WorklistID group_id, T_WorklistName group_name - from t_worklist - where T_WorklistIsActive = 'Y' - order by T_WorklistName ASC - limit 0, {$max_rst}"; - $query = $this->db_smartone->query($sql); - - if ($query) { - $rows = $query->result_array(); - foreach ($rows as $k => $v) - $rows[$k]['data'] = json_decode($v['data']); - $result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows), "q" => $this->db_smartone->last_query()); - $this->sys_ok($result); - } - else { - $this->sys_error_db("worklist rows", $this->db_smartone); - exit; - } - } - - public function search_rerun() - { - $prm = $this->sys_input; - $id = $prm["detail_id"]; - - $sql = "CALL sp_process_result_rerun(?)"; - $query = $this->db_smartone->query($sql, [$id]); - - if ($query) - { - $rows = $query->result_array(); - $this->sys_ok(["records"=>$rows]); - } - else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - - - function getdoctorsfna() - { - $prm = $this->sys_input; - // $id = $prm["id"]; - - $sql = " SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY M_DoctorName ASC"; - //echo $sql; - $query = $this->db_smartone->query($sql); - - if ($query) - { - $rows = $query->result_array(); - $this->sys_ok(["records"=>$rows]); - } - else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - function getfnaresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT Other_FNADetailsID as xid, - Other_FNAT_OrderDetailID as orderdetail_id, - Other_FNADetailsCode as code, - Other_FNADetailsLabel as label, - Other_FNADetailsResult as result, - IFNULL(Other_FNAM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_FNAM_DoctorID) OR Other_FNAM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_fna - JOIN other_fnadetails ON Other_FNADetailsOther_FNAID = Other_FNAID AND Other_FNADetailsIsActive = 'Y' - LEFT JOIN m_doctor ON Other_FNAM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_FNAT_OrderDetailID = {$id} AND Other_FNAIsActive = 'Y' - GROUP BY Other_FNADetailsID - ORDER BY Other_FNADetailsCode ASC"; - $query = $this->db_smartone->query($sql); - - if ($query) - { - $rows = $query->result_array(); - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $images = array(); - $sql = "SELECT So_ImageUploadID as xid, - CONCAT('/one-media/one-image-nonlab/',So_ImageUploadNewName) as image_url - FROM t_orderdetail - JOIN so_imageupload ON So_ImageUploadT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND - So_ImageUploadIsActive = 'Y' - WHERE - T_OrderDetailID = {$id} AND - T_OrderDetailIsActive = 'Y' - GROUP BY So_ImageUploadID"; - $images = $this->db_smartone->query($sql)->result_array(); - - $rst = array('doctors'=>$doctors,'results'=>$rows,'images'=>$images); - $this->sys_ok(["records"=>$rst]); - } - else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - - function uploadimage(){ - if (! $this->isLogin) { - $this->sys_error("Invalid Token"); - exit; - } - - $userid = $this->sys_user["M_UserID"]; - $data = []; - //print_r($_SERVER); - - $prm = $this->sys_input; - $orderid = $this->input->post('orderid'); - $labnumber = $this->input->post('labnumber'); - $sql = "UPDATE so_imageupload SET - So_ImageUploadIsActive = 'N', - So_ImageUploadUserID = {$userid} - WHERE - So_ImageUploadT_OrderHeaderID = {$orderid}"; - //echo $sql; - $this->db_onedev->query($sql); - //$config['upload_path'] = 'assets/'; - - $path = '/home/one/project/one/one-media/one-image-nonlab/'; - //echo $path; - $config['upload_path'] = $path; - $config['allowed_types'] = 'jpg|jpeg|png|gif'; - - $config['max_size'] = '10000'; - $count = count($_FILES['files']['name']); - //echo $count; - $this->load->library('upload',$config); - - $error = []; - for($i=0;$i<$count;$i++){ - - - if(!empty($_FILES['files']['name'][$i])){ - - - - $_FILES['file']['name'] = $_FILES['files']['name'][$i]; - - $_FILES['file']['type'] = $_FILES['files']['type'][$i]; - - $_FILES['file']['tmp_name'] = $_FILES['files']['tmp_name'][$i]; - - $_FILES['file']['error'] = $_FILES['files']['error'][$i]; - - $_FILES['file']['size'] = $_FILES['files']['size'][$i]; - - - - $namex = $orderid.'-'.$labnumber.'-'.$this->generateRandomString(5); - //echo $namex; - - $config['file_name'] = $namex; - $this->upload->initialize($config); - //echo $config['file_name'] ; - - - - - - if($this->upload->do_upload('file')){ - - $uploadData = $this->upload->data(); - - $filename = $uploadData['file_name']; - //echo $filename; - - - $sql = "INSERT INTO so_imageupload ( - So_ImageUploadT_OrderHeaderID, - So_ImageUploadT_OrderHeaderLabNumber, - So_ImageUploadT_SampleTypeID, - So_ImageUploadOldName, - So_ImageUploadNewName, - So_ImageUploadCreated, - So_ImageUploadUserID - ) - VALUES( - {$orderid}, - '{$labnumber}', - '150', - '{$_FILES['files']['name'][$i]}', - '{$filename}', - NOW(), - {$userid} - - )"; - //echo $sql; - $this->db_onedev->query($sql); - $xlast_id = $this->db_onedev->insert_id(); - $data['totalFiles'][] = array('xid' => $xlast_id ,'image_url' => '/one-media/one-image-nonlab/'.$filename); - - } - else{ - $error = array('error' => $this->upload->display_errors()); - } - - } - - - - } - - $result = array("total" =>count( $data['totalFiles']), "records" => $data['totalFiles'],'errors'=>$error); - $this->sys_ok($result); - } - - - function generateRandomString($length = 10) { - $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; - $charactersLength = strlen($characters); - $randomString = ''; - for ($i = 0; $i < $length; $i++) { - $randomString .= $characters[rand(0, $charactersLength - 1)]; - } - return $randomString; - } - - function getcytologiresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT Other_CytologiDetailsID as xid, - Other_CytologiT_OrderDetailID as orderdetail_id, - Other_CytologiDetailsCode as code, - Other_CytologiDetailsLabel as label, - Other_CytologiDetailsResult as result, - IFNULL(Other_CytologiM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_CytologiM_DoctorID) OR Other_CytologiM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_cytologi - JOIN other_cytologidetails ON Other_CytologiDetailsOther_CytologiID = Other_CytologiID AND Other_CytologiDetailsIsActive = 'Y' - LEFT JOIN m_doctor ON Other_CytologiM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_CytologiT_OrderDetailID = {$id} AND Other_CytologiIsActive = 'Y' - GROUP BY Other_CytologiDetailsID - ORDER BY Other_CytologiDetailsCode ASC"; - //echo $sql; - $query = $this->db_smartone->query($sql); - - if ($query) - { - $rows = $query->result_array(); - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $rst = array('doctors'=>$doctors,'results'=>$rows); - $this->sys_ok(["records"=>$rst]); - } - else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - function getmikroresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT - Other_MikroID as xid, - Other_MikroHasilBiakan as hasil_biakan, - Other_MikroSampleTypeName as sample_name, - Other_MikroT_OrderDetailID as orderdetail_id, - Other_MikroResult as result_value, - '' as result_other, - IFNULL(T_BacteriaID,0) as T_BacteriaID, - IFNULL(T_BacteriaName,'') as T_BacteriaName, - '' as details, - IFNULL(Other_MikroM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_MikroM_DoctorID) OR Other_MikroM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_mikro - LEFT JOIN t_bacteria ON Other_MikroT_BacteriaID = T_BacteriaID - LEFT JOIN m_doctor ON Other_MikroM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_MikroT_OrderDetailID = {$id} AND Other_MikroIsActive = 'Y' - GROUP BY Other_MikroID"; - //echo $sql; - $query = $this->db_smartone->query($sql); - - if ($query) - { - $row = $query->row_array(); - if($row){ - if($row['result_value'] != 'Positif' && $row['result_value'] != 'Negatif'){ - $row['result_other'] = $row['result_value']; - $row['result_value'] = 'other'; - } - $sql = "SELECT '' as xno, - Other_MikroDetailsID as xid, - Other_MikroDetailsValue as value, - IF(Other_MikroDetailsNote = 'R','Y','N') as chx_r, - IF(Other_MikroDetailsNote = 'I','Y','N') as chx_i, - IF(Other_MikroDetailsNote = 'S','Y','N') as chx_s, - Other_MikroDetailsNote as note, - t_antibiotic.* - FROM other_mikrodetails - LEFT JOIN t_antibiotic ON Other_MikroDetailsT_AntibioticID = T_AntibioticID - WHERE - Other_MikroDetailsOther_MikroID = {$row['xid']} AND Other_MikroDetailsIsActive = 'Y' - GROUP BY Other_MikroDetailsID - ORDER BY T_AntibioticName ASC"; - //echo $sql; - $details = $this->db_smartone->query($sql)->result_array(); - if(details){ - foreach($details as $k => $v){ - $details[$k]['xno'] = $k + 1; - } - } - $row['details'] = $details; - } - else{ - $row = array('xid'=>'0','hasil_biakan' => '','result_value'=>'Negatif','sample_name' => '','orderdetail_id'=>$id, 'T_BacteriaID'=>'0','T_BacteriaName'=>'0','details'=>array(),'doctor_id'=>'0','doctor_name'=>'0'); - } - } - else{ - $row = array('xid'=>'0','hasil_biakan' => '','result_value'=>'Negatif','sample_name' => '','orderdetail_id'=>$id, 'T_BacteriaID'=>'0','T_BacteriaName'=>'0','details'=>array(),'doctor_id'=>'0','doctor_name'=>'0'); - } - //print_r($row); - - - - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 7 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $sql = " - SELECT '0' as id, 'Belum memilih bakteria' as name - UNION - SELECT T_BacteriaID as id, T_BacteriaName as name - FROM t_bacteria - WHERE - T_BacteriaIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $bacteries = $this->db_smartone->query($sql)->result_array(); - $rst = array('doctors'=>$doctors,'bacteries'=>$bacteries,'results'=>$row); - $this->sys_ok(["records"=>$rst]); - } - function getantibiotics(){ - $prm = $this->sys_input; - $id = $prm["id"]; - $sql = " SELECT '' as xno, - 0 as xid, - '' as hasil_biakan, - '' as sample_name, - 0 as value, - 'Y' as chx_r, - 'N' as chx_i, - 'N' as chx_s, - 'R' as note, - t_antibiotic.* - FROM t_antibiotic - WHERE - T_AntibioticT_BacteriaID = {$prm['id']} AND T_AntibioticIsActive= 'Y' - ORDER BY T_AntibioticName ASC"; - //echo $sql; - $rows = $this->db_smartone->query($sql)->result_array(); - if(rows){ - foreach($rows as $k => $v){ - $rows[$k]['xno'] = $k + 1; - } - } - - $this->sys_ok(["records"=>$rows]); - } - function getlcprepresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - $sql = " SELECT Other_LcprepDetailsID as xid, - Other_LcprepID as header_id, - Other_LcprepT_orderDetailID as orderdetail_id, - Other_LcprepDetailsCode as code, - Other_LcprepDetailsLabel as label, - Other_LcprepDetailsResult as result, - IFNULL(Other_LcprepM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_LcprepM_DoctorID) OR Other_LcprepM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_lcprep - JOIN other_lcprepdetails ON Other_LcprepDetailsOther_LcprepID = Other_LcprepID AND Other_LcprepDetailsIsActive = 'Y' - LEFT JOIN m_doctor ON Other_LcprepM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_LcprepT_orderDetailID = {$id} AND Other_LcprepIsActive = 'Y' - GROUP BY Other_LcprepDetailsOther_LcprepID, Other_LcprepDetailsCode - ORDER BY Other_LcprepDetailsCode ASC"; - //echo $sql; - $rows = $this->db_smartone->query($sql)->result_array(); - if(!$rows){ - $rows = array( - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'A', - 'label' => 'DESKRIPSI', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ), - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'B', - 'label' => 'KESIMPULAN', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ) - ); - } - - $header_id = $rows[0]['header_id']; - $sql = "SELECT IFNULL(Other_LcprepAdekuasiID,0) as xid, - Lcprep_AdekuasiID as id, - Lcprep_AdekuasiLabel as name, - IF(ISNULL(Other_LcprepAdekuasiID),'N',Other_LcprepAdekuasiChex) as chex - FROM lcprep_adekuasi - LEFT JOIN other_lcprepadekuasi ON Other_LcprepAdekuasiLcprep_AdekuasiID = Lcprep_AdekuasiID AND - Other_LcprepAdekuasiOther_LcprepID = {$header_id} AND - Other_LcprepAdekuasiIsActive = 'Y' - WHERE - Lcprep_AdekuasiIsActive = 'Y' - GROUP BY Lcprep_AdekuasiID - ORDER BY Lcprep_AdekuasiOrder ASC - "; - //echo $sql; - $adeakuasi = $this->db_smartone->query($sql)->result_array(); - foreach($adeakuasi as $kc => $vc){ - $adeakuasi[$kc]['chex'] = $vc['chex'] == 'N'?false:true; - } - - $sql = "SELECT IFNULL(Other_LcprepKategoriUmumID,0) as xid, - Lcprep_KategoriUmumID as id, - Lcprep_KategoriUmumLabel as name, - IF(ISNULL(Other_LcprepKategoriUmumID),'N',Other_LcprepKategoriUmumChex) as chex - FROM lcprep_kategoriumum - LEFT JOIN other_lcprepkategoriumum ON Other_LcprepKategoriUmumLcprep_KategoriUmumID = Lcprep_KategoriUmumID AND - Other_LcprepKategoriUmumOther_LcprepID = {$header_id} AND - Other_LcprepKategoriUmumIsActive = 'Y' - WHERE - Lcprep_KategoriUmumIsActive = 'Y' - GROUP BY Lcprep_KategoriUmumID - "; - //echo $sql; - $kategoriumum = $this->db_smartone->query($sql)->result_array(); - foreach($kategoriumum as $kc => $vc){ - $kategoriumum[$kc]['chex'] = $vc['chex'] == 'N'?false:true; - } - - $sql = " - SELECT Lcprep_InterpretasiGroupID as group_id, - Lcprep_InterpretasiGroupName as group_name, - '' as subgroups - FROM lcprep_interpretasigroup - WHERE - Lcprep_InterpretasiGroupIsActive = 'Y' - "; - //echo $sql; - $interpretasi = $this->db_smartone->query($sql)->result_array(); - foreach($interpretasi as $k => $v){ - $subgroups = array(); - $sql = "SELECT Lcprep_InterpretasiSubgroupID as subgroup_id, - Lcprep_InterpretasiSubgroupName as subgroup_name, - '' as childs - FROM lcprep_interpretasisubgroup - WHERE - Lcprep_InterpretasiSubgroupLcprep_InterpretasiGroupID = {$v['group_id']} AND Lcprep_InterpretasiSubgroupIsActive = 'Y'"; - //echo $sql; - $subgroups = $this->db_smartone->query($sql)->result_array(); - if(count($subgroups) > 0){ - foreach($subgroups as $ki => $vi){ - $childs = array(); - $sql = "SELECT IFNULL(Other_LcprepInterpretasiID,0) as xid, - IFNULL(Other_LcprepInterpretasiChex,'N') as chex, - IFNULL(Other_LcprepInterpretasiValue,'') as value, - Lcprep_InterpretasiID as id, - Lcprep_InterpretasiLcprep_InterpretasiSubgroupID as subgroup_id, - Lcprep_InterpretasiCode as code, - Lcprep_InterpretasiName as name, - Lcprep_InterpretasiParentID as parent_id, - Lcprep_InterpretasiIsParent as is_parent, - Lcprep_InterpretasiHasResult as has_result, - Lcprep_InterpretasiTypeResult as type_result - FROM lcprep_interpretasi - LEFT JOIN other_lcprepinterpretasi ON Other_LcprepInterpretasiOther_LcprepID = {$header_id} AND - Other_LcprepInterpretasiLcprep_InterpretasiID = Lcprep_InterpretasiID AND - Other_LcprepInterpretasiIsActive = 'Y' - WHERE - Lcprep_InterpretasiLcprep_InterpretasiSubgroupID = {$vi['subgroup_id']} AND Lcprep_InterpretasiIsActive = 'Y' - GROUP BY Lcprep_InterpretasiID Order BY Lcprep_InterpretasiCode ASC"; - $childs = $this->db_smartone->query($sql)->result_array(); - if($childs){ - foreach($childs as $kc => $vc){ - $childs[$kc]['chex'] = $vc['chex'] == 'N'?false:true; - } - } - $subgroups[$ki]['childs'] = $childs; - } - } - - $interpretasi[$k]['subgroups'] = $subgroups; - } - - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $rst = array('doctors'=>$doctors,'results'=>$rows,'adekuasi'=>$adeakuasi,'kategoriumum'=>$kategoriumum,'interpretasi'=>$interpretasi); - $this->sys_ok(["records"=>$rst]); - } - - function getpapsmearresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT Other_PapSmearDetailsID as xid, - Other_PapSmearID as header_id, - Other_PapSmearT_OrderDetailID as orderdetail_id, - Other_PapSmearDetailsCode as code, - Other_PapSmearDetailsLabel as label, - Other_PapSmearDetailsResult as result, - IFNULL(Other_PapSmearM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_PapSmearM_DoctorID) OR Other_PapSmearM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_papsmear - JOIN other_papsmeardetails ON Other_PapSmearDetailsOther_PapSmearID = Other_PapSmearID AND Other_PapSmearDetailsIsActive = 'Y' - LEFT JOIN m_doctor ON Other_PapSmearM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_PapSmearT_OrderDetailID = {$id} AND Other_PapSmearIsActive = 'Y' - GROUP BY Other_PapSmearDetailsID - ORDER BY Other_PapSmearDetailsCode ASC"; - //echo $sql; - $rows = $this->db_smartone->query($sql)->result_array(); - if(!$rows){ - $rows = array( - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'A', - 'label' => 'Makroskopik', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ), - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'B', - 'label' => 'Mikroskopik', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ), - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'C', - 'label' => 'Kesimpulan', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ) - ); - } - - $header_id = $rows[0]['header_id']; - $sql = "SELECT Other_PapSmearMaturasiID as xid, - Other_PapSmearMaturasiValue as value - FROM other_papsmearmaturasi - WHERE - Other_PapSmearMaturasiOther_PapSmearID = {$header_id} AND - Other_PapSmearMaturasiIsActive = 'Y' - "; - //echo $sql; - $dt_maturasi = $this->db_smartone->query($sql)->row_array(); - if(!$dt_maturasi){ - $maturasi = array('xid'=>'0','value'=> array('','','')); - } - else{ - $value = explode('/',$dt_maturasi['value']); - $maturasi = array('xid'=>$dt_maturasi['xid'],'value'=> $value); - } - - $sql = "SELECT IFNULL(Other_PapSmearBahanID,0) as xid, - M_PapSmearBahanID as bahan_id, - M_PapSmearBahanName as name, - IF(ISNULL(Other_PapSmearBahanID),'N','Y') as selected - FROM m_papsmearbahan - LEFT JOIN other_papsmearbahan ON Other_PapSmearBahanM_PapSmearBahanID = M_PapSmearBahanID AND - Other_PapSmearBahanOther_PapSmearID = {$header_id} AND - Other_PapSmearBahanIsActive = 'Y' - WHERE - M_PapSmearBahanIsActive = 'Y' - ORDER BY M_PapSmearBahanID ASC - "; - //echo $sql; - $bahans = $this->db_smartone->query($sql)->result_array(); - - $sql = "SELECT IFNULL(Other_PapsmearCategoryID,0) as xid, - M_PapSmearCategoryID as category_id, - M_PapSmearCategoryName as name, - IF(ISNULL(Other_PapsmearCategoryID),'N','Y') as selected - FROM m_papsmearcategory - LEFT JOIN other_papsmearcategory ON Other_PapsmearCategoryM_PapSmearCategoryID = M_PapSmearCategoryID AND - Other_PapsmearCategoryOther_PapSmearID = {$header_id} AND - Other_PapsmearCategoryIsActive = 'Y' - WHERE - M_PapSmearCategoryIsActive = 'Y' - ORDER BY M_PapSmearCategoryID ASC - "; - //echo $sql; - $categories = $this->db_smartone->query($sql)->result_array(); - - $sql = "SELECT IFNULL(Other_PapSmearCheckID,0) as xid, - M_PapSmearCheckID as check_id, - M_PapSmearCheckLabel as name, - IF(ISNULL(Other_PapSmearCheckID),'N','Y') as selected, - Other_PapSmearCheckNote as note - FROM m_papsmearcheck - LEFT JOIN other_papsmearcheck ON Other_PapSmearCheckM_PapSmearCheckID = M_PapSmearCheckID AND - Other_PapSmearCheckOther_PapSmearID = {$header_id} AND - Other_PapSmearCheckIsActive = 'Y' - WHERE - M_PapSmearCheckIsActive = 'Y' - ORDER BY M_PapSmearCheckCode ASC - "; - $checks = $this->db_smartone->query($sql)->result_array(); - - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $rst = array('doctors'=>$doctors,'checks'=>$checks,'bahans'=>$bahans,'categories'=>$categories,'maturasi'=>$maturasi,'results'=>$rows); - $this->sys_ok(["records"=>$rst]); - - } - - function saveresult_lcprep() - { - $prm = $this->sys_input; - $detail_id = $prm['detail_id']; - $doctor_id = $prm['doctor']; - $adekuasi = $prm['adekuasi']; - $kategoriumum = $prm['kategoriumum']; - $interpretasi = $prm['interpretasi']; - $results = $prm['results']; - - $userid = $this->sys_user['M_UserID']; - - $header_id = 0; - $sql = "SELECT * FROM other_lcprep WHERE Other_LcprepT_orderDetailID = {$detail_id} AND Other_LcprepIsActive = 'Y'"; - $dt_header = $this->db_smartone->query($sql)->row_array(); - if($dt_header){ - $header_id = $dt_header['Other_LcprepID']; - } - if($header_id == 0){ - $sql = "INSERT INTO other_lcprep( - Other_LcprepT_orderDetailID, - Other_LcprepM_DoctorID, - Other_LcprepUserID, - Other_LcprepCreated - ) - VALUES( - {$detail_id}, - {$doctor_id}, - {$userid}, - NOW() - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - }else{ - $sql = "UPDATE other_lcprep SET Other_LcprepM_DoctorID = {$doctor_id}, Other_LcprepUserID = {$userid} WHERE Other_LcprepID = {$header_id}"; - $this->db_smartone->query($sql); - } - - if($adekuasi){ - foreach($adekuasi as $k =>$v){ - $selected = $v['chex']?'Y':'N'; - if(intval($v['xid'] == 0)){ - $sql = "UPDATE other_lcprepadekuasi SET Other_LcprepAdekuasiIsActive = 'N' - WHERE - Other_LcprepAdekuasiOther_LcprepID = {$header_id} AND - Other_LcprepAdekuasiIsActive = 'Y' AND - Other_LcprepAdekuasiLcprep_AdekuasiID = {$v['id']}"; - $this->db_smartone->query($sql); - $sql = "INSERT INTO other_lcprepadekuasi ( - Other_LcprepAdekuasiOther_LcprepID, - Other_LcprepAdekuasiLcprep_AdekuasiID, - Other_LcprepAdekuasiChex, - Other_LcprepAdekuasiUserID, - Other_LcprepAdekuasiCreated - ) - VALUES( - {$header_id}, - {$v['id']}, - '{$selected}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - //echo $sql; - } - if(intval($v['xid'] != 0)){ - - $sql = "UPDATE other_lcprepadekuasi SET - Other_LcprepAdekuasiChex = '{$selected}', - Other_LcprepAdekuasiUserID = {$userid} - WHERE - Other_LcprepAdekuasiID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - - //echo $sql; - } - } - - if($kategoriumum){ - foreach($kategoriumum as $k =>$v){ - $selected = $v['chex']?'Y':'N'; - if(intval($v['xid'] == 0)){ - $sql = "UPDATE other_lcprepkategoriumum SET Other_LcprepKategoriUmumIsActive = 'N' - WHERE - Other_LcprepKategoriUmumOther_LcprepID = {$header_id} AND - Other_LcprepKategoriUmumLcprep_KategoriUmumID = {$v['id']} AND - Other_LcprepKategoriUmumIsActive = 'Y' - "; - $this->db_smartone->query($sql); - $sql = "INSERT INTO other_lcprepkategoriumum ( - Other_LcprepKategoriUmumOther_LcprepID, - Other_LcprepKategoriUmumLcprep_KategoriUmumID, - Other_LcprepKategoriUmumChex, - Other_LcprepKategoriUmumUserID, - Other_LcprepKategoriUmumCreated - ) - VALUES( - {$header_id}, - {$v['id']}, - '{$selected}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if(intval($v['xid'] != 0)){ - $sql = "UPDATE other_lcprepkategoriumum SET - Other_LcprepKategoriUmumChex = '{$selected }', - Other_LcprepKategoriUmumUserID = {$userid} - WHERE - Other_LcprepKategoriUmumID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - - //echo $sql; - } - } - - if($results){ - foreach($results as $k =>$v){ - if(intval($v['xid'] == 0)){ - $sql = "UPDATE other_lcprepdetails SET Other_LcprepDetailsIsActive = 'N' - WHERE - Other_LcprepDetailsOther_LcprepID = {$header_id} AND - Other_LcprepDetailsCode = '{$v['code']}' AND - Other_LcprepDetailsIsActive = 'Y'"; - $this->db_smartone->query($sql); - $sql = "INSERT INTO other_lcprepdetails ( - Other_LcprepDetailsOther_LcprepID, - Other_LcprepDetailsCode, - Other_LcprepDetailsLabel, - Other_LcprepDetailsResult, - Other_LcprepDetailsUserID, - Other_LcprepDetailsCreated - ) - VALUES( - {$header_id}, - '{$v['code']}', - '{$v['label']}', - '{$v['result']}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if(intval($v['xid'] != 0)){ - $sql = "UPDATE other_lcprepdetails SET - Other_LcprepDetailsCode = '{$v['code']}', - Other_LcprepDetailsLabel = '{$v['label']}', - Other_LcprepDetailsResult = '{$v['result']}', - Other_LcprepDetailsUserID = {$userid} - WHERE - Other_LcprepDetailsID = {$v['xid']}"; - $this->db_smartone->query($sql); - - } - //echo $sql; - } - } - - if($interpretasi){ - foreach($interpretasi as $k =>$v){ - if(count($v['subgroups']) > 0){ - foreach($v['subgroups'] as $ik => $iv){ - if(count($iv['childs']) > 0){ - foreach($iv['childs'] as $iik => $iiv){ - if(intval($iiv['xid'] == 0)){ - $chex = $iiv['chex'] ? 'Y':'N'; - $sql = "UPDATE other_lcprepinterpretasi SET Other_LcprepInterpretasiIsActive = 'N' - WHERE - Other_LcprepInterpretasiOther_LcprepID = {$header_id} AND - Other_LcprepInterpretasiLcprep_InterpretasiID = '{$iiv['id']}' AND - Other_LcprepInterpretasiIsActive = 'Y'"; - $this->db_smartone->query($sql); - $sql = "INSERT INTO other_lcprepinterpretasi ( - Other_LcprepInterpretasiOther_LcprepID, - Other_LcprepInterpretasiLcprep_InterpretasiID, - Other_LcprepInterpretasiChex, - Other_LcprepInterpretasiValue, - Other_LcprepInterpretasiUserID, - Other_LcprepInterpretasiCreated - ) - VALUES( - {$header_id}, - '{$iiv['id']}', - '{$chex}', - '{$iiv['value']}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - - if(intval($iiv['xid'] != 0)){ - $chex = $iiv['chex'] ? 'Y':'N'; - $sql = "UPDATE other_lcprepinterpretasi SET - Other_LcprepInterpretasiChex = '{$chex}', - Other_LcprepInterpretasiValue = '{$iiv['value']}', - Other_LcprepInterpretasiUserID = {$userid} - WHERE - Other_LcprepInterpretasiID = {$iiv['xid']}"; - $this->db_smartone->query($sql); - //echo $sql; - - } - - } - } - } - } - //echo $sql; - } - } - - - $result = array("total" => 1, "records" => array(), "sql"=> ''); - $this->sys_ok($result); - exit; - } - - function saveresult_papsmear() - { - $prm = $this->sys_input; - $detail_id = $prm['detail_id']; - $doctor_id = $prm['doctor']; - $checks = $prm['checks']; - $maturasi = $prm['maturasi']; - $bahans = $prm['bahans']; - $categories = $prm['categories']; - $results = $prm['results']; - - $userid = $this->sys_user['M_UserID']; - - $header_id = 0; - $sql = "SELECT * FROM other_papsmear WHERE Other_PapSmearT_OrderDetailID = {$detail_id} AND Other_PapSmearIsActive = 'Y'"; - $dt_header = $this->db_smartone->query($sql)->row_array(); - if($dt_header){ - $header_id = $dt_header['Other_PapSmearID']; - } - if($header_id == 0){ - $sql = "INSERT INTO other_papsmear( - Other_PapSmearT_OrderDetailID, - Other_PapSmearM_DoctorID, - Other_PapSmearUserID, - Other_PapSmearCreated - ) - VALUES( - {$detail_id}, - {$doctor_id}, - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } - else{ - $sql = "UPDATE other_papsmear SET Other_PapSmearM_DoctorID = {$doctor_id}, Other_PapSmearUserID = {$userid} WHERE Other_PapSmearID = {$header_id}"; - $this->db_smartone->query($sql); - } - - if($checks){ - foreach($checks as $k =>$v){ - if(intval($v['xid']) == 0 && $v['selected'] === 'Y'){ - $sql = "INSERT INTO other_papsmearcheck ( - Other_PapSmearCheckOther_PapSmearID, - Other_PapSmearCheckM_PapSmearCheckID, - Other_PapSmearCheckNote, - Other_PapSmearCheckUserID, - Other_PapSmearCheckCreated - ) - VALUES( - {$header_id}, - {$v['check_id']}, - '{$v['note']}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if(intval($v['xid']) != 0 && $v['selected'] === 'N'){ - $sql = "UPDATE other_papsmearcheck SET - Other_PapSmearCheckIsActive = 'N', - Other_PapSmearCheckUserID = {$userid} - WHERE - Other_PapSmearCheckID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - if(intval($v['xid']) != 0 && $v['selected'] === 'Y'){ - $sql = "UPDATE other_papsmearcheck SET - Other_PapSmearCheckNote = '{$v['note']}', - Other_PapSmearCheckUserID = {$userid} - WHERE - Other_PapSmearCheckID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - //echo $sql; - } - } - - if($maturasi){ - if(intval($maturasi['xid']) == 0){ - $value = join("/",$maturasi['value']); - $sql = "INSERT INTO other_papsmearmaturasi ( - Other_PapSmearMaturasiOther_PapSmearID, - Other_PapSmearMaturasiValue, - Other_PapSmearMaturasiUserID, - Other_PapSmearMaturasiCreated - ) - VALUE( - {$header_id}, - '{$value}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - //echo $sql; - } - if(intval($maturasi['xid']) != 0){ - $value = join("/",$maturasi['value']); - $sql = "UPDATE other_papsmearmaturasi SET - Other_PapSmearMaturasiValue = '{$value}', - Other_PapSmearMaturasiUserID = {$userid} - WHERE - Other_PapSmearMaturasiID = {$maturasi['xid']}"; - // echo $sql; - $this->db_smartone->query($sql); - } - } - - if($bahans){ - foreach($bahans as $k =>$v){ - if(intval($v['xid']) == 0 && $v['selected'] === 'Y'){ - $sql = "INSERT INTO other_papsmearbahan ( - Other_PapSmearBahanOther_PapSmearID, - Other_PapSmearBahanM_PapSmearBahanID, - Other_PapSmearBahanUserID, - Other_PapSmearBahanCreated - ) - VALUES( - {$header_id}, - {$v['bahan_id']}, - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if(intval($v['xid']) != 0 && $v['selected'] === 'N'){ - $sql = "UPDATE other_papsmearbahan SET - Other_PapSmearBahanIsActive = 'N', - Other_PapsmearCategoryUserID = {$userid} - WHERE - Other_PapSmearBahanID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - if(intval($v['xid']) != 0 && $v['selected'] === 'Y'){ - $sql = "UPDATE other_papsmearbahan SET - Other_PapSmearBahanIsActive = 'Y', - Other_PapsmearCategoryUserID = {$userid} - WHERE - Other_PapSmearBahanID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - //echo $sql; - } - } - - if($categories){ - foreach($categories as $k =>$v){ - if(intval($v['xid']) == 0 && $v['selected'] === 'Y'){ - $sql = "INSERT INTO other_papsmearcategory ( - Other_PapsmearCategoryOther_PapSmearID, - Other_PapsmearCategoryM_PapSmearCategoryID, - Other_PapsmearCategoryUserID, - Other_PapsmearCategoryCreated - ) - VALUES( - {$header_id}, - {$v['category_id']}, - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if(intval($v['xid']) != 0 && $v['selected'] === 'N'){ - $sql = "UPDATE other_papsmearcategory SET - Other_PapsmearCategoryIsActive = 'N', - Other_PapsmearCategoryUserID = {$userid} - WHERE - Other_PapsmearCategoryID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - //echo $sql; - if(intval($v['xid']) != 0 && $v['selected'] === 'Y'){ - $sql = "UPDATE other_papsmearcategory SET - Other_PapsmearCategoryIsActive = 'Y', - Other_PapsmearCategoryUserID = {$userid} - WHERE - Other_PapsmearCategoryID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - } - } - - if($results){ - foreach($results as $k =>$v){ - if(intval($v['xid']) == 0){ - $sql = "INSERT INTO other_papsmeardetails ( - Other_PapSmearDetailsOther_PapSmearID, - Other_PapSmearDetailsCode, - Other_PapSmearDetailsLabel, - Other_PapSmearDetailsResult, - Other_PapSmearDetailsUserID, - Other_PapSmearDetailsCreated - ) - VALUES( - {$header_id}, - '{$v['code']}', - '{$v['label']}', - '{$v['result']}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if(intval($v['xid']) != 0){ - $sql = "UPDATE other_papsmeardetails SET - Other_PapSmearDetailsCode = '{$v['code']}', - Other_PapSmearDetailsLabel = '{$v['label']}', - Other_PapSmearDetailsResult = '{$v['result']}', - Other_PapSmearDetailsUserID = {$userid} - WHERE - Other_PapSmearDetailsID = {$v['xid']}"; - $this->db_smartone->query($sql); - - } - //echo $sql; - } - } - - $result = array("total" => 1, "records" => array(), "sql"=> ''); - $this->sys_ok($result); - exit; - } - - function saveresult_fna() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = $inp['doctor']; - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - if($prm[0]['xid'] == '0'){ - $sql = "INSERT INTO other_fna( - Other_FNAM_DoctorID, - Other_FNAT_OrderDetailID, - Other_FNAUserID, - Other_FNACreated - ) - VALUES( - {$doctor_id}, - {$prm[0]['orderdetail_id']}, - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } - else{ - $sql = "SELECT * FROM other_fna WHERE Other_FNAT_OrderDetailID = {$prm[0]['orderdetail_id']} AND Other_FNAIsActive = 'Y'"; - $data_header = $this->db_smartone->query($sql)->row_array(); - $header_id = $data_header['Other_FNAID']; - $sql = "UPDATE other_fna SET - Other_FNAM_DoctorID = {$doctor_id}, - Other_FNAUserID = {$userid} - WHERE - Other_FNAID = {$header_id}"; - $this->db_smartone->query($sql); - } - foreach($prm as $k => $v){ - if($v['xid'] == '0'){ - $results = str_replace("'", "\\'", $v['result']); - $sql = "INSERT INTO other_fnadetails( - Other_FNADetailsOther_FNAID , - Other_FNADetailsCode, - Other_FNADetailsLabel, - Other_FNADetailsResult, - Other_FNADetailsCreated, - Other_FNADetailsUserID - ) - VALUES( - {$header_id}, - '{$v['code']}', - '{$v['label']}', - '{$results}', - NOW(), - {$userid} - )"; - $query = $this->db_smartone->query($sql); - } - else{ - $results = str_replace("'", "\\'", $v['result']); - $sql = "UPDATE other_fnadetails SET - Other_FNADetailsResult = '{$results}', - Other_FNADetailsUserID = {$userid} - WHERE - Other_FNADetailsID = {$v['xid']}"; - $query = $this->db_smartone->query($sql); - } - } - - $result = array("total" => 1, "records" => array(), "sql"=> ''); - $this->sys_ok($result); - exit; - } - - function saveresult_cytologi() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = $inp['doctor']; - - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - if($prm[0]['xid'] == '0'){ - $sql = "INSERT INTO other_cytologi( - Other_CytologiT_OrderDetailID, - Other_CytologiM_DoctorID, - Other_CytologiUserID, - Other_CytologiCreated - ) - VALUES( - {$prm[0]['orderdetail_id']}, - {$doctor_id}, - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } - else{ - $sql = "SELECT * FROM other_cytologi WHERE Other_CytologiT_OrderDetailID = {$prm[0]['orderdetail_id']} AND Other_CytologiIsActive = 'Y'"; - $data_header = $this->db_smartone->query($sql)->row_array(); - $header_id = $data_header['Other_CytologiID']; - $sql = "UPDATE other_cytologi SET - Other_CytologiM_DoctorID = {$doctor_id}, - Other_CytologiUserID = {$userid} - WHERE - Other_CytologiID = {$header_id}"; - $this->db_smartone->query($sql); - } - foreach($prm as $k => $v){ - if($v['xid'] == '0'){ - $results = str_replace("'", "\\'", $v['result']); - $sql = "INSERT INTO other_cytologidetails( - Other_CytologiDetailsOther_CytologiID , - Other_CytologiDetailsCode, - Other_CytologiDetailsLabel, - Other_CytologiDetailsResult, - Other_CytologiDetailsCreated, - Other_CytologiDetailsUserID - ) - VALUES( - {$header_id}, - '{$v['code']}', - '{$v['label']}', - '{$results}', - NOW(), - {$userid} - )"; - $query = $this->db_smartone->query($sql); - } - else{ - $results = str_replace("'", "\\'", $v['result']); - $sql = "UPDATE other_cytologidetails SET - Other_CytologiDetailsResult = '{$results}', - Other_CytologiDetailsUserID = {$userid} - WHERE - Other_CytologiDetailsID = {$v['xid']}"; - $query = $this->db_smartone->query($sql); - } - } - - $result = array("total" => 1, "records" => array(), "sql"=> ''); - $this->sys_ok($result); - exit; - } - - function saveresult_mikro() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = $inp['doctor']; - $backteria_id = $inp['bacteria']; - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - - if($inp['result_value'] != 'Negatif' && $inp['result_value'] != 'Positif'){ - $prm['result_value'] = $prm['result_other']; - } - else{ - $prm['result_value'] = $inp['result_value']; - } - - if($prm['xid'] == '0'){ - $sql = "INSERT INTO other_mikro( - Other_MikroM_DoctorID, - Other_MikroResult, - Other_MikroT_BacteriaID, - Other_MikroT_OrderDetailID, - Other_MikroHasilBiakan, - Other_MikroSampleTypeName, - Other_MikroUserID, - Other_MikroCreated - ) - VALUES( - {$doctor_id}, - '{$prm['result_value']}', - {$backteria_id}, - {$prm['orderdetail_id']}, - '{$prm['hasil_biakan']}', - '{$prm['sample_name']}', - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } - else{ - $sql = "SELECT * FROM other_mikro WHERE Other_MikroT_OrderDetailID = {$prm['orderdetail_id']} AND Other_MikroIsActive = 'Y'"; - $data_header = $this->db_smartone->query($sql)->row_array(); - $header_id = $data_header['Other_MikroID']; - $sql = "UPDATE other_mikro SET - Other_MikroResult = '{$prm['result_value']}', - Other_MikroM_DoctorID = {$doctor_id}, - Other_MikroT_BacteriaID = {$backteria_id}, - Other_MikroHasilBiakan = '{$prm['hasil_biakan']}', - Other_MikroSampleTypeName = '{$prm['sample_name']}', - Other_MikroUserID = {$userid} - WHERE - Other_MikroID = {$header_id}"; - //echo $sql; - $this->db_smartone->query($sql); - } - - - - $sql = "UPDATE other_mikrodetails SET Other_MikroDetailsIsActive = 'N', Other_MikroDetailsUserID = 0 WHERE Other_MikroDetailsOther_MikroID = {$header_id}"; - $this->db_smartone->query($sql); - - $results = $prm['details']; - if($inp['result_value'] == 'Positif'){ - foreach($results as $k => $v){ - if($v['xid'] == '0'){ - $sql = "INSERT INTO other_mikrodetails( - Other_MikroDetailsOther_MikroID , - Other_MikroDetailsT_AntibioticID, - Other_MikroDetailsValue, - Other_MikroDetailsNote, - Other_MikroDetailsCreated, - Other_MikroDetailsUserID - ) - VALUES( - {$header_id}, - '{$v['T_AntibioticID']}', - '{$v['value']}', - '{$v['note']}', - NOW(), - {$userid} - )"; - $query = $this->db_smartone->query($sql); - } - else{ - $sql = "UPDATE other_mikrodetails SET - Other_MikroDetailsT_AntibioticID = '{$v['T_AntibioticID']}', - Other_MikroDetailsValue = '{$v['value']}', - Other_MikroDetailsNote = '{$v['note']}', - Other_MikroDetailsIsActive = 'Y', - Other_MikroDetailsUserID = {$userid} - WHERE - Other_MikroDetailsID = {$v['xid']}"; - //echo $sql; - $query = $this->db_smartone->query($sql); - } - } - } - - - $result = array("total" => 1, "records" => array(), "sql"=> ''); - $this->sys_ok($result); - exit; - } - - - function get_doctors_preparasi_sperma() - { - $prm = $this->sys_input; - // $id = $prm["id"]; - - $sql = " SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 10 AND - M_DoctorSOIsActive = 'Y' - ORDER BY M_DoctorName ASC"; - //echo $sql; - $query = $this->db_smartone->query($sql); - $rows = $query->result_array(); - $sql = " - SELECT '0' as id, 'Belum memilih metode' as name - UNION - SELECT M_MethodeSpermaID as id, M_MethodeSpermaName as name - FROM m_methodesperma - WHERE - M_MethodeSpermaIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $methodes = $this->db_smartone->query($sql)->result_array(); - - - $this->sys_ok(["records"=>$rows,"methodes"=>$methodes]); - - } - - - function getpreparasispermaresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT other_preparasisperma.*, - Other_PreparasiSpermaID as xid, - Other_PreparasiSpermaT_OrderDetailID as orderdetail_id, - IFNULL(Other_PreparasiSpermaM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_PreparasiSpermaM_DoctorID) OR Other_PreparasiSpermaM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name, - IFNULL(M_MethodeSpermaID,0) as methode_id, - IFNULL(M_MethodeSpermaName,'') as methode_name - FROM other_preparasisperma - LEFT JOIN m_doctor ON Other_PreparasiSpermaM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - LEFT JOIN m_methodesperma ON Other_PreparasiSpermaM_MethodeSpermaID = M_MethodeSpermaID AND - M_MethodeSpermaIsActive = 'Y' - WHERE - Other_PreparasiSpermaT_OrderDetailID = {$id} AND Other_PreparasiSpermaIsActive = 'Y' - GROUP BY Other_PreparasiSpermaID"; - $query = $this->db_smartone->query($sql); - - if ($query) - { - $rows = $query->row_array(); - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 10 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $sql = " - SELECT '0' as id, 'Belum memilih metode' as name - UNION - SELECT M_MethodeSpermaID as id, M_MethodeSpermaName as name - FROM m_methodesperma - WHERE - M_MethodeSpermaIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $methodes = $this->db_smartone->query($sql)->result_array(); - $images = array(); - $sql = "SELECT Other_PreparasiSpermaImgID as xid, - Other_PreparasiSpermaImgType as type, - CONCAT('/one-media/one-image-nonlab/',Other_PreparasiSpermaImgNewName) as image_url - FROM t_orderdetail - JOIN other_preparasisperma_img ON Other_PreparasiSpermaImgT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND - Other_PreparasiSpermaImgIsActive = 'Y' - WHERE - T_OrderDetailID = {$id} AND - T_OrderDetailIsActive = 'Y' - GROUP BY Other_PreparasiSpermaImgID"; - //echo $sql; - $images = $this->db_smartone->query($sql)->result_array(); - - $rst = array('doctors'=>$doctors,'methodes'=>$methodes,'results'=>$rows,'images'=>$images); - $this->sys_ok(["records"=>$rst]); - } - else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - - function uploadimage_preparasi_sperma(){ - if (! $this->isLogin) { - $this->sys_error("Invalid Token"); - exit; - } - - $userid = $this->sys_user["M_UserID"]; - $data = []; - //print_r($_SERVER); - - $prm = $this->sys_input; - $orderid = $this->input->post('orderid'); - $type = $this->input->post('type'); - $labnumber = $this->input->post('labnumber'); - $sql = "UPDATE other_preparasisperma_img SET - Other_PreparasiSpermaImgIsActive = 'N', - Other_PreparasiSpermaImgUserID = {$userid} - WHERE - Other_PreparasiSpermaImgT_OrderHeaderID = {$orderid} AND - Other_PreparasiSpermaImgType = '{$type}'"; - //echo $sql; - $this->db_onedev->query($sql); - //$config['upload_path'] = 'assets/'; - - $path = '/home/one/project/one/one-media/one-image-nonlab/'; - //echo $path; - $config['upload_path'] = $path; - $config['allowed_types'] = 'jpg|jpeg|png|gif'; - - $config['max_size'] = '10000'; - $count = count($_FILES['files']['name']); - //echo $count; - $this->load->library('upload',$config); - - $error = []; - for($i=0;$i<$count;$i++){ - - - if(!empty($_FILES['files']['name'][$i])){ - - - - $_FILES['file']['name'] = $_FILES['files']['name'][$i]; - - $_FILES['file']['type'] = $_FILES['files']['type'][$i]; - - $_FILES['file']['tmp_name'] = $_FILES['files']['tmp_name'][$i]; - - $_FILES['file']['error'] = $_FILES['files']['error'][$i]; - - $_FILES['file']['size'] = $_FILES['files']['size'][$i]; - - - - $namex = $orderid.'-'.$labnumber.'-'.$this->generateRandomString(5); - //echo $namex; - - $config['file_name'] = $namex; - $this->upload->initialize($config); - //echo $config['file_name'] ; - - - - - - if($this->upload->do_upload('file')){ - - $uploadData = $this->upload->data(); - - $filename = $uploadData['file_name']; - //echo $filename; - - - $sql = "INSERT INTO other_preparasisperma_img ( - Other_PreparasiSpermaImgT_OrderHeaderID, - Other_PreparasiSpermaImgType, - Other_PreparasiSpermaImgOldName, - Other_PreparasiSpermaImgNewName, - Other_PreparasiSpermaImgCreated, - Other_PreparasiSpermaImgUserID - ) - VALUES( - {$orderid}, - '{$type}', - '{$_FILES['files']['name'][$i]}', - '{$filename}', - NOW(), - {$userid} - - )"; - //echo $sql; - $this->db_onedev->query($sql); - $xlast_id = $this->db_onedev->insert_id(); - $data['totalFiles'][] = array('xid' => $xlast_id ,'type'=>$type,'image_url' => '/one-media/one-image-nonlab/'.$filename); - - } - else{ - $error = array('error' => $this->upload->display_errors()); - } - - } - - - - } - - $result = array("total" =>count( $data['totalFiles']), "records" => $data['totalFiles'],'errors'=>$error); - $this->sys_ok($result); - } - - - function saveresult_preparasi_sperma() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = $inp['doctor']; - $orderdetail_id = $inp['orderdetailid']; - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - if($prm['xid'] == '0'){ - $sql = "INSERT INTO other_preparasisperma( - Other_PreparasiSpermaM_DoctorID, - Other_PreparasiSpermaT_OrderDetailID, - Other_PreparasiSpermaPreMotilitasA, - Other_PreparasiSpermaPreMotilitasB, - Other_PreparasiSpermaPreMotilitasC, - Other_PreparasiSpermaPreKonsentrasi, - Other_PreparasiSpermaPreKontaminan, - Other_PreparasiSpermaPostMotilitasA, - Other_PreparasiSpermaPostMotilitasB, - Other_PreparasiSpermaPostMotilitasC, - Other_PreparasiSpermaPostKonsentrasi, - Other_PreparasiSpermaPostKontaminan, - Other_PreparasiSpermaPreVolume, - Other_PreparasiSpermaPostVolume, - Other_PreparasiSpermaM_MethodeSpermaID, - Other_PreparasiSpermaNote, - Other_PreparasiSpermaUserID, - Other_PreparasiSpermaCreated - ) - VALUES( - {$doctor_id}, - {$orderdetail_id}, - '{$prm['Other_PreparasiSpermaPreMotilitasA']}', - '{$prm['Other_PreparasiSpermaPreMotilitasB']}', - '{$prm['Other_PreparasiSpermaPreMotilitasC']}', - '{$prm['Other_PreparasiSpermaPreKonsentrasi']}', - '{$prm['Other_PreparasiSpermaPreKontaminan']}', - '{$prm['Other_PreparasiSpermaPostMotilitasA']}', - '{$prm['Other_PreparasiSpermaPostMotilitasB']}', - '{$prm['Other_PreparasiSpermaPostMotilitasC']}', - '{$prm['Other_PreparasiSpermaPostKonsentrasi']}', - '{$prm['Other_PreparasiSpermaPostKontaminan']}', - '{$prm['Other_PreparasiSpermaPreVolume']}', - '{$prm['Other_PreparasiSpermaPostVolume']}', - '{$prm['Other_PreparasiSpermaM_MethodeSpermaID']}', - '{$prm['Other_PreparasiSpermaNote']}', - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } - else{ - $sql = "SELECT * FROM other_preparasisperma WHERE Other_PreparasiSpermaT_OrderDetailID = {$orderdetail_id} AND Other_PreparasiSpermaIsActive = 'Y'"; - $data_header = $this->db_smartone->query($sql)->row_array(); - $header_id = $data_header['Other_PreparasiSpermaID']; - $sql = "UPDATE other_preparasisperma SET - Other_PreparasiSpermaM_DoctorID = {$doctor_id}, - Other_PreparasiSpermaPreMotilitasA = '{$prm['Other_PreparasiSpermaPreMotilitasA']}', - Other_PreparasiSpermaPreMotilitasB = '{$prm['Other_PreparasiSpermaPreMotilitasB']}', - Other_PreparasiSpermaPreMotilitasC = '{$prm['Other_PreparasiSpermaPreMotilitasC']}', - Other_PreparasiSpermaPreKonsentrasi = '{$prm['Other_PreparasiSpermaPreKonsentrasi']}', - Other_PreparasiSpermaPreKontaminan = '{$prm['Other_PreparasiSpermaPreKontaminan']}', - Other_PreparasiSpermaPostMotilitasA = '{$prm['Other_PreparasiSpermaPostMotilitasA']}', - Other_PreparasiSpermaPostMotilitasB = '{$prm['Other_PreparasiSpermaPostMotilitasB']}', - Other_PreparasiSpermaPostMotilitasC = '{$prm['Other_PreparasiSpermaPostMotilitasC']}', - Other_PreparasiSpermaPostKonsentrasi = '{$prm['Other_PreparasiSpermaPostKonsentrasi']}', - Other_PreparasiSpermaPostKontaminan = '{$prm['Other_PreparasiSpermaPostKontaminan']}', - Other_PreparasiSpermaPreVolume = '{$prm['Other_PreparasiSpermaPreVolume']}', - Other_PreparasiSpermaPostVolume = '{$prm['Other_PreparasiSpermaPostVolume']}', - Other_PreparasiSpermaM_MethodeSpermaID = '{$prm['Other_PreparasiSpermaM_MethodeSpermaID']}', - Other_PreparasiSpermaNote = '{$prm['Other_PreparasiSpermaNote']}', - Other_PreparasiSpermaUserID = {$userid} - WHERE - Other_PreparasiSpermaID = {$header_id}"; - $this->db_smartone->query($sql); - } - - - $result = array("total" => 1, "records" => array(), "sql"=> ''); - $this->sys_ok($result); - exit; - } - - function getdnafragmentasiresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT other_dnafragmentasi.*, - Other_DnaFragmentasiID as xid, - Other_DnaFragmentasiT_OrderDetailID as orderdetail_id, - IFNULL(Other_DnaFragmentasiM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_DnaFragmentasiM_DoctorID) OR Other_DnaFragmentasiM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name, - IFNULL(Other_DnaFragmentasiOther_DnaFragmentasiMethodeID,0) as methode_id, - IFNULL(Other_DnaFragmentasiMethodeName,'') as methode_name, - Other_DnaFragmentasiHaloLuas as halo_luas, - Other_DnaFragmentasiHaloSedang as halo_sedang, - Other_DnaFragmentasiHaloSempit as halo_sempit, - Other_DnaFragmentasiTanpaHalo as tanpa_halo, - Other_DnaFragmentasiDFI as dfi, - Other_DnaFragmentasiKesimpulan as kesimpulan, - Other_DnaFragmentasiCatatan as catatan - FROM other_dnafragmentasi - LEFT JOIN m_doctor ON Other_DnaFragmentasiM_DoctorID = M_DoctorID - LEFT JOIN other_dnafragmentasimethode ON Other_DnaFragmentasiOther_DnaFragmentasiMethodeID = Other_DnaFragmentasiMethodeID - WHERE - Other_DnaFragmentasiT_OrderDetailID = {$id} AND Other_DnaFragmentasiIsActive = 'Y' - GROUP BY Other_DnaFragmentasiID - LIMIT 1"; - //echo $sql; - $query = $this->db_smartone->query($sql); - - if ($query) - { - $rows = $query->row_array(); - if(!$rows){ - $rows = array( - 'xid' => 0, - 'orderdetail_id' =>$id, - 'doctor_id' => 0, - 'doctor_name' => '', - 'methode_id' => 0, - 'methode_name' => '', - 'halo_luas' => '', - 'halo_sedang' => '', - 'tanpa_halo' => '', - 'dfi' => '', - 'kesimpulan' => '', - 'catatan' => '' - ); - } - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID - WHERE - M_DoctorSONat_SubGroupID = 4 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - - $sql = " - SELECT '0' as id, 'Belum memilih metode' as name - UNION - SELECT Other_DnaFragmentasiMethodeID as id, Other_DnaFragmentasiMethodeName as name - FROM other_dnafragmentasimethode - WHERE - Other_DnaFragmentasiMethodeIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $methodes = $this->db_smartone->query($sql)->result_array(); - - - $rst = array('doctors'=>$doctors,'methodes'=>$methodes,'results'=>$rows); - $this->sys_ok(["records"=>$rst]); - } - else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - function saveresult_dnafragmentasi() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = $inp['doctor']['id']; - $methode_id = $inp['methode']['id']; - $orderdetail_id = $inp['results']['orderdetail_id']; - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - if(intval($prm['xid']) == 0){ - $sql = "INSERT INTO other_dnafragmentasi( - Other_DnaFragmentasiT_OrderDetailID, - Other_DnaFragmentasiM_DoctorID, - Other_DnaFragmentasiOther_DnaFragmentasiMethodeID, - Other_DnaFragmentasiHaloLuas, - Other_DnaFragmentasiHaloSedang, - Other_DnaFragmentasiHaloSempit, - Other_DnaFragmentasiTanpaHalo, - Other_DnaFragmentasiDFI, - Other_DnaFragmentasiKesimpulan, - Other_DnaFragmentasiCatatan, - Other_DnaFragmentasiUserID, - Other_DnaFragmentasiLastUpdated - ) - VALUES( - {$orderdetail_id}, - {$doctor_id}, - {$methode_id}, - '{$prm['halo_luas']}', - '{$prm['halo_sedang']}', - '{$prm['halo_sempit']}', - '{$prm['tanpa_halo']}', - '{$prm['dfi']}', - '{$prm['kesimpulan']}', - '{$prm['catatan']}', - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } - else{ - $sql = "UPDATE other_dnafragmentasi SET - Other_DnaFragmentasiT_OrderDetailID = {$orderdetail_id}, - Other_DnaFragmentasiM_DoctorID = {$doctor_id}, - Other_DnaFragmentasiOther_DnaFragmentasiMethodeID = '{$methode_id}', - Other_DnaFragmentasiHaloLuas = '{$prm['halo_luas']}', - Other_DnaFragmentasiHaloSedang = '{$prm['halo_sedang']}', - Other_DnaFragmentasiHaloSempit = '{$prm['halo_sempit']}', - Other_DnaFragmentasiTanpaHalo = '{$prm['tanpa_halo']}', - Other_DnaFragmentasiDFI = '{$prm['dfi']}', - Other_DnaFragmentasiKesimpulan = '{$prm['kesimpulan']}', - Other_DnaFragmentasiCatatan = '{$prm['catatan']}', - Other_DnaFragmentasiLastUpdated = NOW(), - Other_DnaFragmentasiUserID = {$userid} - WHERE - Other_DnaFragmentasiID = {$prm['xid']}"; - //echo $sql; - $this->db_smartone->query($sql); - } - - - $result = array("total" => 1, "records" => array(), "sql"=> ''); - $this->sys_ok($result); - exit; - } - - -} - +db_smartone = $this->load->database("onedev", true); + $this->load->helper(array('form', 'url')); + } + function getMethodeID($natTestID) { + $sql = "select M_MethodePriorityNat_MethodeID MethodeID, Nat_MethodeName + from + m_methode_priority + join nat_methode on Nat_MethodeID = M_MethodePriorityNat_MethodeID + and Nat_MethodeIsActive = 'Y' + join m_instrumentmethode on M_InstrumentMethodeNat_MethodeID = Nat_MethodeID and M_InstrumentMethodeIsActive = 'Y' + join nat_instrument on M_InstrumentMethodeNat_InstrumentID = Nat_InstrumentID + and Nat_InstrumentIsActive ='Y' + where M_MethodePriorityIsActive = 'Y' + and M_MethodePriorityNat_TestID = $natTestID + and M_MethodePriorityM_DayOfWeekID = dayofweek(now()) + order by M_MethodePriorityNumber desc + limit 0,1 "; + $qry = $this->db->query($sql); + if ($qry) { + $rows = $qry->result_array(); + if (count($rows) > 0 ) return array($rows[0]["MethodeID"],$rows[0]["Nat_MethodeName"]); + } + //2nd + $sql= "select + M_InstrumentMethodeNat_MethodeID MethodeID, Nat_MethodeName + from m_instrumentmethode + join nat_methode on M_InstrumentMethodeNat_MethodeID = Nat_MethodeID + and Nat_MethodeIsActive = 'Y' + join nat_instrument on M_InstrumentMethodeNat_InstrumentID = Nat_InstrumentID + and Nat_InstrumentIsActive ='Y' + where M_InstrumentMethodeNat_TestID = $natTestID + and M_InstrumentMethodeIsActive = 'Y' + order by M_InstrumentMethodePriority desc + limit 0,1"; + $qry = $this->db->query($sql); + if ($qry) { + $rows = $qry->result_array(); + if (count($rows) > 0 ) return array($rows[0]["MethodeID"],$rows[0]["Nat_MethodeName"]); + } + // + $sql = "select Nat_NormalValueNat_MethodeID MethodeID, Nat_MethodeName + from + nat_normalvalue + join nat_methode on Nat_NormalValueNat_MethodeID = Nat_MethodeID + and Nat_MethodeIsActive = 'Y' + where Nat_NormalValueNat_TestID = $natTestID + and Nat_NormalValueIsActive = 'Y' + order by Nat_NormalValueID + limit 0,1"; + $qry = $this->db->query($sql); + if ($qry) { + $rows = $qry->result_array(); + if (count($rows) > 0 ) return array($rows[0]["MethodeID"],$rows[0]["Nat_MethodeName"]); + } + return array(0,""); + } + function get_normal_value($methodeID, $natTestID, $sexID, $ageInDay ) { + $this->load->library('ibl_sampling_normal'); + return $this->ibl_sampling_normal->get_normal_value_id($methodeID, $natTestID, $sexID, $ageInDay); + } + return 0; + } + function fn_fix_normal($order_id) { + $sql = "select + T_OrderDetailID, M_PatientM_SexID, fn_global_age_count_day(M_PatientDOB, date(T_OrderHeaderDate)) Dob , + T_TestNat_TestID + from t_orderheader + join m_patient on T_OrderHeaderID = $order_id and T_OrderHeaderM_PatientID = M_PatientID + join t_orderdetail on T_OrderDetailT_OrderHeaderID = T_OrderHeaderID + and T_OrderDetailIsACtive = 'Y' + and ( T_OrderDetailNat_NormalValueID is null or T_OrderDetailNat_NormalValueID = 0 ) + join t_test on T_OrderDetailT_TestID = T_TestID and T_TestIsResult = 'Y' "; + $qry = $this->db->query($sql); + if(! $qry) { + return; + } + $rows = $qry->result_array(); + if(count($rows) == 0 ) return; + $sql_u = "update t_orderdetail + join nat_normalvalue on T_OrderDetailID = ? and Nat_NormalValueID = ? + set + T_OrderDetailNat_NormalValueID = Nat_NormalValueID, + T_OrderDetailNormalValueNote = Nat_NormalValueNote, + T_OrderDetailNormalValueDescription = Nat_NormalValueDescription, + T_OrderDetailMinValue = Nat_NormalValueMinValue, + T_OrderDetailMaxValue = Nat_NormalValueMaxValue, + T_OrderDetailMinValueInclusive = Nat_NormalValueMinValueInclusive, + T_OrderDetailMaxValueInclusive = Nat_NormalValueMaxValueInclusive, + T_OrderDetailNat_MethodeID = ?, + T_OrderdetailNat_MethodeName =?"; + + foreach($rows as $r) { + $T_OrderDetailID = $r["T_OrderDetailID"]; + $sexID = $r["M_PatientM_SexID"]; + $ageInDay = $r["Dob"]; + $natTestID = $r["T_TestNat_TestID"]; + list($methodeID,$methodeName) = $this->getMethodeID($natTestID); + if ($methodeID == 0 ) continue; + $normalValueID = $this->get_normal_value($methodeID, $natTestID, $sexID, $ageInDay); + if ($normalValueID == 0) return; + $this->db->query($sql_u, array($T_OrderDetailID, $normalValueID, $methodeID, $methodeName)); + } + } + function update_order_sample($targetID, $sourceID) { + $sql = "update t_ordersample target + join t_ordersample source on + target.T_OrderSampleID = ? + and target.T_OrderSampleWorklistReceive = 'N' + and source.T_OrderSampleID = ? + set + target.T_OrderSampleSampling = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSampling, source.T_OrderSampleSampling), + target.T_OrderSampleSamplingDate = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingDate, source.T_OrderSampleSamplingDate), + target.T_OrderSampleSamplingTime = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingTime, source.T_OrderSampleSamplingTime), + target.T_OrderSampleSamplingUserID = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingUserID, source.T_OrderSampleSamplingUserID), + + target.T_OrderSampleReceive = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceive, source.T_OrderSampleReceive), + target.T_OrderSampleReceiveDate = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveDate, source.T_OrderSampleReceiveDate), + target.T_OrderSampleReceiveTime = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveTime, source.T_OrderSampleReceiveTime), + target.T_OrderSampleReceiveUserID = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveUserID, source.T_OrderSampleReceiveUserID), + + target.T_OrderSampleVerification = if(target.T_OrderSampleVerification='Y',target.T_OrderSampleVerification, source.T_OrderSampleVerification), + target.T_OrderSampleVerificationDate =if(target.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationDate, source.T_OrderSampleVerificationDate), + target.T_OrderSampleVerificationTime =if(source.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationTime, source.T_OrderSampleVerificationTime), + target.T_OrderSampleVerificationUserID =if(source.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationUserID, source.T_OrderSampleVerificationUserID), + + target.T_OrderSampleProcessing = if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessing, source.T_OrderSampleProcessing), + target.T_OrderSampleProcessingDate= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingDate, source.T_OrderSampleProcessingDate), + target.T_OrderSampleProcessingTime= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingTime, source.T_OrderSampleProcessingTime), + target.T_OrderSampleProcessingUserID= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingUserID, source.T_OrderSampleProcessingUserID), + + target.T_OrderSampleReceiveHandling =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandling, source.T_OrderSampleReceiveHandling ), + target.T_OrderSampleReceiveHandlingDate =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingDate, source.T_OrderSampleReceiveHandlingDate), + target.T_OrderSampleReceiveHandlingTime =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingTime, source.T_OrderSampleReceiveHandlingTime), + target.T_OrderSampleReceiveHandlingUserID =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingUserID, source.T_OrderSampleReceiveHandlingUserID), + + target.T_OrderSampleHandling = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandling, source.T_OrderSampleHandling), + target.T_OrderSampleHandlingDate = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingDate, source.T_OrderSampleHandlingDate), + target.T_OrderSampleHandlingTime = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingTime, source.T_OrderSampleHandlingTime), + target.T_OrderSampleHandlingUserID = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingUserID, source.T_OrderSampleHandlingUserID), + + target.T_OrderSampleWorklistReceive = source.T_OrderSampleWorklistReceive, + target.T_OrderSampleWorklistReceiveDatetime = source.T_OrderSampleWorklistReceiveDateTime, + target.T_OrderSampleWorklistReceiveUserID = source.T_OrderSampleWorklistReceiveUserID + "; + $qry = $this->db->query($sql,array($targetID,$sourceID)); + if(! $qry ) { + echo json_encode(array( "status" => "ERR" , "message" => print_r($this->db->error(),true))); + exit; + } + } + function fix_sample_serum($headerID) { + //cari t_ordersample yg belum worklist receive dengan code 017% + $sql = "select T_OrderSampleID + from t_ordersample + join t_sampletype on + T_OrderSampleT_OrderHeaderID = ? + and T_OrderSampleWorklistReceive = 'N' + and T_OrderSampleIsActive = 'Y' + and T_OrderSampleT_SampleTypeID = T_SampletypeID + and T_SampleTypeCode like '017%' + "; + $qry = $this->db->query($sql, array($headerID)); + if(!$qry) { + echo json_encode(array( "status" => "ERR" , "message" => print_r($this->db->error(),true))); + exit; + } + $rows = $qry->result_array(); + if (count($rows) == 0 ) return; + //cari T_OrderSample yang sudah di receive yg terakhir + $sql = "select T_OrderSampleID + from t_ordersample + join t_sampletype on + T_OrderSampleT_OrderHeaderID = ? + and T_OrderSampleWorklistReceive = 'Y' + and T_OrderSampleIsActive = 'Y' + and T_OrderSampleT_SampleTypeID = T_SampletypeID + and T_SampleTypeCode like '017%' + order by T_OrderSampleWorklistReceiveDatetime desc + limit 0,1 + "; + $qry = $this->db->query($sql, array($headerID)); + if(!$qry) { + echo json_encode(array( "status" => "ERR" , "message" => print_r($this->db->error(),true))); + exit; + } + $rcv_rows = $qry->result_array(); + if (count($rcv_rows) == 0 ) return; + + //print_r($rows); + //print_r($rcv_rows); + $rcv_T_OrderSampleID = $rcv_rows[0]["T_OrderSampleID"]; + //ada yg belum di receive + foreach($rows as $r) { + $T_OrderSampleID = $r["T_OrderSampleID"]; + $this->update_order_sample($T_OrderSampleID,$rcv_T_OrderSampleID); + } + } + public function search() + { + $prm = $this->sys_input; + $max_rst = 99; + + $id = $prm["order_id"]; + if ($id > 0 ) { + $this->fix_sample_serum($id); + $this->fn_fix_normal($id); + } + $lang = $this->lang_default_code; + $lang_id = isset($prm['lang_id']) ? $prm['lang_id'] : '0'; + + if ($lang_id != 0) + { + $l = $this->db_smartone->where("Nat_LangID", $lang_id)->get("nat_lang")->row(); + $lang = $l->Nat_LangCode; + } + + //tambahan fajri + $sql = " UPDATE t_orderdetail + JOIN t_test ON T_OrderDetailT_TestID = T_TestID + SET T_OrderDetailT_TestIsResult = T_TestIsResult + WHERE + T_OrderDetailT_OrderHeaderID = {$id} AND + T_OrderDetailT_TestIsResult = '' AND + T_OrderDetailIsActive = 'Y'"; + $this->db_smartone->query($sql); + + $tot_count = 0; + $lq = ""; + $group_id = 0; + if (isset($prm['group_id'])) + $group_id = $prm['group_id']; + + if ($group_id != 0) + { + $sql = "select distinct T_WorklistDetailNat_TestID Nat_TestID + from t_worklistdetailv2 + where T_WorklistDetailT_WorklistID = {$group_id}"; + $qry = $this->db_smartone->query($sql); + $rows = $qry->result_array(); + $nat_test_ids = "0"; + foreach($rows as $r) { + $nat_test_ids .= ", " . $r["Nat_TestID"]; + } + $q_group = " ( $nat_test_ids ) "; + + $sql = " + SELECT a1.*, cOUNT(a2.T_OrderDetailID) level + FROM ( + SELECT IFNULL(y.T_OrderDetailT_TestID, x.T_OrderDetailT_TestID) t_testid, + IFNULL(y.T_OrderDetailT_TestName, y.T_OrderDetailT_TestName) t_testname, + y.T_OrderDetailResult result, y.T_OrderDetailResult result_old, y.T_OrderDetailNote note, y.T_OrderDetailNote note_old, + y.T_OrderDetailID id, + y.T_OrderDetailT_TestIsResult is_result, a.T_TestIsQuantitative is_quantitative, + y.T_OrderDetailResultFlag result_flag, + y.T_OrderDetailNat_NormalValueID normal_id, + y.T_OrderDetailNormalValueNote normal_note, y.T_OrderDetailNat_UnitName unit_name, + y.T_OrderdetailNat_MethodeID methode_id, y.T_OrderdetailNat_MethodeName methode_name, + a.T_TestNat_TestID nattest_id, a.T_TestID tx_id, count(T_ResultInstrumentID) as result_instrument_n, + y.T_OrderDetailVerification, T_OrderSampleReceive sample_receive, + T_OrderSampleProcessing sample_processing, T_OrderSampleWorklistReceive sample_worklist_receive, + IF(T_OrderDetailAddOnPreAnalytic = 'Y', T_OrderDetailAddOnPreAnalytic, PreAnalyticIsOk) pre_analytic, + T_OrderDetailAddOnPreAnalytic, + T_OrderHeaderID order_id, y.T_OrderDetailT_TestSasCode test_sas_code, + tx.T_TestSasCode, + T_OrderDetailAddOnResample `resample`, T_OrderDetailAddOnResampleStatus resample_status, + T_OrderDetailAddOnRef ref, y.T_OrderDetailVerification verification, y.T_OrderDetailValidation validation, + T_OrderPromiseDateTime, Group_ResultName as ResultGroupName + FROM t_orderdetail x + left join t_orderpromise on x.T_OrderDetailT_OrderPromiseID = T_OrderPromiseID + JOIN t_test tx ON x.T_OrderDetailT_TestID = T_TestID + JOIN t_test tcheck on tcheck.T_TestNat_TestID in {$q_group} + and ( tx.T_TestID = tcheck.T_TestID or tx.T_TestSasCode like concat(tcheck.T_TestSasCode,'%')) + LEFT JOIN group_resultdetail ON Group_ResultDetailT_TestID = x.T_OrderDetailT_TestID AND Group_ResultDetailIsActive = 'Y' + LEFT JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND Group_ResultFlagNonLab = 'N' + LEFT JOIN t_orderdetail y ON x.T_OrderDetailT_TestSasCode LIKE CONCAT(y.T_OrderDetailT_TestSasCode, '%') + AND x.T_OrderDetailT_OrderHeaderID = y.T_OrderDetailT_OrderHeaderID + AND y.T_OrderDetailIsActive = 'Y' + LEFT JOIN t_orderdetailaddon ON x.T_OrderDetailID = T_OrderDetailAddOnT_OrderDetailID + JOIN t_orderheader ON y.T_OrderDetailT_OrderHeaderID = T_OrderHeaderID + LEFT JOIN t_test a ON y.T_OrderDetailT_TestID = a.T_TestID + AND a.T_TestIsNonLab = '' + LEFT JOIN (SELECT T_OrderSampleT_SampleTypeID, T_OrderSampleReceive, T_OrderSampleProcessing, T_OrderSampleWorklistReceive + FROM t_ordersample WHERE T_OrderSampleT_OrderHeaderID = {$id} + AND T_OrderSampleIsactive = 'Y' + GROUP BY T_OrderSampleT_SampleTypeID) os ON a.T_TestT_SampleTypeID = os.T_OrderSampleT_SampleTypeID + or os.T_OrderSampleT_SampleTypeID = fn_sampletype_from_local(a.T_TestNat_TestID) + + LEFT JOIN t_resultinstrument ON T_ResultInstrumentT_OrderDetailID = x.T_OrderDetailID + LEFT JOIN pre_analytic ON PreAnalyticNat_TestID = a.T_TestNat_TestID AND PreAnalyticDate = date(now()) and PreAnalyticIsActive = 'Y' + WHERE x.T_OrderDetailT_OrderHeaderID = {$id} + AND x.T_OrderDetailIsActive = 'Y' + GROUP BY y.T_OrderDetailT_TestID + ORDER BY y.T_OrderDetailT_TestSasCode ASC + ) a1 + + LEFT JOIN t_orderdetail a2 ON a2.T_OrderDetailT_OrderHeaderID = a1.order_id + AND a2.T_OrderDetailIsActive = 'Y' + AND a1.test_sas_code LIKE CONCAT(a2.T_OrderDetailT_testSasCode, '%') + GROUP BY a1.t_testid + order by a1.test_sas_code +"; + $query = $this->db_smartone->query($sql); + $lq = $this->db_smartone->last_query(); + } + else + { + $sql = " + SELECT a1.*, cOUNT(a2.T_OrderDetailID) level + FROM ( + SELECT IFNULL(y.T_OrderDetailT_TestID, x.T_OrderDetailT_TestID) t_testid, + IFNULL(y.T_OrderDetailT_TestName, y.T_OrderDetailT_TestName) t_testname, + y.T_OrderDetailResult result, y.T_OrderDetailResult result_old, y.T_OrderDetailNote note, y.T_OrderDetailNote note_old, + y.T_OrderDetailID id, + y.T_OrderDetailT_TestIsResult is_result, a.T_TestIsQuantitative is_quantitative, + y.T_OrderDetailResultFlag result_flag, + y.T_OrderDetailNat_NormalValueID normal_id, + y.T_OrderDetailNormalValueNote normal_note, y.T_OrderDetailNat_UnitName unit_name, + y.T_OrderdetailNat_MethodeID methode_id, y.T_OrderdetailNat_MethodeName methode_name, + a.T_TestNat_TestID nattest_id, a.T_TestID tx_id, count(T_ResultInstrumentID) as result_instrument_n, + y.T_OrderDetailVerification, T_OrderSampleReceive sample_receive, + T_OrderSampleProcessing sample_processing, T_OrderSampleWorklistReceive sample_worklist_receive, + IF(T_OrderDetailAddOnPreAnalytic = 'Y', T_OrderDetailAddOnPreAnalytic, PreAnalyticIsOk) pre_analytic, + T_OrderDetailAddOnPreAnalytic, + T_OrderHeaderID order_id, y.T_OrderDetailT_TestSasCode test_sas_code, + tx.T_TestSasCode, + T_OrderDetailAddOnResample `resample`, T_OrderDetailAddOnResampleStatus resample_status, + T_OrderDetailAddOnRef ref, y.T_OrderDetailVerification verification, y.T_OrderDetailValidation validation, + T_OrderPromiseDateTime , Group_ResultName as ResultGroupName + FROM t_orderdetail x + left join t_orderpromise on x.T_OrderDetailT_OrderPromiseID = T_OrderPromiseID + JOIN t_test tx ON x.T_OrderDetailT_TestID = T_TestID + LEFT JOIN group_resultdetail ON Group_ResultDetailT_TestID = x.T_OrderDetailT_TestID AND Group_ResultDetailIsActive = 'Y' + LEFT JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND Group_ResultFlagNonLab = 'N' + LEFT JOIN t_orderdetail y ON x.T_OrderDetailT_TestSasCode LIKE CONCAT(y.T_OrderDetailT_TestSasCode, '%') + AND x.T_OrderDetailT_OrderHeaderID = y.T_OrderDetailT_OrderHeaderID + AND y.T_OrderDetailIsActive = 'Y' + + LEFT JOIN t_orderdetailaddon ON x.T_OrderDetailID = T_OrderDetailAddOnT_OrderDetailID + + JOIN t_orderheader ON y.T_OrderDetailT_OrderHeaderID = T_OrderHeaderID + LEFT JOIN t_test a ON y.T_OrderDetailT_TestID = a.T_TestID + AND a.T_TestIsNonLab = '' + LEFT JOIN (SELECT T_OrderSampleT_SampleTypeID, T_OrderSampleReceive, T_OrderSampleProcessing, T_OrderSampleWorklistReceive + FROM t_ordersample WHERE T_OrderSampleT_OrderHeaderID = {$id} + AND T_OrderSampleIsactive = 'Y' + GROUP BY T_OrderSampleT_SampleTypeID) os ON a.T_TestT_SampleTypeID = os.T_OrderSampleT_SampleTypeID + or os.T_OrderSampleT_SampleTypeID = fn_sampletype_from_local(a.T_TestNat_TestID) + + LEFT JOIN t_resultinstrument ON T_ResultInstrumentT_OrderDetailID = x.T_OrderDetailID + LEFT JOIN pre_analytic ON PreAnalyticNat_TestID = a.T_TestNat_TestID AND PreAnalyticDate = date(now()) and PreAnalyticIsActive = 'Y' + WHERE x.T_OrderDetailT_OrderHeaderID = {$id} + AND x.T_OrderDetailIsActive = 'Y' + GROUP BY y.T_OrderDetailT_TestID + ORDER BY y.T_OrderDetailT_TestSasCode ASC + ) a1 + + LEFT JOIN t_orderdetail a2 ON a2.T_OrderDetailT_OrderHeaderID = a1.order_id + AND a2.T_OrderDetailIsActive = 'Y' + AND a1.test_sas_code LIKE CONCAT(a2.T_OrderDetailT_testSasCode, '%') + GROUP BY a1.t_testid + order by a1.test_sas_code +"; +//echo $sql; + $query = $this->db_smartone->query($sql); + $lq = $this->db_smartone->last_query(); + } + // file_put_contents("/xtmp/re-query.sql",$lq); + + if ($query) { + $rst = []; + $rows = $query->result_array(); + + foreach($rows as $k => $v) + { + + if ($v['is_result'] == "Y" && $v['is_quantitative'] == "N") + { + $v['template'] = []; + $x = $this->db_smartone->query("CALL sp_master_resulttemplate_get('{$v['t_testid']}')"); + $this->clean_mysqli_connection($this->db_smartone->conn_id); + if ($x) + $v['template'] = $x->result_array(); + } + + // IF Rujukan, by pas Pre Analytik + if ($v['ref'] == 'Y') + $v['pre_analytic'] = 'Y'; + if ($v["id"] == "885455" ) + { + //sipe workaround + //$v["sample_receive"] = "Y"; + $v["sample_worklist_receive"] = "Y"; + } + $rst[] = $v; + } + + $result = array("total" => $tot_count, "records" => $rst, "total_display" => sizeof($rows), "q" => $lq); + $this->sys_ok($result); + } + else { + $this->sys_error_db("RE Px rows", $this->db_smartone); + exit; + } + } + + public function save() + { + $prm = $this->sys_input; + $data = json_decode($prm["data"]); + $lang = $this->lang_default_code; + $lang_id = isset($prm['lang_id']) ? $prm['lang_id'] : '0'; + + if ($lang_id != 0) + { + $l = $this->db_smartone->where("Nat_LangID", $lang_id)->get("nat_lang")->row(); + $lang = $l->Nat_LangCode; + } + + $sql_norm = "select T_OrderDetailMinValue, T_OrderDetailMaxValue, + T_OrderDetailMinValueInclusive, T_OrderDetailMaxValueInclusive, + Nat_TestFlagLow, Nat_TestFlagHigh + from t_orderdetail + join t_test on T_OrderDetailT_TestID = T_TestID + join nat_test on T_TestNat_TestID = Nat_TestID and T_TestIsActive = 'Y' + where T_OrderDetailID = ? "; + + $ids = []; + foreach ($data as $k => $v) + { + if ( $v->resultInstrumentID > 0 ) { + $sql_i = "select T_ResultInstrumentNat_NormalValueID normalValueID + from t_resultinstrument + where T_ResultInstrumentID = ?"; + $qry_i = $this->db_smartone->query($sql_i, array($v->resultInstrumentID)); + if ($qry_i) { + $rows_i = $qry_i->result_array(); + + if (count($rows_i) > 0 ) { + $sql_iu = "update t_orderdetail, nat_normalvalue , nat_methode + set T_OrderDetailMinValue = Nat_NormalValueMinValue, + T_OrderDetailMinValueInclusive = Nat_NormalValueMinValueInclusive, + T_OrderDetailMaxValue = Nat_NormalValueMaxValue , + T_OrderDetailMaxValueInclusive = Nat_NormalValueMaxValueInclusive, + T_OrderDetailNormalValueNote = Nat_NormalValueNote, + T_OrderDetailNormalValueDescription = Nat_NormalValueDescription, + T_OrderDetailNat_NormalValueID = Nat_NormalValueID, + T_OrderDetailNat_MethodeID = Nat_NormalValueNat_MethodeID, + T_OrderDetailNat_MethodeName = Nat_MethodeName + where T_OrderDetailID = ? and Nat_NormalValueID = ? + and Nat_NormalValueNat_MethodeID = Nat_MethodeID + "; + $this->db_smartone->query($sql_iu, array($v->id, $rows_i[0]["normalValueID"])); + //file_put_contents("/xtmp/update-nilai-normal", $this->db_smartone->last_query() . "\n", FILE_APPEND); + } + } + } + $y = $this->db_smartone->query("SELECT fn_process_sample_handling_perfect('{$v->order_id}', '{$v->test_id}') c") + ->row(); + $req_status = $y->c; + $qry_norm = $this->db_smartone->query($sql_norm,$v->id); + $result_flag = ""; + if ($qry_norm) { + $rows_norm = $qry_norm->result_array(); + if (count($rows_norm) > 0 ) { + $r = $rows_norm[0]; + if (is_numeric($v->result)) { + + if ( $r["T_OrderDetailMinValueInclusive"] == "Y" && $v->result < $r["T_OrderDetailMinValue"] ) { + $result_flag = $r["Nat_TestFlagLow"]; + } + if ( $r["T_OrderDetailMinValueInclusive"] == "N" && $v->result <= $r["T_OrderDetailMinValue"] ) { + $result_flag = $r["Nat_TestFlagLow"]; + } + if ( $r["T_OrderDetailMaxValueInclusive"] == "Y" && $v->result > $r["T_OrderDetailMaxValue"] ) { + $result_flag = $r["Nat_TestFlagHigh"]; + } + if ( $r["T_OrderDetailMaxValueInclusive"] == "N" && $v->result >= $r["T_OrderDetailMaxValue"] ) { + $result_flag = $r["Nat_TestFlagHigh"]; + } + } + } + } + if ($lang == $this->lang_default_code) + { + $this->db_smartone->set('T_OrderDetailResult', $v->result) + ->set('T_OrderDetailResultFlag', $result_flag) + ->set('T_OrderDetailNote', $v->note) + ->set('T_OrderDetailReqStatus', $req_status) + ->where('T_OrderDetailID', $v->id) + ->update('t_orderdetail'); + } + else + { + $this->db_smartone->set('T_OrderDetailLangResult', $v->result) + ->set('T_OrderDetailLangNote', $v->note) + ->where('T_OrderDetailLangID', $v->id) + ->update('t_orderdetaillang'); + } + + $ids[] = $v->id; + } + + // LOG Process + $order = $this->db_smartone->select('T_OrderDetailT_OrderHeaderID id, T_OrderHeaderLabNumber lab_number', false) + ->join('t_orderheader', 'T_OrderHeaderID = T_OrderDetailT_OrderHeaderID') + ->where('T_OrderDetailID', $data[0]->id) + ->get('t_orderdetail') + ->row(); + + $dblog = $this->load->database("onelog", true); + $dblog->set('Log_ProcessCode', 'PROCESS.Result.Entry') + ->set('Log_ProcessOrderID', $order->id) + ->set('Log_ProcessOrderNumber', $order->lab_number) + ->set('Log_ProcessJson', json_encode($data)) + ->set('Log_ProcessUserID', $this->sys_user['M_UserID']) + ->insert('log_process'); + // END OF Log Process + //auto calculation + $this->load->library("Resultcalc"); + $rows = $this->resultcalc->auto($order->id); + + try { + foreach($ids as $id ) { + $this->db_smartone->query("call sp_set_normal_value_flag($id)"); + $this->clean_mysqli_connection($this->db_smartone->conn_id); + } + } catch(Exception $e) { + } + + $this->sys_ok($ids); + } + + public function save_template() + { + $prm = $this->sys_input; + + $n = $this->db_smartone->select("COUNT(T_ResultTemplateID) n") + ->where("T_ResultTemplateT_TestID", $prm['test_id']) + ->where("T_ResultTemplateIsActive", "Y") + ->where("T_ResultTemplateValue", $prm['value']) + ->get('t_resulttemplate') + ->row(); + if ($n->n > 0) + { + $this->sys_error_db("Insert Result Template", $this->db_smartone); + return; + } + + $r = $this->db_smartone->set("T_ResultTemplateT_TestID", $prm['test_id']) + ->set("T_ResultTemplateValue", $prm['value']) + ->insert('t_resulttemplate'); + if ($r) + { + $template = []; + $x = $this->db_smartone->query("CALL sp_master_resulttemplate_get('{$prm['test_id']}')"); + $this->clean_mysqli_connection($this->db_smartone->conn_id); + if ($x) + $template = $x->result_array(); + + $this->sys_ok($template); + } + } + + public function export() + { + $prm = $this->sys_input; + + $sql = "CALL sp_process_result_lang(?, ?, ?, ?)"; + $query = $this->db_smartone->query($sql, [$prm['order_id'], $prm['lang_id'], $prm['is_si'], $this->sys_user['M_UserID']]); + if ($query) + { + $r = $query->row(); + if ($r->status == "OK") + { + $this->sys_ok($r->data); + return; + } + + $this->sys_error_db("Message : " . $r->message, $this->db_smartone); + } + else + { + $this->sys_error_db("Lang Result", $this->db_smartone); + return; + } + } + + public function search_group() + { + $prm = $this->sys_input; + $max_rst = 100; + + // QUERY TOTAL + $sql = "select count(*) total + from t_worklist + where T_WorklistIsActive = 'Y' + order by T_WorklistName ASC"; + $query = $this->db_smartone->query($sql); + + if ($query) { + $tot_count = $query->result_array()[0]["total"]; + } + else { + $this->sys_error_db("worklist count", $this->db_smartone); + exit; + } + + $sql = "select T_WorklistID group_id, T_WorklistName group_name + from t_worklist + where T_WorklistIsActive = 'Y' + order by T_WorklistName ASC + limit 0, {$max_rst}"; + $query = $this->db_smartone->query($sql); + + if ($query) { + $rows = $query->result_array(); + foreach ($rows as $k => $v) + $rows[$k]['data'] = json_decode($v['data']); + $result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows), "q" => $this->db_smartone->last_query()); + $this->sys_ok($result); + } + else { + $this->sys_error_db("worklist rows", $this->db_smartone); + exit; + } + } + + public function search_rerun() + { + $prm = $this->sys_input; + $id = $prm["detail_id"]; + + $sql = "CALL sp_process_result_rerun(?)"; + $query = $this->db_smartone->query($sql, [$id]); + + if ($query) + { + $rows = $query->result_array(); + $this->sys_ok(["records"=>$rows]); + } + else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + + + function getdoctorsfna() + { + $prm = $this->sys_input; + // $id = $prm["id"]; + + $sql = " SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY M_DoctorName ASC"; + //echo $sql; + $query = $this->db_smartone->query($sql); + + if ($query) + { + $rows = $query->result_array(); + $this->sys_ok(["records"=>$rows]); + } + else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + function getfnaresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT Other_FNADetailsID as xid, + Other_FNAT_OrderDetailID as orderdetail_id, + Other_FNADetailsCode as code, + Other_FNADetailsLabel as label, + Other_FNADetailsResult as result, + IFNULL(Other_FNAM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_FNAM_DoctorID) OR Other_FNAM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_fna + JOIN other_fnadetails ON Other_FNADetailsOther_FNAID = Other_FNAID AND Other_FNADetailsIsActive = 'Y' + LEFT JOIN m_doctor ON Other_FNAM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_FNAT_OrderDetailID = {$id} AND Other_FNAIsActive = 'Y' + GROUP BY Other_FNADetailsID + ORDER BY Other_FNADetailsCode ASC"; + $query = $this->db_smartone->query($sql); + + if ($query) + { + $rows = $query->result_array(); + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $images = array(); + $sql = "SELECT So_ImageUploadID as xid, + CONCAT('/one-media/one-image-nonlab/',So_ImageUploadNewName) as image_url + FROM t_orderdetail + JOIN so_imageupload ON So_ImageUploadT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND + So_ImageUploadIsActive = 'Y' + WHERE + T_OrderDetailID = {$id} AND + T_OrderDetailIsActive = 'Y' + GROUP BY So_ImageUploadID"; + $images = $this->db_smartone->query($sql)->result_array(); + + $rst = array('doctors'=>$doctors,'results'=>$rows,'images'=>$images); + $this->sys_ok(["records"=>$rst]); + } + else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + + function uploadimage(){ + if (! $this->isLogin) { + $this->sys_error("Invalid Token"); + exit; + } + + $userid = $this->sys_user["M_UserID"]; + $data = []; + //print_r($_SERVER); + + $prm = $this->sys_input; + $orderid = $this->input->post('orderid'); + $labnumber = $this->input->post('labnumber'); + $sql = "UPDATE so_imageupload SET + So_ImageUploadIsActive = 'N', + So_ImageUploadUserID = {$userid} + WHERE + So_ImageUploadT_OrderHeaderID = {$orderid}"; + //echo $sql; + $this->db_onedev->query($sql); + //$config['upload_path'] = 'assets/'; + + $path = '/home/one/project/one/one-media/one-image-nonlab/'; + //echo $path; + $config['upload_path'] = $path; + $config['allowed_types'] = 'jpg|jpeg|png|gif'; + + $config['max_size'] = '10000'; + $count = count($_FILES['files']['name']); + //echo $count; + $this->load->library('upload',$config); + + $error = []; + for($i=0;$i<$count;$i++){ + + + if(!empty($_FILES['files']['name'][$i])){ + + + + $_FILES['file']['name'] = $_FILES['files']['name'][$i]; + + $_FILES['file']['type'] = $_FILES['files']['type'][$i]; + + $_FILES['file']['tmp_name'] = $_FILES['files']['tmp_name'][$i]; + + $_FILES['file']['error'] = $_FILES['files']['error'][$i]; + + $_FILES['file']['size'] = $_FILES['files']['size'][$i]; + + + + $namex = $orderid.'-'.$labnumber.'-'.$this->generateRandomString(5); + //echo $namex; + + $config['file_name'] = $namex; + $this->upload->initialize($config); + //echo $config['file_name'] ; + + + + + + if($this->upload->do_upload('file')){ + + $uploadData = $this->upload->data(); + + $filename = $uploadData['file_name']; + //echo $filename; + + + $sql = "INSERT INTO so_imageupload ( + So_ImageUploadT_OrderHeaderID, + So_ImageUploadT_OrderHeaderLabNumber, + So_ImageUploadT_SampleTypeID, + So_ImageUploadOldName, + So_ImageUploadNewName, + So_ImageUploadCreated, + So_ImageUploadUserID + ) + VALUES( + {$orderid}, + '{$labnumber}', + '150', + '{$_FILES['files']['name'][$i]}', + '{$filename}', + NOW(), + {$userid} + + )"; + //echo $sql; + $this->db_onedev->query($sql); + $xlast_id = $this->db_onedev->insert_id(); + $data['totalFiles'][] = array('xid' => $xlast_id ,'image_url' => '/one-media/one-image-nonlab/'.$filename); + + } + else{ + $error = array('error' => $this->upload->display_errors()); + } + + } + + + + } + + $result = array("total" =>count( $data['totalFiles']), "records" => $data['totalFiles'],'errors'=>$error); + $this->sys_ok($result); + } + + + function generateRandomString($length = 10) { + $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; + $charactersLength = strlen($characters); + $randomString = ''; + for ($i = 0; $i < $length; $i++) { + $randomString .= $characters[rand(0, $charactersLength - 1)]; + } + return $randomString; + } + + function getcytologiresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT Other_CytologiDetailsID as xid, + Other_CytologiT_OrderDetailID as orderdetail_id, + Other_CytologiDetailsCode as code, + Other_CytologiDetailsLabel as label, + Other_CytologiDetailsResult as result, + IFNULL(Other_CytologiM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_CytologiM_DoctorID) OR Other_CytologiM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_cytologi + JOIN other_cytologidetails ON Other_CytologiDetailsOther_CytologiID = Other_CytologiID AND Other_CytologiDetailsIsActive = 'Y' + LEFT JOIN m_doctor ON Other_CytologiM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_CytologiT_OrderDetailID = {$id} AND Other_CytologiIsActive = 'Y' + GROUP BY Other_CytologiDetailsID + ORDER BY Other_CytologiDetailsCode ASC"; + //echo $sql; + $query = $this->db_smartone->query($sql); + + if ($query) + { + $rows = $query->result_array(); + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $rst = array('doctors'=>$doctors,'results'=>$rows); + $this->sys_ok(["records"=>$rst]); + } + else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + function getmikroresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT + Other_MikroID as xid, + Other_MikroHasilBiakan as hasil_biakan, + Other_MikroSampleTypeName as sample_name, + Other_MikroT_OrderDetailID as orderdetail_id, + Other_MikroResult as result_value, + '' as result_other, + IFNULL(T_BacteriaID,0) as T_BacteriaID, + IFNULL(T_BacteriaName,'') as T_BacteriaName, + '' as details, + IFNULL(Other_MikroM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_MikroM_DoctorID) OR Other_MikroM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_mikro + LEFT JOIN t_bacteria ON Other_MikroT_BacteriaID = T_BacteriaID + LEFT JOIN m_doctor ON Other_MikroM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_MikroT_OrderDetailID = {$id} AND Other_MikroIsActive = 'Y' + GROUP BY Other_MikroID"; + //echo $sql; + $query = $this->db_smartone->query($sql); + + if ($query) + { + $row = $query->row_array(); + if($row){ + if($row['result_value'] != 'Positif' && $row['result_value'] != 'Negatif'){ + $row['result_other'] = $row['result_value']; + $row['result_value'] = 'other'; + } + $sql = "SELECT '' as xno, + Other_MikroDetailsID as xid, + Other_MikroDetailsValue as value, + IF(Other_MikroDetailsNote = 'R','Y','N') as chx_r, + IF(Other_MikroDetailsNote = 'I','Y','N') as chx_i, + IF(Other_MikroDetailsNote = 'S','Y','N') as chx_s, + Other_MikroDetailsNote as note, + t_antibiotic.* + FROM other_mikrodetails + LEFT JOIN t_antibiotic ON Other_MikroDetailsT_AntibioticID = T_AntibioticID + WHERE + Other_MikroDetailsOther_MikroID = {$row['xid']} AND Other_MikroDetailsIsActive = 'Y' + GROUP BY Other_MikroDetailsID + ORDER BY T_AntibioticName ASC"; + //echo $sql; + $details = $this->db_smartone->query($sql)->result_array(); + if(details){ + foreach($details as $k => $v){ + $details[$k]['xno'] = $k + 1; + } + } + $row['details'] = $details; + } + else{ + $row = array('xid'=>'0','hasil_biakan' => '','result_value'=>'Negatif','sample_name' => '','orderdetail_id'=>$id, 'T_BacteriaID'=>'0','T_BacteriaName'=>'0','details'=>array(),'doctor_id'=>'0','doctor_name'=>'0'); + } + } + else{ + $row = array('xid'=>'0','hasil_biakan' => '','result_value'=>'Negatif','sample_name' => '','orderdetail_id'=>$id, 'T_BacteriaID'=>'0','T_BacteriaName'=>'0','details'=>array(),'doctor_id'=>'0','doctor_name'=>'0'); + } + //print_r($row); + + + + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 7 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $sql = " + SELECT '0' as id, 'Belum memilih bakteria' as name + UNION + SELECT T_BacteriaID as id, T_BacteriaName as name + FROM t_bacteria + WHERE + T_BacteriaIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $bacteries = $this->db_smartone->query($sql)->result_array(); + $rst = array('doctors'=>$doctors,'bacteries'=>$bacteries,'results'=>$row); + $this->sys_ok(["records"=>$rst]); + } + function getantibiotics(){ + $prm = $this->sys_input; + $id = $prm["id"]; + $sql = " SELECT '' as xno, + 0 as xid, + '' as hasil_biakan, + '' as sample_name, + 0 as value, + 'Y' as chx_r, + 'N' as chx_i, + 'N' as chx_s, + 'R' as note, + t_antibiotic.* + FROM t_antibiotic + WHERE + T_AntibioticT_BacteriaID = {$prm['id']} AND T_AntibioticIsActive= 'Y' + ORDER BY T_AntibioticName ASC"; + //echo $sql; + $rows = $this->db_smartone->query($sql)->result_array(); + if(rows){ + foreach($rows as $k => $v){ + $rows[$k]['xno'] = $k + 1; + } + } + + $this->sys_ok(["records"=>$rows]); + } + function getlcprepresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + $sql = " SELECT Other_LcprepDetailsID as xid, + Other_LcprepID as header_id, + Other_LcprepT_orderDetailID as orderdetail_id, + Other_LcprepDetailsCode as code, + Other_LcprepDetailsLabel as label, + Other_LcprepDetailsResult as result, + IFNULL(Other_LcprepM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_LcprepM_DoctorID) OR Other_LcprepM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_lcprep + JOIN other_lcprepdetails ON Other_LcprepDetailsOther_LcprepID = Other_LcprepID AND Other_LcprepDetailsIsActive = 'Y' + LEFT JOIN m_doctor ON Other_LcprepM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_LcprepT_orderDetailID = {$id} AND Other_LcprepIsActive = 'Y' + GROUP BY Other_LcprepDetailsOther_LcprepID, Other_LcprepDetailsCode + ORDER BY Other_LcprepDetailsCode ASC"; + //echo $sql; + $rows = $this->db_smartone->query($sql)->result_array(); + if(!$rows){ + $rows = array( + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'A', + 'label' => 'DESKRIPSI', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ), + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'B', + 'label' => 'KESIMPULAN', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ) + ); + } + + $header_id = $rows[0]['header_id']; + $sql = "SELECT IFNULL(Other_LcprepAdekuasiID,0) as xid, + Lcprep_AdekuasiID as id, + Lcprep_AdekuasiLabel as name, + IF(ISNULL(Other_LcprepAdekuasiID),'N',Other_LcprepAdekuasiChex) as chex + FROM lcprep_adekuasi + LEFT JOIN other_lcprepadekuasi ON Other_LcprepAdekuasiLcprep_AdekuasiID = Lcprep_AdekuasiID AND + Other_LcprepAdekuasiOther_LcprepID = {$header_id} AND + Other_LcprepAdekuasiIsActive = 'Y' + WHERE + Lcprep_AdekuasiIsActive = 'Y' + GROUP BY Lcprep_AdekuasiID + ORDER BY Lcprep_AdekuasiOrder ASC + "; + //echo $sql; + $adeakuasi = $this->db_smartone->query($sql)->result_array(); + foreach($adeakuasi as $kc => $vc){ + $adeakuasi[$kc]['chex'] = $vc['chex'] == 'N'?false:true; + } + + $sql = "SELECT IFNULL(Other_LcprepKategoriUmumID,0) as xid, + Lcprep_KategoriUmumID as id, + Lcprep_KategoriUmumLabel as name, + IF(ISNULL(Other_LcprepKategoriUmumID),'N',Other_LcprepKategoriUmumChex) as chex + FROM lcprep_kategoriumum + LEFT JOIN other_lcprepkategoriumum ON Other_LcprepKategoriUmumLcprep_KategoriUmumID = Lcprep_KategoriUmumID AND + Other_LcprepKategoriUmumOther_LcprepID = {$header_id} AND + Other_LcprepKategoriUmumIsActive = 'Y' + WHERE + Lcprep_KategoriUmumIsActive = 'Y' + GROUP BY Lcprep_KategoriUmumID + "; + //echo $sql; + $kategoriumum = $this->db_smartone->query($sql)->result_array(); + foreach($kategoriumum as $kc => $vc){ + $kategoriumum[$kc]['chex'] = $vc['chex'] == 'N'?false:true; + } + + $sql = " + SELECT Lcprep_InterpretasiGroupID as group_id, + Lcprep_InterpretasiGroupName as group_name, + '' as subgroups + FROM lcprep_interpretasigroup + WHERE + Lcprep_InterpretasiGroupIsActive = 'Y' + "; + //echo $sql; + $interpretasi = $this->db_smartone->query($sql)->result_array(); + foreach($interpretasi as $k => $v){ + $subgroups = array(); + $sql = "SELECT Lcprep_InterpretasiSubgroupID as subgroup_id, + Lcprep_InterpretasiSubgroupName as subgroup_name, + '' as childs + FROM lcprep_interpretasisubgroup + WHERE + Lcprep_InterpretasiSubgroupLcprep_InterpretasiGroupID = {$v['group_id']} AND Lcprep_InterpretasiSubgroupIsActive = 'Y'"; + //echo $sql; + $subgroups = $this->db_smartone->query($sql)->result_array(); + if(count($subgroups) > 0){ + foreach($subgroups as $ki => $vi){ + $childs = array(); + $sql = "SELECT IFNULL(Other_LcprepInterpretasiID,0) as xid, + IFNULL(Other_LcprepInterpretasiChex,'N') as chex, + IFNULL(Other_LcprepInterpretasiValue,'') as value, + Lcprep_InterpretasiID as id, + Lcprep_InterpretasiLcprep_InterpretasiSubgroupID as subgroup_id, + Lcprep_InterpretasiCode as code, + Lcprep_InterpretasiName as name, + Lcprep_InterpretasiParentID as parent_id, + Lcprep_InterpretasiIsParent as is_parent, + Lcprep_InterpretasiHasResult as has_result, + Lcprep_InterpretasiTypeResult as type_result + FROM lcprep_interpretasi + LEFT JOIN other_lcprepinterpretasi ON Other_LcprepInterpretasiOther_LcprepID = {$header_id} AND + Other_LcprepInterpretasiLcprep_InterpretasiID = Lcprep_InterpretasiID AND + Other_LcprepInterpretasiIsActive = 'Y' + WHERE + Lcprep_InterpretasiLcprep_InterpretasiSubgroupID = {$vi['subgroup_id']} AND Lcprep_InterpretasiIsActive = 'Y' + GROUP BY Lcprep_InterpretasiID Order BY Lcprep_InterpretasiCode ASC"; + $childs = $this->db_smartone->query($sql)->result_array(); + if($childs){ + foreach($childs as $kc => $vc){ + $childs[$kc]['chex'] = $vc['chex'] == 'N'?false:true; + } + } + $subgroups[$ki]['childs'] = $childs; + } + } + + $interpretasi[$k]['subgroups'] = $subgroups; + } + + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $rst = array('doctors'=>$doctors,'results'=>$rows,'adekuasi'=>$adeakuasi,'kategoriumum'=>$kategoriumum,'interpretasi'=>$interpretasi); + $this->sys_ok(["records"=>$rst]); + } + + function getpapsmearresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT Other_PapSmearDetailsID as xid, + Other_PapSmearID as header_id, + Other_PapSmearT_OrderDetailID as orderdetail_id, + Other_PapSmearDetailsCode as code, + Other_PapSmearDetailsLabel as label, + Other_PapSmearDetailsResult as result, + IFNULL(Other_PapSmearM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_PapSmearM_DoctorID) OR Other_PapSmearM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_papsmear + JOIN other_papsmeardetails ON Other_PapSmearDetailsOther_PapSmearID = Other_PapSmearID AND Other_PapSmearDetailsIsActive = 'Y' + LEFT JOIN m_doctor ON Other_PapSmearM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_PapSmearT_OrderDetailID = {$id} AND Other_PapSmearIsActive = 'Y' + GROUP BY Other_PapSmearDetailsID + ORDER BY Other_PapSmearDetailsCode ASC"; + //echo $sql; + $rows = $this->db_smartone->query($sql)->result_array(); + if(!$rows){ + $rows = array( + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'A', + 'label' => 'Makroskopik', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ), + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'B', + 'label' => 'Mikroskopik', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ), + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'C', + 'label' => 'Kesimpulan', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ) + ); + } + + $header_id = $rows[0]['header_id']; + $sql = "SELECT Other_PapSmearMaturasiID as xid, + Other_PapSmearMaturasiValue as value + FROM other_papsmearmaturasi + WHERE + Other_PapSmearMaturasiOther_PapSmearID = {$header_id} AND + Other_PapSmearMaturasiIsActive = 'Y' + "; + //echo $sql; + $dt_maturasi = $this->db_smartone->query($sql)->row_array(); + if(!$dt_maturasi){ + $maturasi = array('xid'=>'0','value'=> array('','','')); + } + else{ + $value = explode('/',$dt_maturasi['value']); + $maturasi = array('xid'=>$dt_maturasi['xid'],'value'=> $value); + } + + $sql = "SELECT IFNULL(Other_PapSmearBahanID,0) as xid, + M_PapSmearBahanID as bahan_id, + M_PapSmearBahanName as name, + IF(ISNULL(Other_PapSmearBahanID),'N','Y') as selected + FROM m_papsmearbahan + LEFT JOIN other_papsmearbahan ON Other_PapSmearBahanM_PapSmearBahanID = M_PapSmearBahanID AND + Other_PapSmearBahanOther_PapSmearID = {$header_id} AND + Other_PapSmearBahanIsActive = 'Y' + WHERE + M_PapSmearBahanIsActive = 'Y' + ORDER BY M_PapSmearBahanID ASC + "; + //echo $sql; + $bahans = $this->db_smartone->query($sql)->result_array(); + + $sql = "SELECT IFNULL(Other_PapsmearCategoryID,0) as xid, + M_PapSmearCategoryID as category_id, + M_PapSmearCategoryName as name, + IF(ISNULL(Other_PapsmearCategoryID),'N','Y') as selected + FROM m_papsmearcategory + LEFT JOIN other_papsmearcategory ON Other_PapsmearCategoryM_PapSmearCategoryID = M_PapSmearCategoryID AND + Other_PapsmearCategoryOther_PapSmearID = {$header_id} AND + Other_PapsmearCategoryIsActive = 'Y' + WHERE + M_PapSmearCategoryIsActive = 'Y' + ORDER BY M_PapSmearCategoryID ASC + "; + //echo $sql; + $categories = $this->db_smartone->query($sql)->result_array(); + + $sql = "SELECT IFNULL(Other_PapSmearCheckID,0) as xid, + M_PapSmearCheckID as check_id, + M_PapSmearCheckLabel as name, + IF(ISNULL(Other_PapSmearCheckID),'N','Y') as selected, + Other_PapSmearCheckNote as note + FROM m_papsmearcheck + LEFT JOIN other_papsmearcheck ON Other_PapSmearCheckM_PapSmearCheckID = M_PapSmearCheckID AND + Other_PapSmearCheckOther_PapSmearID = {$header_id} AND + Other_PapSmearCheckIsActive = 'Y' + WHERE + M_PapSmearCheckIsActive = 'Y' + ORDER BY M_PapSmearCheckCode ASC + "; + $checks = $this->db_smartone->query($sql)->result_array(); + + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $rst = array('doctors'=>$doctors,'checks'=>$checks,'bahans'=>$bahans,'categories'=>$categories,'maturasi'=>$maturasi,'results'=>$rows); + $this->sys_ok(["records"=>$rst]); + + } + + function saveresult_lcprep() + { + $prm = $this->sys_input; + $detail_id = $prm['detail_id']; + $doctor_id = $prm['doctor']; + $adekuasi = $prm['adekuasi']; + $kategoriumum = $prm['kategoriumum']; + $interpretasi = $prm['interpretasi']; + $results = $prm['results']; + + $userid = $this->sys_user['M_UserID']; + + $header_id = 0; + $sql = "SELECT * FROM other_lcprep WHERE Other_LcprepT_orderDetailID = {$detail_id} AND Other_LcprepIsActive = 'Y'"; + $dt_header = $this->db_smartone->query($sql)->row_array(); + if($dt_header){ + $header_id = $dt_header['Other_LcprepID']; + } + if($header_id == 0){ + $sql = "INSERT INTO other_lcprep( + Other_LcprepT_orderDetailID, + Other_LcprepM_DoctorID, + Other_LcprepUserID, + Other_LcprepCreated + ) + VALUES( + {$detail_id}, + {$doctor_id}, + {$userid}, + NOW() + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + }else{ + $sql = "UPDATE other_lcprep SET Other_LcprepM_DoctorID = {$doctor_id}, Other_LcprepUserID = {$userid} WHERE Other_LcprepID = {$header_id}"; + $this->db_smartone->query($sql); + } + + if($adekuasi){ + foreach($adekuasi as $k =>$v){ + $selected = $v['chex']?'Y':'N'; + if(intval($v['xid'] == 0)){ + $sql = "UPDATE other_lcprepadekuasi SET Other_LcprepAdekuasiIsActive = 'N' + WHERE + Other_LcprepAdekuasiOther_LcprepID = {$header_id} AND + Other_LcprepAdekuasiIsActive = 'Y' AND + Other_LcprepAdekuasiLcprep_AdekuasiID = {$v['id']}"; + $this->db_smartone->query($sql); + $sql = "INSERT INTO other_lcprepadekuasi ( + Other_LcprepAdekuasiOther_LcprepID, + Other_LcprepAdekuasiLcprep_AdekuasiID, + Other_LcprepAdekuasiChex, + Other_LcprepAdekuasiUserID, + Other_LcprepAdekuasiCreated + ) + VALUES( + {$header_id}, + {$v['id']}, + '{$selected}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + //echo $sql; + } + if(intval($v['xid'] != 0)){ + + $sql = "UPDATE other_lcprepadekuasi SET + Other_LcprepAdekuasiChex = '{$selected}', + Other_LcprepAdekuasiUserID = {$userid} + WHERE + Other_LcprepAdekuasiID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + + //echo $sql; + } + } + + if($kategoriumum){ + foreach($kategoriumum as $k =>$v){ + $selected = $v['chex']?'Y':'N'; + if(intval($v['xid'] == 0)){ + $sql = "UPDATE other_lcprepkategoriumum SET Other_LcprepKategoriUmumIsActive = 'N' + WHERE + Other_LcprepKategoriUmumOther_LcprepID = {$header_id} AND + Other_LcprepKategoriUmumLcprep_KategoriUmumID = {$v['id']} AND + Other_LcprepKategoriUmumIsActive = 'Y' + "; + $this->db_smartone->query($sql); + $sql = "INSERT INTO other_lcprepkategoriumum ( + Other_LcprepKategoriUmumOther_LcprepID, + Other_LcprepKategoriUmumLcprep_KategoriUmumID, + Other_LcprepKategoriUmumChex, + Other_LcprepKategoriUmumUserID, + Other_LcprepKategoriUmumCreated + ) + VALUES( + {$header_id}, + {$v['id']}, + '{$selected}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if(intval($v['xid'] != 0)){ + $sql = "UPDATE other_lcprepkategoriumum SET + Other_LcprepKategoriUmumChex = '{$selected }', + Other_LcprepKategoriUmumUserID = {$userid} + WHERE + Other_LcprepKategoriUmumID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + + //echo $sql; + } + } + + if($results){ + foreach($results as $k =>$v){ + if(intval($v['xid'] == 0)){ + $sql = "UPDATE other_lcprepdetails SET Other_LcprepDetailsIsActive = 'N' + WHERE + Other_LcprepDetailsOther_LcprepID = {$header_id} AND + Other_LcprepDetailsCode = '{$v['code']}' AND + Other_LcprepDetailsIsActive = 'Y'"; + $this->db_smartone->query($sql); + $sql = "INSERT INTO other_lcprepdetails ( + Other_LcprepDetailsOther_LcprepID, + Other_LcprepDetailsCode, + Other_LcprepDetailsLabel, + Other_LcprepDetailsResult, + Other_LcprepDetailsUserID, + Other_LcprepDetailsCreated + ) + VALUES( + {$header_id}, + '{$v['code']}', + '{$v['label']}', + '{$v['result']}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if(intval($v['xid'] != 0)){ + $sql = "UPDATE other_lcprepdetails SET + Other_LcprepDetailsCode = '{$v['code']}', + Other_LcprepDetailsLabel = '{$v['label']}', + Other_LcprepDetailsResult = '{$v['result']}', + Other_LcprepDetailsUserID = {$userid} + WHERE + Other_LcprepDetailsID = {$v['xid']}"; + $this->db_smartone->query($sql); + + } + //echo $sql; + } + } + + if($interpretasi){ + foreach($interpretasi as $k =>$v){ + if(count($v['subgroups']) > 0){ + foreach($v['subgroups'] as $ik => $iv){ + if(count($iv['childs']) > 0){ + foreach($iv['childs'] as $iik => $iiv){ + if(intval($iiv['xid'] == 0)){ + $chex = $iiv['chex'] ? 'Y':'N'; + $sql = "UPDATE other_lcprepinterpretasi SET Other_LcprepInterpretasiIsActive = 'N' + WHERE + Other_LcprepInterpretasiOther_LcprepID = {$header_id} AND + Other_LcprepInterpretasiLcprep_InterpretasiID = '{$iiv['id']}' AND + Other_LcprepInterpretasiIsActive = 'Y'"; + $this->db_smartone->query($sql); + $sql = "INSERT INTO other_lcprepinterpretasi ( + Other_LcprepInterpretasiOther_LcprepID, + Other_LcprepInterpretasiLcprep_InterpretasiID, + Other_LcprepInterpretasiChex, + Other_LcprepInterpretasiValue, + Other_LcprepInterpretasiUserID, + Other_LcprepInterpretasiCreated + ) + VALUES( + {$header_id}, + '{$iiv['id']}', + '{$chex}', + '{$iiv['value']}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + + if(intval($iiv['xid'] != 0)){ + $chex = $iiv['chex'] ? 'Y':'N'; + $sql = "UPDATE other_lcprepinterpretasi SET + Other_LcprepInterpretasiChex = '{$chex}', + Other_LcprepInterpretasiValue = '{$iiv['value']}', + Other_LcprepInterpretasiUserID = {$userid} + WHERE + Other_LcprepInterpretasiID = {$iiv['xid']}"; + $this->db_smartone->query($sql); + //echo $sql; + + } + + } + } + } + } + //echo $sql; + } + } + + + $result = array("total" => 1, "records" => array(), "sql"=> ''); + $this->sys_ok($result); + exit; + } + + function saveresult_papsmear() + { + $prm = $this->sys_input; + $detail_id = $prm['detail_id']; + $doctor_id = $prm['doctor']; + $checks = $prm['checks']; + $maturasi = $prm['maturasi']; + $bahans = $prm['bahans']; + $categories = $prm['categories']; + $results = $prm['results']; + + $userid = $this->sys_user['M_UserID']; + + $header_id = 0; + $sql = "SELECT * FROM other_papsmear WHERE Other_PapSmearT_OrderDetailID = {$detail_id} AND Other_PapSmearIsActive = 'Y'"; + $dt_header = $this->db_smartone->query($sql)->row_array(); + if($dt_header){ + $header_id = $dt_header['Other_PapSmearID']; + } + if($header_id == 0){ + $sql = "INSERT INTO other_papsmear( + Other_PapSmearT_OrderDetailID, + Other_PapSmearM_DoctorID, + Other_PapSmearUserID, + Other_PapSmearCreated + ) + VALUES( + {$detail_id}, + {$doctor_id}, + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } + else{ + $sql = "UPDATE other_papsmear SET Other_PapSmearM_DoctorID = {$doctor_id}, Other_PapSmearUserID = {$userid} WHERE Other_PapSmearID = {$header_id}"; + $this->db_smartone->query($sql); + } + + if($checks){ + foreach($checks as $k =>$v){ + if(intval($v['xid']) == 0 && $v['selected'] === 'Y'){ + $sql = "INSERT INTO other_papsmearcheck ( + Other_PapSmearCheckOther_PapSmearID, + Other_PapSmearCheckM_PapSmearCheckID, + Other_PapSmearCheckNote, + Other_PapSmearCheckUserID, + Other_PapSmearCheckCreated + ) + VALUES( + {$header_id}, + {$v['check_id']}, + '{$v['note']}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if(intval($v['xid']) != 0 && $v['selected'] === 'N'){ + $sql = "UPDATE other_papsmearcheck SET + Other_PapSmearCheckIsActive = 'N', + Other_PapSmearCheckUserID = {$userid} + WHERE + Other_PapSmearCheckID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + if(intval($v['xid']) != 0 && $v['selected'] === 'Y'){ + $sql = "UPDATE other_papsmearcheck SET + Other_PapSmearCheckNote = '{$v['note']}', + Other_PapSmearCheckUserID = {$userid} + WHERE + Other_PapSmearCheckID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + //echo $sql; + } + } + + if($maturasi){ + if(intval($maturasi['xid']) == 0){ + $value = join("/",$maturasi['value']); + $sql = "INSERT INTO other_papsmearmaturasi ( + Other_PapSmearMaturasiOther_PapSmearID, + Other_PapSmearMaturasiValue, + Other_PapSmearMaturasiUserID, + Other_PapSmearMaturasiCreated + ) + VALUE( + {$header_id}, + '{$value}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + //echo $sql; + } + if(intval($maturasi['xid']) != 0){ + $value = join("/",$maturasi['value']); + $sql = "UPDATE other_papsmearmaturasi SET + Other_PapSmearMaturasiValue = '{$value}', + Other_PapSmearMaturasiUserID = {$userid} + WHERE + Other_PapSmearMaturasiID = {$maturasi['xid']}"; + // echo $sql; + $this->db_smartone->query($sql); + } + } + + if($bahans){ + foreach($bahans as $k =>$v){ + if(intval($v['xid']) == 0 && $v['selected'] === 'Y'){ + $sql = "INSERT INTO other_papsmearbahan ( + Other_PapSmearBahanOther_PapSmearID, + Other_PapSmearBahanM_PapSmearBahanID, + Other_PapSmearBahanUserID, + Other_PapSmearBahanCreated + ) + VALUES( + {$header_id}, + {$v['bahan_id']}, + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if(intval($v['xid']) != 0 && $v['selected'] === 'N'){ + $sql = "UPDATE other_papsmearbahan SET + Other_PapSmearBahanIsActive = 'N', + Other_PapsmearCategoryUserID = {$userid} + WHERE + Other_PapSmearBahanID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + if(intval($v['xid']) != 0 && $v['selected'] === 'Y'){ + $sql = "UPDATE other_papsmearbahan SET + Other_PapSmearBahanIsActive = 'Y', + Other_PapsmearCategoryUserID = {$userid} + WHERE + Other_PapSmearBahanID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + //echo $sql; + } + } + + if($categories){ + foreach($categories as $k =>$v){ + if(intval($v['xid']) == 0 && $v['selected'] === 'Y'){ + $sql = "INSERT INTO other_papsmearcategory ( + Other_PapsmearCategoryOther_PapSmearID, + Other_PapsmearCategoryM_PapSmearCategoryID, + Other_PapsmearCategoryUserID, + Other_PapsmearCategoryCreated + ) + VALUES( + {$header_id}, + {$v['category_id']}, + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if(intval($v['xid']) != 0 && $v['selected'] === 'N'){ + $sql = "UPDATE other_papsmearcategory SET + Other_PapsmearCategoryIsActive = 'N', + Other_PapsmearCategoryUserID = {$userid} + WHERE + Other_PapsmearCategoryID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + //echo $sql; + if(intval($v['xid']) != 0 && $v['selected'] === 'Y'){ + $sql = "UPDATE other_papsmearcategory SET + Other_PapsmearCategoryIsActive = 'Y', + Other_PapsmearCategoryUserID = {$userid} + WHERE + Other_PapsmearCategoryID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + } + } + + if($results){ + foreach($results as $k =>$v){ + if(intval($v['xid']) == 0){ + $sql = "INSERT INTO other_papsmeardetails ( + Other_PapSmearDetailsOther_PapSmearID, + Other_PapSmearDetailsCode, + Other_PapSmearDetailsLabel, + Other_PapSmearDetailsResult, + Other_PapSmearDetailsUserID, + Other_PapSmearDetailsCreated + ) + VALUES( + {$header_id}, + '{$v['code']}', + '{$v['label']}', + '{$v['result']}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if(intval($v['xid']) != 0){ + $sql = "UPDATE other_papsmeardetails SET + Other_PapSmearDetailsCode = '{$v['code']}', + Other_PapSmearDetailsLabel = '{$v['label']}', + Other_PapSmearDetailsResult = '{$v['result']}', + Other_PapSmearDetailsUserID = {$userid} + WHERE + Other_PapSmearDetailsID = {$v['xid']}"; + $this->db_smartone->query($sql); + + } + //echo $sql; + } + } + + $result = array("total" => 1, "records" => array(), "sql"=> ''); + $this->sys_ok($result); + exit; + } + + function saveresult_fna() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = $inp['doctor']; + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + if($prm[0]['xid'] == '0'){ + $sql = "INSERT INTO other_fna( + Other_FNAM_DoctorID, + Other_FNAT_OrderDetailID, + Other_FNAUserID, + Other_FNACreated + ) + VALUES( + {$doctor_id}, + {$prm[0]['orderdetail_id']}, + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } + else{ + $sql = "SELECT * FROM other_fna WHERE Other_FNAT_OrderDetailID = {$prm[0]['orderdetail_id']} AND Other_FNAIsActive = 'Y'"; + $data_header = $this->db_smartone->query($sql)->row_array(); + $header_id = $data_header['Other_FNAID']; + $sql = "UPDATE other_fna SET + Other_FNAM_DoctorID = {$doctor_id}, + Other_FNAUserID = {$userid} + WHERE + Other_FNAID = {$header_id}"; + $this->db_smartone->query($sql); + } + foreach($prm as $k => $v){ + if($v['xid'] == '0'){ + $results = str_replace("'", "\\'", $v['result']); + $sql = "INSERT INTO other_fnadetails( + Other_FNADetailsOther_FNAID , + Other_FNADetailsCode, + Other_FNADetailsLabel, + Other_FNADetailsResult, + Other_FNADetailsCreated, + Other_FNADetailsUserID + ) + VALUES( + {$header_id}, + '{$v['code']}', + '{$v['label']}', + '{$results}', + NOW(), + {$userid} + )"; + $query = $this->db_smartone->query($sql); + } + else{ + $results = str_replace("'", "\\'", $v['result']); + $sql = "UPDATE other_fnadetails SET + Other_FNADetailsResult = '{$results}', + Other_FNADetailsUserID = {$userid} + WHERE + Other_FNADetailsID = {$v['xid']}"; + $query = $this->db_smartone->query($sql); + } + } + + $result = array("total" => 1, "records" => array(), "sql"=> ''); + $this->sys_ok($result); + exit; + } + + function saveresult_cytologi() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = $inp['doctor']; + + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + if($prm[0]['xid'] == '0'){ + $sql = "INSERT INTO other_cytologi( + Other_CytologiT_OrderDetailID, + Other_CytologiM_DoctorID, + Other_CytologiUserID, + Other_CytologiCreated + ) + VALUES( + {$prm[0]['orderdetail_id']}, + {$doctor_id}, + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } + else{ + $sql = "SELECT * FROM other_cytologi WHERE Other_CytologiT_OrderDetailID = {$prm[0]['orderdetail_id']} AND Other_CytologiIsActive = 'Y'"; + $data_header = $this->db_smartone->query($sql)->row_array(); + $header_id = $data_header['Other_CytologiID']; + $sql = "UPDATE other_cytologi SET + Other_CytologiM_DoctorID = {$doctor_id}, + Other_CytologiUserID = {$userid} + WHERE + Other_CytologiID = {$header_id}"; + $this->db_smartone->query($sql); + } + foreach($prm as $k => $v){ + if($v['xid'] == '0'){ + $results = str_replace("'", "\\'", $v['result']); + $sql = "INSERT INTO other_cytologidetails( + Other_CytologiDetailsOther_CytologiID , + Other_CytologiDetailsCode, + Other_CytologiDetailsLabel, + Other_CytologiDetailsResult, + Other_CytologiDetailsCreated, + Other_CytologiDetailsUserID + ) + VALUES( + {$header_id}, + '{$v['code']}', + '{$v['label']}', + '{$results}', + NOW(), + {$userid} + )"; + $query = $this->db_smartone->query($sql); + } + else{ + $results = str_replace("'", "\\'", $v['result']); + $sql = "UPDATE other_cytologidetails SET + Other_CytologiDetailsResult = '{$results}', + Other_CytologiDetailsUserID = {$userid} + WHERE + Other_CytologiDetailsID = {$v['xid']}"; + $query = $this->db_smartone->query($sql); + } + } + + $result = array("total" => 1, "records" => array(), "sql"=> ''); + $this->sys_ok($result); + exit; + } + + function saveresult_mikro() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = $inp['doctor']; + $backteria_id = $inp['bacteria']; + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + + if($inp['result_value'] != 'Negatif' && $inp['result_value'] != 'Positif'){ + $prm['result_value'] = $prm['result_other']; + } + else{ + $prm['result_value'] = $inp['result_value']; + } + + if($prm['xid'] == '0'){ + $sql = "INSERT INTO other_mikro( + Other_MikroM_DoctorID, + Other_MikroResult, + Other_MikroT_BacteriaID, + Other_MikroT_OrderDetailID, + Other_MikroHasilBiakan, + Other_MikroSampleTypeName, + Other_MikroUserID, + Other_MikroCreated + ) + VALUES( + {$doctor_id}, + '{$prm['result_value']}', + {$backteria_id}, + {$prm['orderdetail_id']}, + '{$prm['hasil_biakan']}', + '{$prm['sample_name']}', + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } + else{ + $sql = "SELECT * FROM other_mikro WHERE Other_MikroT_OrderDetailID = {$prm['orderdetail_id']} AND Other_MikroIsActive = 'Y'"; + $data_header = $this->db_smartone->query($sql)->row_array(); + $header_id = $data_header['Other_MikroID']; + $sql = "UPDATE other_mikro SET + Other_MikroResult = '{$prm['result_value']}', + Other_MikroM_DoctorID = {$doctor_id}, + Other_MikroT_BacteriaID = {$backteria_id}, + Other_MikroHasilBiakan = '{$prm['hasil_biakan']}', + Other_MikroSampleTypeName = '{$prm['sample_name']}', + Other_MikroUserID = {$userid} + WHERE + Other_MikroID = {$header_id}"; + //echo $sql; + $this->db_smartone->query($sql); + } + + + + $sql = "UPDATE other_mikrodetails SET Other_MikroDetailsIsActive = 'N', Other_MikroDetailsUserID = 0 WHERE Other_MikroDetailsOther_MikroID = {$header_id}"; + $this->db_smartone->query($sql); + + $results = $prm['details']; + if($inp['result_value'] == 'Positif'){ + foreach($results as $k => $v){ + if($v['xid'] == '0'){ + $sql = "INSERT INTO other_mikrodetails( + Other_MikroDetailsOther_MikroID , + Other_MikroDetailsT_AntibioticID, + Other_MikroDetailsValue, + Other_MikroDetailsNote, + Other_MikroDetailsCreated, + Other_MikroDetailsUserID + ) + VALUES( + {$header_id}, + '{$v['T_AntibioticID']}', + '{$v['value']}', + '{$v['note']}', + NOW(), + {$userid} + )"; + $query = $this->db_smartone->query($sql); + } + else{ + $sql = "UPDATE other_mikrodetails SET + Other_MikroDetailsT_AntibioticID = '{$v['T_AntibioticID']}', + Other_MikroDetailsValue = '{$v['value']}', + Other_MikroDetailsNote = '{$v['note']}', + Other_MikroDetailsIsActive = 'Y', + Other_MikroDetailsUserID = {$userid} + WHERE + Other_MikroDetailsID = {$v['xid']}"; + //echo $sql; + $query = $this->db_smartone->query($sql); + } + } + } + + + $result = array("total" => 1, "records" => array(), "sql"=> ''); + $this->sys_ok($result); + exit; + } + + + function get_doctors_preparasi_sperma() + { + $prm = $this->sys_input; + // $id = $prm["id"]; + + $sql = " SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 10 AND + M_DoctorSOIsActive = 'Y' + ORDER BY M_DoctorName ASC"; + //echo $sql; + $query = $this->db_smartone->query($sql); + $rows = $query->result_array(); + $sql = " + SELECT '0' as id, 'Belum memilih metode' as name + UNION + SELECT M_MethodeSpermaID as id, M_MethodeSpermaName as name + FROM m_methodesperma + WHERE + M_MethodeSpermaIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $methodes = $this->db_smartone->query($sql)->result_array(); + + + $this->sys_ok(["records"=>$rows,"methodes"=>$methodes]); + + } + + + function getpreparasispermaresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT other_preparasisperma.*, + Other_PreparasiSpermaID as xid, + Other_PreparasiSpermaT_OrderDetailID as orderdetail_id, + IFNULL(Other_PreparasiSpermaM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_PreparasiSpermaM_DoctorID) OR Other_PreparasiSpermaM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name, + IFNULL(M_MethodeSpermaID,0) as methode_id, + IFNULL(M_MethodeSpermaName,'') as methode_name + FROM other_preparasisperma + LEFT JOIN m_doctor ON Other_PreparasiSpermaM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + LEFT JOIN m_methodesperma ON Other_PreparasiSpermaM_MethodeSpermaID = M_MethodeSpermaID AND + M_MethodeSpermaIsActive = 'Y' + WHERE + Other_PreparasiSpermaT_OrderDetailID = {$id} AND Other_PreparasiSpermaIsActive = 'Y' + GROUP BY Other_PreparasiSpermaID"; + $query = $this->db_smartone->query($sql); + + if ($query) + { + $rows = $query->row_array(); + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 10 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $sql = " + SELECT '0' as id, 'Belum memilih metode' as name + UNION + SELECT M_MethodeSpermaID as id, M_MethodeSpermaName as name + FROM m_methodesperma + WHERE + M_MethodeSpermaIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $methodes = $this->db_smartone->query($sql)->result_array(); + $images = array(); + $sql = "SELECT Other_PreparasiSpermaImgID as xid, + Other_PreparasiSpermaImgType as type, + CONCAT('/one-media/one-image-nonlab/',Other_PreparasiSpermaImgNewName) as image_url + FROM t_orderdetail + JOIN other_preparasisperma_img ON Other_PreparasiSpermaImgT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND + Other_PreparasiSpermaImgIsActive = 'Y' + WHERE + T_OrderDetailID = {$id} AND + T_OrderDetailIsActive = 'Y' + GROUP BY Other_PreparasiSpermaImgID"; + //echo $sql; + $images = $this->db_smartone->query($sql)->result_array(); + + $rst = array('doctors'=>$doctors,'methodes'=>$methodes,'results'=>$rows,'images'=>$images); + $this->sys_ok(["records"=>$rst]); + } + else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + + function uploadimage_preparasi_sperma(){ + if (! $this->isLogin) { + $this->sys_error("Invalid Token"); + exit; + } + + $userid = $this->sys_user["M_UserID"]; + $data = []; + //print_r($_SERVER); + + $prm = $this->sys_input; + $orderid = $this->input->post('orderid'); + $type = $this->input->post('type'); + $labnumber = $this->input->post('labnumber'); + $sql = "UPDATE other_preparasisperma_img SET + Other_PreparasiSpermaImgIsActive = 'N', + Other_PreparasiSpermaImgUserID = {$userid} + WHERE + Other_PreparasiSpermaImgT_OrderHeaderID = {$orderid} AND + Other_PreparasiSpermaImgType = '{$type}'"; + //echo $sql; + $this->db_onedev->query($sql); + //$config['upload_path'] = 'assets/'; + + $path = '/home/one/project/one/one-media/one-image-nonlab/'; + //echo $path; + $config['upload_path'] = $path; + $config['allowed_types'] = 'jpg|jpeg|png|gif'; + + $config['max_size'] = '10000'; + $count = count($_FILES['files']['name']); + //echo $count; + $this->load->library('upload',$config); + + $error = []; + for($i=0;$i<$count;$i++){ + + + if(!empty($_FILES['files']['name'][$i])){ + + + + $_FILES['file']['name'] = $_FILES['files']['name'][$i]; + + $_FILES['file']['type'] = $_FILES['files']['type'][$i]; + + $_FILES['file']['tmp_name'] = $_FILES['files']['tmp_name'][$i]; + + $_FILES['file']['error'] = $_FILES['files']['error'][$i]; + + $_FILES['file']['size'] = $_FILES['files']['size'][$i]; + + + + $namex = $orderid.'-'.$labnumber.'-'.$this->generateRandomString(5); + //echo $namex; + + $config['file_name'] = $namex; + $this->upload->initialize($config); + //echo $config['file_name'] ; + + + + + + if($this->upload->do_upload('file')){ + + $uploadData = $this->upload->data(); + + $filename = $uploadData['file_name']; + //echo $filename; + + + $sql = "INSERT INTO other_preparasisperma_img ( + Other_PreparasiSpermaImgT_OrderHeaderID, + Other_PreparasiSpermaImgType, + Other_PreparasiSpermaImgOldName, + Other_PreparasiSpermaImgNewName, + Other_PreparasiSpermaImgCreated, + Other_PreparasiSpermaImgUserID + ) + VALUES( + {$orderid}, + '{$type}', + '{$_FILES['files']['name'][$i]}', + '{$filename}', + NOW(), + {$userid} + + )"; + //echo $sql; + $this->db_onedev->query($sql); + $xlast_id = $this->db_onedev->insert_id(); + $data['totalFiles'][] = array('xid' => $xlast_id ,'type'=>$type,'image_url' => '/one-media/one-image-nonlab/'.$filename); + + } + else{ + $error = array('error' => $this->upload->display_errors()); + } + + } + + + + } + + $result = array("total" =>count( $data['totalFiles']), "records" => $data['totalFiles'],'errors'=>$error); + $this->sys_ok($result); + } + + + function saveresult_preparasi_sperma() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = $inp['doctor']; + $orderdetail_id = $inp['orderdetailid']; + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + if($prm['xid'] == '0'){ + $sql = "INSERT INTO other_preparasisperma( + Other_PreparasiSpermaM_DoctorID, + Other_PreparasiSpermaT_OrderDetailID, + Other_PreparasiSpermaPreMotilitasA, + Other_PreparasiSpermaPreMotilitasB, + Other_PreparasiSpermaPreMotilitasC, + Other_PreparasiSpermaPreKonsentrasi, + Other_PreparasiSpermaPreKontaminan, + Other_PreparasiSpermaPostMotilitasA, + Other_PreparasiSpermaPostMotilitasB, + Other_PreparasiSpermaPostMotilitasC, + Other_PreparasiSpermaPostKonsentrasi, + Other_PreparasiSpermaPostKontaminan, + Other_PreparasiSpermaPreVolume, + Other_PreparasiSpermaPostVolume, + Other_PreparasiSpermaM_MethodeSpermaID, + Other_PreparasiSpermaNote, + Other_PreparasiSpermaUserID, + Other_PreparasiSpermaCreated + ) + VALUES( + {$doctor_id}, + {$orderdetail_id}, + '{$prm['Other_PreparasiSpermaPreMotilitasA']}', + '{$prm['Other_PreparasiSpermaPreMotilitasB']}', + '{$prm['Other_PreparasiSpermaPreMotilitasC']}', + '{$prm['Other_PreparasiSpermaPreKonsentrasi']}', + '{$prm['Other_PreparasiSpermaPreKontaminan']}', + '{$prm['Other_PreparasiSpermaPostMotilitasA']}', + '{$prm['Other_PreparasiSpermaPostMotilitasB']}', + '{$prm['Other_PreparasiSpermaPostMotilitasC']}', + '{$prm['Other_PreparasiSpermaPostKonsentrasi']}', + '{$prm['Other_PreparasiSpermaPostKontaminan']}', + '{$prm['Other_PreparasiSpermaPreVolume']}', + '{$prm['Other_PreparasiSpermaPostVolume']}', + '{$prm['Other_PreparasiSpermaM_MethodeSpermaID']}', + '{$prm['Other_PreparasiSpermaNote']}', + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } + else{ + $sql = "SELECT * FROM other_preparasisperma WHERE Other_PreparasiSpermaT_OrderDetailID = {$orderdetail_id} AND Other_PreparasiSpermaIsActive = 'Y'"; + $data_header = $this->db_smartone->query($sql)->row_array(); + $header_id = $data_header['Other_PreparasiSpermaID']; + $sql = "UPDATE other_preparasisperma SET + Other_PreparasiSpermaM_DoctorID = {$doctor_id}, + Other_PreparasiSpermaPreMotilitasA = '{$prm['Other_PreparasiSpermaPreMotilitasA']}', + Other_PreparasiSpermaPreMotilitasB = '{$prm['Other_PreparasiSpermaPreMotilitasB']}', + Other_PreparasiSpermaPreMotilitasC = '{$prm['Other_PreparasiSpermaPreMotilitasC']}', + Other_PreparasiSpermaPreKonsentrasi = '{$prm['Other_PreparasiSpermaPreKonsentrasi']}', + Other_PreparasiSpermaPreKontaminan = '{$prm['Other_PreparasiSpermaPreKontaminan']}', + Other_PreparasiSpermaPostMotilitasA = '{$prm['Other_PreparasiSpermaPostMotilitasA']}', + Other_PreparasiSpermaPostMotilitasB = '{$prm['Other_PreparasiSpermaPostMotilitasB']}', + Other_PreparasiSpermaPostMotilitasC = '{$prm['Other_PreparasiSpermaPostMotilitasC']}', + Other_PreparasiSpermaPostKonsentrasi = '{$prm['Other_PreparasiSpermaPostKonsentrasi']}', + Other_PreparasiSpermaPostKontaminan = '{$prm['Other_PreparasiSpermaPostKontaminan']}', + Other_PreparasiSpermaPreVolume = '{$prm['Other_PreparasiSpermaPreVolume']}', + Other_PreparasiSpermaPostVolume = '{$prm['Other_PreparasiSpermaPostVolume']}', + Other_PreparasiSpermaM_MethodeSpermaID = '{$prm['Other_PreparasiSpermaM_MethodeSpermaID']}', + Other_PreparasiSpermaNote = '{$prm['Other_PreparasiSpermaNote']}', + Other_PreparasiSpermaUserID = {$userid} + WHERE + Other_PreparasiSpermaID = {$header_id}"; + $this->db_smartone->query($sql); + } + + + $result = array("total" => 1, "records" => array(), "sql"=> ''); + $this->sys_ok($result); + exit; + } + + function getdnafragmentasiresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT other_dnafragmentasi.*, + Other_DnaFragmentasiID as xid, + Other_DnaFragmentasiT_OrderDetailID as orderdetail_id, + IFNULL(Other_DnaFragmentasiM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_DnaFragmentasiM_DoctorID) OR Other_DnaFragmentasiM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name, + IFNULL(Other_DnaFragmentasiOther_DnaFragmentasiMethodeID,0) as methode_id, + IFNULL(Other_DnaFragmentasiMethodeName,'') as methode_name, + Other_DnaFragmentasiHaloLuas as halo_luas, + Other_DnaFragmentasiHaloSedang as halo_sedang, + Other_DnaFragmentasiHaloSempit as halo_sempit, + Other_DnaFragmentasiTanpaHalo as tanpa_halo, + Other_DnaFragmentasiDFI as dfi, + Other_DnaFragmentasiKesimpulan as kesimpulan, + Other_DnaFragmentasiCatatan as catatan + FROM other_dnafragmentasi + LEFT JOIN m_doctor ON Other_DnaFragmentasiM_DoctorID = M_DoctorID + LEFT JOIN other_dnafragmentasimethode ON Other_DnaFragmentasiOther_DnaFragmentasiMethodeID = Other_DnaFragmentasiMethodeID + WHERE + Other_DnaFragmentasiT_OrderDetailID = {$id} AND Other_DnaFragmentasiIsActive = 'Y' + GROUP BY Other_DnaFragmentasiID + LIMIT 1"; + //echo $sql; + $query = $this->db_smartone->query($sql); + + if ($query) + { + $rows = $query->row_array(); + if(!$rows){ + $rows = array( + 'xid' => 0, + 'orderdetail_id' =>$id, + 'doctor_id' => 0, + 'doctor_name' => '', + 'methode_id' => 0, + 'methode_name' => '', + 'halo_luas' => '', + 'halo_sedang' => '', + 'tanpa_halo' => '', + 'dfi' => '', + 'kesimpulan' => '', + 'catatan' => '' + ); + } + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID + WHERE + M_DoctorSONat_SubGroupID = 4 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + + $sql = " + SELECT '0' as id, 'Belum memilih metode' as name + UNION + SELECT Other_DnaFragmentasiMethodeID as id, Other_DnaFragmentasiMethodeName as name + FROM other_dnafragmentasimethode + WHERE + Other_DnaFragmentasiMethodeIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $methodes = $this->db_smartone->query($sql)->result_array(); + + + $rst = array('doctors'=>$doctors,'methodes'=>$methodes,'results'=>$rows); + $this->sys_ok(["records"=>$rst]); + } + else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + function saveresult_dnafragmentasi() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = $inp['doctor']['id']; + $methode_id = $inp['methode']['id']; + $orderdetail_id = $inp['results']['orderdetail_id']; + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + if(intval($prm['xid']) == 0){ + $sql = "INSERT INTO other_dnafragmentasi( + Other_DnaFragmentasiT_OrderDetailID, + Other_DnaFragmentasiM_DoctorID, + Other_DnaFragmentasiOther_DnaFragmentasiMethodeID, + Other_DnaFragmentasiHaloLuas, + Other_DnaFragmentasiHaloSedang, + Other_DnaFragmentasiHaloSempit, + Other_DnaFragmentasiTanpaHalo, + Other_DnaFragmentasiDFI, + Other_DnaFragmentasiKesimpulan, + Other_DnaFragmentasiCatatan, + Other_DnaFragmentasiUserID, + Other_DnaFragmentasiLastUpdated + ) + VALUES( + {$orderdetail_id}, + {$doctor_id}, + {$methode_id}, + '{$prm['halo_luas']}', + '{$prm['halo_sedang']}', + '{$prm['halo_sempit']}', + '{$prm['tanpa_halo']}', + '{$prm['dfi']}', + '{$prm['kesimpulan']}', + '{$prm['catatan']}', + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } + else{ + $sql = "UPDATE other_dnafragmentasi SET + Other_DnaFragmentasiT_OrderDetailID = {$orderdetail_id}, + Other_DnaFragmentasiM_DoctorID = {$doctor_id}, + Other_DnaFragmentasiOther_DnaFragmentasiMethodeID = '{$methode_id}', + Other_DnaFragmentasiHaloLuas = '{$prm['halo_luas']}', + Other_DnaFragmentasiHaloSedang = '{$prm['halo_sedang']}', + Other_DnaFragmentasiHaloSempit = '{$prm['halo_sempit']}', + Other_DnaFragmentasiTanpaHalo = '{$prm['tanpa_halo']}', + Other_DnaFragmentasiDFI = '{$prm['dfi']}', + Other_DnaFragmentasiKesimpulan = '{$prm['kesimpulan']}', + Other_DnaFragmentasiCatatan = '{$prm['catatan']}', + Other_DnaFragmentasiLastUpdated = NOW(), + Other_DnaFragmentasiUserID = {$userid} + WHERE + Other_DnaFragmentasiID = {$prm['xid']}"; + //echo $sql; + $this->db_smartone->query($sql); + } + + + $result = array("total" => 1, "records" => array(), "sql"=> ''); + $this->sys_ok($result); + exit; + } + + +} + diff --git a/application/controllers/mockup/process/resultvalidation-v20pg/Re_px.php b/application/controllers/mockup/process/resultvalidation-v20pg/Re_px.php index d2c44b96..df562286 100644 --- a/application/controllers/mockup/process/resultvalidation-v20pg/Re_px.php +++ b/application/controllers/mockup/process/resultvalidation-v20pg/Re_px.php @@ -1,2495 +1,2492 @@ -db_smartone = $this->load->database("onedev", true); - $this->load->helper(array('form', 'url')); - } - function getMethodeID($natTestID) { - $sql = "select M_MethodePriorityNat_MethodeID MethodeID, Nat_MethodeName - from - m_methode_priority - join nat_methode on Nat_MethodeID = M_MethodePriorityNat_MethodeID - and Nat_MethodeIsActive = 'Y' - join m_instrumentmethode on M_InstrumentMethodeNat_MethodeID = Nat_MethodeID and M_InstrumentMethodeIsActive = 'Y' - join nat_instrument on M_InstrumentMethodeNat_InstrumentID = Nat_InstrumentID - and Nat_InstrumentIsActive ='Y' - where M_MethodePriorityIsActive = 'Y' - and M_MethodePriorityNat_TestID = $natTestID - and M_MethodePriorityM_DayOfWeekID = dayofweek(now()) - order by M_MethodePriorityNumber desc - limit 0,1 "; - $qry = $this->db->query($sql); - if ($qry) { - $rows = $qry->result_array(); - if (count($rows) > 0 ) return array($rows[0]["MethodeID"],$rows[0]["Nat_MethodeName"]); - } - //2nd - $sql= "select - M_InstrumentMethodeNat_MethodeID MethodeID, Nat_MethodeName - from m_instrumentmethode - join nat_methode on M_InstrumentMethodeNat_MethodeID = Nat_MethodeID - and Nat_MethodeIsActive = 'Y' - join nat_instrument on M_InstrumentMethodeNat_InstrumentID = Nat_InstrumentID - and Nat_InstrumentIsActive ='Y' - where M_InstrumentMethodeNat_TestID = $natTestID - and M_InstrumentMethodeIsActive = 'Y' - order by M_InstrumentMethodePriority desc - limit 0,1"; - $qry = $this->db->query($sql); - if ($qry) { - $rows = $qry->result_array(); - if (count($rows) > 0 ) return array($rows[0]["MethodeID"],$rows[0]["Nat_MethodeName"]); - } - // - $sql = "select Nat_NormalValueNat_MethodeID MethodeID, Nat_MethodeName - from - nat_normalvalue - join nat_methode on Nat_NormalValueNat_MethodeID = Nat_MethodeID - and Nat_MethodeIsActive = 'Y' - where Nat_NormalValueNat_TestID = $natTestID - and Nat_NormalValueIsActive = 'Y' - order by Nat_NormalValueID - limit 0,1"; - $qry = $this->db->query($sql); - if ($qry) { - $rows = $qry->result_array(); - if (count($rows) > 0 ) return array($rows[0]["MethodeID"],$rows[0]["Nat_MethodeName"]); - } - return array(0,""); - } - function get_normal_value($methodeID, $natTestID, $sexID, $ageInDay ) { - $sql = "select fn_sampling_get_normal($methodeID, $natTestID, $sexID, $ageInDay) as normalValueID"; - $qry = $this->db->query($sql); - if ($qry) { - $rows = $qry->result_array(); - if (count($rows) > 0 ) return $rows[0]["normalValueID"]; - } - return 0; - } - function fn_fix_normal($order_id) { - $sql = "select - T_OrderDetailID, M_PatientM_SexID, fn_global_age_count_day(M_PatientDOB, date(T_OrderHeaderDate)) Dob , - T_TestNat_TestID - from t_orderheader - join m_patient on T_OrderHeaderID = $order_id and T_OrderHeaderM_PatientID = M_PatientID - join t_orderdetail on T_OrderDetailT_OrderHeaderID = T_OrderHeaderID - and T_OrderDetailIsACtive = 'Y' - and ( T_OrderDetailNat_NormalValueID is null or T_OrderDetailNat_NormalValueID = 0 ) - join t_test on T_OrderDetailT_TestID = T_TestID and T_TestIsResult = 'Y' "; - $qry = $this->db->query($sql); - if(! $qry) { - return; - } - $rows = $qry->result_array(); - if(count($rows) == 0 ) return; - $sql_u = "update t_orderdetail - join nat_normalvalue on T_OrderDetailID = ? and Nat_NormalValueID = ? - set - T_OrderDetailNat_NormalValueID = Nat_NormalValueID, - T_OrderDetailNormalValueNote = Nat_NormalValueNote, - T_OrderDetailNormalValueDescription = Nat_NormalValueDescription, - T_OrderDetailMinValue = Nat_NormalValueMinValue, - T_OrderDetailMaxValue = Nat_NormalValueMaxValue, - T_OrderDetailMinValueInclusive = Nat_NormalValueMinValueInclusive, - T_OrderDetailMaxValueInclusive = Nat_NormalValueMaxValueInclusive, - T_OrderDetailNat_MethodeID = ?, - T_OrderdetailNat_MethodeName =?"; - - foreach($rows as $r) { - $T_OrderDetailID = $r["T_OrderDetailID"]; - $sexID = $r["M_PatientM_SexID"]; - $ageInDay = $r["Dob"]; - $natTestID = $r["T_TestNat_TestID"]; - list($methodeID,$methodeName) = $this->getMethodeID($natTestID); - if ($methodeID == 0 ) continue; - $normalValueID = $this->get_normal_value($methodeID, $natTestID, $sexID, $ageInDay); - if ($normalValueID == 0) return; - $this->db->query($sql_u, array($T_OrderDetailID, $normalValueID, $methodeID, $methodeName)); - } - } - function update_order_sample($targetID, $sourceID) { - $sql = "update t_ordersample target - join t_ordersample source on - target.T_OrderSampleID = ? - and target.T_OrderSampleWorklistReceive = 'N' - and source.T_OrderSampleID = ? - set - target.T_OrderSampleSampling = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSampling, source.T_OrderSampleSampling), - target.T_OrderSampleSamplingDate = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingDate, source.T_OrderSampleSamplingDate), - target.T_OrderSampleSamplingTime = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingTime, source.T_OrderSampleSamplingTime), - target.T_OrderSampleSamplingUserID = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingUserID, source.T_OrderSampleSamplingUserID), - - target.T_OrderSampleReceive = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceive, source.T_OrderSampleReceive), - target.T_OrderSampleReceiveDate = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveDate, source.T_OrderSampleReceiveDate), - target.T_OrderSampleReceiveTime = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveTime, source.T_OrderSampleReceiveTime), - target.T_OrderSampleReceiveUserID = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveUserID, source.T_OrderSampleReceiveUserID), - - target.T_OrderSampleVerification = if(target.T_OrderSampleVerification='Y',target.T_OrderSampleVerification, source.T_OrderSampleVerification), - target.T_OrderSampleVerificationDate =if(target.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationDate, source.T_OrderSampleVerificationDate), - target.T_OrderSampleVerificationTime =if(source.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationTime, source.T_OrderSampleVerificationTime), - target.T_OrderSampleVerificationUserID =if(source.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationUserID, source.T_OrderSampleVerificationUserID), - - target.T_OrderSampleProcessing = if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessing, source.T_OrderSampleProcessing), - target.T_OrderSampleProcessingDate= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingDate, source.T_OrderSampleProcessingDate), - target.T_OrderSampleProcessingTime= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingTime, source.T_OrderSampleProcessingTime), - target.T_OrderSampleProcessingUserID= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingUserID, source.T_OrderSampleProcessingUserID), - - target.T_OrderSampleReceiveHandling =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandling, source.T_OrderSampleReceiveHandling ), - target.T_OrderSampleReceiveHandlingDate =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingDate, source.T_OrderSampleReceiveHandlingDate), - target.T_OrderSampleReceiveHandlingTime =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingTime, source.T_OrderSampleReceiveHandlingTime), - target.T_OrderSampleReceiveHandlingUserID =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingUserID, source.T_OrderSampleReceiveHandlingUserID), - - target.T_OrderSampleHandling = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandling, source.T_OrderSampleHandling), - target.T_OrderSampleHandlingDate = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingDate, source.T_OrderSampleHandlingDate), - target.T_OrderSampleHandlingTime = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingTime, source.T_OrderSampleHandlingTime), - target.T_OrderSampleHandlingUserID = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingUserID, source.T_OrderSampleHandlingUserID), - - target.T_OrderSampleWorklistReceive = source.T_OrderSampleWorklistReceive, - target.T_OrderSampleWorklistReceiveDatetime = source.T_OrderSampleWorklistReceiveDateTime, - target.T_OrderSampleWorklistReceiveUserID = source.T_OrderSampleWorklistReceiveUserID - "; - $qry = $this->db->query($sql,array($targetID,$sourceID)); - if(! $qry ) { - echo json_encode(array( "status" => "ERR" , "message" => print_r($this->db->error(),true))); - exit; - } - } - function fix_sample_serum($headerID) { - //cari t_ordersample yg belum worklist receive dengan code 017% - $sql = "select T_OrderSampleID - from t_ordersample - join t_sampletype on - T_OrderSampleT_OrderHeaderID = ? - and T_OrderSampleWorklistReceive = 'N' - and T_OrderSampleIsActive = 'Y' - and T_OrderSampleT_SampleTypeID = T_SampletypeID - and T_SampleTypeCode like '017%' - "; - $qry = $this->db->query($sql, array($headerID)); - if(!$qry) { - echo json_encode(array( "status" => "ERR" , "message" => print_r($this->db->error(),true))); - exit; - } - $rows = $qry->result_array(); - if (count($rows) == 0 ) return; - //cari T_OrderSample yang sudah di receive yg terakhir - $sql = "select T_OrderSampleID - from t_ordersample - join t_sampletype on - T_OrderSampleT_OrderHeaderID = ? - and T_OrderSampleWorklistReceive = 'Y' - and T_OrderSampleIsActive = 'Y' - and T_OrderSampleT_SampleTypeID = T_SampletypeID - and T_SampleTypeCode like '017%' - order by T_OrderSampleWorklistReceiveDatetime desc - limit 0,1 - "; - $qry = $this->db->query($sql, array($headerID)); - if(!$qry) { - echo json_encode(array( "status" => "ERR" , "message" => print_r($this->db->error(),true))); - exit; - } - $rcv_rows = $qry->result_array(); - if (count($rcv_rows) == 0 ) return; - - //print_r($rows); - //print_r($rcv_rows); - $rcv_T_OrderSampleID = $rcv_rows[0]["T_OrderSampleID"]; - //ada yg belum di receive - foreach($rows as $r) { - $T_OrderSampleID = $r["T_OrderSampleID"]; - $this->update_order_sample($T_OrderSampleID,$rcv_T_OrderSampleID); - } - } - public function search() - { - $prm = $this->sys_input; - $max_rst = 99; - - $id = $prm["order_id"]; - if ($id > 0 ) { - $this->fix_sample_serum($id); - $this->fn_fix_normal($id); - } - $lang = $this->lang_default_code; - $lang_id = isset($prm['lang_id']) ? $prm['lang_id'] : '0'; - - if ($lang_id != 0) - { - $l = $this->db_smartone->where("Nat_LangID", $lang_id)->get("nat_lang")->row(); - $lang = $l->Nat_LangCode; - } - - //tambahan fajri - $sql = " UPDATE t_orderdetail - JOIN t_test ON T_OrderDetailT_TestID = T_TestID - SET T_OrderDetailT_TestIsResult = T_TestIsResult - WHERE - T_OrderDetailT_OrderHeaderID = {$id} AND - T_OrderDetailT_TestIsResult = '' AND - T_OrderDetailIsActive = 'Y'"; - $this->db_smartone->query($sql); - - $tot_count = 0; - $lq = ""; - $group_id = 0; - if (isset($prm['group_id'])) - $group_id = $prm['group_id']; - - if ($group_id != 0) - { - $sql = "select distinct T_WorklistDetailNat_TestID Nat_TestID - from t_worklistdetailv2 - where T_WorklistDetailT_WorklistID = {$group_id}"; - $qry = $this->db_smartone->query($sql); - $rows = $qry->result_array(); - $nat_test_ids = "0"; - foreach($rows as $r) { - $nat_test_ids .= ", " . $r["Nat_TestID"]; - } - $q_group = " ( $nat_test_ids ) "; - - $sql = " - SELECT a1.*, cOUNT(a2.T_OrderDetailID) level - FROM ( - SELECT IFNULL(y.T_OrderDetailT_TestID, x.T_OrderDetailT_TestID) t_testid, - IFNULL(y.T_OrderDetailT_TestName, y.T_OrderDetailT_TestName) t_testname, - y.T_OrderDetailResult result, y.T_OrderDetailResult result_old, y.T_OrderDetailNote note, y.T_OrderDetailNote note_old, - y.T_OrderDetailID id, - y.T_OrderDetailT_TestIsResult is_result, a.T_TestIsQuantitative is_quantitative, - y.T_OrderDetailResultFlag result_flag, - y.T_OrderDetailNat_NormalValueID normal_id, - y.T_OrderDetailNormalValueNote normal_note, y.T_OrderDetailNat_UnitName unit_name, - y.T_OrderdetailNat_MethodeID methode_id, y.T_OrderdetailNat_MethodeName methode_name, - a.T_TestNat_TestID nattest_id, a.T_TestID tx_id, count(T_ResultInstrumentID) as result_instrument_n, - y.T_OrderDetailVerification, T_OrderSampleReceive sample_receive, - T_OrderSampleProcessing sample_processing, T_OrderSampleWorklistReceive sample_worklist_receive, - IF(T_OrderDetailAddOnPreAnalytic = 'Y', T_OrderDetailAddOnPreAnalytic, PreAnalyticIsOk) pre_analytic, - T_OrderDetailAddOnPreAnalytic, - T_OrderHeaderID order_id, y.T_OrderDetailT_TestSasCode test_sas_code, - tx.T_TestSasCode, - T_OrderDetailAddOnResample `resample`, T_OrderDetailAddOnResampleStatus resample_status, - T_OrderDetailAddOnRef ref, y.T_OrderDetailVerification verification, y.T_OrderDetailValidation validation, - T_OrderPromiseDateTime, Group_ResultName as ResultGroupName - FROM t_orderdetail x - left join t_orderpromise on x.T_OrderDetailT_OrderPromiseID = T_OrderPromiseID - JOIN t_test tx ON x.T_OrderDetailT_TestID = T_TestID - JOIN t_test tcheck on tcheck.T_TestNat_TestID in {$q_group} - and ( tx.T_TestID = tcheck.T_TestID or tx.T_TestSasCode like concat(tcheck.T_TestSasCode,'%')) - LEFT JOIN group_resultdetail ON Group_ResultDetailT_TestID = x.T_OrderDetailT_TestID AND Group_ResultDetailIsActive = 'Y' - LEFT JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND Group_ResultFlagNonLab = 'N' - LEFT JOIN t_orderdetail y ON x.T_OrderDetailT_TestSasCode LIKE CONCAT(y.T_OrderDetailT_TestSasCode, '%') - AND x.T_OrderDetailT_OrderHeaderID = y.T_OrderDetailT_OrderHeaderID - AND y.T_OrderDetailIsActive = 'Y' - LEFT JOIN t_orderdetailaddon ON x.T_OrderDetailID = T_OrderDetailAddOnT_OrderDetailID - JOIN t_orderheader ON y.T_OrderDetailT_OrderHeaderID = T_OrderHeaderID - LEFT JOIN t_test a ON y.T_OrderDetailT_TestID = a.T_TestID - AND a.T_TestIsNonLab = '' - LEFT JOIN (SELECT T_OrderSampleT_SampleTypeID, T_OrderSampleReceive, T_OrderSampleProcessing, T_OrderSampleWorklistReceive - FROM t_ordersample WHERE T_OrderSampleT_OrderHeaderID = {$id} - AND T_OrderSampleIsactive = 'Y' - GROUP BY T_OrderSampleT_SampleTypeID) os ON a.T_TestT_SampleTypeID = os.T_OrderSampleT_SampleTypeID - or os.T_OrderSampleT_SampleTypeID = fn_sampletype_from_local(a.T_TestNat_TestID) - - LEFT JOIN t_resultinstrument ON T_ResultInstrumentT_OrderDetailID = x.T_OrderDetailID - LEFT JOIN pre_analytic ON PreAnalyticNat_TestID = a.T_TestNat_TestID AND PreAnalyticDate = date(now()) and PreAnalyticIsActive = 'Y' - WHERE x.T_OrderDetailT_OrderHeaderID = {$id} - AND x.T_OrderDetailIsActive = 'Y' - GROUP BY y.T_OrderDetailT_TestID - ORDER BY y.T_OrderDetailT_TestSasCode ASC - ) a1 - - LEFT JOIN t_orderdetail a2 ON a2.T_OrderDetailT_OrderHeaderID = a1.order_id - AND a2.T_OrderDetailIsActive = 'Y' - AND a1.test_sas_code LIKE CONCAT(a2.T_OrderDetailT_testSasCode, '%') - GROUP BY a1.t_testid - order by a1.test_sas_code -"; - $query = $this->db_smartone->query($sql); - $lq = $this->db_smartone->last_query(); - } - else - { - $sql = " - SELECT a1.*, cOUNT(a2.T_OrderDetailID) level - FROM ( - SELECT IFNULL(y.T_OrderDetailT_TestID, x.T_OrderDetailT_TestID) t_testid, - IFNULL(y.T_OrderDetailT_TestName, y.T_OrderDetailT_TestName) t_testname, - y.T_OrderDetailResult result, y.T_OrderDetailResult result_old, y.T_OrderDetailNote note, y.T_OrderDetailNote note_old, - y.T_OrderDetailID id, - y.T_OrderDetailT_TestIsResult is_result, a.T_TestIsQuantitative is_quantitative, - y.T_OrderDetailResultFlag result_flag, - y.T_OrderDetailNat_NormalValueID normal_id, - y.T_OrderDetailNormalValueNote normal_note, y.T_OrderDetailNat_UnitName unit_name, - y.T_OrderdetailNat_MethodeID methode_id, y.T_OrderdetailNat_MethodeName methode_name, - a.T_TestNat_TestID nattest_id, a.T_TestID tx_id, count(T_ResultInstrumentID) as result_instrument_n, - y.T_OrderDetailVerification, T_OrderSampleReceive sample_receive, - T_OrderSampleProcessing sample_processing, T_OrderSampleWorklistReceive sample_worklist_receive, - IF(T_OrderDetailAddOnPreAnalytic = 'Y', T_OrderDetailAddOnPreAnalytic, PreAnalyticIsOk) pre_analytic, - T_OrderDetailAddOnPreAnalytic, - T_OrderHeaderID order_id, y.T_OrderDetailT_TestSasCode test_sas_code, - tx.T_TestSasCode, - T_OrderDetailAddOnResample `resample`, T_OrderDetailAddOnResampleStatus resample_status, - T_OrderDetailAddOnRef ref, y.T_OrderDetailVerification verification, y.T_OrderDetailValidation validation, - T_OrderPromiseDateTime , Group_ResultName as ResultGroupName - FROM t_orderdetail x - left join t_orderpromise on x.T_OrderDetailT_OrderPromiseID = T_OrderPromiseID - JOIN t_test tx ON x.T_OrderDetailT_TestID = T_TestID - LEFT JOIN group_resultdetail ON Group_ResultDetailT_TestID = x.T_OrderDetailT_TestID AND Group_ResultDetailIsActive = 'Y' - LEFT JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND Group_ResultFlagNonLab = 'N' - LEFT JOIN t_orderdetail y ON x.T_OrderDetailT_TestSasCode LIKE CONCAT(y.T_OrderDetailT_TestSasCode, '%') - AND x.T_OrderDetailT_OrderHeaderID = y.T_OrderDetailT_OrderHeaderID - AND y.T_OrderDetailIsActive = 'Y' - - LEFT JOIN t_orderdetailaddon ON x.T_OrderDetailID = T_OrderDetailAddOnT_OrderDetailID - - JOIN t_orderheader ON y.T_OrderDetailT_OrderHeaderID = T_OrderHeaderID - LEFT JOIN t_test a ON y.T_OrderDetailT_TestID = a.T_TestID - AND a.T_TestIsNonLab = '' - LEFT JOIN (SELECT T_OrderSampleT_SampleTypeID, T_OrderSampleReceive, T_OrderSampleProcessing, T_OrderSampleWorklistReceive - FROM t_ordersample WHERE T_OrderSampleT_OrderHeaderID = {$id} - AND T_OrderSampleIsactive = 'Y' - GROUP BY T_OrderSampleT_SampleTypeID) os ON a.T_TestT_SampleTypeID = os.T_OrderSampleT_SampleTypeID - or os.T_OrderSampleT_SampleTypeID = fn_sampletype_from_local(a.T_TestNat_TestID) - - LEFT JOIN t_resultinstrument ON T_ResultInstrumentT_OrderDetailID = x.T_OrderDetailID - LEFT JOIN pre_analytic ON PreAnalyticNat_TestID = a.T_TestNat_TestID AND PreAnalyticDate = date(now()) and PreAnalyticIsActive = 'Y' - WHERE x.T_OrderDetailT_OrderHeaderID = {$id} - AND x.T_OrderDetailIsActive = 'Y' - GROUP BY y.T_OrderDetailT_TestID - ORDER BY y.T_OrderDetailT_TestSasCode ASC - ) a1 - - LEFT JOIN t_orderdetail a2 ON a2.T_OrderDetailT_OrderHeaderID = a1.order_id - AND a2.T_OrderDetailIsActive = 'Y' - AND a1.test_sas_code LIKE CONCAT(a2.T_OrderDetailT_testSasCode, '%') - GROUP BY a1.t_testid - order by a1.test_sas_code -"; -//echo $sql; - $query = $this->db_smartone->query($sql); - $lq = $this->db_smartone->last_query(); - } - // file_put_contents("/xtmp/re-query.sql",$lq); - - if ($query) { - $rst = []; - $rows = $query->result_array(); - - foreach($rows as $k => $v) - { - - if ($v['is_result'] == "Y" && $v['is_quantitative'] == "N") - { - $v['template'] = []; - $x = $this->db_smartone->query("CALL sp_master_resulttemplate_get('{$v['t_testid']}')"); - $this->clean_mysqli_connection($this->db_smartone->conn_id); - if ($x) - $v['template'] = $x->result_array(); - } - - // IF Rujukan, by pas Pre Analytik - if ($v['ref'] == 'Y') - $v['pre_analytic'] = 'Y'; - if ($v["id"] == "885455" ) - { - //sipe workaround - //$v["sample_receive"] = "Y"; - $v["sample_worklist_receive"] = "Y"; - } - $rst[] = $v; - } - - $result = array("total" => $tot_count, "records" => $rst, "total_display" => sizeof($rows), "q" => $lq); - $this->sys_ok($result); - } - else { - $this->sys_error_db("RE Px rows", $this->db_smartone); - exit; - } - } - - public function save() - { - $prm = $this->sys_input; - $data = json_decode($prm["data"]); - $lang = $this->lang_default_code; - $lang_id = isset($prm['lang_id']) ? $prm['lang_id'] : '0'; - - if ($lang_id != 0) - { - $l = $this->db_smartone->where("Nat_LangID", $lang_id)->get("nat_lang")->row(); - $lang = $l->Nat_LangCode; - } - - $sql_norm = "select T_OrderDetailMinValue, T_OrderDetailMaxValue, - T_OrderDetailMinValueInclusive, T_OrderDetailMaxValueInclusive, - Nat_TestFlagLow, Nat_TestFlagHigh - from t_orderdetail - join t_test on T_OrderDetailT_TestID = T_TestID - join nat_test on T_TestNat_TestID = Nat_TestID and T_TestIsActive = 'Y' - where T_OrderDetailID = ? "; - - $ids = []; - foreach ($data as $k => $v) - { - if ( $v->resultInstrumentID > 0 ) { - $sql_i = "select T_ResultInstrumentNat_NormalValueID normalValueID - from t_resultinstrument - where T_ResultInstrumentID = ?"; - $qry_i = $this->db_smartone->query($sql_i, array($v->resultInstrumentID)); - if ($qry_i) { - $rows_i = $qry_i->result_array(); - - if (count($rows_i) > 0 ) { - $sql_iu = "update t_orderdetail, nat_normalvalue , nat_methode - set T_OrderDetailMinValue = Nat_NormalValueMinValue, - T_OrderDetailMinValueInclusive = Nat_NormalValueMinValueInclusive, - T_OrderDetailMaxValue = Nat_NormalValueMaxValue , - T_OrderDetailMaxValueInclusive = Nat_NormalValueMaxValueInclusive, - T_OrderDetailNormalValueNote = Nat_NormalValueNote, - T_OrderDetailNormalValueDescription = Nat_NormalValueDescription, - T_OrderDetailNat_NormalValueID = Nat_NormalValueID, - T_OrderDetailNat_MethodeID = Nat_NormalValueNat_MethodeID, - T_OrderDetailNat_MethodeName = Nat_MethodeName - where T_OrderDetailID = ? and Nat_NormalValueID = ? - and Nat_NormalValueNat_MethodeID = Nat_MethodeID - "; - $this->db_smartone->query($sql_iu, array($v->id, $rows_i[0]["normalValueID"])); - //file_put_contents("/xtmp/update-nilai-normal", $this->db_smartone->last_query() . "\n", FILE_APPEND); - } - } - } - $y = $this->db_smartone->query("SELECT fn_process_sample_handling_perfect('{$v->order_id}', '{$v->test_id}') c") - ->row(); - $req_status = $y->c; - $qry_norm = $this->db_smartone->query($sql_norm,$v->id); - $result_flag = ""; - if ($qry_norm) { - $rows_norm = $qry_norm->result_array(); - if (count($rows_norm) > 0 ) { - $r = $rows_norm[0]; - if (is_numeric($v->result)) { - - if ( $r["T_OrderDetailMinValueInclusive"] == "Y" && $v->result < $r["T_OrderDetailMinValue"] ) { - $result_flag = $r["Nat_TestFlagLow"]; - } - if ( $r["T_OrderDetailMinValueInclusive"] == "N" && $v->result <= $r["T_OrderDetailMinValue"] ) { - $result_flag = $r["Nat_TestFlagLow"]; - } - if ( $r["T_OrderDetailMaxValueInclusive"] == "Y" && $v->result > $r["T_OrderDetailMaxValue"] ) { - $result_flag = $r["Nat_TestFlagHigh"]; - } - if ( $r["T_OrderDetailMaxValueInclusive"] == "N" && $v->result >= $r["T_OrderDetailMaxValue"] ) { - $result_flag = $r["Nat_TestFlagHigh"]; - } - } - } - } - if ($lang == $this->lang_default_code) - { - $this->db_smartone->set('T_OrderDetailResult', $v->result) - ->set('T_OrderDetailResultFlag', $result_flag) - ->set('T_OrderDetailNote', $v->note) - ->set('T_OrderDetailReqStatus', $req_status) - ->where('T_OrderDetailID', $v->id) - ->update('t_orderdetail'); - } - else - { - $this->db_smartone->set('T_OrderDetailLangResult', $v->result) - ->set('T_OrderDetailLangNote', $v->note) - ->where('T_OrderDetailLangID', $v->id) - ->update('t_orderdetaillang'); - } - - $ids[] = $v->id; - } - - // LOG Process - $order = $this->db_smartone->select('T_OrderDetailT_OrderHeaderID id, T_OrderHeaderLabNumber lab_number', false) - ->join('t_orderheader', 'T_OrderHeaderID = T_OrderDetailT_OrderHeaderID') - ->where('T_OrderDetailID', $data[0]->id) - ->get('t_orderdetail') - ->row(); - - $dblog = $this->load->database("onelog", true); - $dblog->set('Log_ProcessCode', 'PROCESS.Result.Entry') - ->set('Log_ProcessOrderID', $order->id) - ->set('Log_ProcessOrderNumber', $order->lab_number) - ->set('Log_ProcessJson', json_encode($data)) - ->set('Log_ProcessUserID', $this->sys_user['M_UserID']) - ->insert('log_process'); - // END OF Log Process - //auto calculation - $this->load->library("Resultcalc"); - $rows = $this->resultcalc->auto($order->id); - - try { - foreach($ids as $id ) { - $this->db_smartone->query("call sp_set_normal_value_flag($id)"); - $this->clean_mysqli_connection($this->db_smartone->conn_id); - } - } catch(Exception $e) { - } - - $this->sys_ok($ids); - } - - public function save_template() - { - $prm = $this->sys_input; - - $n = $this->db_smartone->select("COUNT(T_ResultTemplateID) n") - ->where("T_ResultTemplateT_TestID", $prm['test_id']) - ->where("T_ResultTemplateIsActive", "Y") - ->where("T_ResultTemplateValue", $prm['value']) - ->get('t_resulttemplate') - ->row(); - if ($n->n > 0) - { - $this->sys_error_db("Insert Result Template", $this->db_smartone); - return; - } - - $r = $this->db_smartone->set("T_ResultTemplateT_TestID", $prm['test_id']) - ->set("T_ResultTemplateValue", $prm['value']) - ->insert('t_resulttemplate'); - if ($r) - { - $template = []; - $x = $this->db_smartone->query("CALL sp_master_resulttemplate_get('{$prm['test_id']}')"); - $this->clean_mysqli_connection($this->db_smartone->conn_id); - if ($x) - $template = $x->result_array(); - - $this->sys_ok($template); - } - } - - public function export() - { - $prm = $this->sys_input; - - $sql = "CALL sp_process_result_lang(?, ?, ?, ?)"; - $query = $this->db_smartone->query($sql, [$prm['order_id'], $prm['lang_id'], $prm['is_si'], $this->sys_user['M_UserID']]); - if ($query) - { - $r = $query->row(); - if ($r->status == "OK") - { - $this->sys_ok($r->data); - return; - } - - $this->sys_error_db("Message : " . $r->message, $this->db_smartone); - } - else - { - $this->sys_error_db("Lang Result", $this->db_smartone); - return; - } - } - - public function search_group() - { - $prm = $this->sys_input; - $max_rst = 100; - - // QUERY TOTAL - $sql = "select count(*) total - from t_worklist - where T_WorklistIsActive = 'Y' - order by T_WorklistName ASC"; - $query = $this->db_smartone->query($sql); - - if ($query) { - $tot_count = $query->result_array()[0]["total"]; - } - else { - $this->sys_error_db("worklist count", $this->db_smartone); - exit; - } - - $sql = "select T_WorklistID group_id, T_WorklistName group_name - from t_worklist - where T_WorklistIsActive = 'Y' - order by T_WorklistName ASC - limit 0, {$max_rst}"; - $query = $this->db_smartone->query($sql); - - if ($query) { - $rows = $query->result_array(); - foreach ($rows as $k => $v) - $rows[$k]['data'] = json_decode($v['data']); - $result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows), "q" => $this->db_smartone->last_query()); - $this->sys_ok($result); - } - else { - $this->sys_error_db("worklist rows", $this->db_smartone); - exit; - } - } - - public function search_rerun() - { - $prm = $this->sys_input; - $id = $prm["detail_id"]; - - $sql = "CALL sp_process_result_rerun(?)"; - $query = $this->db_smartone->query($sql, [$id]); - - if ($query) - { - $rows = $query->result_array(); - $this->sys_ok(["records"=>$rows]); - } - else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - - - function getdoctorsfna() - { - $prm = $this->sys_input; - // $id = $prm["id"]; - - $sql = " SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY M_DoctorName ASC"; - //echo $sql; - $query = $this->db_smartone->query($sql); - - if ($query) - { - $rows = $query->result_array(); - $this->sys_ok(["records"=>$rows]); - } - else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - function getfnaresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT Other_FNADetailsID as xid, - Other_FNAT_OrderDetailID as orderdetail_id, - Other_FNADetailsCode as code, - Other_FNADetailsLabel as label, - Other_FNADetailsResult as result, - IFNULL(Other_FNAM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_FNAM_DoctorID) OR Other_FNAM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_fna - JOIN other_fnadetails ON Other_FNADetailsOther_FNAID = Other_FNAID AND Other_FNADetailsIsActive = 'Y' - LEFT JOIN m_doctor ON Other_FNAM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_FNAT_OrderDetailID = {$id} AND Other_FNAIsActive = 'Y' - GROUP BY Other_FNADetailsID - ORDER BY Other_FNADetailsCode ASC"; - $query = $this->db_smartone->query($sql); - - if ($query) - { - $rows = $query->result_array(); - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $images = array(); - $sql = "SELECT So_ImageUploadID as xid, - CONCAT('/one-media/one-image-nonlab/',So_ImageUploadNewName) as image_url - FROM t_orderdetail - JOIN so_imageupload ON So_ImageUploadT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND - So_ImageUploadIsActive = 'Y' - WHERE - T_OrderDetailID = {$id} AND - T_OrderDetailIsActive = 'Y' - GROUP BY So_ImageUploadID"; - $images = $this->db_smartone->query($sql)->result_array(); - - $rst = array('doctors'=>$doctors,'results'=>$rows,'images'=>$images); - $this->sys_ok(["records"=>$rst]); - } - else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - - function uploadimage(){ - if (! $this->isLogin) { - $this->sys_error("Invalid Token"); - exit; - } - - $userid = $this->sys_user["M_UserID"]; - $data = []; - //print_r($_SERVER); - - $prm = $this->sys_input; - $orderid = $this->input->post('orderid'); - $labnumber = $this->input->post('labnumber'); - $sql = "UPDATE so_imageupload SET - So_ImageUploadIsActive = 'N', - So_ImageUploadUserID = {$userid} - WHERE - So_ImageUploadT_OrderHeaderID = {$orderid}"; - //echo $sql; - $this->db_onedev->query($sql); - //$config['upload_path'] = 'assets/'; - - $path = '/home/one/project/one/one-media/one-image-nonlab/'; - //echo $path; - $config['upload_path'] = $path; - $config['allowed_types'] = 'jpg|jpeg|png|gif'; - - $config['max_size'] = '10000'; - $count = count($_FILES['files']['name']); - //echo $count; - $this->load->library('upload',$config); - - $error = []; - for($i=0;$i<$count;$i++){ - - - if(!empty($_FILES['files']['name'][$i])){ - - - - $_FILES['file']['name'] = $_FILES['files']['name'][$i]; - - $_FILES['file']['type'] = $_FILES['files']['type'][$i]; - - $_FILES['file']['tmp_name'] = $_FILES['files']['tmp_name'][$i]; - - $_FILES['file']['error'] = $_FILES['files']['error'][$i]; - - $_FILES['file']['size'] = $_FILES['files']['size'][$i]; - - - - $namex = $orderid.'-'.$labnumber.'-'.$this->generateRandomString(5); - //echo $namex; - - $config['file_name'] = $namex; - $this->upload->initialize($config); - //echo $config['file_name'] ; - - - - - - if($this->upload->do_upload('file')){ - - $uploadData = $this->upload->data(); - - $filename = $uploadData['file_name']; - //echo $filename; - - - $sql = "INSERT INTO so_imageupload ( - So_ImageUploadT_OrderHeaderID, - So_ImageUploadT_OrderHeaderLabNumber, - So_ImageUploadT_SampleTypeID, - So_ImageUploadOldName, - So_ImageUploadNewName, - So_ImageUploadCreated, - So_ImageUploadUserID - ) - VALUES( - {$orderid}, - '{$labnumber}', - '150', - '{$_FILES['files']['name'][$i]}', - '{$filename}', - NOW(), - {$userid} - - )"; - //echo $sql; - $this->db_onedev->query($sql); - $xlast_id = $this->db_onedev->insert_id(); - $data['totalFiles'][] = array('xid' => $xlast_id ,'image_url' => '/one-media/one-image-nonlab/'.$filename); - - } - else{ - $error = array('error' => $this->upload->display_errors()); - } - - } - - - - } - - $result = array("total" =>count( $data['totalFiles']), "records" => $data['totalFiles'],'errors'=>$error); - $this->sys_ok($result); - } - - - function generateRandomString($length = 10) { - $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; - $charactersLength = strlen($characters); - $randomString = ''; - for ($i = 0; $i < $length; $i++) { - $randomString .= $characters[rand(0, $charactersLength - 1)]; - } - return $randomString; - } - - function getcytologiresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT Other_CytologiDetailsID as xid, - Other_CytologiT_OrderDetailID as orderdetail_id, - Other_CytologiDetailsCode as code, - Other_CytologiDetailsLabel as label, - Other_CytologiDetailsResult as result, - IFNULL(Other_CytologiM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_CytologiM_DoctorID) OR Other_CytologiM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_cytologi - JOIN other_cytologidetails ON Other_CytologiDetailsOther_CytologiID = Other_CytologiID AND Other_CytologiDetailsIsActive = 'Y' - LEFT JOIN m_doctor ON Other_CytologiM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_CytologiT_OrderDetailID = {$id} AND Other_CytologiIsActive = 'Y' - GROUP BY Other_CytologiDetailsID - ORDER BY Other_CytologiDetailsCode ASC"; - //echo $sql; - $query = $this->db_smartone->query($sql); - - if ($query) - { - $rows = $query->result_array(); - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $rst = array('doctors'=>$doctors,'results'=>$rows); - $this->sys_ok(["records"=>$rst]); - } - else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - function getmikroresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT - Other_MikroID as xid, - Other_MikroHasilBiakan as hasil_biakan, - Other_MikroSampleTypeName as sample_name, - Other_MikroT_OrderDetailID as orderdetail_id, - Other_MikroResult as result_value, - '' as result_other, - IFNULL(T_BacteriaID,0) as T_BacteriaID, - IFNULL(T_BacteriaName,'') as T_BacteriaName, - '' as details, - IFNULL(Other_MikroM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_MikroM_DoctorID) OR Other_MikroM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_mikro - LEFT JOIN t_bacteria ON Other_MikroT_BacteriaID = T_BacteriaID - LEFT JOIN m_doctor ON Other_MikroM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_MikroT_OrderDetailID = {$id} AND Other_MikroIsActive = 'Y' - GROUP BY Other_MikroID"; - //echo $sql; - $query = $this->db_smartone->query($sql); - - if ($query) - { - $row = $query->row_array(); - if($row){ - if($row['result_value'] != 'Positif' && $row['result_value'] != 'Negatif'){ - $row['result_other'] = $row['result_value']; - $row['result_value'] = 'other'; - } - $sql = "SELECT '' as xno, - Other_MikroDetailsID as xid, - Other_MikroDetailsValue as value, - IF(Other_MikroDetailsNote = 'R','Y','N') as chx_r, - IF(Other_MikroDetailsNote = 'I','Y','N') as chx_i, - IF(Other_MikroDetailsNote = 'S','Y','N') as chx_s, - Other_MikroDetailsNote as note, - t_antibiotic.* - FROM other_mikrodetails - LEFT JOIN t_antibiotic ON Other_MikroDetailsT_AntibioticID = T_AntibioticID - WHERE - Other_MikroDetailsOther_MikroID = {$row['xid']} AND Other_MikroDetailsIsActive = 'Y' - GROUP BY Other_MikroDetailsID - ORDER BY T_AntibioticName ASC"; - //echo $sql; - $details = $this->db_smartone->query($sql)->result_array(); - if(details){ - foreach($details as $k => $v){ - $details[$k]['xno'] = $k + 1; - } - } - $row['details'] = $details; - } - else{ - $row = array('xid'=>'0','hasil_biakan' => '','result_value'=>'Negatif','sample_name' => '','orderdetail_id'=>$id, 'T_BacteriaID'=>'0','T_BacteriaName'=>'0','details'=>array(),'doctor_id'=>'0','doctor_name'=>'0'); - } - } - else{ - $row = array('xid'=>'0','hasil_biakan' => '','result_value'=>'Negatif','sample_name' => '','orderdetail_id'=>$id, 'T_BacteriaID'=>'0','T_BacteriaName'=>'0','details'=>array(),'doctor_id'=>'0','doctor_name'=>'0'); - } - //print_r($row); - - - - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 7 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $sql = " - SELECT '0' as id, 'Belum memilih bakteria' as name - UNION - SELECT T_BacteriaID as id, T_BacteriaName as name - FROM t_bacteria - WHERE - T_BacteriaIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $bacteries = $this->db_smartone->query($sql)->result_array(); - $rst = array('doctors'=>$doctors,'bacteries'=>$bacteries,'results'=>$row); - $this->sys_ok(["records"=>$rst]); - } - function getantibiotics(){ - $prm = $this->sys_input; - $id = $prm["id"]; - $sql = " SELECT '' as xno, - 0 as xid, - '' as hasil_biakan, - '' as sample_name, - 0 as value, - 'Y' as chx_r, - 'N' as chx_i, - 'N' as chx_s, - 'R' as note, - t_antibiotic.* - FROM t_antibiotic - WHERE - T_AntibioticT_BacteriaID = {$prm['id']} AND T_AntibioticIsActive= 'Y' - ORDER BY T_AntibioticName ASC"; - //echo $sql; - $rows = $this->db_smartone->query($sql)->result_array(); - if(rows){ - foreach($rows as $k => $v){ - $rows[$k]['xno'] = $k + 1; - } - } - - $this->sys_ok(["records"=>$rows]); - } - function getlcprepresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - $sql = " SELECT Other_LcprepDetailsID as xid, - Other_LcprepID as header_id, - Other_LcprepT_orderDetailID as orderdetail_id, - Other_LcprepDetailsCode as code, - Other_LcprepDetailsLabel as label, - Other_LcprepDetailsResult as result, - IFNULL(Other_LcprepM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_LcprepM_DoctorID) OR Other_LcprepM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_lcprep - JOIN other_lcprepdetails ON Other_LcprepDetailsOther_LcprepID = Other_LcprepID AND Other_LcprepDetailsIsActive = 'Y' - LEFT JOIN m_doctor ON Other_LcprepM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_LcprepT_orderDetailID = {$id} AND Other_LcprepIsActive = 'Y' - GROUP BY Other_LcprepDetailsOther_LcprepID, Other_LcprepDetailsCode - ORDER BY Other_LcprepDetailsCode ASC"; - //echo $sql; - $rows = $this->db_smartone->query($sql)->result_array(); - if(!$rows){ - $rows = array( - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'A', - 'label' => 'DESKRIPSI', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ), - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'B', - 'label' => 'KESIMPULAN', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ) - ); - } - - $header_id = $rows[0]['header_id']; - $sql = "SELECT IFNULL(Other_LcprepAdekuasiID,0) as xid, - Lcprep_AdekuasiID as id, - Lcprep_AdekuasiLabel as name, - IF(ISNULL(Other_LcprepAdekuasiID),'N',Other_LcprepAdekuasiChex) as chex - FROM lcprep_adekuasi - LEFT JOIN other_lcprepadekuasi ON Other_LcprepAdekuasiLcprep_AdekuasiID = Lcprep_AdekuasiID AND - Other_LcprepAdekuasiOther_LcprepID = {$header_id} AND - Other_LcprepAdekuasiIsActive = 'Y' - WHERE - Lcprep_AdekuasiIsActive = 'Y' - GROUP BY Lcprep_AdekuasiID - ORDER BY Lcprep_AdekuasiOrder ASC - "; - //echo $sql; - $adeakuasi = $this->db_smartone->query($sql)->result_array(); - foreach($adeakuasi as $kc => $vc){ - $adeakuasi[$kc]['chex'] = $vc['chex'] == 'N'?false:true; - } - - $sql = "SELECT IFNULL(Other_LcprepKategoriUmumID,0) as xid, - Lcprep_KategoriUmumID as id, - Lcprep_KategoriUmumLabel as name, - IF(ISNULL(Other_LcprepKategoriUmumID),'N',Other_LcprepKategoriUmumChex) as chex - FROM lcprep_kategoriumum - LEFT JOIN other_lcprepkategoriumum ON Other_LcprepKategoriUmumLcprep_KategoriUmumID = Lcprep_KategoriUmumID AND - Other_LcprepKategoriUmumOther_LcprepID = {$header_id} AND - Other_LcprepKategoriUmumIsActive = 'Y' - WHERE - Lcprep_KategoriUmumIsActive = 'Y' - GROUP BY Lcprep_KategoriUmumID - "; - //echo $sql; - $kategoriumum = $this->db_smartone->query($sql)->result_array(); - foreach($kategoriumum as $kc => $vc){ - $kategoriumum[$kc]['chex'] = $vc['chex'] == 'N'?false:true; - } - - $sql = " - SELECT Lcprep_InterpretasiGroupID as group_id, - Lcprep_InterpretasiGroupName as group_name, - '' as subgroups - FROM lcprep_interpretasigroup - WHERE - Lcprep_InterpretasiGroupIsActive = 'Y' - "; - //echo $sql; - $interpretasi = $this->db_smartone->query($sql)->result_array(); - foreach($interpretasi as $k => $v){ - $subgroups = array(); - $sql = "SELECT Lcprep_InterpretasiSubgroupID as subgroup_id, - Lcprep_InterpretasiSubgroupName as subgroup_name, - '' as childs - FROM lcprep_interpretasisubgroup - WHERE - Lcprep_InterpretasiSubgroupLcprep_InterpretasiGroupID = {$v['group_id']} AND Lcprep_InterpretasiSubgroupIsActive = 'Y'"; - //echo $sql; - $subgroups = $this->db_smartone->query($sql)->result_array(); - if(count($subgroups) > 0){ - foreach($subgroups as $ki => $vi){ - $childs = array(); - $sql = "SELECT IFNULL(Other_LcprepInterpretasiID,0) as xid, - IFNULL(Other_LcprepInterpretasiChex,'N') as chex, - IFNULL(Other_LcprepInterpretasiValue,'') as value, - Lcprep_InterpretasiID as id, - Lcprep_InterpretasiLcprep_InterpretasiSubgroupID as subgroup_id, - Lcprep_InterpretasiCode as code, - Lcprep_InterpretasiName as name, - Lcprep_InterpretasiParentID as parent_id, - Lcprep_InterpretasiIsParent as is_parent, - Lcprep_InterpretasiHasResult as has_result, - Lcprep_InterpretasiTypeResult as type_result - FROM lcprep_interpretasi - LEFT JOIN other_lcprepinterpretasi ON Other_LcprepInterpretasiOther_LcprepID = {$header_id} AND - Other_LcprepInterpretasiLcprep_InterpretasiID = Lcprep_InterpretasiID AND - Other_LcprepInterpretasiIsActive = 'Y' - WHERE - Lcprep_InterpretasiLcprep_InterpretasiSubgroupID = {$vi['subgroup_id']} AND Lcprep_InterpretasiIsActive = 'Y' - GROUP BY Lcprep_InterpretasiID Order BY Lcprep_InterpretasiCode ASC"; - $childs = $this->db_smartone->query($sql)->result_array(); - if($childs){ - foreach($childs as $kc => $vc){ - $childs[$kc]['chex'] = $vc['chex'] == 'N'?false:true; - } - } - $subgroups[$ki]['childs'] = $childs; - } - } - - $interpretasi[$k]['subgroups'] = $subgroups; - } - - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $rst = array('doctors'=>$doctors,'results'=>$rows,'adekuasi'=>$adeakuasi,'kategoriumum'=>$kategoriumum,'interpretasi'=>$interpretasi); - $this->sys_ok(["records"=>$rst]); - } - - function getpapsmearresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT Other_PapSmearDetailsID as xid, - Other_PapSmearID as header_id, - Other_PapSmearT_OrderDetailID as orderdetail_id, - Other_PapSmearDetailsCode as code, - Other_PapSmearDetailsLabel as label, - Other_PapSmearDetailsResult as result, - IFNULL(Other_PapSmearM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_PapSmearM_DoctorID) OR Other_PapSmearM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_papsmear - JOIN other_papsmeardetails ON Other_PapSmearDetailsOther_PapSmearID = Other_PapSmearID AND Other_PapSmearDetailsIsActive = 'Y' - LEFT JOIN m_doctor ON Other_PapSmearM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_PapSmearT_OrderDetailID = {$id} AND Other_PapSmearIsActive = 'Y' - GROUP BY Other_PapSmearDetailsID - ORDER BY Other_PapSmearDetailsCode ASC"; - //echo $sql; - $rows = $this->db_smartone->query($sql)->result_array(); - if(!$rows){ - $rows = array( - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'A', - 'label' => 'Makroskopik', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ), - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'B', - 'label' => 'Mikroskopik', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ), - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'C', - 'label' => 'Kesimpulan', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ) - ); - } - - $header_id = $rows[0]['header_id']; - $sql = "SELECT Other_PapSmearMaturasiID as xid, - Other_PapSmearMaturasiValue as value - FROM other_papsmearmaturasi - WHERE - Other_PapSmearMaturasiOther_PapSmearID = {$header_id} AND - Other_PapSmearMaturasiIsActive = 'Y' - "; - //echo $sql; - $dt_maturasi = $this->db_smartone->query($sql)->row_array(); - if(!$dt_maturasi){ - $maturasi = array('xid'=>'0','value'=> array('','','')); - } - else{ - $value = explode('/',$dt_maturasi['value']); - $maturasi = array('xid'=>$dt_maturasi['xid'],'value'=> $value); - } - - $sql = "SELECT IFNULL(Other_PapSmearBahanID,0) as xid, - M_PapSmearBahanID as bahan_id, - M_PapSmearBahanName as name, - IF(ISNULL(Other_PapSmearBahanID),'N','Y') as selected - FROM m_papsmearbahan - LEFT JOIN other_papsmearbahan ON Other_PapSmearBahanM_PapSmearBahanID = M_PapSmearBahanID AND - Other_PapSmearBahanOther_PapSmearID = {$header_id} AND - Other_PapSmearBahanIsActive = 'Y' - WHERE - M_PapSmearBahanIsActive = 'Y' - ORDER BY M_PapSmearBahanID ASC - "; - //echo $sql; - $bahans = $this->db_smartone->query($sql)->result_array(); - - $sql = "SELECT IFNULL(Other_PapsmearCategoryID,0) as xid, - M_PapSmearCategoryID as category_id, - M_PapSmearCategoryName as name, - IF(ISNULL(Other_PapsmearCategoryID),'N','Y') as selected - FROM m_papsmearcategory - LEFT JOIN other_papsmearcategory ON Other_PapsmearCategoryM_PapSmearCategoryID = M_PapSmearCategoryID AND - Other_PapsmearCategoryOther_PapSmearID = {$header_id} AND - Other_PapsmearCategoryIsActive = 'Y' - WHERE - M_PapSmearCategoryIsActive = 'Y' - ORDER BY M_PapSmearCategoryID ASC - "; - //echo $sql; - $categories = $this->db_smartone->query($sql)->result_array(); - - $sql = "SELECT IFNULL(Other_PapSmearCheckID,0) as xid, - M_PapSmearCheckID as check_id, - M_PapSmearCheckLabel as name, - IF(ISNULL(Other_PapSmearCheckID),'N','Y') as selected, - Other_PapSmearCheckNote as note - FROM m_papsmearcheck - LEFT JOIN other_papsmearcheck ON Other_PapSmearCheckM_PapSmearCheckID = M_PapSmearCheckID AND - Other_PapSmearCheckOther_PapSmearID = {$header_id} AND - Other_PapSmearCheckIsActive = 'Y' - WHERE - M_PapSmearCheckIsActive = 'Y' - ORDER BY M_PapSmearCheckCode ASC - "; - $checks = $this->db_smartone->query($sql)->result_array(); - - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $rst = array('doctors'=>$doctors,'checks'=>$checks,'bahans'=>$bahans,'categories'=>$categories,'maturasi'=>$maturasi,'results'=>$rows); - $this->sys_ok(["records"=>$rst]); - - } - - function saveresult_lcprep() - { - $prm = $this->sys_input; - $detail_id = $prm['detail_id']; - $doctor_id = $prm['doctor']; - $adekuasi = $prm['adekuasi']; - $kategoriumum = $prm['kategoriumum']; - $interpretasi = $prm['interpretasi']; - $results = $prm['results']; - - $userid = $this->sys_user['M_UserID']; - - $header_id = 0; - $sql = "SELECT * FROM other_lcprep WHERE Other_LcprepT_orderDetailID = {$detail_id} AND Other_LcprepIsActive = 'Y'"; - $dt_header = $this->db_smartone->query($sql)->row_array(); - if($dt_header){ - $header_id = $dt_header['Other_LcprepID']; - } - if($header_id == 0){ - $sql = "INSERT INTO other_lcprep( - Other_LcprepT_orderDetailID, - Other_LcprepM_DoctorID, - Other_LcprepUserID, - Other_LcprepCreated - ) - VALUES( - {$detail_id}, - {$doctor_id}, - {$userid}, - NOW() - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - }else{ - $sql = "UPDATE other_lcprep SET Other_LcprepM_DoctorID = {$doctor_id}, Other_LcprepUserID = {$userid} WHERE Other_LcprepID = {$header_id}"; - $this->db_smartone->query($sql); - } - - if($adekuasi){ - foreach($adekuasi as $k =>$v){ - $selected = $v['chex']?'Y':'N'; - if(intval($v['xid'] == 0)){ - $sql = "UPDATE other_lcprepadekuasi SET Other_LcprepAdekuasiIsActive = 'N' - WHERE - Other_LcprepAdekuasiOther_LcprepID = {$header_id} AND - Other_LcprepAdekuasiIsActive = 'Y' AND - Other_LcprepAdekuasiLcprep_AdekuasiID = {$v['id']}"; - $this->db_smartone->query($sql); - $sql = "INSERT INTO other_lcprepadekuasi ( - Other_LcprepAdekuasiOther_LcprepID, - Other_LcprepAdekuasiLcprep_AdekuasiID, - Other_LcprepAdekuasiChex, - Other_LcprepAdekuasiUserID, - Other_LcprepAdekuasiCreated - ) - VALUES( - {$header_id}, - {$v['id']}, - '{$selected}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - //echo $sql; - } - if(intval($v['xid'] != 0)){ - - $sql = "UPDATE other_lcprepadekuasi SET - Other_LcprepAdekuasiChex = '{$selected}', - Other_LcprepAdekuasiUserID = {$userid} - WHERE - Other_LcprepAdekuasiID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - - //echo $sql; - } - } - - if($kategoriumum){ - foreach($kategoriumum as $k =>$v){ - $selected = $v['chex']?'Y':'N'; - if(intval($v['xid'] == 0)){ - $sql = "UPDATE other_lcprepkategoriumum SET Other_LcprepKategoriUmumIsActive = 'N' - WHERE - Other_LcprepKategoriUmumOther_LcprepID = {$header_id} AND - Other_LcprepKategoriUmumLcprep_KategoriUmumID = {$v['id']} AND - Other_LcprepKategoriUmumIsActive = 'Y' - "; - $this->db_smartone->query($sql); - $sql = "INSERT INTO other_lcprepkategoriumum ( - Other_LcprepKategoriUmumOther_LcprepID, - Other_LcprepKategoriUmumLcprep_KategoriUmumID, - Other_LcprepKategoriUmumChex, - Other_LcprepKategoriUmumUserID, - Other_LcprepKategoriUmumCreated - ) - VALUES( - {$header_id}, - {$v['id']}, - '{$selected}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if(intval($v['xid'] != 0)){ - $sql = "UPDATE other_lcprepkategoriumum SET - Other_LcprepKategoriUmumChex = '{$selected }', - Other_LcprepKategoriUmumUserID = {$userid} - WHERE - Other_LcprepKategoriUmumID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - - //echo $sql; - } - } - - if($results){ - foreach($results as $k =>$v){ - if(intval($v['xid'] == 0)){ - $sql = "UPDATE other_lcprepdetails SET Other_LcprepDetailsIsActive = 'N' - WHERE - Other_LcprepDetailsOther_LcprepID = {$header_id} AND - Other_LcprepDetailsCode = '{$v['code']}' AND - Other_LcprepDetailsIsActive = 'Y'"; - $this->db_smartone->query($sql); - $sql = "INSERT INTO other_lcprepdetails ( - Other_LcprepDetailsOther_LcprepID, - Other_LcprepDetailsCode, - Other_LcprepDetailsLabel, - Other_LcprepDetailsResult, - Other_LcprepDetailsUserID, - Other_LcprepDetailsCreated - ) - VALUES( - {$header_id}, - '{$v['code']}', - '{$v['label']}', - '{$v['result']}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if(intval($v['xid'] != 0)){ - $sql = "UPDATE other_lcprepdetails SET - Other_LcprepDetailsCode = '{$v['code']}', - Other_LcprepDetailsLabel = '{$v['label']}', - Other_LcprepDetailsResult = '{$v['result']}', - Other_LcprepDetailsUserID = {$userid} - WHERE - Other_LcprepDetailsID = {$v['xid']}"; - $this->db_smartone->query($sql); - - } - //echo $sql; - } - } - - if($interpretasi){ - foreach($interpretasi as $k =>$v){ - if(count($v['subgroups']) > 0){ - foreach($v['subgroups'] as $ik => $iv){ - if(count($iv['childs']) > 0){ - foreach($iv['childs'] as $iik => $iiv){ - if(intval($iiv['xid'] == 0)){ - $chex = $iiv['chex'] ? 'Y':'N'; - $sql = "UPDATE other_lcprepinterpretasi SET Other_LcprepInterpretasiIsActive = 'N' - WHERE - Other_LcprepInterpretasiOther_LcprepID = {$header_id} AND - Other_LcprepInterpretasiLcprep_InterpretasiID = '{$iiv['id']}' AND - Other_LcprepInterpretasiIsActive = 'Y'"; - $this->db_smartone->query($sql); - $sql = "INSERT INTO other_lcprepinterpretasi ( - Other_LcprepInterpretasiOther_LcprepID, - Other_LcprepInterpretasiLcprep_InterpretasiID, - Other_LcprepInterpretasiChex, - Other_LcprepInterpretasiValue, - Other_LcprepInterpretasiUserID, - Other_LcprepInterpretasiCreated - ) - VALUES( - {$header_id}, - '{$iiv['id']}', - '{$chex}', - '{$iiv['value']}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - - if(intval($iiv['xid'] != 0)){ - $chex = $iiv['chex'] ? 'Y':'N'; - $sql = "UPDATE other_lcprepinterpretasi SET - Other_LcprepInterpretasiChex = '{$chex}', - Other_LcprepInterpretasiValue = '{$iiv['value']}', - Other_LcprepInterpretasiUserID = {$userid} - WHERE - Other_LcprepInterpretasiID = {$iiv['xid']}"; - $this->db_smartone->query($sql); - //echo $sql; - - } - - } - } - } - } - //echo $sql; - } - } - - - $result = array("total" => 1, "records" => array(), "sql"=> ''); - $this->sys_ok($result); - exit; - } - - function saveresult_papsmear() - { - $prm = $this->sys_input; - $detail_id = $prm['detail_id']; - $doctor_id = $prm['doctor']; - $checks = $prm['checks']; - $maturasi = $prm['maturasi']; - $bahans = $prm['bahans']; - $categories = $prm['categories']; - $results = $prm['results']; - - $userid = $this->sys_user['M_UserID']; - - $header_id = 0; - $sql = "SELECT * FROM other_papsmear WHERE Other_PapSmearT_OrderDetailID = {$detail_id} AND Other_PapSmearIsActive = 'Y'"; - $dt_header = $this->db_smartone->query($sql)->row_array(); - if($dt_header){ - $header_id = $dt_header['Other_PapSmearID']; - } - if($header_id == 0){ - $sql = "INSERT INTO other_papsmear( - Other_PapSmearT_OrderDetailID, - Other_PapSmearM_DoctorID, - Other_PapSmearUserID, - Other_PapSmearCreated - ) - VALUES( - {$detail_id}, - {$doctor_id}, - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } - else{ - $sql = "UPDATE other_papsmear SET Other_PapSmearM_DoctorID = {$doctor_id}, Other_PapSmearUserID = {$userid} WHERE Other_PapSmearID = {$header_id}"; - $this->db_smartone->query($sql); - } - - if($checks){ - foreach($checks as $k =>$v){ - if(intval($v['xid']) == 0 && $v['selected'] === 'Y'){ - $sql = "INSERT INTO other_papsmearcheck ( - Other_PapSmearCheckOther_PapSmearID, - Other_PapSmearCheckM_PapSmearCheckID, - Other_PapSmearCheckNote, - Other_PapSmearCheckUserID, - Other_PapSmearCheckCreated - ) - VALUES( - {$header_id}, - {$v['check_id']}, - '{$v['note']}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if(intval($v['xid']) != 0 && $v['selected'] === 'N'){ - $sql = "UPDATE other_papsmearcheck SET - Other_PapSmearCheckIsActive = 'N', - Other_PapSmearCheckUserID = {$userid} - WHERE - Other_PapSmearCheckID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - if(intval($v['xid']) != 0 && $v['selected'] === 'Y'){ - $sql = "UPDATE other_papsmearcheck SET - Other_PapSmearCheckNote = '{$v['note']}', - Other_PapSmearCheckUserID = {$userid} - WHERE - Other_PapSmearCheckID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - //echo $sql; - } - } - - if($maturasi){ - if(intval($maturasi['xid']) == 0){ - $value = join("/",$maturasi['value']); - $sql = "INSERT INTO other_papsmearmaturasi ( - Other_PapSmearMaturasiOther_PapSmearID, - Other_PapSmearMaturasiValue, - Other_PapSmearMaturasiUserID, - Other_PapSmearMaturasiCreated - ) - VALUE( - {$header_id}, - '{$value}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - //echo $sql; - } - if(intval($maturasi['xid']) != 0){ - $value = join("/",$maturasi['value']); - $sql = "UPDATE other_papsmearmaturasi SET - Other_PapSmearMaturasiValue = '{$value}', - Other_PapSmearMaturasiUserID = {$userid} - WHERE - Other_PapSmearMaturasiID = {$maturasi['xid']}"; - // echo $sql; - $this->db_smartone->query($sql); - } - } - - if($bahans){ - foreach($bahans as $k =>$v){ - if(intval($v['xid']) == 0 && $v['selected'] === 'Y'){ - $sql = "INSERT INTO other_papsmearbahan ( - Other_PapSmearBahanOther_PapSmearID, - Other_PapSmearBahanM_PapSmearBahanID, - Other_PapSmearBahanUserID, - Other_PapSmearBahanCreated - ) - VALUES( - {$header_id}, - {$v['bahan_id']}, - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if(intval($v['xid']) != 0 && $v['selected'] === 'N'){ - $sql = "UPDATE other_papsmearbahan SET - Other_PapSmearBahanIsActive = 'N', - Other_PapsmearCategoryUserID = {$userid} - WHERE - Other_PapSmearBahanID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - if(intval($v['xid']) != 0 && $v['selected'] === 'Y'){ - $sql = "UPDATE other_papsmearbahan SET - Other_PapSmearBahanIsActive = 'Y', - Other_PapsmearCategoryUserID = {$userid} - WHERE - Other_PapSmearBahanID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - //echo $sql; - } - } - - if($categories){ - foreach($categories as $k =>$v){ - if(intval($v['xid']) == 0 && $v['selected'] === 'Y'){ - $sql = "INSERT INTO other_papsmearcategory ( - Other_PapsmearCategoryOther_PapSmearID, - Other_PapsmearCategoryM_PapSmearCategoryID, - Other_PapsmearCategoryUserID, - Other_PapsmearCategoryCreated - ) - VALUES( - {$header_id}, - {$v['category_id']}, - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if(intval($v['xid']) != 0 && $v['selected'] === 'N'){ - $sql = "UPDATE other_papsmearcategory SET - Other_PapsmearCategoryIsActive = 'N', - Other_PapsmearCategoryUserID = {$userid} - WHERE - Other_PapsmearCategoryID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - //echo $sql; - if(intval($v['xid']) != 0 && $v['selected'] === 'Y'){ - $sql = "UPDATE other_papsmearcategory SET - Other_PapsmearCategoryIsActive = 'Y', - Other_PapsmearCategoryUserID = {$userid} - WHERE - Other_PapsmearCategoryID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - } - } - - if($results){ - foreach($results as $k =>$v){ - if(intval($v['xid']) == 0){ - $sql = "INSERT INTO other_papsmeardetails ( - Other_PapSmearDetailsOther_PapSmearID, - Other_PapSmearDetailsCode, - Other_PapSmearDetailsLabel, - Other_PapSmearDetailsResult, - Other_PapSmearDetailsUserID, - Other_PapSmearDetailsCreated - ) - VALUES( - {$header_id}, - '{$v['code']}', - '{$v['label']}', - '{$v['result']}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if(intval($v['xid']) != 0){ - $sql = "UPDATE other_papsmeardetails SET - Other_PapSmearDetailsCode = '{$v['code']}', - Other_PapSmearDetailsLabel = '{$v['label']}', - Other_PapSmearDetailsResult = '{$v['result']}', - Other_PapSmearDetailsUserID = {$userid} - WHERE - Other_PapSmearDetailsID = {$v['xid']}"; - $this->db_smartone->query($sql); - - } - //echo $sql; - } - } - - $result = array("total" => 1, "records" => array(), "sql"=> ''); - $this->sys_ok($result); - exit; - } - - function saveresult_fna() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = $inp['doctor']; - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - if($prm[0]['xid'] == '0'){ - $sql = "INSERT INTO other_fna( - Other_FNAM_DoctorID, - Other_FNAT_OrderDetailID, - Other_FNAUserID, - Other_FNACreated - ) - VALUES( - {$doctor_id}, - {$prm[0]['orderdetail_id']}, - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } - else{ - $sql = "SELECT * FROM other_fna WHERE Other_FNAT_OrderDetailID = {$prm[0]['orderdetail_id']} AND Other_FNAIsActive = 'Y'"; - $data_header = $this->db_smartone->query($sql)->row_array(); - $header_id = $data_header['Other_FNAID']; - $sql = "UPDATE other_fna SET - Other_FNAM_DoctorID = {$doctor_id}, - Other_FNAUserID = {$userid} - WHERE - Other_FNAID = {$header_id}"; - $this->db_smartone->query($sql); - } - foreach($prm as $k => $v){ - if($v['xid'] == '0'){ - $results = str_replace("'", "\\'", $v['result']); - $sql = "INSERT INTO other_fnadetails( - Other_FNADetailsOther_FNAID , - Other_FNADetailsCode, - Other_FNADetailsLabel, - Other_FNADetailsResult, - Other_FNADetailsCreated, - Other_FNADetailsUserID - ) - VALUES( - {$header_id}, - '{$v['code']}', - '{$v['label']}', - '{$results}', - NOW(), - {$userid} - )"; - $query = $this->db_smartone->query($sql); - } - else{ - $results = str_replace("'", "\\'", $v['result']); - $sql = "UPDATE other_fnadetails SET - Other_FNADetailsResult = '{$results}', - Other_FNADetailsUserID = {$userid} - WHERE - Other_FNADetailsID = {$v['xid']}"; - $query = $this->db_smartone->query($sql); - } - } - - $result = array("total" => 1, "records" => array(), "sql"=> ''); - $this->sys_ok($result); - exit; - } - - function saveresult_cytologi() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = $inp['doctor']; - - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - if($prm[0]['xid'] == '0'){ - $sql = "INSERT INTO other_cytologi( - Other_CytologiT_OrderDetailID, - Other_CytologiM_DoctorID, - Other_CytologiUserID, - Other_CytologiCreated - ) - VALUES( - {$prm[0]['orderdetail_id']}, - {$doctor_id}, - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } - else{ - $sql = "SELECT * FROM other_cytologi WHERE Other_CytologiT_OrderDetailID = {$prm[0]['orderdetail_id']} AND Other_CytologiIsActive = 'Y'"; - $data_header = $this->db_smartone->query($sql)->row_array(); - $header_id = $data_header['Other_CytologiID']; - $sql = "UPDATE other_cytologi SET - Other_CytologiM_DoctorID = {$doctor_id}, - Other_CytologiUserID = {$userid} - WHERE - Other_CytologiID = {$header_id}"; - $this->db_smartone->query($sql); - } - foreach($prm as $k => $v){ - if($v['xid'] == '0'){ - $results = str_replace("'", "\\'", $v['result']); - $sql = "INSERT INTO other_cytologidetails( - Other_CytologiDetailsOther_CytologiID , - Other_CytologiDetailsCode, - Other_CytologiDetailsLabel, - Other_CytologiDetailsResult, - Other_CytologiDetailsCreated, - Other_CytologiDetailsUserID - ) - VALUES( - {$header_id}, - '{$v['code']}', - '{$v['label']}', - '{$results}', - NOW(), - {$userid} - )"; - $query = $this->db_smartone->query($sql); - } - else{ - $results = str_replace("'", "\\'", $v['result']); - $sql = "UPDATE other_cytologidetails SET - Other_CytologiDetailsResult = '{$results}', - Other_CytologiDetailsUserID = {$userid} - WHERE - Other_CytologiDetailsID = {$v['xid']}"; - $query = $this->db_smartone->query($sql); - } - } - - $result = array("total" => 1, "records" => array(), "sql"=> ''); - $this->sys_ok($result); - exit; - } - - function saveresult_mikro() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = $inp['doctor']; - $backteria_id = $inp['bacteria']; - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - - if($inp['result_value'] != 'Negatif' && $inp['result_value'] != 'Positif'){ - $prm['result_value'] = $prm['result_other']; - } - else{ - $prm['result_value'] = $inp['result_value']; - } - - if($prm['xid'] == '0'){ - $sql = "INSERT INTO other_mikro( - Other_MikroM_DoctorID, - Other_MikroResult, - Other_MikroT_BacteriaID, - Other_MikroT_OrderDetailID, - Other_MikroHasilBiakan, - Other_MikroSampleTypeName, - Other_MikroUserID, - Other_MikroCreated - ) - VALUES( - {$doctor_id}, - '{$prm['result_value']}', - {$backteria_id}, - {$prm['orderdetail_id']}, - '{$prm['hasil_biakan']}', - '{$prm['sample_name']}', - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } - else{ - $sql = "SELECT * FROM other_mikro WHERE Other_MikroT_OrderDetailID = {$prm['orderdetail_id']} AND Other_MikroIsActive = 'Y'"; - $data_header = $this->db_smartone->query($sql)->row_array(); - $header_id = $data_header['Other_MikroID']; - $sql = "UPDATE other_mikro SET - Other_MikroResult = '{$prm['result_value']}', - Other_MikroM_DoctorID = {$doctor_id}, - Other_MikroT_BacteriaID = {$backteria_id}, - Other_MikroHasilBiakan = '{$prm['hasil_biakan']}', - Other_MikroSampleTypeName = '{$prm['sample_name']}', - Other_MikroUserID = {$userid} - WHERE - Other_MikroID = {$header_id}"; - //echo $sql; - $this->db_smartone->query($sql); - } - - - - $sql = "UPDATE other_mikrodetails SET Other_MikroDetailsIsActive = 'N', Other_MikroDetailsUserID = 0 WHERE Other_MikroDetailsOther_MikroID = {$header_id}"; - $this->db_smartone->query($sql); - - $results = $prm['details']; - if($inp['result_value'] == 'Positif'){ - foreach($results as $k => $v){ - if($v['xid'] == '0'){ - $sql = "INSERT INTO other_mikrodetails( - Other_MikroDetailsOther_MikroID , - Other_MikroDetailsT_AntibioticID, - Other_MikroDetailsValue, - Other_MikroDetailsNote, - Other_MikroDetailsCreated, - Other_MikroDetailsUserID - ) - VALUES( - {$header_id}, - '{$v['T_AntibioticID']}', - '{$v['value']}', - '{$v['note']}', - NOW(), - {$userid} - )"; - $query = $this->db_smartone->query($sql); - } - else{ - $sql = "UPDATE other_mikrodetails SET - Other_MikroDetailsT_AntibioticID = '{$v['T_AntibioticID']}', - Other_MikroDetailsValue = '{$v['value']}', - Other_MikroDetailsNote = '{$v['note']}', - Other_MikroDetailsIsActive = 'Y', - Other_MikroDetailsUserID = {$userid} - WHERE - Other_MikroDetailsID = {$v['xid']}"; - //echo $sql; - $query = $this->db_smartone->query($sql); - } - } - } - - - $result = array("total" => 1, "records" => array(), "sql"=> ''); - $this->sys_ok($result); - exit; - } - - - function get_doctors_preparasi_sperma() - { - $prm = $this->sys_input; - // $id = $prm["id"]; - - $sql = " SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 10 AND - M_DoctorSOIsActive = 'Y' - ORDER BY M_DoctorName ASC"; - //echo $sql; - $query = $this->db_smartone->query($sql); - $rows = $query->result_array(); - $sql = " - SELECT '0' as id, 'Belum memilih metode' as name - UNION - SELECT M_MethodeSpermaID as id, M_MethodeSpermaName as name - FROM m_methodesperma - WHERE - M_MethodeSpermaIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $methodes = $this->db_smartone->query($sql)->result_array(); - - - $this->sys_ok(["records"=>$rows,"methodes"=>$methodes]); - - } - - - function getpreparasispermaresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT other_preparasisperma.*, - Other_PreparasiSpermaID as xid, - Other_PreparasiSpermaT_OrderDetailID as orderdetail_id, - IFNULL(Other_PreparasiSpermaM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_PreparasiSpermaM_DoctorID) OR Other_PreparasiSpermaM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name, - IFNULL(M_MethodeSpermaID,0) as methode_id, - IFNULL(M_MethodeSpermaName,'') as methode_name - FROM other_preparasisperma - LEFT JOIN m_doctor ON Other_PreparasiSpermaM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - LEFT JOIN m_methodesperma ON Other_PreparasiSpermaM_MethodeSpermaID = M_MethodeSpermaID AND - M_MethodeSpermaIsActive = 'Y' - WHERE - Other_PreparasiSpermaT_OrderDetailID = {$id} AND Other_PreparasiSpermaIsActive = 'Y' - GROUP BY Other_PreparasiSpermaID"; - $query = $this->db_smartone->query($sql); - - if ($query) - { - $rows = $query->row_array(); - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 10 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $sql = " - SELECT '0' as id, 'Belum memilih metode' as name - UNION - SELECT M_MethodeSpermaID as id, M_MethodeSpermaName as name - FROM m_methodesperma - WHERE - M_MethodeSpermaIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $methodes = $this->db_smartone->query($sql)->result_array(); - $images = array(); - $sql = "SELECT Other_PreparasiSpermaImgID as xid, - Other_PreparasiSpermaImgType as type, - CONCAT('/one-media/one-image-nonlab/',Other_PreparasiSpermaImgNewName) as image_url - FROM t_orderdetail - JOIN other_preparasisperma_img ON Other_PreparasiSpermaImgT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND - Other_PreparasiSpermaImgIsActive = 'Y' - WHERE - T_OrderDetailID = {$id} AND - T_OrderDetailIsActive = 'Y' - GROUP BY Other_PreparasiSpermaImgID"; - //echo $sql; - $images = $this->db_smartone->query($sql)->result_array(); - - $rst = array('doctors'=>$doctors,'methodes'=>$methodes,'results'=>$rows,'images'=>$images); - $this->sys_ok(["records"=>$rst]); - } - else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - - function uploadimage_preparasi_sperma(){ - if (! $this->isLogin) { - $this->sys_error("Invalid Token"); - exit; - } - - $userid = $this->sys_user["M_UserID"]; - $data = []; - //print_r($_SERVER); - - $prm = $this->sys_input; - $orderid = $this->input->post('orderid'); - $type = $this->input->post('type'); - $labnumber = $this->input->post('labnumber'); - $sql = "UPDATE other_preparasisperma_img SET - Other_PreparasiSpermaImgIsActive = 'N', - Other_PreparasiSpermaImgUserID = {$userid} - WHERE - Other_PreparasiSpermaImgT_OrderHeaderID = {$orderid} AND - Other_PreparasiSpermaImgType = '{$type}'"; - //echo $sql; - $this->db_onedev->query($sql); - //$config['upload_path'] = 'assets/'; - - $path = '/home/one/project/one/one-media/one-image-nonlab/'; - //echo $path; - $config['upload_path'] = $path; - $config['allowed_types'] = 'jpg|jpeg|png|gif'; - - $config['max_size'] = '10000'; - $count = count($_FILES['files']['name']); - //echo $count; - $this->load->library('upload',$config); - - $error = []; - for($i=0;$i<$count;$i++){ - - - if(!empty($_FILES['files']['name'][$i])){ - - - - $_FILES['file']['name'] = $_FILES['files']['name'][$i]; - - $_FILES['file']['type'] = $_FILES['files']['type'][$i]; - - $_FILES['file']['tmp_name'] = $_FILES['files']['tmp_name'][$i]; - - $_FILES['file']['error'] = $_FILES['files']['error'][$i]; - - $_FILES['file']['size'] = $_FILES['files']['size'][$i]; - - - - $namex = $orderid.'-'.$labnumber.'-'.$this->generateRandomString(5); - //echo $namex; - - $config['file_name'] = $namex; - $this->upload->initialize($config); - //echo $config['file_name'] ; - - - - - - if($this->upload->do_upload('file')){ - - $uploadData = $this->upload->data(); - - $filename = $uploadData['file_name']; - //echo $filename; - - - $sql = "INSERT INTO other_preparasisperma_img ( - Other_PreparasiSpermaImgT_OrderHeaderID, - Other_PreparasiSpermaImgType, - Other_PreparasiSpermaImgOldName, - Other_PreparasiSpermaImgNewName, - Other_PreparasiSpermaImgCreated, - Other_PreparasiSpermaImgUserID - ) - VALUES( - {$orderid}, - '{$type}', - '{$_FILES['files']['name'][$i]}', - '{$filename}', - NOW(), - {$userid} - - )"; - //echo $sql; - $this->db_onedev->query($sql); - $xlast_id = $this->db_onedev->insert_id(); - $data['totalFiles'][] = array('xid' => $xlast_id ,'type'=>$type,'image_url' => '/one-media/one-image-nonlab/'.$filename); - - } - else{ - $error = array('error' => $this->upload->display_errors()); - } - - } - - - - } - - $result = array("total" =>count( $data['totalFiles']), "records" => $data['totalFiles'],'errors'=>$error); - $this->sys_ok($result); - } - - - function saveresult_preparasi_sperma() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = $inp['doctor']; - $orderdetail_id = $inp['orderdetailid']; - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - if($prm['xid'] == '0'){ - $sql = "INSERT INTO other_preparasisperma( - Other_PreparasiSpermaM_DoctorID, - Other_PreparasiSpermaT_OrderDetailID, - Other_PreparasiSpermaPreMotilitasA, - Other_PreparasiSpermaPreMotilitasB, - Other_PreparasiSpermaPreMotilitasC, - Other_PreparasiSpermaPreKonsentrasi, - Other_PreparasiSpermaPreKontaminan, - Other_PreparasiSpermaPostMotilitasA, - Other_PreparasiSpermaPostMotilitasB, - Other_PreparasiSpermaPostMotilitasC, - Other_PreparasiSpermaPostKonsentrasi, - Other_PreparasiSpermaPostKontaminan, - Other_PreparasiSpermaPreVolume, - Other_PreparasiSpermaPostVolume, - Other_PreparasiSpermaM_MethodeSpermaID, - Other_PreparasiSpermaNote, - Other_PreparasiSpermaUserID, - Other_PreparasiSpermaCreated - ) - VALUES( - {$doctor_id}, - {$orderdetail_id}, - '{$prm['Other_PreparasiSpermaPreMotilitasA']}', - '{$prm['Other_PreparasiSpermaPreMotilitasB']}', - '{$prm['Other_PreparasiSpermaPreMotilitasC']}', - '{$prm['Other_PreparasiSpermaPreKonsentrasi']}', - '{$prm['Other_PreparasiSpermaPreKontaminan']}', - '{$prm['Other_PreparasiSpermaPostMotilitasA']}', - '{$prm['Other_PreparasiSpermaPostMotilitasB']}', - '{$prm['Other_PreparasiSpermaPostMotilitasC']}', - '{$prm['Other_PreparasiSpermaPostKonsentrasi']}', - '{$prm['Other_PreparasiSpermaPostKontaminan']}', - '{$prm['Other_PreparasiSpermaPreVolume']}', - '{$prm['Other_PreparasiSpermaPostVolume']}', - '{$prm['Other_PreparasiSpermaM_MethodeSpermaID']}', - '{$prm['Other_PreparasiSpermaNote']}', - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } - else{ - $sql = "SELECT * FROM other_preparasisperma WHERE Other_PreparasiSpermaT_OrderDetailID = {$orderdetail_id} AND Other_PreparasiSpermaIsActive = 'Y'"; - $data_header = $this->db_smartone->query($sql)->row_array(); - $header_id = $data_header['Other_PreparasiSpermaID']; - $sql = "UPDATE other_preparasisperma SET - Other_PreparasiSpermaM_DoctorID = {$doctor_id}, - Other_PreparasiSpermaPreMotilitasA = '{$prm['Other_PreparasiSpermaPreMotilitasA']}', - Other_PreparasiSpermaPreMotilitasB = '{$prm['Other_PreparasiSpermaPreMotilitasB']}', - Other_PreparasiSpermaPreMotilitasC = '{$prm['Other_PreparasiSpermaPreMotilitasC']}', - Other_PreparasiSpermaPreKonsentrasi = '{$prm['Other_PreparasiSpermaPreKonsentrasi']}', - Other_PreparasiSpermaPreKontaminan = '{$prm['Other_PreparasiSpermaPreKontaminan']}', - Other_PreparasiSpermaPostMotilitasA = '{$prm['Other_PreparasiSpermaPostMotilitasA']}', - Other_PreparasiSpermaPostMotilitasB = '{$prm['Other_PreparasiSpermaPostMotilitasB']}', - Other_PreparasiSpermaPostMotilitasC = '{$prm['Other_PreparasiSpermaPostMotilitasC']}', - Other_PreparasiSpermaPostKonsentrasi = '{$prm['Other_PreparasiSpermaPostKonsentrasi']}', - Other_PreparasiSpermaPostKontaminan = '{$prm['Other_PreparasiSpermaPostKontaminan']}', - Other_PreparasiSpermaPreVolume = '{$prm['Other_PreparasiSpermaPreVolume']}', - Other_PreparasiSpermaPostVolume = '{$prm['Other_PreparasiSpermaPostVolume']}', - Other_PreparasiSpermaM_MethodeSpermaID = '{$prm['Other_PreparasiSpermaM_MethodeSpermaID']}', - Other_PreparasiSpermaNote = '{$prm['Other_PreparasiSpermaNote']}', - Other_PreparasiSpermaUserID = {$userid} - WHERE - Other_PreparasiSpermaID = {$header_id}"; - $this->db_smartone->query($sql); - } - - - $result = array("total" => 1, "records" => array(), "sql"=> ''); - $this->sys_ok($result); - exit; - } - - function getdnafragmentasiresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT other_dnafragmentasi.*, - Other_DnaFragmentasiID as xid, - Other_DnaFragmentasiT_OrderDetailID as orderdetail_id, - IFNULL(Other_DnaFragmentasiM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_DnaFragmentasiM_DoctorID) OR Other_DnaFragmentasiM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name, - IFNULL(Other_DnaFragmentasiOther_DnaFragmentasiMethodeID,0) as methode_id, - IFNULL(Other_DnaFragmentasiMethodeName,'') as methode_name, - Other_DnaFragmentasiHaloLuas as halo_luas, - Other_DnaFragmentasiHaloSedang as halo_sedang, - Other_DnaFragmentasiHaloSempit as halo_sempit, - Other_DnaFragmentasiTanpaHalo as tanpa_halo, - Other_DnaFragmentasiDFI as dfi, - Other_DnaFragmentasiKesimpulan as kesimpulan, - Other_DnaFragmentasiCatatan as catatan - FROM other_dnafragmentasi - LEFT JOIN m_doctor ON Other_DnaFragmentasiM_DoctorID = M_DoctorID - LEFT JOIN other_dnafragmentasimethode ON Other_DnaFragmentasiOther_DnaFragmentasiMethodeID = Other_DnaFragmentasiMethodeID - WHERE - Other_DnaFragmentasiT_OrderDetailID = {$id} AND Other_DnaFragmentasiIsActive = 'Y' - GROUP BY Other_DnaFragmentasiID - LIMIT 1"; - //echo $sql; - $query = $this->db_smartone->query($sql); - - if ($query) - { - $rows = $query->row_array(); - if(!$rows){ - $rows = array( - 'xid' => 0, - 'orderdetail_id' =>$id, - 'doctor_id' => 0, - 'doctor_name' => '', - 'methode_id' => 0, - 'methode_name' => '', - 'halo_luas' => '', - 'halo_sedang' => '', - 'tanpa_halo' => '', - 'dfi' => '', - 'kesimpulan' => '', - 'catatan' => '' - ); - } - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID - WHERE - M_DoctorSONat_SubGroupID = 4 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - - $sql = " - SELECT '0' as id, 'Belum memilih metode' as name - UNION - SELECT Other_DnaFragmentasiMethodeID as id, Other_DnaFragmentasiMethodeName as name - FROM other_dnafragmentasimethode - WHERE - Other_DnaFragmentasiMethodeIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $methodes = $this->db_smartone->query($sql)->result_array(); - - - $rst = array('doctors'=>$doctors,'methodes'=>$methodes,'results'=>$rows); - $this->sys_ok(["records"=>$rst]); - } - else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - function saveresult_dnafragmentasi() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = $inp['doctor']['id']; - $methode_id = $inp['methode']['id']; - $orderdetail_id = $inp['results']['orderdetail_id']; - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - if(intval($prm['xid']) == 0){ - $sql = "INSERT INTO other_dnafragmentasi( - Other_DnaFragmentasiT_OrderDetailID, - Other_DnaFragmentasiM_DoctorID, - Other_DnaFragmentasiOther_DnaFragmentasiMethodeID, - Other_DnaFragmentasiHaloLuas, - Other_DnaFragmentasiHaloSedang, - Other_DnaFragmentasiHaloSempit, - Other_DnaFragmentasiTanpaHalo, - Other_DnaFragmentasiDFI, - Other_DnaFragmentasiKesimpulan, - Other_DnaFragmentasiCatatan, - Other_DnaFragmentasiUserID, - Other_DnaFragmentasiLastUpdated - ) - VALUES( - {$orderdetail_id}, - {$doctor_id}, - {$methode_id}, - '{$prm['halo_luas']}', - '{$prm['halo_sedang']}', - '{$prm['halo_sempit']}', - '{$prm['tanpa_halo']}', - '{$prm['dfi']}', - '{$prm['kesimpulan']}', - '{$prm['catatan']}', - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } - else{ - $sql = "UPDATE other_dnafragmentasi SET - Other_DnaFragmentasiT_OrderDetailID = {$orderdetail_id}, - Other_DnaFragmentasiM_DoctorID = {$doctor_id}, - Other_DnaFragmentasiOther_DnaFragmentasiMethodeID = '{$methode_id}', - Other_DnaFragmentasiHaloLuas = '{$prm['halo_luas']}', - Other_DnaFragmentasiHaloSedang = '{$prm['halo_sedang']}', - Other_DnaFragmentasiHaloSempit = '{$prm['halo_sempit']}', - Other_DnaFragmentasiTanpaHalo = '{$prm['tanpa_halo']}', - Other_DnaFragmentasiDFI = '{$prm['dfi']}', - Other_DnaFragmentasiKesimpulan = '{$prm['kesimpulan']}', - Other_DnaFragmentasiCatatan = '{$prm['catatan']}', - Other_DnaFragmentasiLastUpdated = NOW(), - Other_DnaFragmentasiUserID = {$userid} - WHERE - Other_DnaFragmentasiID = {$prm['xid']}"; - //echo $sql; - $this->db_smartone->query($sql); - } - - - $result = array("total" => 1, "records" => array(), "sql"=> ''); - $this->sys_ok($result); - exit; - } - - -} - +db_smartone = $this->load->database("onedev", true); + $this->load->helper(array('form', 'url')); + } + function getMethodeID($natTestID) { + $sql = "select M_MethodePriorityNat_MethodeID MethodeID, Nat_MethodeName + from + m_methode_priority + join nat_methode on Nat_MethodeID = M_MethodePriorityNat_MethodeID + and Nat_MethodeIsActive = 'Y' + join m_instrumentmethode on M_InstrumentMethodeNat_MethodeID = Nat_MethodeID and M_InstrumentMethodeIsActive = 'Y' + join nat_instrument on M_InstrumentMethodeNat_InstrumentID = Nat_InstrumentID + and Nat_InstrumentIsActive ='Y' + where M_MethodePriorityIsActive = 'Y' + and M_MethodePriorityNat_TestID = $natTestID + and M_MethodePriorityM_DayOfWeekID = dayofweek(now()) + order by M_MethodePriorityNumber desc + limit 0,1 "; + $qry = $this->db->query($sql); + if ($qry) { + $rows = $qry->result_array(); + if (count($rows) > 0 ) return array($rows[0]["MethodeID"],$rows[0]["Nat_MethodeName"]); + } + //2nd + $sql= "select + M_InstrumentMethodeNat_MethodeID MethodeID, Nat_MethodeName + from m_instrumentmethode + join nat_methode on M_InstrumentMethodeNat_MethodeID = Nat_MethodeID + and Nat_MethodeIsActive = 'Y' + join nat_instrument on M_InstrumentMethodeNat_InstrumentID = Nat_InstrumentID + and Nat_InstrumentIsActive ='Y' + where M_InstrumentMethodeNat_TestID = $natTestID + and M_InstrumentMethodeIsActive = 'Y' + order by M_InstrumentMethodePriority desc + limit 0,1"; + $qry = $this->db->query($sql); + if ($qry) { + $rows = $qry->result_array(); + if (count($rows) > 0 ) return array($rows[0]["MethodeID"],$rows[0]["Nat_MethodeName"]); + } + // + $sql = "select Nat_NormalValueNat_MethodeID MethodeID, Nat_MethodeName + from + nat_normalvalue + join nat_methode on Nat_NormalValueNat_MethodeID = Nat_MethodeID + and Nat_MethodeIsActive = 'Y' + where Nat_NormalValueNat_TestID = $natTestID + and Nat_NormalValueIsActive = 'Y' + order by Nat_NormalValueID + limit 0,1"; + $qry = $this->db->query($sql); + if ($qry) { + $rows = $qry->result_array(); + if (count($rows) > 0 ) return array($rows[0]["MethodeID"],$rows[0]["Nat_MethodeName"]); + } + return array(0,""); + } + function get_normal_value($methodeID, $natTestID, $sexID, $ageInDay ) { + $this->load->library('ibl_sampling_normal'); + return $this->ibl_sampling_normal->get_normal_value_id($methodeID, $natTestID, $sexID, $ageInDay); + } + return 0; + } + function fn_fix_normal($order_id) { + $sql = "select + T_OrderDetailID, M_PatientM_SexID, fn_global_age_count_day(M_PatientDOB, date(T_OrderHeaderDate)) Dob , + T_TestNat_TestID + from t_orderheader + join m_patient on T_OrderHeaderID = $order_id and T_OrderHeaderM_PatientID = M_PatientID + join t_orderdetail on T_OrderDetailT_OrderHeaderID = T_OrderHeaderID + and T_OrderDetailIsACtive = 'Y' + and ( T_OrderDetailNat_NormalValueID is null or T_OrderDetailNat_NormalValueID = 0 ) + join t_test on T_OrderDetailT_TestID = T_TestID and T_TestIsResult = 'Y' "; + $qry = $this->db->query($sql); + if(! $qry) { + return; + } + $rows = $qry->result_array(); + if(count($rows) == 0 ) return; + $sql_u = "update t_orderdetail + join nat_normalvalue on T_OrderDetailID = ? and Nat_NormalValueID = ? + set + T_OrderDetailNat_NormalValueID = Nat_NormalValueID, + T_OrderDetailNormalValueNote = Nat_NormalValueNote, + T_OrderDetailNormalValueDescription = Nat_NormalValueDescription, + T_OrderDetailMinValue = Nat_NormalValueMinValue, + T_OrderDetailMaxValue = Nat_NormalValueMaxValue, + T_OrderDetailMinValueInclusive = Nat_NormalValueMinValueInclusive, + T_OrderDetailMaxValueInclusive = Nat_NormalValueMaxValueInclusive, + T_OrderDetailNat_MethodeID = ?, + T_OrderdetailNat_MethodeName =?"; + + foreach($rows as $r) { + $T_OrderDetailID = $r["T_OrderDetailID"]; + $sexID = $r["M_PatientM_SexID"]; + $ageInDay = $r["Dob"]; + $natTestID = $r["T_TestNat_TestID"]; + list($methodeID,$methodeName) = $this->getMethodeID($natTestID); + if ($methodeID == 0 ) continue; + $normalValueID = $this->get_normal_value($methodeID, $natTestID, $sexID, $ageInDay); + if ($normalValueID == 0) return; + $this->db->query($sql_u, array($T_OrderDetailID, $normalValueID, $methodeID, $methodeName)); + } + } + function update_order_sample($targetID, $sourceID) { + $sql = "update t_ordersample target + join t_ordersample source on + target.T_OrderSampleID = ? + and target.T_OrderSampleWorklistReceive = 'N' + and source.T_OrderSampleID = ? + set + target.T_OrderSampleSampling = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSampling, source.T_OrderSampleSampling), + target.T_OrderSampleSamplingDate = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingDate, source.T_OrderSampleSamplingDate), + target.T_OrderSampleSamplingTime = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingTime, source.T_OrderSampleSamplingTime), + target.T_OrderSampleSamplingUserID = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingUserID, source.T_OrderSampleSamplingUserID), + + target.T_OrderSampleReceive = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceive, source.T_OrderSampleReceive), + target.T_OrderSampleReceiveDate = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveDate, source.T_OrderSampleReceiveDate), + target.T_OrderSampleReceiveTime = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveTime, source.T_OrderSampleReceiveTime), + target.T_OrderSampleReceiveUserID = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveUserID, source.T_OrderSampleReceiveUserID), + + target.T_OrderSampleVerification = if(target.T_OrderSampleVerification='Y',target.T_OrderSampleVerification, source.T_OrderSampleVerification), + target.T_OrderSampleVerificationDate =if(target.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationDate, source.T_OrderSampleVerificationDate), + target.T_OrderSampleVerificationTime =if(source.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationTime, source.T_OrderSampleVerificationTime), + target.T_OrderSampleVerificationUserID =if(source.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationUserID, source.T_OrderSampleVerificationUserID), + + target.T_OrderSampleProcessing = if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessing, source.T_OrderSampleProcessing), + target.T_OrderSampleProcessingDate= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingDate, source.T_OrderSampleProcessingDate), + target.T_OrderSampleProcessingTime= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingTime, source.T_OrderSampleProcessingTime), + target.T_OrderSampleProcessingUserID= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingUserID, source.T_OrderSampleProcessingUserID), + + target.T_OrderSampleReceiveHandling =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandling, source.T_OrderSampleReceiveHandling ), + target.T_OrderSampleReceiveHandlingDate =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingDate, source.T_OrderSampleReceiveHandlingDate), + target.T_OrderSampleReceiveHandlingTime =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingTime, source.T_OrderSampleReceiveHandlingTime), + target.T_OrderSampleReceiveHandlingUserID =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingUserID, source.T_OrderSampleReceiveHandlingUserID), + + target.T_OrderSampleHandling = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandling, source.T_OrderSampleHandling), + target.T_OrderSampleHandlingDate = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingDate, source.T_OrderSampleHandlingDate), + target.T_OrderSampleHandlingTime = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingTime, source.T_OrderSampleHandlingTime), + target.T_OrderSampleHandlingUserID = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingUserID, source.T_OrderSampleHandlingUserID), + + target.T_OrderSampleWorklistReceive = source.T_OrderSampleWorklistReceive, + target.T_OrderSampleWorklistReceiveDatetime = source.T_OrderSampleWorklistReceiveDateTime, + target.T_OrderSampleWorklistReceiveUserID = source.T_OrderSampleWorklistReceiveUserID + "; + $qry = $this->db->query($sql,array($targetID,$sourceID)); + if(! $qry ) { + echo json_encode(array( "status" => "ERR" , "message" => print_r($this->db->error(),true))); + exit; + } + } + function fix_sample_serum($headerID) { + //cari t_ordersample yg belum worklist receive dengan code 017% + $sql = "select T_OrderSampleID + from t_ordersample + join t_sampletype on + T_OrderSampleT_OrderHeaderID = ? + and T_OrderSampleWorklistReceive = 'N' + and T_OrderSampleIsActive = 'Y' + and T_OrderSampleT_SampleTypeID = T_SampletypeID + and T_SampleTypeCode like '017%' + "; + $qry = $this->db->query($sql, array($headerID)); + if(!$qry) { + echo json_encode(array( "status" => "ERR" , "message" => print_r($this->db->error(),true))); + exit; + } + $rows = $qry->result_array(); + if (count($rows) == 0 ) return; + //cari T_OrderSample yang sudah di receive yg terakhir + $sql = "select T_OrderSampleID + from t_ordersample + join t_sampletype on + T_OrderSampleT_OrderHeaderID = ? + and T_OrderSampleWorklistReceive = 'Y' + and T_OrderSampleIsActive = 'Y' + and T_OrderSampleT_SampleTypeID = T_SampletypeID + and T_SampleTypeCode like '017%' + order by T_OrderSampleWorklistReceiveDatetime desc + limit 0,1 + "; + $qry = $this->db->query($sql, array($headerID)); + if(!$qry) { + echo json_encode(array( "status" => "ERR" , "message" => print_r($this->db->error(),true))); + exit; + } + $rcv_rows = $qry->result_array(); + if (count($rcv_rows) == 0 ) return; + + //print_r($rows); + //print_r($rcv_rows); + $rcv_T_OrderSampleID = $rcv_rows[0]["T_OrderSampleID"]; + //ada yg belum di receive + foreach($rows as $r) { + $T_OrderSampleID = $r["T_OrderSampleID"]; + $this->update_order_sample($T_OrderSampleID,$rcv_T_OrderSampleID); + } + } + public function search() + { + $prm = $this->sys_input; + $max_rst = 99; + + $id = $prm["order_id"]; + if ($id > 0 ) { + $this->fix_sample_serum($id); + $this->fn_fix_normal($id); + } + $lang = $this->lang_default_code; + $lang_id = isset($prm['lang_id']) ? $prm['lang_id'] : '0'; + + if ($lang_id != 0) + { + $l = $this->db_smartone->where("Nat_LangID", $lang_id)->get("nat_lang")->row(); + $lang = $l->Nat_LangCode; + } + + //tambahan fajri + $sql = " UPDATE t_orderdetail + JOIN t_test ON T_OrderDetailT_TestID = T_TestID + SET T_OrderDetailT_TestIsResult = T_TestIsResult + WHERE + T_OrderDetailT_OrderHeaderID = {$id} AND + T_OrderDetailT_TestIsResult = '' AND + T_OrderDetailIsActive = 'Y'"; + $this->db_smartone->query($sql); + + $tot_count = 0; + $lq = ""; + $group_id = 0; + if (isset($prm['group_id'])) + $group_id = $prm['group_id']; + + if ($group_id != 0) + { + $sql = "select distinct T_WorklistDetailNat_TestID Nat_TestID + from t_worklistdetailv2 + where T_WorklistDetailT_WorklistID = {$group_id}"; + $qry = $this->db_smartone->query($sql); + $rows = $qry->result_array(); + $nat_test_ids = "0"; + foreach($rows as $r) { + $nat_test_ids .= ", " . $r["Nat_TestID"]; + } + $q_group = " ( $nat_test_ids ) "; + + $sql = " + SELECT a1.*, cOUNT(a2.T_OrderDetailID) level + FROM ( + SELECT IFNULL(y.T_OrderDetailT_TestID, x.T_OrderDetailT_TestID) t_testid, + IFNULL(y.T_OrderDetailT_TestName, y.T_OrderDetailT_TestName) t_testname, + y.T_OrderDetailResult result, y.T_OrderDetailResult result_old, y.T_OrderDetailNote note, y.T_OrderDetailNote note_old, + y.T_OrderDetailID id, + y.T_OrderDetailT_TestIsResult is_result, a.T_TestIsQuantitative is_quantitative, + y.T_OrderDetailResultFlag result_flag, + y.T_OrderDetailNat_NormalValueID normal_id, + y.T_OrderDetailNormalValueNote normal_note, y.T_OrderDetailNat_UnitName unit_name, + y.T_OrderdetailNat_MethodeID methode_id, y.T_OrderdetailNat_MethodeName methode_name, + a.T_TestNat_TestID nattest_id, a.T_TestID tx_id, count(T_ResultInstrumentID) as result_instrument_n, + y.T_OrderDetailVerification, T_OrderSampleReceive sample_receive, + T_OrderSampleProcessing sample_processing, T_OrderSampleWorklistReceive sample_worklist_receive, + IF(T_OrderDetailAddOnPreAnalytic = 'Y', T_OrderDetailAddOnPreAnalytic, PreAnalyticIsOk) pre_analytic, + T_OrderDetailAddOnPreAnalytic, + T_OrderHeaderID order_id, y.T_OrderDetailT_TestSasCode test_sas_code, + tx.T_TestSasCode, + T_OrderDetailAddOnResample `resample`, T_OrderDetailAddOnResampleStatus resample_status, + T_OrderDetailAddOnRef ref, y.T_OrderDetailVerification verification, y.T_OrderDetailValidation validation, + T_OrderPromiseDateTime, Group_ResultName as ResultGroupName + FROM t_orderdetail x + left join t_orderpromise on x.T_OrderDetailT_OrderPromiseID = T_OrderPromiseID + JOIN t_test tx ON x.T_OrderDetailT_TestID = T_TestID + JOIN t_test tcheck on tcheck.T_TestNat_TestID in {$q_group} + and ( tx.T_TestID = tcheck.T_TestID or tx.T_TestSasCode like concat(tcheck.T_TestSasCode,'%')) + LEFT JOIN group_resultdetail ON Group_ResultDetailT_TestID = x.T_OrderDetailT_TestID AND Group_ResultDetailIsActive = 'Y' + LEFT JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND Group_ResultFlagNonLab = 'N' + LEFT JOIN t_orderdetail y ON x.T_OrderDetailT_TestSasCode LIKE CONCAT(y.T_OrderDetailT_TestSasCode, '%') + AND x.T_OrderDetailT_OrderHeaderID = y.T_OrderDetailT_OrderHeaderID + AND y.T_OrderDetailIsActive = 'Y' + LEFT JOIN t_orderdetailaddon ON x.T_OrderDetailID = T_OrderDetailAddOnT_OrderDetailID + JOIN t_orderheader ON y.T_OrderDetailT_OrderHeaderID = T_OrderHeaderID + LEFT JOIN t_test a ON y.T_OrderDetailT_TestID = a.T_TestID + AND a.T_TestIsNonLab = '' + LEFT JOIN (SELECT T_OrderSampleT_SampleTypeID, T_OrderSampleReceive, T_OrderSampleProcessing, T_OrderSampleWorklistReceive + FROM t_ordersample WHERE T_OrderSampleT_OrderHeaderID = {$id} + AND T_OrderSampleIsactive = 'Y' + GROUP BY T_OrderSampleT_SampleTypeID) os ON a.T_TestT_SampleTypeID = os.T_OrderSampleT_SampleTypeID + or os.T_OrderSampleT_SampleTypeID = fn_sampletype_from_local(a.T_TestNat_TestID) + + LEFT JOIN t_resultinstrument ON T_ResultInstrumentT_OrderDetailID = x.T_OrderDetailID + LEFT JOIN pre_analytic ON PreAnalyticNat_TestID = a.T_TestNat_TestID AND PreAnalyticDate = date(now()) and PreAnalyticIsActive = 'Y' + WHERE x.T_OrderDetailT_OrderHeaderID = {$id} + AND x.T_OrderDetailIsActive = 'Y' + GROUP BY y.T_OrderDetailT_TestID + ORDER BY y.T_OrderDetailT_TestSasCode ASC + ) a1 + + LEFT JOIN t_orderdetail a2 ON a2.T_OrderDetailT_OrderHeaderID = a1.order_id + AND a2.T_OrderDetailIsActive = 'Y' + AND a1.test_sas_code LIKE CONCAT(a2.T_OrderDetailT_testSasCode, '%') + GROUP BY a1.t_testid + order by a1.test_sas_code +"; + $query = $this->db_smartone->query($sql); + $lq = $this->db_smartone->last_query(); + } + else + { + $sql = " + SELECT a1.*, cOUNT(a2.T_OrderDetailID) level + FROM ( + SELECT IFNULL(y.T_OrderDetailT_TestID, x.T_OrderDetailT_TestID) t_testid, + IFNULL(y.T_OrderDetailT_TestName, y.T_OrderDetailT_TestName) t_testname, + y.T_OrderDetailResult result, y.T_OrderDetailResult result_old, y.T_OrderDetailNote note, y.T_OrderDetailNote note_old, + y.T_OrderDetailID id, + y.T_OrderDetailT_TestIsResult is_result, a.T_TestIsQuantitative is_quantitative, + y.T_OrderDetailResultFlag result_flag, + y.T_OrderDetailNat_NormalValueID normal_id, + y.T_OrderDetailNormalValueNote normal_note, y.T_OrderDetailNat_UnitName unit_name, + y.T_OrderdetailNat_MethodeID methode_id, y.T_OrderdetailNat_MethodeName methode_name, + a.T_TestNat_TestID nattest_id, a.T_TestID tx_id, count(T_ResultInstrumentID) as result_instrument_n, + y.T_OrderDetailVerification, T_OrderSampleReceive sample_receive, + T_OrderSampleProcessing sample_processing, T_OrderSampleWorklistReceive sample_worklist_receive, + IF(T_OrderDetailAddOnPreAnalytic = 'Y', T_OrderDetailAddOnPreAnalytic, PreAnalyticIsOk) pre_analytic, + T_OrderDetailAddOnPreAnalytic, + T_OrderHeaderID order_id, y.T_OrderDetailT_TestSasCode test_sas_code, + tx.T_TestSasCode, + T_OrderDetailAddOnResample `resample`, T_OrderDetailAddOnResampleStatus resample_status, + T_OrderDetailAddOnRef ref, y.T_OrderDetailVerification verification, y.T_OrderDetailValidation validation, + T_OrderPromiseDateTime , Group_ResultName as ResultGroupName + FROM t_orderdetail x + left join t_orderpromise on x.T_OrderDetailT_OrderPromiseID = T_OrderPromiseID + JOIN t_test tx ON x.T_OrderDetailT_TestID = T_TestID + LEFT JOIN group_resultdetail ON Group_ResultDetailT_TestID = x.T_OrderDetailT_TestID AND Group_ResultDetailIsActive = 'Y' + LEFT JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND Group_ResultFlagNonLab = 'N' + LEFT JOIN t_orderdetail y ON x.T_OrderDetailT_TestSasCode LIKE CONCAT(y.T_OrderDetailT_TestSasCode, '%') + AND x.T_OrderDetailT_OrderHeaderID = y.T_OrderDetailT_OrderHeaderID + AND y.T_OrderDetailIsActive = 'Y' + + LEFT JOIN t_orderdetailaddon ON x.T_OrderDetailID = T_OrderDetailAddOnT_OrderDetailID + + JOIN t_orderheader ON y.T_OrderDetailT_OrderHeaderID = T_OrderHeaderID + LEFT JOIN t_test a ON y.T_OrderDetailT_TestID = a.T_TestID + AND a.T_TestIsNonLab = '' + LEFT JOIN (SELECT T_OrderSampleT_SampleTypeID, T_OrderSampleReceive, T_OrderSampleProcessing, T_OrderSampleWorklistReceive + FROM t_ordersample WHERE T_OrderSampleT_OrderHeaderID = {$id} + AND T_OrderSampleIsactive = 'Y' + GROUP BY T_OrderSampleT_SampleTypeID) os ON a.T_TestT_SampleTypeID = os.T_OrderSampleT_SampleTypeID + or os.T_OrderSampleT_SampleTypeID = fn_sampletype_from_local(a.T_TestNat_TestID) + + LEFT JOIN t_resultinstrument ON T_ResultInstrumentT_OrderDetailID = x.T_OrderDetailID + LEFT JOIN pre_analytic ON PreAnalyticNat_TestID = a.T_TestNat_TestID AND PreAnalyticDate = date(now()) and PreAnalyticIsActive = 'Y' + WHERE x.T_OrderDetailT_OrderHeaderID = {$id} + AND x.T_OrderDetailIsActive = 'Y' + GROUP BY y.T_OrderDetailT_TestID + ORDER BY y.T_OrderDetailT_TestSasCode ASC + ) a1 + + LEFT JOIN t_orderdetail a2 ON a2.T_OrderDetailT_OrderHeaderID = a1.order_id + AND a2.T_OrderDetailIsActive = 'Y' + AND a1.test_sas_code LIKE CONCAT(a2.T_OrderDetailT_testSasCode, '%') + GROUP BY a1.t_testid + order by a1.test_sas_code +"; +//echo $sql; + $query = $this->db_smartone->query($sql); + $lq = $this->db_smartone->last_query(); + } + // file_put_contents("/xtmp/re-query.sql",$lq); + + if ($query) { + $rst = []; + $rows = $query->result_array(); + + foreach($rows as $k => $v) + { + + if ($v['is_result'] == "Y" && $v['is_quantitative'] == "N") + { + $v['template'] = []; + $x = $this->db_smartone->query("CALL sp_master_resulttemplate_get('{$v['t_testid']}')"); + $this->clean_mysqli_connection($this->db_smartone->conn_id); + if ($x) + $v['template'] = $x->result_array(); + } + + // IF Rujukan, by pas Pre Analytik + if ($v['ref'] == 'Y') + $v['pre_analytic'] = 'Y'; + if ($v["id"] == "885455" ) + { + //sipe workaround + //$v["sample_receive"] = "Y"; + $v["sample_worklist_receive"] = "Y"; + } + $rst[] = $v; + } + + $result = array("total" => $tot_count, "records" => $rst, "total_display" => sizeof($rows), "q" => $lq); + $this->sys_ok($result); + } + else { + $this->sys_error_db("RE Px rows", $this->db_smartone); + exit; + } + } + + public function save() + { + $prm = $this->sys_input; + $data = json_decode($prm["data"]); + $lang = $this->lang_default_code; + $lang_id = isset($prm['lang_id']) ? $prm['lang_id'] : '0'; + + if ($lang_id != 0) + { + $l = $this->db_smartone->where("Nat_LangID", $lang_id)->get("nat_lang")->row(); + $lang = $l->Nat_LangCode; + } + + $sql_norm = "select T_OrderDetailMinValue, T_OrderDetailMaxValue, + T_OrderDetailMinValueInclusive, T_OrderDetailMaxValueInclusive, + Nat_TestFlagLow, Nat_TestFlagHigh + from t_orderdetail + join t_test on T_OrderDetailT_TestID = T_TestID + join nat_test on T_TestNat_TestID = Nat_TestID and T_TestIsActive = 'Y' + where T_OrderDetailID = ? "; + + $ids = []; + foreach ($data as $k => $v) + { + if ( $v->resultInstrumentID > 0 ) { + $sql_i = "select T_ResultInstrumentNat_NormalValueID normalValueID + from t_resultinstrument + where T_ResultInstrumentID = ?"; + $qry_i = $this->db_smartone->query($sql_i, array($v->resultInstrumentID)); + if ($qry_i) { + $rows_i = $qry_i->result_array(); + + if (count($rows_i) > 0 ) { + $sql_iu = "update t_orderdetail, nat_normalvalue , nat_methode + set T_OrderDetailMinValue = Nat_NormalValueMinValue, + T_OrderDetailMinValueInclusive = Nat_NormalValueMinValueInclusive, + T_OrderDetailMaxValue = Nat_NormalValueMaxValue , + T_OrderDetailMaxValueInclusive = Nat_NormalValueMaxValueInclusive, + T_OrderDetailNormalValueNote = Nat_NormalValueNote, + T_OrderDetailNormalValueDescription = Nat_NormalValueDescription, + T_OrderDetailNat_NormalValueID = Nat_NormalValueID, + T_OrderDetailNat_MethodeID = Nat_NormalValueNat_MethodeID, + T_OrderDetailNat_MethodeName = Nat_MethodeName + where T_OrderDetailID = ? and Nat_NormalValueID = ? + and Nat_NormalValueNat_MethodeID = Nat_MethodeID + "; + $this->db_smartone->query($sql_iu, array($v->id, $rows_i[0]["normalValueID"])); + //file_put_contents("/xtmp/update-nilai-normal", $this->db_smartone->last_query() . "\n", FILE_APPEND); + } + } + } + $y = $this->db_smartone->query("SELECT fn_process_sample_handling_perfect('{$v->order_id}', '{$v->test_id}') c") + ->row(); + $req_status = $y->c; + $qry_norm = $this->db_smartone->query($sql_norm,$v->id); + $result_flag = ""; + if ($qry_norm) { + $rows_norm = $qry_norm->result_array(); + if (count($rows_norm) > 0 ) { + $r = $rows_norm[0]; + if (is_numeric($v->result)) { + + if ( $r["T_OrderDetailMinValueInclusive"] == "Y" && $v->result < $r["T_OrderDetailMinValue"] ) { + $result_flag = $r["Nat_TestFlagLow"]; + } + if ( $r["T_OrderDetailMinValueInclusive"] == "N" && $v->result <= $r["T_OrderDetailMinValue"] ) { + $result_flag = $r["Nat_TestFlagLow"]; + } + if ( $r["T_OrderDetailMaxValueInclusive"] == "Y" && $v->result > $r["T_OrderDetailMaxValue"] ) { + $result_flag = $r["Nat_TestFlagHigh"]; + } + if ( $r["T_OrderDetailMaxValueInclusive"] == "N" && $v->result >= $r["T_OrderDetailMaxValue"] ) { + $result_flag = $r["Nat_TestFlagHigh"]; + } + } + } + } + if ($lang == $this->lang_default_code) + { + $this->db_smartone->set('T_OrderDetailResult', $v->result) + ->set('T_OrderDetailResultFlag', $result_flag) + ->set('T_OrderDetailNote', $v->note) + ->set('T_OrderDetailReqStatus', $req_status) + ->where('T_OrderDetailID', $v->id) + ->update('t_orderdetail'); + } + else + { + $this->db_smartone->set('T_OrderDetailLangResult', $v->result) + ->set('T_OrderDetailLangNote', $v->note) + ->where('T_OrderDetailLangID', $v->id) + ->update('t_orderdetaillang'); + } + + $ids[] = $v->id; + } + + // LOG Process + $order = $this->db_smartone->select('T_OrderDetailT_OrderHeaderID id, T_OrderHeaderLabNumber lab_number', false) + ->join('t_orderheader', 'T_OrderHeaderID = T_OrderDetailT_OrderHeaderID') + ->where('T_OrderDetailID', $data[0]->id) + ->get('t_orderdetail') + ->row(); + + $dblog = $this->load->database("onelog", true); + $dblog->set('Log_ProcessCode', 'PROCESS.Result.Entry') + ->set('Log_ProcessOrderID', $order->id) + ->set('Log_ProcessOrderNumber', $order->lab_number) + ->set('Log_ProcessJson', json_encode($data)) + ->set('Log_ProcessUserID', $this->sys_user['M_UserID']) + ->insert('log_process'); + // END OF Log Process + //auto calculation + $this->load->library("Resultcalc"); + $rows = $this->resultcalc->auto($order->id); + + try { + foreach($ids as $id ) { + $this->db_smartone->query("call sp_set_normal_value_flag($id)"); + $this->clean_mysqli_connection($this->db_smartone->conn_id); + } + } catch(Exception $e) { + } + + $this->sys_ok($ids); + } + + public function save_template() + { + $prm = $this->sys_input; + + $n = $this->db_smartone->select("COUNT(T_ResultTemplateID) n") + ->where("T_ResultTemplateT_TestID", $prm['test_id']) + ->where("T_ResultTemplateIsActive", "Y") + ->where("T_ResultTemplateValue", $prm['value']) + ->get('t_resulttemplate') + ->row(); + if ($n->n > 0) + { + $this->sys_error_db("Insert Result Template", $this->db_smartone); + return; + } + + $r = $this->db_smartone->set("T_ResultTemplateT_TestID", $prm['test_id']) + ->set("T_ResultTemplateValue", $prm['value']) + ->insert('t_resulttemplate'); + if ($r) + { + $template = []; + $x = $this->db_smartone->query("CALL sp_master_resulttemplate_get('{$prm['test_id']}')"); + $this->clean_mysqli_connection($this->db_smartone->conn_id); + if ($x) + $template = $x->result_array(); + + $this->sys_ok($template); + } + } + + public function export() + { + $prm = $this->sys_input; + + $sql = "CALL sp_process_result_lang(?, ?, ?, ?)"; + $query = $this->db_smartone->query($sql, [$prm['order_id'], $prm['lang_id'], $prm['is_si'], $this->sys_user['M_UserID']]); + if ($query) + { + $r = $query->row(); + if ($r->status == "OK") + { + $this->sys_ok($r->data); + return; + } + + $this->sys_error_db("Message : " . $r->message, $this->db_smartone); + } + else + { + $this->sys_error_db("Lang Result", $this->db_smartone); + return; + } + } + + public function search_group() + { + $prm = $this->sys_input; + $max_rst = 100; + + // QUERY TOTAL + $sql = "select count(*) total + from t_worklist + where T_WorklistIsActive = 'Y' + order by T_WorklistName ASC"; + $query = $this->db_smartone->query($sql); + + if ($query) { + $tot_count = $query->result_array()[0]["total"]; + } + else { + $this->sys_error_db("worklist count", $this->db_smartone); + exit; + } + + $sql = "select T_WorklistID group_id, T_WorklistName group_name + from t_worklist + where T_WorklistIsActive = 'Y' + order by T_WorklistName ASC + limit 0, {$max_rst}"; + $query = $this->db_smartone->query($sql); + + if ($query) { + $rows = $query->result_array(); + foreach ($rows as $k => $v) + $rows[$k]['data'] = json_decode($v['data']); + $result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows), "q" => $this->db_smartone->last_query()); + $this->sys_ok($result); + } + else { + $this->sys_error_db("worklist rows", $this->db_smartone); + exit; + } + } + + public function search_rerun() + { + $prm = $this->sys_input; + $id = $prm["detail_id"]; + + $sql = "CALL sp_process_result_rerun(?)"; + $query = $this->db_smartone->query($sql, [$id]); + + if ($query) + { + $rows = $query->result_array(); + $this->sys_ok(["records"=>$rows]); + } + else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + + + function getdoctorsfna() + { + $prm = $this->sys_input; + // $id = $prm["id"]; + + $sql = " SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY M_DoctorName ASC"; + //echo $sql; + $query = $this->db_smartone->query($sql); + + if ($query) + { + $rows = $query->result_array(); + $this->sys_ok(["records"=>$rows]); + } + else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + function getfnaresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT Other_FNADetailsID as xid, + Other_FNAT_OrderDetailID as orderdetail_id, + Other_FNADetailsCode as code, + Other_FNADetailsLabel as label, + Other_FNADetailsResult as result, + IFNULL(Other_FNAM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_FNAM_DoctorID) OR Other_FNAM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_fna + JOIN other_fnadetails ON Other_FNADetailsOther_FNAID = Other_FNAID AND Other_FNADetailsIsActive = 'Y' + LEFT JOIN m_doctor ON Other_FNAM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_FNAT_OrderDetailID = {$id} AND Other_FNAIsActive = 'Y' + GROUP BY Other_FNADetailsID + ORDER BY Other_FNADetailsCode ASC"; + $query = $this->db_smartone->query($sql); + + if ($query) + { + $rows = $query->result_array(); + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $images = array(); + $sql = "SELECT So_ImageUploadID as xid, + CONCAT('/one-media/one-image-nonlab/',So_ImageUploadNewName) as image_url + FROM t_orderdetail + JOIN so_imageupload ON So_ImageUploadT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND + So_ImageUploadIsActive = 'Y' + WHERE + T_OrderDetailID = {$id} AND + T_OrderDetailIsActive = 'Y' + GROUP BY So_ImageUploadID"; + $images = $this->db_smartone->query($sql)->result_array(); + + $rst = array('doctors'=>$doctors,'results'=>$rows,'images'=>$images); + $this->sys_ok(["records"=>$rst]); + } + else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + + function uploadimage(){ + if (! $this->isLogin) { + $this->sys_error("Invalid Token"); + exit; + } + + $userid = $this->sys_user["M_UserID"]; + $data = []; + //print_r($_SERVER); + + $prm = $this->sys_input; + $orderid = $this->input->post('orderid'); + $labnumber = $this->input->post('labnumber'); + $sql = "UPDATE so_imageupload SET + So_ImageUploadIsActive = 'N', + So_ImageUploadUserID = {$userid} + WHERE + So_ImageUploadT_OrderHeaderID = {$orderid}"; + //echo $sql; + $this->db_onedev->query($sql); + //$config['upload_path'] = 'assets/'; + + $path = '/home/one/project/one/one-media/one-image-nonlab/'; + //echo $path; + $config['upload_path'] = $path; + $config['allowed_types'] = 'jpg|jpeg|png|gif'; + + $config['max_size'] = '10000'; + $count = count($_FILES['files']['name']); + //echo $count; + $this->load->library('upload',$config); + + $error = []; + for($i=0;$i<$count;$i++){ + + + if(!empty($_FILES['files']['name'][$i])){ + + + + $_FILES['file']['name'] = $_FILES['files']['name'][$i]; + + $_FILES['file']['type'] = $_FILES['files']['type'][$i]; + + $_FILES['file']['tmp_name'] = $_FILES['files']['tmp_name'][$i]; + + $_FILES['file']['error'] = $_FILES['files']['error'][$i]; + + $_FILES['file']['size'] = $_FILES['files']['size'][$i]; + + + + $namex = $orderid.'-'.$labnumber.'-'.$this->generateRandomString(5); + //echo $namex; + + $config['file_name'] = $namex; + $this->upload->initialize($config); + //echo $config['file_name'] ; + + + + + + if($this->upload->do_upload('file')){ + + $uploadData = $this->upload->data(); + + $filename = $uploadData['file_name']; + //echo $filename; + + + $sql = "INSERT INTO so_imageupload ( + So_ImageUploadT_OrderHeaderID, + So_ImageUploadT_OrderHeaderLabNumber, + So_ImageUploadT_SampleTypeID, + So_ImageUploadOldName, + So_ImageUploadNewName, + So_ImageUploadCreated, + So_ImageUploadUserID + ) + VALUES( + {$orderid}, + '{$labnumber}', + '150', + '{$_FILES['files']['name'][$i]}', + '{$filename}', + NOW(), + {$userid} + + )"; + //echo $sql; + $this->db_onedev->query($sql); + $xlast_id = $this->db_onedev->insert_id(); + $data['totalFiles'][] = array('xid' => $xlast_id ,'image_url' => '/one-media/one-image-nonlab/'.$filename); + + } + else{ + $error = array('error' => $this->upload->display_errors()); + } + + } + + + + } + + $result = array("total" =>count( $data['totalFiles']), "records" => $data['totalFiles'],'errors'=>$error); + $this->sys_ok($result); + } + + + function generateRandomString($length = 10) { + $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; + $charactersLength = strlen($characters); + $randomString = ''; + for ($i = 0; $i < $length; $i++) { + $randomString .= $characters[rand(0, $charactersLength - 1)]; + } + return $randomString; + } + + function getcytologiresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT Other_CytologiDetailsID as xid, + Other_CytologiT_OrderDetailID as orderdetail_id, + Other_CytologiDetailsCode as code, + Other_CytologiDetailsLabel as label, + Other_CytologiDetailsResult as result, + IFNULL(Other_CytologiM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_CytologiM_DoctorID) OR Other_CytologiM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_cytologi + JOIN other_cytologidetails ON Other_CytologiDetailsOther_CytologiID = Other_CytologiID AND Other_CytologiDetailsIsActive = 'Y' + LEFT JOIN m_doctor ON Other_CytologiM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_CytologiT_OrderDetailID = {$id} AND Other_CytologiIsActive = 'Y' + GROUP BY Other_CytologiDetailsID + ORDER BY Other_CytologiDetailsCode ASC"; + //echo $sql; + $query = $this->db_smartone->query($sql); + + if ($query) + { + $rows = $query->result_array(); + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $rst = array('doctors'=>$doctors,'results'=>$rows); + $this->sys_ok(["records"=>$rst]); + } + else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + function getmikroresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT + Other_MikroID as xid, + Other_MikroHasilBiakan as hasil_biakan, + Other_MikroSampleTypeName as sample_name, + Other_MikroT_OrderDetailID as orderdetail_id, + Other_MikroResult as result_value, + '' as result_other, + IFNULL(T_BacteriaID,0) as T_BacteriaID, + IFNULL(T_BacteriaName,'') as T_BacteriaName, + '' as details, + IFNULL(Other_MikroM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_MikroM_DoctorID) OR Other_MikroM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_mikro + LEFT JOIN t_bacteria ON Other_MikroT_BacteriaID = T_BacteriaID + LEFT JOIN m_doctor ON Other_MikroM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_MikroT_OrderDetailID = {$id} AND Other_MikroIsActive = 'Y' + GROUP BY Other_MikroID"; + //echo $sql; + $query = $this->db_smartone->query($sql); + + if ($query) + { + $row = $query->row_array(); + if($row){ + if($row['result_value'] != 'Positif' && $row['result_value'] != 'Negatif'){ + $row['result_other'] = $row['result_value']; + $row['result_value'] = 'other'; + } + $sql = "SELECT '' as xno, + Other_MikroDetailsID as xid, + Other_MikroDetailsValue as value, + IF(Other_MikroDetailsNote = 'R','Y','N') as chx_r, + IF(Other_MikroDetailsNote = 'I','Y','N') as chx_i, + IF(Other_MikroDetailsNote = 'S','Y','N') as chx_s, + Other_MikroDetailsNote as note, + t_antibiotic.* + FROM other_mikrodetails + LEFT JOIN t_antibiotic ON Other_MikroDetailsT_AntibioticID = T_AntibioticID + WHERE + Other_MikroDetailsOther_MikroID = {$row['xid']} AND Other_MikroDetailsIsActive = 'Y' + GROUP BY Other_MikroDetailsID + ORDER BY T_AntibioticName ASC"; + //echo $sql; + $details = $this->db_smartone->query($sql)->result_array(); + if(details){ + foreach($details as $k => $v){ + $details[$k]['xno'] = $k + 1; + } + } + $row['details'] = $details; + } + else{ + $row = array('xid'=>'0','hasil_biakan' => '','result_value'=>'Negatif','sample_name' => '','orderdetail_id'=>$id, 'T_BacteriaID'=>'0','T_BacteriaName'=>'0','details'=>array(),'doctor_id'=>'0','doctor_name'=>'0'); + } + } + else{ + $row = array('xid'=>'0','hasil_biakan' => '','result_value'=>'Negatif','sample_name' => '','orderdetail_id'=>$id, 'T_BacteriaID'=>'0','T_BacteriaName'=>'0','details'=>array(),'doctor_id'=>'0','doctor_name'=>'0'); + } + //print_r($row); + + + + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 7 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $sql = " + SELECT '0' as id, 'Belum memilih bakteria' as name + UNION + SELECT T_BacteriaID as id, T_BacteriaName as name + FROM t_bacteria + WHERE + T_BacteriaIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $bacteries = $this->db_smartone->query($sql)->result_array(); + $rst = array('doctors'=>$doctors,'bacteries'=>$bacteries,'results'=>$row); + $this->sys_ok(["records"=>$rst]); + } + function getantibiotics(){ + $prm = $this->sys_input; + $id = $prm["id"]; + $sql = " SELECT '' as xno, + 0 as xid, + '' as hasil_biakan, + '' as sample_name, + 0 as value, + 'Y' as chx_r, + 'N' as chx_i, + 'N' as chx_s, + 'R' as note, + t_antibiotic.* + FROM t_antibiotic + WHERE + T_AntibioticT_BacteriaID = {$prm['id']} AND T_AntibioticIsActive= 'Y' + ORDER BY T_AntibioticName ASC"; + //echo $sql; + $rows = $this->db_smartone->query($sql)->result_array(); + if(rows){ + foreach($rows as $k => $v){ + $rows[$k]['xno'] = $k + 1; + } + } + + $this->sys_ok(["records"=>$rows]); + } + function getlcprepresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + $sql = " SELECT Other_LcprepDetailsID as xid, + Other_LcprepID as header_id, + Other_LcprepT_orderDetailID as orderdetail_id, + Other_LcprepDetailsCode as code, + Other_LcprepDetailsLabel as label, + Other_LcprepDetailsResult as result, + IFNULL(Other_LcprepM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_LcprepM_DoctorID) OR Other_LcprepM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_lcprep + JOIN other_lcprepdetails ON Other_LcprepDetailsOther_LcprepID = Other_LcprepID AND Other_LcprepDetailsIsActive = 'Y' + LEFT JOIN m_doctor ON Other_LcprepM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_LcprepT_orderDetailID = {$id} AND Other_LcprepIsActive = 'Y' + GROUP BY Other_LcprepDetailsOther_LcprepID, Other_LcprepDetailsCode + ORDER BY Other_LcprepDetailsCode ASC"; + //echo $sql; + $rows = $this->db_smartone->query($sql)->result_array(); + if(!$rows){ + $rows = array( + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'A', + 'label' => 'DESKRIPSI', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ), + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'B', + 'label' => 'KESIMPULAN', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ) + ); + } + + $header_id = $rows[0]['header_id']; + $sql = "SELECT IFNULL(Other_LcprepAdekuasiID,0) as xid, + Lcprep_AdekuasiID as id, + Lcprep_AdekuasiLabel as name, + IF(ISNULL(Other_LcprepAdekuasiID),'N',Other_LcprepAdekuasiChex) as chex + FROM lcprep_adekuasi + LEFT JOIN other_lcprepadekuasi ON Other_LcprepAdekuasiLcprep_AdekuasiID = Lcprep_AdekuasiID AND + Other_LcprepAdekuasiOther_LcprepID = {$header_id} AND + Other_LcprepAdekuasiIsActive = 'Y' + WHERE + Lcprep_AdekuasiIsActive = 'Y' + GROUP BY Lcprep_AdekuasiID + ORDER BY Lcprep_AdekuasiOrder ASC + "; + //echo $sql; + $adeakuasi = $this->db_smartone->query($sql)->result_array(); + foreach($adeakuasi as $kc => $vc){ + $adeakuasi[$kc]['chex'] = $vc['chex'] == 'N'?false:true; + } + + $sql = "SELECT IFNULL(Other_LcprepKategoriUmumID,0) as xid, + Lcprep_KategoriUmumID as id, + Lcprep_KategoriUmumLabel as name, + IF(ISNULL(Other_LcprepKategoriUmumID),'N',Other_LcprepKategoriUmumChex) as chex + FROM lcprep_kategoriumum + LEFT JOIN other_lcprepkategoriumum ON Other_LcprepKategoriUmumLcprep_KategoriUmumID = Lcprep_KategoriUmumID AND + Other_LcprepKategoriUmumOther_LcprepID = {$header_id} AND + Other_LcprepKategoriUmumIsActive = 'Y' + WHERE + Lcprep_KategoriUmumIsActive = 'Y' + GROUP BY Lcprep_KategoriUmumID + "; + //echo $sql; + $kategoriumum = $this->db_smartone->query($sql)->result_array(); + foreach($kategoriumum as $kc => $vc){ + $kategoriumum[$kc]['chex'] = $vc['chex'] == 'N'?false:true; + } + + $sql = " + SELECT Lcprep_InterpretasiGroupID as group_id, + Lcprep_InterpretasiGroupName as group_name, + '' as subgroups + FROM lcprep_interpretasigroup + WHERE + Lcprep_InterpretasiGroupIsActive = 'Y' + "; + //echo $sql; + $interpretasi = $this->db_smartone->query($sql)->result_array(); + foreach($interpretasi as $k => $v){ + $subgroups = array(); + $sql = "SELECT Lcprep_InterpretasiSubgroupID as subgroup_id, + Lcprep_InterpretasiSubgroupName as subgroup_name, + '' as childs + FROM lcprep_interpretasisubgroup + WHERE + Lcprep_InterpretasiSubgroupLcprep_InterpretasiGroupID = {$v['group_id']} AND Lcprep_InterpretasiSubgroupIsActive = 'Y'"; + //echo $sql; + $subgroups = $this->db_smartone->query($sql)->result_array(); + if(count($subgroups) > 0){ + foreach($subgroups as $ki => $vi){ + $childs = array(); + $sql = "SELECT IFNULL(Other_LcprepInterpretasiID,0) as xid, + IFNULL(Other_LcprepInterpretasiChex,'N') as chex, + IFNULL(Other_LcprepInterpretasiValue,'') as value, + Lcprep_InterpretasiID as id, + Lcprep_InterpretasiLcprep_InterpretasiSubgroupID as subgroup_id, + Lcprep_InterpretasiCode as code, + Lcprep_InterpretasiName as name, + Lcprep_InterpretasiParentID as parent_id, + Lcprep_InterpretasiIsParent as is_parent, + Lcprep_InterpretasiHasResult as has_result, + Lcprep_InterpretasiTypeResult as type_result + FROM lcprep_interpretasi + LEFT JOIN other_lcprepinterpretasi ON Other_LcprepInterpretasiOther_LcprepID = {$header_id} AND + Other_LcprepInterpretasiLcprep_InterpretasiID = Lcprep_InterpretasiID AND + Other_LcprepInterpretasiIsActive = 'Y' + WHERE + Lcprep_InterpretasiLcprep_InterpretasiSubgroupID = {$vi['subgroup_id']} AND Lcprep_InterpretasiIsActive = 'Y' + GROUP BY Lcprep_InterpretasiID Order BY Lcprep_InterpretasiCode ASC"; + $childs = $this->db_smartone->query($sql)->result_array(); + if($childs){ + foreach($childs as $kc => $vc){ + $childs[$kc]['chex'] = $vc['chex'] == 'N'?false:true; + } + } + $subgroups[$ki]['childs'] = $childs; + } + } + + $interpretasi[$k]['subgroups'] = $subgroups; + } + + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $rst = array('doctors'=>$doctors,'results'=>$rows,'adekuasi'=>$adeakuasi,'kategoriumum'=>$kategoriumum,'interpretasi'=>$interpretasi); + $this->sys_ok(["records"=>$rst]); + } + + function getpapsmearresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT Other_PapSmearDetailsID as xid, + Other_PapSmearID as header_id, + Other_PapSmearT_OrderDetailID as orderdetail_id, + Other_PapSmearDetailsCode as code, + Other_PapSmearDetailsLabel as label, + Other_PapSmearDetailsResult as result, + IFNULL(Other_PapSmearM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_PapSmearM_DoctorID) OR Other_PapSmearM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_papsmear + JOIN other_papsmeardetails ON Other_PapSmearDetailsOther_PapSmearID = Other_PapSmearID AND Other_PapSmearDetailsIsActive = 'Y' + LEFT JOIN m_doctor ON Other_PapSmearM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_PapSmearT_OrderDetailID = {$id} AND Other_PapSmearIsActive = 'Y' + GROUP BY Other_PapSmearDetailsID + ORDER BY Other_PapSmearDetailsCode ASC"; + //echo $sql; + $rows = $this->db_smartone->query($sql)->result_array(); + if(!$rows){ + $rows = array( + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'A', + 'label' => 'Makroskopik', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ), + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'B', + 'label' => 'Mikroskopik', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ), + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'C', + 'label' => 'Kesimpulan', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ) + ); + } + + $header_id = $rows[0]['header_id']; + $sql = "SELECT Other_PapSmearMaturasiID as xid, + Other_PapSmearMaturasiValue as value + FROM other_papsmearmaturasi + WHERE + Other_PapSmearMaturasiOther_PapSmearID = {$header_id} AND + Other_PapSmearMaturasiIsActive = 'Y' + "; + //echo $sql; + $dt_maturasi = $this->db_smartone->query($sql)->row_array(); + if(!$dt_maturasi){ + $maturasi = array('xid'=>'0','value'=> array('','','')); + } + else{ + $value = explode('/',$dt_maturasi['value']); + $maturasi = array('xid'=>$dt_maturasi['xid'],'value'=> $value); + } + + $sql = "SELECT IFNULL(Other_PapSmearBahanID,0) as xid, + M_PapSmearBahanID as bahan_id, + M_PapSmearBahanName as name, + IF(ISNULL(Other_PapSmearBahanID),'N','Y') as selected + FROM m_papsmearbahan + LEFT JOIN other_papsmearbahan ON Other_PapSmearBahanM_PapSmearBahanID = M_PapSmearBahanID AND + Other_PapSmearBahanOther_PapSmearID = {$header_id} AND + Other_PapSmearBahanIsActive = 'Y' + WHERE + M_PapSmearBahanIsActive = 'Y' + ORDER BY M_PapSmearBahanID ASC + "; + //echo $sql; + $bahans = $this->db_smartone->query($sql)->result_array(); + + $sql = "SELECT IFNULL(Other_PapsmearCategoryID,0) as xid, + M_PapSmearCategoryID as category_id, + M_PapSmearCategoryName as name, + IF(ISNULL(Other_PapsmearCategoryID),'N','Y') as selected + FROM m_papsmearcategory + LEFT JOIN other_papsmearcategory ON Other_PapsmearCategoryM_PapSmearCategoryID = M_PapSmearCategoryID AND + Other_PapsmearCategoryOther_PapSmearID = {$header_id} AND + Other_PapsmearCategoryIsActive = 'Y' + WHERE + M_PapSmearCategoryIsActive = 'Y' + ORDER BY M_PapSmearCategoryID ASC + "; + //echo $sql; + $categories = $this->db_smartone->query($sql)->result_array(); + + $sql = "SELECT IFNULL(Other_PapSmearCheckID,0) as xid, + M_PapSmearCheckID as check_id, + M_PapSmearCheckLabel as name, + IF(ISNULL(Other_PapSmearCheckID),'N','Y') as selected, + Other_PapSmearCheckNote as note + FROM m_papsmearcheck + LEFT JOIN other_papsmearcheck ON Other_PapSmearCheckM_PapSmearCheckID = M_PapSmearCheckID AND + Other_PapSmearCheckOther_PapSmearID = {$header_id} AND + Other_PapSmearCheckIsActive = 'Y' + WHERE + M_PapSmearCheckIsActive = 'Y' + ORDER BY M_PapSmearCheckCode ASC + "; + $checks = $this->db_smartone->query($sql)->result_array(); + + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $rst = array('doctors'=>$doctors,'checks'=>$checks,'bahans'=>$bahans,'categories'=>$categories,'maturasi'=>$maturasi,'results'=>$rows); + $this->sys_ok(["records"=>$rst]); + + } + + function saveresult_lcprep() + { + $prm = $this->sys_input; + $detail_id = $prm['detail_id']; + $doctor_id = $prm['doctor']; + $adekuasi = $prm['adekuasi']; + $kategoriumum = $prm['kategoriumum']; + $interpretasi = $prm['interpretasi']; + $results = $prm['results']; + + $userid = $this->sys_user['M_UserID']; + + $header_id = 0; + $sql = "SELECT * FROM other_lcprep WHERE Other_LcprepT_orderDetailID = {$detail_id} AND Other_LcprepIsActive = 'Y'"; + $dt_header = $this->db_smartone->query($sql)->row_array(); + if($dt_header){ + $header_id = $dt_header['Other_LcprepID']; + } + if($header_id == 0){ + $sql = "INSERT INTO other_lcprep( + Other_LcprepT_orderDetailID, + Other_LcprepM_DoctorID, + Other_LcprepUserID, + Other_LcprepCreated + ) + VALUES( + {$detail_id}, + {$doctor_id}, + {$userid}, + NOW() + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + }else{ + $sql = "UPDATE other_lcprep SET Other_LcprepM_DoctorID = {$doctor_id}, Other_LcprepUserID = {$userid} WHERE Other_LcprepID = {$header_id}"; + $this->db_smartone->query($sql); + } + + if($adekuasi){ + foreach($adekuasi as $k =>$v){ + $selected = $v['chex']?'Y':'N'; + if(intval($v['xid'] == 0)){ + $sql = "UPDATE other_lcprepadekuasi SET Other_LcprepAdekuasiIsActive = 'N' + WHERE + Other_LcprepAdekuasiOther_LcprepID = {$header_id} AND + Other_LcprepAdekuasiIsActive = 'Y' AND + Other_LcprepAdekuasiLcprep_AdekuasiID = {$v['id']}"; + $this->db_smartone->query($sql); + $sql = "INSERT INTO other_lcprepadekuasi ( + Other_LcprepAdekuasiOther_LcprepID, + Other_LcprepAdekuasiLcprep_AdekuasiID, + Other_LcprepAdekuasiChex, + Other_LcprepAdekuasiUserID, + Other_LcprepAdekuasiCreated + ) + VALUES( + {$header_id}, + {$v['id']}, + '{$selected}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + //echo $sql; + } + if(intval($v['xid'] != 0)){ + + $sql = "UPDATE other_lcprepadekuasi SET + Other_LcprepAdekuasiChex = '{$selected}', + Other_LcprepAdekuasiUserID = {$userid} + WHERE + Other_LcprepAdekuasiID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + + //echo $sql; + } + } + + if($kategoriumum){ + foreach($kategoriumum as $k =>$v){ + $selected = $v['chex']?'Y':'N'; + if(intval($v['xid'] == 0)){ + $sql = "UPDATE other_lcprepkategoriumum SET Other_LcprepKategoriUmumIsActive = 'N' + WHERE + Other_LcprepKategoriUmumOther_LcprepID = {$header_id} AND + Other_LcprepKategoriUmumLcprep_KategoriUmumID = {$v['id']} AND + Other_LcprepKategoriUmumIsActive = 'Y' + "; + $this->db_smartone->query($sql); + $sql = "INSERT INTO other_lcprepkategoriumum ( + Other_LcprepKategoriUmumOther_LcprepID, + Other_LcprepKategoriUmumLcprep_KategoriUmumID, + Other_LcprepKategoriUmumChex, + Other_LcprepKategoriUmumUserID, + Other_LcprepKategoriUmumCreated + ) + VALUES( + {$header_id}, + {$v['id']}, + '{$selected}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if(intval($v['xid'] != 0)){ + $sql = "UPDATE other_lcprepkategoriumum SET + Other_LcprepKategoriUmumChex = '{$selected }', + Other_LcprepKategoriUmumUserID = {$userid} + WHERE + Other_LcprepKategoriUmumID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + + //echo $sql; + } + } + + if($results){ + foreach($results as $k =>$v){ + if(intval($v['xid'] == 0)){ + $sql = "UPDATE other_lcprepdetails SET Other_LcprepDetailsIsActive = 'N' + WHERE + Other_LcprepDetailsOther_LcprepID = {$header_id} AND + Other_LcprepDetailsCode = '{$v['code']}' AND + Other_LcprepDetailsIsActive = 'Y'"; + $this->db_smartone->query($sql); + $sql = "INSERT INTO other_lcprepdetails ( + Other_LcprepDetailsOther_LcprepID, + Other_LcprepDetailsCode, + Other_LcprepDetailsLabel, + Other_LcprepDetailsResult, + Other_LcprepDetailsUserID, + Other_LcprepDetailsCreated + ) + VALUES( + {$header_id}, + '{$v['code']}', + '{$v['label']}', + '{$v['result']}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if(intval($v['xid'] != 0)){ + $sql = "UPDATE other_lcprepdetails SET + Other_LcprepDetailsCode = '{$v['code']}', + Other_LcprepDetailsLabel = '{$v['label']}', + Other_LcprepDetailsResult = '{$v['result']}', + Other_LcprepDetailsUserID = {$userid} + WHERE + Other_LcprepDetailsID = {$v['xid']}"; + $this->db_smartone->query($sql); + + } + //echo $sql; + } + } + + if($interpretasi){ + foreach($interpretasi as $k =>$v){ + if(count($v['subgroups']) > 0){ + foreach($v['subgroups'] as $ik => $iv){ + if(count($iv['childs']) > 0){ + foreach($iv['childs'] as $iik => $iiv){ + if(intval($iiv['xid'] == 0)){ + $chex = $iiv['chex'] ? 'Y':'N'; + $sql = "UPDATE other_lcprepinterpretasi SET Other_LcprepInterpretasiIsActive = 'N' + WHERE + Other_LcprepInterpretasiOther_LcprepID = {$header_id} AND + Other_LcprepInterpretasiLcprep_InterpretasiID = '{$iiv['id']}' AND + Other_LcprepInterpretasiIsActive = 'Y'"; + $this->db_smartone->query($sql); + $sql = "INSERT INTO other_lcprepinterpretasi ( + Other_LcprepInterpretasiOther_LcprepID, + Other_LcprepInterpretasiLcprep_InterpretasiID, + Other_LcprepInterpretasiChex, + Other_LcprepInterpretasiValue, + Other_LcprepInterpretasiUserID, + Other_LcprepInterpretasiCreated + ) + VALUES( + {$header_id}, + '{$iiv['id']}', + '{$chex}', + '{$iiv['value']}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + + if(intval($iiv['xid'] != 0)){ + $chex = $iiv['chex'] ? 'Y':'N'; + $sql = "UPDATE other_lcprepinterpretasi SET + Other_LcprepInterpretasiChex = '{$chex}', + Other_LcprepInterpretasiValue = '{$iiv['value']}', + Other_LcprepInterpretasiUserID = {$userid} + WHERE + Other_LcprepInterpretasiID = {$iiv['xid']}"; + $this->db_smartone->query($sql); + //echo $sql; + + } + + } + } + } + } + //echo $sql; + } + } + + + $result = array("total" => 1, "records" => array(), "sql"=> ''); + $this->sys_ok($result); + exit; + } + + function saveresult_papsmear() + { + $prm = $this->sys_input; + $detail_id = $prm['detail_id']; + $doctor_id = $prm['doctor']; + $checks = $prm['checks']; + $maturasi = $prm['maturasi']; + $bahans = $prm['bahans']; + $categories = $prm['categories']; + $results = $prm['results']; + + $userid = $this->sys_user['M_UserID']; + + $header_id = 0; + $sql = "SELECT * FROM other_papsmear WHERE Other_PapSmearT_OrderDetailID = {$detail_id} AND Other_PapSmearIsActive = 'Y'"; + $dt_header = $this->db_smartone->query($sql)->row_array(); + if($dt_header){ + $header_id = $dt_header['Other_PapSmearID']; + } + if($header_id == 0){ + $sql = "INSERT INTO other_papsmear( + Other_PapSmearT_OrderDetailID, + Other_PapSmearM_DoctorID, + Other_PapSmearUserID, + Other_PapSmearCreated + ) + VALUES( + {$detail_id}, + {$doctor_id}, + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } + else{ + $sql = "UPDATE other_papsmear SET Other_PapSmearM_DoctorID = {$doctor_id}, Other_PapSmearUserID = {$userid} WHERE Other_PapSmearID = {$header_id}"; + $this->db_smartone->query($sql); + } + + if($checks){ + foreach($checks as $k =>$v){ + if(intval($v['xid']) == 0 && $v['selected'] === 'Y'){ + $sql = "INSERT INTO other_papsmearcheck ( + Other_PapSmearCheckOther_PapSmearID, + Other_PapSmearCheckM_PapSmearCheckID, + Other_PapSmearCheckNote, + Other_PapSmearCheckUserID, + Other_PapSmearCheckCreated + ) + VALUES( + {$header_id}, + {$v['check_id']}, + '{$v['note']}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if(intval($v['xid']) != 0 && $v['selected'] === 'N'){ + $sql = "UPDATE other_papsmearcheck SET + Other_PapSmearCheckIsActive = 'N', + Other_PapSmearCheckUserID = {$userid} + WHERE + Other_PapSmearCheckID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + if(intval($v['xid']) != 0 && $v['selected'] === 'Y'){ + $sql = "UPDATE other_papsmearcheck SET + Other_PapSmearCheckNote = '{$v['note']}', + Other_PapSmearCheckUserID = {$userid} + WHERE + Other_PapSmearCheckID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + //echo $sql; + } + } + + if($maturasi){ + if(intval($maturasi['xid']) == 0){ + $value = join("/",$maturasi['value']); + $sql = "INSERT INTO other_papsmearmaturasi ( + Other_PapSmearMaturasiOther_PapSmearID, + Other_PapSmearMaturasiValue, + Other_PapSmearMaturasiUserID, + Other_PapSmearMaturasiCreated + ) + VALUE( + {$header_id}, + '{$value}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + //echo $sql; + } + if(intval($maturasi['xid']) != 0){ + $value = join("/",$maturasi['value']); + $sql = "UPDATE other_papsmearmaturasi SET + Other_PapSmearMaturasiValue = '{$value}', + Other_PapSmearMaturasiUserID = {$userid} + WHERE + Other_PapSmearMaturasiID = {$maturasi['xid']}"; + // echo $sql; + $this->db_smartone->query($sql); + } + } + + if($bahans){ + foreach($bahans as $k =>$v){ + if(intval($v['xid']) == 0 && $v['selected'] === 'Y'){ + $sql = "INSERT INTO other_papsmearbahan ( + Other_PapSmearBahanOther_PapSmearID, + Other_PapSmearBahanM_PapSmearBahanID, + Other_PapSmearBahanUserID, + Other_PapSmearBahanCreated + ) + VALUES( + {$header_id}, + {$v['bahan_id']}, + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if(intval($v['xid']) != 0 && $v['selected'] === 'N'){ + $sql = "UPDATE other_papsmearbahan SET + Other_PapSmearBahanIsActive = 'N', + Other_PapsmearCategoryUserID = {$userid} + WHERE + Other_PapSmearBahanID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + if(intval($v['xid']) != 0 && $v['selected'] === 'Y'){ + $sql = "UPDATE other_papsmearbahan SET + Other_PapSmearBahanIsActive = 'Y', + Other_PapsmearCategoryUserID = {$userid} + WHERE + Other_PapSmearBahanID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + //echo $sql; + } + } + + if($categories){ + foreach($categories as $k =>$v){ + if(intval($v['xid']) == 0 && $v['selected'] === 'Y'){ + $sql = "INSERT INTO other_papsmearcategory ( + Other_PapsmearCategoryOther_PapSmearID, + Other_PapsmearCategoryM_PapSmearCategoryID, + Other_PapsmearCategoryUserID, + Other_PapsmearCategoryCreated + ) + VALUES( + {$header_id}, + {$v['category_id']}, + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if(intval($v['xid']) != 0 && $v['selected'] === 'N'){ + $sql = "UPDATE other_papsmearcategory SET + Other_PapsmearCategoryIsActive = 'N', + Other_PapsmearCategoryUserID = {$userid} + WHERE + Other_PapsmearCategoryID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + //echo $sql; + if(intval($v['xid']) != 0 && $v['selected'] === 'Y'){ + $sql = "UPDATE other_papsmearcategory SET + Other_PapsmearCategoryIsActive = 'Y', + Other_PapsmearCategoryUserID = {$userid} + WHERE + Other_PapsmearCategoryID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + } + } + + if($results){ + foreach($results as $k =>$v){ + if(intval($v['xid']) == 0){ + $sql = "INSERT INTO other_papsmeardetails ( + Other_PapSmearDetailsOther_PapSmearID, + Other_PapSmearDetailsCode, + Other_PapSmearDetailsLabel, + Other_PapSmearDetailsResult, + Other_PapSmearDetailsUserID, + Other_PapSmearDetailsCreated + ) + VALUES( + {$header_id}, + '{$v['code']}', + '{$v['label']}', + '{$v['result']}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if(intval($v['xid']) != 0){ + $sql = "UPDATE other_papsmeardetails SET + Other_PapSmearDetailsCode = '{$v['code']}', + Other_PapSmearDetailsLabel = '{$v['label']}', + Other_PapSmearDetailsResult = '{$v['result']}', + Other_PapSmearDetailsUserID = {$userid} + WHERE + Other_PapSmearDetailsID = {$v['xid']}"; + $this->db_smartone->query($sql); + + } + //echo $sql; + } + } + + $result = array("total" => 1, "records" => array(), "sql"=> ''); + $this->sys_ok($result); + exit; + } + + function saveresult_fna() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = $inp['doctor']; + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + if($prm[0]['xid'] == '0'){ + $sql = "INSERT INTO other_fna( + Other_FNAM_DoctorID, + Other_FNAT_OrderDetailID, + Other_FNAUserID, + Other_FNACreated + ) + VALUES( + {$doctor_id}, + {$prm[0]['orderdetail_id']}, + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } + else{ + $sql = "SELECT * FROM other_fna WHERE Other_FNAT_OrderDetailID = {$prm[0]['orderdetail_id']} AND Other_FNAIsActive = 'Y'"; + $data_header = $this->db_smartone->query($sql)->row_array(); + $header_id = $data_header['Other_FNAID']; + $sql = "UPDATE other_fna SET + Other_FNAM_DoctorID = {$doctor_id}, + Other_FNAUserID = {$userid} + WHERE + Other_FNAID = {$header_id}"; + $this->db_smartone->query($sql); + } + foreach($prm as $k => $v){ + if($v['xid'] == '0'){ + $results = str_replace("'", "\\'", $v['result']); + $sql = "INSERT INTO other_fnadetails( + Other_FNADetailsOther_FNAID , + Other_FNADetailsCode, + Other_FNADetailsLabel, + Other_FNADetailsResult, + Other_FNADetailsCreated, + Other_FNADetailsUserID + ) + VALUES( + {$header_id}, + '{$v['code']}', + '{$v['label']}', + '{$results}', + NOW(), + {$userid} + )"; + $query = $this->db_smartone->query($sql); + } + else{ + $results = str_replace("'", "\\'", $v['result']); + $sql = "UPDATE other_fnadetails SET + Other_FNADetailsResult = '{$results}', + Other_FNADetailsUserID = {$userid} + WHERE + Other_FNADetailsID = {$v['xid']}"; + $query = $this->db_smartone->query($sql); + } + } + + $result = array("total" => 1, "records" => array(), "sql"=> ''); + $this->sys_ok($result); + exit; + } + + function saveresult_cytologi() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = $inp['doctor']; + + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + if($prm[0]['xid'] == '0'){ + $sql = "INSERT INTO other_cytologi( + Other_CytologiT_OrderDetailID, + Other_CytologiM_DoctorID, + Other_CytologiUserID, + Other_CytologiCreated + ) + VALUES( + {$prm[0]['orderdetail_id']}, + {$doctor_id}, + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } + else{ + $sql = "SELECT * FROM other_cytologi WHERE Other_CytologiT_OrderDetailID = {$prm[0]['orderdetail_id']} AND Other_CytologiIsActive = 'Y'"; + $data_header = $this->db_smartone->query($sql)->row_array(); + $header_id = $data_header['Other_CytologiID']; + $sql = "UPDATE other_cytologi SET + Other_CytologiM_DoctorID = {$doctor_id}, + Other_CytologiUserID = {$userid} + WHERE + Other_CytologiID = {$header_id}"; + $this->db_smartone->query($sql); + } + foreach($prm as $k => $v){ + if($v['xid'] == '0'){ + $results = str_replace("'", "\\'", $v['result']); + $sql = "INSERT INTO other_cytologidetails( + Other_CytologiDetailsOther_CytologiID , + Other_CytologiDetailsCode, + Other_CytologiDetailsLabel, + Other_CytologiDetailsResult, + Other_CytologiDetailsCreated, + Other_CytologiDetailsUserID + ) + VALUES( + {$header_id}, + '{$v['code']}', + '{$v['label']}', + '{$results}', + NOW(), + {$userid} + )"; + $query = $this->db_smartone->query($sql); + } + else{ + $results = str_replace("'", "\\'", $v['result']); + $sql = "UPDATE other_cytologidetails SET + Other_CytologiDetailsResult = '{$results}', + Other_CytologiDetailsUserID = {$userid} + WHERE + Other_CytologiDetailsID = {$v['xid']}"; + $query = $this->db_smartone->query($sql); + } + } + + $result = array("total" => 1, "records" => array(), "sql"=> ''); + $this->sys_ok($result); + exit; + } + + function saveresult_mikro() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = $inp['doctor']; + $backteria_id = $inp['bacteria']; + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + + if($inp['result_value'] != 'Negatif' && $inp['result_value'] != 'Positif'){ + $prm['result_value'] = $prm['result_other']; + } + else{ + $prm['result_value'] = $inp['result_value']; + } + + if($prm['xid'] == '0'){ + $sql = "INSERT INTO other_mikro( + Other_MikroM_DoctorID, + Other_MikroResult, + Other_MikroT_BacteriaID, + Other_MikroT_OrderDetailID, + Other_MikroHasilBiakan, + Other_MikroSampleTypeName, + Other_MikroUserID, + Other_MikroCreated + ) + VALUES( + {$doctor_id}, + '{$prm['result_value']}', + {$backteria_id}, + {$prm['orderdetail_id']}, + '{$prm['hasil_biakan']}', + '{$prm['sample_name']}', + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } + else{ + $sql = "SELECT * FROM other_mikro WHERE Other_MikroT_OrderDetailID = {$prm['orderdetail_id']} AND Other_MikroIsActive = 'Y'"; + $data_header = $this->db_smartone->query($sql)->row_array(); + $header_id = $data_header['Other_MikroID']; + $sql = "UPDATE other_mikro SET + Other_MikroResult = '{$prm['result_value']}', + Other_MikroM_DoctorID = {$doctor_id}, + Other_MikroT_BacteriaID = {$backteria_id}, + Other_MikroHasilBiakan = '{$prm['hasil_biakan']}', + Other_MikroSampleTypeName = '{$prm['sample_name']}', + Other_MikroUserID = {$userid} + WHERE + Other_MikroID = {$header_id}"; + //echo $sql; + $this->db_smartone->query($sql); + } + + + + $sql = "UPDATE other_mikrodetails SET Other_MikroDetailsIsActive = 'N', Other_MikroDetailsUserID = 0 WHERE Other_MikroDetailsOther_MikroID = {$header_id}"; + $this->db_smartone->query($sql); + + $results = $prm['details']; + if($inp['result_value'] == 'Positif'){ + foreach($results as $k => $v){ + if($v['xid'] == '0'){ + $sql = "INSERT INTO other_mikrodetails( + Other_MikroDetailsOther_MikroID , + Other_MikroDetailsT_AntibioticID, + Other_MikroDetailsValue, + Other_MikroDetailsNote, + Other_MikroDetailsCreated, + Other_MikroDetailsUserID + ) + VALUES( + {$header_id}, + '{$v['T_AntibioticID']}', + '{$v['value']}', + '{$v['note']}', + NOW(), + {$userid} + )"; + $query = $this->db_smartone->query($sql); + } + else{ + $sql = "UPDATE other_mikrodetails SET + Other_MikroDetailsT_AntibioticID = '{$v['T_AntibioticID']}', + Other_MikroDetailsValue = '{$v['value']}', + Other_MikroDetailsNote = '{$v['note']}', + Other_MikroDetailsIsActive = 'Y', + Other_MikroDetailsUserID = {$userid} + WHERE + Other_MikroDetailsID = {$v['xid']}"; + //echo $sql; + $query = $this->db_smartone->query($sql); + } + } + } + + + $result = array("total" => 1, "records" => array(), "sql"=> ''); + $this->sys_ok($result); + exit; + } + + + function get_doctors_preparasi_sperma() + { + $prm = $this->sys_input; + // $id = $prm["id"]; + + $sql = " SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 10 AND + M_DoctorSOIsActive = 'Y' + ORDER BY M_DoctorName ASC"; + //echo $sql; + $query = $this->db_smartone->query($sql); + $rows = $query->result_array(); + $sql = " + SELECT '0' as id, 'Belum memilih metode' as name + UNION + SELECT M_MethodeSpermaID as id, M_MethodeSpermaName as name + FROM m_methodesperma + WHERE + M_MethodeSpermaIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $methodes = $this->db_smartone->query($sql)->result_array(); + + + $this->sys_ok(["records"=>$rows,"methodes"=>$methodes]); + + } + + + function getpreparasispermaresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT other_preparasisperma.*, + Other_PreparasiSpermaID as xid, + Other_PreparasiSpermaT_OrderDetailID as orderdetail_id, + IFNULL(Other_PreparasiSpermaM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_PreparasiSpermaM_DoctorID) OR Other_PreparasiSpermaM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name, + IFNULL(M_MethodeSpermaID,0) as methode_id, + IFNULL(M_MethodeSpermaName,'') as methode_name + FROM other_preparasisperma + LEFT JOIN m_doctor ON Other_PreparasiSpermaM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + LEFT JOIN m_methodesperma ON Other_PreparasiSpermaM_MethodeSpermaID = M_MethodeSpermaID AND + M_MethodeSpermaIsActive = 'Y' + WHERE + Other_PreparasiSpermaT_OrderDetailID = {$id} AND Other_PreparasiSpermaIsActive = 'Y' + GROUP BY Other_PreparasiSpermaID"; + $query = $this->db_smartone->query($sql); + + if ($query) + { + $rows = $query->row_array(); + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 10 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $sql = " + SELECT '0' as id, 'Belum memilih metode' as name + UNION + SELECT M_MethodeSpermaID as id, M_MethodeSpermaName as name + FROM m_methodesperma + WHERE + M_MethodeSpermaIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $methodes = $this->db_smartone->query($sql)->result_array(); + $images = array(); + $sql = "SELECT Other_PreparasiSpermaImgID as xid, + Other_PreparasiSpermaImgType as type, + CONCAT('/one-media/one-image-nonlab/',Other_PreparasiSpermaImgNewName) as image_url + FROM t_orderdetail + JOIN other_preparasisperma_img ON Other_PreparasiSpermaImgT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND + Other_PreparasiSpermaImgIsActive = 'Y' + WHERE + T_OrderDetailID = {$id} AND + T_OrderDetailIsActive = 'Y' + GROUP BY Other_PreparasiSpermaImgID"; + //echo $sql; + $images = $this->db_smartone->query($sql)->result_array(); + + $rst = array('doctors'=>$doctors,'methodes'=>$methodes,'results'=>$rows,'images'=>$images); + $this->sys_ok(["records"=>$rst]); + } + else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + + function uploadimage_preparasi_sperma(){ + if (! $this->isLogin) { + $this->sys_error("Invalid Token"); + exit; + } + + $userid = $this->sys_user["M_UserID"]; + $data = []; + //print_r($_SERVER); + + $prm = $this->sys_input; + $orderid = $this->input->post('orderid'); + $type = $this->input->post('type'); + $labnumber = $this->input->post('labnumber'); + $sql = "UPDATE other_preparasisperma_img SET + Other_PreparasiSpermaImgIsActive = 'N', + Other_PreparasiSpermaImgUserID = {$userid} + WHERE + Other_PreparasiSpermaImgT_OrderHeaderID = {$orderid} AND + Other_PreparasiSpermaImgType = '{$type}'"; + //echo $sql; + $this->db_onedev->query($sql); + //$config['upload_path'] = 'assets/'; + + $path = '/home/one/project/one/one-media/one-image-nonlab/'; + //echo $path; + $config['upload_path'] = $path; + $config['allowed_types'] = 'jpg|jpeg|png|gif'; + + $config['max_size'] = '10000'; + $count = count($_FILES['files']['name']); + //echo $count; + $this->load->library('upload',$config); + + $error = []; + for($i=0;$i<$count;$i++){ + + + if(!empty($_FILES['files']['name'][$i])){ + + + + $_FILES['file']['name'] = $_FILES['files']['name'][$i]; + + $_FILES['file']['type'] = $_FILES['files']['type'][$i]; + + $_FILES['file']['tmp_name'] = $_FILES['files']['tmp_name'][$i]; + + $_FILES['file']['error'] = $_FILES['files']['error'][$i]; + + $_FILES['file']['size'] = $_FILES['files']['size'][$i]; + + + + $namex = $orderid.'-'.$labnumber.'-'.$this->generateRandomString(5); + //echo $namex; + + $config['file_name'] = $namex; + $this->upload->initialize($config); + //echo $config['file_name'] ; + + + + + + if($this->upload->do_upload('file')){ + + $uploadData = $this->upload->data(); + + $filename = $uploadData['file_name']; + //echo $filename; + + + $sql = "INSERT INTO other_preparasisperma_img ( + Other_PreparasiSpermaImgT_OrderHeaderID, + Other_PreparasiSpermaImgType, + Other_PreparasiSpermaImgOldName, + Other_PreparasiSpermaImgNewName, + Other_PreparasiSpermaImgCreated, + Other_PreparasiSpermaImgUserID + ) + VALUES( + {$orderid}, + '{$type}', + '{$_FILES['files']['name'][$i]}', + '{$filename}', + NOW(), + {$userid} + + )"; + //echo $sql; + $this->db_onedev->query($sql); + $xlast_id = $this->db_onedev->insert_id(); + $data['totalFiles'][] = array('xid' => $xlast_id ,'type'=>$type,'image_url' => '/one-media/one-image-nonlab/'.$filename); + + } + else{ + $error = array('error' => $this->upload->display_errors()); + } + + } + + + + } + + $result = array("total" =>count( $data['totalFiles']), "records" => $data['totalFiles'],'errors'=>$error); + $this->sys_ok($result); + } + + + function saveresult_preparasi_sperma() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = $inp['doctor']; + $orderdetail_id = $inp['orderdetailid']; + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + if($prm['xid'] == '0'){ + $sql = "INSERT INTO other_preparasisperma( + Other_PreparasiSpermaM_DoctorID, + Other_PreparasiSpermaT_OrderDetailID, + Other_PreparasiSpermaPreMotilitasA, + Other_PreparasiSpermaPreMotilitasB, + Other_PreparasiSpermaPreMotilitasC, + Other_PreparasiSpermaPreKonsentrasi, + Other_PreparasiSpermaPreKontaminan, + Other_PreparasiSpermaPostMotilitasA, + Other_PreparasiSpermaPostMotilitasB, + Other_PreparasiSpermaPostMotilitasC, + Other_PreparasiSpermaPostKonsentrasi, + Other_PreparasiSpermaPostKontaminan, + Other_PreparasiSpermaPreVolume, + Other_PreparasiSpermaPostVolume, + Other_PreparasiSpermaM_MethodeSpermaID, + Other_PreparasiSpermaNote, + Other_PreparasiSpermaUserID, + Other_PreparasiSpermaCreated + ) + VALUES( + {$doctor_id}, + {$orderdetail_id}, + '{$prm['Other_PreparasiSpermaPreMotilitasA']}', + '{$prm['Other_PreparasiSpermaPreMotilitasB']}', + '{$prm['Other_PreparasiSpermaPreMotilitasC']}', + '{$prm['Other_PreparasiSpermaPreKonsentrasi']}', + '{$prm['Other_PreparasiSpermaPreKontaminan']}', + '{$prm['Other_PreparasiSpermaPostMotilitasA']}', + '{$prm['Other_PreparasiSpermaPostMotilitasB']}', + '{$prm['Other_PreparasiSpermaPostMotilitasC']}', + '{$prm['Other_PreparasiSpermaPostKonsentrasi']}', + '{$prm['Other_PreparasiSpermaPostKontaminan']}', + '{$prm['Other_PreparasiSpermaPreVolume']}', + '{$prm['Other_PreparasiSpermaPostVolume']}', + '{$prm['Other_PreparasiSpermaM_MethodeSpermaID']}', + '{$prm['Other_PreparasiSpermaNote']}', + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } + else{ + $sql = "SELECT * FROM other_preparasisperma WHERE Other_PreparasiSpermaT_OrderDetailID = {$orderdetail_id} AND Other_PreparasiSpermaIsActive = 'Y'"; + $data_header = $this->db_smartone->query($sql)->row_array(); + $header_id = $data_header['Other_PreparasiSpermaID']; + $sql = "UPDATE other_preparasisperma SET + Other_PreparasiSpermaM_DoctorID = {$doctor_id}, + Other_PreparasiSpermaPreMotilitasA = '{$prm['Other_PreparasiSpermaPreMotilitasA']}', + Other_PreparasiSpermaPreMotilitasB = '{$prm['Other_PreparasiSpermaPreMotilitasB']}', + Other_PreparasiSpermaPreMotilitasC = '{$prm['Other_PreparasiSpermaPreMotilitasC']}', + Other_PreparasiSpermaPreKonsentrasi = '{$prm['Other_PreparasiSpermaPreKonsentrasi']}', + Other_PreparasiSpermaPreKontaminan = '{$prm['Other_PreparasiSpermaPreKontaminan']}', + Other_PreparasiSpermaPostMotilitasA = '{$prm['Other_PreparasiSpermaPostMotilitasA']}', + Other_PreparasiSpermaPostMotilitasB = '{$prm['Other_PreparasiSpermaPostMotilitasB']}', + Other_PreparasiSpermaPostMotilitasC = '{$prm['Other_PreparasiSpermaPostMotilitasC']}', + Other_PreparasiSpermaPostKonsentrasi = '{$prm['Other_PreparasiSpermaPostKonsentrasi']}', + Other_PreparasiSpermaPostKontaminan = '{$prm['Other_PreparasiSpermaPostKontaminan']}', + Other_PreparasiSpermaPreVolume = '{$prm['Other_PreparasiSpermaPreVolume']}', + Other_PreparasiSpermaPostVolume = '{$prm['Other_PreparasiSpermaPostVolume']}', + Other_PreparasiSpermaM_MethodeSpermaID = '{$prm['Other_PreparasiSpermaM_MethodeSpermaID']}', + Other_PreparasiSpermaNote = '{$prm['Other_PreparasiSpermaNote']}', + Other_PreparasiSpermaUserID = {$userid} + WHERE + Other_PreparasiSpermaID = {$header_id}"; + $this->db_smartone->query($sql); + } + + + $result = array("total" => 1, "records" => array(), "sql"=> ''); + $this->sys_ok($result); + exit; + } + + function getdnafragmentasiresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT other_dnafragmentasi.*, + Other_DnaFragmentasiID as xid, + Other_DnaFragmentasiT_OrderDetailID as orderdetail_id, + IFNULL(Other_DnaFragmentasiM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_DnaFragmentasiM_DoctorID) OR Other_DnaFragmentasiM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name, + IFNULL(Other_DnaFragmentasiOther_DnaFragmentasiMethodeID,0) as methode_id, + IFNULL(Other_DnaFragmentasiMethodeName,'') as methode_name, + Other_DnaFragmentasiHaloLuas as halo_luas, + Other_DnaFragmentasiHaloSedang as halo_sedang, + Other_DnaFragmentasiHaloSempit as halo_sempit, + Other_DnaFragmentasiTanpaHalo as tanpa_halo, + Other_DnaFragmentasiDFI as dfi, + Other_DnaFragmentasiKesimpulan as kesimpulan, + Other_DnaFragmentasiCatatan as catatan + FROM other_dnafragmentasi + LEFT JOIN m_doctor ON Other_DnaFragmentasiM_DoctorID = M_DoctorID + LEFT JOIN other_dnafragmentasimethode ON Other_DnaFragmentasiOther_DnaFragmentasiMethodeID = Other_DnaFragmentasiMethodeID + WHERE + Other_DnaFragmentasiT_OrderDetailID = {$id} AND Other_DnaFragmentasiIsActive = 'Y' + GROUP BY Other_DnaFragmentasiID + LIMIT 1"; + //echo $sql; + $query = $this->db_smartone->query($sql); + + if ($query) + { + $rows = $query->row_array(); + if(!$rows){ + $rows = array( + 'xid' => 0, + 'orderdetail_id' =>$id, + 'doctor_id' => 0, + 'doctor_name' => '', + 'methode_id' => 0, + 'methode_name' => '', + 'halo_luas' => '', + 'halo_sedang' => '', + 'tanpa_halo' => '', + 'dfi' => '', + 'kesimpulan' => '', + 'catatan' => '' + ); + } + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID + WHERE + M_DoctorSONat_SubGroupID = 4 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + + $sql = " + SELECT '0' as id, 'Belum memilih metode' as name + UNION + SELECT Other_DnaFragmentasiMethodeID as id, Other_DnaFragmentasiMethodeName as name + FROM other_dnafragmentasimethode + WHERE + Other_DnaFragmentasiMethodeIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $methodes = $this->db_smartone->query($sql)->result_array(); + + + $rst = array('doctors'=>$doctors,'methodes'=>$methodes,'results'=>$rows); + $this->sys_ok(["records"=>$rst]); + } + else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + function saveresult_dnafragmentasi() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = $inp['doctor']['id']; + $methode_id = $inp['methode']['id']; + $orderdetail_id = $inp['results']['orderdetail_id']; + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + if(intval($prm['xid']) == 0){ + $sql = "INSERT INTO other_dnafragmentasi( + Other_DnaFragmentasiT_OrderDetailID, + Other_DnaFragmentasiM_DoctorID, + Other_DnaFragmentasiOther_DnaFragmentasiMethodeID, + Other_DnaFragmentasiHaloLuas, + Other_DnaFragmentasiHaloSedang, + Other_DnaFragmentasiHaloSempit, + Other_DnaFragmentasiTanpaHalo, + Other_DnaFragmentasiDFI, + Other_DnaFragmentasiKesimpulan, + Other_DnaFragmentasiCatatan, + Other_DnaFragmentasiUserID, + Other_DnaFragmentasiLastUpdated + ) + VALUES( + {$orderdetail_id}, + {$doctor_id}, + {$methode_id}, + '{$prm['halo_luas']}', + '{$prm['halo_sedang']}', + '{$prm['halo_sempit']}', + '{$prm['tanpa_halo']}', + '{$prm['dfi']}', + '{$prm['kesimpulan']}', + '{$prm['catatan']}', + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } + else{ + $sql = "UPDATE other_dnafragmentasi SET + Other_DnaFragmentasiT_OrderDetailID = {$orderdetail_id}, + Other_DnaFragmentasiM_DoctorID = {$doctor_id}, + Other_DnaFragmentasiOther_DnaFragmentasiMethodeID = '{$methode_id}', + Other_DnaFragmentasiHaloLuas = '{$prm['halo_luas']}', + Other_DnaFragmentasiHaloSedang = '{$prm['halo_sedang']}', + Other_DnaFragmentasiHaloSempit = '{$prm['halo_sempit']}', + Other_DnaFragmentasiTanpaHalo = '{$prm['tanpa_halo']}', + Other_DnaFragmentasiDFI = '{$prm['dfi']}', + Other_DnaFragmentasiKesimpulan = '{$prm['kesimpulan']}', + Other_DnaFragmentasiCatatan = '{$prm['catatan']}', + Other_DnaFragmentasiLastUpdated = NOW(), + Other_DnaFragmentasiUserID = {$userid} + WHERE + Other_DnaFragmentasiID = {$prm['xid']}"; + //echo $sql; + $this->db_smartone->query($sql); + } + + + $result = array("total" => 1, "records" => array(), "sql"=> ''); + $this->sys_ok($result); + exit; + } + + +} + diff --git a/application/controllers/mockup/process/resultvalidation-v21/Re_px.php b/application/controllers/mockup/process/resultvalidation-v21/Re_px.php index d2c44b96..df562286 100644 --- a/application/controllers/mockup/process/resultvalidation-v21/Re_px.php +++ b/application/controllers/mockup/process/resultvalidation-v21/Re_px.php @@ -1,2495 +1,2492 @@ -db_smartone = $this->load->database("onedev", true); - $this->load->helper(array('form', 'url')); - } - function getMethodeID($natTestID) { - $sql = "select M_MethodePriorityNat_MethodeID MethodeID, Nat_MethodeName - from - m_methode_priority - join nat_methode on Nat_MethodeID = M_MethodePriorityNat_MethodeID - and Nat_MethodeIsActive = 'Y' - join m_instrumentmethode on M_InstrumentMethodeNat_MethodeID = Nat_MethodeID and M_InstrumentMethodeIsActive = 'Y' - join nat_instrument on M_InstrumentMethodeNat_InstrumentID = Nat_InstrumentID - and Nat_InstrumentIsActive ='Y' - where M_MethodePriorityIsActive = 'Y' - and M_MethodePriorityNat_TestID = $natTestID - and M_MethodePriorityM_DayOfWeekID = dayofweek(now()) - order by M_MethodePriorityNumber desc - limit 0,1 "; - $qry = $this->db->query($sql); - if ($qry) { - $rows = $qry->result_array(); - if (count($rows) > 0 ) return array($rows[0]["MethodeID"],$rows[0]["Nat_MethodeName"]); - } - //2nd - $sql= "select - M_InstrumentMethodeNat_MethodeID MethodeID, Nat_MethodeName - from m_instrumentmethode - join nat_methode on M_InstrumentMethodeNat_MethodeID = Nat_MethodeID - and Nat_MethodeIsActive = 'Y' - join nat_instrument on M_InstrumentMethodeNat_InstrumentID = Nat_InstrumentID - and Nat_InstrumentIsActive ='Y' - where M_InstrumentMethodeNat_TestID = $natTestID - and M_InstrumentMethodeIsActive = 'Y' - order by M_InstrumentMethodePriority desc - limit 0,1"; - $qry = $this->db->query($sql); - if ($qry) { - $rows = $qry->result_array(); - if (count($rows) > 0 ) return array($rows[0]["MethodeID"],$rows[0]["Nat_MethodeName"]); - } - // - $sql = "select Nat_NormalValueNat_MethodeID MethodeID, Nat_MethodeName - from - nat_normalvalue - join nat_methode on Nat_NormalValueNat_MethodeID = Nat_MethodeID - and Nat_MethodeIsActive = 'Y' - where Nat_NormalValueNat_TestID = $natTestID - and Nat_NormalValueIsActive = 'Y' - order by Nat_NormalValueID - limit 0,1"; - $qry = $this->db->query($sql); - if ($qry) { - $rows = $qry->result_array(); - if (count($rows) > 0 ) return array($rows[0]["MethodeID"],$rows[0]["Nat_MethodeName"]); - } - return array(0,""); - } - function get_normal_value($methodeID, $natTestID, $sexID, $ageInDay ) { - $sql = "select fn_sampling_get_normal($methodeID, $natTestID, $sexID, $ageInDay) as normalValueID"; - $qry = $this->db->query($sql); - if ($qry) { - $rows = $qry->result_array(); - if (count($rows) > 0 ) return $rows[0]["normalValueID"]; - } - return 0; - } - function fn_fix_normal($order_id) { - $sql = "select - T_OrderDetailID, M_PatientM_SexID, fn_global_age_count_day(M_PatientDOB, date(T_OrderHeaderDate)) Dob , - T_TestNat_TestID - from t_orderheader - join m_patient on T_OrderHeaderID = $order_id and T_OrderHeaderM_PatientID = M_PatientID - join t_orderdetail on T_OrderDetailT_OrderHeaderID = T_OrderHeaderID - and T_OrderDetailIsACtive = 'Y' - and ( T_OrderDetailNat_NormalValueID is null or T_OrderDetailNat_NormalValueID = 0 ) - join t_test on T_OrderDetailT_TestID = T_TestID and T_TestIsResult = 'Y' "; - $qry = $this->db->query($sql); - if(! $qry) { - return; - } - $rows = $qry->result_array(); - if(count($rows) == 0 ) return; - $sql_u = "update t_orderdetail - join nat_normalvalue on T_OrderDetailID = ? and Nat_NormalValueID = ? - set - T_OrderDetailNat_NormalValueID = Nat_NormalValueID, - T_OrderDetailNormalValueNote = Nat_NormalValueNote, - T_OrderDetailNormalValueDescription = Nat_NormalValueDescription, - T_OrderDetailMinValue = Nat_NormalValueMinValue, - T_OrderDetailMaxValue = Nat_NormalValueMaxValue, - T_OrderDetailMinValueInclusive = Nat_NormalValueMinValueInclusive, - T_OrderDetailMaxValueInclusive = Nat_NormalValueMaxValueInclusive, - T_OrderDetailNat_MethodeID = ?, - T_OrderdetailNat_MethodeName =?"; - - foreach($rows as $r) { - $T_OrderDetailID = $r["T_OrderDetailID"]; - $sexID = $r["M_PatientM_SexID"]; - $ageInDay = $r["Dob"]; - $natTestID = $r["T_TestNat_TestID"]; - list($methodeID,$methodeName) = $this->getMethodeID($natTestID); - if ($methodeID == 0 ) continue; - $normalValueID = $this->get_normal_value($methodeID, $natTestID, $sexID, $ageInDay); - if ($normalValueID == 0) return; - $this->db->query($sql_u, array($T_OrderDetailID, $normalValueID, $methodeID, $methodeName)); - } - } - function update_order_sample($targetID, $sourceID) { - $sql = "update t_ordersample target - join t_ordersample source on - target.T_OrderSampleID = ? - and target.T_OrderSampleWorklistReceive = 'N' - and source.T_OrderSampleID = ? - set - target.T_OrderSampleSampling = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSampling, source.T_OrderSampleSampling), - target.T_OrderSampleSamplingDate = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingDate, source.T_OrderSampleSamplingDate), - target.T_OrderSampleSamplingTime = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingTime, source.T_OrderSampleSamplingTime), - target.T_OrderSampleSamplingUserID = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingUserID, source.T_OrderSampleSamplingUserID), - - target.T_OrderSampleReceive = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceive, source.T_OrderSampleReceive), - target.T_OrderSampleReceiveDate = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveDate, source.T_OrderSampleReceiveDate), - target.T_OrderSampleReceiveTime = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveTime, source.T_OrderSampleReceiveTime), - target.T_OrderSampleReceiveUserID = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveUserID, source.T_OrderSampleReceiveUserID), - - target.T_OrderSampleVerification = if(target.T_OrderSampleVerification='Y',target.T_OrderSampleVerification, source.T_OrderSampleVerification), - target.T_OrderSampleVerificationDate =if(target.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationDate, source.T_OrderSampleVerificationDate), - target.T_OrderSampleVerificationTime =if(source.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationTime, source.T_OrderSampleVerificationTime), - target.T_OrderSampleVerificationUserID =if(source.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationUserID, source.T_OrderSampleVerificationUserID), - - target.T_OrderSampleProcessing = if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessing, source.T_OrderSampleProcessing), - target.T_OrderSampleProcessingDate= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingDate, source.T_OrderSampleProcessingDate), - target.T_OrderSampleProcessingTime= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingTime, source.T_OrderSampleProcessingTime), - target.T_OrderSampleProcessingUserID= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingUserID, source.T_OrderSampleProcessingUserID), - - target.T_OrderSampleReceiveHandling =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandling, source.T_OrderSampleReceiveHandling ), - target.T_OrderSampleReceiveHandlingDate =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingDate, source.T_OrderSampleReceiveHandlingDate), - target.T_OrderSampleReceiveHandlingTime =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingTime, source.T_OrderSampleReceiveHandlingTime), - target.T_OrderSampleReceiveHandlingUserID =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingUserID, source.T_OrderSampleReceiveHandlingUserID), - - target.T_OrderSampleHandling = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandling, source.T_OrderSampleHandling), - target.T_OrderSampleHandlingDate = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingDate, source.T_OrderSampleHandlingDate), - target.T_OrderSampleHandlingTime = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingTime, source.T_OrderSampleHandlingTime), - target.T_OrderSampleHandlingUserID = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingUserID, source.T_OrderSampleHandlingUserID), - - target.T_OrderSampleWorklistReceive = source.T_OrderSampleWorklistReceive, - target.T_OrderSampleWorklistReceiveDatetime = source.T_OrderSampleWorklistReceiveDateTime, - target.T_OrderSampleWorklistReceiveUserID = source.T_OrderSampleWorklistReceiveUserID - "; - $qry = $this->db->query($sql,array($targetID,$sourceID)); - if(! $qry ) { - echo json_encode(array( "status" => "ERR" , "message" => print_r($this->db->error(),true))); - exit; - } - } - function fix_sample_serum($headerID) { - //cari t_ordersample yg belum worklist receive dengan code 017% - $sql = "select T_OrderSampleID - from t_ordersample - join t_sampletype on - T_OrderSampleT_OrderHeaderID = ? - and T_OrderSampleWorklistReceive = 'N' - and T_OrderSampleIsActive = 'Y' - and T_OrderSampleT_SampleTypeID = T_SampletypeID - and T_SampleTypeCode like '017%' - "; - $qry = $this->db->query($sql, array($headerID)); - if(!$qry) { - echo json_encode(array( "status" => "ERR" , "message" => print_r($this->db->error(),true))); - exit; - } - $rows = $qry->result_array(); - if (count($rows) == 0 ) return; - //cari T_OrderSample yang sudah di receive yg terakhir - $sql = "select T_OrderSampleID - from t_ordersample - join t_sampletype on - T_OrderSampleT_OrderHeaderID = ? - and T_OrderSampleWorklistReceive = 'Y' - and T_OrderSampleIsActive = 'Y' - and T_OrderSampleT_SampleTypeID = T_SampletypeID - and T_SampleTypeCode like '017%' - order by T_OrderSampleWorklistReceiveDatetime desc - limit 0,1 - "; - $qry = $this->db->query($sql, array($headerID)); - if(!$qry) { - echo json_encode(array( "status" => "ERR" , "message" => print_r($this->db->error(),true))); - exit; - } - $rcv_rows = $qry->result_array(); - if (count($rcv_rows) == 0 ) return; - - //print_r($rows); - //print_r($rcv_rows); - $rcv_T_OrderSampleID = $rcv_rows[0]["T_OrderSampleID"]; - //ada yg belum di receive - foreach($rows as $r) { - $T_OrderSampleID = $r["T_OrderSampleID"]; - $this->update_order_sample($T_OrderSampleID,$rcv_T_OrderSampleID); - } - } - public function search() - { - $prm = $this->sys_input; - $max_rst = 99; - - $id = $prm["order_id"]; - if ($id > 0 ) { - $this->fix_sample_serum($id); - $this->fn_fix_normal($id); - } - $lang = $this->lang_default_code; - $lang_id = isset($prm['lang_id']) ? $prm['lang_id'] : '0'; - - if ($lang_id != 0) - { - $l = $this->db_smartone->where("Nat_LangID", $lang_id)->get("nat_lang")->row(); - $lang = $l->Nat_LangCode; - } - - //tambahan fajri - $sql = " UPDATE t_orderdetail - JOIN t_test ON T_OrderDetailT_TestID = T_TestID - SET T_OrderDetailT_TestIsResult = T_TestIsResult - WHERE - T_OrderDetailT_OrderHeaderID = {$id} AND - T_OrderDetailT_TestIsResult = '' AND - T_OrderDetailIsActive = 'Y'"; - $this->db_smartone->query($sql); - - $tot_count = 0; - $lq = ""; - $group_id = 0; - if (isset($prm['group_id'])) - $group_id = $prm['group_id']; - - if ($group_id != 0) - { - $sql = "select distinct T_WorklistDetailNat_TestID Nat_TestID - from t_worklistdetailv2 - where T_WorklistDetailT_WorklistID = {$group_id}"; - $qry = $this->db_smartone->query($sql); - $rows = $qry->result_array(); - $nat_test_ids = "0"; - foreach($rows as $r) { - $nat_test_ids .= ", " . $r["Nat_TestID"]; - } - $q_group = " ( $nat_test_ids ) "; - - $sql = " - SELECT a1.*, cOUNT(a2.T_OrderDetailID) level - FROM ( - SELECT IFNULL(y.T_OrderDetailT_TestID, x.T_OrderDetailT_TestID) t_testid, - IFNULL(y.T_OrderDetailT_TestName, y.T_OrderDetailT_TestName) t_testname, - y.T_OrderDetailResult result, y.T_OrderDetailResult result_old, y.T_OrderDetailNote note, y.T_OrderDetailNote note_old, - y.T_OrderDetailID id, - y.T_OrderDetailT_TestIsResult is_result, a.T_TestIsQuantitative is_quantitative, - y.T_OrderDetailResultFlag result_flag, - y.T_OrderDetailNat_NormalValueID normal_id, - y.T_OrderDetailNormalValueNote normal_note, y.T_OrderDetailNat_UnitName unit_name, - y.T_OrderdetailNat_MethodeID methode_id, y.T_OrderdetailNat_MethodeName methode_name, - a.T_TestNat_TestID nattest_id, a.T_TestID tx_id, count(T_ResultInstrumentID) as result_instrument_n, - y.T_OrderDetailVerification, T_OrderSampleReceive sample_receive, - T_OrderSampleProcessing sample_processing, T_OrderSampleWorklistReceive sample_worklist_receive, - IF(T_OrderDetailAddOnPreAnalytic = 'Y', T_OrderDetailAddOnPreAnalytic, PreAnalyticIsOk) pre_analytic, - T_OrderDetailAddOnPreAnalytic, - T_OrderHeaderID order_id, y.T_OrderDetailT_TestSasCode test_sas_code, - tx.T_TestSasCode, - T_OrderDetailAddOnResample `resample`, T_OrderDetailAddOnResampleStatus resample_status, - T_OrderDetailAddOnRef ref, y.T_OrderDetailVerification verification, y.T_OrderDetailValidation validation, - T_OrderPromiseDateTime, Group_ResultName as ResultGroupName - FROM t_orderdetail x - left join t_orderpromise on x.T_OrderDetailT_OrderPromiseID = T_OrderPromiseID - JOIN t_test tx ON x.T_OrderDetailT_TestID = T_TestID - JOIN t_test tcheck on tcheck.T_TestNat_TestID in {$q_group} - and ( tx.T_TestID = tcheck.T_TestID or tx.T_TestSasCode like concat(tcheck.T_TestSasCode,'%')) - LEFT JOIN group_resultdetail ON Group_ResultDetailT_TestID = x.T_OrderDetailT_TestID AND Group_ResultDetailIsActive = 'Y' - LEFT JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND Group_ResultFlagNonLab = 'N' - LEFT JOIN t_orderdetail y ON x.T_OrderDetailT_TestSasCode LIKE CONCAT(y.T_OrderDetailT_TestSasCode, '%') - AND x.T_OrderDetailT_OrderHeaderID = y.T_OrderDetailT_OrderHeaderID - AND y.T_OrderDetailIsActive = 'Y' - LEFT JOIN t_orderdetailaddon ON x.T_OrderDetailID = T_OrderDetailAddOnT_OrderDetailID - JOIN t_orderheader ON y.T_OrderDetailT_OrderHeaderID = T_OrderHeaderID - LEFT JOIN t_test a ON y.T_OrderDetailT_TestID = a.T_TestID - AND a.T_TestIsNonLab = '' - LEFT JOIN (SELECT T_OrderSampleT_SampleTypeID, T_OrderSampleReceive, T_OrderSampleProcessing, T_OrderSampleWorklistReceive - FROM t_ordersample WHERE T_OrderSampleT_OrderHeaderID = {$id} - AND T_OrderSampleIsactive = 'Y' - GROUP BY T_OrderSampleT_SampleTypeID) os ON a.T_TestT_SampleTypeID = os.T_OrderSampleT_SampleTypeID - or os.T_OrderSampleT_SampleTypeID = fn_sampletype_from_local(a.T_TestNat_TestID) - - LEFT JOIN t_resultinstrument ON T_ResultInstrumentT_OrderDetailID = x.T_OrderDetailID - LEFT JOIN pre_analytic ON PreAnalyticNat_TestID = a.T_TestNat_TestID AND PreAnalyticDate = date(now()) and PreAnalyticIsActive = 'Y' - WHERE x.T_OrderDetailT_OrderHeaderID = {$id} - AND x.T_OrderDetailIsActive = 'Y' - GROUP BY y.T_OrderDetailT_TestID - ORDER BY y.T_OrderDetailT_TestSasCode ASC - ) a1 - - LEFT JOIN t_orderdetail a2 ON a2.T_OrderDetailT_OrderHeaderID = a1.order_id - AND a2.T_OrderDetailIsActive = 'Y' - AND a1.test_sas_code LIKE CONCAT(a2.T_OrderDetailT_testSasCode, '%') - GROUP BY a1.t_testid - order by a1.test_sas_code -"; - $query = $this->db_smartone->query($sql); - $lq = $this->db_smartone->last_query(); - } - else - { - $sql = " - SELECT a1.*, cOUNT(a2.T_OrderDetailID) level - FROM ( - SELECT IFNULL(y.T_OrderDetailT_TestID, x.T_OrderDetailT_TestID) t_testid, - IFNULL(y.T_OrderDetailT_TestName, y.T_OrderDetailT_TestName) t_testname, - y.T_OrderDetailResult result, y.T_OrderDetailResult result_old, y.T_OrderDetailNote note, y.T_OrderDetailNote note_old, - y.T_OrderDetailID id, - y.T_OrderDetailT_TestIsResult is_result, a.T_TestIsQuantitative is_quantitative, - y.T_OrderDetailResultFlag result_flag, - y.T_OrderDetailNat_NormalValueID normal_id, - y.T_OrderDetailNormalValueNote normal_note, y.T_OrderDetailNat_UnitName unit_name, - y.T_OrderdetailNat_MethodeID methode_id, y.T_OrderdetailNat_MethodeName methode_name, - a.T_TestNat_TestID nattest_id, a.T_TestID tx_id, count(T_ResultInstrumentID) as result_instrument_n, - y.T_OrderDetailVerification, T_OrderSampleReceive sample_receive, - T_OrderSampleProcessing sample_processing, T_OrderSampleWorklistReceive sample_worklist_receive, - IF(T_OrderDetailAddOnPreAnalytic = 'Y', T_OrderDetailAddOnPreAnalytic, PreAnalyticIsOk) pre_analytic, - T_OrderDetailAddOnPreAnalytic, - T_OrderHeaderID order_id, y.T_OrderDetailT_TestSasCode test_sas_code, - tx.T_TestSasCode, - T_OrderDetailAddOnResample `resample`, T_OrderDetailAddOnResampleStatus resample_status, - T_OrderDetailAddOnRef ref, y.T_OrderDetailVerification verification, y.T_OrderDetailValidation validation, - T_OrderPromiseDateTime , Group_ResultName as ResultGroupName - FROM t_orderdetail x - left join t_orderpromise on x.T_OrderDetailT_OrderPromiseID = T_OrderPromiseID - JOIN t_test tx ON x.T_OrderDetailT_TestID = T_TestID - LEFT JOIN group_resultdetail ON Group_ResultDetailT_TestID = x.T_OrderDetailT_TestID AND Group_ResultDetailIsActive = 'Y' - LEFT JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND Group_ResultFlagNonLab = 'N' - LEFT JOIN t_orderdetail y ON x.T_OrderDetailT_TestSasCode LIKE CONCAT(y.T_OrderDetailT_TestSasCode, '%') - AND x.T_OrderDetailT_OrderHeaderID = y.T_OrderDetailT_OrderHeaderID - AND y.T_OrderDetailIsActive = 'Y' - - LEFT JOIN t_orderdetailaddon ON x.T_OrderDetailID = T_OrderDetailAddOnT_OrderDetailID - - JOIN t_orderheader ON y.T_OrderDetailT_OrderHeaderID = T_OrderHeaderID - LEFT JOIN t_test a ON y.T_OrderDetailT_TestID = a.T_TestID - AND a.T_TestIsNonLab = '' - LEFT JOIN (SELECT T_OrderSampleT_SampleTypeID, T_OrderSampleReceive, T_OrderSampleProcessing, T_OrderSampleWorklistReceive - FROM t_ordersample WHERE T_OrderSampleT_OrderHeaderID = {$id} - AND T_OrderSampleIsactive = 'Y' - GROUP BY T_OrderSampleT_SampleTypeID) os ON a.T_TestT_SampleTypeID = os.T_OrderSampleT_SampleTypeID - or os.T_OrderSampleT_SampleTypeID = fn_sampletype_from_local(a.T_TestNat_TestID) - - LEFT JOIN t_resultinstrument ON T_ResultInstrumentT_OrderDetailID = x.T_OrderDetailID - LEFT JOIN pre_analytic ON PreAnalyticNat_TestID = a.T_TestNat_TestID AND PreAnalyticDate = date(now()) and PreAnalyticIsActive = 'Y' - WHERE x.T_OrderDetailT_OrderHeaderID = {$id} - AND x.T_OrderDetailIsActive = 'Y' - GROUP BY y.T_OrderDetailT_TestID - ORDER BY y.T_OrderDetailT_TestSasCode ASC - ) a1 - - LEFT JOIN t_orderdetail a2 ON a2.T_OrderDetailT_OrderHeaderID = a1.order_id - AND a2.T_OrderDetailIsActive = 'Y' - AND a1.test_sas_code LIKE CONCAT(a2.T_OrderDetailT_testSasCode, '%') - GROUP BY a1.t_testid - order by a1.test_sas_code -"; -//echo $sql; - $query = $this->db_smartone->query($sql); - $lq = $this->db_smartone->last_query(); - } - // file_put_contents("/xtmp/re-query.sql",$lq); - - if ($query) { - $rst = []; - $rows = $query->result_array(); - - foreach($rows as $k => $v) - { - - if ($v['is_result'] == "Y" && $v['is_quantitative'] == "N") - { - $v['template'] = []; - $x = $this->db_smartone->query("CALL sp_master_resulttemplate_get('{$v['t_testid']}')"); - $this->clean_mysqli_connection($this->db_smartone->conn_id); - if ($x) - $v['template'] = $x->result_array(); - } - - // IF Rujukan, by pas Pre Analytik - if ($v['ref'] == 'Y') - $v['pre_analytic'] = 'Y'; - if ($v["id"] == "885455" ) - { - //sipe workaround - //$v["sample_receive"] = "Y"; - $v["sample_worklist_receive"] = "Y"; - } - $rst[] = $v; - } - - $result = array("total" => $tot_count, "records" => $rst, "total_display" => sizeof($rows), "q" => $lq); - $this->sys_ok($result); - } - else { - $this->sys_error_db("RE Px rows", $this->db_smartone); - exit; - } - } - - public function save() - { - $prm = $this->sys_input; - $data = json_decode($prm["data"]); - $lang = $this->lang_default_code; - $lang_id = isset($prm['lang_id']) ? $prm['lang_id'] : '0'; - - if ($lang_id != 0) - { - $l = $this->db_smartone->where("Nat_LangID", $lang_id)->get("nat_lang")->row(); - $lang = $l->Nat_LangCode; - } - - $sql_norm = "select T_OrderDetailMinValue, T_OrderDetailMaxValue, - T_OrderDetailMinValueInclusive, T_OrderDetailMaxValueInclusive, - Nat_TestFlagLow, Nat_TestFlagHigh - from t_orderdetail - join t_test on T_OrderDetailT_TestID = T_TestID - join nat_test on T_TestNat_TestID = Nat_TestID and T_TestIsActive = 'Y' - where T_OrderDetailID = ? "; - - $ids = []; - foreach ($data as $k => $v) - { - if ( $v->resultInstrumentID > 0 ) { - $sql_i = "select T_ResultInstrumentNat_NormalValueID normalValueID - from t_resultinstrument - where T_ResultInstrumentID = ?"; - $qry_i = $this->db_smartone->query($sql_i, array($v->resultInstrumentID)); - if ($qry_i) { - $rows_i = $qry_i->result_array(); - - if (count($rows_i) > 0 ) { - $sql_iu = "update t_orderdetail, nat_normalvalue , nat_methode - set T_OrderDetailMinValue = Nat_NormalValueMinValue, - T_OrderDetailMinValueInclusive = Nat_NormalValueMinValueInclusive, - T_OrderDetailMaxValue = Nat_NormalValueMaxValue , - T_OrderDetailMaxValueInclusive = Nat_NormalValueMaxValueInclusive, - T_OrderDetailNormalValueNote = Nat_NormalValueNote, - T_OrderDetailNormalValueDescription = Nat_NormalValueDescription, - T_OrderDetailNat_NormalValueID = Nat_NormalValueID, - T_OrderDetailNat_MethodeID = Nat_NormalValueNat_MethodeID, - T_OrderDetailNat_MethodeName = Nat_MethodeName - where T_OrderDetailID = ? and Nat_NormalValueID = ? - and Nat_NormalValueNat_MethodeID = Nat_MethodeID - "; - $this->db_smartone->query($sql_iu, array($v->id, $rows_i[0]["normalValueID"])); - //file_put_contents("/xtmp/update-nilai-normal", $this->db_smartone->last_query() . "\n", FILE_APPEND); - } - } - } - $y = $this->db_smartone->query("SELECT fn_process_sample_handling_perfect('{$v->order_id}', '{$v->test_id}') c") - ->row(); - $req_status = $y->c; - $qry_norm = $this->db_smartone->query($sql_norm,$v->id); - $result_flag = ""; - if ($qry_norm) { - $rows_norm = $qry_norm->result_array(); - if (count($rows_norm) > 0 ) { - $r = $rows_norm[0]; - if (is_numeric($v->result)) { - - if ( $r["T_OrderDetailMinValueInclusive"] == "Y" && $v->result < $r["T_OrderDetailMinValue"] ) { - $result_flag = $r["Nat_TestFlagLow"]; - } - if ( $r["T_OrderDetailMinValueInclusive"] == "N" && $v->result <= $r["T_OrderDetailMinValue"] ) { - $result_flag = $r["Nat_TestFlagLow"]; - } - if ( $r["T_OrderDetailMaxValueInclusive"] == "Y" && $v->result > $r["T_OrderDetailMaxValue"] ) { - $result_flag = $r["Nat_TestFlagHigh"]; - } - if ( $r["T_OrderDetailMaxValueInclusive"] == "N" && $v->result >= $r["T_OrderDetailMaxValue"] ) { - $result_flag = $r["Nat_TestFlagHigh"]; - } - } - } - } - if ($lang == $this->lang_default_code) - { - $this->db_smartone->set('T_OrderDetailResult', $v->result) - ->set('T_OrderDetailResultFlag', $result_flag) - ->set('T_OrderDetailNote', $v->note) - ->set('T_OrderDetailReqStatus', $req_status) - ->where('T_OrderDetailID', $v->id) - ->update('t_orderdetail'); - } - else - { - $this->db_smartone->set('T_OrderDetailLangResult', $v->result) - ->set('T_OrderDetailLangNote', $v->note) - ->where('T_OrderDetailLangID', $v->id) - ->update('t_orderdetaillang'); - } - - $ids[] = $v->id; - } - - // LOG Process - $order = $this->db_smartone->select('T_OrderDetailT_OrderHeaderID id, T_OrderHeaderLabNumber lab_number', false) - ->join('t_orderheader', 'T_OrderHeaderID = T_OrderDetailT_OrderHeaderID') - ->where('T_OrderDetailID', $data[0]->id) - ->get('t_orderdetail') - ->row(); - - $dblog = $this->load->database("onelog", true); - $dblog->set('Log_ProcessCode', 'PROCESS.Result.Entry') - ->set('Log_ProcessOrderID', $order->id) - ->set('Log_ProcessOrderNumber', $order->lab_number) - ->set('Log_ProcessJson', json_encode($data)) - ->set('Log_ProcessUserID', $this->sys_user['M_UserID']) - ->insert('log_process'); - // END OF Log Process - //auto calculation - $this->load->library("Resultcalc"); - $rows = $this->resultcalc->auto($order->id); - - try { - foreach($ids as $id ) { - $this->db_smartone->query("call sp_set_normal_value_flag($id)"); - $this->clean_mysqli_connection($this->db_smartone->conn_id); - } - } catch(Exception $e) { - } - - $this->sys_ok($ids); - } - - public function save_template() - { - $prm = $this->sys_input; - - $n = $this->db_smartone->select("COUNT(T_ResultTemplateID) n") - ->where("T_ResultTemplateT_TestID", $prm['test_id']) - ->where("T_ResultTemplateIsActive", "Y") - ->where("T_ResultTemplateValue", $prm['value']) - ->get('t_resulttemplate') - ->row(); - if ($n->n > 0) - { - $this->sys_error_db("Insert Result Template", $this->db_smartone); - return; - } - - $r = $this->db_smartone->set("T_ResultTemplateT_TestID", $prm['test_id']) - ->set("T_ResultTemplateValue", $prm['value']) - ->insert('t_resulttemplate'); - if ($r) - { - $template = []; - $x = $this->db_smartone->query("CALL sp_master_resulttemplate_get('{$prm['test_id']}')"); - $this->clean_mysqli_connection($this->db_smartone->conn_id); - if ($x) - $template = $x->result_array(); - - $this->sys_ok($template); - } - } - - public function export() - { - $prm = $this->sys_input; - - $sql = "CALL sp_process_result_lang(?, ?, ?, ?)"; - $query = $this->db_smartone->query($sql, [$prm['order_id'], $prm['lang_id'], $prm['is_si'], $this->sys_user['M_UserID']]); - if ($query) - { - $r = $query->row(); - if ($r->status == "OK") - { - $this->sys_ok($r->data); - return; - } - - $this->sys_error_db("Message : " . $r->message, $this->db_smartone); - } - else - { - $this->sys_error_db("Lang Result", $this->db_smartone); - return; - } - } - - public function search_group() - { - $prm = $this->sys_input; - $max_rst = 100; - - // QUERY TOTAL - $sql = "select count(*) total - from t_worklist - where T_WorklistIsActive = 'Y' - order by T_WorklistName ASC"; - $query = $this->db_smartone->query($sql); - - if ($query) { - $tot_count = $query->result_array()[0]["total"]; - } - else { - $this->sys_error_db("worklist count", $this->db_smartone); - exit; - } - - $sql = "select T_WorklistID group_id, T_WorklistName group_name - from t_worklist - where T_WorklistIsActive = 'Y' - order by T_WorklistName ASC - limit 0, {$max_rst}"; - $query = $this->db_smartone->query($sql); - - if ($query) { - $rows = $query->result_array(); - foreach ($rows as $k => $v) - $rows[$k]['data'] = json_decode($v['data']); - $result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows), "q" => $this->db_smartone->last_query()); - $this->sys_ok($result); - } - else { - $this->sys_error_db("worklist rows", $this->db_smartone); - exit; - } - } - - public function search_rerun() - { - $prm = $this->sys_input; - $id = $prm["detail_id"]; - - $sql = "CALL sp_process_result_rerun(?)"; - $query = $this->db_smartone->query($sql, [$id]); - - if ($query) - { - $rows = $query->result_array(); - $this->sys_ok(["records"=>$rows]); - } - else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - - - function getdoctorsfna() - { - $prm = $this->sys_input; - // $id = $prm["id"]; - - $sql = " SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY M_DoctorName ASC"; - //echo $sql; - $query = $this->db_smartone->query($sql); - - if ($query) - { - $rows = $query->result_array(); - $this->sys_ok(["records"=>$rows]); - } - else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - function getfnaresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT Other_FNADetailsID as xid, - Other_FNAT_OrderDetailID as orderdetail_id, - Other_FNADetailsCode as code, - Other_FNADetailsLabel as label, - Other_FNADetailsResult as result, - IFNULL(Other_FNAM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_FNAM_DoctorID) OR Other_FNAM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_fna - JOIN other_fnadetails ON Other_FNADetailsOther_FNAID = Other_FNAID AND Other_FNADetailsIsActive = 'Y' - LEFT JOIN m_doctor ON Other_FNAM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_FNAT_OrderDetailID = {$id} AND Other_FNAIsActive = 'Y' - GROUP BY Other_FNADetailsID - ORDER BY Other_FNADetailsCode ASC"; - $query = $this->db_smartone->query($sql); - - if ($query) - { - $rows = $query->result_array(); - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $images = array(); - $sql = "SELECT So_ImageUploadID as xid, - CONCAT('/one-media/one-image-nonlab/',So_ImageUploadNewName) as image_url - FROM t_orderdetail - JOIN so_imageupload ON So_ImageUploadT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND - So_ImageUploadIsActive = 'Y' - WHERE - T_OrderDetailID = {$id} AND - T_OrderDetailIsActive = 'Y' - GROUP BY So_ImageUploadID"; - $images = $this->db_smartone->query($sql)->result_array(); - - $rst = array('doctors'=>$doctors,'results'=>$rows,'images'=>$images); - $this->sys_ok(["records"=>$rst]); - } - else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - - function uploadimage(){ - if (! $this->isLogin) { - $this->sys_error("Invalid Token"); - exit; - } - - $userid = $this->sys_user["M_UserID"]; - $data = []; - //print_r($_SERVER); - - $prm = $this->sys_input; - $orderid = $this->input->post('orderid'); - $labnumber = $this->input->post('labnumber'); - $sql = "UPDATE so_imageupload SET - So_ImageUploadIsActive = 'N', - So_ImageUploadUserID = {$userid} - WHERE - So_ImageUploadT_OrderHeaderID = {$orderid}"; - //echo $sql; - $this->db_onedev->query($sql); - //$config['upload_path'] = 'assets/'; - - $path = '/home/one/project/one/one-media/one-image-nonlab/'; - //echo $path; - $config['upload_path'] = $path; - $config['allowed_types'] = 'jpg|jpeg|png|gif'; - - $config['max_size'] = '10000'; - $count = count($_FILES['files']['name']); - //echo $count; - $this->load->library('upload',$config); - - $error = []; - for($i=0;$i<$count;$i++){ - - - if(!empty($_FILES['files']['name'][$i])){ - - - - $_FILES['file']['name'] = $_FILES['files']['name'][$i]; - - $_FILES['file']['type'] = $_FILES['files']['type'][$i]; - - $_FILES['file']['tmp_name'] = $_FILES['files']['tmp_name'][$i]; - - $_FILES['file']['error'] = $_FILES['files']['error'][$i]; - - $_FILES['file']['size'] = $_FILES['files']['size'][$i]; - - - - $namex = $orderid.'-'.$labnumber.'-'.$this->generateRandomString(5); - //echo $namex; - - $config['file_name'] = $namex; - $this->upload->initialize($config); - //echo $config['file_name'] ; - - - - - - if($this->upload->do_upload('file')){ - - $uploadData = $this->upload->data(); - - $filename = $uploadData['file_name']; - //echo $filename; - - - $sql = "INSERT INTO so_imageupload ( - So_ImageUploadT_OrderHeaderID, - So_ImageUploadT_OrderHeaderLabNumber, - So_ImageUploadT_SampleTypeID, - So_ImageUploadOldName, - So_ImageUploadNewName, - So_ImageUploadCreated, - So_ImageUploadUserID - ) - VALUES( - {$orderid}, - '{$labnumber}', - '150', - '{$_FILES['files']['name'][$i]}', - '{$filename}', - NOW(), - {$userid} - - )"; - //echo $sql; - $this->db_onedev->query($sql); - $xlast_id = $this->db_onedev->insert_id(); - $data['totalFiles'][] = array('xid' => $xlast_id ,'image_url' => '/one-media/one-image-nonlab/'.$filename); - - } - else{ - $error = array('error' => $this->upload->display_errors()); - } - - } - - - - } - - $result = array("total" =>count( $data['totalFiles']), "records" => $data['totalFiles'],'errors'=>$error); - $this->sys_ok($result); - } - - - function generateRandomString($length = 10) { - $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; - $charactersLength = strlen($characters); - $randomString = ''; - for ($i = 0; $i < $length; $i++) { - $randomString .= $characters[rand(0, $charactersLength - 1)]; - } - return $randomString; - } - - function getcytologiresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT Other_CytologiDetailsID as xid, - Other_CytologiT_OrderDetailID as orderdetail_id, - Other_CytologiDetailsCode as code, - Other_CytologiDetailsLabel as label, - Other_CytologiDetailsResult as result, - IFNULL(Other_CytologiM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_CytologiM_DoctorID) OR Other_CytologiM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_cytologi - JOIN other_cytologidetails ON Other_CytologiDetailsOther_CytologiID = Other_CytologiID AND Other_CytologiDetailsIsActive = 'Y' - LEFT JOIN m_doctor ON Other_CytologiM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_CytologiT_OrderDetailID = {$id} AND Other_CytologiIsActive = 'Y' - GROUP BY Other_CytologiDetailsID - ORDER BY Other_CytologiDetailsCode ASC"; - //echo $sql; - $query = $this->db_smartone->query($sql); - - if ($query) - { - $rows = $query->result_array(); - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $rst = array('doctors'=>$doctors,'results'=>$rows); - $this->sys_ok(["records"=>$rst]); - } - else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - function getmikroresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT - Other_MikroID as xid, - Other_MikroHasilBiakan as hasil_biakan, - Other_MikroSampleTypeName as sample_name, - Other_MikroT_OrderDetailID as orderdetail_id, - Other_MikroResult as result_value, - '' as result_other, - IFNULL(T_BacteriaID,0) as T_BacteriaID, - IFNULL(T_BacteriaName,'') as T_BacteriaName, - '' as details, - IFNULL(Other_MikroM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_MikroM_DoctorID) OR Other_MikroM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_mikro - LEFT JOIN t_bacteria ON Other_MikroT_BacteriaID = T_BacteriaID - LEFT JOIN m_doctor ON Other_MikroM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_MikroT_OrderDetailID = {$id} AND Other_MikroIsActive = 'Y' - GROUP BY Other_MikroID"; - //echo $sql; - $query = $this->db_smartone->query($sql); - - if ($query) - { - $row = $query->row_array(); - if($row){ - if($row['result_value'] != 'Positif' && $row['result_value'] != 'Negatif'){ - $row['result_other'] = $row['result_value']; - $row['result_value'] = 'other'; - } - $sql = "SELECT '' as xno, - Other_MikroDetailsID as xid, - Other_MikroDetailsValue as value, - IF(Other_MikroDetailsNote = 'R','Y','N') as chx_r, - IF(Other_MikroDetailsNote = 'I','Y','N') as chx_i, - IF(Other_MikroDetailsNote = 'S','Y','N') as chx_s, - Other_MikroDetailsNote as note, - t_antibiotic.* - FROM other_mikrodetails - LEFT JOIN t_antibiotic ON Other_MikroDetailsT_AntibioticID = T_AntibioticID - WHERE - Other_MikroDetailsOther_MikroID = {$row['xid']} AND Other_MikroDetailsIsActive = 'Y' - GROUP BY Other_MikroDetailsID - ORDER BY T_AntibioticName ASC"; - //echo $sql; - $details = $this->db_smartone->query($sql)->result_array(); - if(details){ - foreach($details as $k => $v){ - $details[$k]['xno'] = $k + 1; - } - } - $row['details'] = $details; - } - else{ - $row = array('xid'=>'0','hasil_biakan' => '','result_value'=>'Negatif','sample_name' => '','orderdetail_id'=>$id, 'T_BacteriaID'=>'0','T_BacteriaName'=>'0','details'=>array(),'doctor_id'=>'0','doctor_name'=>'0'); - } - } - else{ - $row = array('xid'=>'0','hasil_biakan' => '','result_value'=>'Negatif','sample_name' => '','orderdetail_id'=>$id, 'T_BacteriaID'=>'0','T_BacteriaName'=>'0','details'=>array(),'doctor_id'=>'0','doctor_name'=>'0'); - } - //print_r($row); - - - - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 7 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $sql = " - SELECT '0' as id, 'Belum memilih bakteria' as name - UNION - SELECT T_BacteriaID as id, T_BacteriaName as name - FROM t_bacteria - WHERE - T_BacteriaIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $bacteries = $this->db_smartone->query($sql)->result_array(); - $rst = array('doctors'=>$doctors,'bacteries'=>$bacteries,'results'=>$row); - $this->sys_ok(["records"=>$rst]); - } - function getantibiotics(){ - $prm = $this->sys_input; - $id = $prm["id"]; - $sql = " SELECT '' as xno, - 0 as xid, - '' as hasil_biakan, - '' as sample_name, - 0 as value, - 'Y' as chx_r, - 'N' as chx_i, - 'N' as chx_s, - 'R' as note, - t_antibiotic.* - FROM t_antibiotic - WHERE - T_AntibioticT_BacteriaID = {$prm['id']} AND T_AntibioticIsActive= 'Y' - ORDER BY T_AntibioticName ASC"; - //echo $sql; - $rows = $this->db_smartone->query($sql)->result_array(); - if(rows){ - foreach($rows as $k => $v){ - $rows[$k]['xno'] = $k + 1; - } - } - - $this->sys_ok(["records"=>$rows]); - } - function getlcprepresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - $sql = " SELECT Other_LcprepDetailsID as xid, - Other_LcprepID as header_id, - Other_LcprepT_orderDetailID as orderdetail_id, - Other_LcprepDetailsCode as code, - Other_LcprepDetailsLabel as label, - Other_LcprepDetailsResult as result, - IFNULL(Other_LcprepM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_LcprepM_DoctorID) OR Other_LcprepM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_lcprep - JOIN other_lcprepdetails ON Other_LcprepDetailsOther_LcprepID = Other_LcprepID AND Other_LcprepDetailsIsActive = 'Y' - LEFT JOIN m_doctor ON Other_LcprepM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_LcprepT_orderDetailID = {$id} AND Other_LcprepIsActive = 'Y' - GROUP BY Other_LcprepDetailsOther_LcprepID, Other_LcprepDetailsCode - ORDER BY Other_LcprepDetailsCode ASC"; - //echo $sql; - $rows = $this->db_smartone->query($sql)->result_array(); - if(!$rows){ - $rows = array( - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'A', - 'label' => 'DESKRIPSI', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ), - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'B', - 'label' => 'KESIMPULAN', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ) - ); - } - - $header_id = $rows[0]['header_id']; - $sql = "SELECT IFNULL(Other_LcprepAdekuasiID,0) as xid, - Lcprep_AdekuasiID as id, - Lcprep_AdekuasiLabel as name, - IF(ISNULL(Other_LcprepAdekuasiID),'N',Other_LcprepAdekuasiChex) as chex - FROM lcprep_adekuasi - LEFT JOIN other_lcprepadekuasi ON Other_LcprepAdekuasiLcprep_AdekuasiID = Lcprep_AdekuasiID AND - Other_LcprepAdekuasiOther_LcprepID = {$header_id} AND - Other_LcprepAdekuasiIsActive = 'Y' - WHERE - Lcprep_AdekuasiIsActive = 'Y' - GROUP BY Lcprep_AdekuasiID - ORDER BY Lcprep_AdekuasiOrder ASC - "; - //echo $sql; - $adeakuasi = $this->db_smartone->query($sql)->result_array(); - foreach($adeakuasi as $kc => $vc){ - $adeakuasi[$kc]['chex'] = $vc['chex'] == 'N'?false:true; - } - - $sql = "SELECT IFNULL(Other_LcprepKategoriUmumID,0) as xid, - Lcprep_KategoriUmumID as id, - Lcprep_KategoriUmumLabel as name, - IF(ISNULL(Other_LcprepKategoriUmumID),'N',Other_LcprepKategoriUmumChex) as chex - FROM lcprep_kategoriumum - LEFT JOIN other_lcprepkategoriumum ON Other_LcprepKategoriUmumLcprep_KategoriUmumID = Lcprep_KategoriUmumID AND - Other_LcprepKategoriUmumOther_LcprepID = {$header_id} AND - Other_LcprepKategoriUmumIsActive = 'Y' - WHERE - Lcprep_KategoriUmumIsActive = 'Y' - GROUP BY Lcprep_KategoriUmumID - "; - //echo $sql; - $kategoriumum = $this->db_smartone->query($sql)->result_array(); - foreach($kategoriumum as $kc => $vc){ - $kategoriumum[$kc]['chex'] = $vc['chex'] == 'N'?false:true; - } - - $sql = " - SELECT Lcprep_InterpretasiGroupID as group_id, - Lcprep_InterpretasiGroupName as group_name, - '' as subgroups - FROM lcprep_interpretasigroup - WHERE - Lcprep_InterpretasiGroupIsActive = 'Y' - "; - //echo $sql; - $interpretasi = $this->db_smartone->query($sql)->result_array(); - foreach($interpretasi as $k => $v){ - $subgroups = array(); - $sql = "SELECT Lcprep_InterpretasiSubgroupID as subgroup_id, - Lcprep_InterpretasiSubgroupName as subgroup_name, - '' as childs - FROM lcprep_interpretasisubgroup - WHERE - Lcprep_InterpretasiSubgroupLcprep_InterpretasiGroupID = {$v['group_id']} AND Lcprep_InterpretasiSubgroupIsActive = 'Y'"; - //echo $sql; - $subgroups = $this->db_smartone->query($sql)->result_array(); - if(count($subgroups) > 0){ - foreach($subgroups as $ki => $vi){ - $childs = array(); - $sql = "SELECT IFNULL(Other_LcprepInterpretasiID,0) as xid, - IFNULL(Other_LcprepInterpretasiChex,'N') as chex, - IFNULL(Other_LcprepInterpretasiValue,'') as value, - Lcprep_InterpretasiID as id, - Lcprep_InterpretasiLcprep_InterpretasiSubgroupID as subgroup_id, - Lcprep_InterpretasiCode as code, - Lcprep_InterpretasiName as name, - Lcprep_InterpretasiParentID as parent_id, - Lcprep_InterpretasiIsParent as is_parent, - Lcprep_InterpretasiHasResult as has_result, - Lcprep_InterpretasiTypeResult as type_result - FROM lcprep_interpretasi - LEFT JOIN other_lcprepinterpretasi ON Other_LcprepInterpretasiOther_LcprepID = {$header_id} AND - Other_LcprepInterpretasiLcprep_InterpretasiID = Lcprep_InterpretasiID AND - Other_LcprepInterpretasiIsActive = 'Y' - WHERE - Lcprep_InterpretasiLcprep_InterpretasiSubgroupID = {$vi['subgroup_id']} AND Lcprep_InterpretasiIsActive = 'Y' - GROUP BY Lcprep_InterpretasiID Order BY Lcprep_InterpretasiCode ASC"; - $childs = $this->db_smartone->query($sql)->result_array(); - if($childs){ - foreach($childs as $kc => $vc){ - $childs[$kc]['chex'] = $vc['chex'] == 'N'?false:true; - } - } - $subgroups[$ki]['childs'] = $childs; - } - } - - $interpretasi[$k]['subgroups'] = $subgroups; - } - - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $rst = array('doctors'=>$doctors,'results'=>$rows,'adekuasi'=>$adeakuasi,'kategoriumum'=>$kategoriumum,'interpretasi'=>$interpretasi); - $this->sys_ok(["records"=>$rst]); - } - - function getpapsmearresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT Other_PapSmearDetailsID as xid, - Other_PapSmearID as header_id, - Other_PapSmearT_OrderDetailID as orderdetail_id, - Other_PapSmearDetailsCode as code, - Other_PapSmearDetailsLabel as label, - Other_PapSmearDetailsResult as result, - IFNULL(Other_PapSmearM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_PapSmearM_DoctorID) OR Other_PapSmearM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_papsmear - JOIN other_papsmeardetails ON Other_PapSmearDetailsOther_PapSmearID = Other_PapSmearID AND Other_PapSmearDetailsIsActive = 'Y' - LEFT JOIN m_doctor ON Other_PapSmearM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_PapSmearT_OrderDetailID = {$id} AND Other_PapSmearIsActive = 'Y' - GROUP BY Other_PapSmearDetailsID - ORDER BY Other_PapSmearDetailsCode ASC"; - //echo $sql; - $rows = $this->db_smartone->query($sql)->result_array(); - if(!$rows){ - $rows = array( - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'A', - 'label' => 'Makroskopik', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ), - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'B', - 'label' => 'Mikroskopik', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ), - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'C', - 'label' => 'Kesimpulan', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ) - ); - } - - $header_id = $rows[0]['header_id']; - $sql = "SELECT Other_PapSmearMaturasiID as xid, - Other_PapSmearMaturasiValue as value - FROM other_papsmearmaturasi - WHERE - Other_PapSmearMaturasiOther_PapSmearID = {$header_id} AND - Other_PapSmearMaturasiIsActive = 'Y' - "; - //echo $sql; - $dt_maturasi = $this->db_smartone->query($sql)->row_array(); - if(!$dt_maturasi){ - $maturasi = array('xid'=>'0','value'=> array('','','')); - } - else{ - $value = explode('/',$dt_maturasi['value']); - $maturasi = array('xid'=>$dt_maturasi['xid'],'value'=> $value); - } - - $sql = "SELECT IFNULL(Other_PapSmearBahanID,0) as xid, - M_PapSmearBahanID as bahan_id, - M_PapSmearBahanName as name, - IF(ISNULL(Other_PapSmearBahanID),'N','Y') as selected - FROM m_papsmearbahan - LEFT JOIN other_papsmearbahan ON Other_PapSmearBahanM_PapSmearBahanID = M_PapSmearBahanID AND - Other_PapSmearBahanOther_PapSmearID = {$header_id} AND - Other_PapSmearBahanIsActive = 'Y' - WHERE - M_PapSmearBahanIsActive = 'Y' - ORDER BY M_PapSmearBahanID ASC - "; - //echo $sql; - $bahans = $this->db_smartone->query($sql)->result_array(); - - $sql = "SELECT IFNULL(Other_PapsmearCategoryID,0) as xid, - M_PapSmearCategoryID as category_id, - M_PapSmearCategoryName as name, - IF(ISNULL(Other_PapsmearCategoryID),'N','Y') as selected - FROM m_papsmearcategory - LEFT JOIN other_papsmearcategory ON Other_PapsmearCategoryM_PapSmearCategoryID = M_PapSmearCategoryID AND - Other_PapsmearCategoryOther_PapSmearID = {$header_id} AND - Other_PapsmearCategoryIsActive = 'Y' - WHERE - M_PapSmearCategoryIsActive = 'Y' - ORDER BY M_PapSmearCategoryID ASC - "; - //echo $sql; - $categories = $this->db_smartone->query($sql)->result_array(); - - $sql = "SELECT IFNULL(Other_PapSmearCheckID,0) as xid, - M_PapSmearCheckID as check_id, - M_PapSmearCheckLabel as name, - IF(ISNULL(Other_PapSmearCheckID),'N','Y') as selected, - Other_PapSmearCheckNote as note - FROM m_papsmearcheck - LEFT JOIN other_papsmearcheck ON Other_PapSmearCheckM_PapSmearCheckID = M_PapSmearCheckID AND - Other_PapSmearCheckOther_PapSmearID = {$header_id} AND - Other_PapSmearCheckIsActive = 'Y' - WHERE - M_PapSmearCheckIsActive = 'Y' - ORDER BY M_PapSmearCheckCode ASC - "; - $checks = $this->db_smartone->query($sql)->result_array(); - - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $rst = array('doctors'=>$doctors,'checks'=>$checks,'bahans'=>$bahans,'categories'=>$categories,'maturasi'=>$maturasi,'results'=>$rows); - $this->sys_ok(["records"=>$rst]); - - } - - function saveresult_lcprep() - { - $prm = $this->sys_input; - $detail_id = $prm['detail_id']; - $doctor_id = $prm['doctor']; - $adekuasi = $prm['adekuasi']; - $kategoriumum = $prm['kategoriumum']; - $interpretasi = $prm['interpretasi']; - $results = $prm['results']; - - $userid = $this->sys_user['M_UserID']; - - $header_id = 0; - $sql = "SELECT * FROM other_lcprep WHERE Other_LcprepT_orderDetailID = {$detail_id} AND Other_LcprepIsActive = 'Y'"; - $dt_header = $this->db_smartone->query($sql)->row_array(); - if($dt_header){ - $header_id = $dt_header['Other_LcprepID']; - } - if($header_id == 0){ - $sql = "INSERT INTO other_lcprep( - Other_LcprepT_orderDetailID, - Other_LcprepM_DoctorID, - Other_LcprepUserID, - Other_LcprepCreated - ) - VALUES( - {$detail_id}, - {$doctor_id}, - {$userid}, - NOW() - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - }else{ - $sql = "UPDATE other_lcprep SET Other_LcprepM_DoctorID = {$doctor_id}, Other_LcprepUserID = {$userid} WHERE Other_LcprepID = {$header_id}"; - $this->db_smartone->query($sql); - } - - if($adekuasi){ - foreach($adekuasi as $k =>$v){ - $selected = $v['chex']?'Y':'N'; - if(intval($v['xid'] == 0)){ - $sql = "UPDATE other_lcprepadekuasi SET Other_LcprepAdekuasiIsActive = 'N' - WHERE - Other_LcprepAdekuasiOther_LcprepID = {$header_id} AND - Other_LcprepAdekuasiIsActive = 'Y' AND - Other_LcprepAdekuasiLcprep_AdekuasiID = {$v['id']}"; - $this->db_smartone->query($sql); - $sql = "INSERT INTO other_lcprepadekuasi ( - Other_LcprepAdekuasiOther_LcprepID, - Other_LcprepAdekuasiLcprep_AdekuasiID, - Other_LcprepAdekuasiChex, - Other_LcprepAdekuasiUserID, - Other_LcprepAdekuasiCreated - ) - VALUES( - {$header_id}, - {$v['id']}, - '{$selected}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - //echo $sql; - } - if(intval($v['xid'] != 0)){ - - $sql = "UPDATE other_lcprepadekuasi SET - Other_LcprepAdekuasiChex = '{$selected}', - Other_LcprepAdekuasiUserID = {$userid} - WHERE - Other_LcprepAdekuasiID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - - //echo $sql; - } - } - - if($kategoriumum){ - foreach($kategoriumum as $k =>$v){ - $selected = $v['chex']?'Y':'N'; - if(intval($v['xid'] == 0)){ - $sql = "UPDATE other_lcprepkategoriumum SET Other_LcprepKategoriUmumIsActive = 'N' - WHERE - Other_LcprepKategoriUmumOther_LcprepID = {$header_id} AND - Other_LcprepKategoriUmumLcprep_KategoriUmumID = {$v['id']} AND - Other_LcprepKategoriUmumIsActive = 'Y' - "; - $this->db_smartone->query($sql); - $sql = "INSERT INTO other_lcprepkategoriumum ( - Other_LcprepKategoriUmumOther_LcprepID, - Other_LcprepKategoriUmumLcprep_KategoriUmumID, - Other_LcprepKategoriUmumChex, - Other_LcprepKategoriUmumUserID, - Other_LcprepKategoriUmumCreated - ) - VALUES( - {$header_id}, - {$v['id']}, - '{$selected}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if(intval($v['xid'] != 0)){ - $sql = "UPDATE other_lcprepkategoriumum SET - Other_LcprepKategoriUmumChex = '{$selected }', - Other_LcprepKategoriUmumUserID = {$userid} - WHERE - Other_LcprepKategoriUmumID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - - //echo $sql; - } - } - - if($results){ - foreach($results as $k =>$v){ - if(intval($v['xid'] == 0)){ - $sql = "UPDATE other_lcprepdetails SET Other_LcprepDetailsIsActive = 'N' - WHERE - Other_LcprepDetailsOther_LcprepID = {$header_id} AND - Other_LcprepDetailsCode = '{$v['code']}' AND - Other_LcprepDetailsIsActive = 'Y'"; - $this->db_smartone->query($sql); - $sql = "INSERT INTO other_lcprepdetails ( - Other_LcprepDetailsOther_LcprepID, - Other_LcprepDetailsCode, - Other_LcprepDetailsLabel, - Other_LcprepDetailsResult, - Other_LcprepDetailsUserID, - Other_LcprepDetailsCreated - ) - VALUES( - {$header_id}, - '{$v['code']}', - '{$v['label']}', - '{$v['result']}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if(intval($v['xid'] != 0)){ - $sql = "UPDATE other_lcprepdetails SET - Other_LcprepDetailsCode = '{$v['code']}', - Other_LcprepDetailsLabel = '{$v['label']}', - Other_LcprepDetailsResult = '{$v['result']}', - Other_LcprepDetailsUserID = {$userid} - WHERE - Other_LcprepDetailsID = {$v['xid']}"; - $this->db_smartone->query($sql); - - } - //echo $sql; - } - } - - if($interpretasi){ - foreach($interpretasi as $k =>$v){ - if(count($v['subgroups']) > 0){ - foreach($v['subgroups'] as $ik => $iv){ - if(count($iv['childs']) > 0){ - foreach($iv['childs'] as $iik => $iiv){ - if(intval($iiv['xid'] == 0)){ - $chex = $iiv['chex'] ? 'Y':'N'; - $sql = "UPDATE other_lcprepinterpretasi SET Other_LcprepInterpretasiIsActive = 'N' - WHERE - Other_LcprepInterpretasiOther_LcprepID = {$header_id} AND - Other_LcprepInterpretasiLcprep_InterpretasiID = '{$iiv['id']}' AND - Other_LcprepInterpretasiIsActive = 'Y'"; - $this->db_smartone->query($sql); - $sql = "INSERT INTO other_lcprepinterpretasi ( - Other_LcprepInterpretasiOther_LcprepID, - Other_LcprepInterpretasiLcprep_InterpretasiID, - Other_LcprepInterpretasiChex, - Other_LcprepInterpretasiValue, - Other_LcprepInterpretasiUserID, - Other_LcprepInterpretasiCreated - ) - VALUES( - {$header_id}, - '{$iiv['id']}', - '{$chex}', - '{$iiv['value']}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - - if(intval($iiv['xid'] != 0)){ - $chex = $iiv['chex'] ? 'Y':'N'; - $sql = "UPDATE other_lcprepinterpretasi SET - Other_LcprepInterpretasiChex = '{$chex}', - Other_LcprepInterpretasiValue = '{$iiv['value']}', - Other_LcprepInterpretasiUserID = {$userid} - WHERE - Other_LcprepInterpretasiID = {$iiv['xid']}"; - $this->db_smartone->query($sql); - //echo $sql; - - } - - } - } - } - } - //echo $sql; - } - } - - - $result = array("total" => 1, "records" => array(), "sql"=> ''); - $this->sys_ok($result); - exit; - } - - function saveresult_papsmear() - { - $prm = $this->sys_input; - $detail_id = $prm['detail_id']; - $doctor_id = $prm['doctor']; - $checks = $prm['checks']; - $maturasi = $prm['maturasi']; - $bahans = $prm['bahans']; - $categories = $prm['categories']; - $results = $prm['results']; - - $userid = $this->sys_user['M_UserID']; - - $header_id = 0; - $sql = "SELECT * FROM other_papsmear WHERE Other_PapSmearT_OrderDetailID = {$detail_id} AND Other_PapSmearIsActive = 'Y'"; - $dt_header = $this->db_smartone->query($sql)->row_array(); - if($dt_header){ - $header_id = $dt_header['Other_PapSmearID']; - } - if($header_id == 0){ - $sql = "INSERT INTO other_papsmear( - Other_PapSmearT_OrderDetailID, - Other_PapSmearM_DoctorID, - Other_PapSmearUserID, - Other_PapSmearCreated - ) - VALUES( - {$detail_id}, - {$doctor_id}, - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } - else{ - $sql = "UPDATE other_papsmear SET Other_PapSmearM_DoctorID = {$doctor_id}, Other_PapSmearUserID = {$userid} WHERE Other_PapSmearID = {$header_id}"; - $this->db_smartone->query($sql); - } - - if($checks){ - foreach($checks as $k =>$v){ - if(intval($v['xid']) == 0 && $v['selected'] === 'Y'){ - $sql = "INSERT INTO other_papsmearcheck ( - Other_PapSmearCheckOther_PapSmearID, - Other_PapSmearCheckM_PapSmearCheckID, - Other_PapSmearCheckNote, - Other_PapSmearCheckUserID, - Other_PapSmearCheckCreated - ) - VALUES( - {$header_id}, - {$v['check_id']}, - '{$v['note']}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if(intval($v['xid']) != 0 && $v['selected'] === 'N'){ - $sql = "UPDATE other_papsmearcheck SET - Other_PapSmearCheckIsActive = 'N', - Other_PapSmearCheckUserID = {$userid} - WHERE - Other_PapSmearCheckID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - if(intval($v['xid']) != 0 && $v['selected'] === 'Y'){ - $sql = "UPDATE other_papsmearcheck SET - Other_PapSmearCheckNote = '{$v['note']}', - Other_PapSmearCheckUserID = {$userid} - WHERE - Other_PapSmearCheckID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - //echo $sql; - } - } - - if($maturasi){ - if(intval($maturasi['xid']) == 0){ - $value = join("/",$maturasi['value']); - $sql = "INSERT INTO other_papsmearmaturasi ( - Other_PapSmearMaturasiOther_PapSmearID, - Other_PapSmearMaturasiValue, - Other_PapSmearMaturasiUserID, - Other_PapSmearMaturasiCreated - ) - VALUE( - {$header_id}, - '{$value}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - //echo $sql; - } - if(intval($maturasi['xid']) != 0){ - $value = join("/",$maturasi['value']); - $sql = "UPDATE other_papsmearmaturasi SET - Other_PapSmearMaturasiValue = '{$value}', - Other_PapSmearMaturasiUserID = {$userid} - WHERE - Other_PapSmearMaturasiID = {$maturasi['xid']}"; - // echo $sql; - $this->db_smartone->query($sql); - } - } - - if($bahans){ - foreach($bahans as $k =>$v){ - if(intval($v['xid']) == 0 && $v['selected'] === 'Y'){ - $sql = "INSERT INTO other_papsmearbahan ( - Other_PapSmearBahanOther_PapSmearID, - Other_PapSmearBahanM_PapSmearBahanID, - Other_PapSmearBahanUserID, - Other_PapSmearBahanCreated - ) - VALUES( - {$header_id}, - {$v['bahan_id']}, - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if(intval($v['xid']) != 0 && $v['selected'] === 'N'){ - $sql = "UPDATE other_papsmearbahan SET - Other_PapSmearBahanIsActive = 'N', - Other_PapsmearCategoryUserID = {$userid} - WHERE - Other_PapSmearBahanID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - if(intval($v['xid']) != 0 && $v['selected'] === 'Y'){ - $sql = "UPDATE other_papsmearbahan SET - Other_PapSmearBahanIsActive = 'Y', - Other_PapsmearCategoryUserID = {$userid} - WHERE - Other_PapSmearBahanID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - //echo $sql; - } - } - - if($categories){ - foreach($categories as $k =>$v){ - if(intval($v['xid']) == 0 && $v['selected'] === 'Y'){ - $sql = "INSERT INTO other_papsmearcategory ( - Other_PapsmearCategoryOther_PapSmearID, - Other_PapsmearCategoryM_PapSmearCategoryID, - Other_PapsmearCategoryUserID, - Other_PapsmearCategoryCreated - ) - VALUES( - {$header_id}, - {$v['category_id']}, - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if(intval($v['xid']) != 0 && $v['selected'] === 'N'){ - $sql = "UPDATE other_papsmearcategory SET - Other_PapsmearCategoryIsActive = 'N', - Other_PapsmearCategoryUserID = {$userid} - WHERE - Other_PapsmearCategoryID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - //echo $sql; - if(intval($v['xid']) != 0 && $v['selected'] === 'Y'){ - $sql = "UPDATE other_papsmearcategory SET - Other_PapsmearCategoryIsActive = 'Y', - Other_PapsmearCategoryUserID = {$userid} - WHERE - Other_PapsmearCategoryID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - } - } - - if($results){ - foreach($results as $k =>$v){ - if(intval($v['xid']) == 0){ - $sql = "INSERT INTO other_papsmeardetails ( - Other_PapSmearDetailsOther_PapSmearID, - Other_PapSmearDetailsCode, - Other_PapSmearDetailsLabel, - Other_PapSmearDetailsResult, - Other_PapSmearDetailsUserID, - Other_PapSmearDetailsCreated - ) - VALUES( - {$header_id}, - '{$v['code']}', - '{$v['label']}', - '{$v['result']}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if(intval($v['xid']) != 0){ - $sql = "UPDATE other_papsmeardetails SET - Other_PapSmearDetailsCode = '{$v['code']}', - Other_PapSmearDetailsLabel = '{$v['label']}', - Other_PapSmearDetailsResult = '{$v['result']}', - Other_PapSmearDetailsUserID = {$userid} - WHERE - Other_PapSmearDetailsID = {$v['xid']}"; - $this->db_smartone->query($sql); - - } - //echo $sql; - } - } - - $result = array("total" => 1, "records" => array(), "sql"=> ''); - $this->sys_ok($result); - exit; - } - - function saveresult_fna() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = $inp['doctor']; - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - if($prm[0]['xid'] == '0'){ - $sql = "INSERT INTO other_fna( - Other_FNAM_DoctorID, - Other_FNAT_OrderDetailID, - Other_FNAUserID, - Other_FNACreated - ) - VALUES( - {$doctor_id}, - {$prm[0]['orderdetail_id']}, - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } - else{ - $sql = "SELECT * FROM other_fna WHERE Other_FNAT_OrderDetailID = {$prm[0]['orderdetail_id']} AND Other_FNAIsActive = 'Y'"; - $data_header = $this->db_smartone->query($sql)->row_array(); - $header_id = $data_header['Other_FNAID']; - $sql = "UPDATE other_fna SET - Other_FNAM_DoctorID = {$doctor_id}, - Other_FNAUserID = {$userid} - WHERE - Other_FNAID = {$header_id}"; - $this->db_smartone->query($sql); - } - foreach($prm as $k => $v){ - if($v['xid'] == '0'){ - $results = str_replace("'", "\\'", $v['result']); - $sql = "INSERT INTO other_fnadetails( - Other_FNADetailsOther_FNAID , - Other_FNADetailsCode, - Other_FNADetailsLabel, - Other_FNADetailsResult, - Other_FNADetailsCreated, - Other_FNADetailsUserID - ) - VALUES( - {$header_id}, - '{$v['code']}', - '{$v['label']}', - '{$results}', - NOW(), - {$userid} - )"; - $query = $this->db_smartone->query($sql); - } - else{ - $results = str_replace("'", "\\'", $v['result']); - $sql = "UPDATE other_fnadetails SET - Other_FNADetailsResult = '{$results}', - Other_FNADetailsUserID = {$userid} - WHERE - Other_FNADetailsID = {$v['xid']}"; - $query = $this->db_smartone->query($sql); - } - } - - $result = array("total" => 1, "records" => array(), "sql"=> ''); - $this->sys_ok($result); - exit; - } - - function saveresult_cytologi() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = $inp['doctor']; - - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - if($prm[0]['xid'] == '0'){ - $sql = "INSERT INTO other_cytologi( - Other_CytologiT_OrderDetailID, - Other_CytologiM_DoctorID, - Other_CytologiUserID, - Other_CytologiCreated - ) - VALUES( - {$prm[0]['orderdetail_id']}, - {$doctor_id}, - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } - else{ - $sql = "SELECT * FROM other_cytologi WHERE Other_CytologiT_OrderDetailID = {$prm[0]['orderdetail_id']} AND Other_CytologiIsActive = 'Y'"; - $data_header = $this->db_smartone->query($sql)->row_array(); - $header_id = $data_header['Other_CytologiID']; - $sql = "UPDATE other_cytologi SET - Other_CytologiM_DoctorID = {$doctor_id}, - Other_CytologiUserID = {$userid} - WHERE - Other_CytologiID = {$header_id}"; - $this->db_smartone->query($sql); - } - foreach($prm as $k => $v){ - if($v['xid'] == '0'){ - $results = str_replace("'", "\\'", $v['result']); - $sql = "INSERT INTO other_cytologidetails( - Other_CytologiDetailsOther_CytologiID , - Other_CytologiDetailsCode, - Other_CytologiDetailsLabel, - Other_CytologiDetailsResult, - Other_CytologiDetailsCreated, - Other_CytologiDetailsUserID - ) - VALUES( - {$header_id}, - '{$v['code']}', - '{$v['label']}', - '{$results}', - NOW(), - {$userid} - )"; - $query = $this->db_smartone->query($sql); - } - else{ - $results = str_replace("'", "\\'", $v['result']); - $sql = "UPDATE other_cytologidetails SET - Other_CytologiDetailsResult = '{$results}', - Other_CytologiDetailsUserID = {$userid} - WHERE - Other_CytologiDetailsID = {$v['xid']}"; - $query = $this->db_smartone->query($sql); - } - } - - $result = array("total" => 1, "records" => array(), "sql"=> ''); - $this->sys_ok($result); - exit; - } - - function saveresult_mikro() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = $inp['doctor']; - $backteria_id = $inp['bacteria']; - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - - if($inp['result_value'] != 'Negatif' && $inp['result_value'] != 'Positif'){ - $prm['result_value'] = $prm['result_other']; - } - else{ - $prm['result_value'] = $inp['result_value']; - } - - if($prm['xid'] == '0'){ - $sql = "INSERT INTO other_mikro( - Other_MikroM_DoctorID, - Other_MikroResult, - Other_MikroT_BacteriaID, - Other_MikroT_OrderDetailID, - Other_MikroHasilBiakan, - Other_MikroSampleTypeName, - Other_MikroUserID, - Other_MikroCreated - ) - VALUES( - {$doctor_id}, - '{$prm['result_value']}', - {$backteria_id}, - {$prm['orderdetail_id']}, - '{$prm['hasil_biakan']}', - '{$prm['sample_name']}', - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } - else{ - $sql = "SELECT * FROM other_mikro WHERE Other_MikroT_OrderDetailID = {$prm['orderdetail_id']} AND Other_MikroIsActive = 'Y'"; - $data_header = $this->db_smartone->query($sql)->row_array(); - $header_id = $data_header['Other_MikroID']; - $sql = "UPDATE other_mikro SET - Other_MikroResult = '{$prm['result_value']}', - Other_MikroM_DoctorID = {$doctor_id}, - Other_MikroT_BacteriaID = {$backteria_id}, - Other_MikroHasilBiakan = '{$prm['hasil_biakan']}', - Other_MikroSampleTypeName = '{$prm['sample_name']}', - Other_MikroUserID = {$userid} - WHERE - Other_MikroID = {$header_id}"; - //echo $sql; - $this->db_smartone->query($sql); - } - - - - $sql = "UPDATE other_mikrodetails SET Other_MikroDetailsIsActive = 'N', Other_MikroDetailsUserID = 0 WHERE Other_MikroDetailsOther_MikroID = {$header_id}"; - $this->db_smartone->query($sql); - - $results = $prm['details']; - if($inp['result_value'] == 'Positif'){ - foreach($results as $k => $v){ - if($v['xid'] == '0'){ - $sql = "INSERT INTO other_mikrodetails( - Other_MikroDetailsOther_MikroID , - Other_MikroDetailsT_AntibioticID, - Other_MikroDetailsValue, - Other_MikroDetailsNote, - Other_MikroDetailsCreated, - Other_MikroDetailsUserID - ) - VALUES( - {$header_id}, - '{$v['T_AntibioticID']}', - '{$v['value']}', - '{$v['note']}', - NOW(), - {$userid} - )"; - $query = $this->db_smartone->query($sql); - } - else{ - $sql = "UPDATE other_mikrodetails SET - Other_MikroDetailsT_AntibioticID = '{$v['T_AntibioticID']}', - Other_MikroDetailsValue = '{$v['value']}', - Other_MikroDetailsNote = '{$v['note']}', - Other_MikroDetailsIsActive = 'Y', - Other_MikroDetailsUserID = {$userid} - WHERE - Other_MikroDetailsID = {$v['xid']}"; - //echo $sql; - $query = $this->db_smartone->query($sql); - } - } - } - - - $result = array("total" => 1, "records" => array(), "sql"=> ''); - $this->sys_ok($result); - exit; - } - - - function get_doctors_preparasi_sperma() - { - $prm = $this->sys_input; - // $id = $prm["id"]; - - $sql = " SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 10 AND - M_DoctorSOIsActive = 'Y' - ORDER BY M_DoctorName ASC"; - //echo $sql; - $query = $this->db_smartone->query($sql); - $rows = $query->result_array(); - $sql = " - SELECT '0' as id, 'Belum memilih metode' as name - UNION - SELECT M_MethodeSpermaID as id, M_MethodeSpermaName as name - FROM m_methodesperma - WHERE - M_MethodeSpermaIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $methodes = $this->db_smartone->query($sql)->result_array(); - - - $this->sys_ok(["records"=>$rows,"methodes"=>$methodes]); - - } - - - function getpreparasispermaresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT other_preparasisperma.*, - Other_PreparasiSpermaID as xid, - Other_PreparasiSpermaT_OrderDetailID as orderdetail_id, - IFNULL(Other_PreparasiSpermaM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_PreparasiSpermaM_DoctorID) OR Other_PreparasiSpermaM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name, - IFNULL(M_MethodeSpermaID,0) as methode_id, - IFNULL(M_MethodeSpermaName,'') as methode_name - FROM other_preparasisperma - LEFT JOIN m_doctor ON Other_PreparasiSpermaM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - LEFT JOIN m_methodesperma ON Other_PreparasiSpermaM_MethodeSpermaID = M_MethodeSpermaID AND - M_MethodeSpermaIsActive = 'Y' - WHERE - Other_PreparasiSpermaT_OrderDetailID = {$id} AND Other_PreparasiSpermaIsActive = 'Y' - GROUP BY Other_PreparasiSpermaID"; - $query = $this->db_smartone->query($sql); - - if ($query) - { - $rows = $query->row_array(); - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 10 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $sql = " - SELECT '0' as id, 'Belum memilih metode' as name - UNION - SELECT M_MethodeSpermaID as id, M_MethodeSpermaName as name - FROM m_methodesperma - WHERE - M_MethodeSpermaIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $methodes = $this->db_smartone->query($sql)->result_array(); - $images = array(); - $sql = "SELECT Other_PreparasiSpermaImgID as xid, - Other_PreparasiSpermaImgType as type, - CONCAT('/one-media/one-image-nonlab/',Other_PreparasiSpermaImgNewName) as image_url - FROM t_orderdetail - JOIN other_preparasisperma_img ON Other_PreparasiSpermaImgT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND - Other_PreparasiSpermaImgIsActive = 'Y' - WHERE - T_OrderDetailID = {$id} AND - T_OrderDetailIsActive = 'Y' - GROUP BY Other_PreparasiSpermaImgID"; - //echo $sql; - $images = $this->db_smartone->query($sql)->result_array(); - - $rst = array('doctors'=>$doctors,'methodes'=>$methodes,'results'=>$rows,'images'=>$images); - $this->sys_ok(["records"=>$rst]); - } - else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - - function uploadimage_preparasi_sperma(){ - if (! $this->isLogin) { - $this->sys_error("Invalid Token"); - exit; - } - - $userid = $this->sys_user["M_UserID"]; - $data = []; - //print_r($_SERVER); - - $prm = $this->sys_input; - $orderid = $this->input->post('orderid'); - $type = $this->input->post('type'); - $labnumber = $this->input->post('labnumber'); - $sql = "UPDATE other_preparasisperma_img SET - Other_PreparasiSpermaImgIsActive = 'N', - Other_PreparasiSpermaImgUserID = {$userid} - WHERE - Other_PreparasiSpermaImgT_OrderHeaderID = {$orderid} AND - Other_PreparasiSpermaImgType = '{$type}'"; - //echo $sql; - $this->db_onedev->query($sql); - //$config['upload_path'] = 'assets/'; - - $path = '/home/one/project/one/one-media/one-image-nonlab/'; - //echo $path; - $config['upload_path'] = $path; - $config['allowed_types'] = 'jpg|jpeg|png|gif'; - - $config['max_size'] = '10000'; - $count = count($_FILES['files']['name']); - //echo $count; - $this->load->library('upload',$config); - - $error = []; - for($i=0;$i<$count;$i++){ - - - if(!empty($_FILES['files']['name'][$i])){ - - - - $_FILES['file']['name'] = $_FILES['files']['name'][$i]; - - $_FILES['file']['type'] = $_FILES['files']['type'][$i]; - - $_FILES['file']['tmp_name'] = $_FILES['files']['tmp_name'][$i]; - - $_FILES['file']['error'] = $_FILES['files']['error'][$i]; - - $_FILES['file']['size'] = $_FILES['files']['size'][$i]; - - - - $namex = $orderid.'-'.$labnumber.'-'.$this->generateRandomString(5); - //echo $namex; - - $config['file_name'] = $namex; - $this->upload->initialize($config); - //echo $config['file_name'] ; - - - - - - if($this->upload->do_upload('file')){ - - $uploadData = $this->upload->data(); - - $filename = $uploadData['file_name']; - //echo $filename; - - - $sql = "INSERT INTO other_preparasisperma_img ( - Other_PreparasiSpermaImgT_OrderHeaderID, - Other_PreparasiSpermaImgType, - Other_PreparasiSpermaImgOldName, - Other_PreparasiSpermaImgNewName, - Other_PreparasiSpermaImgCreated, - Other_PreparasiSpermaImgUserID - ) - VALUES( - {$orderid}, - '{$type}', - '{$_FILES['files']['name'][$i]}', - '{$filename}', - NOW(), - {$userid} - - )"; - //echo $sql; - $this->db_onedev->query($sql); - $xlast_id = $this->db_onedev->insert_id(); - $data['totalFiles'][] = array('xid' => $xlast_id ,'type'=>$type,'image_url' => '/one-media/one-image-nonlab/'.$filename); - - } - else{ - $error = array('error' => $this->upload->display_errors()); - } - - } - - - - } - - $result = array("total" =>count( $data['totalFiles']), "records" => $data['totalFiles'],'errors'=>$error); - $this->sys_ok($result); - } - - - function saveresult_preparasi_sperma() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = $inp['doctor']; - $orderdetail_id = $inp['orderdetailid']; - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - if($prm['xid'] == '0'){ - $sql = "INSERT INTO other_preparasisperma( - Other_PreparasiSpermaM_DoctorID, - Other_PreparasiSpermaT_OrderDetailID, - Other_PreparasiSpermaPreMotilitasA, - Other_PreparasiSpermaPreMotilitasB, - Other_PreparasiSpermaPreMotilitasC, - Other_PreparasiSpermaPreKonsentrasi, - Other_PreparasiSpermaPreKontaminan, - Other_PreparasiSpermaPostMotilitasA, - Other_PreparasiSpermaPostMotilitasB, - Other_PreparasiSpermaPostMotilitasC, - Other_PreparasiSpermaPostKonsentrasi, - Other_PreparasiSpermaPostKontaminan, - Other_PreparasiSpermaPreVolume, - Other_PreparasiSpermaPostVolume, - Other_PreparasiSpermaM_MethodeSpermaID, - Other_PreparasiSpermaNote, - Other_PreparasiSpermaUserID, - Other_PreparasiSpermaCreated - ) - VALUES( - {$doctor_id}, - {$orderdetail_id}, - '{$prm['Other_PreparasiSpermaPreMotilitasA']}', - '{$prm['Other_PreparasiSpermaPreMotilitasB']}', - '{$prm['Other_PreparasiSpermaPreMotilitasC']}', - '{$prm['Other_PreparasiSpermaPreKonsentrasi']}', - '{$prm['Other_PreparasiSpermaPreKontaminan']}', - '{$prm['Other_PreparasiSpermaPostMotilitasA']}', - '{$prm['Other_PreparasiSpermaPostMotilitasB']}', - '{$prm['Other_PreparasiSpermaPostMotilitasC']}', - '{$prm['Other_PreparasiSpermaPostKonsentrasi']}', - '{$prm['Other_PreparasiSpermaPostKontaminan']}', - '{$prm['Other_PreparasiSpermaPreVolume']}', - '{$prm['Other_PreparasiSpermaPostVolume']}', - '{$prm['Other_PreparasiSpermaM_MethodeSpermaID']}', - '{$prm['Other_PreparasiSpermaNote']}', - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } - else{ - $sql = "SELECT * FROM other_preparasisperma WHERE Other_PreparasiSpermaT_OrderDetailID = {$orderdetail_id} AND Other_PreparasiSpermaIsActive = 'Y'"; - $data_header = $this->db_smartone->query($sql)->row_array(); - $header_id = $data_header['Other_PreparasiSpermaID']; - $sql = "UPDATE other_preparasisperma SET - Other_PreparasiSpermaM_DoctorID = {$doctor_id}, - Other_PreparasiSpermaPreMotilitasA = '{$prm['Other_PreparasiSpermaPreMotilitasA']}', - Other_PreparasiSpermaPreMotilitasB = '{$prm['Other_PreparasiSpermaPreMotilitasB']}', - Other_PreparasiSpermaPreMotilitasC = '{$prm['Other_PreparasiSpermaPreMotilitasC']}', - Other_PreparasiSpermaPreKonsentrasi = '{$prm['Other_PreparasiSpermaPreKonsentrasi']}', - Other_PreparasiSpermaPreKontaminan = '{$prm['Other_PreparasiSpermaPreKontaminan']}', - Other_PreparasiSpermaPostMotilitasA = '{$prm['Other_PreparasiSpermaPostMotilitasA']}', - Other_PreparasiSpermaPostMotilitasB = '{$prm['Other_PreparasiSpermaPostMotilitasB']}', - Other_PreparasiSpermaPostMotilitasC = '{$prm['Other_PreparasiSpermaPostMotilitasC']}', - Other_PreparasiSpermaPostKonsentrasi = '{$prm['Other_PreparasiSpermaPostKonsentrasi']}', - Other_PreparasiSpermaPostKontaminan = '{$prm['Other_PreparasiSpermaPostKontaminan']}', - Other_PreparasiSpermaPreVolume = '{$prm['Other_PreparasiSpermaPreVolume']}', - Other_PreparasiSpermaPostVolume = '{$prm['Other_PreparasiSpermaPostVolume']}', - Other_PreparasiSpermaM_MethodeSpermaID = '{$prm['Other_PreparasiSpermaM_MethodeSpermaID']}', - Other_PreparasiSpermaNote = '{$prm['Other_PreparasiSpermaNote']}', - Other_PreparasiSpermaUserID = {$userid} - WHERE - Other_PreparasiSpermaID = {$header_id}"; - $this->db_smartone->query($sql); - } - - - $result = array("total" => 1, "records" => array(), "sql"=> ''); - $this->sys_ok($result); - exit; - } - - function getdnafragmentasiresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT other_dnafragmentasi.*, - Other_DnaFragmentasiID as xid, - Other_DnaFragmentasiT_OrderDetailID as orderdetail_id, - IFNULL(Other_DnaFragmentasiM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_DnaFragmentasiM_DoctorID) OR Other_DnaFragmentasiM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name, - IFNULL(Other_DnaFragmentasiOther_DnaFragmentasiMethodeID,0) as methode_id, - IFNULL(Other_DnaFragmentasiMethodeName,'') as methode_name, - Other_DnaFragmentasiHaloLuas as halo_luas, - Other_DnaFragmentasiHaloSedang as halo_sedang, - Other_DnaFragmentasiHaloSempit as halo_sempit, - Other_DnaFragmentasiTanpaHalo as tanpa_halo, - Other_DnaFragmentasiDFI as dfi, - Other_DnaFragmentasiKesimpulan as kesimpulan, - Other_DnaFragmentasiCatatan as catatan - FROM other_dnafragmentasi - LEFT JOIN m_doctor ON Other_DnaFragmentasiM_DoctorID = M_DoctorID - LEFT JOIN other_dnafragmentasimethode ON Other_DnaFragmentasiOther_DnaFragmentasiMethodeID = Other_DnaFragmentasiMethodeID - WHERE - Other_DnaFragmentasiT_OrderDetailID = {$id} AND Other_DnaFragmentasiIsActive = 'Y' - GROUP BY Other_DnaFragmentasiID - LIMIT 1"; - //echo $sql; - $query = $this->db_smartone->query($sql); - - if ($query) - { - $rows = $query->row_array(); - if(!$rows){ - $rows = array( - 'xid' => 0, - 'orderdetail_id' =>$id, - 'doctor_id' => 0, - 'doctor_name' => '', - 'methode_id' => 0, - 'methode_name' => '', - 'halo_luas' => '', - 'halo_sedang' => '', - 'tanpa_halo' => '', - 'dfi' => '', - 'kesimpulan' => '', - 'catatan' => '' - ); - } - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID - WHERE - M_DoctorSONat_SubGroupID = 4 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - - $sql = " - SELECT '0' as id, 'Belum memilih metode' as name - UNION - SELECT Other_DnaFragmentasiMethodeID as id, Other_DnaFragmentasiMethodeName as name - FROM other_dnafragmentasimethode - WHERE - Other_DnaFragmentasiMethodeIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $methodes = $this->db_smartone->query($sql)->result_array(); - - - $rst = array('doctors'=>$doctors,'methodes'=>$methodes,'results'=>$rows); - $this->sys_ok(["records"=>$rst]); - } - else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - function saveresult_dnafragmentasi() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = $inp['doctor']['id']; - $methode_id = $inp['methode']['id']; - $orderdetail_id = $inp['results']['orderdetail_id']; - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - if(intval($prm['xid']) == 0){ - $sql = "INSERT INTO other_dnafragmentasi( - Other_DnaFragmentasiT_OrderDetailID, - Other_DnaFragmentasiM_DoctorID, - Other_DnaFragmentasiOther_DnaFragmentasiMethodeID, - Other_DnaFragmentasiHaloLuas, - Other_DnaFragmentasiHaloSedang, - Other_DnaFragmentasiHaloSempit, - Other_DnaFragmentasiTanpaHalo, - Other_DnaFragmentasiDFI, - Other_DnaFragmentasiKesimpulan, - Other_DnaFragmentasiCatatan, - Other_DnaFragmentasiUserID, - Other_DnaFragmentasiLastUpdated - ) - VALUES( - {$orderdetail_id}, - {$doctor_id}, - {$methode_id}, - '{$prm['halo_luas']}', - '{$prm['halo_sedang']}', - '{$prm['halo_sempit']}', - '{$prm['tanpa_halo']}', - '{$prm['dfi']}', - '{$prm['kesimpulan']}', - '{$prm['catatan']}', - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } - else{ - $sql = "UPDATE other_dnafragmentasi SET - Other_DnaFragmentasiT_OrderDetailID = {$orderdetail_id}, - Other_DnaFragmentasiM_DoctorID = {$doctor_id}, - Other_DnaFragmentasiOther_DnaFragmentasiMethodeID = '{$methode_id}', - Other_DnaFragmentasiHaloLuas = '{$prm['halo_luas']}', - Other_DnaFragmentasiHaloSedang = '{$prm['halo_sedang']}', - Other_DnaFragmentasiHaloSempit = '{$prm['halo_sempit']}', - Other_DnaFragmentasiTanpaHalo = '{$prm['tanpa_halo']}', - Other_DnaFragmentasiDFI = '{$prm['dfi']}', - Other_DnaFragmentasiKesimpulan = '{$prm['kesimpulan']}', - Other_DnaFragmentasiCatatan = '{$prm['catatan']}', - Other_DnaFragmentasiLastUpdated = NOW(), - Other_DnaFragmentasiUserID = {$userid} - WHERE - Other_DnaFragmentasiID = {$prm['xid']}"; - //echo $sql; - $this->db_smartone->query($sql); - } - - - $result = array("total" => 1, "records" => array(), "sql"=> ''); - $this->sys_ok($result); - exit; - } - - -} - +db_smartone = $this->load->database("onedev", true); + $this->load->helper(array('form', 'url')); + } + function getMethodeID($natTestID) { + $sql = "select M_MethodePriorityNat_MethodeID MethodeID, Nat_MethodeName + from + m_methode_priority + join nat_methode on Nat_MethodeID = M_MethodePriorityNat_MethodeID + and Nat_MethodeIsActive = 'Y' + join m_instrumentmethode on M_InstrumentMethodeNat_MethodeID = Nat_MethodeID and M_InstrumentMethodeIsActive = 'Y' + join nat_instrument on M_InstrumentMethodeNat_InstrumentID = Nat_InstrumentID + and Nat_InstrumentIsActive ='Y' + where M_MethodePriorityIsActive = 'Y' + and M_MethodePriorityNat_TestID = $natTestID + and M_MethodePriorityM_DayOfWeekID = dayofweek(now()) + order by M_MethodePriorityNumber desc + limit 0,1 "; + $qry = $this->db->query($sql); + if ($qry) { + $rows = $qry->result_array(); + if (count($rows) > 0 ) return array($rows[0]["MethodeID"],$rows[0]["Nat_MethodeName"]); + } + //2nd + $sql= "select + M_InstrumentMethodeNat_MethodeID MethodeID, Nat_MethodeName + from m_instrumentmethode + join nat_methode on M_InstrumentMethodeNat_MethodeID = Nat_MethodeID + and Nat_MethodeIsActive = 'Y' + join nat_instrument on M_InstrumentMethodeNat_InstrumentID = Nat_InstrumentID + and Nat_InstrumentIsActive ='Y' + where M_InstrumentMethodeNat_TestID = $natTestID + and M_InstrumentMethodeIsActive = 'Y' + order by M_InstrumentMethodePriority desc + limit 0,1"; + $qry = $this->db->query($sql); + if ($qry) { + $rows = $qry->result_array(); + if (count($rows) > 0 ) return array($rows[0]["MethodeID"],$rows[0]["Nat_MethodeName"]); + } + // + $sql = "select Nat_NormalValueNat_MethodeID MethodeID, Nat_MethodeName + from + nat_normalvalue + join nat_methode on Nat_NormalValueNat_MethodeID = Nat_MethodeID + and Nat_MethodeIsActive = 'Y' + where Nat_NormalValueNat_TestID = $natTestID + and Nat_NormalValueIsActive = 'Y' + order by Nat_NormalValueID + limit 0,1"; + $qry = $this->db->query($sql); + if ($qry) { + $rows = $qry->result_array(); + if (count($rows) > 0 ) return array($rows[0]["MethodeID"],$rows[0]["Nat_MethodeName"]); + } + return array(0,""); + } + function get_normal_value($methodeID, $natTestID, $sexID, $ageInDay ) { + $this->load->library('ibl_sampling_normal'); + return $this->ibl_sampling_normal->get_normal_value_id($methodeID, $natTestID, $sexID, $ageInDay); + } + return 0; + } + function fn_fix_normal($order_id) { + $sql = "select + T_OrderDetailID, M_PatientM_SexID, fn_global_age_count_day(M_PatientDOB, date(T_OrderHeaderDate)) Dob , + T_TestNat_TestID + from t_orderheader + join m_patient on T_OrderHeaderID = $order_id and T_OrderHeaderM_PatientID = M_PatientID + join t_orderdetail on T_OrderDetailT_OrderHeaderID = T_OrderHeaderID + and T_OrderDetailIsACtive = 'Y' + and ( T_OrderDetailNat_NormalValueID is null or T_OrderDetailNat_NormalValueID = 0 ) + join t_test on T_OrderDetailT_TestID = T_TestID and T_TestIsResult = 'Y' "; + $qry = $this->db->query($sql); + if(! $qry) { + return; + } + $rows = $qry->result_array(); + if(count($rows) == 0 ) return; + $sql_u = "update t_orderdetail + join nat_normalvalue on T_OrderDetailID = ? and Nat_NormalValueID = ? + set + T_OrderDetailNat_NormalValueID = Nat_NormalValueID, + T_OrderDetailNormalValueNote = Nat_NormalValueNote, + T_OrderDetailNormalValueDescription = Nat_NormalValueDescription, + T_OrderDetailMinValue = Nat_NormalValueMinValue, + T_OrderDetailMaxValue = Nat_NormalValueMaxValue, + T_OrderDetailMinValueInclusive = Nat_NormalValueMinValueInclusive, + T_OrderDetailMaxValueInclusive = Nat_NormalValueMaxValueInclusive, + T_OrderDetailNat_MethodeID = ?, + T_OrderdetailNat_MethodeName =?"; + + foreach($rows as $r) { + $T_OrderDetailID = $r["T_OrderDetailID"]; + $sexID = $r["M_PatientM_SexID"]; + $ageInDay = $r["Dob"]; + $natTestID = $r["T_TestNat_TestID"]; + list($methodeID,$methodeName) = $this->getMethodeID($natTestID); + if ($methodeID == 0 ) continue; + $normalValueID = $this->get_normal_value($methodeID, $natTestID, $sexID, $ageInDay); + if ($normalValueID == 0) return; + $this->db->query($sql_u, array($T_OrderDetailID, $normalValueID, $methodeID, $methodeName)); + } + } + function update_order_sample($targetID, $sourceID) { + $sql = "update t_ordersample target + join t_ordersample source on + target.T_OrderSampleID = ? + and target.T_OrderSampleWorklistReceive = 'N' + and source.T_OrderSampleID = ? + set + target.T_OrderSampleSampling = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSampling, source.T_OrderSampleSampling), + target.T_OrderSampleSamplingDate = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingDate, source.T_OrderSampleSamplingDate), + target.T_OrderSampleSamplingTime = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingTime, source.T_OrderSampleSamplingTime), + target.T_OrderSampleSamplingUserID = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingUserID, source.T_OrderSampleSamplingUserID), + + target.T_OrderSampleReceive = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceive, source.T_OrderSampleReceive), + target.T_OrderSampleReceiveDate = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveDate, source.T_OrderSampleReceiveDate), + target.T_OrderSampleReceiveTime = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveTime, source.T_OrderSampleReceiveTime), + target.T_OrderSampleReceiveUserID = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveUserID, source.T_OrderSampleReceiveUserID), + + target.T_OrderSampleVerification = if(target.T_OrderSampleVerification='Y',target.T_OrderSampleVerification, source.T_OrderSampleVerification), + target.T_OrderSampleVerificationDate =if(target.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationDate, source.T_OrderSampleVerificationDate), + target.T_OrderSampleVerificationTime =if(source.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationTime, source.T_OrderSampleVerificationTime), + target.T_OrderSampleVerificationUserID =if(source.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationUserID, source.T_OrderSampleVerificationUserID), + + target.T_OrderSampleProcessing = if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessing, source.T_OrderSampleProcessing), + target.T_OrderSampleProcessingDate= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingDate, source.T_OrderSampleProcessingDate), + target.T_OrderSampleProcessingTime= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingTime, source.T_OrderSampleProcessingTime), + target.T_OrderSampleProcessingUserID= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingUserID, source.T_OrderSampleProcessingUserID), + + target.T_OrderSampleReceiveHandling =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandling, source.T_OrderSampleReceiveHandling ), + target.T_OrderSampleReceiveHandlingDate =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingDate, source.T_OrderSampleReceiveHandlingDate), + target.T_OrderSampleReceiveHandlingTime =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingTime, source.T_OrderSampleReceiveHandlingTime), + target.T_OrderSampleReceiveHandlingUserID =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingUserID, source.T_OrderSampleReceiveHandlingUserID), + + target.T_OrderSampleHandling = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandling, source.T_OrderSampleHandling), + target.T_OrderSampleHandlingDate = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingDate, source.T_OrderSampleHandlingDate), + target.T_OrderSampleHandlingTime = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingTime, source.T_OrderSampleHandlingTime), + target.T_OrderSampleHandlingUserID = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingUserID, source.T_OrderSampleHandlingUserID), + + target.T_OrderSampleWorklistReceive = source.T_OrderSampleWorklistReceive, + target.T_OrderSampleWorklistReceiveDatetime = source.T_OrderSampleWorklistReceiveDateTime, + target.T_OrderSampleWorklistReceiveUserID = source.T_OrderSampleWorklistReceiveUserID + "; + $qry = $this->db->query($sql,array($targetID,$sourceID)); + if(! $qry ) { + echo json_encode(array( "status" => "ERR" , "message" => print_r($this->db->error(),true))); + exit; + } + } + function fix_sample_serum($headerID) { + //cari t_ordersample yg belum worklist receive dengan code 017% + $sql = "select T_OrderSampleID + from t_ordersample + join t_sampletype on + T_OrderSampleT_OrderHeaderID = ? + and T_OrderSampleWorklistReceive = 'N' + and T_OrderSampleIsActive = 'Y' + and T_OrderSampleT_SampleTypeID = T_SampletypeID + and T_SampleTypeCode like '017%' + "; + $qry = $this->db->query($sql, array($headerID)); + if(!$qry) { + echo json_encode(array( "status" => "ERR" , "message" => print_r($this->db->error(),true))); + exit; + } + $rows = $qry->result_array(); + if (count($rows) == 0 ) return; + //cari T_OrderSample yang sudah di receive yg terakhir + $sql = "select T_OrderSampleID + from t_ordersample + join t_sampletype on + T_OrderSampleT_OrderHeaderID = ? + and T_OrderSampleWorklistReceive = 'Y' + and T_OrderSampleIsActive = 'Y' + and T_OrderSampleT_SampleTypeID = T_SampletypeID + and T_SampleTypeCode like '017%' + order by T_OrderSampleWorklistReceiveDatetime desc + limit 0,1 + "; + $qry = $this->db->query($sql, array($headerID)); + if(!$qry) { + echo json_encode(array( "status" => "ERR" , "message" => print_r($this->db->error(),true))); + exit; + } + $rcv_rows = $qry->result_array(); + if (count($rcv_rows) == 0 ) return; + + //print_r($rows); + //print_r($rcv_rows); + $rcv_T_OrderSampleID = $rcv_rows[0]["T_OrderSampleID"]; + //ada yg belum di receive + foreach($rows as $r) { + $T_OrderSampleID = $r["T_OrderSampleID"]; + $this->update_order_sample($T_OrderSampleID,$rcv_T_OrderSampleID); + } + } + public function search() + { + $prm = $this->sys_input; + $max_rst = 99; + + $id = $prm["order_id"]; + if ($id > 0 ) { + $this->fix_sample_serum($id); + $this->fn_fix_normal($id); + } + $lang = $this->lang_default_code; + $lang_id = isset($prm['lang_id']) ? $prm['lang_id'] : '0'; + + if ($lang_id != 0) + { + $l = $this->db_smartone->where("Nat_LangID", $lang_id)->get("nat_lang")->row(); + $lang = $l->Nat_LangCode; + } + + //tambahan fajri + $sql = " UPDATE t_orderdetail + JOIN t_test ON T_OrderDetailT_TestID = T_TestID + SET T_OrderDetailT_TestIsResult = T_TestIsResult + WHERE + T_OrderDetailT_OrderHeaderID = {$id} AND + T_OrderDetailT_TestIsResult = '' AND + T_OrderDetailIsActive = 'Y'"; + $this->db_smartone->query($sql); + + $tot_count = 0; + $lq = ""; + $group_id = 0; + if (isset($prm['group_id'])) + $group_id = $prm['group_id']; + + if ($group_id != 0) + { + $sql = "select distinct T_WorklistDetailNat_TestID Nat_TestID + from t_worklistdetailv2 + where T_WorklistDetailT_WorklistID = {$group_id}"; + $qry = $this->db_smartone->query($sql); + $rows = $qry->result_array(); + $nat_test_ids = "0"; + foreach($rows as $r) { + $nat_test_ids .= ", " . $r["Nat_TestID"]; + } + $q_group = " ( $nat_test_ids ) "; + + $sql = " + SELECT a1.*, cOUNT(a2.T_OrderDetailID) level + FROM ( + SELECT IFNULL(y.T_OrderDetailT_TestID, x.T_OrderDetailT_TestID) t_testid, + IFNULL(y.T_OrderDetailT_TestName, y.T_OrderDetailT_TestName) t_testname, + y.T_OrderDetailResult result, y.T_OrderDetailResult result_old, y.T_OrderDetailNote note, y.T_OrderDetailNote note_old, + y.T_OrderDetailID id, + y.T_OrderDetailT_TestIsResult is_result, a.T_TestIsQuantitative is_quantitative, + y.T_OrderDetailResultFlag result_flag, + y.T_OrderDetailNat_NormalValueID normal_id, + y.T_OrderDetailNormalValueNote normal_note, y.T_OrderDetailNat_UnitName unit_name, + y.T_OrderdetailNat_MethodeID methode_id, y.T_OrderdetailNat_MethodeName methode_name, + a.T_TestNat_TestID nattest_id, a.T_TestID tx_id, count(T_ResultInstrumentID) as result_instrument_n, + y.T_OrderDetailVerification, T_OrderSampleReceive sample_receive, + T_OrderSampleProcessing sample_processing, T_OrderSampleWorklistReceive sample_worklist_receive, + IF(T_OrderDetailAddOnPreAnalytic = 'Y', T_OrderDetailAddOnPreAnalytic, PreAnalyticIsOk) pre_analytic, + T_OrderDetailAddOnPreAnalytic, + T_OrderHeaderID order_id, y.T_OrderDetailT_TestSasCode test_sas_code, + tx.T_TestSasCode, + T_OrderDetailAddOnResample `resample`, T_OrderDetailAddOnResampleStatus resample_status, + T_OrderDetailAddOnRef ref, y.T_OrderDetailVerification verification, y.T_OrderDetailValidation validation, + T_OrderPromiseDateTime, Group_ResultName as ResultGroupName + FROM t_orderdetail x + left join t_orderpromise on x.T_OrderDetailT_OrderPromiseID = T_OrderPromiseID + JOIN t_test tx ON x.T_OrderDetailT_TestID = T_TestID + JOIN t_test tcheck on tcheck.T_TestNat_TestID in {$q_group} + and ( tx.T_TestID = tcheck.T_TestID or tx.T_TestSasCode like concat(tcheck.T_TestSasCode,'%')) + LEFT JOIN group_resultdetail ON Group_ResultDetailT_TestID = x.T_OrderDetailT_TestID AND Group_ResultDetailIsActive = 'Y' + LEFT JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND Group_ResultFlagNonLab = 'N' + LEFT JOIN t_orderdetail y ON x.T_OrderDetailT_TestSasCode LIKE CONCAT(y.T_OrderDetailT_TestSasCode, '%') + AND x.T_OrderDetailT_OrderHeaderID = y.T_OrderDetailT_OrderHeaderID + AND y.T_OrderDetailIsActive = 'Y' + LEFT JOIN t_orderdetailaddon ON x.T_OrderDetailID = T_OrderDetailAddOnT_OrderDetailID + JOIN t_orderheader ON y.T_OrderDetailT_OrderHeaderID = T_OrderHeaderID + LEFT JOIN t_test a ON y.T_OrderDetailT_TestID = a.T_TestID + AND a.T_TestIsNonLab = '' + LEFT JOIN (SELECT T_OrderSampleT_SampleTypeID, T_OrderSampleReceive, T_OrderSampleProcessing, T_OrderSampleWorklistReceive + FROM t_ordersample WHERE T_OrderSampleT_OrderHeaderID = {$id} + AND T_OrderSampleIsactive = 'Y' + GROUP BY T_OrderSampleT_SampleTypeID) os ON a.T_TestT_SampleTypeID = os.T_OrderSampleT_SampleTypeID + or os.T_OrderSampleT_SampleTypeID = fn_sampletype_from_local(a.T_TestNat_TestID) + + LEFT JOIN t_resultinstrument ON T_ResultInstrumentT_OrderDetailID = x.T_OrderDetailID + LEFT JOIN pre_analytic ON PreAnalyticNat_TestID = a.T_TestNat_TestID AND PreAnalyticDate = date(now()) and PreAnalyticIsActive = 'Y' + WHERE x.T_OrderDetailT_OrderHeaderID = {$id} + AND x.T_OrderDetailIsActive = 'Y' + GROUP BY y.T_OrderDetailT_TestID + ORDER BY y.T_OrderDetailT_TestSasCode ASC + ) a1 + + LEFT JOIN t_orderdetail a2 ON a2.T_OrderDetailT_OrderHeaderID = a1.order_id + AND a2.T_OrderDetailIsActive = 'Y' + AND a1.test_sas_code LIKE CONCAT(a2.T_OrderDetailT_testSasCode, '%') + GROUP BY a1.t_testid + order by a1.test_sas_code +"; + $query = $this->db_smartone->query($sql); + $lq = $this->db_smartone->last_query(); + } + else + { + $sql = " + SELECT a1.*, cOUNT(a2.T_OrderDetailID) level + FROM ( + SELECT IFNULL(y.T_OrderDetailT_TestID, x.T_OrderDetailT_TestID) t_testid, + IFNULL(y.T_OrderDetailT_TestName, y.T_OrderDetailT_TestName) t_testname, + y.T_OrderDetailResult result, y.T_OrderDetailResult result_old, y.T_OrderDetailNote note, y.T_OrderDetailNote note_old, + y.T_OrderDetailID id, + y.T_OrderDetailT_TestIsResult is_result, a.T_TestIsQuantitative is_quantitative, + y.T_OrderDetailResultFlag result_flag, + y.T_OrderDetailNat_NormalValueID normal_id, + y.T_OrderDetailNormalValueNote normal_note, y.T_OrderDetailNat_UnitName unit_name, + y.T_OrderdetailNat_MethodeID methode_id, y.T_OrderdetailNat_MethodeName methode_name, + a.T_TestNat_TestID nattest_id, a.T_TestID tx_id, count(T_ResultInstrumentID) as result_instrument_n, + y.T_OrderDetailVerification, T_OrderSampleReceive sample_receive, + T_OrderSampleProcessing sample_processing, T_OrderSampleWorklistReceive sample_worklist_receive, + IF(T_OrderDetailAddOnPreAnalytic = 'Y', T_OrderDetailAddOnPreAnalytic, PreAnalyticIsOk) pre_analytic, + T_OrderDetailAddOnPreAnalytic, + T_OrderHeaderID order_id, y.T_OrderDetailT_TestSasCode test_sas_code, + tx.T_TestSasCode, + T_OrderDetailAddOnResample `resample`, T_OrderDetailAddOnResampleStatus resample_status, + T_OrderDetailAddOnRef ref, y.T_OrderDetailVerification verification, y.T_OrderDetailValidation validation, + T_OrderPromiseDateTime , Group_ResultName as ResultGroupName + FROM t_orderdetail x + left join t_orderpromise on x.T_OrderDetailT_OrderPromiseID = T_OrderPromiseID + JOIN t_test tx ON x.T_OrderDetailT_TestID = T_TestID + LEFT JOIN group_resultdetail ON Group_ResultDetailT_TestID = x.T_OrderDetailT_TestID AND Group_ResultDetailIsActive = 'Y' + LEFT JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND Group_ResultFlagNonLab = 'N' + LEFT JOIN t_orderdetail y ON x.T_OrderDetailT_TestSasCode LIKE CONCAT(y.T_OrderDetailT_TestSasCode, '%') + AND x.T_OrderDetailT_OrderHeaderID = y.T_OrderDetailT_OrderHeaderID + AND y.T_OrderDetailIsActive = 'Y' + + LEFT JOIN t_orderdetailaddon ON x.T_OrderDetailID = T_OrderDetailAddOnT_OrderDetailID + + JOIN t_orderheader ON y.T_OrderDetailT_OrderHeaderID = T_OrderHeaderID + LEFT JOIN t_test a ON y.T_OrderDetailT_TestID = a.T_TestID + AND a.T_TestIsNonLab = '' + LEFT JOIN (SELECT T_OrderSampleT_SampleTypeID, T_OrderSampleReceive, T_OrderSampleProcessing, T_OrderSampleWorklistReceive + FROM t_ordersample WHERE T_OrderSampleT_OrderHeaderID = {$id} + AND T_OrderSampleIsactive = 'Y' + GROUP BY T_OrderSampleT_SampleTypeID) os ON a.T_TestT_SampleTypeID = os.T_OrderSampleT_SampleTypeID + or os.T_OrderSampleT_SampleTypeID = fn_sampletype_from_local(a.T_TestNat_TestID) + + LEFT JOIN t_resultinstrument ON T_ResultInstrumentT_OrderDetailID = x.T_OrderDetailID + LEFT JOIN pre_analytic ON PreAnalyticNat_TestID = a.T_TestNat_TestID AND PreAnalyticDate = date(now()) and PreAnalyticIsActive = 'Y' + WHERE x.T_OrderDetailT_OrderHeaderID = {$id} + AND x.T_OrderDetailIsActive = 'Y' + GROUP BY y.T_OrderDetailT_TestID + ORDER BY y.T_OrderDetailT_TestSasCode ASC + ) a1 + + LEFT JOIN t_orderdetail a2 ON a2.T_OrderDetailT_OrderHeaderID = a1.order_id + AND a2.T_OrderDetailIsActive = 'Y' + AND a1.test_sas_code LIKE CONCAT(a2.T_OrderDetailT_testSasCode, '%') + GROUP BY a1.t_testid + order by a1.test_sas_code +"; +//echo $sql; + $query = $this->db_smartone->query($sql); + $lq = $this->db_smartone->last_query(); + } + // file_put_contents("/xtmp/re-query.sql",$lq); + + if ($query) { + $rst = []; + $rows = $query->result_array(); + + foreach($rows as $k => $v) + { + + if ($v['is_result'] == "Y" && $v['is_quantitative'] == "N") + { + $v['template'] = []; + $x = $this->db_smartone->query("CALL sp_master_resulttemplate_get('{$v['t_testid']}')"); + $this->clean_mysqli_connection($this->db_smartone->conn_id); + if ($x) + $v['template'] = $x->result_array(); + } + + // IF Rujukan, by pas Pre Analytik + if ($v['ref'] == 'Y') + $v['pre_analytic'] = 'Y'; + if ($v["id"] == "885455" ) + { + //sipe workaround + //$v["sample_receive"] = "Y"; + $v["sample_worklist_receive"] = "Y"; + } + $rst[] = $v; + } + + $result = array("total" => $tot_count, "records" => $rst, "total_display" => sizeof($rows), "q" => $lq); + $this->sys_ok($result); + } + else { + $this->sys_error_db("RE Px rows", $this->db_smartone); + exit; + } + } + + public function save() + { + $prm = $this->sys_input; + $data = json_decode($prm["data"]); + $lang = $this->lang_default_code; + $lang_id = isset($prm['lang_id']) ? $prm['lang_id'] : '0'; + + if ($lang_id != 0) + { + $l = $this->db_smartone->where("Nat_LangID", $lang_id)->get("nat_lang")->row(); + $lang = $l->Nat_LangCode; + } + + $sql_norm = "select T_OrderDetailMinValue, T_OrderDetailMaxValue, + T_OrderDetailMinValueInclusive, T_OrderDetailMaxValueInclusive, + Nat_TestFlagLow, Nat_TestFlagHigh + from t_orderdetail + join t_test on T_OrderDetailT_TestID = T_TestID + join nat_test on T_TestNat_TestID = Nat_TestID and T_TestIsActive = 'Y' + where T_OrderDetailID = ? "; + + $ids = []; + foreach ($data as $k => $v) + { + if ( $v->resultInstrumentID > 0 ) { + $sql_i = "select T_ResultInstrumentNat_NormalValueID normalValueID + from t_resultinstrument + where T_ResultInstrumentID = ?"; + $qry_i = $this->db_smartone->query($sql_i, array($v->resultInstrumentID)); + if ($qry_i) { + $rows_i = $qry_i->result_array(); + + if (count($rows_i) > 0 ) { + $sql_iu = "update t_orderdetail, nat_normalvalue , nat_methode + set T_OrderDetailMinValue = Nat_NormalValueMinValue, + T_OrderDetailMinValueInclusive = Nat_NormalValueMinValueInclusive, + T_OrderDetailMaxValue = Nat_NormalValueMaxValue , + T_OrderDetailMaxValueInclusive = Nat_NormalValueMaxValueInclusive, + T_OrderDetailNormalValueNote = Nat_NormalValueNote, + T_OrderDetailNormalValueDescription = Nat_NormalValueDescription, + T_OrderDetailNat_NormalValueID = Nat_NormalValueID, + T_OrderDetailNat_MethodeID = Nat_NormalValueNat_MethodeID, + T_OrderDetailNat_MethodeName = Nat_MethodeName + where T_OrderDetailID = ? and Nat_NormalValueID = ? + and Nat_NormalValueNat_MethodeID = Nat_MethodeID + "; + $this->db_smartone->query($sql_iu, array($v->id, $rows_i[0]["normalValueID"])); + //file_put_contents("/xtmp/update-nilai-normal", $this->db_smartone->last_query() . "\n", FILE_APPEND); + } + } + } + $y = $this->db_smartone->query("SELECT fn_process_sample_handling_perfect('{$v->order_id}', '{$v->test_id}') c") + ->row(); + $req_status = $y->c; + $qry_norm = $this->db_smartone->query($sql_norm,$v->id); + $result_flag = ""; + if ($qry_norm) { + $rows_norm = $qry_norm->result_array(); + if (count($rows_norm) > 0 ) { + $r = $rows_norm[0]; + if (is_numeric($v->result)) { + + if ( $r["T_OrderDetailMinValueInclusive"] == "Y" && $v->result < $r["T_OrderDetailMinValue"] ) { + $result_flag = $r["Nat_TestFlagLow"]; + } + if ( $r["T_OrderDetailMinValueInclusive"] == "N" && $v->result <= $r["T_OrderDetailMinValue"] ) { + $result_flag = $r["Nat_TestFlagLow"]; + } + if ( $r["T_OrderDetailMaxValueInclusive"] == "Y" && $v->result > $r["T_OrderDetailMaxValue"] ) { + $result_flag = $r["Nat_TestFlagHigh"]; + } + if ( $r["T_OrderDetailMaxValueInclusive"] == "N" && $v->result >= $r["T_OrderDetailMaxValue"] ) { + $result_flag = $r["Nat_TestFlagHigh"]; + } + } + } + } + if ($lang == $this->lang_default_code) + { + $this->db_smartone->set('T_OrderDetailResult', $v->result) + ->set('T_OrderDetailResultFlag', $result_flag) + ->set('T_OrderDetailNote', $v->note) + ->set('T_OrderDetailReqStatus', $req_status) + ->where('T_OrderDetailID', $v->id) + ->update('t_orderdetail'); + } + else + { + $this->db_smartone->set('T_OrderDetailLangResult', $v->result) + ->set('T_OrderDetailLangNote', $v->note) + ->where('T_OrderDetailLangID', $v->id) + ->update('t_orderdetaillang'); + } + + $ids[] = $v->id; + } + + // LOG Process + $order = $this->db_smartone->select('T_OrderDetailT_OrderHeaderID id, T_OrderHeaderLabNumber lab_number', false) + ->join('t_orderheader', 'T_OrderHeaderID = T_OrderDetailT_OrderHeaderID') + ->where('T_OrderDetailID', $data[0]->id) + ->get('t_orderdetail') + ->row(); + + $dblog = $this->load->database("onelog", true); + $dblog->set('Log_ProcessCode', 'PROCESS.Result.Entry') + ->set('Log_ProcessOrderID', $order->id) + ->set('Log_ProcessOrderNumber', $order->lab_number) + ->set('Log_ProcessJson', json_encode($data)) + ->set('Log_ProcessUserID', $this->sys_user['M_UserID']) + ->insert('log_process'); + // END OF Log Process + //auto calculation + $this->load->library("Resultcalc"); + $rows = $this->resultcalc->auto($order->id); + + try { + foreach($ids as $id ) { + $this->db_smartone->query("call sp_set_normal_value_flag($id)"); + $this->clean_mysqli_connection($this->db_smartone->conn_id); + } + } catch(Exception $e) { + } + + $this->sys_ok($ids); + } + + public function save_template() + { + $prm = $this->sys_input; + + $n = $this->db_smartone->select("COUNT(T_ResultTemplateID) n") + ->where("T_ResultTemplateT_TestID", $prm['test_id']) + ->where("T_ResultTemplateIsActive", "Y") + ->where("T_ResultTemplateValue", $prm['value']) + ->get('t_resulttemplate') + ->row(); + if ($n->n > 0) + { + $this->sys_error_db("Insert Result Template", $this->db_smartone); + return; + } + + $r = $this->db_smartone->set("T_ResultTemplateT_TestID", $prm['test_id']) + ->set("T_ResultTemplateValue", $prm['value']) + ->insert('t_resulttemplate'); + if ($r) + { + $template = []; + $x = $this->db_smartone->query("CALL sp_master_resulttemplate_get('{$prm['test_id']}')"); + $this->clean_mysqli_connection($this->db_smartone->conn_id); + if ($x) + $template = $x->result_array(); + + $this->sys_ok($template); + } + } + + public function export() + { + $prm = $this->sys_input; + + $sql = "CALL sp_process_result_lang(?, ?, ?, ?)"; + $query = $this->db_smartone->query($sql, [$prm['order_id'], $prm['lang_id'], $prm['is_si'], $this->sys_user['M_UserID']]); + if ($query) + { + $r = $query->row(); + if ($r->status == "OK") + { + $this->sys_ok($r->data); + return; + } + + $this->sys_error_db("Message : " . $r->message, $this->db_smartone); + } + else + { + $this->sys_error_db("Lang Result", $this->db_smartone); + return; + } + } + + public function search_group() + { + $prm = $this->sys_input; + $max_rst = 100; + + // QUERY TOTAL + $sql = "select count(*) total + from t_worklist + where T_WorklistIsActive = 'Y' + order by T_WorklistName ASC"; + $query = $this->db_smartone->query($sql); + + if ($query) { + $tot_count = $query->result_array()[0]["total"]; + } + else { + $this->sys_error_db("worklist count", $this->db_smartone); + exit; + } + + $sql = "select T_WorklistID group_id, T_WorklistName group_name + from t_worklist + where T_WorklistIsActive = 'Y' + order by T_WorklistName ASC + limit 0, {$max_rst}"; + $query = $this->db_smartone->query($sql); + + if ($query) { + $rows = $query->result_array(); + foreach ($rows as $k => $v) + $rows[$k]['data'] = json_decode($v['data']); + $result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows), "q" => $this->db_smartone->last_query()); + $this->sys_ok($result); + } + else { + $this->sys_error_db("worklist rows", $this->db_smartone); + exit; + } + } + + public function search_rerun() + { + $prm = $this->sys_input; + $id = $prm["detail_id"]; + + $sql = "CALL sp_process_result_rerun(?)"; + $query = $this->db_smartone->query($sql, [$id]); + + if ($query) + { + $rows = $query->result_array(); + $this->sys_ok(["records"=>$rows]); + } + else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + + + function getdoctorsfna() + { + $prm = $this->sys_input; + // $id = $prm["id"]; + + $sql = " SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY M_DoctorName ASC"; + //echo $sql; + $query = $this->db_smartone->query($sql); + + if ($query) + { + $rows = $query->result_array(); + $this->sys_ok(["records"=>$rows]); + } + else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + function getfnaresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT Other_FNADetailsID as xid, + Other_FNAT_OrderDetailID as orderdetail_id, + Other_FNADetailsCode as code, + Other_FNADetailsLabel as label, + Other_FNADetailsResult as result, + IFNULL(Other_FNAM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_FNAM_DoctorID) OR Other_FNAM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_fna + JOIN other_fnadetails ON Other_FNADetailsOther_FNAID = Other_FNAID AND Other_FNADetailsIsActive = 'Y' + LEFT JOIN m_doctor ON Other_FNAM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_FNAT_OrderDetailID = {$id} AND Other_FNAIsActive = 'Y' + GROUP BY Other_FNADetailsID + ORDER BY Other_FNADetailsCode ASC"; + $query = $this->db_smartone->query($sql); + + if ($query) + { + $rows = $query->result_array(); + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $images = array(); + $sql = "SELECT So_ImageUploadID as xid, + CONCAT('/one-media/one-image-nonlab/',So_ImageUploadNewName) as image_url + FROM t_orderdetail + JOIN so_imageupload ON So_ImageUploadT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND + So_ImageUploadIsActive = 'Y' + WHERE + T_OrderDetailID = {$id} AND + T_OrderDetailIsActive = 'Y' + GROUP BY So_ImageUploadID"; + $images = $this->db_smartone->query($sql)->result_array(); + + $rst = array('doctors'=>$doctors,'results'=>$rows,'images'=>$images); + $this->sys_ok(["records"=>$rst]); + } + else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + + function uploadimage(){ + if (! $this->isLogin) { + $this->sys_error("Invalid Token"); + exit; + } + + $userid = $this->sys_user["M_UserID"]; + $data = []; + //print_r($_SERVER); + + $prm = $this->sys_input; + $orderid = $this->input->post('orderid'); + $labnumber = $this->input->post('labnumber'); + $sql = "UPDATE so_imageupload SET + So_ImageUploadIsActive = 'N', + So_ImageUploadUserID = {$userid} + WHERE + So_ImageUploadT_OrderHeaderID = {$orderid}"; + //echo $sql; + $this->db_onedev->query($sql); + //$config['upload_path'] = 'assets/'; + + $path = '/home/one/project/one/one-media/one-image-nonlab/'; + //echo $path; + $config['upload_path'] = $path; + $config['allowed_types'] = 'jpg|jpeg|png|gif'; + + $config['max_size'] = '10000'; + $count = count($_FILES['files']['name']); + //echo $count; + $this->load->library('upload',$config); + + $error = []; + for($i=0;$i<$count;$i++){ + + + if(!empty($_FILES['files']['name'][$i])){ + + + + $_FILES['file']['name'] = $_FILES['files']['name'][$i]; + + $_FILES['file']['type'] = $_FILES['files']['type'][$i]; + + $_FILES['file']['tmp_name'] = $_FILES['files']['tmp_name'][$i]; + + $_FILES['file']['error'] = $_FILES['files']['error'][$i]; + + $_FILES['file']['size'] = $_FILES['files']['size'][$i]; + + + + $namex = $orderid.'-'.$labnumber.'-'.$this->generateRandomString(5); + //echo $namex; + + $config['file_name'] = $namex; + $this->upload->initialize($config); + //echo $config['file_name'] ; + + + + + + if($this->upload->do_upload('file')){ + + $uploadData = $this->upload->data(); + + $filename = $uploadData['file_name']; + //echo $filename; + + + $sql = "INSERT INTO so_imageupload ( + So_ImageUploadT_OrderHeaderID, + So_ImageUploadT_OrderHeaderLabNumber, + So_ImageUploadT_SampleTypeID, + So_ImageUploadOldName, + So_ImageUploadNewName, + So_ImageUploadCreated, + So_ImageUploadUserID + ) + VALUES( + {$orderid}, + '{$labnumber}', + '150', + '{$_FILES['files']['name'][$i]}', + '{$filename}', + NOW(), + {$userid} + + )"; + //echo $sql; + $this->db_onedev->query($sql); + $xlast_id = $this->db_onedev->insert_id(); + $data['totalFiles'][] = array('xid' => $xlast_id ,'image_url' => '/one-media/one-image-nonlab/'.$filename); + + } + else{ + $error = array('error' => $this->upload->display_errors()); + } + + } + + + + } + + $result = array("total" =>count( $data['totalFiles']), "records" => $data['totalFiles'],'errors'=>$error); + $this->sys_ok($result); + } + + + function generateRandomString($length = 10) { + $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; + $charactersLength = strlen($characters); + $randomString = ''; + for ($i = 0; $i < $length; $i++) { + $randomString .= $characters[rand(0, $charactersLength - 1)]; + } + return $randomString; + } + + function getcytologiresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT Other_CytologiDetailsID as xid, + Other_CytologiT_OrderDetailID as orderdetail_id, + Other_CytologiDetailsCode as code, + Other_CytologiDetailsLabel as label, + Other_CytologiDetailsResult as result, + IFNULL(Other_CytologiM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_CytologiM_DoctorID) OR Other_CytologiM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_cytologi + JOIN other_cytologidetails ON Other_CytologiDetailsOther_CytologiID = Other_CytologiID AND Other_CytologiDetailsIsActive = 'Y' + LEFT JOIN m_doctor ON Other_CytologiM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_CytologiT_OrderDetailID = {$id} AND Other_CytologiIsActive = 'Y' + GROUP BY Other_CytologiDetailsID + ORDER BY Other_CytologiDetailsCode ASC"; + //echo $sql; + $query = $this->db_smartone->query($sql); + + if ($query) + { + $rows = $query->result_array(); + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $rst = array('doctors'=>$doctors,'results'=>$rows); + $this->sys_ok(["records"=>$rst]); + } + else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + function getmikroresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT + Other_MikroID as xid, + Other_MikroHasilBiakan as hasil_biakan, + Other_MikroSampleTypeName as sample_name, + Other_MikroT_OrderDetailID as orderdetail_id, + Other_MikroResult as result_value, + '' as result_other, + IFNULL(T_BacteriaID,0) as T_BacteriaID, + IFNULL(T_BacteriaName,'') as T_BacteriaName, + '' as details, + IFNULL(Other_MikroM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_MikroM_DoctorID) OR Other_MikroM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_mikro + LEFT JOIN t_bacteria ON Other_MikroT_BacteriaID = T_BacteriaID + LEFT JOIN m_doctor ON Other_MikroM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_MikroT_OrderDetailID = {$id} AND Other_MikroIsActive = 'Y' + GROUP BY Other_MikroID"; + //echo $sql; + $query = $this->db_smartone->query($sql); + + if ($query) + { + $row = $query->row_array(); + if($row){ + if($row['result_value'] != 'Positif' && $row['result_value'] != 'Negatif'){ + $row['result_other'] = $row['result_value']; + $row['result_value'] = 'other'; + } + $sql = "SELECT '' as xno, + Other_MikroDetailsID as xid, + Other_MikroDetailsValue as value, + IF(Other_MikroDetailsNote = 'R','Y','N') as chx_r, + IF(Other_MikroDetailsNote = 'I','Y','N') as chx_i, + IF(Other_MikroDetailsNote = 'S','Y','N') as chx_s, + Other_MikroDetailsNote as note, + t_antibiotic.* + FROM other_mikrodetails + LEFT JOIN t_antibiotic ON Other_MikroDetailsT_AntibioticID = T_AntibioticID + WHERE + Other_MikroDetailsOther_MikroID = {$row['xid']} AND Other_MikroDetailsIsActive = 'Y' + GROUP BY Other_MikroDetailsID + ORDER BY T_AntibioticName ASC"; + //echo $sql; + $details = $this->db_smartone->query($sql)->result_array(); + if(details){ + foreach($details as $k => $v){ + $details[$k]['xno'] = $k + 1; + } + } + $row['details'] = $details; + } + else{ + $row = array('xid'=>'0','hasil_biakan' => '','result_value'=>'Negatif','sample_name' => '','orderdetail_id'=>$id, 'T_BacteriaID'=>'0','T_BacteriaName'=>'0','details'=>array(),'doctor_id'=>'0','doctor_name'=>'0'); + } + } + else{ + $row = array('xid'=>'0','hasil_biakan' => '','result_value'=>'Negatif','sample_name' => '','orderdetail_id'=>$id, 'T_BacteriaID'=>'0','T_BacteriaName'=>'0','details'=>array(),'doctor_id'=>'0','doctor_name'=>'0'); + } + //print_r($row); + + + + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 7 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $sql = " + SELECT '0' as id, 'Belum memilih bakteria' as name + UNION + SELECT T_BacteriaID as id, T_BacteriaName as name + FROM t_bacteria + WHERE + T_BacteriaIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $bacteries = $this->db_smartone->query($sql)->result_array(); + $rst = array('doctors'=>$doctors,'bacteries'=>$bacteries,'results'=>$row); + $this->sys_ok(["records"=>$rst]); + } + function getantibiotics(){ + $prm = $this->sys_input; + $id = $prm["id"]; + $sql = " SELECT '' as xno, + 0 as xid, + '' as hasil_biakan, + '' as sample_name, + 0 as value, + 'Y' as chx_r, + 'N' as chx_i, + 'N' as chx_s, + 'R' as note, + t_antibiotic.* + FROM t_antibiotic + WHERE + T_AntibioticT_BacteriaID = {$prm['id']} AND T_AntibioticIsActive= 'Y' + ORDER BY T_AntibioticName ASC"; + //echo $sql; + $rows = $this->db_smartone->query($sql)->result_array(); + if(rows){ + foreach($rows as $k => $v){ + $rows[$k]['xno'] = $k + 1; + } + } + + $this->sys_ok(["records"=>$rows]); + } + function getlcprepresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + $sql = " SELECT Other_LcprepDetailsID as xid, + Other_LcprepID as header_id, + Other_LcprepT_orderDetailID as orderdetail_id, + Other_LcprepDetailsCode as code, + Other_LcprepDetailsLabel as label, + Other_LcprepDetailsResult as result, + IFNULL(Other_LcprepM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_LcprepM_DoctorID) OR Other_LcprepM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_lcprep + JOIN other_lcprepdetails ON Other_LcprepDetailsOther_LcprepID = Other_LcprepID AND Other_LcprepDetailsIsActive = 'Y' + LEFT JOIN m_doctor ON Other_LcprepM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_LcprepT_orderDetailID = {$id} AND Other_LcprepIsActive = 'Y' + GROUP BY Other_LcprepDetailsOther_LcprepID, Other_LcprepDetailsCode + ORDER BY Other_LcprepDetailsCode ASC"; + //echo $sql; + $rows = $this->db_smartone->query($sql)->result_array(); + if(!$rows){ + $rows = array( + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'A', + 'label' => 'DESKRIPSI', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ), + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'B', + 'label' => 'KESIMPULAN', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ) + ); + } + + $header_id = $rows[0]['header_id']; + $sql = "SELECT IFNULL(Other_LcprepAdekuasiID,0) as xid, + Lcprep_AdekuasiID as id, + Lcprep_AdekuasiLabel as name, + IF(ISNULL(Other_LcprepAdekuasiID),'N',Other_LcprepAdekuasiChex) as chex + FROM lcprep_adekuasi + LEFT JOIN other_lcprepadekuasi ON Other_LcprepAdekuasiLcprep_AdekuasiID = Lcprep_AdekuasiID AND + Other_LcprepAdekuasiOther_LcprepID = {$header_id} AND + Other_LcprepAdekuasiIsActive = 'Y' + WHERE + Lcprep_AdekuasiIsActive = 'Y' + GROUP BY Lcprep_AdekuasiID + ORDER BY Lcprep_AdekuasiOrder ASC + "; + //echo $sql; + $adeakuasi = $this->db_smartone->query($sql)->result_array(); + foreach($adeakuasi as $kc => $vc){ + $adeakuasi[$kc]['chex'] = $vc['chex'] == 'N'?false:true; + } + + $sql = "SELECT IFNULL(Other_LcprepKategoriUmumID,0) as xid, + Lcprep_KategoriUmumID as id, + Lcprep_KategoriUmumLabel as name, + IF(ISNULL(Other_LcprepKategoriUmumID),'N',Other_LcprepKategoriUmumChex) as chex + FROM lcprep_kategoriumum + LEFT JOIN other_lcprepkategoriumum ON Other_LcprepKategoriUmumLcprep_KategoriUmumID = Lcprep_KategoriUmumID AND + Other_LcprepKategoriUmumOther_LcprepID = {$header_id} AND + Other_LcprepKategoriUmumIsActive = 'Y' + WHERE + Lcprep_KategoriUmumIsActive = 'Y' + GROUP BY Lcprep_KategoriUmumID + "; + //echo $sql; + $kategoriumum = $this->db_smartone->query($sql)->result_array(); + foreach($kategoriumum as $kc => $vc){ + $kategoriumum[$kc]['chex'] = $vc['chex'] == 'N'?false:true; + } + + $sql = " + SELECT Lcprep_InterpretasiGroupID as group_id, + Lcprep_InterpretasiGroupName as group_name, + '' as subgroups + FROM lcprep_interpretasigroup + WHERE + Lcprep_InterpretasiGroupIsActive = 'Y' + "; + //echo $sql; + $interpretasi = $this->db_smartone->query($sql)->result_array(); + foreach($interpretasi as $k => $v){ + $subgroups = array(); + $sql = "SELECT Lcprep_InterpretasiSubgroupID as subgroup_id, + Lcprep_InterpretasiSubgroupName as subgroup_name, + '' as childs + FROM lcprep_interpretasisubgroup + WHERE + Lcprep_InterpretasiSubgroupLcprep_InterpretasiGroupID = {$v['group_id']} AND Lcprep_InterpretasiSubgroupIsActive = 'Y'"; + //echo $sql; + $subgroups = $this->db_smartone->query($sql)->result_array(); + if(count($subgroups) > 0){ + foreach($subgroups as $ki => $vi){ + $childs = array(); + $sql = "SELECT IFNULL(Other_LcprepInterpretasiID,0) as xid, + IFNULL(Other_LcprepInterpretasiChex,'N') as chex, + IFNULL(Other_LcprepInterpretasiValue,'') as value, + Lcprep_InterpretasiID as id, + Lcprep_InterpretasiLcprep_InterpretasiSubgroupID as subgroup_id, + Lcprep_InterpretasiCode as code, + Lcprep_InterpretasiName as name, + Lcprep_InterpretasiParentID as parent_id, + Lcprep_InterpretasiIsParent as is_parent, + Lcprep_InterpretasiHasResult as has_result, + Lcprep_InterpretasiTypeResult as type_result + FROM lcprep_interpretasi + LEFT JOIN other_lcprepinterpretasi ON Other_LcprepInterpretasiOther_LcprepID = {$header_id} AND + Other_LcprepInterpretasiLcprep_InterpretasiID = Lcprep_InterpretasiID AND + Other_LcprepInterpretasiIsActive = 'Y' + WHERE + Lcprep_InterpretasiLcprep_InterpretasiSubgroupID = {$vi['subgroup_id']} AND Lcprep_InterpretasiIsActive = 'Y' + GROUP BY Lcprep_InterpretasiID Order BY Lcprep_InterpretasiCode ASC"; + $childs = $this->db_smartone->query($sql)->result_array(); + if($childs){ + foreach($childs as $kc => $vc){ + $childs[$kc]['chex'] = $vc['chex'] == 'N'?false:true; + } + } + $subgroups[$ki]['childs'] = $childs; + } + } + + $interpretasi[$k]['subgroups'] = $subgroups; + } + + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $rst = array('doctors'=>$doctors,'results'=>$rows,'adekuasi'=>$adeakuasi,'kategoriumum'=>$kategoriumum,'interpretasi'=>$interpretasi); + $this->sys_ok(["records"=>$rst]); + } + + function getpapsmearresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT Other_PapSmearDetailsID as xid, + Other_PapSmearID as header_id, + Other_PapSmearT_OrderDetailID as orderdetail_id, + Other_PapSmearDetailsCode as code, + Other_PapSmearDetailsLabel as label, + Other_PapSmearDetailsResult as result, + IFNULL(Other_PapSmearM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_PapSmearM_DoctorID) OR Other_PapSmearM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_papsmear + JOIN other_papsmeardetails ON Other_PapSmearDetailsOther_PapSmearID = Other_PapSmearID AND Other_PapSmearDetailsIsActive = 'Y' + LEFT JOIN m_doctor ON Other_PapSmearM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_PapSmearT_OrderDetailID = {$id} AND Other_PapSmearIsActive = 'Y' + GROUP BY Other_PapSmearDetailsID + ORDER BY Other_PapSmearDetailsCode ASC"; + //echo $sql; + $rows = $this->db_smartone->query($sql)->result_array(); + if(!$rows){ + $rows = array( + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'A', + 'label' => 'Makroskopik', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ), + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'B', + 'label' => 'Mikroskopik', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ), + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'C', + 'label' => 'Kesimpulan', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ) + ); + } + + $header_id = $rows[0]['header_id']; + $sql = "SELECT Other_PapSmearMaturasiID as xid, + Other_PapSmearMaturasiValue as value + FROM other_papsmearmaturasi + WHERE + Other_PapSmearMaturasiOther_PapSmearID = {$header_id} AND + Other_PapSmearMaturasiIsActive = 'Y' + "; + //echo $sql; + $dt_maturasi = $this->db_smartone->query($sql)->row_array(); + if(!$dt_maturasi){ + $maturasi = array('xid'=>'0','value'=> array('','','')); + } + else{ + $value = explode('/',$dt_maturasi['value']); + $maturasi = array('xid'=>$dt_maturasi['xid'],'value'=> $value); + } + + $sql = "SELECT IFNULL(Other_PapSmearBahanID,0) as xid, + M_PapSmearBahanID as bahan_id, + M_PapSmearBahanName as name, + IF(ISNULL(Other_PapSmearBahanID),'N','Y') as selected + FROM m_papsmearbahan + LEFT JOIN other_papsmearbahan ON Other_PapSmearBahanM_PapSmearBahanID = M_PapSmearBahanID AND + Other_PapSmearBahanOther_PapSmearID = {$header_id} AND + Other_PapSmearBahanIsActive = 'Y' + WHERE + M_PapSmearBahanIsActive = 'Y' + ORDER BY M_PapSmearBahanID ASC + "; + //echo $sql; + $bahans = $this->db_smartone->query($sql)->result_array(); + + $sql = "SELECT IFNULL(Other_PapsmearCategoryID,0) as xid, + M_PapSmearCategoryID as category_id, + M_PapSmearCategoryName as name, + IF(ISNULL(Other_PapsmearCategoryID),'N','Y') as selected + FROM m_papsmearcategory + LEFT JOIN other_papsmearcategory ON Other_PapsmearCategoryM_PapSmearCategoryID = M_PapSmearCategoryID AND + Other_PapsmearCategoryOther_PapSmearID = {$header_id} AND + Other_PapsmearCategoryIsActive = 'Y' + WHERE + M_PapSmearCategoryIsActive = 'Y' + ORDER BY M_PapSmearCategoryID ASC + "; + //echo $sql; + $categories = $this->db_smartone->query($sql)->result_array(); + + $sql = "SELECT IFNULL(Other_PapSmearCheckID,0) as xid, + M_PapSmearCheckID as check_id, + M_PapSmearCheckLabel as name, + IF(ISNULL(Other_PapSmearCheckID),'N','Y') as selected, + Other_PapSmearCheckNote as note + FROM m_papsmearcheck + LEFT JOIN other_papsmearcheck ON Other_PapSmearCheckM_PapSmearCheckID = M_PapSmearCheckID AND + Other_PapSmearCheckOther_PapSmearID = {$header_id} AND + Other_PapSmearCheckIsActive = 'Y' + WHERE + M_PapSmearCheckIsActive = 'Y' + ORDER BY M_PapSmearCheckCode ASC + "; + $checks = $this->db_smartone->query($sql)->result_array(); + + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $rst = array('doctors'=>$doctors,'checks'=>$checks,'bahans'=>$bahans,'categories'=>$categories,'maturasi'=>$maturasi,'results'=>$rows); + $this->sys_ok(["records"=>$rst]); + + } + + function saveresult_lcprep() + { + $prm = $this->sys_input; + $detail_id = $prm['detail_id']; + $doctor_id = $prm['doctor']; + $adekuasi = $prm['adekuasi']; + $kategoriumum = $prm['kategoriumum']; + $interpretasi = $prm['interpretasi']; + $results = $prm['results']; + + $userid = $this->sys_user['M_UserID']; + + $header_id = 0; + $sql = "SELECT * FROM other_lcprep WHERE Other_LcprepT_orderDetailID = {$detail_id} AND Other_LcprepIsActive = 'Y'"; + $dt_header = $this->db_smartone->query($sql)->row_array(); + if($dt_header){ + $header_id = $dt_header['Other_LcprepID']; + } + if($header_id == 0){ + $sql = "INSERT INTO other_lcprep( + Other_LcprepT_orderDetailID, + Other_LcprepM_DoctorID, + Other_LcprepUserID, + Other_LcprepCreated + ) + VALUES( + {$detail_id}, + {$doctor_id}, + {$userid}, + NOW() + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + }else{ + $sql = "UPDATE other_lcprep SET Other_LcprepM_DoctorID = {$doctor_id}, Other_LcprepUserID = {$userid} WHERE Other_LcprepID = {$header_id}"; + $this->db_smartone->query($sql); + } + + if($adekuasi){ + foreach($adekuasi as $k =>$v){ + $selected = $v['chex']?'Y':'N'; + if(intval($v['xid'] == 0)){ + $sql = "UPDATE other_lcprepadekuasi SET Other_LcprepAdekuasiIsActive = 'N' + WHERE + Other_LcprepAdekuasiOther_LcprepID = {$header_id} AND + Other_LcprepAdekuasiIsActive = 'Y' AND + Other_LcprepAdekuasiLcprep_AdekuasiID = {$v['id']}"; + $this->db_smartone->query($sql); + $sql = "INSERT INTO other_lcprepadekuasi ( + Other_LcprepAdekuasiOther_LcprepID, + Other_LcprepAdekuasiLcprep_AdekuasiID, + Other_LcprepAdekuasiChex, + Other_LcprepAdekuasiUserID, + Other_LcprepAdekuasiCreated + ) + VALUES( + {$header_id}, + {$v['id']}, + '{$selected}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + //echo $sql; + } + if(intval($v['xid'] != 0)){ + + $sql = "UPDATE other_lcprepadekuasi SET + Other_LcprepAdekuasiChex = '{$selected}', + Other_LcprepAdekuasiUserID = {$userid} + WHERE + Other_LcprepAdekuasiID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + + //echo $sql; + } + } + + if($kategoriumum){ + foreach($kategoriumum as $k =>$v){ + $selected = $v['chex']?'Y':'N'; + if(intval($v['xid'] == 0)){ + $sql = "UPDATE other_lcprepkategoriumum SET Other_LcprepKategoriUmumIsActive = 'N' + WHERE + Other_LcprepKategoriUmumOther_LcprepID = {$header_id} AND + Other_LcprepKategoriUmumLcprep_KategoriUmumID = {$v['id']} AND + Other_LcprepKategoriUmumIsActive = 'Y' + "; + $this->db_smartone->query($sql); + $sql = "INSERT INTO other_lcprepkategoriumum ( + Other_LcprepKategoriUmumOther_LcprepID, + Other_LcprepKategoriUmumLcprep_KategoriUmumID, + Other_LcprepKategoriUmumChex, + Other_LcprepKategoriUmumUserID, + Other_LcprepKategoriUmumCreated + ) + VALUES( + {$header_id}, + {$v['id']}, + '{$selected}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if(intval($v['xid'] != 0)){ + $sql = "UPDATE other_lcprepkategoriumum SET + Other_LcprepKategoriUmumChex = '{$selected }', + Other_LcprepKategoriUmumUserID = {$userid} + WHERE + Other_LcprepKategoriUmumID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + + //echo $sql; + } + } + + if($results){ + foreach($results as $k =>$v){ + if(intval($v['xid'] == 0)){ + $sql = "UPDATE other_lcprepdetails SET Other_LcprepDetailsIsActive = 'N' + WHERE + Other_LcprepDetailsOther_LcprepID = {$header_id} AND + Other_LcprepDetailsCode = '{$v['code']}' AND + Other_LcprepDetailsIsActive = 'Y'"; + $this->db_smartone->query($sql); + $sql = "INSERT INTO other_lcprepdetails ( + Other_LcprepDetailsOther_LcprepID, + Other_LcprepDetailsCode, + Other_LcprepDetailsLabel, + Other_LcprepDetailsResult, + Other_LcprepDetailsUserID, + Other_LcprepDetailsCreated + ) + VALUES( + {$header_id}, + '{$v['code']}', + '{$v['label']}', + '{$v['result']}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if(intval($v['xid'] != 0)){ + $sql = "UPDATE other_lcprepdetails SET + Other_LcprepDetailsCode = '{$v['code']}', + Other_LcprepDetailsLabel = '{$v['label']}', + Other_LcprepDetailsResult = '{$v['result']}', + Other_LcprepDetailsUserID = {$userid} + WHERE + Other_LcprepDetailsID = {$v['xid']}"; + $this->db_smartone->query($sql); + + } + //echo $sql; + } + } + + if($interpretasi){ + foreach($interpretasi as $k =>$v){ + if(count($v['subgroups']) > 0){ + foreach($v['subgroups'] as $ik => $iv){ + if(count($iv['childs']) > 0){ + foreach($iv['childs'] as $iik => $iiv){ + if(intval($iiv['xid'] == 0)){ + $chex = $iiv['chex'] ? 'Y':'N'; + $sql = "UPDATE other_lcprepinterpretasi SET Other_LcprepInterpretasiIsActive = 'N' + WHERE + Other_LcprepInterpretasiOther_LcprepID = {$header_id} AND + Other_LcprepInterpretasiLcprep_InterpretasiID = '{$iiv['id']}' AND + Other_LcprepInterpretasiIsActive = 'Y'"; + $this->db_smartone->query($sql); + $sql = "INSERT INTO other_lcprepinterpretasi ( + Other_LcprepInterpretasiOther_LcprepID, + Other_LcprepInterpretasiLcprep_InterpretasiID, + Other_LcprepInterpretasiChex, + Other_LcprepInterpretasiValue, + Other_LcprepInterpretasiUserID, + Other_LcprepInterpretasiCreated + ) + VALUES( + {$header_id}, + '{$iiv['id']}', + '{$chex}', + '{$iiv['value']}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + + if(intval($iiv['xid'] != 0)){ + $chex = $iiv['chex'] ? 'Y':'N'; + $sql = "UPDATE other_lcprepinterpretasi SET + Other_LcprepInterpretasiChex = '{$chex}', + Other_LcprepInterpretasiValue = '{$iiv['value']}', + Other_LcprepInterpretasiUserID = {$userid} + WHERE + Other_LcprepInterpretasiID = {$iiv['xid']}"; + $this->db_smartone->query($sql); + //echo $sql; + + } + + } + } + } + } + //echo $sql; + } + } + + + $result = array("total" => 1, "records" => array(), "sql"=> ''); + $this->sys_ok($result); + exit; + } + + function saveresult_papsmear() + { + $prm = $this->sys_input; + $detail_id = $prm['detail_id']; + $doctor_id = $prm['doctor']; + $checks = $prm['checks']; + $maturasi = $prm['maturasi']; + $bahans = $prm['bahans']; + $categories = $prm['categories']; + $results = $prm['results']; + + $userid = $this->sys_user['M_UserID']; + + $header_id = 0; + $sql = "SELECT * FROM other_papsmear WHERE Other_PapSmearT_OrderDetailID = {$detail_id} AND Other_PapSmearIsActive = 'Y'"; + $dt_header = $this->db_smartone->query($sql)->row_array(); + if($dt_header){ + $header_id = $dt_header['Other_PapSmearID']; + } + if($header_id == 0){ + $sql = "INSERT INTO other_papsmear( + Other_PapSmearT_OrderDetailID, + Other_PapSmearM_DoctorID, + Other_PapSmearUserID, + Other_PapSmearCreated + ) + VALUES( + {$detail_id}, + {$doctor_id}, + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } + else{ + $sql = "UPDATE other_papsmear SET Other_PapSmearM_DoctorID = {$doctor_id}, Other_PapSmearUserID = {$userid} WHERE Other_PapSmearID = {$header_id}"; + $this->db_smartone->query($sql); + } + + if($checks){ + foreach($checks as $k =>$v){ + if(intval($v['xid']) == 0 && $v['selected'] === 'Y'){ + $sql = "INSERT INTO other_papsmearcheck ( + Other_PapSmearCheckOther_PapSmearID, + Other_PapSmearCheckM_PapSmearCheckID, + Other_PapSmearCheckNote, + Other_PapSmearCheckUserID, + Other_PapSmearCheckCreated + ) + VALUES( + {$header_id}, + {$v['check_id']}, + '{$v['note']}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if(intval($v['xid']) != 0 && $v['selected'] === 'N'){ + $sql = "UPDATE other_papsmearcheck SET + Other_PapSmearCheckIsActive = 'N', + Other_PapSmearCheckUserID = {$userid} + WHERE + Other_PapSmearCheckID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + if(intval($v['xid']) != 0 && $v['selected'] === 'Y'){ + $sql = "UPDATE other_papsmearcheck SET + Other_PapSmearCheckNote = '{$v['note']}', + Other_PapSmearCheckUserID = {$userid} + WHERE + Other_PapSmearCheckID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + //echo $sql; + } + } + + if($maturasi){ + if(intval($maturasi['xid']) == 0){ + $value = join("/",$maturasi['value']); + $sql = "INSERT INTO other_papsmearmaturasi ( + Other_PapSmearMaturasiOther_PapSmearID, + Other_PapSmearMaturasiValue, + Other_PapSmearMaturasiUserID, + Other_PapSmearMaturasiCreated + ) + VALUE( + {$header_id}, + '{$value}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + //echo $sql; + } + if(intval($maturasi['xid']) != 0){ + $value = join("/",$maturasi['value']); + $sql = "UPDATE other_papsmearmaturasi SET + Other_PapSmearMaturasiValue = '{$value}', + Other_PapSmearMaturasiUserID = {$userid} + WHERE + Other_PapSmearMaturasiID = {$maturasi['xid']}"; + // echo $sql; + $this->db_smartone->query($sql); + } + } + + if($bahans){ + foreach($bahans as $k =>$v){ + if(intval($v['xid']) == 0 && $v['selected'] === 'Y'){ + $sql = "INSERT INTO other_papsmearbahan ( + Other_PapSmearBahanOther_PapSmearID, + Other_PapSmearBahanM_PapSmearBahanID, + Other_PapSmearBahanUserID, + Other_PapSmearBahanCreated + ) + VALUES( + {$header_id}, + {$v['bahan_id']}, + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if(intval($v['xid']) != 0 && $v['selected'] === 'N'){ + $sql = "UPDATE other_papsmearbahan SET + Other_PapSmearBahanIsActive = 'N', + Other_PapsmearCategoryUserID = {$userid} + WHERE + Other_PapSmearBahanID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + if(intval($v['xid']) != 0 && $v['selected'] === 'Y'){ + $sql = "UPDATE other_papsmearbahan SET + Other_PapSmearBahanIsActive = 'Y', + Other_PapsmearCategoryUserID = {$userid} + WHERE + Other_PapSmearBahanID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + //echo $sql; + } + } + + if($categories){ + foreach($categories as $k =>$v){ + if(intval($v['xid']) == 0 && $v['selected'] === 'Y'){ + $sql = "INSERT INTO other_papsmearcategory ( + Other_PapsmearCategoryOther_PapSmearID, + Other_PapsmearCategoryM_PapSmearCategoryID, + Other_PapsmearCategoryUserID, + Other_PapsmearCategoryCreated + ) + VALUES( + {$header_id}, + {$v['category_id']}, + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if(intval($v['xid']) != 0 && $v['selected'] === 'N'){ + $sql = "UPDATE other_papsmearcategory SET + Other_PapsmearCategoryIsActive = 'N', + Other_PapsmearCategoryUserID = {$userid} + WHERE + Other_PapsmearCategoryID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + //echo $sql; + if(intval($v['xid']) != 0 && $v['selected'] === 'Y'){ + $sql = "UPDATE other_papsmearcategory SET + Other_PapsmearCategoryIsActive = 'Y', + Other_PapsmearCategoryUserID = {$userid} + WHERE + Other_PapsmearCategoryID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + } + } + + if($results){ + foreach($results as $k =>$v){ + if(intval($v['xid']) == 0){ + $sql = "INSERT INTO other_papsmeardetails ( + Other_PapSmearDetailsOther_PapSmearID, + Other_PapSmearDetailsCode, + Other_PapSmearDetailsLabel, + Other_PapSmearDetailsResult, + Other_PapSmearDetailsUserID, + Other_PapSmearDetailsCreated + ) + VALUES( + {$header_id}, + '{$v['code']}', + '{$v['label']}', + '{$v['result']}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if(intval($v['xid']) != 0){ + $sql = "UPDATE other_papsmeardetails SET + Other_PapSmearDetailsCode = '{$v['code']}', + Other_PapSmearDetailsLabel = '{$v['label']}', + Other_PapSmearDetailsResult = '{$v['result']}', + Other_PapSmearDetailsUserID = {$userid} + WHERE + Other_PapSmearDetailsID = {$v['xid']}"; + $this->db_smartone->query($sql); + + } + //echo $sql; + } + } + + $result = array("total" => 1, "records" => array(), "sql"=> ''); + $this->sys_ok($result); + exit; + } + + function saveresult_fna() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = $inp['doctor']; + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + if($prm[0]['xid'] == '0'){ + $sql = "INSERT INTO other_fna( + Other_FNAM_DoctorID, + Other_FNAT_OrderDetailID, + Other_FNAUserID, + Other_FNACreated + ) + VALUES( + {$doctor_id}, + {$prm[0]['orderdetail_id']}, + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } + else{ + $sql = "SELECT * FROM other_fna WHERE Other_FNAT_OrderDetailID = {$prm[0]['orderdetail_id']} AND Other_FNAIsActive = 'Y'"; + $data_header = $this->db_smartone->query($sql)->row_array(); + $header_id = $data_header['Other_FNAID']; + $sql = "UPDATE other_fna SET + Other_FNAM_DoctorID = {$doctor_id}, + Other_FNAUserID = {$userid} + WHERE + Other_FNAID = {$header_id}"; + $this->db_smartone->query($sql); + } + foreach($prm as $k => $v){ + if($v['xid'] == '0'){ + $results = str_replace("'", "\\'", $v['result']); + $sql = "INSERT INTO other_fnadetails( + Other_FNADetailsOther_FNAID , + Other_FNADetailsCode, + Other_FNADetailsLabel, + Other_FNADetailsResult, + Other_FNADetailsCreated, + Other_FNADetailsUserID + ) + VALUES( + {$header_id}, + '{$v['code']}', + '{$v['label']}', + '{$results}', + NOW(), + {$userid} + )"; + $query = $this->db_smartone->query($sql); + } + else{ + $results = str_replace("'", "\\'", $v['result']); + $sql = "UPDATE other_fnadetails SET + Other_FNADetailsResult = '{$results}', + Other_FNADetailsUserID = {$userid} + WHERE + Other_FNADetailsID = {$v['xid']}"; + $query = $this->db_smartone->query($sql); + } + } + + $result = array("total" => 1, "records" => array(), "sql"=> ''); + $this->sys_ok($result); + exit; + } + + function saveresult_cytologi() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = $inp['doctor']; + + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + if($prm[0]['xid'] == '0'){ + $sql = "INSERT INTO other_cytologi( + Other_CytologiT_OrderDetailID, + Other_CytologiM_DoctorID, + Other_CytologiUserID, + Other_CytologiCreated + ) + VALUES( + {$prm[0]['orderdetail_id']}, + {$doctor_id}, + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } + else{ + $sql = "SELECT * FROM other_cytologi WHERE Other_CytologiT_OrderDetailID = {$prm[0]['orderdetail_id']} AND Other_CytologiIsActive = 'Y'"; + $data_header = $this->db_smartone->query($sql)->row_array(); + $header_id = $data_header['Other_CytologiID']; + $sql = "UPDATE other_cytologi SET + Other_CytologiM_DoctorID = {$doctor_id}, + Other_CytologiUserID = {$userid} + WHERE + Other_CytologiID = {$header_id}"; + $this->db_smartone->query($sql); + } + foreach($prm as $k => $v){ + if($v['xid'] == '0'){ + $results = str_replace("'", "\\'", $v['result']); + $sql = "INSERT INTO other_cytologidetails( + Other_CytologiDetailsOther_CytologiID , + Other_CytologiDetailsCode, + Other_CytologiDetailsLabel, + Other_CytologiDetailsResult, + Other_CytologiDetailsCreated, + Other_CytologiDetailsUserID + ) + VALUES( + {$header_id}, + '{$v['code']}', + '{$v['label']}', + '{$results}', + NOW(), + {$userid} + )"; + $query = $this->db_smartone->query($sql); + } + else{ + $results = str_replace("'", "\\'", $v['result']); + $sql = "UPDATE other_cytologidetails SET + Other_CytologiDetailsResult = '{$results}', + Other_CytologiDetailsUserID = {$userid} + WHERE + Other_CytologiDetailsID = {$v['xid']}"; + $query = $this->db_smartone->query($sql); + } + } + + $result = array("total" => 1, "records" => array(), "sql"=> ''); + $this->sys_ok($result); + exit; + } + + function saveresult_mikro() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = $inp['doctor']; + $backteria_id = $inp['bacteria']; + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + + if($inp['result_value'] != 'Negatif' && $inp['result_value'] != 'Positif'){ + $prm['result_value'] = $prm['result_other']; + } + else{ + $prm['result_value'] = $inp['result_value']; + } + + if($prm['xid'] == '0'){ + $sql = "INSERT INTO other_mikro( + Other_MikroM_DoctorID, + Other_MikroResult, + Other_MikroT_BacteriaID, + Other_MikroT_OrderDetailID, + Other_MikroHasilBiakan, + Other_MikroSampleTypeName, + Other_MikroUserID, + Other_MikroCreated + ) + VALUES( + {$doctor_id}, + '{$prm['result_value']}', + {$backteria_id}, + {$prm['orderdetail_id']}, + '{$prm['hasil_biakan']}', + '{$prm['sample_name']}', + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } + else{ + $sql = "SELECT * FROM other_mikro WHERE Other_MikroT_OrderDetailID = {$prm['orderdetail_id']} AND Other_MikroIsActive = 'Y'"; + $data_header = $this->db_smartone->query($sql)->row_array(); + $header_id = $data_header['Other_MikroID']; + $sql = "UPDATE other_mikro SET + Other_MikroResult = '{$prm['result_value']}', + Other_MikroM_DoctorID = {$doctor_id}, + Other_MikroT_BacteriaID = {$backteria_id}, + Other_MikroHasilBiakan = '{$prm['hasil_biakan']}', + Other_MikroSampleTypeName = '{$prm['sample_name']}', + Other_MikroUserID = {$userid} + WHERE + Other_MikroID = {$header_id}"; + //echo $sql; + $this->db_smartone->query($sql); + } + + + + $sql = "UPDATE other_mikrodetails SET Other_MikroDetailsIsActive = 'N', Other_MikroDetailsUserID = 0 WHERE Other_MikroDetailsOther_MikroID = {$header_id}"; + $this->db_smartone->query($sql); + + $results = $prm['details']; + if($inp['result_value'] == 'Positif'){ + foreach($results as $k => $v){ + if($v['xid'] == '0'){ + $sql = "INSERT INTO other_mikrodetails( + Other_MikroDetailsOther_MikroID , + Other_MikroDetailsT_AntibioticID, + Other_MikroDetailsValue, + Other_MikroDetailsNote, + Other_MikroDetailsCreated, + Other_MikroDetailsUserID + ) + VALUES( + {$header_id}, + '{$v['T_AntibioticID']}', + '{$v['value']}', + '{$v['note']}', + NOW(), + {$userid} + )"; + $query = $this->db_smartone->query($sql); + } + else{ + $sql = "UPDATE other_mikrodetails SET + Other_MikroDetailsT_AntibioticID = '{$v['T_AntibioticID']}', + Other_MikroDetailsValue = '{$v['value']}', + Other_MikroDetailsNote = '{$v['note']}', + Other_MikroDetailsIsActive = 'Y', + Other_MikroDetailsUserID = {$userid} + WHERE + Other_MikroDetailsID = {$v['xid']}"; + //echo $sql; + $query = $this->db_smartone->query($sql); + } + } + } + + + $result = array("total" => 1, "records" => array(), "sql"=> ''); + $this->sys_ok($result); + exit; + } + + + function get_doctors_preparasi_sperma() + { + $prm = $this->sys_input; + // $id = $prm["id"]; + + $sql = " SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 10 AND + M_DoctorSOIsActive = 'Y' + ORDER BY M_DoctorName ASC"; + //echo $sql; + $query = $this->db_smartone->query($sql); + $rows = $query->result_array(); + $sql = " + SELECT '0' as id, 'Belum memilih metode' as name + UNION + SELECT M_MethodeSpermaID as id, M_MethodeSpermaName as name + FROM m_methodesperma + WHERE + M_MethodeSpermaIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $methodes = $this->db_smartone->query($sql)->result_array(); + + + $this->sys_ok(["records"=>$rows,"methodes"=>$methodes]); + + } + + + function getpreparasispermaresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT other_preparasisperma.*, + Other_PreparasiSpermaID as xid, + Other_PreparasiSpermaT_OrderDetailID as orderdetail_id, + IFNULL(Other_PreparasiSpermaM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_PreparasiSpermaM_DoctorID) OR Other_PreparasiSpermaM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name, + IFNULL(M_MethodeSpermaID,0) as methode_id, + IFNULL(M_MethodeSpermaName,'') as methode_name + FROM other_preparasisperma + LEFT JOIN m_doctor ON Other_PreparasiSpermaM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + LEFT JOIN m_methodesperma ON Other_PreparasiSpermaM_MethodeSpermaID = M_MethodeSpermaID AND + M_MethodeSpermaIsActive = 'Y' + WHERE + Other_PreparasiSpermaT_OrderDetailID = {$id} AND Other_PreparasiSpermaIsActive = 'Y' + GROUP BY Other_PreparasiSpermaID"; + $query = $this->db_smartone->query($sql); + + if ($query) + { + $rows = $query->row_array(); + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 10 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $sql = " + SELECT '0' as id, 'Belum memilih metode' as name + UNION + SELECT M_MethodeSpermaID as id, M_MethodeSpermaName as name + FROM m_methodesperma + WHERE + M_MethodeSpermaIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $methodes = $this->db_smartone->query($sql)->result_array(); + $images = array(); + $sql = "SELECT Other_PreparasiSpermaImgID as xid, + Other_PreparasiSpermaImgType as type, + CONCAT('/one-media/one-image-nonlab/',Other_PreparasiSpermaImgNewName) as image_url + FROM t_orderdetail + JOIN other_preparasisperma_img ON Other_PreparasiSpermaImgT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND + Other_PreparasiSpermaImgIsActive = 'Y' + WHERE + T_OrderDetailID = {$id} AND + T_OrderDetailIsActive = 'Y' + GROUP BY Other_PreparasiSpermaImgID"; + //echo $sql; + $images = $this->db_smartone->query($sql)->result_array(); + + $rst = array('doctors'=>$doctors,'methodes'=>$methodes,'results'=>$rows,'images'=>$images); + $this->sys_ok(["records"=>$rst]); + } + else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + + function uploadimage_preparasi_sperma(){ + if (! $this->isLogin) { + $this->sys_error("Invalid Token"); + exit; + } + + $userid = $this->sys_user["M_UserID"]; + $data = []; + //print_r($_SERVER); + + $prm = $this->sys_input; + $orderid = $this->input->post('orderid'); + $type = $this->input->post('type'); + $labnumber = $this->input->post('labnumber'); + $sql = "UPDATE other_preparasisperma_img SET + Other_PreparasiSpermaImgIsActive = 'N', + Other_PreparasiSpermaImgUserID = {$userid} + WHERE + Other_PreparasiSpermaImgT_OrderHeaderID = {$orderid} AND + Other_PreparasiSpermaImgType = '{$type}'"; + //echo $sql; + $this->db_onedev->query($sql); + //$config['upload_path'] = 'assets/'; + + $path = '/home/one/project/one/one-media/one-image-nonlab/'; + //echo $path; + $config['upload_path'] = $path; + $config['allowed_types'] = 'jpg|jpeg|png|gif'; + + $config['max_size'] = '10000'; + $count = count($_FILES['files']['name']); + //echo $count; + $this->load->library('upload',$config); + + $error = []; + for($i=0;$i<$count;$i++){ + + + if(!empty($_FILES['files']['name'][$i])){ + + + + $_FILES['file']['name'] = $_FILES['files']['name'][$i]; + + $_FILES['file']['type'] = $_FILES['files']['type'][$i]; + + $_FILES['file']['tmp_name'] = $_FILES['files']['tmp_name'][$i]; + + $_FILES['file']['error'] = $_FILES['files']['error'][$i]; + + $_FILES['file']['size'] = $_FILES['files']['size'][$i]; + + + + $namex = $orderid.'-'.$labnumber.'-'.$this->generateRandomString(5); + //echo $namex; + + $config['file_name'] = $namex; + $this->upload->initialize($config); + //echo $config['file_name'] ; + + + + + + if($this->upload->do_upload('file')){ + + $uploadData = $this->upload->data(); + + $filename = $uploadData['file_name']; + //echo $filename; + + + $sql = "INSERT INTO other_preparasisperma_img ( + Other_PreparasiSpermaImgT_OrderHeaderID, + Other_PreparasiSpermaImgType, + Other_PreparasiSpermaImgOldName, + Other_PreparasiSpermaImgNewName, + Other_PreparasiSpermaImgCreated, + Other_PreparasiSpermaImgUserID + ) + VALUES( + {$orderid}, + '{$type}', + '{$_FILES['files']['name'][$i]}', + '{$filename}', + NOW(), + {$userid} + + )"; + //echo $sql; + $this->db_onedev->query($sql); + $xlast_id = $this->db_onedev->insert_id(); + $data['totalFiles'][] = array('xid' => $xlast_id ,'type'=>$type,'image_url' => '/one-media/one-image-nonlab/'.$filename); + + } + else{ + $error = array('error' => $this->upload->display_errors()); + } + + } + + + + } + + $result = array("total" =>count( $data['totalFiles']), "records" => $data['totalFiles'],'errors'=>$error); + $this->sys_ok($result); + } + + + function saveresult_preparasi_sperma() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = $inp['doctor']; + $orderdetail_id = $inp['orderdetailid']; + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + if($prm['xid'] == '0'){ + $sql = "INSERT INTO other_preparasisperma( + Other_PreparasiSpermaM_DoctorID, + Other_PreparasiSpermaT_OrderDetailID, + Other_PreparasiSpermaPreMotilitasA, + Other_PreparasiSpermaPreMotilitasB, + Other_PreparasiSpermaPreMotilitasC, + Other_PreparasiSpermaPreKonsentrasi, + Other_PreparasiSpermaPreKontaminan, + Other_PreparasiSpermaPostMotilitasA, + Other_PreparasiSpermaPostMotilitasB, + Other_PreparasiSpermaPostMotilitasC, + Other_PreparasiSpermaPostKonsentrasi, + Other_PreparasiSpermaPostKontaminan, + Other_PreparasiSpermaPreVolume, + Other_PreparasiSpermaPostVolume, + Other_PreparasiSpermaM_MethodeSpermaID, + Other_PreparasiSpermaNote, + Other_PreparasiSpermaUserID, + Other_PreparasiSpermaCreated + ) + VALUES( + {$doctor_id}, + {$orderdetail_id}, + '{$prm['Other_PreparasiSpermaPreMotilitasA']}', + '{$prm['Other_PreparasiSpermaPreMotilitasB']}', + '{$prm['Other_PreparasiSpermaPreMotilitasC']}', + '{$prm['Other_PreparasiSpermaPreKonsentrasi']}', + '{$prm['Other_PreparasiSpermaPreKontaminan']}', + '{$prm['Other_PreparasiSpermaPostMotilitasA']}', + '{$prm['Other_PreparasiSpermaPostMotilitasB']}', + '{$prm['Other_PreparasiSpermaPostMotilitasC']}', + '{$prm['Other_PreparasiSpermaPostKonsentrasi']}', + '{$prm['Other_PreparasiSpermaPostKontaminan']}', + '{$prm['Other_PreparasiSpermaPreVolume']}', + '{$prm['Other_PreparasiSpermaPostVolume']}', + '{$prm['Other_PreparasiSpermaM_MethodeSpermaID']}', + '{$prm['Other_PreparasiSpermaNote']}', + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } + else{ + $sql = "SELECT * FROM other_preparasisperma WHERE Other_PreparasiSpermaT_OrderDetailID = {$orderdetail_id} AND Other_PreparasiSpermaIsActive = 'Y'"; + $data_header = $this->db_smartone->query($sql)->row_array(); + $header_id = $data_header['Other_PreparasiSpermaID']; + $sql = "UPDATE other_preparasisperma SET + Other_PreparasiSpermaM_DoctorID = {$doctor_id}, + Other_PreparasiSpermaPreMotilitasA = '{$prm['Other_PreparasiSpermaPreMotilitasA']}', + Other_PreparasiSpermaPreMotilitasB = '{$prm['Other_PreparasiSpermaPreMotilitasB']}', + Other_PreparasiSpermaPreMotilitasC = '{$prm['Other_PreparasiSpermaPreMotilitasC']}', + Other_PreparasiSpermaPreKonsentrasi = '{$prm['Other_PreparasiSpermaPreKonsentrasi']}', + Other_PreparasiSpermaPreKontaminan = '{$prm['Other_PreparasiSpermaPreKontaminan']}', + Other_PreparasiSpermaPostMotilitasA = '{$prm['Other_PreparasiSpermaPostMotilitasA']}', + Other_PreparasiSpermaPostMotilitasB = '{$prm['Other_PreparasiSpermaPostMotilitasB']}', + Other_PreparasiSpermaPostMotilitasC = '{$prm['Other_PreparasiSpermaPostMotilitasC']}', + Other_PreparasiSpermaPostKonsentrasi = '{$prm['Other_PreparasiSpermaPostKonsentrasi']}', + Other_PreparasiSpermaPostKontaminan = '{$prm['Other_PreparasiSpermaPostKontaminan']}', + Other_PreparasiSpermaPreVolume = '{$prm['Other_PreparasiSpermaPreVolume']}', + Other_PreparasiSpermaPostVolume = '{$prm['Other_PreparasiSpermaPostVolume']}', + Other_PreparasiSpermaM_MethodeSpermaID = '{$prm['Other_PreparasiSpermaM_MethodeSpermaID']}', + Other_PreparasiSpermaNote = '{$prm['Other_PreparasiSpermaNote']}', + Other_PreparasiSpermaUserID = {$userid} + WHERE + Other_PreparasiSpermaID = {$header_id}"; + $this->db_smartone->query($sql); + } + + + $result = array("total" => 1, "records" => array(), "sql"=> ''); + $this->sys_ok($result); + exit; + } + + function getdnafragmentasiresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT other_dnafragmentasi.*, + Other_DnaFragmentasiID as xid, + Other_DnaFragmentasiT_OrderDetailID as orderdetail_id, + IFNULL(Other_DnaFragmentasiM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_DnaFragmentasiM_DoctorID) OR Other_DnaFragmentasiM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name, + IFNULL(Other_DnaFragmentasiOther_DnaFragmentasiMethodeID,0) as methode_id, + IFNULL(Other_DnaFragmentasiMethodeName,'') as methode_name, + Other_DnaFragmentasiHaloLuas as halo_luas, + Other_DnaFragmentasiHaloSedang as halo_sedang, + Other_DnaFragmentasiHaloSempit as halo_sempit, + Other_DnaFragmentasiTanpaHalo as tanpa_halo, + Other_DnaFragmentasiDFI as dfi, + Other_DnaFragmentasiKesimpulan as kesimpulan, + Other_DnaFragmentasiCatatan as catatan + FROM other_dnafragmentasi + LEFT JOIN m_doctor ON Other_DnaFragmentasiM_DoctorID = M_DoctorID + LEFT JOIN other_dnafragmentasimethode ON Other_DnaFragmentasiOther_DnaFragmentasiMethodeID = Other_DnaFragmentasiMethodeID + WHERE + Other_DnaFragmentasiT_OrderDetailID = {$id} AND Other_DnaFragmentasiIsActive = 'Y' + GROUP BY Other_DnaFragmentasiID + LIMIT 1"; + //echo $sql; + $query = $this->db_smartone->query($sql); + + if ($query) + { + $rows = $query->row_array(); + if(!$rows){ + $rows = array( + 'xid' => 0, + 'orderdetail_id' =>$id, + 'doctor_id' => 0, + 'doctor_name' => '', + 'methode_id' => 0, + 'methode_name' => '', + 'halo_luas' => '', + 'halo_sedang' => '', + 'tanpa_halo' => '', + 'dfi' => '', + 'kesimpulan' => '', + 'catatan' => '' + ); + } + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID + WHERE + M_DoctorSONat_SubGroupID = 4 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + + $sql = " + SELECT '0' as id, 'Belum memilih metode' as name + UNION + SELECT Other_DnaFragmentasiMethodeID as id, Other_DnaFragmentasiMethodeName as name + FROM other_dnafragmentasimethode + WHERE + Other_DnaFragmentasiMethodeIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $methodes = $this->db_smartone->query($sql)->result_array(); + + + $rst = array('doctors'=>$doctors,'methodes'=>$methodes,'results'=>$rows); + $this->sys_ok(["records"=>$rst]); + } + else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + function saveresult_dnafragmentasi() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = $inp['doctor']['id']; + $methode_id = $inp['methode']['id']; + $orderdetail_id = $inp['results']['orderdetail_id']; + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + if(intval($prm['xid']) == 0){ + $sql = "INSERT INTO other_dnafragmentasi( + Other_DnaFragmentasiT_OrderDetailID, + Other_DnaFragmentasiM_DoctorID, + Other_DnaFragmentasiOther_DnaFragmentasiMethodeID, + Other_DnaFragmentasiHaloLuas, + Other_DnaFragmentasiHaloSedang, + Other_DnaFragmentasiHaloSempit, + Other_DnaFragmentasiTanpaHalo, + Other_DnaFragmentasiDFI, + Other_DnaFragmentasiKesimpulan, + Other_DnaFragmentasiCatatan, + Other_DnaFragmentasiUserID, + Other_DnaFragmentasiLastUpdated + ) + VALUES( + {$orderdetail_id}, + {$doctor_id}, + {$methode_id}, + '{$prm['halo_luas']}', + '{$prm['halo_sedang']}', + '{$prm['halo_sempit']}', + '{$prm['tanpa_halo']}', + '{$prm['dfi']}', + '{$prm['kesimpulan']}', + '{$prm['catatan']}', + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } + else{ + $sql = "UPDATE other_dnafragmentasi SET + Other_DnaFragmentasiT_OrderDetailID = {$orderdetail_id}, + Other_DnaFragmentasiM_DoctorID = {$doctor_id}, + Other_DnaFragmentasiOther_DnaFragmentasiMethodeID = '{$methode_id}', + Other_DnaFragmentasiHaloLuas = '{$prm['halo_luas']}', + Other_DnaFragmentasiHaloSedang = '{$prm['halo_sedang']}', + Other_DnaFragmentasiHaloSempit = '{$prm['halo_sempit']}', + Other_DnaFragmentasiTanpaHalo = '{$prm['tanpa_halo']}', + Other_DnaFragmentasiDFI = '{$prm['dfi']}', + Other_DnaFragmentasiKesimpulan = '{$prm['kesimpulan']}', + Other_DnaFragmentasiCatatan = '{$prm['catatan']}', + Other_DnaFragmentasiLastUpdated = NOW(), + Other_DnaFragmentasiUserID = {$userid} + WHERE + Other_DnaFragmentasiID = {$prm['xid']}"; + //echo $sql; + $this->db_smartone->query($sql); + } + + + $result = array("total" => 1, "records" => array(), "sql"=> ''); + $this->sys_ok($result); + exit; + } + + +} + diff --git a/application/controllers/mockup/process/resultvalidation-v22/Re_px.php b/application/controllers/mockup/process/resultvalidation-v22/Re_px.php index 34a3086b..2d75999a 100644 --- a/application/controllers/mockup/process/resultvalidation-v22/Re_px.php +++ b/application/controllers/mockup/process/resultvalidation-v22/Re_px.php @@ -1,2549 +1,2546 @@ -db_smartone = $this->load->database("onedev", true); - $this->load->helper(array('form', 'url')); - } - function getMethodeID($natTestID) { - $sql = "select M_MethodePriorityNat_MethodeID MethodeID, Nat_MethodeName - from - m_methode_priority - join nat_methode on Nat_MethodeID = M_MethodePriorityNat_MethodeID - and Nat_MethodeIsActive = 'Y' - join m_instrumentmethode on M_InstrumentMethodeNat_MethodeID = Nat_MethodeID and M_InstrumentMethodeIsActive = 'Y' - join nat_instrument on M_InstrumentMethodeNat_InstrumentID = Nat_InstrumentID - and Nat_InstrumentIsActive ='Y' - where M_MethodePriorityIsActive = 'Y' - and M_MethodePriorityNat_TestID = $natTestID - and M_MethodePriorityM_DayOfWeekID = dayofweek(now()) - order by M_MethodePriorityNumber desc - limit 0,1 "; - $qry = $this->db->query($sql); - if ($qry) { - $rows = $qry->result_array(); - if (count($rows) > 0 ) return array($rows[0]["MethodeID"],$rows[0]["Nat_MethodeName"]); - } - //2nd - $sql= "select - M_InstrumentMethodeNat_MethodeID MethodeID, Nat_MethodeName - from m_instrumentmethode - join nat_methode on M_InstrumentMethodeNat_MethodeID = Nat_MethodeID - and Nat_MethodeIsActive = 'Y' - join nat_instrument on M_InstrumentMethodeNat_InstrumentID = Nat_InstrumentID - and Nat_InstrumentIsActive ='Y' - where M_InstrumentMethodeNat_TestID = $natTestID - and M_InstrumentMethodeIsActive = 'Y' - order by M_InstrumentMethodePriority desc - limit 0,1"; - $qry = $this->db->query($sql); - if ($qry) { - $rows = $qry->result_array(); - if (count($rows) > 0 ) return array($rows[0]["MethodeID"],$rows[0]["Nat_MethodeName"]); - } - // - $sql = "select Nat_NormalValueNat_MethodeID MethodeID, Nat_MethodeName - from - nat_normalvalue - join nat_methode on Nat_NormalValueNat_MethodeID = Nat_MethodeID - and Nat_MethodeIsActive = 'Y' - where Nat_NormalValueNat_TestID = $natTestID - and Nat_NormalValueIsActive = 'Y' - order by Nat_NormalValueID - limit 0,1"; - $qry = $this->db->query($sql); - if ($qry) { - $rows = $qry->result_array(); - if (count($rows) > 0 ) return array($rows[0]["MethodeID"],$rows[0]["Nat_MethodeName"]); - } - return array(0,""); - } - function get_normal_value($methodeID, $natTestID, $sexID, $ageInDay ) { - $sql = "select fn_sampling_get_normal($methodeID, $natTestID, $sexID, $ageInDay) as normalValueID"; - $qry = $this->db->query($sql); - if ($qry) { - $rows = $qry->result_array(); - if (count($rows) > 0 ) return $rows[0]["normalValueID"]; - } - return 0; - } - function fn_fix_normal($order_id) { - $sql = "select - T_OrderDetailID, M_PatientM_SexID, fn_global_age_count_day(M_PatientDOB, date(T_OrderHeaderDate)) Dob , - T_TestNat_TestID - from t_orderheader - join m_patient on T_OrderHeaderID = $order_id and T_OrderHeaderM_PatientID = M_PatientID - join t_orderdetail on T_OrderDetailT_OrderHeaderID = T_OrderHeaderID - and T_OrderDetailIsACtive = 'Y' - and ( T_OrderDetailNat_NormalValueID is null or T_OrderDetailNat_NormalValueID = 0 ) - join t_test on T_OrderDetailT_TestID = T_TestID and T_TestIsResult = 'Y' "; - $qry = $this->db->query($sql); - if(! $qry) { - return; - } - $rows = $qry->result_array(); - if(count($rows) == 0 ) return; - $sql_u = "update t_orderdetail - join nat_normalvalue on T_OrderDetailID = ? and Nat_NormalValueID = ? - set - T_OrderDetailNat_NormalValueID = Nat_NormalValueID, - T_OrderDetailNormalValueNote = Nat_NormalValueNote, - T_OrderDetailNormalValueDescription = Nat_NormalValueDescription, - T_OrderDetailMinValue = Nat_NormalValueMinValue, - T_OrderDetailMaxValue = Nat_NormalValueMaxValue, - T_OrderDetailMinValueInclusive = Nat_NormalValueMinValueInclusive, - T_OrderDetailMaxValueInclusive = Nat_NormalValueMaxValueInclusive, - T_OrderDetailNat_MethodeID = ?, - T_OrderdetailNat_MethodeName =?"; - - foreach($rows as $r) { - $T_OrderDetailID = $r["T_OrderDetailID"]; - $sexID = $r["M_PatientM_SexID"]; - $ageInDay = $r["Dob"]; - $natTestID = $r["T_TestNat_TestID"]; - list($methodeID,$methodeName) = $this->getMethodeID($natTestID); - if ($methodeID == 0 ) continue; - $normalValueID = $this->get_normal_value($methodeID, $natTestID, $sexID, $ageInDay); - if ($normalValueID == 0) return; - $this->db->query($sql_u, array($T_OrderDetailID, $normalValueID, $methodeID, $methodeName)); - } - } - function update_order_sample($targetID, $sourceID) { - $sql = "update t_ordersample target - join t_ordersample source on - target.T_OrderSampleID = ? - and target.T_OrderSampleWorklistReceive = 'N' - and source.T_OrderSampleID = ? - set - target.T_OrderSampleSampling = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSampling, source.T_OrderSampleSampling), - target.T_OrderSampleSamplingDate = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingDate, source.T_OrderSampleSamplingDate), - target.T_OrderSampleSamplingTime = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingTime, source.T_OrderSampleSamplingTime), - target.T_OrderSampleSamplingUserID = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingUserID, source.T_OrderSampleSamplingUserID), - - target.T_OrderSampleReceive = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceive, source.T_OrderSampleReceive), - target.T_OrderSampleReceiveDate = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveDate, source.T_OrderSampleReceiveDate), - target.T_OrderSampleReceiveTime = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveTime, source.T_OrderSampleReceiveTime), - target.T_OrderSampleReceiveUserID = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveUserID, source.T_OrderSampleReceiveUserID), - - target.T_OrderSampleVerification = if(target.T_OrderSampleVerification='Y',target.T_OrderSampleVerification, source.T_OrderSampleVerification), - target.T_OrderSampleVerificationDate =if(target.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationDate, source.T_OrderSampleVerificationDate), - target.T_OrderSampleVerificationTime =if(source.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationTime, source.T_OrderSampleVerificationTime), - target.T_OrderSampleVerificationUserID =if(source.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationUserID, source.T_OrderSampleVerificationUserID), - - target.T_OrderSampleProcessing = if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessing, source.T_OrderSampleProcessing), - target.T_OrderSampleProcessingDate= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingDate, source.T_OrderSampleProcessingDate), - target.T_OrderSampleProcessingTime= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingTime, source.T_OrderSampleProcessingTime), - target.T_OrderSampleProcessingUserID= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingUserID, source.T_OrderSampleProcessingUserID), - - target.T_OrderSampleReceiveHandling =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandling, source.T_OrderSampleReceiveHandling ), - target.T_OrderSampleReceiveHandlingDate =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingDate, source.T_OrderSampleReceiveHandlingDate), - target.T_OrderSampleReceiveHandlingTime =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingTime, source.T_OrderSampleReceiveHandlingTime), - target.T_OrderSampleReceiveHandlingUserID =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingUserID, source.T_OrderSampleReceiveHandlingUserID), - - target.T_OrderSampleHandling = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandling, source.T_OrderSampleHandling), - target.T_OrderSampleHandlingDate = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingDate, source.T_OrderSampleHandlingDate), - target.T_OrderSampleHandlingTime = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingTime, source.T_OrderSampleHandlingTime), - target.T_OrderSampleHandlingUserID = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingUserID, source.T_OrderSampleHandlingUserID), - - target.T_OrderSampleWorklistReceive = source.T_OrderSampleWorklistReceive, - target.T_OrderSampleWorklistReceiveDatetime = source.T_OrderSampleWorklistReceiveDateTime, - target.T_OrderSampleWorklistReceiveUserID = source.T_OrderSampleWorklistReceiveUserID - "; - $qry = $this->db->query($sql,array($targetID,$sourceID)); - if(! $qry ) { - echo json_encode(array( "status" => "ERR" , "message" => print_r($this->db->error(),true))); - exit; - } - } - function fix_sample_serum($headerID) { - //cari t_ordersample yg belum worklist receive dengan code 017% - $sql = "select T_OrderSampleID - from t_ordersample - join t_sampletype on - T_OrderSampleT_OrderHeaderID = ? - and T_OrderSampleWorklistReceive = 'N' - and T_OrderSampleIsActive = 'Y' - and T_OrderSampleT_SampleTypeID = T_SampletypeID - and T_SampleTypeCode like '017%' - "; - $qry = $this->db->query($sql, array($headerID)); - if(!$qry) { - echo json_encode(array( "status" => "ERR" , "message" => print_r($this->db->error(),true))); - exit; - } - $rows = $qry->result_array(); - if (count($rows) == 0 ) return; - //cari T_OrderSample yang sudah di receive yg terakhir - $sql = "select T_OrderSampleID - from t_ordersample - join t_sampletype on - T_OrderSampleT_OrderHeaderID = ? - and T_OrderSampleWorklistReceive = 'Y' - and T_OrderSampleIsActive = 'Y' - and T_OrderSampleT_SampleTypeID = T_SampletypeID - and T_SampleTypeCode like '017%' - order by T_OrderSampleWorklistReceiveDatetime desc - limit 0,1 - "; - $qry = $this->db->query($sql, array($headerID)); - if(!$qry) { - echo json_encode(array( "status" => "ERR" , "message" => print_r($this->db->error(),true))); - exit; - } - $rcv_rows = $qry->result_array(); - if (count($rcv_rows) == 0 ) return; - - //print_r($rows); - //print_r($rcv_rows); - $rcv_T_OrderSampleID = $rcv_rows[0]["T_OrderSampleID"]; - //ada yg belum di receive - foreach($rows as $r) { - $T_OrderSampleID = $r["T_OrderSampleID"]; - $this->update_order_sample($T_OrderSampleID,$rcv_T_OrderSampleID); - } - } - public function search() - { - $prm = $this->sys_input; - $max_rst = 99; - - $id = $prm["order_id"]; - if ($id > 0 ) { - $this->fix_sample_serum($id); - $this->fn_fix_normal($id); - } - $lang = $this->lang_default_code; - $lang_id = isset($prm['lang_id']) ? $prm['lang_id'] : '0'; - - if ($lang_id != 0) - { - $l = $this->db_smartone->where("Nat_LangID", $lang_id)->get("nat_lang")->row(); - $lang = $l->Nat_LangCode; - } - - //tambahan fajri - $sql = " UPDATE t_orderdetail - JOIN t_test ON T_OrderDetailT_TestID = T_TestID - SET T_OrderDetailT_TestIsResult = T_TestIsResult - WHERE - T_OrderDetailT_OrderHeaderID = {$id} AND - T_OrderDetailT_TestIsResult = '' AND - T_OrderDetailIsActive = 'Y'"; - $this->db_smartone->query($sql); - - $tot_count = 0; - $lq = ""; - $group_id = 0; - if (isset($prm['group_id'])) - $group_id = $prm['group_id']; - - if ($group_id != 0) - { - $sql = "select distinct T_WorklistDetailNat_TestID Nat_TestID - from t_worklistdetailv2 - where T_WorklistDetailT_WorklistID = {$group_id}"; - $qry = $this->db_smartone->query($sql); - $rows = $qry->result_array(); - $nat_test_ids = "0"; - foreach($rows as $r) { - $nat_test_ids .= ", " . $r["Nat_TestID"]; - } - $q_group = " ( $nat_test_ids ) "; - - $sql = " - SELECT a1.*, cOUNT(a2.T_OrderDetailID) level - FROM ( - SELECT IFNULL(y.T_OrderDetailT_TestID, x.T_OrderDetailT_TestID) t_testid, - IFNULL(y.T_OrderDetailT_TestName, y.T_OrderDetailT_TestName) t_testname, - y.T_OrderDetailResult result, y.T_OrderDetailResult result_old, y.T_OrderDetailNote note, y.T_OrderDetailNote note_old, - y.T_OrderDetailID id, - y.T_OrderDetailT_TestIsResult is_result, a.T_TestIsQuantitative is_quantitative, - y.T_OrderDetailResultFlag result_flag, - y.T_OrderDetailNat_NormalValueID normal_id, - y.T_OrderDetailNormalValueNote normal_note, y.T_OrderDetailNat_UnitName unit_name, - y.T_OrderdetailNat_MethodeID methode_id, y.T_OrderdetailNat_MethodeName methode_name, - a.T_TestNat_TestID nattest_id, a.T_TestID tx_id, count(T_ResultInstrumentID) as result_instrument_n, - y.T_OrderDetailVerification, T_OrderSampleReceive sample_receive, - T_OrderSampleProcessing sample_processing, T_OrderSampleWorklistReceive sample_worklist_receive, - IF(T_OrderDetailAddOnPreAnalytic = 'Y', T_OrderDetailAddOnPreAnalytic, PreAnalyticIsOk) pre_analytic, - T_OrderDetailAddOnPreAnalytic, - T_OrderHeaderID order_id, y.T_OrderDetailT_TestSasCode test_sas_code, - tx.T_TestSasCode, - T_OrderDetailAddOnResample `resample`, T_OrderDetailAddOnResampleStatus resample_status, - T_OrderDetailAddOnRef ref, y.T_OrderDetailVerification verification, y.T_OrderDetailValidation validation, - T_OrderPromiseDateTime, Group_ResultName as ResultGroupName - FROM t_orderdetail x - left join t_orderpromise on x.T_OrderDetailT_OrderPromiseID = T_OrderPromiseID - JOIN t_test tx ON x.T_OrderDetailT_TestID = T_TestID - JOIN t_test tcheck on tcheck.T_TestNat_TestID in {$q_group} - and ( tx.T_TestID = tcheck.T_TestID or tx.T_TestSasCode like concat(tcheck.T_TestSasCode,'%')) - LEFT JOIN group_resultdetail ON Group_ResultDetailT_TestID = x.T_OrderDetailT_TestID AND Group_ResultDetailIsActive = 'Y' - LEFT JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND Group_ResultFlagNonLab = 'N' - LEFT JOIN t_orderdetail y ON x.T_OrderDetailT_TestSasCode LIKE CONCAT(y.T_OrderDetailT_TestSasCode, '%') - AND x.T_OrderDetailT_OrderHeaderID = y.T_OrderDetailT_OrderHeaderID - AND y.T_OrderDetailIsActive = 'Y' - LEFT JOIN t_orderdetailaddon ON x.T_OrderDetailID = T_OrderDetailAddOnT_OrderDetailID - JOIN t_orderheader ON y.T_OrderDetailT_OrderHeaderID = T_OrderHeaderID - LEFT JOIN t_test a ON y.T_OrderDetailT_TestID = a.T_TestID - AND a.T_TestIsNonLab = '' - LEFT JOIN (SELECT T_OrderSampleT_SampleTypeID, T_OrderSampleReceive, T_OrderSampleProcessing, T_OrderSampleWorklistReceive - FROM t_ordersample WHERE T_OrderSampleT_OrderHeaderID = {$id} - AND T_OrderSampleIsactive = 'Y' - GROUP BY T_OrderSampleT_SampleTypeID) os ON a.T_TestT_SampleTypeID = os.T_OrderSampleT_SampleTypeID - or os.T_OrderSampleT_SampleTypeID = fn_sampletype_from_local(a.T_TestNat_TestID) - - LEFT JOIN t_resultinstrument ON T_ResultInstrumentT_OrderDetailID = x.T_OrderDetailID - LEFT JOIN pre_analytic ON PreAnalyticNat_TestID = a.T_TestNat_TestID AND PreAnalyticDate = date(now()) and PreAnalyticIsActive = 'Y' - WHERE x.T_OrderDetailT_OrderHeaderID = {$id} - AND x.T_OrderDetailIsActive = 'Y' - GROUP BY y.T_OrderDetailT_TestID - ORDER BY y.T_OrderDetailT_TestSasCode ASC - ) a1 - - LEFT JOIN t_orderdetail a2 ON a2.T_OrderDetailT_OrderHeaderID = a1.order_id - AND a2.T_OrderDetailIsActive = 'Y' - AND a1.test_sas_code LIKE CONCAT(a2.T_OrderDetailT_testSasCode, '%') - GROUP BY a1.t_testid - order by a1.test_sas_code -"; - $query = $this->db_smartone->query($sql); - $lq = $this->db_smartone->last_query(); - } - else - { - $sql = " - SELECT a1.*, cOUNT(a2.T_OrderDetailID) level - FROM ( - SELECT IFNULL(y.T_OrderDetailT_TestID, x.T_OrderDetailT_TestID) t_testid, - IFNULL(y.T_OrderDetailT_TestName, y.T_OrderDetailT_TestName) t_testname, - y.T_OrderDetailResult result, y.T_OrderDetailResult result_old, y.T_OrderDetailNote note, y.T_OrderDetailNote note_old, - y.T_OrderDetailID id, - y.T_OrderDetailT_TestIsResult is_result, a.T_TestIsQuantitative is_quantitative, - y.T_OrderDetailResultFlag result_flag, - y.T_OrderDetailNat_NormalValueID normal_id, - y.T_OrderDetailNormalValueNote normal_note, y.T_OrderDetailNat_UnitName unit_name, - y.T_OrderdetailNat_MethodeID methode_id, y.T_OrderdetailNat_MethodeName methode_name, - a.T_TestNat_TestID nattest_id, a.T_TestID tx_id, count(T_ResultInstrumentID) as result_instrument_n, - y.T_OrderDetailVerification, T_OrderSampleReceive sample_receive, - T_OrderSampleProcessing sample_processing, T_OrderSampleWorklistReceive sample_worklist_receive, - IF(T_OrderDetailAddOnPreAnalytic = 'Y', T_OrderDetailAddOnPreAnalytic, PreAnalyticIsOk) pre_analytic, - T_OrderDetailAddOnPreAnalytic, - T_OrderHeaderID order_id, y.T_OrderDetailT_TestSasCode test_sas_code, - tx.T_TestSasCode, - T_OrderDetailAddOnResample `resample`, T_OrderDetailAddOnResampleStatus resample_status, - T_OrderDetailAddOnRef ref, y.T_OrderDetailVerification verification, y.T_OrderDetailValidation validation, - T_OrderPromiseDateTime , Group_ResultName as ResultGroupName - FROM t_orderdetail x - left join t_orderpromise on x.T_OrderDetailT_OrderPromiseID = T_OrderPromiseID - JOIN t_test tx ON x.T_OrderDetailT_TestID = T_TestID - LEFT JOIN group_resultdetail ON Group_ResultDetailT_TestID = x.T_OrderDetailT_TestID AND Group_ResultDetailIsActive = 'Y' - LEFT JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND Group_ResultFlagNonLab = 'N' - LEFT JOIN t_orderdetail y ON x.T_OrderDetailT_TestSasCode LIKE CONCAT(y.T_OrderDetailT_TestSasCode, '%') - AND x.T_OrderDetailT_OrderHeaderID = y.T_OrderDetailT_OrderHeaderID - AND y.T_OrderDetailIsActive = 'Y' - - LEFT JOIN t_orderdetailaddon ON x.T_OrderDetailID = T_OrderDetailAddOnT_OrderDetailID - - JOIN t_orderheader ON y.T_OrderDetailT_OrderHeaderID = T_OrderHeaderID - LEFT JOIN t_test a ON y.T_OrderDetailT_TestID = a.T_TestID - AND a.T_TestIsNonLab = '' - LEFT JOIN (SELECT T_OrderSampleT_SampleTypeID, T_OrderSampleReceive, T_OrderSampleProcessing, T_OrderSampleWorklistReceive - FROM t_ordersample WHERE T_OrderSampleT_OrderHeaderID = {$id} - AND T_OrderSampleIsactive = 'Y' - GROUP BY T_OrderSampleT_SampleTypeID) os ON a.T_TestT_SampleTypeID = os.T_OrderSampleT_SampleTypeID - or os.T_OrderSampleT_SampleTypeID = fn_sampletype_from_local(a.T_TestNat_TestID) - - LEFT JOIN t_resultinstrument ON T_ResultInstrumentT_OrderDetailID = x.T_OrderDetailID - LEFT JOIN pre_analytic ON PreAnalyticNat_TestID = a.T_TestNat_TestID AND PreAnalyticDate = date(now()) and PreAnalyticIsActive = 'Y' - WHERE x.T_OrderDetailT_OrderHeaderID = {$id} - AND x.T_OrderDetailIsActive = 'Y' - GROUP BY y.T_OrderDetailT_TestID - ORDER BY y.T_OrderDetailT_TestSasCode ASC - ) a1 - - LEFT JOIN t_orderdetail a2 ON a2.T_OrderDetailT_OrderHeaderID = a1.order_id - AND a2.T_OrderDetailIsActive = 'Y' - AND a1.test_sas_code LIKE CONCAT(a2.T_OrderDetailT_testSasCode, '%') - GROUP BY a1.t_testid - order by a1.test_sas_code -"; -//echo $sql; - $query = $this->db_smartone->query($sql); - $lq = $this->db_smartone->last_query(); - } - // file_put_contents("/xtmp/re-query.sql",$lq); - - if ($query) { - $rst = []; - $rows = $query->result_array(); - - foreach($rows as $k => $v) - { - - if ($v['is_result'] == "Y" && $v['is_quantitative'] == "N") - { - $v['template'] = []; - $x = $this->db_smartone->query("CALL sp_master_resulttemplate_get('{$v['t_testid']}')"); - $this->clean_mysqli_connection($this->db_smartone->conn_id); - if ($x) - $v['template'] = $x->result_array(); - } - - // IF Rujukan, by pas Pre Analytik - if ($v['ref'] == 'Y') - $v['pre_analytic'] = 'Y'; - if ($v["id"] == "885455" ) - { - //sipe workaround - //$v["sample_receive"] = "Y"; - $v["sample_worklist_receive"] = "Y"; - } - $rst[] = $v; - } - - $result = array("total" => $tot_count, "records" => $rst, "total_display" => sizeof($rows), "q" => $lq); - $this->sys_ok($result); - } - else { - $this->sys_error_db("RE Px rows", $this->db_smartone); - exit; - } - } - - public function save() - { - $prm = $this->sys_input; - $data = json_decode($prm["data"]); - $lang = $this->lang_default_code; - $lang_id = isset($prm['lang_id']) ? $prm['lang_id'] : '0'; - - if ($lang_id != 0) - { - $l = $this->db_smartone->where("Nat_LangID", $lang_id)->get("nat_lang")->row(); - $lang = $l->Nat_LangCode; - } - - $sql_norm = "select T_OrderDetailMinValue, T_OrderDetailMaxValue, - T_OrderDetailMinValueInclusive, T_OrderDetailMaxValueInclusive, - Nat_TestFlagLow, Nat_TestFlagHigh - from t_orderdetail - join t_test on T_OrderDetailT_TestID = T_TestID - join nat_test on T_TestNat_TestID = Nat_TestID and T_TestIsActive = 'Y' - where T_OrderDetailID = ? "; - - $ids = []; - foreach ($data as $k => $v) - { - if ( $v->resultInstrumentID > 0 ) { - $sql_i = "select T_ResultInstrumentNat_NormalValueID normalValueID - from t_resultinstrument - where T_ResultInstrumentID = ?"; - $qry_i = $this->db_smartone->query($sql_i, array($v->resultInstrumentID)); - if ($qry_i) { - $rows_i = $qry_i->result_array(); - - if (count($rows_i) > 0 ) { - $sql_iu = "update t_orderdetail, nat_normalvalue , nat_methode - set T_OrderDetailMinValue = Nat_NormalValueMinValue, - T_OrderDetailMinValueInclusive = Nat_NormalValueMinValueInclusive, - T_OrderDetailMaxValue = Nat_NormalValueMaxValue , - T_OrderDetailMaxValueInclusive = Nat_NormalValueMaxValueInclusive, - T_OrderDetailNormalValueNote = Nat_NormalValueNote, - T_OrderDetailNormalValueDescription = Nat_NormalValueDescription, - T_OrderDetailNat_NormalValueID = Nat_NormalValueID, - T_OrderDetailNat_MethodeID = Nat_NormalValueNat_MethodeID, - T_OrderDetailNat_MethodeName = Nat_MethodeName - where T_OrderDetailID = ? and Nat_NormalValueID = ? - and Nat_NormalValueNat_MethodeID = Nat_MethodeID - "; - $this->db_smartone->query($sql_iu, array($v->id, $rows_i[0]["normalValueID"])); - //file_put_contents("/xtmp/update-nilai-normal", $this->db_smartone->last_query() . "\n", FILE_APPEND); - } - } - } - $y = $this->db_smartone->query("SELECT fn_process_sample_handling_perfect('{$v->order_id}', '{$v->test_id}') c") - ->row(); - $req_status = $y->c; - $qry_norm = $this->db_smartone->query($sql_norm,$v->id); - $result_flag = ""; - if ($qry_norm) { - $rows_norm = $qry_norm->result_array(); - if (count($rows_norm) > 0 ) { - $r = $rows_norm[0]; - if (is_numeric($v->result)) { - - if ( $r["T_OrderDetailMinValueInclusive"] == "Y" && $v->result < $r["T_OrderDetailMinValue"] ) { - $result_flag = $r["Nat_TestFlagLow"]; - } - if ( $r["T_OrderDetailMinValueInclusive"] == "N" && $v->result <= $r["T_OrderDetailMinValue"] ) { - $result_flag = $r["Nat_TestFlagLow"]; - } - if ( $r["T_OrderDetailMaxValueInclusive"] == "Y" && $v->result > $r["T_OrderDetailMaxValue"] ) { - $result_flag = $r["Nat_TestFlagHigh"]; - } - if ( $r["T_OrderDetailMaxValueInclusive"] == "N" && $v->result >= $r["T_OrderDetailMaxValue"] ) { - $result_flag = $r["Nat_TestFlagHigh"]; - } - } - } - } - if ($lang == $this->lang_default_code) - { - $this->db_smartone->set('T_OrderDetailResult', $v->result) - ->set('T_OrderDetailResultFlag', $result_flag) - ->set('T_OrderDetailNote', $v->note) - ->set('T_OrderDetailReqStatus', $req_status) - ->where('T_OrderDetailID', $v->id) - ->update('t_orderdetail'); - } - else - { - $this->db_smartone->set('T_OrderDetailLangResult', $v->result) - ->set('T_OrderDetailLangNote', $v->note) - ->where('T_OrderDetailLangID', $v->id) - ->update('t_orderdetaillang'); - } - - $ids[] = $v->id; - } - - // LOG Process - $order = $this->db_smartone->select('T_OrderDetailT_OrderHeaderID id, T_OrderHeaderLabNumber lab_number', false) - ->join('t_orderheader', 'T_OrderHeaderID = T_OrderDetailT_OrderHeaderID') - ->where('T_OrderDetailID', $data[0]->id) - ->get('t_orderdetail') - ->row(); - - $dblog = $this->load->database("onelog", true); - $dblog->set('Log_ProcessCode', 'PROCESS.Result.Entry') - ->set('Log_ProcessOrderID', $order->id) - ->set('Log_ProcessOrderNumber', $order->lab_number) - ->set('Log_ProcessJson', json_encode($data)) - ->set('Log_ProcessUserID', $this->sys_user['M_UserID']) - ->insert('log_process'); - // END OF Log Process - //auto calculation - $this->load->library("Resultcalc"); - $rows = $this->resultcalc->auto($order->id); - - try { - foreach($ids as $id ) { - $this->db_smartone->query("call sp_set_normal_value_flag($id)"); - $this->clean_mysqli_connection($this->db_smartone->conn_id); - } - } catch(Exception $e) { - } - - $this->sys_ok($ids); - } - - public function save_template() - { - $prm = $this->sys_input; - - $n = $this->db_smartone->select("COUNT(T_ResultTemplateID) n") - ->where("T_ResultTemplateT_TestID", $prm['test_id']) - ->where("T_ResultTemplateIsActive", "Y") - ->where("T_ResultTemplateValue", $prm['value']) - ->get('t_resulttemplate') - ->row(); - if ($n->n > 0) - { - $this->sys_error_db("Insert Result Template", $this->db_smartone); - return; - } - - $r = $this->db_smartone->set("T_ResultTemplateT_TestID", $prm['test_id']) - ->set("T_ResultTemplateValue", $prm['value']) - ->insert('t_resulttemplate'); - if ($r) - { - $template = []; - $x = $this->db_smartone->query("CALL sp_master_resulttemplate_get('{$prm['test_id']}')"); - $this->clean_mysqli_connection($this->db_smartone->conn_id); - if ($x) - $template = $x->result_array(); - - $this->sys_ok($template); - } - } - - public function export() - { - $prm = $this->sys_input; - - $sql = "CALL sp_process_result_lang(?, ?, ?, ?)"; - $query = $this->db_smartone->query($sql, [$prm['order_id'], $prm['lang_id'], $prm['is_si'], $this->sys_user['M_UserID']]); - if ($query) - { - $r = $query->row(); - if ($r->status == "OK") - { - $this->sys_ok($r->data); - return; - } - - $this->sys_error_db("Message : " . $r->message, $this->db_smartone); - } - else - { - $this->sys_error_db("Lang Result", $this->db_smartone); - return; - } - } - - public function search_group() - { - $prm = $this->sys_input; - $max_rst = 100; - - // QUERY TOTAL - $sql = "select count(*) total - from t_worklist - where T_WorklistIsActive = 'Y' - order by T_WorklistName ASC"; - $query = $this->db_smartone->query($sql); - - if ($query) { - $tot_count = $query->result_array()[0]["total"]; - } - else { - $this->sys_error_db("worklist count", $this->db_smartone); - exit; - } - - $sql = "select T_WorklistID group_id, T_WorklistName group_name - from t_worklist - where T_WorklistIsActive = 'Y' - order by T_WorklistName ASC - limit 0, {$max_rst}"; - $query = $this->db_smartone->query($sql); - - if ($query) { - $rows = $query->result_array(); - foreach ($rows as $k => $v) - $rows[$k]['data'] = json_decode($v['data']); - $result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows), "q" => $this->db_smartone->last_query()); - $this->sys_ok($result); - } - else { - $this->sys_error_db("worklist rows", $this->db_smartone); - exit; - } - } - - public function search_rerun() - { - $prm = $this->sys_input; - $id = $prm["detail_id"]; - - $sql = "CALL sp_process_result_rerun(?)"; - $query = $this->db_smartone->query($sql, [$id]); - - if ($query) - { - $rows = $query->result_array(); - $this->sys_ok(["records"=>$rows]); - } - else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - - - function getdoctorsfna() - { - $prm = $this->sys_input; - // $id = $prm["id"]; - - $sql = " SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY M_DoctorName ASC"; - //echo $sql; - $query = $this->db_smartone->query($sql); - - if ($query) - { - $rows = $query->result_array(); - $this->sys_ok(["records"=>$rows]); - } - else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - function getfnaresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT Other_FNADetailsID as xid, - Other_FNAT_OrderDetailID as orderdetail_id, - Other_FNADetailsCode as code, - Other_FNADetailsLabel as label, - Other_FNADetailsResult as result, - IFNULL(Other_FNAM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_FNAM_DoctorID) OR Other_FNAM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_fna - JOIN other_fnadetails ON Other_FNADetailsOther_FNAID = Other_FNAID AND Other_FNADetailsIsActive = 'Y' - LEFT JOIN m_doctor ON Other_FNAM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_FNAT_OrderDetailID = {$id} AND Other_FNAIsActive = 'Y' - GROUP BY Other_FNADetailsID - ORDER BY Other_FNADetailsCode ASC"; - $query = $this->db_smartone->query($sql); - - if ($query) - { - $rows = $query->result_array(); - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $images = array(); - $sql = "SELECT So_ImageUploadID as xid, - CONCAT('/one-media/one-image-nonlab/',So_ImageUploadNewName) as image_url - FROM t_orderdetail - JOIN so_imageupload ON So_ImageUploadT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND - So_ImageUploadIsActive = 'Y' - WHERE - T_OrderDetailID = {$id} AND - T_OrderDetailIsActive = 'Y' - GROUP BY So_ImageUploadID"; - $images = $this->db_smartone->query($sql)->result_array(); - - $rst = array('doctors'=>$doctors,'results'=>$rows,'images'=>$images); - $this->sys_ok(["records"=>$rst]); - } - else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - - function uploadimage(){ - if (! $this->isLogin) { - $this->sys_error("Invalid Token"); - exit; - } - - $userid = $this->sys_user["M_UserID"]; - $data = []; - //print_r($_SERVER); - - $prm = $this->sys_input; - $orderid = $this->input->post('orderid'); - $labnumber = $this->input->post('labnumber'); - $sql = "UPDATE so_imageupload SET - So_ImageUploadIsActive = 'N', - So_ImageUploadUserID = {$userid} - WHERE - So_ImageUploadT_OrderHeaderID = {$orderid}"; - //echo $sql; - $this->db_onedev->query($sql); - //$config['upload_path'] = 'assets/'; - - $path = '/home/one/project/one/one-media/one-image-nonlab/'; - //echo $path; - $config['upload_path'] = $path; - $config['allowed_types'] = 'jpg|jpeg|png|gif'; - - $config['max_size'] = '10000'; - $count = count($_FILES['files']['name']); - //echo $count; - $this->load->library('upload',$config); - - $error = []; - for($i=0;$i<$count;$i++){ - - - if(!empty($_FILES['files']['name'][$i])){ - - - - $_FILES['file']['name'] = $_FILES['files']['name'][$i]; - - $_FILES['file']['type'] = $_FILES['files']['type'][$i]; - - $_FILES['file']['tmp_name'] = $_FILES['files']['tmp_name'][$i]; - - $_FILES['file']['error'] = $_FILES['files']['error'][$i]; - - $_FILES['file']['size'] = $_FILES['files']['size'][$i]; - - - - $namex = $orderid.'-'.$labnumber.'-'.$this->generateRandomString(5); - //echo $namex; - - $config['file_name'] = $namex; - $this->upload->initialize($config); - //echo $config['file_name'] ; - - - - - - if($this->upload->do_upload('file')){ - - $uploadData = $this->upload->data(); - - $filename = $uploadData['file_name']; - //echo $filename; - - - $sql = "INSERT INTO so_imageupload ( - So_ImageUploadT_OrderHeaderID, - So_ImageUploadT_OrderHeaderLabNumber, - So_ImageUploadT_SampleTypeID, - So_ImageUploadOldName, - So_ImageUploadNewName, - So_ImageUploadCreated, - So_ImageUploadUserID - ) - VALUES( - {$orderid}, - '{$labnumber}', - '150', - '{$_FILES['files']['name'][$i]}', - '{$filename}', - NOW(), - {$userid} - - )"; - //echo $sql; - $this->db_onedev->query($sql); - $xlast_id = $this->db_onedev->insert_id(); - $data['totalFiles'][] = array('xid' => $xlast_id ,'image_url' => '/one-media/one-image-nonlab/'.$filename); - - } - else{ - $error = array('error' => $this->upload->display_errors()); - } - - } - - - - } - - $result = array("total" =>count( $data['totalFiles']), "records" => $data['totalFiles'],'errors'=>$error); - $this->sys_ok($result); - } - - - function getpatologianatomyresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT Other_PatologiAnatomyID as xid, - Other_PatologiAnatomyT_OrderDetailID as orderdetail_id, - Other_PatologiAnatomyNoSediaan as no_sediaan, - Other_PatologiAnatomyDiagnosaKlinis as diagnosa, - Other_PatologiAnatomyKeteranganKlinis as klinis, - Other_PatologiAnatomyLokasiOrgan as lokasi, - Other_PatologiAnatomyMakroskopik as makroskopik, - Other_PatologiAnatomyMikroskopik as mikroskopik, - Other_PatologiAnatomyKesimpulan as kesimpulan, - IFNULL(Other_PatologiAnatomyM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_PatologiAnatomyM_DoctorID) OR Other_PatologiAnatomyM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_patologi_anatomy - LEFT JOIN m_doctor ON Other_PatologiAnatomyM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_PatologiAnatomyT_OrderDetailID = {$id} AND Other_PatologiAnatomyIsActive = 'Y' - GROUP BY Other_PatologiAnatomyID - ORDER BY Other_PatologiAnatomyID ASC - LIMIT 1"; - $query = $this->db_smartone->query($sql); - - if ($query) - { - $rows = $query->row_array(); - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - - $rst = array('doctors'=>$doctors,'result'=>$rows); - $this->sys_ok(["records"=>$rst]); - } - else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - - - function generateRandomString($length = 10) { - $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; - $charactersLength = strlen($characters); - $randomString = ''; - for ($i = 0; $i < $length; $i++) { - $randomString .= $characters[rand(0, $charactersLength - 1)]; - } - return $randomString; - } - - function getcytologiresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT Other_CytologiDetailsID as xid, - Other_CytologiT_OrderDetailID as orderdetail_id, - Other_CytologiDetailsCode as code, - Other_CytologiDetailsLabel as label, - Other_CytologiDetailsResult as result, - IFNULL(Other_CytologiM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_CytologiM_DoctorID) OR Other_CytologiM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_cytologi - JOIN other_cytologidetails ON Other_CytologiDetailsOther_CytologiID = Other_CytologiID AND Other_CytologiDetailsIsActive = 'Y' - LEFT JOIN m_doctor ON Other_CytologiM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_CytologiT_OrderDetailID = {$id} AND Other_CytologiIsActive = 'Y' - GROUP BY Other_CytologiDetailsID - ORDER BY Other_CytologiDetailsCode ASC"; - //echo $sql; - $query = $this->db_smartone->query($sql); - - if ($query) - { - $rows = $query->result_array(); - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $rst = array('doctors'=>$doctors,'results'=>$rows); - $this->sys_ok(["records"=>$rst]); - } - else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - function getmikroresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT - Other_MikroID as xid, - Other_MikroHasilBiakan as hasil_biakan, - Other_MikroSampleTypeName as sample_name, - Other_MikroT_OrderDetailID as orderdetail_id, - Other_MikroResult as result_value, - '' as result_other, - IFNULL(T_BacteriaID,0) as T_BacteriaID, - IFNULL(T_BacteriaName,'') as T_BacteriaName, - '' as details, - IFNULL(Other_MikroM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_MikroM_DoctorID) OR Other_MikroM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_mikro - LEFT JOIN t_bacteria ON Other_MikroT_BacteriaID = T_BacteriaID - LEFT JOIN m_doctor ON Other_MikroM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_MikroT_OrderDetailID = {$id} AND Other_MikroIsActive = 'Y' - GROUP BY Other_MikroID"; - //echo $sql; - $query = $this->db_smartone->query($sql); - - if ($query) - { - $row = $query->row_array(); - if($row){ - if($row['result_value'] != 'Positif' && $row['result_value'] != 'Negatif'){ - $row['result_other'] = $row['result_value']; - $row['result_value'] = 'other'; - } - $sql = "SELECT '' as xno, - Other_MikroDetailsID as xid, - Other_MikroDetailsValue as value, - IF(Other_MikroDetailsNote = 'R','Y','N') as chx_r, - IF(Other_MikroDetailsNote = 'I','Y','N') as chx_i, - IF(Other_MikroDetailsNote = 'S','Y','N') as chx_s, - Other_MikroDetailsNote as note, - t_antibiotic.* - FROM other_mikrodetails - LEFT JOIN t_antibiotic ON Other_MikroDetailsT_AntibioticID = T_AntibioticID - WHERE - Other_MikroDetailsOther_MikroID = {$row['xid']} AND Other_MikroDetailsIsActive = 'Y' - GROUP BY Other_MikroDetailsID - ORDER BY T_AntibioticName ASC"; - //echo $sql; - $details = $this->db_smartone->query($sql)->result_array(); - if(details){ - foreach($details as $k => $v){ - $details[$k]['xno'] = $k + 1; - } - } - $row['details'] = $details; - } - else{ - $row = array('xid'=>'0','hasil_biakan' => '','result_value'=>'Negatif','sample_name' => '','orderdetail_id'=>$id, 'T_BacteriaID'=>'0','T_BacteriaName'=>'0','details'=>array(),'doctor_id'=>'0','doctor_name'=>'0'); - } - } - else{ - $row = array('xid'=>'0','hasil_biakan' => '','result_value'=>'Negatif','sample_name' => '','orderdetail_id'=>$id, 'T_BacteriaID'=>'0','T_BacteriaName'=>'0','details'=>array(),'doctor_id'=>'0','doctor_name'=>'0'); - } - //print_r($row); - - - - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 7 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $sql = " - SELECT '0' as id, 'Belum memilih bakteria' as name - UNION - SELECT T_BacteriaID as id, T_BacteriaName as name - FROM t_bacteria - WHERE - T_BacteriaIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $bacteries = $this->db_smartone->query($sql)->result_array(); - $rst = array('doctors'=>$doctors,'bacteries'=>$bacteries,'results'=>$row); - $this->sys_ok(["records"=>$rst]); - } - function getantibiotics(){ - $prm = $this->sys_input; - $id = $prm["id"]; - $sql = " SELECT '' as xno, - 0 as xid, - '' as hasil_biakan, - '' as sample_name, - 0 as value, - 'Y' as chx_r, - 'N' as chx_i, - 'N' as chx_s, - 'R' as note, - t_antibiotic.* - FROM t_antibiotic - WHERE - T_AntibioticT_BacteriaID = {$prm['id']} AND T_AntibioticIsActive= 'Y' - ORDER BY T_AntibioticName ASC"; - //echo $sql; - $rows = $this->db_smartone->query($sql)->result_array(); - if(rows){ - foreach($rows as $k => $v){ - $rows[$k]['xno'] = $k + 1; - } - } - - $this->sys_ok(["records"=>$rows]); - } - function getlcprepresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - $sql = " SELECT Other_LcprepDetailsID as xid, - Other_LcprepID as header_id, - Other_LcprepT_orderDetailID as orderdetail_id, - Other_LcprepDetailsCode as code, - Other_LcprepDetailsLabel as label, - Other_LcprepDetailsResult as result, - IFNULL(Other_LcprepM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_LcprepM_DoctorID) OR Other_LcprepM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_lcprep - JOIN other_lcprepdetails ON Other_LcprepDetailsOther_LcprepID = Other_LcprepID AND Other_LcprepDetailsIsActive = 'Y' - LEFT JOIN m_doctor ON Other_LcprepM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_LcprepT_orderDetailID = {$id} AND Other_LcprepIsActive = 'Y' - GROUP BY Other_LcprepDetailsOther_LcprepID, Other_LcprepDetailsCode - ORDER BY Other_LcprepDetailsCode ASC"; - //echo $sql; - $rows = $this->db_smartone->query($sql)->result_array(); - if(!$rows){ - $rows = array( - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'A', - 'label' => 'DESKRIPSI', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ), - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'B', - 'label' => 'KESIMPULAN', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ) - ); - } - - $header_id = $rows[0]['header_id']; - $sql = "SELECT IFNULL(Other_LcprepAdekuasiID,0) as xid, - Lcprep_AdekuasiID as id, - Lcprep_AdekuasiLabel as name, - IF(ISNULL(Other_LcprepAdekuasiID),'N',Other_LcprepAdekuasiChex) as chex - FROM lcprep_adekuasi - LEFT JOIN other_lcprepadekuasi ON Other_LcprepAdekuasiLcprep_AdekuasiID = Lcprep_AdekuasiID AND - Other_LcprepAdekuasiOther_LcprepID = {$header_id} AND - Other_LcprepAdekuasiIsActive = 'Y' - WHERE - Lcprep_AdekuasiIsActive = 'Y' - GROUP BY Lcprep_AdekuasiID - ORDER BY Lcprep_AdekuasiOrder ASC - "; - //echo $sql; - $adeakuasi = $this->db_smartone->query($sql)->result_array(); - foreach($adeakuasi as $kc => $vc){ - $adeakuasi[$kc]['chex'] = $vc['chex'] == 'N'?false:true; - } - - $sql = "SELECT IFNULL(Other_LcprepKategoriUmumID,0) as xid, - Lcprep_KategoriUmumID as id, - Lcprep_KategoriUmumLabel as name, - IF(ISNULL(Other_LcprepKategoriUmumID),'N',Other_LcprepKategoriUmumChex) as chex - FROM lcprep_kategoriumum - LEFT JOIN other_lcprepkategoriumum ON Other_LcprepKategoriUmumLcprep_KategoriUmumID = Lcprep_KategoriUmumID AND - Other_LcprepKategoriUmumOther_LcprepID = {$header_id} AND - Other_LcprepKategoriUmumIsActive = 'Y' - WHERE - Lcprep_KategoriUmumIsActive = 'Y' - GROUP BY Lcprep_KategoriUmumID - "; - //echo $sql; - $kategoriumum = $this->db_smartone->query($sql)->result_array(); - foreach($kategoriumum as $kc => $vc){ - $kategoriumum[$kc]['chex'] = $vc['chex'] == 'N'?false:true; - } - - $sql = " - SELECT Lcprep_InterpretasiGroupID as group_id, - Lcprep_InterpretasiGroupName as group_name, - '' as subgroups - FROM lcprep_interpretasigroup - WHERE - Lcprep_InterpretasiGroupIsActive = 'Y' - "; - //echo $sql; - $interpretasi = $this->db_smartone->query($sql)->result_array(); - foreach($interpretasi as $k => $v){ - $subgroups = array(); - $sql = "SELECT Lcprep_InterpretasiSubgroupID as subgroup_id, - Lcprep_InterpretasiSubgroupName as subgroup_name, - '' as childs - FROM lcprep_interpretasisubgroup - WHERE - Lcprep_InterpretasiSubgroupLcprep_InterpretasiGroupID = {$v['group_id']} AND Lcprep_InterpretasiSubgroupIsActive = 'Y'"; - //echo $sql; - $subgroups = $this->db_smartone->query($sql)->result_array(); - if(count($subgroups) > 0){ - foreach($subgroups as $ki => $vi){ - $childs = array(); - $sql = "SELECT IFNULL(Other_LcprepInterpretasiID,0) as xid, - IFNULL(Other_LcprepInterpretasiChex,'N') as chex, - IFNULL(Other_LcprepInterpretasiValue,'') as value, - Lcprep_InterpretasiID as id, - Lcprep_InterpretasiLcprep_InterpretasiSubgroupID as subgroup_id, - Lcprep_InterpretasiCode as code, - Lcprep_InterpretasiName as name, - Lcprep_InterpretasiParentID as parent_id, - Lcprep_InterpretasiIsParent as is_parent, - Lcprep_InterpretasiHasResult as has_result, - Lcprep_InterpretasiTypeResult as type_result - FROM lcprep_interpretasi - LEFT JOIN other_lcprepinterpretasi ON Other_LcprepInterpretasiOther_LcprepID = {$header_id} AND - Other_LcprepInterpretasiLcprep_InterpretasiID = Lcprep_InterpretasiID AND - Other_LcprepInterpretasiIsActive = 'Y' - WHERE - Lcprep_InterpretasiLcprep_InterpretasiSubgroupID = {$vi['subgroup_id']} AND Lcprep_InterpretasiIsActive = 'Y' - GROUP BY Lcprep_InterpretasiID Order BY Lcprep_InterpretasiCode ASC"; - $childs = $this->db_smartone->query($sql)->result_array(); - if($childs){ - foreach($childs as $kc => $vc){ - $childs[$kc]['chex'] = $vc['chex'] == 'N'?false:true; - } - } - $subgroups[$ki]['childs'] = $childs; - } - } - - $interpretasi[$k]['subgroups'] = $subgroups; - } - - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $rst = array('doctors'=>$doctors,'results'=>$rows,'adekuasi'=>$adeakuasi,'kategoriumum'=>$kategoriumum,'interpretasi'=>$interpretasi); - $this->sys_ok(["records"=>$rst]); - } - - function getpapsmearresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT Other_PapSmearDetailsID as xid, - Other_PapSmearID as header_id, - Other_PapSmearT_OrderDetailID as orderdetail_id, - Other_PapSmearDetailsCode as code, - Other_PapSmearDetailsLabel as label, - Other_PapSmearDetailsResult as result, - IFNULL(Other_PapSmearM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_PapSmearM_DoctorID) OR Other_PapSmearM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_papsmear - JOIN other_papsmeardetails ON Other_PapSmearDetailsOther_PapSmearID = Other_PapSmearID AND Other_PapSmearDetailsIsActive = 'Y' - LEFT JOIN m_doctor ON Other_PapSmearM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_PapSmearT_OrderDetailID = {$id} AND Other_PapSmearIsActive = 'Y' - GROUP BY Other_PapSmearDetailsID - ORDER BY Other_PapSmearDetailsCode ASC"; - //echo $sql; - $rows = $this->db_smartone->query($sql)->result_array(); - if(!$rows){ - $rows = array( - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'A', - 'label' => 'Makroskopik', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ), - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'B', - 'label' => 'Mikroskopik', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ), - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'C', - 'label' => 'Kesimpulan', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ) - ); - } - - $header_id = $rows[0]['header_id']; - $sql = "SELECT Other_PapSmearMaturasiID as xid, - Other_PapSmearMaturasiValue as value - FROM other_papsmearmaturasi - WHERE - Other_PapSmearMaturasiOther_PapSmearID = {$header_id} AND - Other_PapSmearMaturasiIsActive = 'Y' - "; - //echo $sql; - $dt_maturasi = $this->db_smartone->query($sql)->row_array(); - if(!$dt_maturasi){ - $maturasi = array('xid'=>'0','value'=> array('','','')); - } - else{ - $value = explode('/',$dt_maturasi['value']); - $maturasi = array('xid'=>$dt_maturasi['xid'],'value'=> $value); - } - - $sql = "SELECT IFNULL(Other_PapSmearBahanID,0) as xid, - M_PapSmearBahanID as bahan_id, - M_PapSmearBahanName as name, - IF(ISNULL(Other_PapSmearBahanID),'N','Y') as selected - FROM m_papsmearbahan - LEFT JOIN other_papsmearbahan ON Other_PapSmearBahanM_PapSmearBahanID = M_PapSmearBahanID AND - Other_PapSmearBahanOther_PapSmearID = {$header_id} AND - Other_PapSmearBahanIsActive = 'Y' - WHERE - M_PapSmearBahanIsActive = 'Y' - ORDER BY M_PapSmearBahanID ASC - "; - //echo $sql; - $bahans = $this->db_smartone->query($sql)->result_array(); - - $sql = "SELECT IFNULL(Other_PapsmearCategoryID,0) as xid, - M_PapSmearCategoryID as category_id, - M_PapSmearCategoryName as name, - IF(ISNULL(Other_PapsmearCategoryID),'N','Y') as selected - FROM m_papsmearcategory - LEFT JOIN other_papsmearcategory ON Other_PapsmearCategoryM_PapSmearCategoryID = M_PapSmearCategoryID AND - Other_PapsmearCategoryOther_PapSmearID = {$header_id} AND - Other_PapsmearCategoryIsActive = 'Y' - WHERE - M_PapSmearCategoryIsActive = 'Y' - ORDER BY M_PapSmearCategoryID ASC - "; - //echo $sql; - $categories = $this->db_smartone->query($sql)->result_array(); - - $sql = "SELECT IFNULL(Other_PapSmearCheckID,0) as xid, - M_PapSmearCheckID as check_id, - M_PapSmearCheckLabel as name, - IF(ISNULL(Other_PapSmearCheckID),'N','Y') as selected, - Other_PapSmearCheckNote as note - FROM m_papsmearcheck - LEFT JOIN other_papsmearcheck ON Other_PapSmearCheckM_PapSmearCheckID = M_PapSmearCheckID AND - Other_PapSmearCheckOther_PapSmearID = {$header_id} AND - Other_PapSmearCheckIsActive = 'Y' - WHERE - M_PapSmearCheckIsActive = 'Y' - ORDER BY M_PapSmearCheckCode ASC - "; - $checks = $this->db_smartone->query($sql)->result_array(); - - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $rst = array('doctors'=>$doctors,'checks'=>$checks,'bahans'=>$bahans,'categories'=>$categories,'maturasi'=>$maturasi,'results'=>$rows); - $this->sys_ok(["records"=>$rst]); - - } - - function saveresult_lcprep() - { - $prm = $this->sys_input; - $detail_id = $prm['detail_id']; - $doctor_id = $prm['doctor']; - $adekuasi = $prm['adekuasi']; - $kategoriumum = $prm['kategoriumum']; - $interpretasi = $prm['interpretasi']; - $results = $prm['results']; - - $userid = $this->sys_user['M_UserID']; - - $header_id = 0; - $sql = "SELECT * FROM other_lcprep WHERE Other_LcprepT_orderDetailID = {$detail_id} AND Other_LcprepIsActive = 'Y'"; - $dt_header = $this->db_smartone->query($sql)->row_array(); - if($dt_header){ - $header_id = $dt_header['Other_LcprepID']; - } - if($header_id == 0){ - $sql = "INSERT INTO other_lcprep( - Other_LcprepT_orderDetailID, - Other_LcprepM_DoctorID, - Other_LcprepUserID, - Other_LcprepCreated - ) - VALUES( - {$detail_id}, - {$doctor_id}, - {$userid}, - NOW() - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - }else{ - $sql = "UPDATE other_lcprep SET Other_LcprepM_DoctorID = {$doctor_id}, Other_LcprepUserID = {$userid} WHERE Other_LcprepID = {$header_id}"; - $this->db_smartone->query($sql); - } - - if($adekuasi){ - foreach($adekuasi as $k =>$v){ - $selected = $v['chex']?'Y':'N'; - if(intval($v['xid'] == 0)){ - $sql = "UPDATE other_lcprepadekuasi SET Other_LcprepAdekuasiIsActive = 'N' - WHERE - Other_LcprepAdekuasiOther_LcprepID = {$header_id} AND - Other_LcprepAdekuasiIsActive = 'Y' AND - Other_LcprepAdekuasiLcprep_AdekuasiID = {$v['id']}"; - $this->db_smartone->query($sql); - $sql = "INSERT INTO other_lcprepadekuasi ( - Other_LcprepAdekuasiOther_LcprepID, - Other_LcprepAdekuasiLcprep_AdekuasiID, - Other_LcprepAdekuasiChex, - Other_LcprepAdekuasiUserID, - Other_LcprepAdekuasiCreated - ) - VALUES( - {$header_id}, - {$v['id']}, - '{$selected}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - //echo $sql; - } - if(intval($v['xid'] != 0)){ - - $sql = "UPDATE other_lcprepadekuasi SET - Other_LcprepAdekuasiChex = '{$selected}', - Other_LcprepAdekuasiUserID = {$userid} - WHERE - Other_LcprepAdekuasiID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - - //echo $sql; - } - } - - if($kategoriumum){ - foreach($kategoriumum as $k =>$v){ - $selected = $v['chex']?'Y':'N'; - if(intval($v['xid'] == 0)){ - $sql = "UPDATE other_lcprepkategoriumum SET Other_LcprepKategoriUmumIsActive = 'N' - WHERE - Other_LcprepKategoriUmumOther_LcprepID = {$header_id} AND - Other_LcprepKategoriUmumLcprep_KategoriUmumID = {$v['id']} AND - Other_LcprepKategoriUmumIsActive = 'Y' - "; - $this->db_smartone->query($sql); - $sql = "INSERT INTO other_lcprepkategoriumum ( - Other_LcprepKategoriUmumOther_LcprepID, - Other_LcprepKategoriUmumLcprep_KategoriUmumID, - Other_LcprepKategoriUmumChex, - Other_LcprepKategoriUmumUserID, - Other_LcprepKategoriUmumCreated - ) - VALUES( - {$header_id}, - {$v['id']}, - '{$selected}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if(intval($v['xid'] != 0)){ - $sql = "UPDATE other_lcprepkategoriumum SET - Other_LcprepKategoriUmumChex = '{$selected }', - Other_LcprepKategoriUmumUserID = {$userid} - WHERE - Other_LcprepKategoriUmumID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - - //echo $sql; - } - } - - if($results){ - foreach($results as $k =>$v){ - if(intval($v['xid'] == 0)){ - $sql = "UPDATE other_lcprepdetails SET Other_LcprepDetailsIsActive = 'N' - WHERE - Other_LcprepDetailsOther_LcprepID = {$header_id} AND - Other_LcprepDetailsCode = '{$v['code']}' AND - Other_LcprepDetailsIsActive = 'Y'"; - $this->db_smartone->query($sql); - $sql = "INSERT INTO other_lcprepdetails ( - Other_LcprepDetailsOther_LcprepID, - Other_LcprepDetailsCode, - Other_LcprepDetailsLabel, - Other_LcprepDetailsResult, - Other_LcprepDetailsUserID, - Other_LcprepDetailsCreated - ) - VALUES( - {$header_id}, - '{$v['code']}', - '{$v['label']}', - '{$v['result']}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if(intval($v['xid'] != 0)){ - $sql = "UPDATE other_lcprepdetails SET - Other_LcprepDetailsCode = '{$v['code']}', - Other_LcprepDetailsLabel = '{$v['label']}', - Other_LcprepDetailsResult = '{$v['result']}', - Other_LcprepDetailsUserID = {$userid} - WHERE - Other_LcprepDetailsID = {$v['xid']}"; - $this->db_smartone->query($sql); - - } - //echo $sql; - } - } - - if($interpretasi){ - foreach($interpretasi as $k =>$v){ - if(count($v['subgroups']) > 0){ - foreach($v['subgroups'] as $ik => $iv){ - if(count($iv['childs']) > 0){ - foreach($iv['childs'] as $iik => $iiv){ - if(intval($iiv['xid'] == 0)){ - $chex = $iiv['chex'] ? 'Y':'N'; - $sql = "UPDATE other_lcprepinterpretasi SET Other_LcprepInterpretasiIsActive = 'N' - WHERE - Other_LcprepInterpretasiOther_LcprepID = {$header_id} AND - Other_LcprepInterpretasiLcprep_InterpretasiID = '{$iiv['id']}' AND - Other_LcprepInterpretasiIsActive = 'Y'"; - $this->db_smartone->query($sql); - $sql = "INSERT INTO other_lcprepinterpretasi ( - Other_LcprepInterpretasiOther_LcprepID, - Other_LcprepInterpretasiLcprep_InterpretasiID, - Other_LcprepInterpretasiChex, - Other_LcprepInterpretasiValue, - Other_LcprepInterpretasiUserID, - Other_LcprepInterpretasiCreated - ) - VALUES( - {$header_id}, - '{$iiv['id']}', - '{$chex}', - '{$iiv['value']}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - - if(intval($iiv['xid'] != 0)){ - $chex = $iiv['chex'] ? 'Y':'N'; - $sql = "UPDATE other_lcprepinterpretasi SET - Other_LcprepInterpretasiChex = '{$chex}', - Other_LcprepInterpretasiValue = '{$iiv['value']}', - Other_LcprepInterpretasiUserID = {$userid} - WHERE - Other_LcprepInterpretasiID = {$iiv['xid']}"; - $this->db_smartone->query($sql); - //echo $sql; - - } - - } - } - } - } - //echo $sql; - } - } - - - $result = array("total" => 1, "records" => array(), "sql"=> ''); - $this->sys_ok($result); - exit; - } - - function saveresult_papsmear() - { - $prm = $this->sys_input; - $detail_id = $prm['detail_id']; - $doctor_id = $prm['doctor']; - $checks = $prm['checks']; - $maturasi = $prm['maturasi']; - $bahans = $prm['bahans']; - $categories = $prm['categories']; - $results = $prm['results']; - - $userid = $this->sys_user['M_UserID']; - - $header_id = 0; - $sql = "SELECT * FROM other_papsmear WHERE Other_PapSmearT_OrderDetailID = {$detail_id} AND Other_PapSmearIsActive = 'Y'"; - $dt_header = $this->db_smartone->query($sql)->row_array(); - if($dt_header){ - $header_id = $dt_header['Other_PapSmearID']; - } - if($header_id == 0){ - $sql = "INSERT INTO other_papsmear( - Other_PapSmearT_OrderDetailID, - Other_PapSmearM_DoctorID, - Other_PapSmearUserID, - Other_PapSmearCreated - ) - VALUES( - {$detail_id}, - {$doctor_id}, - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } - else{ - $sql = "UPDATE other_papsmear SET Other_PapSmearM_DoctorID = {$doctor_id}, Other_PapSmearUserID = {$userid} WHERE Other_PapSmearID = {$header_id}"; - $this->db_smartone->query($sql); - } - - if($checks){ - foreach($checks as $k =>$v){ - if(intval($v['xid']) == 0 && $v['selected'] === 'Y'){ - $sql = "INSERT INTO other_papsmearcheck ( - Other_PapSmearCheckOther_PapSmearID, - Other_PapSmearCheckM_PapSmearCheckID, - Other_PapSmearCheckNote, - Other_PapSmearCheckUserID, - Other_PapSmearCheckCreated - ) - VALUES( - {$header_id}, - {$v['check_id']}, - '{$v['note']}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if(intval($v['xid']) != 0 && $v['selected'] === 'N'){ - $sql = "UPDATE other_papsmearcheck SET - Other_PapSmearCheckIsActive = 'N', - Other_PapSmearCheckUserID = {$userid} - WHERE - Other_PapSmearCheckID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - if(intval($v['xid']) != 0 && $v['selected'] === 'Y'){ - $sql = "UPDATE other_papsmearcheck SET - Other_PapSmearCheckNote = '{$v['note']}', - Other_PapSmearCheckUserID = {$userid} - WHERE - Other_PapSmearCheckID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - //echo $sql; - } - } - - if($maturasi){ - if(intval($maturasi['xid']) == 0){ - $value = join("/",$maturasi['value']); - $sql = "INSERT INTO other_papsmearmaturasi ( - Other_PapSmearMaturasiOther_PapSmearID, - Other_PapSmearMaturasiValue, - Other_PapSmearMaturasiUserID, - Other_PapSmearMaturasiCreated - ) - VALUE( - {$header_id}, - '{$value}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - //echo $sql; - } - if(intval($maturasi['xid']) != 0){ - $value = join("/",$maturasi['value']); - $sql = "UPDATE other_papsmearmaturasi SET - Other_PapSmearMaturasiValue = '{$value}', - Other_PapSmearMaturasiUserID = {$userid} - WHERE - Other_PapSmearMaturasiID = {$maturasi['xid']}"; - // echo $sql; - $this->db_smartone->query($sql); - } - } - - if($bahans){ - foreach($bahans as $k =>$v){ - if(intval($v['xid']) == 0 && $v['selected'] === 'Y'){ - $sql = "INSERT INTO other_papsmearbahan ( - Other_PapSmearBahanOther_PapSmearID, - Other_PapSmearBahanM_PapSmearBahanID, - Other_PapSmearBahanUserID, - Other_PapSmearBahanCreated - ) - VALUES( - {$header_id}, - {$v['bahan_id']}, - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if(intval($v['xid']) != 0 && $v['selected'] === 'N'){ - $sql = "UPDATE other_papsmearbahan SET - Other_PapSmearBahanIsActive = 'N', - Other_PapsmearCategoryUserID = {$userid} - WHERE - Other_PapSmearBahanID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - if(intval($v['xid']) != 0 && $v['selected'] === 'Y'){ - $sql = "UPDATE other_papsmearbahan SET - Other_PapSmearBahanIsActive = 'Y', - Other_PapsmearCategoryUserID = {$userid} - WHERE - Other_PapSmearBahanID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - //echo $sql; - } - } - - if($categories){ - foreach($categories as $k =>$v){ - if(intval($v['xid']) == 0 && $v['selected'] === 'Y'){ - $sql = "INSERT INTO other_papsmearcategory ( - Other_PapsmearCategoryOther_PapSmearID, - Other_PapsmearCategoryM_PapSmearCategoryID, - Other_PapsmearCategoryUserID, - Other_PapsmearCategoryCreated - ) - VALUES( - {$header_id}, - {$v['category_id']}, - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if(intval($v['xid']) != 0 && $v['selected'] === 'N'){ - $sql = "UPDATE other_papsmearcategory SET - Other_PapsmearCategoryIsActive = 'N', - Other_PapsmearCategoryUserID = {$userid} - WHERE - Other_PapsmearCategoryID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - //echo $sql; - if(intval($v['xid']) != 0 && $v['selected'] === 'Y'){ - $sql = "UPDATE other_papsmearcategory SET - Other_PapsmearCategoryIsActive = 'Y', - Other_PapsmearCategoryUserID = {$userid} - WHERE - Other_PapsmearCategoryID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - } - } - - if($results){ - foreach($results as $k =>$v){ - if(intval($v['xid']) == 0){ - $sql = "INSERT INTO other_papsmeardetails ( - Other_PapSmearDetailsOther_PapSmearID, - Other_PapSmearDetailsCode, - Other_PapSmearDetailsLabel, - Other_PapSmearDetailsResult, - Other_PapSmearDetailsUserID, - Other_PapSmearDetailsCreated - ) - VALUES( - {$header_id}, - '{$v['code']}', - '{$v['label']}', - '{$v['result']}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if(intval($v['xid']) != 0){ - $sql = "UPDATE other_papsmeardetails SET - Other_PapSmearDetailsCode = '{$v['code']}', - Other_PapSmearDetailsLabel = '{$v['label']}', - Other_PapSmearDetailsResult = '{$v['result']}', - Other_PapSmearDetailsUserID = {$userid} - WHERE - Other_PapSmearDetailsID = {$v['xid']}"; - $this->db_smartone->query($sql); - - } - //echo $sql; - } - } - - $result = array("total" => 1, "records" => array(), "sql"=> ''); - $this->sys_ok($result); - exit; - } - - function saveresult_fna() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = $inp['doctor']; - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - if($prm[0]['xid'] == '0'){ - $sql = "INSERT INTO other_fna( - Other_FNAM_DoctorID, - Other_FNAT_OrderDetailID, - Other_FNAUserID, - Other_FNACreated - ) - VALUES( - {$doctor_id}, - {$prm[0]['orderdetail_id']}, - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } - else{ - $sql = "SELECT * FROM other_fna WHERE Other_FNAT_OrderDetailID = {$prm[0]['orderdetail_id']} AND Other_FNAIsActive = 'Y'"; - $data_header = $this->db_smartone->query($sql)->row_array(); - $header_id = $data_header['Other_FNAID']; - $sql = "UPDATE other_fna SET - Other_FNAM_DoctorID = {$doctor_id}, - Other_FNAUserID = {$userid} - WHERE - Other_FNAID = {$header_id}"; - $this->db_smartone->query($sql); - } - foreach($prm as $k => $v){ - if($v['xid'] == '0'){ - $results = str_replace("'", "\\'", $v['result']); - $sql = "INSERT INTO other_fnadetails( - Other_FNADetailsOther_FNAID , - Other_FNADetailsCode, - Other_FNADetailsLabel, - Other_FNADetailsResult, - Other_FNADetailsCreated, - Other_FNADetailsUserID - ) - VALUES( - {$header_id}, - '{$v['code']}', - '{$v['label']}', - '{$results}', - NOW(), - {$userid} - )"; - $query = $this->db_smartone->query($sql); - } - else{ - $results = str_replace("'", "\\'", $v['result']); - $sql = "UPDATE other_fnadetails SET - Other_FNADetailsResult = '{$results}', - Other_FNADetailsUserID = {$userid} - WHERE - Other_FNADetailsID = {$v['xid']}"; - $query = $this->db_smartone->query($sql); - } - } - - $result = array("total" => 1, "records" => array(), "sql"=> ''); - $this->sys_ok($result); - exit; - } - - function saveresult_cytologi() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = $inp['doctor']; - - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - if($prm[0]['xid'] == '0'){ - $sql = "INSERT INTO other_cytologi( - Other_CytologiT_OrderDetailID, - Other_CytologiM_DoctorID, - Other_CytologiUserID, - Other_CytologiCreated - ) - VALUES( - {$prm[0]['orderdetail_id']}, - {$doctor_id}, - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } - else{ - $sql = "SELECT * FROM other_cytologi WHERE Other_CytologiT_OrderDetailID = {$prm[0]['orderdetail_id']} AND Other_CytologiIsActive = 'Y'"; - $data_header = $this->db_smartone->query($sql)->row_array(); - $header_id = $data_header['Other_CytologiID']; - $sql = "UPDATE other_cytologi SET - Other_CytologiM_DoctorID = {$doctor_id}, - Other_CytologiUserID = {$userid} - WHERE - Other_CytologiID = {$header_id}"; - $this->db_smartone->query($sql); - } - foreach($prm as $k => $v){ - if($v['xid'] == '0'){ - $results = str_replace("'", "\\'", $v['result']); - $sql = "INSERT INTO other_cytologidetails( - Other_CytologiDetailsOther_CytologiID , - Other_CytologiDetailsCode, - Other_CytologiDetailsLabel, - Other_CytologiDetailsResult, - Other_CytologiDetailsCreated, - Other_CytologiDetailsUserID - ) - VALUES( - {$header_id}, - '{$v['code']}', - '{$v['label']}', - '{$results}', - NOW(), - {$userid} - )"; - $query = $this->db_smartone->query($sql); - } - else{ - $results = str_replace("'", "\\'", $v['result']); - $sql = "UPDATE other_cytologidetails SET - Other_CytologiDetailsResult = '{$results}', - Other_CytologiDetailsUserID = {$userid} - WHERE - Other_CytologiDetailsID = {$v['xid']}"; - $query = $this->db_smartone->query($sql); - } - } - - $result = array("total" => 1, "records" => array(), "sql"=> ''); - $this->sys_ok($result); - exit; - } - - function saveresult_mikro() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = $inp['doctor']; - $backteria_id = $inp['bacteria']; - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - - if($inp['result_value'] != 'Negatif' && $inp['result_value'] != 'Positif'){ - $prm['result_value'] = $prm['result_other']; - } - else{ - $prm['result_value'] = $inp['result_value']; - } - - if($prm['xid'] == '0'){ - $sql = "INSERT INTO other_mikro( - Other_MikroM_DoctorID, - Other_MikroResult, - Other_MikroT_BacteriaID, - Other_MikroT_OrderDetailID, - Other_MikroHasilBiakan, - Other_MikroSampleTypeName, - Other_MikroUserID, - Other_MikroCreated - ) - VALUES( - {$doctor_id}, - '{$prm['result_value']}', - {$backteria_id}, - {$prm['orderdetail_id']}, - '{$prm['hasil_biakan']}', - '{$prm['sample_name']}', - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } - else{ - $sql = "SELECT * FROM other_mikro WHERE Other_MikroT_OrderDetailID = {$prm['orderdetail_id']} AND Other_MikroIsActive = 'Y'"; - $data_header = $this->db_smartone->query($sql)->row_array(); - $header_id = $data_header['Other_MikroID']; - $sql = "UPDATE other_mikro SET - Other_MikroResult = '{$prm['result_value']}', - Other_MikroM_DoctorID = {$doctor_id}, - Other_MikroT_BacteriaID = {$backteria_id}, - Other_MikroHasilBiakan = '{$prm['hasil_biakan']}', - Other_MikroSampleTypeName = '{$prm['sample_name']}', - Other_MikroUserID = {$userid} - WHERE - Other_MikroID = {$header_id}"; - //echo $sql; - $this->db_smartone->query($sql); - } - - - - $sql = "UPDATE other_mikrodetails SET Other_MikroDetailsIsActive = 'N', Other_MikroDetailsUserID = 0 WHERE Other_MikroDetailsOther_MikroID = {$header_id}"; - $this->db_smartone->query($sql); - - $results = $prm['details']; - if($inp['result_value'] == 'Positif'){ - foreach($results as $k => $v){ - if($v['xid'] == '0'){ - $sql = "INSERT INTO other_mikrodetails( - Other_MikroDetailsOther_MikroID , - Other_MikroDetailsT_AntibioticID, - Other_MikroDetailsValue, - Other_MikroDetailsNote, - Other_MikroDetailsCreated, - Other_MikroDetailsUserID - ) - VALUES( - {$header_id}, - '{$v['T_AntibioticID']}', - '{$v['value']}', - '{$v['note']}', - NOW(), - {$userid} - )"; - $query = $this->db_smartone->query($sql); - } - else{ - $sql = "UPDATE other_mikrodetails SET - Other_MikroDetailsT_AntibioticID = '{$v['T_AntibioticID']}', - Other_MikroDetailsValue = '{$v['value']}', - Other_MikroDetailsNote = '{$v['note']}', - Other_MikroDetailsIsActive = 'Y', - Other_MikroDetailsUserID = {$userid} - WHERE - Other_MikroDetailsID = {$v['xid']}"; - //echo $sql; - $query = $this->db_smartone->query($sql); - } - } - } - - - $result = array("total" => 1, "records" => array(), "sql"=> ''); - $this->sys_ok($result); - exit; - } - - - function get_doctors_preparasi_sperma() - { - $prm = $this->sys_input; - // $id = $prm["id"]; - - $sql = " SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 10 AND - M_DoctorSOIsActive = 'Y' - ORDER BY M_DoctorName ASC"; - //echo $sql; - $query = $this->db_smartone->query($sql); - $rows = $query->result_array(); - $sql = " - SELECT '0' as id, 'Belum memilih metode' as name - UNION - SELECT M_MethodeSpermaID as id, M_MethodeSpermaName as name - FROM m_methodesperma - WHERE - M_MethodeSpermaIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $methodes = $this->db_smartone->query($sql)->result_array(); - - - $this->sys_ok(["records"=>$rows,"methodes"=>$methodes]); - - } - - - function getpreparasispermaresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT other_preparasisperma.*, - Other_PreparasiSpermaID as xid, - Other_PreparasiSpermaT_OrderDetailID as orderdetail_id, - IFNULL(Other_PreparasiSpermaM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_PreparasiSpermaM_DoctorID) OR Other_PreparasiSpermaM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name, - IFNULL(M_MethodeSpermaID,0) as methode_id, - IFNULL(M_MethodeSpermaName,'') as methode_name - FROM other_preparasisperma - LEFT JOIN m_doctor ON Other_PreparasiSpermaM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - LEFT JOIN m_methodesperma ON Other_PreparasiSpermaM_MethodeSpermaID = M_MethodeSpermaID AND - M_MethodeSpermaIsActive = 'Y' - WHERE - Other_PreparasiSpermaT_OrderDetailID = {$id} AND Other_PreparasiSpermaIsActive = 'Y' - GROUP BY Other_PreparasiSpermaID"; - $query = $this->db_smartone->query($sql); - - if ($query) - { - $rows = $query->row_array(); - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 10 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $sql = " - SELECT '0' as id, 'Belum memilih metode' as name - UNION - SELECT M_MethodeSpermaID as id, M_MethodeSpermaName as name - FROM m_methodesperma - WHERE - M_MethodeSpermaIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $methodes = $this->db_smartone->query($sql)->result_array(); - $images = array(); - $sql = "SELECT Other_PreparasiSpermaImgID as xid, - Other_PreparasiSpermaImgType as type, - CONCAT('/one-media/one-image-nonlab/',Other_PreparasiSpermaImgNewName) as image_url - FROM t_orderdetail - JOIN other_preparasisperma_img ON Other_PreparasiSpermaImgT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND - Other_PreparasiSpermaImgIsActive = 'Y' - WHERE - T_OrderDetailID = {$id} AND - T_OrderDetailIsActive = 'Y' - GROUP BY Other_PreparasiSpermaImgID"; - //echo $sql; - $images = $this->db_smartone->query($sql)->result_array(); - - $rst = array('doctors'=>$doctors,'methodes'=>$methodes,'results'=>$rows,'images'=>$images); - $this->sys_ok(["records"=>$rst]); - } - else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - - function uploadimage_preparasi_sperma(){ - if (! $this->isLogin) { - $this->sys_error("Invalid Token"); - exit; - } - - $userid = $this->sys_user["M_UserID"]; - $data = []; - //print_r($_SERVER); - - $prm = $this->sys_input; - $orderid = $this->input->post('orderid'); - $type = $this->input->post('type'); - $labnumber = $this->input->post('labnumber'); - $sql = "UPDATE other_preparasisperma_img SET - Other_PreparasiSpermaImgIsActive = 'N', - Other_PreparasiSpermaImgUserID = {$userid} - WHERE - Other_PreparasiSpermaImgT_OrderHeaderID = {$orderid} AND - Other_PreparasiSpermaImgType = '{$type}'"; - //echo $sql; - $this->db_onedev->query($sql); - //$config['upload_path'] = 'assets/'; - - $path = '/home/one/project/one/one-media/one-image-nonlab/'; - //echo $path; - $config['upload_path'] = $path; - $config['allowed_types'] = 'jpg|jpeg|png|gif'; - - $config['max_size'] = '10000'; - $count = count($_FILES['files']['name']); - //echo $count; - $this->load->library('upload',$config); - - $error = []; - for($i=0;$i<$count;$i++){ - - - if(!empty($_FILES['files']['name'][$i])){ - - - - $_FILES['file']['name'] = $_FILES['files']['name'][$i]; - - $_FILES['file']['type'] = $_FILES['files']['type'][$i]; - - $_FILES['file']['tmp_name'] = $_FILES['files']['tmp_name'][$i]; - - $_FILES['file']['error'] = $_FILES['files']['error'][$i]; - - $_FILES['file']['size'] = $_FILES['files']['size'][$i]; - - - - $namex = $orderid.'-'.$labnumber.'-'.$this->generateRandomString(5); - //echo $namex; - - $config['file_name'] = $namex; - $this->upload->initialize($config); - //echo $config['file_name'] ; - - - - - - if($this->upload->do_upload('file')){ - - $uploadData = $this->upload->data(); - - $filename = $uploadData['file_name']; - //echo $filename; - - - $sql = "INSERT INTO other_preparasisperma_img ( - Other_PreparasiSpermaImgT_OrderHeaderID, - Other_PreparasiSpermaImgType, - Other_PreparasiSpermaImgOldName, - Other_PreparasiSpermaImgNewName, - Other_PreparasiSpermaImgCreated, - Other_PreparasiSpermaImgUserID - ) - VALUES( - {$orderid}, - '{$type}', - '{$_FILES['files']['name'][$i]}', - '{$filename}', - NOW(), - {$userid} - - )"; - //echo $sql; - $this->db_onedev->query($sql); - $xlast_id = $this->db_onedev->insert_id(); - $data['totalFiles'][] = array('xid' => $xlast_id ,'type'=>$type,'image_url' => '/one-media/one-image-nonlab/'.$filename); - - } - else{ - $error = array('error' => $this->upload->display_errors()); - } - - } - - - - } - - $result = array("total" =>count( $data['totalFiles']), "records" => $data['totalFiles'],'errors'=>$error); - $this->sys_ok($result); - } - - - function saveresult_preparasi_sperma() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = $inp['doctor']; - $orderdetail_id = $inp['orderdetailid']; - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - if($prm['xid'] == '0'){ - $sql = "INSERT INTO other_preparasisperma( - Other_PreparasiSpermaM_DoctorID, - Other_PreparasiSpermaT_OrderDetailID, - Other_PreparasiSpermaPreMotilitasA, - Other_PreparasiSpermaPreMotilitasB, - Other_PreparasiSpermaPreMotilitasC, - Other_PreparasiSpermaPreKonsentrasi, - Other_PreparasiSpermaPreKontaminan, - Other_PreparasiSpermaPostMotilitasA, - Other_PreparasiSpermaPostMotilitasB, - Other_PreparasiSpermaPostMotilitasC, - Other_PreparasiSpermaPostKonsentrasi, - Other_PreparasiSpermaPostKontaminan, - Other_PreparasiSpermaPreVolume, - Other_PreparasiSpermaPostVolume, - Other_PreparasiSpermaM_MethodeSpermaID, - Other_PreparasiSpermaNote, - Other_PreparasiSpermaUserID, - Other_PreparasiSpermaCreated - ) - VALUES( - {$doctor_id}, - {$orderdetail_id}, - '{$prm['Other_PreparasiSpermaPreMotilitasA']}', - '{$prm['Other_PreparasiSpermaPreMotilitasB']}', - '{$prm['Other_PreparasiSpermaPreMotilitasC']}', - '{$prm['Other_PreparasiSpermaPreKonsentrasi']}', - '{$prm['Other_PreparasiSpermaPreKontaminan']}', - '{$prm['Other_PreparasiSpermaPostMotilitasA']}', - '{$prm['Other_PreparasiSpermaPostMotilitasB']}', - '{$prm['Other_PreparasiSpermaPostMotilitasC']}', - '{$prm['Other_PreparasiSpermaPostKonsentrasi']}', - '{$prm['Other_PreparasiSpermaPostKontaminan']}', - '{$prm['Other_PreparasiSpermaPreVolume']}', - '{$prm['Other_PreparasiSpermaPostVolume']}', - '{$prm['Other_PreparasiSpermaM_MethodeSpermaID']}', - '{$prm['Other_PreparasiSpermaNote']}', - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } - else{ - $sql = "SELECT * FROM other_preparasisperma WHERE Other_PreparasiSpermaT_OrderDetailID = {$orderdetail_id} AND Other_PreparasiSpermaIsActive = 'Y'"; - $data_header = $this->db_smartone->query($sql)->row_array(); - $header_id = $data_header['Other_PreparasiSpermaID']; - $sql = "UPDATE other_preparasisperma SET - Other_PreparasiSpermaM_DoctorID = {$doctor_id}, - Other_PreparasiSpermaPreMotilitasA = '{$prm['Other_PreparasiSpermaPreMotilitasA']}', - Other_PreparasiSpermaPreMotilitasB = '{$prm['Other_PreparasiSpermaPreMotilitasB']}', - Other_PreparasiSpermaPreMotilitasC = '{$prm['Other_PreparasiSpermaPreMotilitasC']}', - Other_PreparasiSpermaPreKonsentrasi = '{$prm['Other_PreparasiSpermaPreKonsentrasi']}', - Other_PreparasiSpermaPreKontaminan = '{$prm['Other_PreparasiSpermaPreKontaminan']}', - Other_PreparasiSpermaPostMotilitasA = '{$prm['Other_PreparasiSpermaPostMotilitasA']}', - Other_PreparasiSpermaPostMotilitasB = '{$prm['Other_PreparasiSpermaPostMotilitasB']}', - Other_PreparasiSpermaPostMotilitasC = '{$prm['Other_PreparasiSpermaPostMotilitasC']}', - Other_PreparasiSpermaPostKonsentrasi = '{$prm['Other_PreparasiSpermaPostKonsentrasi']}', - Other_PreparasiSpermaPostKontaminan = '{$prm['Other_PreparasiSpermaPostKontaminan']}', - Other_PreparasiSpermaPreVolume = '{$prm['Other_PreparasiSpermaPreVolume']}', - Other_PreparasiSpermaPostVolume = '{$prm['Other_PreparasiSpermaPostVolume']}', - Other_PreparasiSpermaM_MethodeSpermaID = '{$prm['Other_PreparasiSpermaM_MethodeSpermaID']}', - Other_PreparasiSpermaNote = '{$prm['Other_PreparasiSpermaNote']}', - Other_PreparasiSpermaUserID = {$userid} - WHERE - Other_PreparasiSpermaID = {$header_id}"; - $this->db_smartone->query($sql); - } - - - $result = array("total" => 1, "records" => array(), "sql"=> ''); - $this->sys_ok($result); - exit; - } - - function getdnafragmentasiresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT other_dnafragmentasi.*, - Other_DnaFragmentasiID as xid, - Other_DnaFragmentasiT_OrderDetailID as orderdetail_id, - IFNULL(Other_DnaFragmentasiM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_DnaFragmentasiM_DoctorID) OR Other_DnaFragmentasiM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name, - IFNULL(Other_DnaFragmentasiOther_DnaFragmentasiMethodeID,0) as methode_id, - IFNULL(Other_DnaFragmentasiMethodeName,'') as methode_name, - Other_DnaFragmentasiHaloLuas as halo_luas, - Other_DnaFragmentasiHaloSedang as halo_sedang, - Other_DnaFragmentasiHaloSempit as halo_sempit, - Other_DnaFragmentasiTanpaHalo as tanpa_halo, - Other_DnaFragmentasiDFI as dfi, - Other_DnaFragmentasiKesimpulan as kesimpulan, - Other_DnaFragmentasiCatatan as catatan - FROM other_dnafragmentasi - LEFT JOIN m_doctor ON Other_DnaFragmentasiM_DoctorID = M_DoctorID - LEFT JOIN other_dnafragmentasimethode ON Other_DnaFragmentasiOther_DnaFragmentasiMethodeID = Other_DnaFragmentasiMethodeID - WHERE - Other_DnaFragmentasiT_OrderDetailID = {$id} AND Other_DnaFragmentasiIsActive = 'Y' - GROUP BY Other_DnaFragmentasiID - LIMIT 1"; - //echo $sql; - $query = $this->db_smartone->query($sql); - - if ($query) - { - $rows = $query->row_array(); - if(!$rows){ - $rows = array( - 'xid' => 0, - 'orderdetail_id' =>$id, - 'doctor_id' => 0, - 'doctor_name' => '', - 'methode_id' => 0, - 'methode_name' => '', - 'halo_luas' => '', - 'halo_sedang' => '', - 'tanpa_halo' => '', - 'dfi' => '', - 'kesimpulan' => '', - 'catatan' => '' - ); - } - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID - WHERE - M_DoctorSONat_SubGroupID = 4 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - - $sql = " - SELECT '0' as id, 'Belum memilih metode' as name - UNION - SELECT Other_DnaFragmentasiMethodeID as id, Other_DnaFragmentasiMethodeName as name - FROM other_dnafragmentasimethode - WHERE - Other_DnaFragmentasiMethodeIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $methodes = $this->db_smartone->query($sql)->result_array(); - - - $rst = array('doctors'=>$doctors,'methodes'=>$methodes,'results'=>$rows); - $this->sys_ok(["records"=>$rst]); - } - else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - function saveresult_dnafragmentasi() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = $inp['doctor']['id']; - $methode_id = $inp['methode']['id']; - $orderdetail_id = $inp['results']['orderdetail_id']; - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - if(intval($prm['xid']) == 0){ - $sql = "INSERT INTO other_dnafragmentasi( - Other_DnaFragmentasiT_OrderDetailID, - Other_DnaFragmentasiM_DoctorID, - Other_DnaFragmentasiOther_DnaFragmentasiMethodeID, - Other_DnaFragmentasiHaloLuas, - Other_DnaFragmentasiHaloSedang, - Other_DnaFragmentasiHaloSempit, - Other_DnaFragmentasiTanpaHalo, - Other_DnaFragmentasiDFI, - Other_DnaFragmentasiKesimpulan, - Other_DnaFragmentasiCatatan, - Other_DnaFragmentasiUserID, - Other_DnaFragmentasiLastUpdated - ) - VALUES( - {$orderdetail_id}, - {$doctor_id}, - {$methode_id}, - '{$prm['halo_luas']}', - '{$prm['halo_sedang']}', - '{$prm['halo_sempit']}', - '{$prm['tanpa_halo']}', - '{$prm['dfi']}', - '{$prm['kesimpulan']}', - '{$prm['catatan']}', - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } - else{ - $sql = "UPDATE other_dnafragmentasi SET - Other_DnaFragmentasiT_OrderDetailID = {$orderdetail_id}, - Other_DnaFragmentasiM_DoctorID = {$doctor_id}, - Other_DnaFragmentasiOther_DnaFragmentasiMethodeID = '{$methode_id}', - Other_DnaFragmentasiHaloLuas = '{$prm['halo_luas']}', - Other_DnaFragmentasiHaloSedang = '{$prm['halo_sedang']}', - Other_DnaFragmentasiHaloSempit = '{$prm['halo_sempit']}', - Other_DnaFragmentasiTanpaHalo = '{$prm['tanpa_halo']}', - Other_DnaFragmentasiDFI = '{$prm['dfi']}', - Other_DnaFragmentasiKesimpulan = '{$prm['kesimpulan']}', - Other_DnaFragmentasiCatatan = '{$prm['catatan']}', - Other_DnaFragmentasiLastUpdated = NOW(), - Other_DnaFragmentasiUserID = {$userid} - WHERE - Other_DnaFragmentasiID = {$prm['xid']}"; - //echo $sql; - $this->db_smartone->query($sql); - } - - - $result = array("total" => 1, "records" => array(), "sql"=> ''); - $this->sys_ok($result); - exit; - } - - -} - +db_smartone = $this->load->database("onedev", true); + $this->load->helper(array('form', 'url')); + } + function getMethodeID($natTestID) { + $sql = "select M_MethodePriorityNat_MethodeID MethodeID, Nat_MethodeName + from + m_methode_priority + join nat_methode on Nat_MethodeID = M_MethodePriorityNat_MethodeID + and Nat_MethodeIsActive = 'Y' + join m_instrumentmethode on M_InstrumentMethodeNat_MethodeID = Nat_MethodeID and M_InstrumentMethodeIsActive = 'Y' + join nat_instrument on M_InstrumentMethodeNat_InstrumentID = Nat_InstrumentID + and Nat_InstrumentIsActive ='Y' + where M_MethodePriorityIsActive = 'Y' + and M_MethodePriorityNat_TestID = $natTestID + and M_MethodePriorityM_DayOfWeekID = dayofweek(now()) + order by M_MethodePriorityNumber desc + limit 0,1 "; + $qry = $this->db->query($sql); + if ($qry) { + $rows = $qry->result_array(); + if (count($rows) > 0 ) return array($rows[0]["MethodeID"],$rows[0]["Nat_MethodeName"]); + } + //2nd + $sql= "select + M_InstrumentMethodeNat_MethodeID MethodeID, Nat_MethodeName + from m_instrumentmethode + join nat_methode on M_InstrumentMethodeNat_MethodeID = Nat_MethodeID + and Nat_MethodeIsActive = 'Y' + join nat_instrument on M_InstrumentMethodeNat_InstrumentID = Nat_InstrumentID + and Nat_InstrumentIsActive ='Y' + where M_InstrumentMethodeNat_TestID = $natTestID + and M_InstrumentMethodeIsActive = 'Y' + order by M_InstrumentMethodePriority desc + limit 0,1"; + $qry = $this->db->query($sql); + if ($qry) { + $rows = $qry->result_array(); + if (count($rows) > 0 ) return array($rows[0]["MethodeID"],$rows[0]["Nat_MethodeName"]); + } + // + $sql = "select Nat_NormalValueNat_MethodeID MethodeID, Nat_MethodeName + from + nat_normalvalue + join nat_methode on Nat_NormalValueNat_MethodeID = Nat_MethodeID + and Nat_MethodeIsActive = 'Y' + where Nat_NormalValueNat_TestID = $natTestID + and Nat_NormalValueIsActive = 'Y' + order by Nat_NormalValueID + limit 0,1"; + $qry = $this->db->query($sql); + if ($qry) { + $rows = $qry->result_array(); + if (count($rows) > 0 ) return array($rows[0]["MethodeID"],$rows[0]["Nat_MethodeName"]); + } + return array(0,""); + } + function get_normal_value($methodeID, $natTestID, $sexID, $ageInDay ) { + $this->load->library('ibl_sampling_normal'); + return $this->ibl_sampling_normal->get_normal_value_id($methodeID, $natTestID, $sexID, $ageInDay); + } + return 0; + } + function fn_fix_normal($order_id) { + $sql = "select + T_OrderDetailID, M_PatientM_SexID, fn_global_age_count_day(M_PatientDOB, date(T_OrderHeaderDate)) Dob , + T_TestNat_TestID + from t_orderheader + join m_patient on T_OrderHeaderID = $order_id and T_OrderHeaderM_PatientID = M_PatientID + join t_orderdetail on T_OrderDetailT_OrderHeaderID = T_OrderHeaderID + and T_OrderDetailIsACtive = 'Y' + and ( T_OrderDetailNat_NormalValueID is null or T_OrderDetailNat_NormalValueID = 0 ) + join t_test on T_OrderDetailT_TestID = T_TestID and T_TestIsResult = 'Y' "; + $qry = $this->db->query($sql); + if(! $qry) { + return; + } + $rows = $qry->result_array(); + if(count($rows) == 0 ) return; + $sql_u = "update t_orderdetail + join nat_normalvalue on T_OrderDetailID = ? and Nat_NormalValueID = ? + set + T_OrderDetailNat_NormalValueID = Nat_NormalValueID, + T_OrderDetailNormalValueNote = Nat_NormalValueNote, + T_OrderDetailNormalValueDescription = Nat_NormalValueDescription, + T_OrderDetailMinValue = Nat_NormalValueMinValue, + T_OrderDetailMaxValue = Nat_NormalValueMaxValue, + T_OrderDetailMinValueInclusive = Nat_NormalValueMinValueInclusive, + T_OrderDetailMaxValueInclusive = Nat_NormalValueMaxValueInclusive, + T_OrderDetailNat_MethodeID = ?, + T_OrderdetailNat_MethodeName =?"; + + foreach($rows as $r) { + $T_OrderDetailID = $r["T_OrderDetailID"]; + $sexID = $r["M_PatientM_SexID"]; + $ageInDay = $r["Dob"]; + $natTestID = $r["T_TestNat_TestID"]; + list($methodeID,$methodeName) = $this->getMethodeID($natTestID); + if ($methodeID == 0 ) continue; + $normalValueID = $this->get_normal_value($methodeID, $natTestID, $sexID, $ageInDay); + if ($normalValueID == 0) return; + $this->db->query($sql_u, array($T_OrderDetailID, $normalValueID, $methodeID, $methodeName)); + } + } + function update_order_sample($targetID, $sourceID) { + $sql = "update t_ordersample target + join t_ordersample source on + target.T_OrderSampleID = ? + and target.T_OrderSampleWorklistReceive = 'N' + and source.T_OrderSampleID = ? + set + target.T_OrderSampleSampling = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSampling, source.T_OrderSampleSampling), + target.T_OrderSampleSamplingDate = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingDate, source.T_OrderSampleSamplingDate), + target.T_OrderSampleSamplingTime = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingTime, source.T_OrderSampleSamplingTime), + target.T_OrderSampleSamplingUserID = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingUserID, source.T_OrderSampleSamplingUserID), + + target.T_OrderSampleReceive = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceive, source.T_OrderSampleReceive), + target.T_OrderSampleReceiveDate = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveDate, source.T_OrderSampleReceiveDate), + target.T_OrderSampleReceiveTime = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveTime, source.T_OrderSampleReceiveTime), + target.T_OrderSampleReceiveUserID = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveUserID, source.T_OrderSampleReceiveUserID), + + target.T_OrderSampleVerification = if(target.T_OrderSampleVerification='Y',target.T_OrderSampleVerification, source.T_OrderSampleVerification), + target.T_OrderSampleVerificationDate =if(target.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationDate, source.T_OrderSampleVerificationDate), + target.T_OrderSampleVerificationTime =if(source.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationTime, source.T_OrderSampleVerificationTime), + target.T_OrderSampleVerificationUserID =if(source.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationUserID, source.T_OrderSampleVerificationUserID), + + target.T_OrderSampleProcessing = if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessing, source.T_OrderSampleProcessing), + target.T_OrderSampleProcessingDate= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingDate, source.T_OrderSampleProcessingDate), + target.T_OrderSampleProcessingTime= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingTime, source.T_OrderSampleProcessingTime), + target.T_OrderSampleProcessingUserID= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingUserID, source.T_OrderSampleProcessingUserID), + + target.T_OrderSampleReceiveHandling =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandling, source.T_OrderSampleReceiveHandling ), + target.T_OrderSampleReceiveHandlingDate =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingDate, source.T_OrderSampleReceiveHandlingDate), + target.T_OrderSampleReceiveHandlingTime =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingTime, source.T_OrderSampleReceiveHandlingTime), + target.T_OrderSampleReceiveHandlingUserID =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingUserID, source.T_OrderSampleReceiveHandlingUserID), + + target.T_OrderSampleHandling = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandling, source.T_OrderSampleHandling), + target.T_OrderSampleHandlingDate = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingDate, source.T_OrderSampleHandlingDate), + target.T_OrderSampleHandlingTime = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingTime, source.T_OrderSampleHandlingTime), + target.T_OrderSampleHandlingUserID = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingUserID, source.T_OrderSampleHandlingUserID), + + target.T_OrderSampleWorklistReceive = source.T_OrderSampleWorklistReceive, + target.T_OrderSampleWorklistReceiveDatetime = source.T_OrderSampleWorklistReceiveDateTime, + target.T_OrderSampleWorklistReceiveUserID = source.T_OrderSampleWorklistReceiveUserID + "; + $qry = $this->db->query($sql,array($targetID,$sourceID)); + if(! $qry ) { + echo json_encode(array( "status" => "ERR" , "message" => print_r($this->db->error(),true))); + exit; + } + } + function fix_sample_serum($headerID) { + //cari t_ordersample yg belum worklist receive dengan code 017% + $sql = "select T_OrderSampleID + from t_ordersample + join t_sampletype on + T_OrderSampleT_OrderHeaderID = ? + and T_OrderSampleWorklistReceive = 'N' + and T_OrderSampleIsActive = 'Y' + and T_OrderSampleT_SampleTypeID = T_SampletypeID + and T_SampleTypeCode like '017%' + "; + $qry = $this->db->query($sql, array($headerID)); + if(!$qry) { + echo json_encode(array( "status" => "ERR" , "message" => print_r($this->db->error(),true))); + exit; + } + $rows = $qry->result_array(); + if (count($rows) == 0 ) return; + //cari T_OrderSample yang sudah di receive yg terakhir + $sql = "select T_OrderSampleID + from t_ordersample + join t_sampletype on + T_OrderSampleT_OrderHeaderID = ? + and T_OrderSampleWorklistReceive = 'Y' + and T_OrderSampleIsActive = 'Y' + and T_OrderSampleT_SampleTypeID = T_SampletypeID + and T_SampleTypeCode like '017%' + order by T_OrderSampleWorklistReceiveDatetime desc + limit 0,1 + "; + $qry = $this->db->query($sql, array($headerID)); + if(!$qry) { + echo json_encode(array( "status" => "ERR" , "message" => print_r($this->db->error(),true))); + exit; + } + $rcv_rows = $qry->result_array(); + if (count($rcv_rows) == 0 ) return; + + //print_r($rows); + //print_r($rcv_rows); + $rcv_T_OrderSampleID = $rcv_rows[0]["T_OrderSampleID"]; + //ada yg belum di receive + foreach($rows as $r) { + $T_OrderSampleID = $r["T_OrderSampleID"]; + $this->update_order_sample($T_OrderSampleID,$rcv_T_OrderSampleID); + } + } + public function search() + { + $prm = $this->sys_input; + $max_rst = 99; + + $id = $prm["order_id"]; + if ($id > 0 ) { + $this->fix_sample_serum($id); + $this->fn_fix_normal($id); + } + $lang = $this->lang_default_code; + $lang_id = isset($prm['lang_id']) ? $prm['lang_id'] : '0'; + + if ($lang_id != 0) + { + $l = $this->db_smartone->where("Nat_LangID", $lang_id)->get("nat_lang")->row(); + $lang = $l->Nat_LangCode; + } + + //tambahan fajri + $sql = " UPDATE t_orderdetail + JOIN t_test ON T_OrderDetailT_TestID = T_TestID + SET T_OrderDetailT_TestIsResult = T_TestIsResult + WHERE + T_OrderDetailT_OrderHeaderID = {$id} AND + T_OrderDetailT_TestIsResult = '' AND + T_OrderDetailIsActive = 'Y'"; + $this->db_smartone->query($sql); + + $tot_count = 0; + $lq = ""; + $group_id = 0; + if (isset($prm['group_id'])) + $group_id = $prm['group_id']; + + if ($group_id != 0) + { + $sql = "select distinct T_WorklistDetailNat_TestID Nat_TestID + from t_worklistdetailv2 + where T_WorklistDetailT_WorklistID = {$group_id}"; + $qry = $this->db_smartone->query($sql); + $rows = $qry->result_array(); + $nat_test_ids = "0"; + foreach($rows as $r) { + $nat_test_ids .= ", " . $r["Nat_TestID"]; + } + $q_group = " ( $nat_test_ids ) "; + + $sql = " + SELECT a1.*, cOUNT(a2.T_OrderDetailID) level + FROM ( + SELECT IFNULL(y.T_OrderDetailT_TestID, x.T_OrderDetailT_TestID) t_testid, + IFNULL(y.T_OrderDetailT_TestName, y.T_OrderDetailT_TestName) t_testname, + y.T_OrderDetailResult result, y.T_OrderDetailResult result_old, y.T_OrderDetailNote note, y.T_OrderDetailNote note_old, + y.T_OrderDetailID id, + y.T_OrderDetailT_TestIsResult is_result, a.T_TestIsQuantitative is_quantitative, + y.T_OrderDetailResultFlag result_flag, + y.T_OrderDetailNat_NormalValueID normal_id, + y.T_OrderDetailNormalValueNote normal_note, y.T_OrderDetailNat_UnitName unit_name, + y.T_OrderdetailNat_MethodeID methode_id, y.T_OrderdetailNat_MethodeName methode_name, + a.T_TestNat_TestID nattest_id, a.T_TestID tx_id, count(T_ResultInstrumentID) as result_instrument_n, + y.T_OrderDetailVerification, T_OrderSampleReceive sample_receive, + T_OrderSampleProcessing sample_processing, T_OrderSampleWorklistReceive sample_worklist_receive, + IF(T_OrderDetailAddOnPreAnalytic = 'Y', T_OrderDetailAddOnPreAnalytic, PreAnalyticIsOk) pre_analytic, + T_OrderDetailAddOnPreAnalytic, + T_OrderHeaderID order_id, y.T_OrderDetailT_TestSasCode test_sas_code, + tx.T_TestSasCode, + T_OrderDetailAddOnResample `resample`, T_OrderDetailAddOnResampleStatus resample_status, + T_OrderDetailAddOnRef ref, y.T_OrderDetailVerification verification, y.T_OrderDetailValidation validation, + T_OrderPromiseDateTime, Group_ResultName as ResultGroupName + FROM t_orderdetail x + left join t_orderpromise on x.T_OrderDetailT_OrderPromiseID = T_OrderPromiseID + JOIN t_test tx ON x.T_OrderDetailT_TestID = T_TestID + JOIN t_test tcheck on tcheck.T_TestNat_TestID in {$q_group} + and ( tx.T_TestID = tcheck.T_TestID or tx.T_TestSasCode like concat(tcheck.T_TestSasCode,'%')) + LEFT JOIN group_resultdetail ON Group_ResultDetailT_TestID = x.T_OrderDetailT_TestID AND Group_ResultDetailIsActive = 'Y' + LEFT JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND Group_ResultFlagNonLab = 'N' + LEFT JOIN t_orderdetail y ON x.T_OrderDetailT_TestSasCode LIKE CONCAT(y.T_OrderDetailT_TestSasCode, '%') + AND x.T_OrderDetailT_OrderHeaderID = y.T_OrderDetailT_OrderHeaderID + AND y.T_OrderDetailIsActive = 'Y' + LEFT JOIN t_orderdetailaddon ON x.T_OrderDetailID = T_OrderDetailAddOnT_OrderDetailID + JOIN t_orderheader ON y.T_OrderDetailT_OrderHeaderID = T_OrderHeaderID + LEFT JOIN t_test a ON y.T_OrderDetailT_TestID = a.T_TestID + AND a.T_TestIsNonLab = '' + LEFT JOIN (SELECT T_OrderSampleT_SampleTypeID, T_OrderSampleReceive, T_OrderSampleProcessing, T_OrderSampleWorklistReceive + FROM t_ordersample WHERE T_OrderSampleT_OrderHeaderID = {$id} + AND T_OrderSampleIsactive = 'Y' + GROUP BY T_OrderSampleT_SampleTypeID) os ON a.T_TestT_SampleTypeID = os.T_OrderSampleT_SampleTypeID + or os.T_OrderSampleT_SampleTypeID = fn_sampletype_from_local(a.T_TestNat_TestID) + + LEFT JOIN t_resultinstrument ON T_ResultInstrumentT_OrderDetailID = x.T_OrderDetailID + LEFT JOIN pre_analytic ON PreAnalyticNat_TestID = a.T_TestNat_TestID AND PreAnalyticDate = date(now()) and PreAnalyticIsActive = 'Y' + WHERE x.T_OrderDetailT_OrderHeaderID = {$id} + AND x.T_OrderDetailIsActive = 'Y' + GROUP BY y.T_OrderDetailT_TestID + ORDER BY y.T_OrderDetailT_TestSasCode ASC + ) a1 + + LEFT JOIN t_orderdetail a2 ON a2.T_OrderDetailT_OrderHeaderID = a1.order_id + AND a2.T_OrderDetailIsActive = 'Y' + AND a1.test_sas_code LIKE CONCAT(a2.T_OrderDetailT_testSasCode, '%') + GROUP BY a1.t_testid + order by a1.test_sas_code +"; + $query = $this->db_smartone->query($sql); + $lq = $this->db_smartone->last_query(); + } + else + { + $sql = " + SELECT a1.*, cOUNT(a2.T_OrderDetailID) level + FROM ( + SELECT IFNULL(y.T_OrderDetailT_TestID, x.T_OrderDetailT_TestID) t_testid, + IFNULL(y.T_OrderDetailT_TestName, y.T_OrderDetailT_TestName) t_testname, + y.T_OrderDetailResult result, y.T_OrderDetailResult result_old, y.T_OrderDetailNote note, y.T_OrderDetailNote note_old, + y.T_OrderDetailID id, + y.T_OrderDetailT_TestIsResult is_result, a.T_TestIsQuantitative is_quantitative, + y.T_OrderDetailResultFlag result_flag, + y.T_OrderDetailNat_NormalValueID normal_id, + y.T_OrderDetailNormalValueNote normal_note, y.T_OrderDetailNat_UnitName unit_name, + y.T_OrderdetailNat_MethodeID methode_id, y.T_OrderdetailNat_MethodeName methode_name, + a.T_TestNat_TestID nattest_id, a.T_TestID tx_id, count(T_ResultInstrumentID) as result_instrument_n, + y.T_OrderDetailVerification, T_OrderSampleReceive sample_receive, + T_OrderSampleProcessing sample_processing, T_OrderSampleWorklistReceive sample_worklist_receive, + IF(T_OrderDetailAddOnPreAnalytic = 'Y', T_OrderDetailAddOnPreAnalytic, PreAnalyticIsOk) pre_analytic, + T_OrderDetailAddOnPreAnalytic, + T_OrderHeaderID order_id, y.T_OrderDetailT_TestSasCode test_sas_code, + tx.T_TestSasCode, + T_OrderDetailAddOnResample `resample`, T_OrderDetailAddOnResampleStatus resample_status, + T_OrderDetailAddOnRef ref, y.T_OrderDetailVerification verification, y.T_OrderDetailValidation validation, + T_OrderPromiseDateTime , Group_ResultName as ResultGroupName + FROM t_orderdetail x + left join t_orderpromise on x.T_OrderDetailT_OrderPromiseID = T_OrderPromiseID + JOIN t_test tx ON x.T_OrderDetailT_TestID = T_TestID + LEFT JOIN group_resultdetail ON Group_ResultDetailT_TestID = x.T_OrderDetailT_TestID AND Group_ResultDetailIsActive = 'Y' + LEFT JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND Group_ResultFlagNonLab = 'N' + LEFT JOIN t_orderdetail y ON x.T_OrderDetailT_TestSasCode LIKE CONCAT(y.T_OrderDetailT_TestSasCode, '%') + AND x.T_OrderDetailT_OrderHeaderID = y.T_OrderDetailT_OrderHeaderID + AND y.T_OrderDetailIsActive = 'Y' + + LEFT JOIN t_orderdetailaddon ON x.T_OrderDetailID = T_OrderDetailAddOnT_OrderDetailID + + JOIN t_orderheader ON y.T_OrderDetailT_OrderHeaderID = T_OrderHeaderID + LEFT JOIN t_test a ON y.T_OrderDetailT_TestID = a.T_TestID + AND a.T_TestIsNonLab = '' + LEFT JOIN (SELECT T_OrderSampleT_SampleTypeID, T_OrderSampleReceive, T_OrderSampleProcessing, T_OrderSampleWorklistReceive + FROM t_ordersample WHERE T_OrderSampleT_OrderHeaderID = {$id} + AND T_OrderSampleIsactive = 'Y' + GROUP BY T_OrderSampleT_SampleTypeID) os ON a.T_TestT_SampleTypeID = os.T_OrderSampleT_SampleTypeID + or os.T_OrderSampleT_SampleTypeID = fn_sampletype_from_local(a.T_TestNat_TestID) + + LEFT JOIN t_resultinstrument ON T_ResultInstrumentT_OrderDetailID = x.T_OrderDetailID + LEFT JOIN pre_analytic ON PreAnalyticNat_TestID = a.T_TestNat_TestID AND PreAnalyticDate = date(now()) and PreAnalyticIsActive = 'Y' + WHERE x.T_OrderDetailT_OrderHeaderID = {$id} + AND x.T_OrderDetailIsActive = 'Y' + GROUP BY y.T_OrderDetailT_TestID + ORDER BY y.T_OrderDetailT_TestSasCode ASC + ) a1 + + LEFT JOIN t_orderdetail a2 ON a2.T_OrderDetailT_OrderHeaderID = a1.order_id + AND a2.T_OrderDetailIsActive = 'Y' + AND a1.test_sas_code LIKE CONCAT(a2.T_OrderDetailT_testSasCode, '%') + GROUP BY a1.t_testid + order by a1.test_sas_code +"; +//echo $sql; + $query = $this->db_smartone->query($sql); + $lq = $this->db_smartone->last_query(); + } + // file_put_contents("/xtmp/re-query.sql",$lq); + + if ($query) { + $rst = []; + $rows = $query->result_array(); + + foreach($rows as $k => $v) + { + + if ($v['is_result'] == "Y" && $v['is_quantitative'] == "N") + { + $v['template'] = []; + $x = $this->db_smartone->query("CALL sp_master_resulttemplate_get('{$v['t_testid']}')"); + $this->clean_mysqli_connection($this->db_smartone->conn_id); + if ($x) + $v['template'] = $x->result_array(); + } + + // IF Rujukan, by pas Pre Analytik + if ($v['ref'] == 'Y') + $v['pre_analytic'] = 'Y'; + if ($v["id"] == "885455" ) + { + //sipe workaround + //$v["sample_receive"] = "Y"; + $v["sample_worklist_receive"] = "Y"; + } + $rst[] = $v; + } + + $result = array("total" => $tot_count, "records" => $rst, "total_display" => sizeof($rows), "q" => $lq); + $this->sys_ok($result); + } + else { + $this->sys_error_db("RE Px rows", $this->db_smartone); + exit; + } + } + + public function save() + { + $prm = $this->sys_input; + $data = json_decode($prm["data"]); + $lang = $this->lang_default_code; + $lang_id = isset($prm['lang_id']) ? $prm['lang_id'] : '0'; + + if ($lang_id != 0) + { + $l = $this->db_smartone->where("Nat_LangID", $lang_id)->get("nat_lang")->row(); + $lang = $l->Nat_LangCode; + } + + $sql_norm = "select T_OrderDetailMinValue, T_OrderDetailMaxValue, + T_OrderDetailMinValueInclusive, T_OrderDetailMaxValueInclusive, + Nat_TestFlagLow, Nat_TestFlagHigh + from t_orderdetail + join t_test on T_OrderDetailT_TestID = T_TestID + join nat_test on T_TestNat_TestID = Nat_TestID and T_TestIsActive = 'Y' + where T_OrderDetailID = ? "; + + $ids = []; + foreach ($data as $k => $v) + { + if ( $v->resultInstrumentID > 0 ) { + $sql_i = "select T_ResultInstrumentNat_NormalValueID normalValueID + from t_resultinstrument + where T_ResultInstrumentID = ?"; + $qry_i = $this->db_smartone->query($sql_i, array($v->resultInstrumentID)); + if ($qry_i) { + $rows_i = $qry_i->result_array(); + + if (count($rows_i) > 0 ) { + $sql_iu = "update t_orderdetail, nat_normalvalue , nat_methode + set T_OrderDetailMinValue = Nat_NormalValueMinValue, + T_OrderDetailMinValueInclusive = Nat_NormalValueMinValueInclusive, + T_OrderDetailMaxValue = Nat_NormalValueMaxValue , + T_OrderDetailMaxValueInclusive = Nat_NormalValueMaxValueInclusive, + T_OrderDetailNormalValueNote = Nat_NormalValueNote, + T_OrderDetailNormalValueDescription = Nat_NormalValueDescription, + T_OrderDetailNat_NormalValueID = Nat_NormalValueID, + T_OrderDetailNat_MethodeID = Nat_NormalValueNat_MethodeID, + T_OrderDetailNat_MethodeName = Nat_MethodeName + where T_OrderDetailID = ? and Nat_NormalValueID = ? + and Nat_NormalValueNat_MethodeID = Nat_MethodeID + "; + $this->db_smartone->query($sql_iu, array($v->id, $rows_i[0]["normalValueID"])); + //file_put_contents("/xtmp/update-nilai-normal", $this->db_smartone->last_query() . "\n", FILE_APPEND); + } + } + } + $y = $this->db_smartone->query("SELECT fn_process_sample_handling_perfect('{$v->order_id}', '{$v->test_id}') c") + ->row(); + $req_status = $y->c; + $qry_norm = $this->db_smartone->query($sql_norm,$v->id); + $result_flag = ""; + if ($qry_norm) { + $rows_norm = $qry_norm->result_array(); + if (count($rows_norm) > 0 ) { + $r = $rows_norm[0]; + if (is_numeric($v->result)) { + + if ( $r["T_OrderDetailMinValueInclusive"] == "Y" && $v->result < $r["T_OrderDetailMinValue"] ) { + $result_flag = $r["Nat_TestFlagLow"]; + } + if ( $r["T_OrderDetailMinValueInclusive"] == "N" && $v->result <= $r["T_OrderDetailMinValue"] ) { + $result_flag = $r["Nat_TestFlagLow"]; + } + if ( $r["T_OrderDetailMaxValueInclusive"] == "Y" && $v->result > $r["T_OrderDetailMaxValue"] ) { + $result_flag = $r["Nat_TestFlagHigh"]; + } + if ( $r["T_OrderDetailMaxValueInclusive"] == "N" && $v->result >= $r["T_OrderDetailMaxValue"] ) { + $result_flag = $r["Nat_TestFlagHigh"]; + } + } + } + } + if ($lang == $this->lang_default_code) + { + $this->db_smartone->set('T_OrderDetailResult', $v->result) + ->set('T_OrderDetailResultFlag', $result_flag) + ->set('T_OrderDetailNote', $v->note) + ->set('T_OrderDetailReqStatus', $req_status) + ->where('T_OrderDetailID', $v->id) + ->update('t_orderdetail'); + } + else + { + $this->db_smartone->set('T_OrderDetailLangResult', $v->result) + ->set('T_OrderDetailLangNote', $v->note) + ->where('T_OrderDetailLangID', $v->id) + ->update('t_orderdetaillang'); + } + + $ids[] = $v->id; + } + + // LOG Process + $order = $this->db_smartone->select('T_OrderDetailT_OrderHeaderID id, T_OrderHeaderLabNumber lab_number', false) + ->join('t_orderheader', 'T_OrderHeaderID = T_OrderDetailT_OrderHeaderID') + ->where('T_OrderDetailID', $data[0]->id) + ->get('t_orderdetail') + ->row(); + + $dblog = $this->load->database("onelog", true); + $dblog->set('Log_ProcessCode', 'PROCESS.Result.Entry') + ->set('Log_ProcessOrderID', $order->id) + ->set('Log_ProcessOrderNumber', $order->lab_number) + ->set('Log_ProcessJson', json_encode($data)) + ->set('Log_ProcessUserID', $this->sys_user['M_UserID']) + ->insert('log_process'); + // END OF Log Process + //auto calculation + $this->load->library("Resultcalc"); + $rows = $this->resultcalc->auto($order->id); + + try { + foreach($ids as $id ) { + $this->db_smartone->query("call sp_set_normal_value_flag($id)"); + $this->clean_mysqli_connection($this->db_smartone->conn_id); + } + } catch(Exception $e) { + } + + $this->sys_ok($ids); + } + + public function save_template() + { + $prm = $this->sys_input; + + $n = $this->db_smartone->select("COUNT(T_ResultTemplateID) n") + ->where("T_ResultTemplateT_TestID", $prm['test_id']) + ->where("T_ResultTemplateIsActive", "Y") + ->where("T_ResultTemplateValue", $prm['value']) + ->get('t_resulttemplate') + ->row(); + if ($n->n > 0) + { + $this->sys_error_db("Insert Result Template", $this->db_smartone); + return; + } + + $r = $this->db_smartone->set("T_ResultTemplateT_TestID", $prm['test_id']) + ->set("T_ResultTemplateValue", $prm['value']) + ->insert('t_resulttemplate'); + if ($r) + { + $template = []; + $x = $this->db_smartone->query("CALL sp_master_resulttemplate_get('{$prm['test_id']}')"); + $this->clean_mysqli_connection($this->db_smartone->conn_id); + if ($x) + $template = $x->result_array(); + + $this->sys_ok($template); + } + } + + public function export() + { + $prm = $this->sys_input; + + $sql = "CALL sp_process_result_lang(?, ?, ?, ?)"; + $query = $this->db_smartone->query($sql, [$prm['order_id'], $prm['lang_id'], $prm['is_si'], $this->sys_user['M_UserID']]); + if ($query) + { + $r = $query->row(); + if ($r->status == "OK") + { + $this->sys_ok($r->data); + return; + } + + $this->sys_error_db("Message : " . $r->message, $this->db_smartone); + } + else + { + $this->sys_error_db("Lang Result", $this->db_smartone); + return; + } + } + + public function search_group() + { + $prm = $this->sys_input; + $max_rst = 100; + + // QUERY TOTAL + $sql = "select count(*) total + from t_worklist + where T_WorklistIsActive = 'Y' + order by T_WorklistName ASC"; + $query = $this->db_smartone->query($sql); + + if ($query) { + $tot_count = $query->result_array()[0]["total"]; + } + else { + $this->sys_error_db("worklist count", $this->db_smartone); + exit; + } + + $sql = "select T_WorklistID group_id, T_WorklistName group_name + from t_worklist + where T_WorklistIsActive = 'Y' + order by T_WorklistName ASC + limit 0, {$max_rst}"; + $query = $this->db_smartone->query($sql); + + if ($query) { + $rows = $query->result_array(); + foreach ($rows as $k => $v) + $rows[$k]['data'] = json_decode($v['data']); + $result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows), "q" => $this->db_smartone->last_query()); + $this->sys_ok($result); + } + else { + $this->sys_error_db("worklist rows", $this->db_smartone); + exit; + } + } + + public function search_rerun() + { + $prm = $this->sys_input; + $id = $prm["detail_id"]; + + $sql = "CALL sp_process_result_rerun(?)"; + $query = $this->db_smartone->query($sql, [$id]); + + if ($query) + { + $rows = $query->result_array(); + $this->sys_ok(["records"=>$rows]); + } + else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + + + function getdoctorsfna() + { + $prm = $this->sys_input; + // $id = $prm["id"]; + + $sql = " SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY M_DoctorName ASC"; + //echo $sql; + $query = $this->db_smartone->query($sql); + + if ($query) + { + $rows = $query->result_array(); + $this->sys_ok(["records"=>$rows]); + } + else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + function getfnaresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT Other_FNADetailsID as xid, + Other_FNAT_OrderDetailID as orderdetail_id, + Other_FNADetailsCode as code, + Other_FNADetailsLabel as label, + Other_FNADetailsResult as result, + IFNULL(Other_FNAM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_FNAM_DoctorID) OR Other_FNAM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_fna + JOIN other_fnadetails ON Other_FNADetailsOther_FNAID = Other_FNAID AND Other_FNADetailsIsActive = 'Y' + LEFT JOIN m_doctor ON Other_FNAM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_FNAT_OrderDetailID = {$id} AND Other_FNAIsActive = 'Y' + GROUP BY Other_FNADetailsID + ORDER BY Other_FNADetailsCode ASC"; + $query = $this->db_smartone->query($sql); + + if ($query) + { + $rows = $query->result_array(); + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $images = array(); + $sql = "SELECT So_ImageUploadID as xid, + CONCAT('/one-media/one-image-nonlab/',So_ImageUploadNewName) as image_url + FROM t_orderdetail + JOIN so_imageupload ON So_ImageUploadT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND + So_ImageUploadIsActive = 'Y' + WHERE + T_OrderDetailID = {$id} AND + T_OrderDetailIsActive = 'Y' + GROUP BY So_ImageUploadID"; + $images = $this->db_smartone->query($sql)->result_array(); + + $rst = array('doctors'=>$doctors,'results'=>$rows,'images'=>$images); + $this->sys_ok(["records"=>$rst]); + } + else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + + function uploadimage(){ + if (! $this->isLogin) { + $this->sys_error("Invalid Token"); + exit; + } + + $userid = $this->sys_user["M_UserID"]; + $data = []; + //print_r($_SERVER); + + $prm = $this->sys_input; + $orderid = $this->input->post('orderid'); + $labnumber = $this->input->post('labnumber'); + $sql = "UPDATE so_imageupload SET + So_ImageUploadIsActive = 'N', + So_ImageUploadUserID = {$userid} + WHERE + So_ImageUploadT_OrderHeaderID = {$orderid}"; + //echo $sql; + $this->db_onedev->query($sql); + //$config['upload_path'] = 'assets/'; + + $path = '/home/one/project/one/one-media/one-image-nonlab/'; + //echo $path; + $config['upload_path'] = $path; + $config['allowed_types'] = 'jpg|jpeg|png|gif'; + + $config['max_size'] = '10000'; + $count = count($_FILES['files']['name']); + //echo $count; + $this->load->library('upload',$config); + + $error = []; + for($i=0;$i<$count;$i++){ + + + if(!empty($_FILES['files']['name'][$i])){ + + + + $_FILES['file']['name'] = $_FILES['files']['name'][$i]; + + $_FILES['file']['type'] = $_FILES['files']['type'][$i]; + + $_FILES['file']['tmp_name'] = $_FILES['files']['tmp_name'][$i]; + + $_FILES['file']['error'] = $_FILES['files']['error'][$i]; + + $_FILES['file']['size'] = $_FILES['files']['size'][$i]; + + + + $namex = $orderid.'-'.$labnumber.'-'.$this->generateRandomString(5); + //echo $namex; + + $config['file_name'] = $namex; + $this->upload->initialize($config); + //echo $config['file_name'] ; + + + + + + if($this->upload->do_upload('file')){ + + $uploadData = $this->upload->data(); + + $filename = $uploadData['file_name']; + //echo $filename; + + + $sql = "INSERT INTO so_imageupload ( + So_ImageUploadT_OrderHeaderID, + So_ImageUploadT_OrderHeaderLabNumber, + So_ImageUploadT_SampleTypeID, + So_ImageUploadOldName, + So_ImageUploadNewName, + So_ImageUploadCreated, + So_ImageUploadUserID + ) + VALUES( + {$orderid}, + '{$labnumber}', + '150', + '{$_FILES['files']['name'][$i]}', + '{$filename}', + NOW(), + {$userid} + + )"; + //echo $sql; + $this->db_onedev->query($sql); + $xlast_id = $this->db_onedev->insert_id(); + $data['totalFiles'][] = array('xid' => $xlast_id ,'image_url' => '/one-media/one-image-nonlab/'.$filename); + + } + else{ + $error = array('error' => $this->upload->display_errors()); + } + + } + + + + } + + $result = array("total" =>count( $data['totalFiles']), "records" => $data['totalFiles'],'errors'=>$error); + $this->sys_ok($result); + } + + + function getpatologianatomyresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT Other_PatologiAnatomyID as xid, + Other_PatologiAnatomyT_OrderDetailID as orderdetail_id, + Other_PatologiAnatomyNoSediaan as no_sediaan, + Other_PatologiAnatomyDiagnosaKlinis as diagnosa, + Other_PatologiAnatomyKeteranganKlinis as klinis, + Other_PatologiAnatomyLokasiOrgan as lokasi, + Other_PatologiAnatomyMakroskopik as makroskopik, + Other_PatologiAnatomyMikroskopik as mikroskopik, + Other_PatologiAnatomyKesimpulan as kesimpulan, + IFNULL(Other_PatologiAnatomyM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_PatologiAnatomyM_DoctorID) OR Other_PatologiAnatomyM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_patologi_anatomy + LEFT JOIN m_doctor ON Other_PatologiAnatomyM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_PatologiAnatomyT_OrderDetailID = {$id} AND Other_PatologiAnatomyIsActive = 'Y' + GROUP BY Other_PatologiAnatomyID + ORDER BY Other_PatologiAnatomyID ASC + LIMIT 1"; + $query = $this->db_smartone->query($sql); + + if ($query) + { + $rows = $query->row_array(); + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + + $rst = array('doctors'=>$doctors,'result'=>$rows); + $this->sys_ok(["records"=>$rst]); + } + else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + + + function generateRandomString($length = 10) { + $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; + $charactersLength = strlen($characters); + $randomString = ''; + for ($i = 0; $i < $length; $i++) { + $randomString .= $characters[rand(0, $charactersLength - 1)]; + } + return $randomString; + } + + function getcytologiresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT Other_CytologiDetailsID as xid, + Other_CytologiT_OrderDetailID as orderdetail_id, + Other_CytologiDetailsCode as code, + Other_CytologiDetailsLabel as label, + Other_CytologiDetailsResult as result, + IFNULL(Other_CytologiM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_CytologiM_DoctorID) OR Other_CytologiM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_cytologi + JOIN other_cytologidetails ON Other_CytologiDetailsOther_CytologiID = Other_CytologiID AND Other_CytologiDetailsIsActive = 'Y' + LEFT JOIN m_doctor ON Other_CytologiM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_CytologiT_OrderDetailID = {$id} AND Other_CytologiIsActive = 'Y' + GROUP BY Other_CytologiDetailsID + ORDER BY Other_CytologiDetailsCode ASC"; + //echo $sql; + $query = $this->db_smartone->query($sql); + + if ($query) + { + $rows = $query->result_array(); + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $rst = array('doctors'=>$doctors,'results'=>$rows); + $this->sys_ok(["records"=>$rst]); + } + else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + function getmikroresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT + Other_MikroID as xid, + Other_MikroHasilBiakan as hasil_biakan, + Other_MikroSampleTypeName as sample_name, + Other_MikroT_OrderDetailID as orderdetail_id, + Other_MikroResult as result_value, + '' as result_other, + IFNULL(T_BacteriaID,0) as T_BacteriaID, + IFNULL(T_BacteriaName,'') as T_BacteriaName, + '' as details, + IFNULL(Other_MikroM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_MikroM_DoctorID) OR Other_MikroM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_mikro + LEFT JOIN t_bacteria ON Other_MikroT_BacteriaID = T_BacteriaID + LEFT JOIN m_doctor ON Other_MikroM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_MikroT_OrderDetailID = {$id} AND Other_MikroIsActive = 'Y' + GROUP BY Other_MikroID"; + //echo $sql; + $query = $this->db_smartone->query($sql); + + if ($query) + { + $row = $query->row_array(); + if($row){ + if($row['result_value'] != 'Positif' && $row['result_value'] != 'Negatif'){ + $row['result_other'] = $row['result_value']; + $row['result_value'] = 'other'; + } + $sql = "SELECT '' as xno, + Other_MikroDetailsID as xid, + Other_MikroDetailsValue as value, + IF(Other_MikroDetailsNote = 'R','Y','N') as chx_r, + IF(Other_MikroDetailsNote = 'I','Y','N') as chx_i, + IF(Other_MikroDetailsNote = 'S','Y','N') as chx_s, + Other_MikroDetailsNote as note, + t_antibiotic.* + FROM other_mikrodetails + LEFT JOIN t_antibiotic ON Other_MikroDetailsT_AntibioticID = T_AntibioticID + WHERE + Other_MikroDetailsOther_MikroID = {$row['xid']} AND Other_MikroDetailsIsActive = 'Y' + GROUP BY Other_MikroDetailsID + ORDER BY T_AntibioticName ASC"; + //echo $sql; + $details = $this->db_smartone->query($sql)->result_array(); + if(details){ + foreach($details as $k => $v){ + $details[$k]['xno'] = $k + 1; + } + } + $row['details'] = $details; + } + else{ + $row = array('xid'=>'0','hasil_biakan' => '','result_value'=>'Negatif','sample_name' => '','orderdetail_id'=>$id, 'T_BacteriaID'=>'0','T_BacteriaName'=>'0','details'=>array(),'doctor_id'=>'0','doctor_name'=>'0'); + } + } + else{ + $row = array('xid'=>'0','hasil_biakan' => '','result_value'=>'Negatif','sample_name' => '','orderdetail_id'=>$id, 'T_BacteriaID'=>'0','T_BacteriaName'=>'0','details'=>array(),'doctor_id'=>'0','doctor_name'=>'0'); + } + //print_r($row); + + + + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 7 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $sql = " + SELECT '0' as id, 'Belum memilih bakteria' as name + UNION + SELECT T_BacteriaID as id, T_BacteriaName as name + FROM t_bacteria + WHERE + T_BacteriaIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $bacteries = $this->db_smartone->query($sql)->result_array(); + $rst = array('doctors'=>$doctors,'bacteries'=>$bacteries,'results'=>$row); + $this->sys_ok(["records"=>$rst]); + } + function getantibiotics(){ + $prm = $this->sys_input; + $id = $prm["id"]; + $sql = " SELECT '' as xno, + 0 as xid, + '' as hasil_biakan, + '' as sample_name, + 0 as value, + 'Y' as chx_r, + 'N' as chx_i, + 'N' as chx_s, + 'R' as note, + t_antibiotic.* + FROM t_antibiotic + WHERE + T_AntibioticT_BacteriaID = {$prm['id']} AND T_AntibioticIsActive= 'Y' + ORDER BY T_AntibioticName ASC"; + //echo $sql; + $rows = $this->db_smartone->query($sql)->result_array(); + if(rows){ + foreach($rows as $k => $v){ + $rows[$k]['xno'] = $k + 1; + } + } + + $this->sys_ok(["records"=>$rows]); + } + function getlcprepresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + $sql = " SELECT Other_LcprepDetailsID as xid, + Other_LcprepID as header_id, + Other_LcprepT_orderDetailID as orderdetail_id, + Other_LcprepDetailsCode as code, + Other_LcprepDetailsLabel as label, + Other_LcprepDetailsResult as result, + IFNULL(Other_LcprepM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_LcprepM_DoctorID) OR Other_LcprepM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_lcprep + JOIN other_lcprepdetails ON Other_LcprepDetailsOther_LcprepID = Other_LcprepID AND Other_LcprepDetailsIsActive = 'Y' + LEFT JOIN m_doctor ON Other_LcprepM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_LcprepT_orderDetailID = {$id} AND Other_LcprepIsActive = 'Y' + GROUP BY Other_LcprepDetailsOther_LcprepID, Other_LcprepDetailsCode + ORDER BY Other_LcprepDetailsCode ASC"; + //echo $sql; + $rows = $this->db_smartone->query($sql)->result_array(); + if(!$rows){ + $rows = array( + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'A', + 'label' => 'DESKRIPSI', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ), + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'B', + 'label' => 'KESIMPULAN', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ) + ); + } + + $header_id = $rows[0]['header_id']; + $sql = "SELECT IFNULL(Other_LcprepAdekuasiID,0) as xid, + Lcprep_AdekuasiID as id, + Lcprep_AdekuasiLabel as name, + IF(ISNULL(Other_LcprepAdekuasiID),'N',Other_LcprepAdekuasiChex) as chex + FROM lcprep_adekuasi + LEFT JOIN other_lcprepadekuasi ON Other_LcprepAdekuasiLcprep_AdekuasiID = Lcprep_AdekuasiID AND + Other_LcprepAdekuasiOther_LcprepID = {$header_id} AND + Other_LcprepAdekuasiIsActive = 'Y' + WHERE + Lcprep_AdekuasiIsActive = 'Y' + GROUP BY Lcprep_AdekuasiID + ORDER BY Lcprep_AdekuasiOrder ASC + "; + //echo $sql; + $adeakuasi = $this->db_smartone->query($sql)->result_array(); + foreach($adeakuasi as $kc => $vc){ + $adeakuasi[$kc]['chex'] = $vc['chex'] == 'N'?false:true; + } + + $sql = "SELECT IFNULL(Other_LcprepKategoriUmumID,0) as xid, + Lcprep_KategoriUmumID as id, + Lcprep_KategoriUmumLabel as name, + IF(ISNULL(Other_LcprepKategoriUmumID),'N',Other_LcprepKategoriUmumChex) as chex + FROM lcprep_kategoriumum + LEFT JOIN other_lcprepkategoriumum ON Other_LcprepKategoriUmumLcprep_KategoriUmumID = Lcprep_KategoriUmumID AND + Other_LcprepKategoriUmumOther_LcprepID = {$header_id} AND + Other_LcprepKategoriUmumIsActive = 'Y' + WHERE + Lcprep_KategoriUmumIsActive = 'Y' + GROUP BY Lcprep_KategoriUmumID + "; + //echo $sql; + $kategoriumum = $this->db_smartone->query($sql)->result_array(); + foreach($kategoriumum as $kc => $vc){ + $kategoriumum[$kc]['chex'] = $vc['chex'] == 'N'?false:true; + } + + $sql = " + SELECT Lcprep_InterpretasiGroupID as group_id, + Lcprep_InterpretasiGroupName as group_name, + '' as subgroups + FROM lcprep_interpretasigroup + WHERE + Lcprep_InterpretasiGroupIsActive = 'Y' + "; + //echo $sql; + $interpretasi = $this->db_smartone->query($sql)->result_array(); + foreach($interpretasi as $k => $v){ + $subgroups = array(); + $sql = "SELECT Lcprep_InterpretasiSubgroupID as subgroup_id, + Lcprep_InterpretasiSubgroupName as subgroup_name, + '' as childs + FROM lcprep_interpretasisubgroup + WHERE + Lcprep_InterpretasiSubgroupLcprep_InterpretasiGroupID = {$v['group_id']} AND Lcprep_InterpretasiSubgroupIsActive = 'Y'"; + //echo $sql; + $subgroups = $this->db_smartone->query($sql)->result_array(); + if(count($subgroups) > 0){ + foreach($subgroups as $ki => $vi){ + $childs = array(); + $sql = "SELECT IFNULL(Other_LcprepInterpretasiID,0) as xid, + IFNULL(Other_LcprepInterpretasiChex,'N') as chex, + IFNULL(Other_LcprepInterpretasiValue,'') as value, + Lcprep_InterpretasiID as id, + Lcprep_InterpretasiLcprep_InterpretasiSubgroupID as subgroup_id, + Lcprep_InterpretasiCode as code, + Lcprep_InterpretasiName as name, + Lcprep_InterpretasiParentID as parent_id, + Lcprep_InterpretasiIsParent as is_parent, + Lcprep_InterpretasiHasResult as has_result, + Lcprep_InterpretasiTypeResult as type_result + FROM lcprep_interpretasi + LEFT JOIN other_lcprepinterpretasi ON Other_LcprepInterpretasiOther_LcprepID = {$header_id} AND + Other_LcprepInterpretasiLcprep_InterpretasiID = Lcprep_InterpretasiID AND + Other_LcprepInterpretasiIsActive = 'Y' + WHERE + Lcprep_InterpretasiLcprep_InterpretasiSubgroupID = {$vi['subgroup_id']} AND Lcprep_InterpretasiIsActive = 'Y' + GROUP BY Lcprep_InterpretasiID Order BY Lcprep_InterpretasiCode ASC"; + $childs = $this->db_smartone->query($sql)->result_array(); + if($childs){ + foreach($childs as $kc => $vc){ + $childs[$kc]['chex'] = $vc['chex'] == 'N'?false:true; + } + } + $subgroups[$ki]['childs'] = $childs; + } + } + + $interpretasi[$k]['subgroups'] = $subgroups; + } + + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $rst = array('doctors'=>$doctors,'results'=>$rows,'adekuasi'=>$adeakuasi,'kategoriumum'=>$kategoriumum,'interpretasi'=>$interpretasi); + $this->sys_ok(["records"=>$rst]); + } + + function getpapsmearresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT Other_PapSmearDetailsID as xid, + Other_PapSmearID as header_id, + Other_PapSmearT_OrderDetailID as orderdetail_id, + Other_PapSmearDetailsCode as code, + Other_PapSmearDetailsLabel as label, + Other_PapSmearDetailsResult as result, + IFNULL(Other_PapSmearM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_PapSmearM_DoctorID) OR Other_PapSmearM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_papsmear + JOIN other_papsmeardetails ON Other_PapSmearDetailsOther_PapSmearID = Other_PapSmearID AND Other_PapSmearDetailsIsActive = 'Y' + LEFT JOIN m_doctor ON Other_PapSmearM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_PapSmearT_OrderDetailID = {$id} AND Other_PapSmearIsActive = 'Y' + GROUP BY Other_PapSmearDetailsID + ORDER BY Other_PapSmearDetailsCode ASC"; + //echo $sql; + $rows = $this->db_smartone->query($sql)->result_array(); + if(!$rows){ + $rows = array( + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'A', + 'label' => 'Makroskopik', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ), + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'B', + 'label' => 'Mikroskopik', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ), + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'C', + 'label' => 'Kesimpulan', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ) + ); + } + + $header_id = $rows[0]['header_id']; + $sql = "SELECT Other_PapSmearMaturasiID as xid, + Other_PapSmearMaturasiValue as value + FROM other_papsmearmaturasi + WHERE + Other_PapSmearMaturasiOther_PapSmearID = {$header_id} AND + Other_PapSmearMaturasiIsActive = 'Y' + "; + //echo $sql; + $dt_maturasi = $this->db_smartone->query($sql)->row_array(); + if(!$dt_maturasi){ + $maturasi = array('xid'=>'0','value'=> array('','','')); + } + else{ + $value = explode('/',$dt_maturasi['value']); + $maturasi = array('xid'=>$dt_maturasi['xid'],'value'=> $value); + } + + $sql = "SELECT IFNULL(Other_PapSmearBahanID,0) as xid, + M_PapSmearBahanID as bahan_id, + M_PapSmearBahanName as name, + IF(ISNULL(Other_PapSmearBahanID),'N','Y') as selected + FROM m_papsmearbahan + LEFT JOIN other_papsmearbahan ON Other_PapSmearBahanM_PapSmearBahanID = M_PapSmearBahanID AND + Other_PapSmearBahanOther_PapSmearID = {$header_id} AND + Other_PapSmearBahanIsActive = 'Y' + WHERE + M_PapSmearBahanIsActive = 'Y' + ORDER BY M_PapSmearBahanID ASC + "; + //echo $sql; + $bahans = $this->db_smartone->query($sql)->result_array(); + + $sql = "SELECT IFNULL(Other_PapsmearCategoryID,0) as xid, + M_PapSmearCategoryID as category_id, + M_PapSmearCategoryName as name, + IF(ISNULL(Other_PapsmearCategoryID),'N','Y') as selected + FROM m_papsmearcategory + LEFT JOIN other_papsmearcategory ON Other_PapsmearCategoryM_PapSmearCategoryID = M_PapSmearCategoryID AND + Other_PapsmearCategoryOther_PapSmearID = {$header_id} AND + Other_PapsmearCategoryIsActive = 'Y' + WHERE + M_PapSmearCategoryIsActive = 'Y' + ORDER BY M_PapSmearCategoryID ASC + "; + //echo $sql; + $categories = $this->db_smartone->query($sql)->result_array(); + + $sql = "SELECT IFNULL(Other_PapSmearCheckID,0) as xid, + M_PapSmearCheckID as check_id, + M_PapSmearCheckLabel as name, + IF(ISNULL(Other_PapSmearCheckID),'N','Y') as selected, + Other_PapSmearCheckNote as note + FROM m_papsmearcheck + LEFT JOIN other_papsmearcheck ON Other_PapSmearCheckM_PapSmearCheckID = M_PapSmearCheckID AND + Other_PapSmearCheckOther_PapSmearID = {$header_id} AND + Other_PapSmearCheckIsActive = 'Y' + WHERE + M_PapSmearCheckIsActive = 'Y' + ORDER BY M_PapSmearCheckCode ASC + "; + $checks = $this->db_smartone->query($sql)->result_array(); + + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $rst = array('doctors'=>$doctors,'checks'=>$checks,'bahans'=>$bahans,'categories'=>$categories,'maturasi'=>$maturasi,'results'=>$rows); + $this->sys_ok(["records"=>$rst]); + + } + + function saveresult_lcprep() + { + $prm = $this->sys_input; + $detail_id = $prm['detail_id']; + $doctor_id = $prm['doctor']; + $adekuasi = $prm['adekuasi']; + $kategoriumum = $prm['kategoriumum']; + $interpretasi = $prm['interpretasi']; + $results = $prm['results']; + + $userid = $this->sys_user['M_UserID']; + + $header_id = 0; + $sql = "SELECT * FROM other_lcprep WHERE Other_LcprepT_orderDetailID = {$detail_id} AND Other_LcprepIsActive = 'Y'"; + $dt_header = $this->db_smartone->query($sql)->row_array(); + if($dt_header){ + $header_id = $dt_header['Other_LcprepID']; + } + if($header_id == 0){ + $sql = "INSERT INTO other_lcprep( + Other_LcprepT_orderDetailID, + Other_LcprepM_DoctorID, + Other_LcprepUserID, + Other_LcprepCreated + ) + VALUES( + {$detail_id}, + {$doctor_id}, + {$userid}, + NOW() + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + }else{ + $sql = "UPDATE other_lcprep SET Other_LcprepM_DoctorID = {$doctor_id}, Other_LcprepUserID = {$userid} WHERE Other_LcprepID = {$header_id}"; + $this->db_smartone->query($sql); + } + + if($adekuasi){ + foreach($adekuasi as $k =>$v){ + $selected = $v['chex']?'Y':'N'; + if(intval($v['xid'] == 0)){ + $sql = "UPDATE other_lcprepadekuasi SET Other_LcprepAdekuasiIsActive = 'N' + WHERE + Other_LcprepAdekuasiOther_LcprepID = {$header_id} AND + Other_LcprepAdekuasiIsActive = 'Y' AND + Other_LcprepAdekuasiLcprep_AdekuasiID = {$v['id']}"; + $this->db_smartone->query($sql); + $sql = "INSERT INTO other_lcprepadekuasi ( + Other_LcprepAdekuasiOther_LcprepID, + Other_LcprepAdekuasiLcprep_AdekuasiID, + Other_LcprepAdekuasiChex, + Other_LcprepAdekuasiUserID, + Other_LcprepAdekuasiCreated + ) + VALUES( + {$header_id}, + {$v['id']}, + '{$selected}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + //echo $sql; + } + if(intval($v['xid'] != 0)){ + + $sql = "UPDATE other_lcprepadekuasi SET + Other_LcprepAdekuasiChex = '{$selected}', + Other_LcprepAdekuasiUserID = {$userid} + WHERE + Other_LcprepAdekuasiID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + + //echo $sql; + } + } + + if($kategoriumum){ + foreach($kategoriumum as $k =>$v){ + $selected = $v['chex']?'Y':'N'; + if(intval($v['xid'] == 0)){ + $sql = "UPDATE other_lcprepkategoriumum SET Other_LcprepKategoriUmumIsActive = 'N' + WHERE + Other_LcprepKategoriUmumOther_LcprepID = {$header_id} AND + Other_LcprepKategoriUmumLcprep_KategoriUmumID = {$v['id']} AND + Other_LcprepKategoriUmumIsActive = 'Y' + "; + $this->db_smartone->query($sql); + $sql = "INSERT INTO other_lcprepkategoriumum ( + Other_LcprepKategoriUmumOther_LcprepID, + Other_LcprepKategoriUmumLcprep_KategoriUmumID, + Other_LcprepKategoriUmumChex, + Other_LcprepKategoriUmumUserID, + Other_LcprepKategoriUmumCreated + ) + VALUES( + {$header_id}, + {$v['id']}, + '{$selected}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if(intval($v['xid'] != 0)){ + $sql = "UPDATE other_lcprepkategoriumum SET + Other_LcprepKategoriUmumChex = '{$selected }', + Other_LcprepKategoriUmumUserID = {$userid} + WHERE + Other_LcprepKategoriUmumID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + + //echo $sql; + } + } + + if($results){ + foreach($results as $k =>$v){ + if(intval($v['xid'] == 0)){ + $sql = "UPDATE other_lcprepdetails SET Other_LcprepDetailsIsActive = 'N' + WHERE + Other_LcprepDetailsOther_LcprepID = {$header_id} AND + Other_LcprepDetailsCode = '{$v['code']}' AND + Other_LcprepDetailsIsActive = 'Y'"; + $this->db_smartone->query($sql); + $sql = "INSERT INTO other_lcprepdetails ( + Other_LcprepDetailsOther_LcprepID, + Other_LcprepDetailsCode, + Other_LcprepDetailsLabel, + Other_LcprepDetailsResult, + Other_LcprepDetailsUserID, + Other_LcprepDetailsCreated + ) + VALUES( + {$header_id}, + '{$v['code']}', + '{$v['label']}', + '{$v['result']}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if(intval($v['xid'] != 0)){ + $sql = "UPDATE other_lcprepdetails SET + Other_LcprepDetailsCode = '{$v['code']}', + Other_LcprepDetailsLabel = '{$v['label']}', + Other_LcprepDetailsResult = '{$v['result']}', + Other_LcprepDetailsUserID = {$userid} + WHERE + Other_LcprepDetailsID = {$v['xid']}"; + $this->db_smartone->query($sql); + + } + //echo $sql; + } + } + + if($interpretasi){ + foreach($interpretasi as $k =>$v){ + if(count($v['subgroups']) > 0){ + foreach($v['subgroups'] as $ik => $iv){ + if(count($iv['childs']) > 0){ + foreach($iv['childs'] as $iik => $iiv){ + if(intval($iiv['xid'] == 0)){ + $chex = $iiv['chex'] ? 'Y':'N'; + $sql = "UPDATE other_lcprepinterpretasi SET Other_LcprepInterpretasiIsActive = 'N' + WHERE + Other_LcprepInterpretasiOther_LcprepID = {$header_id} AND + Other_LcprepInterpretasiLcprep_InterpretasiID = '{$iiv['id']}' AND + Other_LcprepInterpretasiIsActive = 'Y'"; + $this->db_smartone->query($sql); + $sql = "INSERT INTO other_lcprepinterpretasi ( + Other_LcprepInterpretasiOther_LcprepID, + Other_LcprepInterpretasiLcprep_InterpretasiID, + Other_LcprepInterpretasiChex, + Other_LcprepInterpretasiValue, + Other_LcprepInterpretasiUserID, + Other_LcprepInterpretasiCreated + ) + VALUES( + {$header_id}, + '{$iiv['id']}', + '{$chex}', + '{$iiv['value']}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + + if(intval($iiv['xid'] != 0)){ + $chex = $iiv['chex'] ? 'Y':'N'; + $sql = "UPDATE other_lcprepinterpretasi SET + Other_LcprepInterpretasiChex = '{$chex}', + Other_LcprepInterpretasiValue = '{$iiv['value']}', + Other_LcprepInterpretasiUserID = {$userid} + WHERE + Other_LcprepInterpretasiID = {$iiv['xid']}"; + $this->db_smartone->query($sql); + //echo $sql; + + } + + } + } + } + } + //echo $sql; + } + } + + + $result = array("total" => 1, "records" => array(), "sql"=> ''); + $this->sys_ok($result); + exit; + } + + function saveresult_papsmear() + { + $prm = $this->sys_input; + $detail_id = $prm['detail_id']; + $doctor_id = $prm['doctor']; + $checks = $prm['checks']; + $maturasi = $prm['maturasi']; + $bahans = $prm['bahans']; + $categories = $prm['categories']; + $results = $prm['results']; + + $userid = $this->sys_user['M_UserID']; + + $header_id = 0; + $sql = "SELECT * FROM other_papsmear WHERE Other_PapSmearT_OrderDetailID = {$detail_id} AND Other_PapSmearIsActive = 'Y'"; + $dt_header = $this->db_smartone->query($sql)->row_array(); + if($dt_header){ + $header_id = $dt_header['Other_PapSmearID']; + } + if($header_id == 0){ + $sql = "INSERT INTO other_papsmear( + Other_PapSmearT_OrderDetailID, + Other_PapSmearM_DoctorID, + Other_PapSmearUserID, + Other_PapSmearCreated + ) + VALUES( + {$detail_id}, + {$doctor_id}, + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } + else{ + $sql = "UPDATE other_papsmear SET Other_PapSmearM_DoctorID = {$doctor_id}, Other_PapSmearUserID = {$userid} WHERE Other_PapSmearID = {$header_id}"; + $this->db_smartone->query($sql); + } + + if($checks){ + foreach($checks as $k =>$v){ + if(intval($v['xid']) == 0 && $v['selected'] === 'Y'){ + $sql = "INSERT INTO other_papsmearcheck ( + Other_PapSmearCheckOther_PapSmearID, + Other_PapSmearCheckM_PapSmearCheckID, + Other_PapSmearCheckNote, + Other_PapSmearCheckUserID, + Other_PapSmearCheckCreated + ) + VALUES( + {$header_id}, + {$v['check_id']}, + '{$v['note']}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if(intval($v['xid']) != 0 && $v['selected'] === 'N'){ + $sql = "UPDATE other_papsmearcheck SET + Other_PapSmearCheckIsActive = 'N', + Other_PapSmearCheckUserID = {$userid} + WHERE + Other_PapSmearCheckID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + if(intval($v['xid']) != 0 && $v['selected'] === 'Y'){ + $sql = "UPDATE other_papsmearcheck SET + Other_PapSmearCheckNote = '{$v['note']}', + Other_PapSmearCheckUserID = {$userid} + WHERE + Other_PapSmearCheckID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + //echo $sql; + } + } + + if($maturasi){ + if(intval($maturasi['xid']) == 0){ + $value = join("/",$maturasi['value']); + $sql = "INSERT INTO other_papsmearmaturasi ( + Other_PapSmearMaturasiOther_PapSmearID, + Other_PapSmearMaturasiValue, + Other_PapSmearMaturasiUserID, + Other_PapSmearMaturasiCreated + ) + VALUE( + {$header_id}, + '{$value}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + //echo $sql; + } + if(intval($maturasi['xid']) != 0){ + $value = join("/",$maturasi['value']); + $sql = "UPDATE other_papsmearmaturasi SET + Other_PapSmearMaturasiValue = '{$value}', + Other_PapSmearMaturasiUserID = {$userid} + WHERE + Other_PapSmearMaturasiID = {$maturasi['xid']}"; + // echo $sql; + $this->db_smartone->query($sql); + } + } + + if($bahans){ + foreach($bahans as $k =>$v){ + if(intval($v['xid']) == 0 && $v['selected'] === 'Y'){ + $sql = "INSERT INTO other_papsmearbahan ( + Other_PapSmearBahanOther_PapSmearID, + Other_PapSmearBahanM_PapSmearBahanID, + Other_PapSmearBahanUserID, + Other_PapSmearBahanCreated + ) + VALUES( + {$header_id}, + {$v['bahan_id']}, + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if(intval($v['xid']) != 0 && $v['selected'] === 'N'){ + $sql = "UPDATE other_papsmearbahan SET + Other_PapSmearBahanIsActive = 'N', + Other_PapsmearCategoryUserID = {$userid} + WHERE + Other_PapSmearBahanID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + if(intval($v['xid']) != 0 && $v['selected'] === 'Y'){ + $sql = "UPDATE other_papsmearbahan SET + Other_PapSmearBahanIsActive = 'Y', + Other_PapsmearCategoryUserID = {$userid} + WHERE + Other_PapSmearBahanID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + //echo $sql; + } + } + + if($categories){ + foreach($categories as $k =>$v){ + if(intval($v['xid']) == 0 && $v['selected'] === 'Y'){ + $sql = "INSERT INTO other_papsmearcategory ( + Other_PapsmearCategoryOther_PapSmearID, + Other_PapsmearCategoryM_PapSmearCategoryID, + Other_PapsmearCategoryUserID, + Other_PapsmearCategoryCreated + ) + VALUES( + {$header_id}, + {$v['category_id']}, + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if(intval($v['xid']) != 0 && $v['selected'] === 'N'){ + $sql = "UPDATE other_papsmearcategory SET + Other_PapsmearCategoryIsActive = 'N', + Other_PapsmearCategoryUserID = {$userid} + WHERE + Other_PapsmearCategoryID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + //echo $sql; + if(intval($v['xid']) != 0 && $v['selected'] === 'Y'){ + $sql = "UPDATE other_papsmearcategory SET + Other_PapsmearCategoryIsActive = 'Y', + Other_PapsmearCategoryUserID = {$userid} + WHERE + Other_PapsmearCategoryID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + } + } + + if($results){ + foreach($results as $k =>$v){ + if(intval($v['xid']) == 0){ + $sql = "INSERT INTO other_papsmeardetails ( + Other_PapSmearDetailsOther_PapSmearID, + Other_PapSmearDetailsCode, + Other_PapSmearDetailsLabel, + Other_PapSmearDetailsResult, + Other_PapSmearDetailsUserID, + Other_PapSmearDetailsCreated + ) + VALUES( + {$header_id}, + '{$v['code']}', + '{$v['label']}', + '{$v['result']}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if(intval($v['xid']) != 0){ + $sql = "UPDATE other_papsmeardetails SET + Other_PapSmearDetailsCode = '{$v['code']}', + Other_PapSmearDetailsLabel = '{$v['label']}', + Other_PapSmearDetailsResult = '{$v['result']}', + Other_PapSmearDetailsUserID = {$userid} + WHERE + Other_PapSmearDetailsID = {$v['xid']}"; + $this->db_smartone->query($sql); + + } + //echo $sql; + } + } + + $result = array("total" => 1, "records" => array(), "sql"=> ''); + $this->sys_ok($result); + exit; + } + + function saveresult_fna() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = $inp['doctor']; + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + if($prm[0]['xid'] == '0'){ + $sql = "INSERT INTO other_fna( + Other_FNAM_DoctorID, + Other_FNAT_OrderDetailID, + Other_FNAUserID, + Other_FNACreated + ) + VALUES( + {$doctor_id}, + {$prm[0]['orderdetail_id']}, + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } + else{ + $sql = "SELECT * FROM other_fna WHERE Other_FNAT_OrderDetailID = {$prm[0]['orderdetail_id']} AND Other_FNAIsActive = 'Y'"; + $data_header = $this->db_smartone->query($sql)->row_array(); + $header_id = $data_header['Other_FNAID']; + $sql = "UPDATE other_fna SET + Other_FNAM_DoctorID = {$doctor_id}, + Other_FNAUserID = {$userid} + WHERE + Other_FNAID = {$header_id}"; + $this->db_smartone->query($sql); + } + foreach($prm as $k => $v){ + if($v['xid'] == '0'){ + $results = str_replace("'", "\\'", $v['result']); + $sql = "INSERT INTO other_fnadetails( + Other_FNADetailsOther_FNAID , + Other_FNADetailsCode, + Other_FNADetailsLabel, + Other_FNADetailsResult, + Other_FNADetailsCreated, + Other_FNADetailsUserID + ) + VALUES( + {$header_id}, + '{$v['code']}', + '{$v['label']}', + '{$results}', + NOW(), + {$userid} + )"; + $query = $this->db_smartone->query($sql); + } + else{ + $results = str_replace("'", "\\'", $v['result']); + $sql = "UPDATE other_fnadetails SET + Other_FNADetailsResult = '{$results}', + Other_FNADetailsUserID = {$userid} + WHERE + Other_FNADetailsID = {$v['xid']}"; + $query = $this->db_smartone->query($sql); + } + } + + $result = array("total" => 1, "records" => array(), "sql"=> ''); + $this->sys_ok($result); + exit; + } + + function saveresult_cytologi() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = $inp['doctor']; + + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + if($prm[0]['xid'] == '0'){ + $sql = "INSERT INTO other_cytologi( + Other_CytologiT_OrderDetailID, + Other_CytologiM_DoctorID, + Other_CytologiUserID, + Other_CytologiCreated + ) + VALUES( + {$prm[0]['orderdetail_id']}, + {$doctor_id}, + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } + else{ + $sql = "SELECT * FROM other_cytologi WHERE Other_CytologiT_OrderDetailID = {$prm[0]['orderdetail_id']} AND Other_CytologiIsActive = 'Y'"; + $data_header = $this->db_smartone->query($sql)->row_array(); + $header_id = $data_header['Other_CytologiID']; + $sql = "UPDATE other_cytologi SET + Other_CytologiM_DoctorID = {$doctor_id}, + Other_CytologiUserID = {$userid} + WHERE + Other_CytologiID = {$header_id}"; + $this->db_smartone->query($sql); + } + foreach($prm as $k => $v){ + if($v['xid'] == '0'){ + $results = str_replace("'", "\\'", $v['result']); + $sql = "INSERT INTO other_cytologidetails( + Other_CytologiDetailsOther_CytologiID , + Other_CytologiDetailsCode, + Other_CytologiDetailsLabel, + Other_CytologiDetailsResult, + Other_CytologiDetailsCreated, + Other_CytologiDetailsUserID + ) + VALUES( + {$header_id}, + '{$v['code']}', + '{$v['label']}', + '{$results}', + NOW(), + {$userid} + )"; + $query = $this->db_smartone->query($sql); + } + else{ + $results = str_replace("'", "\\'", $v['result']); + $sql = "UPDATE other_cytologidetails SET + Other_CytologiDetailsResult = '{$results}', + Other_CytologiDetailsUserID = {$userid} + WHERE + Other_CytologiDetailsID = {$v['xid']}"; + $query = $this->db_smartone->query($sql); + } + } + + $result = array("total" => 1, "records" => array(), "sql"=> ''); + $this->sys_ok($result); + exit; + } + + function saveresult_mikro() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = $inp['doctor']; + $backteria_id = $inp['bacteria']; + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + + if($inp['result_value'] != 'Negatif' && $inp['result_value'] != 'Positif'){ + $prm['result_value'] = $prm['result_other']; + } + else{ + $prm['result_value'] = $inp['result_value']; + } + + if($prm['xid'] == '0'){ + $sql = "INSERT INTO other_mikro( + Other_MikroM_DoctorID, + Other_MikroResult, + Other_MikroT_BacteriaID, + Other_MikroT_OrderDetailID, + Other_MikroHasilBiakan, + Other_MikroSampleTypeName, + Other_MikroUserID, + Other_MikroCreated + ) + VALUES( + {$doctor_id}, + '{$prm['result_value']}', + {$backteria_id}, + {$prm['orderdetail_id']}, + '{$prm['hasil_biakan']}', + '{$prm['sample_name']}', + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } + else{ + $sql = "SELECT * FROM other_mikro WHERE Other_MikroT_OrderDetailID = {$prm['orderdetail_id']} AND Other_MikroIsActive = 'Y'"; + $data_header = $this->db_smartone->query($sql)->row_array(); + $header_id = $data_header['Other_MikroID']; + $sql = "UPDATE other_mikro SET + Other_MikroResult = '{$prm['result_value']}', + Other_MikroM_DoctorID = {$doctor_id}, + Other_MikroT_BacteriaID = {$backteria_id}, + Other_MikroHasilBiakan = '{$prm['hasil_biakan']}', + Other_MikroSampleTypeName = '{$prm['sample_name']}', + Other_MikroUserID = {$userid} + WHERE + Other_MikroID = {$header_id}"; + //echo $sql; + $this->db_smartone->query($sql); + } + + + + $sql = "UPDATE other_mikrodetails SET Other_MikroDetailsIsActive = 'N', Other_MikroDetailsUserID = 0 WHERE Other_MikroDetailsOther_MikroID = {$header_id}"; + $this->db_smartone->query($sql); + + $results = $prm['details']; + if($inp['result_value'] == 'Positif'){ + foreach($results as $k => $v){ + if($v['xid'] == '0'){ + $sql = "INSERT INTO other_mikrodetails( + Other_MikroDetailsOther_MikroID , + Other_MikroDetailsT_AntibioticID, + Other_MikroDetailsValue, + Other_MikroDetailsNote, + Other_MikroDetailsCreated, + Other_MikroDetailsUserID + ) + VALUES( + {$header_id}, + '{$v['T_AntibioticID']}', + '{$v['value']}', + '{$v['note']}', + NOW(), + {$userid} + )"; + $query = $this->db_smartone->query($sql); + } + else{ + $sql = "UPDATE other_mikrodetails SET + Other_MikroDetailsT_AntibioticID = '{$v['T_AntibioticID']}', + Other_MikroDetailsValue = '{$v['value']}', + Other_MikroDetailsNote = '{$v['note']}', + Other_MikroDetailsIsActive = 'Y', + Other_MikroDetailsUserID = {$userid} + WHERE + Other_MikroDetailsID = {$v['xid']}"; + //echo $sql; + $query = $this->db_smartone->query($sql); + } + } + } + + + $result = array("total" => 1, "records" => array(), "sql"=> ''); + $this->sys_ok($result); + exit; + } + + + function get_doctors_preparasi_sperma() + { + $prm = $this->sys_input; + // $id = $prm["id"]; + + $sql = " SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 10 AND + M_DoctorSOIsActive = 'Y' + ORDER BY M_DoctorName ASC"; + //echo $sql; + $query = $this->db_smartone->query($sql); + $rows = $query->result_array(); + $sql = " + SELECT '0' as id, 'Belum memilih metode' as name + UNION + SELECT M_MethodeSpermaID as id, M_MethodeSpermaName as name + FROM m_methodesperma + WHERE + M_MethodeSpermaIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $methodes = $this->db_smartone->query($sql)->result_array(); + + + $this->sys_ok(["records"=>$rows,"methodes"=>$methodes]); + + } + + + function getpreparasispermaresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT other_preparasisperma.*, + Other_PreparasiSpermaID as xid, + Other_PreparasiSpermaT_OrderDetailID as orderdetail_id, + IFNULL(Other_PreparasiSpermaM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_PreparasiSpermaM_DoctorID) OR Other_PreparasiSpermaM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name, + IFNULL(M_MethodeSpermaID,0) as methode_id, + IFNULL(M_MethodeSpermaName,'') as methode_name + FROM other_preparasisperma + LEFT JOIN m_doctor ON Other_PreparasiSpermaM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + LEFT JOIN m_methodesperma ON Other_PreparasiSpermaM_MethodeSpermaID = M_MethodeSpermaID AND + M_MethodeSpermaIsActive = 'Y' + WHERE + Other_PreparasiSpermaT_OrderDetailID = {$id} AND Other_PreparasiSpermaIsActive = 'Y' + GROUP BY Other_PreparasiSpermaID"; + $query = $this->db_smartone->query($sql); + + if ($query) + { + $rows = $query->row_array(); + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 10 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $sql = " + SELECT '0' as id, 'Belum memilih metode' as name + UNION + SELECT M_MethodeSpermaID as id, M_MethodeSpermaName as name + FROM m_methodesperma + WHERE + M_MethodeSpermaIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $methodes = $this->db_smartone->query($sql)->result_array(); + $images = array(); + $sql = "SELECT Other_PreparasiSpermaImgID as xid, + Other_PreparasiSpermaImgType as type, + CONCAT('/one-media/one-image-nonlab/',Other_PreparasiSpermaImgNewName) as image_url + FROM t_orderdetail + JOIN other_preparasisperma_img ON Other_PreparasiSpermaImgT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND + Other_PreparasiSpermaImgIsActive = 'Y' + WHERE + T_OrderDetailID = {$id} AND + T_OrderDetailIsActive = 'Y' + GROUP BY Other_PreparasiSpermaImgID"; + //echo $sql; + $images = $this->db_smartone->query($sql)->result_array(); + + $rst = array('doctors'=>$doctors,'methodes'=>$methodes,'results'=>$rows,'images'=>$images); + $this->sys_ok(["records"=>$rst]); + } + else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + + function uploadimage_preparasi_sperma(){ + if (! $this->isLogin) { + $this->sys_error("Invalid Token"); + exit; + } + + $userid = $this->sys_user["M_UserID"]; + $data = []; + //print_r($_SERVER); + + $prm = $this->sys_input; + $orderid = $this->input->post('orderid'); + $type = $this->input->post('type'); + $labnumber = $this->input->post('labnumber'); + $sql = "UPDATE other_preparasisperma_img SET + Other_PreparasiSpermaImgIsActive = 'N', + Other_PreparasiSpermaImgUserID = {$userid} + WHERE + Other_PreparasiSpermaImgT_OrderHeaderID = {$orderid} AND + Other_PreparasiSpermaImgType = '{$type}'"; + //echo $sql; + $this->db_onedev->query($sql); + //$config['upload_path'] = 'assets/'; + + $path = '/home/one/project/one/one-media/one-image-nonlab/'; + //echo $path; + $config['upload_path'] = $path; + $config['allowed_types'] = 'jpg|jpeg|png|gif'; + + $config['max_size'] = '10000'; + $count = count($_FILES['files']['name']); + //echo $count; + $this->load->library('upload',$config); + + $error = []; + for($i=0;$i<$count;$i++){ + + + if(!empty($_FILES['files']['name'][$i])){ + + + + $_FILES['file']['name'] = $_FILES['files']['name'][$i]; + + $_FILES['file']['type'] = $_FILES['files']['type'][$i]; + + $_FILES['file']['tmp_name'] = $_FILES['files']['tmp_name'][$i]; + + $_FILES['file']['error'] = $_FILES['files']['error'][$i]; + + $_FILES['file']['size'] = $_FILES['files']['size'][$i]; + + + + $namex = $orderid.'-'.$labnumber.'-'.$this->generateRandomString(5); + //echo $namex; + + $config['file_name'] = $namex; + $this->upload->initialize($config); + //echo $config['file_name'] ; + + + + + + if($this->upload->do_upload('file')){ + + $uploadData = $this->upload->data(); + + $filename = $uploadData['file_name']; + //echo $filename; + + + $sql = "INSERT INTO other_preparasisperma_img ( + Other_PreparasiSpermaImgT_OrderHeaderID, + Other_PreparasiSpermaImgType, + Other_PreparasiSpermaImgOldName, + Other_PreparasiSpermaImgNewName, + Other_PreparasiSpermaImgCreated, + Other_PreparasiSpermaImgUserID + ) + VALUES( + {$orderid}, + '{$type}', + '{$_FILES['files']['name'][$i]}', + '{$filename}', + NOW(), + {$userid} + + )"; + //echo $sql; + $this->db_onedev->query($sql); + $xlast_id = $this->db_onedev->insert_id(); + $data['totalFiles'][] = array('xid' => $xlast_id ,'type'=>$type,'image_url' => '/one-media/one-image-nonlab/'.$filename); + + } + else{ + $error = array('error' => $this->upload->display_errors()); + } + + } + + + + } + + $result = array("total" =>count( $data['totalFiles']), "records" => $data['totalFiles'],'errors'=>$error); + $this->sys_ok($result); + } + + + function saveresult_preparasi_sperma() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = $inp['doctor']; + $orderdetail_id = $inp['orderdetailid']; + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + if($prm['xid'] == '0'){ + $sql = "INSERT INTO other_preparasisperma( + Other_PreparasiSpermaM_DoctorID, + Other_PreparasiSpermaT_OrderDetailID, + Other_PreparasiSpermaPreMotilitasA, + Other_PreparasiSpermaPreMotilitasB, + Other_PreparasiSpermaPreMotilitasC, + Other_PreparasiSpermaPreKonsentrasi, + Other_PreparasiSpermaPreKontaminan, + Other_PreparasiSpermaPostMotilitasA, + Other_PreparasiSpermaPostMotilitasB, + Other_PreparasiSpermaPostMotilitasC, + Other_PreparasiSpermaPostKonsentrasi, + Other_PreparasiSpermaPostKontaminan, + Other_PreparasiSpermaPreVolume, + Other_PreparasiSpermaPostVolume, + Other_PreparasiSpermaM_MethodeSpermaID, + Other_PreparasiSpermaNote, + Other_PreparasiSpermaUserID, + Other_PreparasiSpermaCreated + ) + VALUES( + {$doctor_id}, + {$orderdetail_id}, + '{$prm['Other_PreparasiSpermaPreMotilitasA']}', + '{$prm['Other_PreparasiSpermaPreMotilitasB']}', + '{$prm['Other_PreparasiSpermaPreMotilitasC']}', + '{$prm['Other_PreparasiSpermaPreKonsentrasi']}', + '{$prm['Other_PreparasiSpermaPreKontaminan']}', + '{$prm['Other_PreparasiSpermaPostMotilitasA']}', + '{$prm['Other_PreparasiSpermaPostMotilitasB']}', + '{$prm['Other_PreparasiSpermaPostMotilitasC']}', + '{$prm['Other_PreparasiSpermaPostKonsentrasi']}', + '{$prm['Other_PreparasiSpermaPostKontaminan']}', + '{$prm['Other_PreparasiSpermaPreVolume']}', + '{$prm['Other_PreparasiSpermaPostVolume']}', + '{$prm['Other_PreparasiSpermaM_MethodeSpermaID']}', + '{$prm['Other_PreparasiSpermaNote']}', + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } + else{ + $sql = "SELECT * FROM other_preparasisperma WHERE Other_PreparasiSpermaT_OrderDetailID = {$orderdetail_id} AND Other_PreparasiSpermaIsActive = 'Y'"; + $data_header = $this->db_smartone->query($sql)->row_array(); + $header_id = $data_header['Other_PreparasiSpermaID']; + $sql = "UPDATE other_preparasisperma SET + Other_PreparasiSpermaM_DoctorID = {$doctor_id}, + Other_PreparasiSpermaPreMotilitasA = '{$prm['Other_PreparasiSpermaPreMotilitasA']}', + Other_PreparasiSpermaPreMotilitasB = '{$prm['Other_PreparasiSpermaPreMotilitasB']}', + Other_PreparasiSpermaPreMotilitasC = '{$prm['Other_PreparasiSpermaPreMotilitasC']}', + Other_PreparasiSpermaPreKonsentrasi = '{$prm['Other_PreparasiSpermaPreKonsentrasi']}', + Other_PreparasiSpermaPreKontaminan = '{$prm['Other_PreparasiSpermaPreKontaminan']}', + Other_PreparasiSpermaPostMotilitasA = '{$prm['Other_PreparasiSpermaPostMotilitasA']}', + Other_PreparasiSpermaPostMotilitasB = '{$prm['Other_PreparasiSpermaPostMotilitasB']}', + Other_PreparasiSpermaPostMotilitasC = '{$prm['Other_PreparasiSpermaPostMotilitasC']}', + Other_PreparasiSpermaPostKonsentrasi = '{$prm['Other_PreparasiSpermaPostKonsentrasi']}', + Other_PreparasiSpermaPostKontaminan = '{$prm['Other_PreparasiSpermaPostKontaminan']}', + Other_PreparasiSpermaPreVolume = '{$prm['Other_PreparasiSpermaPreVolume']}', + Other_PreparasiSpermaPostVolume = '{$prm['Other_PreparasiSpermaPostVolume']}', + Other_PreparasiSpermaM_MethodeSpermaID = '{$prm['Other_PreparasiSpermaM_MethodeSpermaID']}', + Other_PreparasiSpermaNote = '{$prm['Other_PreparasiSpermaNote']}', + Other_PreparasiSpermaUserID = {$userid} + WHERE + Other_PreparasiSpermaID = {$header_id}"; + $this->db_smartone->query($sql); + } + + + $result = array("total" => 1, "records" => array(), "sql"=> ''); + $this->sys_ok($result); + exit; + } + + function getdnafragmentasiresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT other_dnafragmentasi.*, + Other_DnaFragmentasiID as xid, + Other_DnaFragmentasiT_OrderDetailID as orderdetail_id, + IFNULL(Other_DnaFragmentasiM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_DnaFragmentasiM_DoctorID) OR Other_DnaFragmentasiM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name, + IFNULL(Other_DnaFragmentasiOther_DnaFragmentasiMethodeID,0) as methode_id, + IFNULL(Other_DnaFragmentasiMethodeName,'') as methode_name, + Other_DnaFragmentasiHaloLuas as halo_luas, + Other_DnaFragmentasiHaloSedang as halo_sedang, + Other_DnaFragmentasiHaloSempit as halo_sempit, + Other_DnaFragmentasiTanpaHalo as tanpa_halo, + Other_DnaFragmentasiDFI as dfi, + Other_DnaFragmentasiKesimpulan as kesimpulan, + Other_DnaFragmentasiCatatan as catatan + FROM other_dnafragmentasi + LEFT JOIN m_doctor ON Other_DnaFragmentasiM_DoctorID = M_DoctorID + LEFT JOIN other_dnafragmentasimethode ON Other_DnaFragmentasiOther_DnaFragmentasiMethodeID = Other_DnaFragmentasiMethodeID + WHERE + Other_DnaFragmentasiT_OrderDetailID = {$id} AND Other_DnaFragmentasiIsActive = 'Y' + GROUP BY Other_DnaFragmentasiID + LIMIT 1"; + //echo $sql; + $query = $this->db_smartone->query($sql); + + if ($query) + { + $rows = $query->row_array(); + if(!$rows){ + $rows = array( + 'xid' => 0, + 'orderdetail_id' =>$id, + 'doctor_id' => 0, + 'doctor_name' => '', + 'methode_id' => 0, + 'methode_name' => '', + 'halo_luas' => '', + 'halo_sedang' => '', + 'tanpa_halo' => '', + 'dfi' => '', + 'kesimpulan' => '', + 'catatan' => '' + ); + } + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID + WHERE + M_DoctorSONat_SubGroupID = 4 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + + $sql = " + SELECT '0' as id, 'Belum memilih metode' as name + UNION + SELECT Other_DnaFragmentasiMethodeID as id, Other_DnaFragmentasiMethodeName as name + FROM other_dnafragmentasimethode + WHERE + Other_DnaFragmentasiMethodeIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $methodes = $this->db_smartone->query($sql)->result_array(); + + + $rst = array('doctors'=>$doctors,'methodes'=>$methodes,'results'=>$rows); + $this->sys_ok(["records"=>$rst]); + } + else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + function saveresult_dnafragmentasi() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = $inp['doctor']['id']; + $methode_id = $inp['methode']['id']; + $orderdetail_id = $inp['results']['orderdetail_id']; + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + if(intval($prm['xid']) == 0){ + $sql = "INSERT INTO other_dnafragmentasi( + Other_DnaFragmentasiT_OrderDetailID, + Other_DnaFragmentasiM_DoctorID, + Other_DnaFragmentasiOther_DnaFragmentasiMethodeID, + Other_DnaFragmentasiHaloLuas, + Other_DnaFragmentasiHaloSedang, + Other_DnaFragmentasiHaloSempit, + Other_DnaFragmentasiTanpaHalo, + Other_DnaFragmentasiDFI, + Other_DnaFragmentasiKesimpulan, + Other_DnaFragmentasiCatatan, + Other_DnaFragmentasiUserID, + Other_DnaFragmentasiLastUpdated + ) + VALUES( + {$orderdetail_id}, + {$doctor_id}, + {$methode_id}, + '{$prm['halo_luas']}', + '{$prm['halo_sedang']}', + '{$prm['halo_sempit']}', + '{$prm['tanpa_halo']}', + '{$prm['dfi']}', + '{$prm['kesimpulan']}', + '{$prm['catatan']}', + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } + else{ + $sql = "UPDATE other_dnafragmentasi SET + Other_DnaFragmentasiT_OrderDetailID = {$orderdetail_id}, + Other_DnaFragmentasiM_DoctorID = {$doctor_id}, + Other_DnaFragmentasiOther_DnaFragmentasiMethodeID = '{$methode_id}', + Other_DnaFragmentasiHaloLuas = '{$prm['halo_luas']}', + Other_DnaFragmentasiHaloSedang = '{$prm['halo_sedang']}', + Other_DnaFragmentasiHaloSempit = '{$prm['halo_sempit']}', + Other_DnaFragmentasiTanpaHalo = '{$prm['tanpa_halo']}', + Other_DnaFragmentasiDFI = '{$prm['dfi']}', + Other_DnaFragmentasiKesimpulan = '{$prm['kesimpulan']}', + Other_DnaFragmentasiCatatan = '{$prm['catatan']}', + Other_DnaFragmentasiLastUpdated = NOW(), + Other_DnaFragmentasiUserID = {$userid} + WHERE + Other_DnaFragmentasiID = {$prm['xid']}"; + //echo $sql; + $this->db_smartone->query($sql); + } + + + $result = array("total" => 1, "records" => array(), "sql"=> ''); + $this->sys_ok($result); + exit; + } + + +} + diff --git a/application/controllers/mockup/process/resultvalidation-v22xx/Re_px.php b/application/controllers/mockup/process/resultvalidation-v22xx/Re_px.php index d2c44b96..df562286 100644 --- a/application/controllers/mockup/process/resultvalidation-v22xx/Re_px.php +++ b/application/controllers/mockup/process/resultvalidation-v22xx/Re_px.php @@ -1,2495 +1,2492 @@ -db_smartone = $this->load->database("onedev", true); - $this->load->helper(array('form', 'url')); - } - function getMethodeID($natTestID) { - $sql = "select M_MethodePriorityNat_MethodeID MethodeID, Nat_MethodeName - from - m_methode_priority - join nat_methode on Nat_MethodeID = M_MethodePriorityNat_MethodeID - and Nat_MethodeIsActive = 'Y' - join m_instrumentmethode on M_InstrumentMethodeNat_MethodeID = Nat_MethodeID and M_InstrumentMethodeIsActive = 'Y' - join nat_instrument on M_InstrumentMethodeNat_InstrumentID = Nat_InstrumentID - and Nat_InstrumentIsActive ='Y' - where M_MethodePriorityIsActive = 'Y' - and M_MethodePriorityNat_TestID = $natTestID - and M_MethodePriorityM_DayOfWeekID = dayofweek(now()) - order by M_MethodePriorityNumber desc - limit 0,1 "; - $qry = $this->db->query($sql); - if ($qry) { - $rows = $qry->result_array(); - if (count($rows) > 0 ) return array($rows[0]["MethodeID"],$rows[0]["Nat_MethodeName"]); - } - //2nd - $sql= "select - M_InstrumentMethodeNat_MethodeID MethodeID, Nat_MethodeName - from m_instrumentmethode - join nat_methode on M_InstrumentMethodeNat_MethodeID = Nat_MethodeID - and Nat_MethodeIsActive = 'Y' - join nat_instrument on M_InstrumentMethodeNat_InstrumentID = Nat_InstrumentID - and Nat_InstrumentIsActive ='Y' - where M_InstrumentMethodeNat_TestID = $natTestID - and M_InstrumentMethodeIsActive = 'Y' - order by M_InstrumentMethodePriority desc - limit 0,1"; - $qry = $this->db->query($sql); - if ($qry) { - $rows = $qry->result_array(); - if (count($rows) > 0 ) return array($rows[0]["MethodeID"],$rows[0]["Nat_MethodeName"]); - } - // - $sql = "select Nat_NormalValueNat_MethodeID MethodeID, Nat_MethodeName - from - nat_normalvalue - join nat_methode on Nat_NormalValueNat_MethodeID = Nat_MethodeID - and Nat_MethodeIsActive = 'Y' - where Nat_NormalValueNat_TestID = $natTestID - and Nat_NormalValueIsActive = 'Y' - order by Nat_NormalValueID - limit 0,1"; - $qry = $this->db->query($sql); - if ($qry) { - $rows = $qry->result_array(); - if (count($rows) > 0 ) return array($rows[0]["MethodeID"],$rows[0]["Nat_MethodeName"]); - } - return array(0,""); - } - function get_normal_value($methodeID, $natTestID, $sexID, $ageInDay ) { - $sql = "select fn_sampling_get_normal($methodeID, $natTestID, $sexID, $ageInDay) as normalValueID"; - $qry = $this->db->query($sql); - if ($qry) { - $rows = $qry->result_array(); - if (count($rows) > 0 ) return $rows[0]["normalValueID"]; - } - return 0; - } - function fn_fix_normal($order_id) { - $sql = "select - T_OrderDetailID, M_PatientM_SexID, fn_global_age_count_day(M_PatientDOB, date(T_OrderHeaderDate)) Dob , - T_TestNat_TestID - from t_orderheader - join m_patient on T_OrderHeaderID = $order_id and T_OrderHeaderM_PatientID = M_PatientID - join t_orderdetail on T_OrderDetailT_OrderHeaderID = T_OrderHeaderID - and T_OrderDetailIsACtive = 'Y' - and ( T_OrderDetailNat_NormalValueID is null or T_OrderDetailNat_NormalValueID = 0 ) - join t_test on T_OrderDetailT_TestID = T_TestID and T_TestIsResult = 'Y' "; - $qry = $this->db->query($sql); - if(! $qry) { - return; - } - $rows = $qry->result_array(); - if(count($rows) == 0 ) return; - $sql_u = "update t_orderdetail - join nat_normalvalue on T_OrderDetailID = ? and Nat_NormalValueID = ? - set - T_OrderDetailNat_NormalValueID = Nat_NormalValueID, - T_OrderDetailNormalValueNote = Nat_NormalValueNote, - T_OrderDetailNormalValueDescription = Nat_NormalValueDescription, - T_OrderDetailMinValue = Nat_NormalValueMinValue, - T_OrderDetailMaxValue = Nat_NormalValueMaxValue, - T_OrderDetailMinValueInclusive = Nat_NormalValueMinValueInclusive, - T_OrderDetailMaxValueInclusive = Nat_NormalValueMaxValueInclusive, - T_OrderDetailNat_MethodeID = ?, - T_OrderdetailNat_MethodeName =?"; - - foreach($rows as $r) { - $T_OrderDetailID = $r["T_OrderDetailID"]; - $sexID = $r["M_PatientM_SexID"]; - $ageInDay = $r["Dob"]; - $natTestID = $r["T_TestNat_TestID"]; - list($methodeID,$methodeName) = $this->getMethodeID($natTestID); - if ($methodeID == 0 ) continue; - $normalValueID = $this->get_normal_value($methodeID, $natTestID, $sexID, $ageInDay); - if ($normalValueID == 0) return; - $this->db->query($sql_u, array($T_OrderDetailID, $normalValueID, $methodeID, $methodeName)); - } - } - function update_order_sample($targetID, $sourceID) { - $sql = "update t_ordersample target - join t_ordersample source on - target.T_OrderSampleID = ? - and target.T_OrderSampleWorklistReceive = 'N' - and source.T_OrderSampleID = ? - set - target.T_OrderSampleSampling = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSampling, source.T_OrderSampleSampling), - target.T_OrderSampleSamplingDate = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingDate, source.T_OrderSampleSamplingDate), - target.T_OrderSampleSamplingTime = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingTime, source.T_OrderSampleSamplingTime), - target.T_OrderSampleSamplingUserID = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingUserID, source.T_OrderSampleSamplingUserID), - - target.T_OrderSampleReceive = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceive, source.T_OrderSampleReceive), - target.T_OrderSampleReceiveDate = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveDate, source.T_OrderSampleReceiveDate), - target.T_OrderSampleReceiveTime = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveTime, source.T_OrderSampleReceiveTime), - target.T_OrderSampleReceiveUserID = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveUserID, source.T_OrderSampleReceiveUserID), - - target.T_OrderSampleVerification = if(target.T_OrderSampleVerification='Y',target.T_OrderSampleVerification, source.T_OrderSampleVerification), - target.T_OrderSampleVerificationDate =if(target.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationDate, source.T_OrderSampleVerificationDate), - target.T_OrderSampleVerificationTime =if(source.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationTime, source.T_OrderSampleVerificationTime), - target.T_OrderSampleVerificationUserID =if(source.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationUserID, source.T_OrderSampleVerificationUserID), - - target.T_OrderSampleProcessing = if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessing, source.T_OrderSampleProcessing), - target.T_OrderSampleProcessingDate= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingDate, source.T_OrderSampleProcessingDate), - target.T_OrderSampleProcessingTime= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingTime, source.T_OrderSampleProcessingTime), - target.T_OrderSampleProcessingUserID= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingUserID, source.T_OrderSampleProcessingUserID), - - target.T_OrderSampleReceiveHandling =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandling, source.T_OrderSampleReceiveHandling ), - target.T_OrderSampleReceiveHandlingDate =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingDate, source.T_OrderSampleReceiveHandlingDate), - target.T_OrderSampleReceiveHandlingTime =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingTime, source.T_OrderSampleReceiveHandlingTime), - target.T_OrderSampleReceiveHandlingUserID =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingUserID, source.T_OrderSampleReceiveHandlingUserID), - - target.T_OrderSampleHandling = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandling, source.T_OrderSampleHandling), - target.T_OrderSampleHandlingDate = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingDate, source.T_OrderSampleHandlingDate), - target.T_OrderSampleHandlingTime = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingTime, source.T_OrderSampleHandlingTime), - target.T_OrderSampleHandlingUserID = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingUserID, source.T_OrderSampleHandlingUserID), - - target.T_OrderSampleWorklistReceive = source.T_OrderSampleWorklistReceive, - target.T_OrderSampleWorklistReceiveDatetime = source.T_OrderSampleWorklistReceiveDateTime, - target.T_OrderSampleWorklistReceiveUserID = source.T_OrderSampleWorklistReceiveUserID - "; - $qry = $this->db->query($sql,array($targetID,$sourceID)); - if(! $qry ) { - echo json_encode(array( "status" => "ERR" , "message" => print_r($this->db->error(),true))); - exit; - } - } - function fix_sample_serum($headerID) { - //cari t_ordersample yg belum worklist receive dengan code 017% - $sql = "select T_OrderSampleID - from t_ordersample - join t_sampletype on - T_OrderSampleT_OrderHeaderID = ? - and T_OrderSampleWorklistReceive = 'N' - and T_OrderSampleIsActive = 'Y' - and T_OrderSampleT_SampleTypeID = T_SampletypeID - and T_SampleTypeCode like '017%' - "; - $qry = $this->db->query($sql, array($headerID)); - if(!$qry) { - echo json_encode(array( "status" => "ERR" , "message" => print_r($this->db->error(),true))); - exit; - } - $rows = $qry->result_array(); - if (count($rows) == 0 ) return; - //cari T_OrderSample yang sudah di receive yg terakhir - $sql = "select T_OrderSampleID - from t_ordersample - join t_sampletype on - T_OrderSampleT_OrderHeaderID = ? - and T_OrderSampleWorklistReceive = 'Y' - and T_OrderSampleIsActive = 'Y' - and T_OrderSampleT_SampleTypeID = T_SampletypeID - and T_SampleTypeCode like '017%' - order by T_OrderSampleWorklistReceiveDatetime desc - limit 0,1 - "; - $qry = $this->db->query($sql, array($headerID)); - if(!$qry) { - echo json_encode(array( "status" => "ERR" , "message" => print_r($this->db->error(),true))); - exit; - } - $rcv_rows = $qry->result_array(); - if (count($rcv_rows) == 0 ) return; - - //print_r($rows); - //print_r($rcv_rows); - $rcv_T_OrderSampleID = $rcv_rows[0]["T_OrderSampleID"]; - //ada yg belum di receive - foreach($rows as $r) { - $T_OrderSampleID = $r["T_OrderSampleID"]; - $this->update_order_sample($T_OrderSampleID,$rcv_T_OrderSampleID); - } - } - public function search() - { - $prm = $this->sys_input; - $max_rst = 99; - - $id = $prm["order_id"]; - if ($id > 0 ) { - $this->fix_sample_serum($id); - $this->fn_fix_normal($id); - } - $lang = $this->lang_default_code; - $lang_id = isset($prm['lang_id']) ? $prm['lang_id'] : '0'; - - if ($lang_id != 0) - { - $l = $this->db_smartone->where("Nat_LangID", $lang_id)->get("nat_lang")->row(); - $lang = $l->Nat_LangCode; - } - - //tambahan fajri - $sql = " UPDATE t_orderdetail - JOIN t_test ON T_OrderDetailT_TestID = T_TestID - SET T_OrderDetailT_TestIsResult = T_TestIsResult - WHERE - T_OrderDetailT_OrderHeaderID = {$id} AND - T_OrderDetailT_TestIsResult = '' AND - T_OrderDetailIsActive = 'Y'"; - $this->db_smartone->query($sql); - - $tot_count = 0; - $lq = ""; - $group_id = 0; - if (isset($prm['group_id'])) - $group_id = $prm['group_id']; - - if ($group_id != 0) - { - $sql = "select distinct T_WorklistDetailNat_TestID Nat_TestID - from t_worklistdetailv2 - where T_WorklistDetailT_WorklistID = {$group_id}"; - $qry = $this->db_smartone->query($sql); - $rows = $qry->result_array(); - $nat_test_ids = "0"; - foreach($rows as $r) { - $nat_test_ids .= ", " . $r["Nat_TestID"]; - } - $q_group = " ( $nat_test_ids ) "; - - $sql = " - SELECT a1.*, cOUNT(a2.T_OrderDetailID) level - FROM ( - SELECT IFNULL(y.T_OrderDetailT_TestID, x.T_OrderDetailT_TestID) t_testid, - IFNULL(y.T_OrderDetailT_TestName, y.T_OrderDetailT_TestName) t_testname, - y.T_OrderDetailResult result, y.T_OrderDetailResult result_old, y.T_OrderDetailNote note, y.T_OrderDetailNote note_old, - y.T_OrderDetailID id, - y.T_OrderDetailT_TestIsResult is_result, a.T_TestIsQuantitative is_quantitative, - y.T_OrderDetailResultFlag result_flag, - y.T_OrderDetailNat_NormalValueID normal_id, - y.T_OrderDetailNormalValueNote normal_note, y.T_OrderDetailNat_UnitName unit_name, - y.T_OrderdetailNat_MethodeID methode_id, y.T_OrderdetailNat_MethodeName methode_name, - a.T_TestNat_TestID nattest_id, a.T_TestID tx_id, count(T_ResultInstrumentID) as result_instrument_n, - y.T_OrderDetailVerification, T_OrderSampleReceive sample_receive, - T_OrderSampleProcessing sample_processing, T_OrderSampleWorklistReceive sample_worklist_receive, - IF(T_OrderDetailAddOnPreAnalytic = 'Y', T_OrderDetailAddOnPreAnalytic, PreAnalyticIsOk) pre_analytic, - T_OrderDetailAddOnPreAnalytic, - T_OrderHeaderID order_id, y.T_OrderDetailT_TestSasCode test_sas_code, - tx.T_TestSasCode, - T_OrderDetailAddOnResample `resample`, T_OrderDetailAddOnResampleStatus resample_status, - T_OrderDetailAddOnRef ref, y.T_OrderDetailVerification verification, y.T_OrderDetailValidation validation, - T_OrderPromiseDateTime, Group_ResultName as ResultGroupName - FROM t_orderdetail x - left join t_orderpromise on x.T_OrderDetailT_OrderPromiseID = T_OrderPromiseID - JOIN t_test tx ON x.T_OrderDetailT_TestID = T_TestID - JOIN t_test tcheck on tcheck.T_TestNat_TestID in {$q_group} - and ( tx.T_TestID = tcheck.T_TestID or tx.T_TestSasCode like concat(tcheck.T_TestSasCode,'%')) - LEFT JOIN group_resultdetail ON Group_ResultDetailT_TestID = x.T_OrderDetailT_TestID AND Group_ResultDetailIsActive = 'Y' - LEFT JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND Group_ResultFlagNonLab = 'N' - LEFT JOIN t_orderdetail y ON x.T_OrderDetailT_TestSasCode LIKE CONCAT(y.T_OrderDetailT_TestSasCode, '%') - AND x.T_OrderDetailT_OrderHeaderID = y.T_OrderDetailT_OrderHeaderID - AND y.T_OrderDetailIsActive = 'Y' - LEFT JOIN t_orderdetailaddon ON x.T_OrderDetailID = T_OrderDetailAddOnT_OrderDetailID - JOIN t_orderheader ON y.T_OrderDetailT_OrderHeaderID = T_OrderHeaderID - LEFT JOIN t_test a ON y.T_OrderDetailT_TestID = a.T_TestID - AND a.T_TestIsNonLab = '' - LEFT JOIN (SELECT T_OrderSampleT_SampleTypeID, T_OrderSampleReceive, T_OrderSampleProcessing, T_OrderSampleWorklistReceive - FROM t_ordersample WHERE T_OrderSampleT_OrderHeaderID = {$id} - AND T_OrderSampleIsactive = 'Y' - GROUP BY T_OrderSampleT_SampleTypeID) os ON a.T_TestT_SampleTypeID = os.T_OrderSampleT_SampleTypeID - or os.T_OrderSampleT_SampleTypeID = fn_sampletype_from_local(a.T_TestNat_TestID) - - LEFT JOIN t_resultinstrument ON T_ResultInstrumentT_OrderDetailID = x.T_OrderDetailID - LEFT JOIN pre_analytic ON PreAnalyticNat_TestID = a.T_TestNat_TestID AND PreAnalyticDate = date(now()) and PreAnalyticIsActive = 'Y' - WHERE x.T_OrderDetailT_OrderHeaderID = {$id} - AND x.T_OrderDetailIsActive = 'Y' - GROUP BY y.T_OrderDetailT_TestID - ORDER BY y.T_OrderDetailT_TestSasCode ASC - ) a1 - - LEFT JOIN t_orderdetail a2 ON a2.T_OrderDetailT_OrderHeaderID = a1.order_id - AND a2.T_OrderDetailIsActive = 'Y' - AND a1.test_sas_code LIKE CONCAT(a2.T_OrderDetailT_testSasCode, '%') - GROUP BY a1.t_testid - order by a1.test_sas_code -"; - $query = $this->db_smartone->query($sql); - $lq = $this->db_smartone->last_query(); - } - else - { - $sql = " - SELECT a1.*, cOUNT(a2.T_OrderDetailID) level - FROM ( - SELECT IFNULL(y.T_OrderDetailT_TestID, x.T_OrderDetailT_TestID) t_testid, - IFNULL(y.T_OrderDetailT_TestName, y.T_OrderDetailT_TestName) t_testname, - y.T_OrderDetailResult result, y.T_OrderDetailResult result_old, y.T_OrderDetailNote note, y.T_OrderDetailNote note_old, - y.T_OrderDetailID id, - y.T_OrderDetailT_TestIsResult is_result, a.T_TestIsQuantitative is_quantitative, - y.T_OrderDetailResultFlag result_flag, - y.T_OrderDetailNat_NormalValueID normal_id, - y.T_OrderDetailNormalValueNote normal_note, y.T_OrderDetailNat_UnitName unit_name, - y.T_OrderdetailNat_MethodeID methode_id, y.T_OrderdetailNat_MethodeName methode_name, - a.T_TestNat_TestID nattest_id, a.T_TestID tx_id, count(T_ResultInstrumentID) as result_instrument_n, - y.T_OrderDetailVerification, T_OrderSampleReceive sample_receive, - T_OrderSampleProcessing sample_processing, T_OrderSampleWorklistReceive sample_worklist_receive, - IF(T_OrderDetailAddOnPreAnalytic = 'Y', T_OrderDetailAddOnPreAnalytic, PreAnalyticIsOk) pre_analytic, - T_OrderDetailAddOnPreAnalytic, - T_OrderHeaderID order_id, y.T_OrderDetailT_TestSasCode test_sas_code, - tx.T_TestSasCode, - T_OrderDetailAddOnResample `resample`, T_OrderDetailAddOnResampleStatus resample_status, - T_OrderDetailAddOnRef ref, y.T_OrderDetailVerification verification, y.T_OrderDetailValidation validation, - T_OrderPromiseDateTime , Group_ResultName as ResultGroupName - FROM t_orderdetail x - left join t_orderpromise on x.T_OrderDetailT_OrderPromiseID = T_OrderPromiseID - JOIN t_test tx ON x.T_OrderDetailT_TestID = T_TestID - LEFT JOIN group_resultdetail ON Group_ResultDetailT_TestID = x.T_OrderDetailT_TestID AND Group_ResultDetailIsActive = 'Y' - LEFT JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND Group_ResultFlagNonLab = 'N' - LEFT JOIN t_orderdetail y ON x.T_OrderDetailT_TestSasCode LIKE CONCAT(y.T_OrderDetailT_TestSasCode, '%') - AND x.T_OrderDetailT_OrderHeaderID = y.T_OrderDetailT_OrderHeaderID - AND y.T_OrderDetailIsActive = 'Y' - - LEFT JOIN t_orderdetailaddon ON x.T_OrderDetailID = T_OrderDetailAddOnT_OrderDetailID - - JOIN t_orderheader ON y.T_OrderDetailT_OrderHeaderID = T_OrderHeaderID - LEFT JOIN t_test a ON y.T_OrderDetailT_TestID = a.T_TestID - AND a.T_TestIsNonLab = '' - LEFT JOIN (SELECT T_OrderSampleT_SampleTypeID, T_OrderSampleReceive, T_OrderSampleProcessing, T_OrderSampleWorklistReceive - FROM t_ordersample WHERE T_OrderSampleT_OrderHeaderID = {$id} - AND T_OrderSampleIsactive = 'Y' - GROUP BY T_OrderSampleT_SampleTypeID) os ON a.T_TestT_SampleTypeID = os.T_OrderSampleT_SampleTypeID - or os.T_OrderSampleT_SampleTypeID = fn_sampletype_from_local(a.T_TestNat_TestID) - - LEFT JOIN t_resultinstrument ON T_ResultInstrumentT_OrderDetailID = x.T_OrderDetailID - LEFT JOIN pre_analytic ON PreAnalyticNat_TestID = a.T_TestNat_TestID AND PreAnalyticDate = date(now()) and PreAnalyticIsActive = 'Y' - WHERE x.T_OrderDetailT_OrderHeaderID = {$id} - AND x.T_OrderDetailIsActive = 'Y' - GROUP BY y.T_OrderDetailT_TestID - ORDER BY y.T_OrderDetailT_TestSasCode ASC - ) a1 - - LEFT JOIN t_orderdetail a2 ON a2.T_OrderDetailT_OrderHeaderID = a1.order_id - AND a2.T_OrderDetailIsActive = 'Y' - AND a1.test_sas_code LIKE CONCAT(a2.T_OrderDetailT_testSasCode, '%') - GROUP BY a1.t_testid - order by a1.test_sas_code -"; -//echo $sql; - $query = $this->db_smartone->query($sql); - $lq = $this->db_smartone->last_query(); - } - // file_put_contents("/xtmp/re-query.sql",$lq); - - if ($query) { - $rst = []; - $rows = $query->result_array(); - - foreach($rows as $k => $v) - { - - if ($v['is_result'] == "Y" && $v['is_quantitative'] == "N") - { - $v['template'] = []; - $x = $this->db_smartone->query("CALL sp_master_resulttemplate_get('{$v['t_testid']}')"); - $this->clean_mysqli_connection($this->db_smartone->conn_id); - if ($x) - $v['template'] = $x->result_array(); - } - - // IF Rujukan, by pas Pre Analytik - if ($v['ref'] == 'Y') - $v['pre_analytic'] = 'Y'; - if ($v["id"] == "885455" ) - { - //sipe workaround - //$v["sample_receive"] = "Y"; - $v["sample_worklist_receive"] = "Y"; - } - $rst[] = $v; - } - - $result = array("total" => $tot_count, "records" => $rst, "total_display" => sizeof($rows), "q" => $lq); - $this->sys_ok($result); - } - else { - $this->sys_error_db("RE Px rows", $this->db_smartone); - exit; - } - } - - public function save() - { - $prm = $this->sys_input; - $data = json_decode($prm["data"]); - $lang = $this->lang_default_code; - $lang_id = isset($prm['lang_id']) ? $prm['lang_id'] : '0'; - - if ($lang_id != 0) - { - $l = $this->db_smartone->where("Nat_LangID", $lang_id)->get("nat_lang")->row(); - $lang = $l->Nat_LangCode; - } - - $sql_norm = "select T_OrderDetailMinValue, T_OrderDetailMaxValue, - T_OrderDetailMinValueInclusive, T_OrderDetailMaxValueInclusive, - Nat_TestFlagLow, Nat_TestFlagHigh - from t_orderdetail - join t_test on T_OrderDetailT_TestID = T_TestID - join nat_test on T_TestNat_TestID = Nat_TestID and T_TestIsActive = 'Y' - where T_OrderDetailID = ? "; - - $ids = []; - foreach ($data as $k => $v) - { - if ( $v->resultInstrumentID > 0 ) { - $sql_i = "select T_ResultInstrumentNat_NormalValueID normalValueID - from t_resultinstrument - where T_ResultInstrumentID = ?"; - $qry_i = $this->db_smartone->query($sql_i, array($v->resultInstrumentID)); - if ($qry_i) { - $rows_i = $qry_i->result_array(); - - if (count($rows_i) > 0 ) { - $sql_iu = "update t_orderdetail, nat_normalvalue , nat_methode - set T_OrderDetailMinValue = Nat_NormalValueMinValue, - T_OrderDetailMinValueInclusive = Nat_NormalValueMinValueInclusive, - T_OrderDetailMaxValue = Nat_NormalValueMaxValue , - T_OrderDetailMaxValueInclusive = Nat_NormalValueMaxValueInclusive, - T_OrderDetailNormalValueNote = Nat_NormalValueNote, - T_OrderDetailNormalValueDescription = Nat_NormalValueDescription, - T_OrderDetailNat_NormalValueID = Nat_NormalValueID, - T_OrderDetailNat_MethodeID = Nat_NormalValueNat_MethodeID, - T_OrderDetailNat_MethodeName = Nat_MethodeName - where T_OrderDetailID = ? and Nat_NormalValueID = ? - and Nat_NormalValueNat_MethodeID = Nat_MethodeID - "; - $this->db_smartone->query($sql_iu, array($v->id, $rows_i[0]["normalValueID"])); - //file_put_contents("/xtmp/update-nilai-normal", $this->db_smartone->last_query() . "\n", FILE_APPEND); - } - } - } - $y = $this->db_smartone->query("SELECT fn_process_sample_handling_perfect('{$v->order_id}', '{$v->test_id}') c") - ->row(); - $req_status = $y->c; - $qry_norm = $this->db_smartone->query($sql_norm,$v->id); - $result_flag = ""; - if ($qry_norm) { - $rows_norm = $qry_norm->result_array(); - if (count($rows_norm) > 0 ) { - $r = $rows_norm[0]; - if (is_numeric($v->result)) { - - if ( $r["T_OrderDetailMinValueInclusive"] == "Y" && $v->result < $r["T_OrderDetailMinValue"] ) { - $result_flag = $r["Nat_TestFlagLow"]; - } - if ( $r["T_OrderDetailMinValueInclusive"] == "N" && $v->result <= $r["T_OrderDetailMinValue"] ) { - $result_flag = $r["Nat_TestFlagLow"]; - } - if ( $r["T_OrderDetailMaxValueInclusive"] == "Y" && $v->result > $r["T_OrderDetailMaxValue"] ) { - $result_flag = $r["Nat_TestFlagHigh"]; - } - if ( $r["T_OrderDetailMaxValueInclusive"] == "N" && $v->result >= $r["T_OrderDetailMaxValue"] ) { - $result_flag = $r["Nat_TestFlagHigh"]; - } - } - } - } - if ($lang == $this->lang_default_code) - { - $this->db_smartone->set('T_OrderDetailResult', $v->result) - ->set('T_OrderDetailResultFlag', $result_flag) - ->set('T_OrderDetailNote', $v->note) - ->set('T_OrderDetailReqStatus', $req_status) - ->where('T_OrderDetailID', $v->id) - ->update('t_orderdetail'); - } - else - { - $this->db_smartone->set('T_OrderDetailLangResult', $v->result) - ->set('T_OrderDetailLangNote', $v->note) - ->where('T_OrderDetailLangID', $v->id) - ->update('t_orderdetaillang'); - } - - $ids[] = $v->id; - } - - // LOG Process - $order = $this->db_smartone->select('T_OrderDetailT_OrderHeaderID id, T_OrderHeaderLabNumber lab_number', false) - ->join('t_orderheader', 'T_OrderHeaderID = T_OrderDetailT_OrderHeaderID') - ->where('T_OrderDetailID', $data[0]->id) - ->get('t_orderdetail') - ->row(); - - $dblog = $this->load->database("onelog", true); - $dblog->set('Log_ProcessCode', 'PROCESS.Result.Entry') - ->set('Log_ProcessOrderID', $order->id) - ->set('Log_ProcessOrderNumber', $order->lab_number) - ->set('Log_ProcessJson', json_encode($data)) - ->set('Log_ProcessUserID', $this->sys_user['M_UserID']) - ->insert('log_process'); - // END OF Log Process - //auto calculation - $this->load->library("Resultcalc"); - $rows = $this->resultcalc->auto($order->id); - - try { - foreach($ids as $id ) { - $this->db_smartone->query("call sp_set_normal_value_flag($id)"); - $this->clean_mysqli_connection($this->db_smartone->conn_id); - } - } catch(Exception $e) { - } - - $this->sys_ok($ids); - } - - public function save_template() - { - $prm = $this->sys_input; - - $n = $this->db_smartone->select("COUNT(T_ResultTemplateID) n") - ->where("T_ResultTemplateT_TestID", $prm['test_id']) - ->where("T_ResultTemplateIsActive", "Y") - ->where("T_ResultTemplateValue", $prm['value']) - ->get('t_resulttemplate') - ->row(); - if ($n->n > 0) - { - $this->sys_error_db("Insert Result Template", $this->db_smartone); - return; - } - - $r = $this->db_smartone->set("T_ResultTemplateT_TestID", $prm['test_id']) - ->set("T_ResultTemplateValue", $prm['value']) - ->insert('t_resulttemplate'); - if ($r) - { - $template = []; - $x = $this->db_smartone->query("CALL sp_master_resulttemplate_get('{$prm['test_id']}')"); - $this->clean_mysqli_connection($this->db_smartone->conn_id); - if ($x) - $template = $x->result_array(); - - $this->sys_ok($template); - } - } - - public function export() - { - $prm = $this->sys_input; - - $sql = "CALL sp_process_result_lang(?, ?, ?, ?)"; - $query = $this->db_smartone->query($sql, [$prm['order_id'], $prm['lang_id'], $prm['is_si'], $this->sys_user['M_UserID']]); - if ($query) - { - $r = $query->row(); - if ($r->status == "OK") - { - $this->sys_ok($r->data); - return; - } - - $this->sys_error_db("Message : " . $r->message, $this->db_smartone); - } - else - { - $this->sys_error_db("Lang Result", $this->db_smartone); - return; - } - } - - public function search_group() - { - $prm = $this->sys_input; - $max_rst = 100; - - // QUERY TOTAL - $sql = "select count(*) total - from t_worklist - where T_WorklistIsActive = 'Y' - order by T_WorklistName ASC"; - $query = $this->db_smartone->query($sql); - - if ($query) { - $tot_count = $query->result_array()[0]["total"]; - } - else { - $this->sys_error_db("worklist count", $this->db_smartone); - exit; - } - - $sql = "select T_WorklistID group_id, T_WorklistName group_name - from t_worklist - where T_WorklistIsActive = 'Y' - order by T_WorklistName ASC - limit 0, {$max_rst}"; - $query = $this->db_smartone->query($sql); - - if ($query) { - $rows = $query->result_array(); - foreach ($rows as $k => $v) - $rows[$k]['data'] = json_decode($v['data']); - $result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows), "q" => $this->db_smartone->last_query()); - $this->sys_ok($result); - } - else { - $this->sys_error_db("worklist rows", $this->db_smartone); - exit; - } - } - - public function search_rerun() - { - $prm = $this->sys_input; - $id = $prm["detail_id"]; - - $sql = "CALL sp_process_result_rerun(?)"; - $query = $this->db_smartone->query($sql, [$id]); - - if ($query) - { - $rows = $query->result_array(); - $this->sys_ok(["records"=>$rows]); - } - else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - - - function getdoctorsfna() - { - $prm = $this->sys_input; - // $id = $prm["id"]; - - $sql = " SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY M_DoctorName ASC"; - //echo $sql; - $query = $this->db_smartone->query($sql); - - if ($query) - { - $rows = $query->result_array(); - $this->sys_ok(["records"=>$rows]); - } - else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - function getfnaresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT Other_FNADetailsID as xid, - Other_FNAT_OrderDetailID as orderdetail_id, - Other_FNADetailsCode as code, - Other_FNADetailsLabel as label, - Other_FNADetailsResult as result, - IFNULL(Other_FNAM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_FNAM_DoctorID) OR Other_FNAM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_fna - JOIN other_fnadetails ON Other_FNADetailsOther_FNAID = Other_FNAID AND Other_FNADetailsIsActive = 'Y' - LEFT JOIN m_doctor ON Other_FNAM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_FNAT_OrderDetailID = {$id} AND Other_FNAIsActive = 'Y' - GROUP BY Other_FNADetailsID - ORDER BY Other_FNADetailsCode ASC"; - $query = $this->db_smartone->query($sql); - - if ($query) - { - $rows = $query->result_array(); - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $images = array(); - $sql = "SELECT So_ImageUploadID as xid, - CONCAT('/one-media/one-image-nonlab/',So_ImageUploadNewName) as image_url - FROM t_orderdetail - JOIN so_imageupload ON So_ImageUploadT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND - So_ImageUploadIsActive = 'Y' - WHERE - T_OrderDetailID = {$id} AND - T_OrderDetailIsActive = 'Y' - GROUP BY So_ImageUploadID"; - $images = $this->db_smartone->query($sql)->result_array(); - - $rst = array('doctors'=>$doctors,'results'=>$rows,'images'=>$images); - $this->sys_ok(["records"=>$rst]); - } - else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - - function uploadimage(){ - if (! $this->isLogin) { - $this->sys_error("Invalid Token"); - exit; - } - - $userid = $this->sys_user["M_UserID"]; - $data = []; - //print_r($_SERVER); - - $prm = $this->sys_input; - $orderid = $this->input->post('orderid'); - $labnumber = $this->input->post('labnumber'); - $sql = "UPDATE so_imageupload SET - So_ImageUploadIsActive = 'N', - So_ImageUploadUserID = {$userid} - WHERE - So_ImageUploadT_OrderHeaderID = {$orderid}"; - //echo $sql; - $this->db_onedev->query($sql); - //$config['upload_path'] = 'assets/'; - - $path = '/home/one/project/one/one-media/one-image-nonlab/'; - //echo $path; - $config['upload_path'] = $path; - $config['allowed_types'] = 'jpg|jpeg|png|gif'; - - $config['max_size'] = '10000'; - $count = count($_FILES['files']['name']); - //echo $count; - $this->load->library('upload',$config); - - $error = []; - for($i=0;$i<$count;$i++){ - - - if(!empty($_FILES['files']['name'][$i])){ - - - - $_FILES['file']['name'] = $_FILES['files']['name'][$i]; - - $_FILES['file']['type'] = $_FILES['files']['type'][$i]; - - $_FILES['file']['tmp_name'] = $_FILES['files']['tmp_name'][$i]; - - $_FILES['file']['error'] = $_FILES['files']['error'][$i]; - - $_FILES['file']['size'] = $_FILES['files']['size'][$i]; - - - - $namex = $orderid.'-'.$labnumber.'-'.$this->generateRandomString(5); - //echo $namex; - - $config['file_name'] = $namex; - $this->upload->initialize($config); - //echo $config['file_name'] ; - - - - - - if($this->upload->do_upload('file')){ - - $uploadData = $this->upload->data(); - - $filename = $uploadData['file_name']; - //echo $filename; - - - $sql = "INSERT INTO so_imageupload ( - So_ImageUploadT_OrderHeaderID, - So_ImageUploadT_OrderHeaderLabNumber, - So_ImageUploadT_SampleTypeID, - So_ImageUploadOldName, - So_ImageUploadNewName, - So_ImageUploadCreated, - So_ImageUploadUserID - ) - VALUES( - {$orderid}, - '{$labnumber}', - '150', - '{$_FILES['files']['name'][$i]}', - '{$filename}', - NOW(), - {$userid} - - )"; - //echo $sql; - $this->db_onedev->query($sql); - $xlast_id = $this->db_onedev->insert_id(); - $data['totalFiles'][] = array('xid' => $xlast_id ,'image_url' => '/one-media/one-image-nonlab/'.$filename); - - } - else{ - $error = array('error' => $this->upload->display_errors()); - } - - } - - - - } - - $result = array("total" =>count( $data['totalFiles']), "records" => $data['totalFiles'],'errors'=>$error); - $this->sys_ok($result); - } - - - function generateRandomString($length = 10) { - $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; - $charactersLength = strlen($characters); - $randomString = ''; - for ($i = 0; $i < $length; $i++) { - $randomString .= $characters[rand(0, $charactersLength - 1)]; - } - return $randomString; - } - - function getcytologiresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT Other_CytologiDetailsID as xid, - Other_CytologiT_OrderDetailID as orderdetail_id, - Other_CytologiDetailsCode as code, - Other_CytologiDetailsLabel as label, - Other_CytologiDetailsResult as result, - IFNULL(Other_CytologiM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_CytologiM_DoctorID) OR Other_CytologiM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_cytologi - JOIN other_cytologidetails ON Other_CytologiDetailsOther_CytologiID = Other_CytologiID AND Other_CytologiDetailsIsActive = 'Y' - LEFT JOIN m_doctor ON Other_CytologiM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_CytologiT_OrderDetailID = {$id} AND Other_CytologiIsActive = 'Y' - GROUP BY Other_CytologiDetailsID - ORDER BY Other_CytologiDetailsCode ASC"; - //echo $sql; - $query = $this->db_smartone->query($sql); - - if ($query) - { - $rows = $query->result_array(); - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $rst = array('doctors'=>$doctors,'results'=>$rows); - $this->sys_ok(["records"=>$rst]); - } - else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - function getmikroresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT - Other_MikroID as xid, - Other_MikroHasilBiakan as hasil_biakan, - Other_MikroSampleTypeName as sample_name, - Other_MikroT_OrderDetailID as orderdetail_id, - Other_MikroResult as result_value, - '' as result_other, - IFNULL(T_BacteriaID,0) as T_BacteriaID, - IFNULL(T_BacteriaName,'') as T_BacteriaName, - '' as details, - IFNULL(Other_MikroM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_MikroM_DoctorID) OR Other_MikroM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_mikro - LEFT JOIN t_bacteria ON Other_MikroT_BacteriaID = T_BacteriaID - LEFT JOIN m_doctor ON Other_MikroM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_MikroT_OrderDetailID = {$id} AND Other_MikroIsActive = 'Y' - GROUP BY Other_MikroID"; - //echo $sql; - $query = $this->db_smartone->query($sql); - - if ($query) - { - $row = $query->row_array(); - if($row){ - if($row['result_value'] != 'Positif' && $row['result_value'] != 'Negatif'){ - $row['result_other'] = $row['result_value']; - $row['result_value'] = 'other'; - } - $sql = "SELECT '' as xno, - Other_MikroDetailsID as xid, - Other_MikroDetailsValue as value, - IF(Other_MikroDetailsNote = 'R','Y','N') as chx_r, - IF(Other_MikroDetailsNote = 'I','Y','N') as chx_i, - IF(Other_MikroDetailsNote = 'S','Y','N') as chx_s, - Other_MikroDetailsNote as note, - t_antibiotic.* - FROM other_mikrodetails - LEFT JOIN t_antibiotic ON Other_MikroDetailsT_AntibioticID = T_AntibioticID - WHERE - Other_MikroDetailsOther_MikroID = {$row['xid']} AND Other_MikroDetailsIsActive = 'Y' - GROUP BY Other_MikroDetailsID - ORDER BY T_AntibioticName ASC"; - //echo $sql; - $details = $this->db_smartone->query($sql)->result_array(); - if(details){ - foreach($details as $k => $v){ - $details[$k]['xno'] = $k + 1; - } - } - $row['details'] = $details; - } - else{ - $row = array('xid'=>'0','hasil_biakan' => '','result_value'=>'Negatif','sample_name' => '','orderdetail_id'=>$id, 'T_BacteriaID'=>'0','T_BacteriaName'=>'0','details'=>array(),'doctor_id'=>'0','doctor_name'=>'0'); - } - } - else{ - $row = array('xid'=>'0','hasil_biakan' => '','result_value'=>'Negatif','sample_name' => '','orderdetail_id'=>$id, 'T_BacteriaID'=>'0','T_BacteriaName'=>'0','details'=>array(),'doctor_id'=>'0','doctor_name'=>'0'); - } - //print_r($row); - - - - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 7 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $sql = " - SELECT '0' as id, 'Belum memilih bakteria' as name - UNION - SELECT T_BacteriaID as id, T_BacteriaName as name - FROM t_bacteria - WHERE - T_BacteriaIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $bacteries = $this->db_smartone->query($sql)->result_array(); - $rst = array('doctors'=>$doctors,'bacteries'=>$bacteries,'results'=>$row); - $this->sys_ok(["records"=>$rst]); - } - function getantibiotics(){ - $prm = $this->sys_input; - $id = $prm["id"]; - $sql = " SELECT '' as xno, - 0 as xid, - '' as hasil_biakan, - '' as sample_name, - 0 as value, - 'Y' as chx_r, - 'N' as chx_i, - 'N' as chx_s, - 'R' as note, - t_antibiotic.* - FROM t_antibiotic - WHERE - T_AntibioticT_BacteriaID = {$prm['id']} AND T_AntibioticIsActive= 'Y' - ORDER BY T_AntibioticName ASC"; - //echo $sql; - $rows = $this->db_smartone->query($sql)->result_array(); - if(rows){ - foreach($rows as $k => $v){ - $rows[$k]['xno'] = $k + 1; - } - } - - $this->sys_ok(["records"=>$rows]); - } - function getlcprepresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - $sql = " SELECT Other_LcprepDetailsID as xid, - Other_LcprepID as header_id, - Other_LcprepT_orderDetailID as orderdetail_id, - Other_LcprepDetailsCode as code, - Other_LcprepDetailsLabel as label, - Other_LcprepDetailsResult as result, - IFNULL(Other_LcprepM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_LcprepM_DoctorID) OR Other_LcprepM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_lcprep - JOIN other_lcprepdetails ON Other_LcprepDetailsOther_LcprepID = Other_LcprepID AND Other_LcprepDetailsIsActive = 'Y' - LEFT JOIN m_doctor ON Other_LcprepM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_LcprepT_orderDetailID = {$id} AND Other_LcprepIsActive = 'Y' - GROUP BY Other_LcprepDetailsOther_LcprepID, Other_LcprepDetailsCode - ORDER BY Other_LcprepDetailsCode ASC"; - //echo $sql; - $rows = $this->db_smartone->query($sql)->result_array(); - if(!$rows){ - $rows = array( - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'A', - 'label' => 'DESKRIPSI', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ), - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'B', - 'label' => 'KESIMPULAN', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ) - ); - } - - $header_id = $rows[0]['header_id']; - $sql = "SELECT IFNULL(Other_LcprepAdekuasiID,0) as xid, - Lcprep_AdekuasiID as id, - Lcprep_AdekuasiLabel as name, - IF(ISNULL(Other_LcprepAdekuasiID),'N',Other_LcprepAdekuasiChex) as chex - FROM lcprep_adekuasi - LEFT JOIN other_lcprepadekuasi ON Other_LcprepAdekuasiLcprep_AdekuasiID = Lcprep_AdekuasiID AND - Other_LcprepAdekuasiOther_LcprepID = {$header_id} AND - Other_LcprepAdekuasiIsActive = 'Y' - WHERE - Lcprep_AdekuasiIsActive = 'Y' - GROUP BY Lcprep_AdekuasiID - ORDER BY Lcprep_AdekuasiOrder ASC - "; - //echo $sql; - $adeakuasi = $this->db_smartone->query($sql)->result_array(); - foreach($adeakuasi as $kc => $vc){ - $adeakuasi[$kc]['chex'] = $vc['chex'] == 'N'?false:true; - } - - $sql = "SELECT IFNULL(Other_LcprepKategoriUmumID,0) as xid, - Lcprep_KategoriUmumID as id, - Lcprep_KategoriUmumLabel as name, - IF(ISNULL(Other_LcprepKategoriUmumID),'N',Other_LcprepKategoriUmumChex) as chex - FROM lcprep_kategoriumum - LEFT JOIN other_lcprepkategoriumum ON Other_LcprepKategoriUmumLcprep_KategoriUmumID = Lcprep_KategoriUmumID AND - Other_LcprepKategoriUmumOther_LcprepID = {$header_id} AND - Other_LcprepKategoriUmumIsActive = 'Y' - WHERE - Lcprep_KategoriUmumIsActive = 'Y' - GROUP BY Lcprep_KategoriUmumID - "; - //echo $sql; - $kategoriumum = $this->db_smartone->query($sql)->result_array(); - foreach($kategoriumum as $kc => $vc){ - $kategoriumum[$kc]['chex'] = $vc['chex'] == 'N'?false:true; - } - - $sql = " - SELECT Lcprep_InterpretasiGroupID as group_id, - Lcprep_InterpretasiGroupName as group_name, - '' as subgroups - FROM lcprep_interpretasigroup - WHERE - Lcprep_InterpretasiGroupIsActive = 'Y' - "; - //echo $sql; - $interpretasi = $this->db_smartone->query($sql)->result_array(); - foreach($interpretasi as $k => $v){ - $subgroups = array(); - $sql = "SELECT Lcprep_InterpretasiSubgroupID as subgroup_id, - Lcprep_InterpretasiSubgroupName as subgroup_name, - '' as childs - FROM lcprep_interpretasisubgroup - WHERE - Lcprep_InterpretasiSubgroupLcprep_InterpretasiGroupID = {$v['group_id']} AND Lcprep_InterpretasiSubgroupIsActive = 'Y'"; - //echo $sql; - $subgroups = $this->db_smartone->query($sql)->result_array(); - if(count($subgroups) > 0){ - foreach($subgroups as $ki => $vi){ - $childs = array(); - $sql = "SELECT IFNULL(Other_LcprepInterpretasiID,0) as xid, - IFNULL(Other_LcprepInterpretasiChex,'N') as chex, - IFNULL(Other_LcprepInterpretasiValue,'') as value, - Lcprep_InterpretasiID as id, - Lcprep_InterpretasiLcprep_InterpretasiSubgroupID as subgroup_id, - Lcprep_InterpretasiCode as code, - Lcprep_InterpretasiName as name, - Lcprep_InterpretasiParentID as parent_id, - Lcprep_InterpretasiIsParent as is_parent, - Lcprep_InterpretasiHasResult as has_result, - Lcprep_InterpretasiTypeResult as type_result - FROM lcprep_interpretasi - LEFT JOIN other_lcprepinterpretasi ON Other_LcprepInterpretasiOther_LcprepID = {$header_id} AND - Other_LcprepInterpretasiLcprep_InterpretasiID = Lcprep_InterpretasiID AND - Other_LcprepInterpretasiIsActive = 'Y' - WHERE - Lcprep_InterpretasiLcprep_InterpretasiSubgroupID = {$vi['subgroup_id']} AND Lcprep_InterpretasiIsActive = 'Y' - GROUP BY Lcprep_InterpretasiID Order BY Lcprep_InterpretasiCode ASC"; - $childs = $this->db_smartone->query($sql)->result_array(); - if($childs){ - foreach($childs as $kc => $vc){ - $childs[$kc]['chex'] = $vc['chex'] == 'N'?false:true; - } - } - $subgroups[$ki]['childs'] = $childs; - } - } - - $interpretasi[$k]['subgroups'] = $subgroups; - } - - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $rst = array('doctors'=>$doctors,'results'=>$rows,'adekuasi'=>$adeakuasi,'kategoriumum'=>$kategoriumum,'interpretasi'=>$interpretasi); - $this->sys_ok(["records"=>$rst]); - } - - function getpapsmearresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT Other_PapSmearDetailsID as xid, - Other_PapSmearID as header_id, - Other_PapSmearT_OrderDetailID as orderdetail_id, - Other_PapSmearDetailsCode as code, - Other_PapSmearDetailsLabel as label, - Other_PapSmearDetailsResult as result, - IFNULL(Other_PapSmearM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_PapSmearM_DoctorID) OR Other_PapSmearM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_papsmear - JOIN other_papsmeardetails ON Other_PapSmearDetailsOther_PapSmearID = Other_PapSmearID AND Other_PapSmearDetailsIsActive = 'Y' - LEFT JOIN m_doctor ON Other_PapSmearM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_PapSmearT_OrderDetailID = {$id} AND Other_PapSmearIsActive = 'Y' - GROUP BY Other_PapSmearDetailsID - ORDER BY Other_PapSmearDetailsCode ASC"; - //echo $sql; - $rows = $this->db_smartone->query($sql)->result_array(); - if(!$rows){ - $rows = array( - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'A', - 'label' => 'Makroskopik', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ), - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'B', - 'label' => 'Mikroskopik', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ), - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'C', - 'label' => 'Kesimpulan', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ) - ); - } - - $header_id = $rows[0]['header_id']; - $sql = "SELECT Other_PapSmearMaturasiID as xid, - Other_PapSmearMaturasiValue as value - FROM other_papsmearmaturasi - WHERE - Other_PapSmearMaturasiOther_PapSmearID = {$header_id} AND - Other_PapSmearMaturasiIsActive = 'Y' - "; - //echo $sql; - $dt_maturasi = $this->db_smartone->query($sql)->row_array(); - if(!$dt_maturasi){ - $maturasi = array('xid'=>'0','value'=> array('','','')); - } - else{ - $value = explode('/',$dt_maturasi['value']); - $maturasi = array('xid'=>$dt_maturasi['xid'],'value'=> $value); - } - - $sql = "SELECT IFNULL(Other_PapSmearBahanID,0) as xid, - M_PapSmearBahanID as bahan_id, - M_PapSmearBahanName as name, - IF(ISNULL(Other_PapSmearBahanID),'N','Y') as selected - FROM m_papsmearbahan - LEFT JOIN other_papsmearbahan ON Other_PapSmearBahanM_PapSmearBahanID = M_PapSmearBahanID AND - Other_PapSmearBahanOther_PapSmearID = {$header_id} AND - Other_PapSmearBahanIsActive = 'Y' - WHERE - M_PapSmearBahanIsActive = 'Y' - ORDER BY M_PapSmearBahanID ASC - "; - //echo $sql; - $bahans = $this->db_smartone->query($sql)->result_array(); - - $sql = "SELECT IFNULL(Other_PapsmearCategoryID,0) as xid, - M_PapSmearCategoryID as category_id, - M_PapSmearCategoryName as name, - IF(ISNULL(Other_PapsmearCategoryID),'N','Y') as selected - FROM m_papsmearcategory - LEFT JOIN other_papsmearcategory ON Other_PapsmearCategoryM_PapSmearCategoryID = M_PapSmearCategoryID AND - Other_PapsmearCategoryOther_PapSmearID = {$header_id} AND - Other_PapsmearCategoryIsActive = 'Y' - WHERE - M_PapSmearCategoryIsActive = 'Y' - ORDER BY M_PapSmearCategoryID ASC - "; - //echo $sql; - $categories = $this->db_smartone->query($sql)->result_array(); - - $sql = "SELECT IFNULL(Other_PapSmearCheckID,0) as xid, - M_PapSmearCheckID as check_id, - M_PapSmearCheckLabel as name, - IF(ISNULL(Other_PapSmearCheckID),'N','Y') as selected, - Other_PapSmearCheckNote as note - FROM m_papsmearcheck - LEFT JOIN other_papsmearcheck ON Other_PapSmearCheckM_PapSmearCheckID = M_PapSmearCheckID AND - Other_PapSmearCheckOther_PapSmearID = {$header_id} AND - Other_PapSmearCheckIsActive = 'Y' - WHERE - M_PapSmearCheckIsActive = 'Y' - ORDER BY M_PapSmearCheckCode ASC - "; - $checks = $this->db_smartone->query($sql)->result_array(); - - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $rst = array('doctors'=>$doctors,'checks'=>$checks,'bahans'=>$bahans,'categories'=>$categories,'maturasi'=>$maturasi,'results'=>$rows); - $this->sys_ok(["records"=>$rst]); - - } - - function saveresult_lcprep() - { - $prm = $this->sys_input; - $detail_id = $prm['detail_id']; - $doctor_id = $prm['doctor']; - $adekuasi = $prm['adekuasi']; - $kategoriumum = $prm['kategoriumum']; - $interpretasi = $prm['interpretasi']; - $results = $prm['results']; - - $userid = $this->sys_user['M_UserID']; - - $header_id = 0; - $sql = "SELECT * FROM other_lcprep WHERE Other_LcprepT_orderDetailID = {$detail_id} AND Other_LcprepIsActive = 'Y'"; - $dt_header = $this->db_smartone->query($sql)->row_array(); - if($dt_header){ - $header_id = $dt_header['Other_LcprepID']; - } - if($header_id == 0){ - $sql = "INSERT INTO other_lcprep( - Other_LcprepT_orderDetailID, - Other_LcprepM_DoctorID, - Other_LcprepUserID, - Other_LcprepCreated - ) - VALUES( - {$detail_id}, - {$doctor_id}, - {$userid}, - NOW() - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - }else{ - $sql = "UPDATE other_lcprep SET Other_LcprepM_DoctorID = {$doctor_id}, Other_LcprepUserID = {$userid} WHERE Other_LcprepID = {$header_id}"; - $this->db_smartone->query($sql); - } - - if($adekuasi){ - foreach($adekuasi as $k =>$v){ - $selected = $v['chex']?'Y':'N'; - if(intval($v['xid'] == 0)){ - $sql = "UPDATE other_lcprepadekuasi SET Other_LcprepAdekuasiIsActive = 'N' - WHERE - Other_LcprepAdekuasiOther_LcprepID = {$header_id} AND - Other_LcprepAdekuasiIsActive = 'Y' AND - Other_LcprepAdekuasiLcprep_AdekuasiID = {$v['id']}"; - $this->db_smartone->query($sql); - $sql = "INSERT INTO other_lcprepadekuasi ( - Other_LcprepAdekuasiOther_LcprepID, - Other_LcprepAdekuasiLcprep_AdekuasiID, - Other_LcprepAdekuasiChex, - Other_LcprepAdekuasiUserID, - Other_LcprepAdekuasiCreated - ) - VALUES( - {$header_id}, - {$v['id']}, - '{$selected}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - //echo $sql; - } - if(intval($v['xid'] != 0)){ - - $sql = "UPDATE other_lcprepadekuasi SET - Other_LcprepAdekuasiChex = '{$selected}', - Other_LcprepAdekuasiUserID = {$userid} - WHERE - Other_LcprepAdekuasiID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - - //echo $sql; - } - } - - if($kategoriumum){ - foreach($kategoriumum as $k =>$v){ - $selected = $v['chex']?'Y':'N'; - if(intval($v['xid'] == 0)){ - $sql = "UPDATE other_lcprepkategoriumum SET Other_LcprepKategoriUmumIsActive = 'N' - WHERE - Other_LcprepKategoriUmumOther_LcprepID = {$header_id} AND - Other_LcprepKategoriUmumLcprep_KategoriUmumID = {$v['id']} AND - Other_LcprepKategoriUmumIsActive = 'Y' - "; - $this->db_smartone->query($sql); - $sql = "INSERT INTO other_lcprepkategoriumum ( - Other_LcprepKategoriUmumOther_LcprepID, - Other_LcprepKategoriUmumLcprep_KategoriUmumID, - Other_LcprepKategoriUmumChex, - Other_LcprepKategoriUmumUserID, - Other_LcprepKategoriUmumCreated - ) - VALUES( - {$header_id}, - {$v['id']}, - '{$selected}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if(intval($v['xid'] != 0)){ - $sql = "UPDATE other_lcprepkategoriumum SET - Other_LcprepKategoriUmumChex = '{$selected }', - Other_LcprepKategoriUmumUserID = {$userid} - WHERE - Other_LcprepKategoriUmumID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - - //echo $sql; - } - } - - if($results){ - foreach($results as $k =>$v){ - if(intval($v['xid'] == 0)){ - $sql = "UPDATE other_lcprepdetails SET Other_LcprepDetailsIsActive = 'N' - WHERE - Other_LcprepDetailsOther_LcprepID = {$header_id} AND - Other_LcprepDetailsCode = '{$v['code']}' AND - Other_LcprepDetailsIsActive = 'Y'"; - $this->db_smartone->query($sql); - $sql = "INSERT INTO other_lcprepdetails ( - Other_LcprepDetailsOther_LcprepID, - Other_LcprepDetailsCode, - Other_LcprepDetailsLabel, - Other_LcprepDetailsResult, - Other_LcprepDetailsUserID, - Other_LcprepDetailsCreated - ) - VALUES( - {$header_id}, - '{$v['code']}', - '{$v['label']}', - '{$v['result']}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if(intval($v['xid'] != 0)){ - $sql = "UPDATE other_lcprepdetails SET - Other_LcprepDetailsCode = '{$v['code']}', - Other_LcprepDetailsLabel = '{$v['label']}', - Other_LcprepDetailsResult = '{$v['result']}', - Other_LcprepDetailsUserID = {$userid} - WHERE - Other_LcprepDetailsID = {$v['xid']}"; - $this->db_smartone->query($sql); - - } - //echo $sql; - } - } - - if($interpretasi){ - foreach($interpretasi as $k =>$v){ - if(count($v['subgroups']) > 0){ - foreach($v['subgroups'] as $ik => $iv){ - if(count($iv['childs']) > 0){ - foreach($iv['childs'] as $iik => $iiv){ - if(intval($iiv['xid'] == 0)){ - $chex = $iiv['chex'] ? 'Y':'N'; - $sql = "UPDATE other_lcprepinterpretasi SET Other_LcprepInterpretasiIsActive = 'N' - WHERE - Other_LcprepInterpretasiOther_LcprepID = {$header_id} AND - Other_LcprepInterpretasiLcprep_InterpretasiID = '{$iiv['id']}' AND - Other_LcprepInterpretasiIsActive = 'Y'"; - $this->db_smartone->query($sql); - $sql = "INSERT INTO other_lcprepinterpretasi ( - Other_LcprepInterpretasiOther_LcprepID, - Other_LcprepInterpretasiLcprep_InterpretasiID, - Other_LcprepInterpretasiChex, - Other_LcprepInterpretasiValue, - Other_LcprepInterpretasiUserID, - Other_LcprepInterpretasiCreated - ) - VALUES( - {$header_id}, - '{$iiv['id']}', - '{$chex}', - '{$iiv['value']}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - - if(intval($iiv['xid'] != 0)){ - $chex = $iiv['chex'] ? 'Y':'N'; - $sql = "UPDATE other_lcprepinterpretasi SET - Other_LcprepInterpretasiChex = '{$chex}', - Other_LcprepInterpretasiValue = '{$iiv['value']}', - Other_LcprepInterpretasiUserID = {$userid} - WHERE - Other_LcprepInterpretasiID = {$iiv['xid']}"; - $this->db_smartone->query($sql); - //echo $sql; - - } - - } - } - } - } - //echo $sql; - } - } - - - $result = array("total" => 1, "records" => array(), "sql"=> ''); - $this->sys_ok($result); - exit; - } - - function saveresult_papsmear() - { - $prm = $this->sys_input; - $detail_id = $prm['detail_id']; - $doctor_id = $prm['doctor']; - $checks = $prm['checks']; - $maturasi = $prm['maturasi']; - $bahans = $prm['bahans']; - $categories = $prm['categories']; - $results = $prm['results']; - - $userid = $this->sys_user['M_UserID']; - - $header_id = 0; - $sql = "SELECT * FROM other_papsmear WHERE Other_PapSmearT_OrderDetailID = {$detail_id} AND Other_PapSmearIsActive = 'Y'"; - $dt_header = $this->db_smartone->query($sql)->row_array(); - if($dt_header){ - $header_id = $dt_header['Other_PapSmearID']; - } - if($header_id == 0){ - $sql = "INSERT INTO other_papsmear( - Other_PapSmearT_OrderDetailID, - Other_PapSmearM_DoctorID, - Other_PapSmearUserID, - Other_PapSmearCreated - ) - VALUES( - {$detail_id}, - {$doctor_id}, - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } - else{ - $sql = "UPDATE other_papsmear SET Other_PapSmearM_DoctorID = {$doctor_id}, Other_PapSmearUserID = {$userid} WHERE Other_PapSmearID = {$header_id}"; - $this->db_smartone->query($sql); - } - - if($checks){ - foreach($checks as $k =>$v){ - if(intval($v['xid']) == 0 && $v['selected'] === 'Y'){ - $sql = "INSERT INTO other_papsmearcheck ( - Other_PapSmearCheckOther_PapSmearID, - Other_PapSmearCheckM_PapSmearCheckID, - Other_PapSmearCheckNote, - Other_PapSmearCheckUserID, - Other_PapSmearCheckCreated - ) - VALUES( - {$header_id}, - {$v['check_id']}, - '{$v['note']}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if(intval($v['xid']) != 0 && $v['selected'] === 'N'){ - $sql = "UPDATE other_papsmearcheck SET - Other_PapSmearCheckIsActive = 'N', - Other_PapSmearCheckUserID = {$userid} - WHERE - Other_PapSmearCheckID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - if(intval($v['xid']) != 0 && $v['selected'] === 'Y'){ - $sql = "UPDATE other_papsmearcheck SET - Other_PapSmearCheckNote = '{$v['note']}', - Other_PapSmearCheckUserID = {$userid} - WHERE - Other_PapSmearCheckID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - //echo $sql; - } - } - - if($maturasi){ - if(intval($maturasi['xid']) == 0){ - $value = join("/",$maturasi['value']); - $sql = "INSERT INTO other_papsmearmaturasi ( - Other_PapSmearMaturasiOther_PapSmearID, - Other_PapSmearMaturasiValue, - Other_PapSmearMaturasiUserID, - Other_PapSmearMaturasiCreated - ) - VALUE( - {$header_id}, - '{$value}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - //echo $sql; - } - if(intval($maturasi['xid']) != 0){ - $value = join("/",$maturasi['value']); - $sql = "UPDATE other_papsmearmaturasi SET - Other_PapSmearMaturasiValue = '{$value}', - Other_PapSmearMaturasiUserID = {$userid} - WHERE - Other_PapSmearMaturasiID = {$maturasi['xid']}"; - // echo $sql; - $this->db_smartone->query($sql); - } - } - - if($bahans){ - foreach($bahans as $k =>$v){ - if(intval($v['xid']) == 0 && $v['selected'] === 'Y'){ - $sql = "INSERT INTO other_papsmearbahan ( - Other_PapSmearBahanOther_PapSmearID, - Other_PapSmearBahanM_PapSmearBahanID, - Other_PapSmearBahanUserID, - Other_PapSmearBahanCreated - ) - VALUES( - {$header_id}, - {$v['bahan_id']}, - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if(intval($v['xid']) != 0 && $v['selected'] === 'N'){ - $sql = "UPDATE other_papsmearbahan SET - Other_PapSmearBahanIsActive = 'N', - Other_PapsmearCategoryUserID = {$userid} - WHERE - Other_PapSmearBahanID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - if(intval($v['xid']) != 0 && $v['selected'] === 'Y'){ - $sql = "UPDATE other_papsmearbahan SET - Other_PapSmearBahanIsActive = 'Y', - Other_PapsmearCategoryUserID = {$userid} - WHERE - Other_PapSmearBahanID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - //echo $sql; - } - } - - if($categories){ - foreach($categories as $k =>$v){ - if(intval($v['xid']) == 0 && $v['selected'] === 'Y'){ - $sql = "INSERT INTO other_papsmearcategory ( - Other_PapsmearCategoryOther_PapSmearID, - Other_PapsmearCategoryM_PapSmearCategoryID, - Other_PapsmearCategoryUserID, - Other_PapsmearCategoryCreated - ) - VALUES( - {$header_id}, - {$v['category_id']}, - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if(intval($v['xid']) != 0 && $v['selected'] === 'N'){ - $sql = "UPDATE other_papsmearcategory SET - Other_PapsmearCategoryIsActive = 'N', - Other_PapsmearCategoryUserID = {$userid} - WHERE - Other_PapsmearCategoryID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - //echo $sql; - if(intval($v['xid']) != 0 && $v['selected'] === 'Y'){ - $sql = "UPDATE other_papsmearcategory SET - Other_PapsmearCategoryIsActive = 'Y', - Other_PapsmearCategoryUserID = {$userid} - WHERE - Other_PapsmearCategoryID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - } - } - - if($results){ - foreach($results as $k =>$v){ - if(intval($v['xid']) == 0){ - $sql = "INSERT INTO other_papsmeardetails ( - Other_PapSmearDetailsOther_PapSmearID, - Other_PapSmearDetailsCode, - Other_PapSmearDetailsLabel, - Other_PapSmearDetailsResult, - Other_PapSmearDetailsUserID, - Other_PapSmearDetailsCreated - ) - VALUES( - {$header_id}, - '{$v['code']}', - '{$v['label']}', - '{$v['result']}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if(intval($v['xid']) != 0){ - $sql = "UPDATE other_papsmeardetails SET - Other_PapSmearDetailsCode = '{$v['code']}', - Other_PapSmearDetailsLabel = '{$v['label']}', - Other_PapSmearDetailsResult = '{$v['result']}', - Other_PapSmearDetailsUserID = {$userid} - WHERE - Other_PapSmearDetailsID = {$v['xid']}"; - $this->db_smartone->query($sql); - - } - //echo $sql; - } - } - - $result = array("total" => 1, "records" => array(), "sql"=> ''); - $this->sys_ok($result); - exit; - } - - function saveresult_fna() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = $inp['doctor']; - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - if($prm[0]['xid'] == '0'){ - $sql = "INSERT INTO other_fna( - Other_FNAM_DoctorID, - Other_FNAT_OrderDetailID, - Other_FNAUserID, - Other_FNACreated - ) - VALUES( - {$doctor_id}, - {$prm[0]['orderdetail_id']}, - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } - else{ - $sql = "SELECT * FROM other_fna WHERE Other_FNAT_OrderDetailID = {$prm[0]['orderdetail_id']} AND Other_FNAIsActive = 'Y'"; - $data_header = $this->db_smartone->query($sql)->row_array(); - $header_id = $data_header['Other_FNAID']; - $sql = "UPDATE other_fna SET - Other_FNAM_DoctorID = {$doctor_id}, - Other_FNAUserID = {$userid} - WHERE - Other_FNAID = {$header_id}"; - $this->db_smartone->query($sql); - } - foreach($prm as $k => $v){ - if($v['xid'] == '0'){ - $results = str_replace("'", "\\'", $v['result']); - $sql = "INSERT INTO other_fnadetails( - Other_FNADetailsOther_FNAID , - Other_FNADetailsCode, - Other_FNADetailsLabel, - Other_FNADetailsResult, - Other_FNADetailsCreated, - Other_FNADetailsUserID - ) - VALUES( - {$header_id}, - '{$v['code']}', - '{$v['label']}', - '{$results}', - NOW(), - {$userid} - )"; - $query = $this->db_smartone->query($sql); - } - else{ - $results = str_replace("'", "\\'", $v['result']); - $sql = "UPDATE other_fnadetails SET - Other_FNADetailsResult = '{$results}', - Other_FNADetailsUserID = {$userid} - WHERE - Other_FNADetailsID = {$v['xid']}"; - $query = $this->db_smartone->query($sql); - } - } - - $result = array("total" => 1, "records" => array(), "sql"=> ''); - $this->sys_ok($result); - exit; - } - - function saveresult_cytologi() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = $inp['doctor']; - - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - if($prm[0]['xid'] == '0'){ - $sql = "INSERT INTO other_cytologi( - Other_CytologiT_OrderDetailID, - Other_CytologiM_DoctorID, - Other_CytologiUserID, - Other_CytologiCreated - ) - VALUES( - {$prm[0]['orderdetail_id']}, - {$doctor_id}, - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } - else{ - $sql = "SELECT * FROM other_cytologi WHERE Other_CytologiT_OrderDetailID = {$prm[0]['orderdetail_id']} AND Other_CytologiIsActive = 'Y'"; - $data_header = $this->db_smartone->query($sql)->row_array(); - $header_id = $data_header['Other_CytologiID']; - $sql = "UPDATE other_cytologi SET - Other_CytologiM_DoctorID = {$doctor_id}, - Other_CytologiUserID = {$userid} - WHERE - Other_CytologiID = {$header_id}"; - $this->db_smartone->query($sql); - } - foreach($prm as $k => $v){ - if($v['xid'] == '0'){ - $results = str_replace("'", "\\'", $v['result']); - $sql = "INSERT INTO other_cytologidetails( - Other_CytologiDetailsOther_CytologiID , - Other_CytologiDetailsCode, - Other_CytologiDetailsLabel, - Other_CytologiDetailsResult, - Other_CytologiDetailsCreated, - Other_CytologiDetailsUserID - ) - VALUES( - {$header_id}, - '{$v['code']}', - '{$v['label']}', - '{$results}', - NOW(), - {$userid} - )"; - $query = $this->db_smartone->query($sql); - } - else{ - $results = str_replace("'", "\\'", $v['result']); - $sql = "UPDATE other_cytologidetails SET - Other_CytologiDetailsResult = '{$results}', - Other_CytologiDetailsUserID = {$userid} - WHERE - Other_CytologiDetailsID = {$v['xid']}"; - $query = $this->db_smartone->query($sql); - } - } - - $result = array("total" => 1, "records" => array(), "sql"=> ''); - $this->sys_ok($result); - exit; - } - - function saveresult_mikro() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = $inp['doctor']; - $backteria_id = $inp['bacteria']; - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - - if($inp['result_value'] != 'Negatif' && $inp['result_value'] != 'Positif'){ - $prm['result_value'] = $prm['result_other']; - } - else{ - $prm['result_value'] = $inp['result_value']; - } - - if($prm['xid'] == '0'){ - $sql = "INSERT INTO other_mikro( - Other_MikroM_DoctorID, - Other_MikroResult, - Other_MikroT_BacteriaID, - Other_MikroT_OrderDetailID, - Other_MikroHasilBiakan, - Other_MikroSampleTypeName, - Other_MikroUserID, - Other_MikroCreated - ) - VALUES( - {$doctor_id}, - '{$prm['result_value']}', - {$backteria_id}, - {$prm['orderdetail_id']}, - '{$prm['hasil_biakan']}', - '{$prm['sample_name']}', - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } - else{ - $sql = "SELECT * FROM other_mikro WHERE Other_MikroT_OrderDetailID = {$prm['orderdetail_id']} AND Other_MikroIsActive = 'Y'"; - $data_header = $this->db_smartone->query($sql)->row_array(); - $header_id = $data_header['Other_MikroID']; - $sql = "UPDATE other_mikro SET - Other_MikroResult = '{$prm['result_value']}', - Other_MikroM_DoctorID = {$doctor_id}, - Other_MikroT_BacteriaID = {$backteria_id}, - Other_MikroHasilBiakan = '{$prm['hasil_biakan']}', - Other_MikroSampleTypeName = '{$prm['sample_name']}', - Other_MikroUserID = {$userid} - WHERE - Other_MikroID = {$header_id}"; - //echo $sql; - $this->db_smartone->query($sql); - } - - - - $sql = "UPDATE other_mikrodetails SET Other_MikroDetailsIsActive = 'N', Other_MikroDetailsUserID = 0 WHERE Other_MikroDetailsOther_MikroID = {$header_id}"; - $this->db_smartone->query($sql); - - $results = $prm['details']; - if($inp['result_value'] == 'Positif'){ - foreach($results as $k => $v){ - if($v['xid'] == '0'){ - $sql = "INSERT INTO other_mikrodetails( - Other_MikroDetailsOther_MikroID , - Other_MikroDetailsT_AntibioticID, - Other_MikroDetailsValue, - Other_MikroDetailsNote, - Other_MikroDetailsCreated, - Other_MikroDetailsUserID - ) - VALUES( - {$header_id}, - '{$v['T_AntibioticID']}', - '{$v['value']}', - '{$v['note']}', - NOW(), - {$userid} - )"; - $query = $this->db_smartone->query($sql); - } - else{ - $sql = "UPDATE other_mikrodetails SET - Other_MikroDetailsT_AntibioticID = '{$v['T_AntibioticID']}', - Other_MikroDetailsValue = '{$v['value']}', - Other_MikroDetailsNote = '{$v['note']}', - Other_MikroDetailsIsActive = 'Y', - Other_MikroDetailsUserID = {$userid} - WHERE - Other_MikroDetailsID = {$v['xid']}"; - //echo $sql; - $query = $this->db_smartone->query($sql); - } - } - } - - - $result = array("total" => 1, "records" => array(), "sql"=> ''); - $this->sys_ok($result); - exit; - } - - - function get_doctors_preparasi_sperma() - { - $prm = $this->sys_input; - // $id = $prm["id"]; - - $sql = " SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 10 AND - M_DoctorSOIsActive = 'Y' - ORDER BY M_DoctorName ASC"; - //echo $sql; - $query = $this->db_smartone->query($sql); - $rows = $query->result_array(); - $sql = " - SELECT '0' as id, 'Belum memilih metode' as name - UNION - SELECT M_MethodeSpermaID as id, M_MethodeSpermaName as name - FROM m_methodesperma - WHERE - M_MethodeSpermaIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $methodes = $this->db_smartone->query($sql)->result_array(); - - - $this->sys_ok(["records"=>$rows,"methodes"=>$methodes]); - - } - - - function getpreparasispermaresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT other_preparasisperma.*, - Other_PreparasiSpermaID as xid, - Other_PreparasiSpermaT_OrderDetailID as orderdetail_id, - IFNULL(Other_PreparasiSpermaM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_PreparasiSpermaM_DoctorID) OR Other_PreparasiSpermaM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name, - IFNULL(M_MethodeSpermaID,0) as methode_id, - IFNULL(M_MethodeSpermaName,'') as methode_name - FROM other_preparasisperma - LEFT JOIN m_doctor ON Other_PreparasiSpermaM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - LEFT JOIN m_methodesperma ON Other_PreparasiSpermaM_MethodeSpermaID = M_MethodeSpermaID AND - M_MethodeSpermaIsActive = 'Y' - WHERE - Other_PreparasiSpermaT_OrderDetailID = {$id} AND Other_PreparasiSpermaIsActive = 'Y' - GROUP BY Other_PreparasiSpermaID"; - $query = $this->db_smartone->query($sql); - - if ($query) - { - $rows = $query->row_array(); - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 10 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $sql = " - SELECT '0' as id, 'Belum memilih metode' as name - UNION - SELECT M_MethodeSpermaID as id, M_MethodeSpermaName as name - FROM m_methodesperma - WHERE - M_MethodeSpermaIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $methodes = $this->db_smartone->query($sql)->result_array(); - $images = array(); - $sql = "SELECT Other_PreparasiSpermaImgID as xid, - Other_PreparasiSpermaImgType as type, - CONCAT('/one-media/one-image-nonlab/',Other_PreparasiSpermaImgNewName) as image_url - FROM t_orderdetail - JOIN other_preparasisperma_img ON Other_PreparasiSpermaImgT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND - Other_PreparasiSpermaImgIsActive = 'Y' - WHERE - T_OrderDetailID = {$id} AND - T_OrderDetailIsActive = 'Y' - GROUP BY Other_PreparasiSpermaImgID"; - //echo $sql; - $images = $this->db_smartone->query($sql)->result_array(); - - $rst = array('doctors'=>$doctors,'methodes'=>$methodes,'results'=>$rows,'images'=>$images); - $this->sys_ok(["records"=>$rst]); - } - else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - - function uploadimage_preparasi_sperma(){ - if (! $this->isLogin) { - $this->sys_error("Invalid Token"); - exit; - } - - $userid = $this->sys_user["M_UserID"]; - $data = []; - //print_r($_SERVER); - - $prm = $this->sys_input; - $orderid = $this->input->post('orderid'); - $type = $this->input->post('type'); - $labnumber = $this->input->post('labnumber'); - $sql = "UPDATE other_preparasisperma_img SET - Other_PreparasiSpermaImgIsActive = 'N', - Other_PreparasiSpermaImgUserID = {$userid} - WHERE - Other_PreparasiSpermaImgT_OrderHeaderID = {$orderid} AND - Other_PreparasiSpermaImgType = '{$type}'"; - //echo $sql; - $this->db_onedev->query($sql); - //$config['upload_path'] = 'assets/'; - - $path = '/home/one/project/one/one-media/one-image-nonlab/'; - //echo $path; - $config['upload_path'] = $path; - $config['allowed_types'] = 'jpg|jpeg|png|gif'; - - $config['max_size'] = '10000'; - $count = count($_FILES['files']['name']); - //echo $count; - $this->load->library('upload',$config); - - $error = []; - for($i=0;$i<$count;$i++){ - - - if(!empty($_FILES['files']['name'][$i])){ - - - - $_FILES['file']['name'] = $_FILES['files']['name'][$i]; - - $_FILES['file']['type'] = $_FILES['files']['type'][$i]; - - $_FILES['file']['tmp_name'] = $_FILES['files']['tmp_name'][$i]; - - $_FILES['file']['error'] = $_FILES['files']['error'][$i]; - - $_FILES['file']['size'] = $_FILES['files']['size'][$i]; - - - - $namex = $orderid.'-'.$labnumber.'-'.$this->generateRandomString(5); - //echo $namex; - - $config['file_name'] = $namex; - $this->upload->initialize($config); - //echo $config['file_name'] ; - - - - - - if($this->upload->do_upload('file')){ - - $uploadData = $this->upload->data(); - - $filename = $uploadData['file_name']; - //echo $filename; - - - $sql = "INSERT INTO other_preparasisperma_img ( - Other_PreparasiSpermaImgT_OrderHeaderID, - Other_PreparasiSpermaImgType, - Other_PreparasiSpermaImgOldName, - Other_PreparasiSpermaImgNewName, - Other_PreparasiSpermaImgCreated, - Other_PreparasiSpermaImgUserID - ) - VALUES( - {$orderid}, - '{$type}', - '{$_FILES['files']['name'][$i]}', - '{$filename}', - NOW(), - {$userid} - - )"; - //echo $sql; - $this->db_onedev->query($sql); - $xlast_id = $this->db_onedev->insert_id(); - $data['totalFiles'][] = array('xid' => $xlast_id ,'type'=>$type,'image_url' => '/one-media/one-image-nonlab/'.$filename); - - } - else{ - $error = array('error' => $this->upload->display_errors()); - } - - } - - - - } - - $result = array("total" =>count( $data['totalFiles']), "records" => $data['totalFiles'],'errors'=>$error); - $this->sys_ok($result); - } - - - function saveresult_preparasi_sperma() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = $inp['doctor']; - $orderdetail_id = $inp['orderdetailid']; - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - if($prm['xid'] == '0'){ - $sql = "INSERT INTO other_preparasisperma( - Other_PreparasiSpermaM_DoctorID, - Other_PreparasiSpermaT_OrderDetailID, - Other_PreparasiSpermaPreMotilitasA, - Other_PreparasiSpermaPreMotilitasB, - Other_PreparasiSpermaPreMotilitasC, - Other_PreparasiSpermaPreKonsentrasi, - Other_PreparasiSpermaPreKontaminan, - Other_PreparasiSpermaPostMotilitasA, - Other_PreparasiSpermaPostMotilitasB, - Other_PreparasiSpermaPostMotilitasC, - Other_PreparasiSpermaPostKonsentrasi, - Other_PreparasiSpermaPostKontaminan, - Other_PreparasiSpermaPreVolume, - Other_PreparasiSpermaPostVolume, - Other_PreparasiSpermaM_MethodeSpermaID, - Other_PreparasiSpermaNote, - Other_PreparasiSpermaUserID, - Other_PreparasiSpermaCreated - ) - VALUES( - {$doctor_id}, - {$orderdetail_id}, - '{$prm['Other_PreparasiSpermaPreMotilitasA']}', - '{$prm['Other_PreparasiSpermaPreMotilitasB']}', - '{$prm['Other_PreparasiSpermaPreMotilitasC']}', - '{$prm['Other_PreparasiSpermaPreKonsentrasi']}', - '{$prm['Other_PreparasiSpermaPreKontaminan']}', - '{$prm['Other_PreparasiSpermaPostMotilitasA']}', - '{$prm['Other_PreparasiSpermaPostMotilitasB']}', - '{$prm['Other_PreparasiSpermaPostMotilitasC']}', - '{$prm['Other_PreparasiSpermaPostKonsentrasi']}', - '{$prm['Other_PreparasiSpermaPostKontaminan']}', - '{$prm['Other_PreparasiSpermaPreVolume']}', - '{$prm['Other_PreparasiSpermaPostVolume']}', - '{$prm['Other_PreparasiSpermaM_MethodeSpermaID']}', - '{$prm['Other_PreparasiSpermaNote']}', - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } - else{ - $sql = "SELECT * FROM other_preparasisperma WHERE Other_PreparasiSpermaT_OrderDetailID = {$orderdetail_id} AND Other_PreparasiSpermaIsActive = 'Y'"; - $data_header = $this->db_smartone->query($sql)->row_array(); - $header_id = $data_header['Other_PreparasiSpermaID']; - $sql = "UPDATE other_preparasisperma SET - Other_PreparasiSpermaM_DoctorID = {$doctor_id}, - Other_PreparasiSpermaPreMotilitasA = '{$prm['Other_PreparasiSpermaPreMotilitasA']}', - Other_PreparasiSpermaPreMotilitasB = '{$prm['Other_PreparasiSpermaPreMotilitasB']}', - Other_PreparasiSpermaPreMotilitasC = '{$prm['Other_PreparasiSpermaPreMotilitasC']}', - Other_PreparasiSpermaPreKonsentrasi = '{$prm['Other_PreparasiSpermaPreKonsentrasi']}', - Other_PreparasiSpermaPreKontaminan = '{$prm['Other_PreparasiSpermaPreKontaminan']}', - Other_PreparasiSpermaPostMotilitasA = '{$prm['Other_PreparasiSpermaPostMotilitasA']}', - Other_PreparasiSpermaPostMotilitasB = '{$prm['Other_PreparasiSpermaPostMotilitasB']}', - Other_PreparasiSpermaPostMotilitasC = '{$prm['Other_PreparasiSpermaPostMotilitasC']}', - Other_PreparasiSpermaPostKonsentrasi = '{$prm['Other_PreparasiSpermaPostKonsentrasi']}', - Other_PreparasiSpermaPostKontaminan = '{$prm['Other_PreparasiSpermaPostKontaminan']}', - Other_PreparasiSpermaPreVolume = '{$prm['Other_PreparasiSpermaPreVolume']}', - Other_PreparasiSpermaPostVolume = '{$prm['Other_PreparasiSpermaPostVolume']}', - Other_PreparasiSpermaM_MethodeSpermaID = '{$prm['Other_PreparasiSpermaM_MethodeSpermaID']}', - Other_PreparasiSpermaNote = '{$prm['Other_PreparasiSpermaNote']}', - Other_PreparasiSpermaUserID = {$userid} - WHERE - Other_PreparasiSpermaID = {$header_id}"; - $this->db_smartone->query($sql); - } - - - $result = array("total" => 1, "records" => array(), "sql"=> ''); - $this->sys_ok($result); - exit; - } - - function getdnafragmentasiresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT other_dnafragmentasi.*, - Other_DnaFragmentasiID as xid, - Other_DnaFragmentasiT_OrderDetailID as orderdetail_id, - IFNULL(Other_DnaFragmentasiM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_DnaFragmentasiM_DoctorID) OR Other_DnaFragmentasiM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name, - IFNULL(Other_DnaFragmentasiOther_DnaFragmentasiMethodeID,0) as methode_id, - IFNULL(Other_DnaFragmentasiMethodeName,'') as methode_name, - Other_DnaFragmentasiHaloLuas as halo_luas, - Other_DnaFragmentasiHaloSedang as halo_sedang, - Other_DnaFragmentasiHaloSempit as halo_sempit, - Other_DnaFragmentasiTanpaHalo as tanpa_halo, - Other_DnaFragmentasiDFI as dfi, - Other_DnaFragmentasiKesimpulan as kesimpulan, - Other_DnaFragmentasiCatatan as catatan - FROM other_dnafragmentasi - LEFT JOIN m_doctor ON Other_DnaFragmentasiM_DoctorID = M_DoctorID - LEFT JOIN other_dnafragmentasimethode ON Other_DnaFragmentasiOther_DnaFragmentasiMethodeID = Other_DnaFragmentasiMethodeID - WHERE - Other_DnaFragmentasiT_OrderDetailID = {$id} AND Other_DnaFragmentasiIsActive = 'Y' - GROUP BY Other_DnaFragmentasiID - LIMIT 1"; - //echo $sql; - $query = $this->db_smartone->query($sql); - - if ($query) - { - $rows = $query->row_array(); - if(!$rows){ - $rows = array( - 'xid' => 0, - 'orderdetail_id' =>$id, - 'doctor_id' => 0, - 'doctor_name' => '', - 'methode_id' => 0, - 'methode_name' => '', - 'halo_luas' => '', - 'halo_sedang' => '', - 'tanpa_halo' => '', - 'dfi' => '', - 'kesimpulan' => '', - 'catatan' => '' - ); - } - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID - WHERE - M_DoctorSONat_SubGroupID = 4 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - - $sql = " - SELECT '0' as id, 'Belum memilih metode' as name - UNION - SELECT Other_DnaFragmentasiMethodeID as id, Other_DnaFragmentasiMethodeName as name - FROM other_dnafragmentasimethode - WHERE - Other_DnaFragmentasiMethodeIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $methodes = $this->db_smartone->query($sql)->result_array(); - - - $rst = array('doctors'=>$doctors,'methodes'=>$methodes,'results'=>$rows); - $this->sys_ok(["records"=>$rst]); - } - else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - function saveresult_dnafragmentasi() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = $inp['doctor']['id']; - $methode_id = $inp['methode']['id']; - $orderdetail_id = $inp['results']['orderdetail_id']; - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - if(intval($prm['xid']) == 0){ - $sql = "INSERT INTO other_dnafragmentasi( - Other_DnaFragmentasiT_OrderDetailID, - Other_DnaFragmentasiM_DoctorID, - Other_DnaFragmentasiOther_DnaFragmentasiMethodeID, - Other_DnaFragmentasiHaloLuas, - Other_DnaFragmentasiHaloSedang, - Other_DnaFragmentasiHaloSempit, - Other_DnaFragmentasiTanpaHalo, - Other_DnaFragmentasiDFI, - Other_DnaFragmentasiKesimpulan, - Other_DnaFragmentasiCatatan, - Other_DnaFragmentasiUserID, - Other_DnaFragmentasiLastUpdated - ) - VALUES( - {$orderdetail_id}, - {$doctor_id}, - {$methode_id}, - '{$prm['halo_luas']}', - '{$prm['halo_sedang']}', - '{$prm['halo_sempit']}', - '{$prm['tanpa_halo']}', - '{$prm['dfi']}', - '{$prm['kesimpulan']}', - '{$prm['catatan']}', - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } - else{ - $sql = "UPDATE other_dnafragmentasi SET - Other_DnaFragmentasiT_OrderDetailID = {$orderdetail_id}, - Other_DnaFragmentasiM_DoctorID = {$doctor_id}, - Other_DnaFragmentasiOther_DnaFragmentasiMethodeID = '{$methode_id}', - Other_DnaFragmentasiHaloLuas = '{$prm['halo_luas']}', - Other_DnaFragmentasiHaloSedang = '{$prm['halo_sedang']}', - Other_DnaFragmentasiHaloSempit = '{$prm['halo_sempit']}', - Other_DnaFragmentasiTanpaHalo = '{$prm['tanpa_halo']}', - Other_DnaFragmentasiDFI = '{$prm['dfi']}', - Other_DnaFragmentasiKesimpulan = '{$prm['kesimpulan']}', - Other_DnaFragmentasiCatatan = '{$prm['catatan']}', - Other_DnaFragmentasiLastUpdated = NOW(), - Other_DnaFragmentasiUserID = {$userid} - WHERE - Other_DnaFragmentasiID = {$prm['xid']}"; - //echo $sql; - $this->db_smartone->query($sql); - } - - - $result = array("total" => 1, "records" => array(), "sql"=> ''); - $this->sys_ok($result); - exit; - } - - -} - +db_smartone = $this->load->database("onedev", true); + $this->load->helper(array('form', 'url')); + } + function getMethodeID($natTestID) { + $sql = "select M_MethodePriorityNat_MethodeID MethodeID, Nat_MethodeName + from + m_methode_priority + join nat_methode on Nat_MethodeID = M_MethodePriorityNat_MethodeID + and Nat_MethodeIsActive = 'Y' + join m_instrumentmethode on M_InstrumentMethodeNat_MethodeID = Nat_MethodeID and M_InstrumentMethodeIsActive = 'Y' + join nat_instrument on M_InstrumentMethodeNat_InstrumentID = Nat_InstrumentID + and Nat_InstrumentIsActive ='Y' + where M_MethodePriorityIsActive = 'Y' + and M_MethodePriorityNat_TestID = $natTestID + and M_MethodePriorityM_DayOfWeekID = dayofweek(now()) + order by M_MethodePriorityNumber desc + limit 0,1 "; + $qry = $this->db->query($sql); + if ($qry) { + $rows = $qry->result_array(); + if (count($rows) > 0 ) return array($rows[0]["MethodeID"],$rows[0]["Nat_MethodeName"]); + } + //2nd + $sql= "select + M_InstrumentMethodeNat_MethodeID MethodeID, Nat_MethodeName + from m_instrumentmethode + join nat_methode on M_InstrumentMethodeNat_MethodeID = Nat_MethodeID + and Nat_MethodeIsActive = 'Y' + join nat_instrument on M_InstrumentMethodeNat_InstrumentID = Nat_InstrumentID + and Nat_InstrumentIsActive ='Y' + where M_InstrumentMethodeNat_TestID = $natTestID + and M_InstrumentMethodeIsActive = 'Y' + order by M_InstrumentMethodePriority desc + limit 0,1"; + $qry = $this->db->query($sql); + if ($qry) { + $rows = $qry->result_array(); + if (count($rows) > 0 ) return array($rows[0]["MethodeID"],$rows[0]["Nat_MethodeName"]); + } + // + $sql = "select Nat_NormalValueNat_MethodeID MethodeID, Nat_MethodeName + from + nat_normalvalue + join nat_methode on Nat_NormalValueNat_MethodeID = Nat_MethodeID + and Nat_MethodeIsActive = 'Y' + where Nat_NormalValueNat_TestID = $natTestID + and Nat_NormalValueIsActive = 'Y' + order by Nat_NormalValueID + limit 0,1"; + $qry = $this->db->query($sql); + if ($qry) { + $rows = $qry->result_array(); + if (count($rows) > 0 ) return array($rows[0]["MethodeID"],$rows[0]["Nat_MethodeName"]); + } + return array(0,""); + } + function get_normal_value($methodeID, $natTestID, $sexID, $ageInDay ) { + $this->load->library('ibl_sampling_normal'); + return $this->ibl_sampling_normal->get_normal_value_id($methodeID, $natTestID, $sexID, $ageInDay); + } + return 0; + } + function fn_fix_normal($order_id) { + $sql = "select + T_OrderDetailID, M_PatientM_SexID, fn_global_age_count_day(M_PatientDOB, date(T_OrderHeaderDate)) Dob , + T_TestNat_TestID + from t_orderheader + join m_patient on T_OrderHeaderID = $order_id and T_OrderHeaderM_PatientID = M_PatientID + join t_orderdetail on T_OrderDetailT_OrderHeaderID = T_OrderHeaderID + and T_OrderDetailIsACtive = 'Y' + and ( T_OrderDetailNat_NormalValueID is null or T_OrderDetailNat_NormalValueID = 0 ) + join t_test on T_OrderDetailT_TestID = T_TestID and T_TestIsResult = 'Y' "; + $qry = $this->db->query($sql); + if(! $qry) { + return; + } + $rows = $qry->result_array(); + if(count($rows) == 0 ) return; + $sql_u = "update t_orderdetail + join nat_normalvalue on T_OrderDetailID = ? and Nat_NormalValueID = ? + set + T_OrderDetailNat_NormalValueID = Nat_NormalValueID, + T_OrderDetailNormalValueNote = Nat_NormalValueNote, + T_OrderDetailNormalValueDescription = Nat_NormalValueDescription, + T_OrderDetailMinValue = Nat_NormalValueMinValue, + T_OrderDetailMaxValue = Nat_NormalValueMaxValue, + T_OrderDetailMinValueInclusive = Nat_NormalValueMinValueInclusive, + T_OrderDetailMaxValueInclusive = Nat_NormalValueMaxValueInclusive, + T_OrderDetailNat_MethodeID = ?, + T_OrderdetailNat_MethodeName =?"; + + foreach($rows as $r) { + $T_OrderDetailID = $r["T_OrderDetailID"]; + $sexID = $r["M_PatientM_SexID"]; + $ageInDay = $r["Dob"]; + $natTestID = $r["T_TestNat_TestID"]; + list($methodeID,$methodeName) = $this->getMethodeID($natTestID); + if ($methodeID == 0 ) continue; + $normalValueID = $this->get_normal_value($methodeID, $natTestID, $sexID, $ageInDay); + if ($normalValueID == 0) return; + $this->db->query($sql_u, array($T_OrderDetailID, $normalValueID, $methodeID, $methodeName)); + } + } + function update_order_sample($targetID, $sourceID) { + $sql = "update t_ordersample target + join t_ordersample source on + target.T_OrderSampleID = ? + and target.T_OrderSampleWorklistReceive = 'N' + and source.T_OrderSampleID = ? + set + target.T_OrderSampleSampling = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSampling, source.T_OrderSampleSampling), + target.T_OrderSampleSamplingDate = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingDate, source.T_OrderSampleSamplingDate), + target.T_OrderSampleSamplingTime = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingTime, source.T_OrderSampleSamplingTime), + target.T_OrderSampleSamplingUserID = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingUserID, source.T_OrderSampleSamplingUserID), + + target.T_OrderSampleReceive = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceive, source.T_OrderSampleReceive), + target.T_OrderSampleReceiveDate = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveDate, source.T_OrderSampleReceiveDate), + target.T_OrderSampleReceiveTime = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveTime, source.T_OrderSampleReceiveTime), + target.T_OrderSampleReceiveUserID = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveUserID, source.T_OrderSampleReceiveUserID), + + target.T_OrderSampleVerification = if(target.T_OrderSampleVerification='Y',target.T_OrderSampleVerification, source.T_OrderSampleVerification), + target.T_OrderSampleVerificationDate =if(target.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationDate, source.T_OrderSampleVerificationDate), + target.T_OrderSampleVerificationTime =if(source.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationTime, source.T_OrderSampleVerificationTime), + target.T_OrderSampleVerificationUserID =if(source.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationUserID, source.T_OrderSampleVerificationUserID), + + target.T_OrderSampleProcessing = if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessing, source.T_OrderSampleProcessing), + target.T_OrderSampleProcessingDate= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingDate, source.T_OrderSampleProcessingDate), + target.T_OrderSampleProcessingTime= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingTime, source.T_OrderSampleProcessingTime), + target.T_OrderSampleProcessingUserID= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingUserID, source.T_OrderSampleProcessingUserID), + + target.T_OrderSampleReceiveHandling =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandling, source.T_OrderSampleReceiveHandling ), + target.T_OrderSampleReceiveHandlingDate =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingDate, source.T_OrderSampleReceiveHandlingDate), + target.T_OrderSampleReceiveHandlingTime =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingTime, source.T_OrderSampleReceiveHandlingTime), + target.T_OrderSampleReceiveHandlingUserID =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingUserID, source.T_OrderSampleReceiveHandlingUserID), + + target.T_OrderSampleHandling = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandling, source.T_OrderSampleHandling), + target.T_OrderSampleHandlingDate = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingDate, source.T_OrderSampleHandlingDate), + target.T_OrderSampleHandlingTime = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingTime, source.T_OrderSampleHandlingTime), + target.T_OrderSampleHandlingUserID = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingUserID, source.T_OrderSampleHandlingUserID), + + target.T_OrderSampleWorklistReceive = source.T_OrderSampleWorklistReceive, + target.T_OrderSampleWorklistReceiveDatetime = source.T_OrderSampleWorklistReceiveDateTime, + target.T_OrderSampleWorklistReceiveUserID = source.T_OrderSampleWorklistReceiveUserID + "; + $qry = $this->db->query($sql,array($targetID,$sourceID)); + if(! $qry ) { + echo json_encode(array( "status" => "ERR" , "message" => print_r($this->db->error(),true))); + exit; + } + } + function fix_sample_serum($headerID) { + //cari t_ordersample yg belum worklist receive dengan code 017% + $sql = "select T_OrderSampleID + from t_ordersample + join t_sampletype on + T_OrderSampleT_OrderHeaderID = ? + and T_OrderSampleWorklistReceive = 'N' + and T_OrderSampleIsActive = 'Y' + and T_OrderSampleT_SampleTypeID = T_SampletypeID + and T_SampleTypeCode like '017%' + "; + $qry = $this->db->query($sql, array($headerID)); + if(!$qry) { + echo json_encode(array( "status" => "ERR" , "message" => print_r($this->db->error(),true))); + exit; + } + $rows = $qry->result_array(); + if (count($rows) == 0 ) return; + //cari T_OrderSample yang sudah di receive yg terakhir + $sql = "select T_OrderSampleID + from t_ordersample + join t_sampletype on + T_OrderSampleT_OrderHeaderID = ? + and T_OrderSampleWorklistReceive = 'Y' + and T_OrderSampleIsActive = 'Y' + and T_OrderSampleT_SampleTypeID = T_SampletypeID + and T_SampleTypeCode like '017%' + order by T_OrderSampleWorklistReceiveDatetime desc + limit 0,1 + "; + $qry = $this->db->query($sql, array($headerID)); + if(!$qry) { + echo json_encode(array( "status" => "ERR" , "message" => print_r($this->db->error(),true))); + exit; + } + $rcv_rows = $qry->result_array(); + if (count($rcv_rows) == 0 ) return; + + //print_r($rows); + //print_r($rcv_rows); + $rcv_T_OrderSampleID = $rcv_rows[0]["T_OrderSampleID"]; + //ada yg belum di receive + foreach($rows as $r) { + $T_OrderSampleID = $r["T_OrderSampleID"]; + $this->update_order_sample($T_OrderSampleID,$rcv_T_OrderSampleID); + } + } + public function search() + { + $prm = $this->sys_input; + $max_rst = 99; + + $id = $prm["order_id"]; + if ($id > 0 ) { + $this->fix_sample_serum($id); + $this->fn_fix_normal($id); + } + $lang = $this->lang_default_code; + $lang_id = isset($prm['lang_id']) ? $prm['lang_id'] : '0'; + + if ($lang_id != 0) + { + $l = $this->db_smartone->where("Nat_LangID", $lang_id)->get("nat_lang")->row(); + $lang = $l->Nat_LangCode; + } + + //tambahan fajri + $sql = " UPDATE t_orderdetail + JOIN t_test ON T_OrderDetailT_TestID = T_TestID + SET T_OrderDetailT_TestIsResult = T_TestIsResult + WHERE + T_OrderDetailT_OrderHeaderID = {$id} AND + T_OrderDetailT_TestIsResult = '' AND + T_OrderDetailIsActive = 'Y'"; + $this->db_smartone->query($sql); + + $tot_count = 0; + $lq = ""; + $group_id = 0; + if (isset($prm['group_id'])) + $group_id = $prm['group_id']; + + if ($group_id != 0) + { + $sql = "select distinct T_WorklistDetailNat_TestID Nat_TestID + from t_worklistdetailv2 + where T_WorklistDetailT_WorklistID = {$group_id}"; + $qry = $this->db_smartone->query($sql); + $rows = $qry->result_array(); + $nat_test_ids = "0"; + foreach($rows as $r) { + $nat_test_ids .= ", " . $r["Nat_TestID"]; + } + $q_group = " ( $nat_test_ids ) "; + + $sql = " + SELECT a1.*, cOUNT(a2.T_OrderDetailID) level + FROM ( + SELECT IFNULL(y.T_OrderDetailT_TestID, x.T_OrderDetailT_TestID) t_testid, + IFNULL(y.T_OrderDetailT_TestName, y.T_OrderDetailT_TestName) t_testname, + y.T_OrderDetailResult result, y.T_OrderDetailResult result_old, y.T_OrderDetailNote note, y.T_OrderDetailNote note_old, + y.T_OrderDetailID id, + y.T_OrderDetailT_TestIsResult is_result, a.T_TestIsQuantitative is_quantitative, + y.T_OrderDetailResultFlag result_flag, + y.T_OrderDetailNat_NormalValueID normal_id, + y.T_OrderDetailNormalValueNote normal_note, y.T_OrderDetailNat_UnitName unit_name, + y.T_OrderdetailNat_MethodeID methode_id, y.T_OrderdetailNat_MethodeName methode_name, + a.T_TestNat_TestID nattest_id, a.T_TestID tx_id, count(T_ResultInstrumentID) as result_instrument_n, + y.T_OrderDetailVerification, T_OrderSampleReceive sample_receive, + T_OrderSampleProcessing sample_processing, T_OrderSampleWorklistReceive sample_worklist_receive, + IF(T_OrderDetailAddOnPreAnalytic = 'Y', T_OrderDetailAddOnPreAnalytic, PreAnalyticIsOk) pre_analytic, + T_OrderDetailAddOnPreAnalytic, + T_OrderHeaderID order_id, y.T_OrderDetailT_TestSasCode test_sas_code, + tx.T_TestSasCode, + T_OrderDetailAddOnResample `resample`, T_OrderDetailAddOnResampleStatus resample_status, + T_OrderDetailAddOnRef ref, y.T_OrderDetailVerification verification, y.T_OrderDetailValidation validation, + T_OrderPromiseDateTime, Group_ResultName as ResultGroupName + FROM t_orderdetail x + left join t_orderpromise on x.T_OrderDetailT_OrderPromiseID = T_OrderPromiseID + JOIN t_test tx ON x.T_OrderDetailT_TestID = T_TestID + JOIN t_test tcheck on tcheck.T_TestNat_TestID in {$q_group} + and ( tx.T_TestID = tcheck.T_TestID or tx.T_TestSasCode like concat(tcheck.T_TestSasCode,'%')) + LEFT JOIN group_resultdetail ON Group_ResultDetailT_TestID = x.T_OrderDetailT_TestID AND Group_ResultDetailIsActive = 'Y' + LEFT JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND Group_ResultFlagNonLab = 'N' + LEFT JOIN t_orderdetail y ON x.T_OrderDetailT_TestSasCode LIKE CONCAT(y.T_OrderDetailT_TestSasCode, '%') + AND x.T_OrderDetailT_OrderHeaderID = y.T_OrderDetailT_OrderHeaderID + AND y.T_OrderDetailIsActive = 'Y' + LEFT JOIN t_orderdetailaddon ON x.T_OrderDetailID = T_OrderDetailAddOnT_OrderDetailID + JOIN t_orderheader ON y.T_OrderDetailT_OrderHeaderID = T_OrderHeaderID + LEFT JOIN t_test a ON y.T_OrderDetailT_TestID = a.T_TestID + AND a.T_TestIsNonLab = '' + LEFT JOIN (SELECT T_OrderSampleT_SampleTypeID, T_OrderSampleReceive, T_OrderSampleProcessing, T_OrderSampleWorklistReceive + FROM t_ordersample WHERE T_OrderSampleT_OrderHeaderID = {$id} + AND T_OrderSampleIsactive = 'Y' + GROUP BY T_OrderSampleT_SampleTypeID) os ON a.T_TestT_SampleTypeID = os.T_OrderSampleT_SampleTypeID + or os.T_OrderSampleT_SampleTypeID = fn_sampletype_from_local(a.T_TestNat_TestID) + + LEFT JOIN t_resultinstrument ON T_ResultInstrumentT_OrderDetailID = x.T_OrderDetailID + LEFT JOIN pre_analytic ON PreAnalyticNat_TestID = a.T_TestNat_TestID AND PreAnalyticDate = date(now()) and PreAnalyticIsActive = 'Y' + WHERE x.T_OrderDetailT_OrderHeaderID = {$id} + AND x.T_OrderDetailIsActive = 'Y' + GROUP BY y.T_OrderDetailT_TestID + ORDER BY y.T_OrderDetailT_TestSasCode ASC + ) a1 + + LEFT JOIN t_orderdetail a2 ON a2.T_OrderDetailT_OrderHeaderID = a1.order_id + AND a2.T_OrderDetailIsActive = 'Y' + AND a1.test_sas_code LIKE CONCAT(a2.T_OrderDetailT_testSasCode, '%') + GROUP BY a1.t_testid + order by a1.test_sas_code +"; + $query = $this->db_smartone->query($sql); + $lq = $this->db_smartone->last_query(); + } + else + { + $sql = " + SELECT a1.*, cOUNT(a2.T_OrderDetailID) level + FROM ( + SELECT IFNULL(y.T_OrderDetailT_TestID, x.T_OrderDetailT_TestID) t_testid, + IFNULL(y.T_OrderDetailT_TestName, y.T_OrderDetailT_TestName) t_testname, + y.T_OrderDetailResult result, y.T_OrderDetailResult result_old, y.T_OrderDetailNote note, y.T_OrderDetailNote note_old, + y.T_OrderDetailID id, + y.T_OrderDetailT_TestIsResult is_result, a.T_TestIsQuantitative is_quantitative, + y.T_OrderDetailResultFlag result_flag, + y.T_OrderDetailNat_NormalValueID normal_id, + y.T_OrderDetailNormalValueNote normal_note, y.T_OrderDetailNat_UnitName unit_name, + y.T_OrderdetailNat_MethodeID methode_id, y.T_OrderdetailNat_MethodeName methode_name, + a.T_TestNat_TestID nattest_id, a.T_TestID tx_id, count(T_ResultInstrumentID) as result_instrument_n, + y.T_OrderDetailVerification, T_OrderSampleReceive sample_receive, + T_OrderSampleProcessing sample_processing, T_OrderSampleWorklistReceive sample_worklist_receive, + IF(T_OrderDetailAddOnPreAnalytic = 'Y', T_OrderDetailAddOnPreAnalytic, PreAnalyticIsOk) pre_analytic, + T_OrderDetailAddOnPreAnalytic, + T_OrderHeaderID order_id, y.T_OrderDetailT_TestSasCode test_sas_code, + tx.T_TestSasCode, + T_OrderDetailAddOnResample `resample`, T_OrderDetailAddOnResampleStatus resample_status, + T_OrderDetailAddOnRef ref, y.T_OrderDetailVerification verification, y.T_OrderDetailValidation validation, + T_OrderPromiseDateTime , Group_ResultName as ResultGroupName + FROM t_orderdetail x + left join t_orderpromise on x.T_OrderDetailT_OrderPromiseID = T_OrderPromiseID + JOIN t_test tx ON x.T_OrderDetailT_TestID = T_TestID + LEFT JOIN group_resultdetail ON Group_ResultDetailT_TestID = x.T_OrderDetailT_TestID AND Group_ResultDetailIsActive = 'Y' + LEFT JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND Group_ResultFlagNonLab = 'N' + LEFT JOIN t_orderdetail y ON x.T_OrderDetailT_TestSasCode LIKE CONCAT(y.T_OrderDetailT_TestSasCode, '%') + AND x.T_OrderDetailT_OrderHeaderID = y.T_OrderDetailT_OrderHeaderID + AND y.T_OrderDetailIsActive = 'Y' + + LEFT JOIN t_orderdetailaddon ON x.T_OrderDetailID = T_OrderDetailAddOnT_OrderDetailID + + JOIN t_orderheader ON y.T_OrderDetailT_OrderHeaderID = T_OrderHeaderID + LEFT JOIN t_test a ON y.T_OrderDetailT_TestID = a.T_TestID + AND a.T_TestIsNonLab = '' + LEFT JOIN (SELECT T_OrderSampleT_SampleTypeID, T_OrderSampleReceive, T_OrderSampleProcessing, T_OrderSampleWorklistReceive + FROM t_ordersample WHERE T_OrderSampleT_OrderHeaderID = {$id} + AND T_OrderSampleIsactive = 'Y' + GROUP BY T_OrderSampleT_SampleTypeID) os ON a.T_TestT_SampleTypeID = os.T_OrderSampleT_SampleTypeID + or os.T_OrderSampleT_SampleTypeID = fn_sampletype_from_local(a.T_TestNat_TestID) + + LEFT JOIN t_resultinstrument ON T_ResultInstrumentT_OrderDetailID = x.T_OrderDetailID + LEFT JOIN pre_analytic ON PreAnalyticNat_TestID = a.T_TestNat_TestID AND PreAnalyticDate = date(now()) and PreAnalyticIsActive = 'Y' + WHERE x.T_OrderDetailT_OrderHeaderID = {$id} + AND x.T_OrderDetailIsActive = 'Y' + GROUP BY y.T_OrderDetailT_TestID + ORDER BY y.T_OrderDetailT_TestSasCode ASC + ) a1 + + LEFT JOIN t_orderdetail a2 ON a2.T_OrderDetailT_OrderHeaderID = a1.order_id + AND a2.T_OrderDetailIsActive = 'Y' + AND a1.test_sas_code LIKE CONCAT(a2.T_OrderDetailT_testSasCode, '%') + GROUP BY a1.t_testid + order by a1.test_sas_code +"; +//echo $sql; + $query = $this->db_smartone->query($sql); + $lq = $this->db_smartone->last_query(); + } + // file_put_contents("/xtmp/re-query.sql",$lq); + + if ($query) { + $rst = []; + $rows = $query->result_array(); + + foreach($rows as $k => $v) + { + + if ($v['is_result'] == "Y" && $v['is_quantitative'] == "N") + { + $v['template'] = []; + $x = $this->db_smartone->query("CALL sp_master_resulttemplate_get('{$v['t_testid']}')"); + $this->clean_mysqli_connection($this->db_smartone->conn_id); + if ($x) + $v['template'] = $x->result_array(); + } + + // IF Rujukan, by pas Pre Analytik + if ($v['ref'] == 'Y') + $v['pre_analytic'] = 'Y'; + if ($v["id"] == "885455" ) + { + //sipe workaround + //$v["sample_receive"] = "Y"; + $v["sample_worklist_receive"] = "Y"; + } + $rst[] = $v; + } + + $result = array("total" => $tot_count, "records" => $rst, "total_display" => sizeof($rows), "q" => $lq); + $this->sys_ok($result); + } + else { + $this->sys_error_db("RE Px rows", $this->db_smartone); + exit; + } + } + + public function save() + { + $prm = $this->sys_input; + $data = json_decode($prm["data"]); + $lang = $this->lang_default_code; + $lang_id = isset($prm['lang_id']) ? $prm['lang_id'] : '0'; + + if ($lang_id != 0) + { + $l = $this->db_smartone->where("Nat_LangID", $lang_id)->get("nat_lang")->row(); + $lang = $l->Nat_LangCode; + } + + $sql_norm = "select T_OrderDetailMinValue, T_OrderDetailMaxValue, + T_OrderDetailMinValueInclusive, T_OrderDetailMaxValueInclusive, + Nat_TestFlagLow, Nat_TestFlagHigh + from t_orderdetail + join t_test on T_OrderDetailT_TestID = T_TestID + join nat_test on T_TestNat_TestID = Nat_TestID and T_TestIsActive = 'Y' + where T_OrderDetailID = ? "; + + $ids = []; + foreach ($data as $k => $v) + { + if ( $v->resultInstrumentID > 0 ) { + $sql_i = "select T_ResultInstrumentNat_NormalValueID normalValueID + from t_resultinstrument + where T_ResultInstrumentID = ?"; + $qry_i = $this->db_smartone->query($sql_i, array($v->resultInstrumentID)); + if ($qry_i) { + $rows_i = $qry_i->result_array(); + + if (count($rows_i) > 0 ) { + $sql_iu = "update t_orderdetail, nat_normalvalue , nat_methode + set T_OrderDetailMinValue = Nat_NormalValueMinValue, + T_OrderDetailMinValueInclusive = Nat_NormalValueMinValueInclusive, + T_OrderDetailMaxValue = Nat_NormalValueMaxValue , + T_OrderDetailMaxValueInclusive = Nat_NormalValueMaxValueInclusive, + T_OrderDetailNormalValueNote = Nat_NormalValueNote, + T_OrderDetailNormalValueDescription = Nat_NormalValueDescription, + T_OrderDetailNat_NormalValueID = Nat_NormalValueID, + T_OrderDetailNat_MethodeID = Nat_NormalValueNat_MethodeID, + T_OrderDetailNat_MethodeName = Nat_MethodeName + where T_OrderDetailID = ? and Nat_NormalValueID = ? + and Nat_NormalValueNat_MethodeID = Nat_MethodeID + "; + $this->db_smartone->query($sql_iu, array($v->id, $rows_i[0]["normalValueID"])); + //file_put_contents("/xtmp/update-nilai-normal", $this->db_smartone->last_query() . "\n", FILE_APPEND); + } + } + } + $y = $this->db_smartone->query("SELECT fn_process_sample_handling_perfect('{$v->order_id}', '{$v->test_id}') c") + ->row(); + $req_status = $y->c; + $qry_norm = $this->db_smartone->query($sql_norm,$v->id); + $result_flag = ""; + if ($qry_norm) { + $rows_norm = $qry_norm->result_array(); + if (count($rows_norm) > 0 ) { + $r = $rows_norm[0]; + if (is_numeric($v->result)) { + + if ( $r["T_OrderDetailMinValueInclusive"] == "Y" && $v->result < $r["T_OrderDetailMinValue"] ) { + $result_flag = $r["Nat_TestFlagLow"]; + } + if ( $r["T_OrderDetailMinValueInclusive"] == "N" && $v->result <= $r["T_OrderDetailMinValue"] ) { + $result_flag = $r["Nat_TestFlagLow"]; + } + if ( $r["T_OrderDetailMaxValueInclusive"] == "Y" && $v->result > $r["T_OrderDetailMaxValue"] ) { + $result_flag = $r["Nat_TestFlagHigh"]; + } + if ( $r["T_OrderDetailMaxValueInclusive"] == "N" && $v->result >= $r["T_OrderDetailMaxValue"] ) { + $result_flag = $r["Nat_TestFlagHigh"]; + } + } + } + } + if ($lang == $this->lang_default_code) + { + $this->db_smartone->set('T_OrderDetailResult', $v->result) + ->set('T_OrderDetailResultFlag', $result_flag) + ->set('T_OrderDetailNote', $v->note) + ->set('T_OrderDetailReqStatus', $req_status) + ->where('T_OrderDetailID', $v->id) + ->update('t_orderdetail'); + } + else + { + $this->db_smartone->set('T_OrderDetailLangResult', $v->result) + ->set('T_OrderDetailLangNote', $v->note) + ->where('T_OrderDetailLangID', $v->id) + ->update('t_orderdetaillang'); + } + + $ids[] = $v->id; + } + + // LOG Process + $order = $this->db_smartone->select('T_OrderDetailT_OrderHeaderID id, T_OrderHeaderLabNumber lab_number', false) + ->join('t_orderheader', 'T_OrderHeaderID = T_OrderDetailT_OrderHeaderID') + ->where('T_OrderDetailID', $data[0]->id) + ->get('t_orderdetail') + ->row(); + + $dblog = $this->load->database("onelog", true); + $dblog->set('Log_ProcessCode', 'PROCESS.Result.Entry') + ->set('Log_ProcessOrderID', $order->id) + ->set('Log_ProcessOrderNumber', $order->lab_number) + ->set('Log_ProcessJson', json_encode($data)) + ->set('Log_ProcessUserID', $this->sys_user['M_UserID']) + ->insert('log_process'); + // END OF Log Process + //auto calculation + $this->load->library("Resultcalc"); + $rows = $this->resultcalc->auto($order->id); + + try { + foreach($ids as $id ) { + $this->db_smartone->query("call sp_set_normal_value_flag($id)"); + $this->clean_mysqli_connection($this->db_smartone->conn_id); + } + } catch(Exception $e) { + } + + $this->sys_ok($ids); + } + + public function save_template() + { + $prm = $this->sys_input; + + $n = $this->db_smartone->select("COUNT(T_ResultTemplateID) n") + ->where("T_ResultTemplateT_TestID", $prm['test_id']) + ->where("T_ResultTemplateIsActive", "Y") + ->where("T_ResultTemplateValue", $prm['value']) + ->get('t_resulttemplate') + ->row(); + if ($n->n > 0) + { + $this->sys_error_db("Insert Result Template", $this->db_smartone); + return; + } + + $r = $this->db_smartone->set("T_ResultTemplateT_TestID", $prm['test_id']) + ->set("T_ResultTemplateValue", $prm['value']) + ->insert('t_resulttemplate'); + if ($r) + { + $template = []; + $x = $this->db_smartone->query("CALL sp_master_resulttemplate_get('{$prm['test_id']}')"); + $this->clean_mysqli_connection($this->db_smartone->conn_id); + if ($x) + $template = $x->result_array(); + + $this->sys_ok($template); + } + } + + public function export() + { + $prm = $this->sys_input; + + $sql = "CALL sp_process_result_lang(?, ?, ?, ?)"; + $query = $this->db_smartone->query($sql, [$prm['order_id'], $prm['lang_id'], $prm['is_si'], $this->sys_user['M_UserID']]); + if ($query) + { + $r = $query->row(); + if ($r->status == "OK") + { + $this->sys_ok($r->data); + return; + } + + $this->sys_error_db("Message : " . $r->message, $this->db_smartone); + } + else + { + $this->sys_error_db("Lang Result", $this->db_smartone); + return; + } + } + + public function search_group() + { + $prm = $this->sys_input; + $max_rst = 100; + + // QUERY TOTAL + $sql = "select count(*) total + from t_worklist + where T_WorklistIsActive = 'Y' + order by T_WorklistName ASC"; + $query = $this->db_smartone->query($sql); + + if ($query) { + $tot_count = $query->result_array()[0]["total"]; + } + else { + $this->sys_error_db("worklist count", $this->db_smartone); + exit; + } + + $sql = "select T_WorklistID group_id, T_WorklistName group_name + from t_worklist + where T_WorklistIsActive = 'Y' + order by T_WorklistName ASC + limit 0, {$max_rst}"; + $query = $this->db_smartone->query($sql); + + if ($query) { + $rows = $query->result_array(); + foreach ($rows as $k => $v) + $rows[$k]['data'] = json_decode($v['data']); + $result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows), "q" => $this->db_smartone->last_query()); + $this->sys_ok($result); + } + else { + $this->sys_error_db("worklist rows", $this->db_smartone); + exit; + } + } + + public function search_rerun() + { + $prm = $this->sys_input; + $id = $prm["detail_id"]; + + $sql = "CALL sp_process_result_rerun(?)"; + $query = $this->db_smartone->query($sql, [$id]); + + if ($query) + { + $rows = $query->result_array(); + $this->sys_ok(["records"=>$rows]); + } + else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + + + function getdoctorsfna() + { + $prm = $this->sys_input; + // $id = $prm["id"]; + + $sql = " SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY M_DoctorName ASC"; + //echo $sql; + $query = $this->db_smartone->query($sql); + + if ($query) + { + $rows = $query->result_array(); + $this->sys_ok(["records"=>$rows]); + } + else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + function getfnaresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT Other_FNADetailsID as xid, + Other_FNAT_OrderDetailID as orderdetail_id, + Other_FNADetailsCode as code, + Other_FNADetailsLabel as label, + Other_FNADetailsResult as result, + IFNULL(Other_FNAM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_FNAM_DoctorID) OR Other_FNAM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_fna + JOIN other_fnadetails ON Other_FNADetailsOther_FNAID = Other_FNAID AND Other_FNADetailsIsActive = 'Y' + LEFT JOIN m_doctor ON Other_FNAM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_FNAT_OrderDetailID = {$id} AND Other_FNAIsActive = 'Y' + GROUP BY Other_FNADetailsID + ORDER BY Other_FNADetailsCode ASC"; + $query = $this->db_smartone->query($sql); + + if ($query) + { + $rows = $query->result_array(); + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $images = array(); + $sql = "SELECT So_ImageUploadID as xid, + CONCAT('/one-media/one-image-nonlab/',So_ImageUploadNewName) as image_url + FROM t_orderdetail + JOIN so_imageupload ON So_ImageUploadT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND + So_ImageUploadIsActive = 'Y' + WHERE + T_OrderDetailID = {$id} AND + T_OrderDetailIsActive = 'Y' + GROUP BY So_ImageUploadID"; + $images = $this->db_smartone->query($sql)->result_array(); + + $rst = array('doctors'=>$doctors,'results'=>$rows,'images'=>$images); + $this->sys_ok(["records"=>$rst]); + } + else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + + function uploadimage(){ + if (! $this->isLogin) { + $this->sys_error("Invalid Token"); + exit; + } + + $userid = $this->sys_user["M_UserID"]; + $data = []; + //print_r($_SERVER); + + $prm = $this->sys_input; + $orderid = $this->input->post('orderid'); + $labnumber = $this->input->post('labnumber'); + $sql = "UPDATE so_imageupload SET + So_ImageUploadIsActive = 'N', + So_ImageUploadUserID = {$userid} + WHERE + So_ImageUploadT_OrderHeaderID = {$orderid}"; + //echo $sql; + $this->db_onedev->query($sql); + //$config['upload_path'] = 'assets/'; + + $path = '/home/one/project/one/one-media/one-image-nonlab/'; + //echo $path; + $config['upload_path'] = $path; + $config['allowed_types'] = 'jpg|jpeg|png|gif'; + + $config['max_size'] = '10000'; + $count = count($_FILES['files']['name']); + //echo $count; + $this->load->library('upload',$config); + + $error = []; + for($i=0;$i<$count;$i++){ + + + if(!empty($_FILES['files']['name'][$i])){ + + + + $_FILES['file']['name'] = $_FILES['files']['name'][$i]; + + $_FILES['file']['type'] = $_FILES['files']['type'][$i]; + + $_FILES['file']['tmp_name'] = $_FILES['files']['tmp_name'][$i]; + + $_FILES['file']['error'] = $_FILES['files']['error'][$i]; + + $_FILES['file']['size'] = $_FILES['files']['size'][$i]; + + + + $namex = $orderid.'-'.$labnumber.'-'.$this->generateRandomString(5); + //echo $namex; + + $config['file_name'] = $namex; + $this->upload->initialize($config); + //echo $config['file_name'] ; + + + + + + if($this->upload->do_upload('file')){ + + $uploadData = $this->upload->data(); + + $filename = $uploadData['file_name']; + //echo $filename; + + + $sql = "INSERT INTO so_imageupload ( + So_ImageUploadT_OrderHeaderID, + So_ImageUploadT_OrderHeaderLabNumber, + So_ImageUploadT_SampleTypeID, + So_ImageUploadOldName, + So_ImageUploadNewName, + So_ImageUploadCreated, + So_ImageUploadUserID + ) + VALUES( + {$orderid}, + '{$labnumber}', + '150', + '{$_FILES['files']['name'][$i]}', + '{$filename}', + NOW(), + {$userid} + + )"; + //echo $sql; + $this->db_onedev->query($sql); + $xlast_id = $this->db_onedev->insert_id(); + $data['totalFiles'][] = array('xid' => $xlast_id ,'image_url' => '/one-media/one-image-nonlab/'.$filename); + + } + else{ + $error = array('error' => $this->upload->display_errors()); + } + + } + + + + } + + $result = array("total" =>count( $data['totalFiles']), "records" => $data['totalFiles'],'errors'=>$error); + $this->sys_ok($result); + } + + + function generateRandomString($length = 10) { + $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; + $charactersLength = strlen($characters); + $randomString = ''; + for ($i = 0; $i < $length; $i++) { + $randomString .= $characters[rand(0, $charactersLength - 1)]; + } + return $randomString; + } + + function getcytologiresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT Other_CytologiDetailsID as xid, + Other_CytologiT_OrderDetailID as orderdetail_id, + Other_CytologiDetailsCode as code, + Other_CytologiDetailsLabel as label, + Other_CytologiDetailsResult as result, + IFNULL(Other_CytologiM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_CytologiM_DoctorID) OR Other_CytologiM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_cytologi + JOIN other_cytologidetails ON Other_CytologiDetailsOther_CytologiID = Other_CytologiID AND Other_CytologiDetailsIsActive = 'Y' + LEFT JOIN m_doctor ON Other_CytologiM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_CytologiT_OrderDetailID = {$id} AND Other_CytologiIsActive = 'Y' + GROUP BY Other_CytologiDetailsID + ORDER BY Other_CytologiDetailsCode ASC"; + //echo $sql; + $query = $this->db_smartone->query($sql); + + if ($query) + { + $rows = $query->result_array(); + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $rst = array('doctors'=>$doctors,'results'=>$rows); + $this->sys_ok(["records"=>$rst]); + } + else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + function getmikroresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT + Other_MikroID as xid, + Other_MikroHasilBiakan as hasil_biakan, + Other_MikroSampleTypeName as sample_name, + Other_MikroT_OrderDetailID as orderdetail_id, + Other_MikroResult as result_value, + '' as result_other, + IFNULL(T_BacteriaID,0) as T_BacteriaID, + IFNULL(T_BacteriaName,'') as T_BacteriaName, + '' as details, + IFNULL(Other_MikroM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_MikroM_DoctorID) OR Other_MikroM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_mikro + LEFT JOIN t_bacteria ON Other_MikroT_BacteriaID = T_BacteriaID + LEFT JOIN m_doctor ON Other_MikroM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_MikroT_OrderDetailID = {$id} AND Other_MikroIsActive = 'Y' + GROUP BY Other_MikroID"; + //echo $sql; + $query = $this->db_smartone->query($sql); + + if ($query) + { + $row = $query->row_array(); + if($row){ + if($row['result_value'] != 'Positif' && $row['result_value'] != 'Negatif'){ + $row['result_other'] = $row['result_value']; + $row['result_value'] = 'other'; + } + $sql = "SELECT '' as xno, + Other_MikroDetailsID as xid, + Other_MikroDetailsValue as value, + IF(Other_MikroDetailsNote = 'R','Y','N') as chx_r, + IF(Other_MikroDetailsNote = 'I','Y','N') as chx_i, + IF(Other_MikroDetailsNote = 'S','Y','N') as chx_s, + Other_MikroDetailsNote as note, + t_antibiotic.* + FROM other_mikrodetails + LEFT JOIN t_antibiotic ON Other_MikroDetailsT_AntibioticID = T_AntibioticID + WHERE + Other_MikroDetailsOther_MikroID = {$row['xid']} AND Other_MikroDetailsIsActive = 'Y' + GROUP BY Other_MikroDetailsID + ORDER BY T_AntibioticName ASC"; + //echo $sql; + $details = $this->db_smartone->query($sql)->result_array(); + if(details){ + foreach($details as $k => $v){ + $details[$k]['xno'] = $k + 1; + } + } + $row['details'] = $details; + } + else{ + $row = array('xid'=>'0','hasil_biakan' => '','result_value'=>'Negatif','sample_name' => '','orderdetail_id'=>$id, 'T_BacteriaID'=>'0','T_BacteriaName'=>'0','details'=>array(),'doctor_id'=>'0','doctor_name'=>'0'); + } + } + else{ + $row = array('xid'=>'0','hasil_biakan' => '','result_value'=>'Negatif','sample_name' => '','orderdetail_id'=>$id, 'T_BacteriaID'=>'0','T_BacteriaName'=>'0','details'=>array(),'doctor_id'=>'0','doctor_name'=>'0'); + } + //print_r($row); + + + + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 7 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $sql = " + SELECT '0' as id, 'Belum memilih bakteria' as name + UNION + SELECT T_BacteriaID as id, T_BacteriaName as name + FROM t_bacteria + WHERE + T_BacteriaIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $bacteries = $this->db_smartone->query($sql)->result_array(); + $rst = array('doctors'=>$doctors,'bacteries'=>$bacteries,'results'=>$row); + $this->sys_ok(["records"=>$rst]); + } + function getantibiotics(){ + $prm = $this->sys_input; + $id = $prm["id"]; + $sql = " SELECT '' as xno, + 0 as xid, + '' as hasil_biakan, + '' as sample_name, + 0 as value, + 'Y' as chx_r, + 'N' as chx_i, + 'N' as chx_s, + 'R' as note, + t_antibiotic.* + FROM t_antibiotic + WHERE + T_AntibioticT_BacteriaID = {$prm['id']} AND T_AntibioticIsActive= 'Y' + ORDER BY T_AntibioticName ASC"; + //echo $sql; + $rows = $this->db_smartone->query($sql)->result_array(); + if(rows){ + foreach($rows as $k => $v){ + $rows[$k]['xno'] = $k + 1; + } + } + + $this->sys_ok(["records"=>$rows]); + } + function getlcprepresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + $sql = " SELECT Other_LcprepDetailsID as xid, + Other_LcprepID as header_id, + Other_LcprepT_orderDetailID as orderdetail_id, + Other_LcprepDetailsCode as code, + Other_LcprepDetailsLabel as label, + Other_LcprepDetailsResult as result, + IFNULL(Other_LcprepM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_LcprepM_DoctorID) OR Other_LcprepM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_lcprep + JOIN other_lcprepdetails ON Other_LcprepDetailsOther_LcprepID = Other_LcprepID AND Other_LcprepDetailsIsActive = 'Y' + LEFT JOIN m_doctor ON Other_LcprepM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_LcprepT_orderDetailID = {$id} AND Other_LcprepIsActive = 'Y' + GROUP BY Other_LcprepDetailsOther_LcprepID, Other_LcprepDetailsCode + ORDER BY Other_LcprepDetailsCode ASC"; + //echo $sql; + $rows = $this->db_smartone->query($sql)->result_array(); + if(!$rows){ + $rows = array( + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'A', + 'label' => 'DESKRIPSI', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ), + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'B', + 'label' => 'KESIMPULAN', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ) + ); + } + + $header_id = $rows[0]['header_id']; + $sql = "SELECT IFNULL(Other_LcprepAdekuasiID,0) as xid, + Lcprep_AdekuasiID as id, + Lcprep_AdekuasiLabel as name, + IF(ISNULL(Other_LcprepAdekuasiID),'N',Other_LcprepAdekuasiChex) as chex + FROM lcprep_adekuasi + LEFT JOIN other_lcprepadekuasi ON Other_LcprepAdekuasiLcprep_AdekuasiID = Lcprep_AdekuasiID AND + Other_LcprepAdekuasiOther_LcprepID = {$header_id} AND + Other_LcprepAdekuasiIsActive = 'Y' + WHERE + Lcprep_AdekuasiIsActive = 'Y' + GROUP BY Lcprep_AdekuasiID + ORDER BY Lcprep_AdekuasiOrder ASC + "; + //echo $sql; + $adeakuasi = $this->db_smartone->query($sql)->result_array(); + foreach($adeakuasi as $kc => $vc){ + $adeakuasi[$kc]['chex'] = $vc['chex'] == 'N'?false:true; + } + + $sql = "SELECT IFNULL(Other_LcprepKategoriUmumID,0) as xid, + Lcprep_KategoriUmumID as id, + Lcprep_KategoriUmumLabel as name, + IF(ISNULL(Other_LcprepKategoriUmumID),'N',Other_LcprepKategoriUmumChex) as chex + FROM lcprep_kategoriumum + LEFT JOIN other_lcprepkategoriumum ON Other_LcprepKategoriUmumLcprep_KategoriUmumID = Lcprep_KategoriUmumID AND + Other_LcprepKategoriUmumOther_LcprepID = {$header_id} AND + Other_LcprepKategoriUmumIsActive = 'Y' + WHERE + Lcprep_KategoriUmumIsActive = 'Y' + GROUP BY Lcprep_KategoriUmumID + "; + //echo $sql; + $kategoriumum = $this->db_smartone->query($sql)->result_array(); + foreach($kategoriumum as $kc => $vc){ + $kategoriumum[$kc]['chex'] = $vc['chex'] == 'N'?false:true; + } + + $sql = " + SELECT Lcprep_InterpretasiGroupID as group_id, + Lcprep_InterpretasiGroupName as group_name, + '' as subgroups + FROM lcprep_interpretasigroup + WHERE + Lcprep_InterpretasiGroupIsActive = 'Y' + "; + //echo $sql; + $interpretasi = $this->db_smartone->query($sql)->result_array(); + foreach($interpretasi as $k => $v){ + $subgroups = array(); + $sql = "SELECT Lcprep_InterpretasiSubgroupID as subgroup_id, + Lcprep_InterpretasiSubgroupName as subgroup_name, + '' as childs + FROM lcprep_interpretasisubgroup + WHERE + Lcprep_InterpretasiSubgroupLcprep_InterpretasiGroupID = {$v['group_id']} AND Lcprep_InterpretasiSubgroupIsActive = 'Y'"; + //echo $sql; + $subgroups = $this->db_smartone->query($sql)->result_array(); + if(count($subgroups) > 0){ + foreach($subgroups as $ki => $vi){ + $childs = array(); + $sql = "SELECT IFNULL(Other_LcprepInterpretasiID,0) as xid, + IFNULL(Other_LcprepInterpretasiChex,'N') as chex, + IFNULL(Other_LcprepInterpretasiValue,'') as value, + Lcprep_InterpretasiID as id, + Lcprep_InterpretasiLcprep_InterpretasiSubgroupID as subgroup_id, + Lcprep_InterpretasiCode as code, + Lcprep_InterpretasiName as name, + Lcprep_InterpretasiParentID as parent_id, + Lcprep_InterpretasiIsParent as is_parent, + Lcprep_InterpretasiHasResult as has_result, + Lcprep_InterpretasiTypeResult as type_result + FROM lcprep_interpretasi + LEFT JOIN other_lcprepinterpretasi ON Other_LcprepInterpretasiOther_LcprepID = {$header_id} AND + Other_LcprepInterpretasiLcprep_InterpretasiID = Lcprep_InterpretasiID AND + Other_LcprepInterpretasiIsActive = 'Y' + WHERE + Lcprep_InterpretasiLcprep_InterpretasiSubgroupID = {$vi['subgroup_id']} AND Lcprep_InterpretasiIsActive = 'Y' + GROUP BY Lcprep_InterpretasiID Order BY Lcprep_InterpretasiCode ASC"; + $childs = $this->db_smartone->query($sql)->result_array(); + if($childs){ + foreach($childs as $kc => $vc){ + $childs[$kc]['chex'] = $vc['chex'] == 'N'?false:true; + } + } + $subgroups[$ki]['childs'] = $childs; + } + } + + $interpretasi[$k]['subgroups'] = $subgroups; + } + + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $rst = array('doctors'=>$doctors,'results'=>$rows,'adekuasi'=>$adeakuasi,'kategoriumum'=>$kategoriumum,'interpretasi'=>$interpretasi); + $this->sys_ok(["records"=>$rst]); + } + + function getpapsmearresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT Other_PapSmearDetailsID as xid, + Other_PapSmearID as header_id, + Other_PapSmearT_OrderDetailID as orderdetail_id, + Other_PapSmearDetailsCode as code, + Other_PapSmearDetailsLabel as label, + Other_PapSmearDetailsResult as result, + IFNULL(Other_PapSmearM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_PapSmearM_DoctorID) OR Other_PapSmearM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_papsmear + JOIN other_papsmeardetails ON Other_PapSmearDetailsOther_PapSmearID = Other_PapSmearID AND Other_PapSmearDetailsIsActive = 'Y' + LEFT JOIN m_doctor ON Other_PapSmearM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_PapSmearT_OrderDetailID = {$id} AND Other_PapSmearIsActive = 'Y' + GROUP BY Other_PapSmearDetailsID + ORDER BY Other_PapSmearDetailsCode ASC"; + //echo $sql; + $rows = $this->db_smartone->query($sql)->result_array(); + if(!$rows){ + $rows = array( + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'A', + 'label' => 'Makroskopik', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ), + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'B', + 'label' => 'Mikroskopik', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ), + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'C', + 'label' => 'Kesimpulan', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ) + ); + } + + $header_id = $rows[0]['header_id']; + $sql = "SELECT Other_PapSmearMaturasiID as xid, + Other_PapSmearMaturasiValue as value + FROM other_papsmearmaturasi + WHERE + Other_PapSmearMaturasiOther_PapSmearID = {$header_id} AND + Other_PapSmearMaturasiIsActive = 'Y' + "; + //echo $sql; + $dt_maturasi = $this->db_smartone->query($sql)->row_array(); + if(!$dt_maturasi){ + $maturasi = array('xid'=>'0','value'=> array('','','')); + } + else{ + $value = explode('/',$dt_maturasi['value']); + $maturasi = array('xid'=>$dt_maturasi['xid'],'value'=> $value); + } + + $sql = "SELECT IFNULL(Other_PapSmearBahanID,0) as xid, + M_PapSmearBahanID as bahan_id, + M_PapSmearBahanName as name, + IF(ISNULL(Other_PapSmearBahanID),'N','Y') as selected + FROM m_papsmearbahan + LEFT JOIN other_papsmearbahan ON Other_PapSmearBahanM_PapSmearBahanID = M_PapSmearBahanID AND + Other_PapSmearBahanOther_PapSmearID = {$header_id} AND + Other_PapSmearBahanIsActive = 'Y' + WHERE + M_PapSmearBahanIsActive = 'Y' + ORDER BY M_PapSmearBahanID ASC + "; + //echo $sql; + $bahans = $this->db_smartone->query($sql)->result_array(); + + $sql = "SELECT IFNULL(Other_PapsmearCategoryID,0) as xid, + M_PapSmearCategoryID as category_id, + M_PapSmearCategoryName as name, + IF(ISNULL(Other_PapsmearCategoryID),'N','Y') as selected + FROM m_papsmearcategory + LEFT JOIN other_papsmearcategory ON Other_PapsmearCategoryM_PapSmearCategoryID = M_PapSmearCategoryID AND + Other_PapsmearCategoryOther_PapSmearID = {$header_id} AND + Other_PapsmearCategoryIsActive = 'Y' + WHERE + M_PapSmearCategoryIsActive = 'Y' + ORDER BY M_PapSmearCategoryID ASC + "; + //echo $sql; + $categories = $this->db_smartone->query($sql)->result_array(); + + $sql = "SELECT IFNULL(Other_PapSmearCheckID,0) as xid, + M_PapSmearCheckID as check_id, + M_PapSmearCheckLabel as name, + IF(ISNULL(Other_PapSmearCheckID),'N','Y') as selected, + Other_PapSmearCheckNote as note + FROM m_papsmearcheck + LEFT JOIN other_papsmearcheck ON Other_PapSmearCheckM_PapSmearCheckID = M_PapSmearCheckID AND + Other_PapSmearCheckOther_PapSmearID = {$header_id} AND + Other_PapSmearCheckIsActive = 'Y' + WHERE + M_PapSmearCheckIsActive = 'Y' + ORDER BY M_PapSmearCheckCode ASC + "; + $checks = $this->db_smartone->query($sql)->result_array(); + + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $rst = array('doctors'=>$doctors,'checks'=>$checks,'bahans'=>$bahans,'categories'=>$categories,'maturasi'=>$maturasi,'results'=>$rows); + $this->sys_ok(["records"=>$rst]); + + } + + function saveresult_lcprep() + { + $prm = $this->sys_input; + $detail_id = $prm['detail_id']; + $doctor_id = $prm['doctor']; + $adekuasi = $prm['adekuasi']; + $kategoriumum = $prm['kategoriumum']; + $interpretasi = $prm['interpretasi']; + $results = $prm['results']; + + $userid = $this->sys_user['M_UserID']; + + $header_id = 0; + $sql = "SELECT * FROM other_lcprep WHERE Other_LcprepT_orderDetailID = {$detail_id} AND Other_LcprepIsActive = 'Y'"; + $dt_header = $this->db_smartone->query($sql)->row_array(); + if($dt_header){ + $header_id = $dt_header['Other_LcprepID']; + } + if($header_id == 0){ + $sql = "INSERT INTO other_lcprep( + Other_LcprepT_orderDetailID, + Other_LcprepM_DoctorID, + Other_LcprepUserID, + Other_LcprepCreated + ) + VALUES( + {$detail_id}, + {$doctor_id}, + {$userid}, + NOW() + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + }else{ + $sql = "UPDATE other_lcprep SET Other_LcprepM_DoctorID = {$doctor_id}, Other_LcprepUserID = {$userid} WHERE Other_LcprepID = {$header_id}"; + $this->db_smartone->query($sql); + } + + if($adekuasi){ + foreach($adekuasi as $k =>$v){ + $selected = $v['chex']?'Y':'N'; + if(intval($v['xid'] == 0)){ + $sql = "UPDATE other_lcprepadekuasi SET Other_LcprepAdekuasiIsActive = 'N' + WHERE + Other_LcprepAdekuasiOther_LcprepID = {$header_id} AND + Other_LcprepAdekuasiIsActive = 'Y' AND + Other_LcprepAdekuasiLcprep_AdekuasiID = {$v['id']}"; + $this->db_smartone->query($sql); + $sql = "INSERT INTO other_lcprepadekuasi ( + Other_LcprepAdekuasiOther_LcprepID, + Other_LcprepAdekuasiLcprep_AdekuasiID, + Other_LcprepAdekuasiChex, + Other_LcprepAdekuasiUserID, + Other_LcprepAdekuasiCreated + ) + VALUES( + {$header_id}, + {$v['id']}, + '{$selected}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + //echo $sql; + } + if(intval($v['xid'] != 0)){ + + $sql = "UPDATE other_lcprepadekuasi SET + Other_LcprepAdekuasiChex = '{$selected}', + Other_LcprepAdekuasiUserID = {$userid} + WHERE + Other_LcprepAdekuasiID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + + //echo $sql; + } + } + + if($kategoriumum){ + foreach($kategoriumum as $k =>$v){ + $selected = $v['chex']?'Y':'N'; + if(intval($v['xid'] == 0)){ + $sql = "UPDATE other_lcprepkategoriumum SET Other_LcprepKategoriUmumIsActive = 'N' + WHERE + Other_LcprepKategoriUmumOther_LcprepID = {$header_id} AND + Other_LcprepKategoriUmumLcprep_KategoriUmumID = {$v['id']} AND + Other_LcprepKategoriUmumIsActive = 'Y' + "; + $this->db_smartone->query($sql); + $sql = "INSERT INTO other_lcprepkategoriumum ( + Other_LcprepKategoriUmumOther_LcprepID, + Other_LcprepKategoriUmumLcprep_KategoriUmumID, + Other_LcprepKategoriUmumChex, + Other_LcprepKategoriUmumUserID, + Other_LcprepKategoriUmumCreated + ) + VALUES( + {$header_id}, + {$v['id']}, + '{$selected}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if(intval($v['xid'] != 0)){ + $sql = "UPDATE other_lcprepkategoriumum SET + Other_LcprepKategoriUmumChex = '{$selected }', + Other_LcprepKategoriUmumUserID = {$userid} + WHERE + Other_LcprepKategoriUmumID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + + //echo $sql; + } + } + + if($results){ + foreach($results as $k =>$v){ + if(intval($v['xid'] == 0)){ + $sql = "UPDATE other_lcprepdetails SET Other_LcprepDetailsIsActive = 'N' + WHERE + Other_LcprepDetailsOther_LcprepID = {$header_id} AND + Other_LcprepDetailsCode = '{$v['code']}' AND + Other_LcprepDetailsIsActive = 'Y'"; + $this->db_smartone->query($sql); + $sql = "INSERT INTO other_lcprepdetails ( + Other_LcprepDetailsOther_LcprepID, + Other_LcprepDetailsCode, + Other_LcprepDetailsLabel, + Other_LcprepDetailsResult, + Other_LcprepDetailsUserID, + Other_LcprepDetailsCreated + ) + VALUES( + {$header_id}, + '{$v['code']}', + '{$v['label']}', + '{$v['result']}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if(intval($v['xid'] != 0)){ + $sql = "UPDATE other_lcprepdetails SET + Other_LcprepDetailsCode = '{$v['code']}', + Other_LcprepDetailsLabel = '{$v['label']}', + Other_LcprepDetailsResult = '{$v['result']}', + Other_LcprepDetailsUserID = {$userid} + WHERE + Other_LcprepDetailsID = {$v['xid']}"; + $this->db_smartone->query($sql); + + } + //echo $sql; + } + } + + if($interpretasi){ + foreach($interpretasi as $k =>$v){ + if(count($v['subgroups']) > 0){ + foreach($v['subgroups'] as $ik => $iv){ + if(count($iv['childs']) > 0){ + foreach($iv['childs'] as $iik => $iiv){ + if(intval($iiv['xid'] == 0)){ + $chex = $iiv['chex'] ? 'Y':'N'; + $sql = "UPDATE other_lcprepinterpretasi SET Other_LcprepInterpretasiIsActive = 'N' + WHERE + Other_LcprepInterpretasiOther_LcprepID = {$header_id} AND + Other_LcprepInterpretasiLcprep_InterpretasiID = '{$iiv['id']}' AND + Other_LcprepInterpretasiIsActive = 'Y'"; + $this->db_smartone->query($sql); + $sql = "INSERT INTO other_lcprepinterpretasi ( + Other_LcprepInterpretasiOther_LcprepID, + Other_LcprepInterpretasiLcprep_InterpretasiID, + Other_LcprepInterpretasiChex, + Other_LcprepInterpretasiValue, + Other_LcprepInterpretasiUserID, + Other_LcprepInterpretasiCreated + ) + VALUES( + {$header_id}, + '{$iiv['id']}', + '{$chex}', + '{$iiv['value']}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + + if(intval($iiv['xid'] != 0)){ + $chex = $iiv['chex'] ? 'Y':'N'; + $sql = "UPDATE other_lcprepinterpretasi SET + Other_LcprepInterpretasiChex = '{$chex}', + Other_LcprepInterpretasiValue = '{$iiv['value']}', + Other_LcprepInterpretasiUserID = {$userid} + WHERE + Other_LcprepInterpretasiID = {$iiv['xid']}"; + $this->db_smartone->query($sql); + //echo $sql; + + } + + } + } + } + } + //echo $sql; + } + } + + + $result = array("total" => 1, "records" => array(), "sql"=> ''); + $this->sys_ok($result); + exit; + } + + function saveresult_papsmear() + { + $prm = $this->sys_input; + $detail_id = $prm['detail_id']; + $doctor_id = $prm['doctor']; + $checks = $prm['checks']; + $maturasi = $prm['maturasi']; + $bahans = $prm['bahans']; + $categories = $prm['categories']; + $results = $prm['results']; + + $userid = $this->sys_user['M_UserID']; + + $header_id = 0; + $sql = "SELECT * FROM other_papsmear WHERE Other_PapSmearT_OrderDetailID = {$detail_id} AND Other_PapSmearIsActive = 'Y'"; + $dt_header = $this->db_smartone->query($sql)->row_array(); + if($dt_header){ + $header_id = $dt_header['Other_PapSmearID']; + } + if($header_id == 0){ + $sql = "INSERT INTO other_papsmear( + Other_PapSmearT_OrderDetailID, + Other_PapSmearM_DoctorID, + Other_PapSmearUserID, + Other_PapSmearCreated + ) + VALUES( + {$detail_id}, + {$doctor_id}, + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } + else{ + $sql = "UPDATE other_papsmear SET Other_PapSmearM_DoctorID = {$doctor_id}, Other_PapSmearUserID = {$userid} WHERE Other_PapSmearID = {$header_id}"; + $this->db_smartone->query($sql); + } + + if($checks){ + foreach($checks as $k =>$v){ + if(intval($v['xid']) == 0 && $v['selected'] === 'Y'){ + $sql = "INSERT INTO other_papsmearcheck ( + Other_PapSmearCheckOther_PapSmearID, + Other_PapSmearCheckM_PapSmearCheckID, + Other_PapSmearCheckNote, + Other_PapSmearCheckUserID, + Other_PapSmearCheckCreated + ) + VALUES( + {$header_id}, + {$v['check_id']}, + '{$v['note']}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if(intval($v['xid']) != 0 && $v['selected'] === 'N'){ + $sql = "UPDATE other_papsmearcheck SET + Other_PapSmearCheckIsActive = 'N', + Other_PapSmearCheckUserID = {$userid} + WHERE + Other_PapSmearCheckID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + if(intval($v['xid']) != 0 && $v['selected'] === 'Y'){ + $sql = "UPDATE other_papsmearcheck SET + Other_PapSmearCheckNote = '{$v['note']}', + Other_PapSmearCheckUserID = {$userid} + WHERE + Other_PapSmearCheckID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + //echo $sql; + } + } + + if($maturasi){ + if(intval($maturasi['xid']) == 0){ + $value = join("/",$maturasi['value']); + $sql = "INSERT INTO other_papsmearmaturasi ( + Other_PapSmearMaturasiOther_PapSmearID, + Other_PapSmearMaturasiValue, + Other_PapSmearMaturasiUserID, + Other_PapSmearMaturasiCreated + ) + VALUE( + {$header_id}, + '{$value}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + //echo $sql; + } + if(intval($maturasi['xid']) != 0){ + $value = join("/",$maturasi['value']); + $sql = "UPDATE other_papsmearmaturasi SET + Other_PapSmearMaturasiValue = '{$value}', + Other_PapSmearMaturasiUserID = {$userid} + WHERE + Other_PapSmearMaturasiID = {$maturasi['xid']}"; + // echo $sql; + $this->db_smartone->query($sql); + } + } + + if($bahans){ + foreach($bahans as $k =>$v){ + if(intval($v['xid']) == 0 && $v['selected'] === 'Y'){ + $sql = "INSERT INTO other_papsmearbahan ( + Other_PapSmearBahanOther_PapSmearID, + Other_PapSmearBahanM_PapSmearBahanID, + Other_PapSmearBahanUserID, + Other_PapSmearBahanCreated + ) + VALUES( + {$header_id}, + {$v['bahan_id']}, + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if(intval($v['xid']) != 0 && $v['selected'] === 'N'){ + $sql = "UPDATE other_papsmearbahan SET + Other_PapSmearBahanIsActive = 'N', + Other_PapsmearCategoryUserID = {$userid} + WHERE + Other_PapSmearBahanID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + if(intval($v['xid']) != 0 && $v['selected'] === 'Y'){ + $sql = "UPDATE other_papsmearbahan SET + Other_PapSmearBahanIsActive = 'Y', + Other_PapsmearCategoryUserID = {$userid} + WHERE + Other_PapSmearBahanID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + //echo $sql; + } + } + + if($categories){ + foreach($categories as $k =>$v){ + if(intval($v['xid']) == 0 && $v['selected'] === 'Y'){ + $sql = "INSERT INTO other_papsmearcategory ( + Other_PapsmearCategoryOther_PapSmearID, + Other_PapsmearCategoryM_PapSmearCategoryID, + Other_PapsmearCategoryUserID, + Other_PapsmearCategoryCreated + ) + VALUES( + {$header_id}, + {$v['category_id']}, + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if(intval($v['xid']) != 0 && $v['selected'] === 'N'){ + $sql = "UPDATE other_papsmearcategory SET + Other_PapsmearCategoryIsActive = 'N', + Other_PapsmearCategoryUserID = {$userid} + WHERE + Other_PapsmearCategoryID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + //echo $sql; + if(intval($v['xid']) != 0 && $v['selected'] === 'Y'){ + $sql = "UPDATE other_papsmearcategory SET + Other_PapsmearCategoryIsActive = 'Y', + Other_PapsmearCategoryUserID = {$userid} + WHERE + Other_PapsmearCategoryID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + } + } + + if($results){ + foreach($results as $k =>$v){ + if(intval($v['xid']) == 0){ + $sql = "INSERT INTO other_papsmeardetails ( + Other_PapSmearDetailsOther_PapSmearID, + Other_PapSmearDetailsCode, + Other_PapSmearDetailsLabel, + Other_PapSmearDetailsResult, + Other_PapSmearDetailsUserID, + Other_PapSmearDetailsCreated + ) + VALUES( + {$header_id}, + '{$v['code']}', + '{$v['label']}', + '{$v['result']}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if(intval($v['xid']) != 0){ + $sql = "UPDATE other_papsmeardetails SET + Other_PapSmearDetailsCode = '{$v['code']}', + Other_PapSmearDetailsLabel = '{$v['label']}', + Other_PapSmearDetailsResult = '{$v['result']}', + Other_PapSmearDetailsUserID = {$userid} + WHERE + Other_PapSmearDetailsID = {$v['xid']}"; + $this->db_smartone->query($sql); + + } + //echo $sql; + } + } + + $result = array("total" => 1, "records" => array(), "sql"=> ''); + $this->sys_ok($result); + exit; + } + + function saveresult_fna() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = $inp['doctor']; + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + if($prm[0]['xid'] == '0'){ + $sql = "INSERT INTO other_fna( + Other_FNAM_DoctorID, + Other_FNAT_OrderDetailID, + Other_FNAUserID, + Other_FNACreated + ) + VALUES( + {$doctor_id}, + {$prm[0]['orderdetail_id']}, + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } + else{ + $sql = "SELECT * FROM other_fna WHERE Other_FNAT_OrderDetailID = {$prm[0]['orderdetail_id']} AND Other_FNAIsActive = 'Y'"; + $data_header = $this->db_smartone->query($sql)->row_array(); + $header_id = $data_header['Other_FNAID']; + $sql = "UPDATE other_fna SET + Other_FNAM_DoctorID = {$doctor_id}, + Other_FNAUserID = {$userid} + WHERE + Other_FNAID = {$header_id}"; + $this->db_smartone->query($sql); + } + foreach($prm as $k => $v){ + if($v['xid'] == '0'){ + $results = str_replace("'", "\\'", $v['result']); + $sql = "INSERT INTO other_fnadetails( + Other_FNADetailsOther_FNAID , + Other_FNADetailsCode, + Other_FNADetailsLabel, + Other_FNADetailsResult, + Other_FNADetailsCreated, + Other_FNADetailsUserID + ) + VALUES( + {$header_id}, + '{$v['code']}', + '{$v['label']}', + '{$results}', + NOW(), + {$userid} + )"; + $query = $this->db_smartone->query($sql); + } + else{ + $results = str_replace("'", "\\'", $v['result']); + $sql = "UPDATE other_fnadetails SET + Other_FNADetailsResult = '{$results}', + Other_FNADetailsUserID = {$userid} + WHERE + Other_FNADetailsID = {$v['xid']}"; + $query = $this->db_smartone->query($sql); + } + } + + $result = array("total" => 1, "records" => array(), "sql"=> ''); + $this->sys_ok($result); + exit; + } + + function saveresult_cytologi() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = $inp['doctor']; + + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + if($prm[0]['xid'] == '0'){ + $sql = "INSERT INTO other_cytologi( + Other_CytologiT_OrderDetailID, + Other_CytologiM_DoctorID, + Other_CytologiUserID, + Other_CytologiCreated + ) + VALUES( + {$prm[0]['orderdetail_id']}, + {$doctor_id}, + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } + else{ + $sql = "SELECT * FROM other_cytologi WHERE Other_CytologiT_OrderDetailID = {$prm[0]['orderdetail_id']} AND Other_CytologiIsActive = 'Y'"; + $data_header = $this->db_smartone->query($sql)->row_array(); + $header_id = $data_header['Other_CytologiID']; + $sql = "UPDATE other_cytologi SET + Other_CytologiM_DoctorID = {$doctor_id}, + Other_CytologiUserID = {$userid} + WHERE + Other_CytologiID = {$header_id}"; + $this->db_smartone->query($sql); + } + foreach($prm as $k => $v){ + if($v['xid'] == '0'){ + $results = str_replace("'", "\\'", $v['result']); + $sql = "INSERT INTO other_cytologidetails( + Other_CytologiDetailsOther_CytologiID , + Other_CytologiDetailsCode, + Other_CytologiDetailsLabel, + Other_CytologiDetailsResult, + Other_CytologiDetailsCreated, + Other_CytologiDetailsUserID + ) + VALUES( + {$header_id}, + '{$v['code']}', + '{$v['label']}', + '{$results}', + NOW(), + {$userid} + )"; + $query = $this->db_smartone->query($sql); + } + else{ + $results = str_replace("'", "\\'", $v['result']); + $sql = "UPDATE other_cytologidetails SET + Other_CytologiDetailsResult = '{$results}', + Other_CytologiDetailsUserID = {$userid} + WHERE + Other_CytologiDetailsID = {$v['xid']}"; + $query = $this->db_smartone->query($sql); + } + } + + $result = array("total" => 1, "records" => array(), "sql"=> ''); + $this->sys_ok($result); + exit; + } + + function saveresult_mikro() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = $inp['doctor']; + $backteria_id = $inp['bacteria']; + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + + if($inp['result_value'] != 'Negatif' && $inp['result_value'] != 'Positif'){ + $prm['result_value'] = $prm['result_other']; + } + else{ + $prm['result_value'] = $inp['result_value']; + } + + if($prm['xid'] == '0'){ + $sql = "INSERT INTO other_mikro( + Other_MikroM_DoctorID, + Other_MikroResult, + Other_MikroT_BacteriaID, + Other_MikroT_OrderDetailID, + Other_MikroHasilBiakan, + Other_MikroSampleTypeName, + Other_MikroUserID, + Other_MikroCreated + ) + VALUES( + {$doctor_id}, + '{$prm['result_value']}', + {$backteria_id}, + {$prm['orderdetail_id']}, + '{$prm['hasil_biakan']}', + '{$prm['sample_name']}', + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } + else{ + $sql = "SELECT * FROM other_mikro WHERE Other_MikroT_OrderDetailID = {$prm['orderdetail_id']} AND Other_MikroIsActive = 'Y'"; + $data_header = $this->db_smartone->query($sql)->row_array(); + $header_id = $data_header['Other_MikroID']; + $sql = "UPDATE other_mikro SET + Other_MikroResult = '{$prm['result_value']}', + Other_MikroM_DoctorID = {$doctor_id}, + Other_MikroT_BacteriaID = {$backteria_id}, + Other_MikroHasilBiakan = '{$prm['hasil_biakan']}', + Other_MikroSampleTypeName = '{$prm['sample_name']}', + Other_MikroUserID = {$userid} + WHERE + Other_MikroID = {$header_id}"; + //echo $sql; + $this->db_smartone->query($sql); + } + + + + $sql = "UPDATE other_mikrodetails SET Other_MikroDetailsIsActive = 'N', Other_MikroDetailsUserID = 0 WHERE Other_MikroDetailsOther_MikroID = {$header_id}"; + $this->db_smartone->query($sql); + + $results = $prm['details']; + if($inp['result_value'] == 'Positif'){ + foreach($results as $k => $v){ + if($v['xid'] == '0'){ + $sql = "INSERT INTO other_mikrodetails( + Other_MikroDetailsOther_MikroID , + Other_MikroDetailsT_AntibioticID, + Other_MikroDetailsValue, + Other_MikroDetailsNote, + Other_MikroDetailsCreated, + Other_MikroDetailsUserID + ) + VALUES( + {$header_id}, + '{$v['T_AntibioticID']}', + '{$v['value']}', + '{$v['note']}', + NOW(), + {$userid} + )"; + $query = $this->db_smartone->query($sql); + } + else{ + $sql = "UPDATE other_mikrodetails SET + Other_MikroDetailsT_AntibioticID = '{$v['T_AntibioticID']}', + Other_MikroDetailsValue = '{$v['value']}', + Other_MikroDetailsNote = '{$v['note']}', + Other_MikroDetailsIsActive = 'Y', + Other_MikroDetailsUserID = {$userid} + WHERE + Other_MikroDetailsID = {$v['xid']}"; + //echo $sql; + $query = $this->db_smartone->query($sql); + } + } + } + + + $result = array("total" => 1, "records" => array(), "sql"=> ''); + $this->sys_ok($result); + exit; + } + + + function get_doctors_preparasi_sperma() + { + $prm = $this->sys_input; + // $id = $prm["id"]; + + $sql = " SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 10 AND + M_DoctorSOIsActive = 'Y' + ORDER BY M_DoctorName ASC"; + //echo $sql; + $query = $this->db_smartone->query($sql); + $rows = $query->result_array(); + $sql = " + SELECT '0' as id, 'Belum memilih metode' as name + UNION + SELECT M_MethodeSpermaID as id, M_MethodeSpermaName as name + FROM m_methodesperma + WHERE + M_MethodeSpermaIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $methodes = $this->db_smartone->query($sql)->result_array(); + + + $this->sys_ok(["records"=>$rows,"methodes"=>$methodes]); + + } + + + function getpreparasispermaresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT other_preparasisperma.*, + Other_PreparasiSpermaID as xid, + Other_PreparasiSpermaT_OrderDetailID as orderdetail_id, + IFNULL(Other_PreparasiSpermaM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_PreparasiSpermaM_DoctorID) OR Other_PreparasiSpermaM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name, + IFNULL(M_MethodeSpermaID,0) as methode_id, + IFNULL(M_MethodeSpermaName,'') as methode_name + FROM other_preparasisperma + LEFT JOIN m_doctor ON Other_PreparasiSpermaM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + LEFT JOIN m_methodesperma ON Other_PreparasiSpermaM_MethodeSpermaID = M_MethodeSpermaID AND + M_MethodeSpermaIsActive = 'Y' + WHERE + Other_PreparasiSpermaT_OrderDetailID = {$id} AND Other_PreparasiSpermaIsActive = 'Y' + GROUP BY Other_PreparasiSpermaID"; + $query = $this->db_smartone->query($sql); + + if ($query) + { + $rows = $query->row_array(); + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 10 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $sql = " + SELECT '0' as id, 'Belum memilih metode' as name + UNION + SELECT M_MethodeSpermaID as id, M_MethodeSpermaName as name + FROM m_methodesperma + WHERE + M_MethodeSpermaIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $methodes = $this->db_smartone->query($sql)->result_array(); + $images = array(); + $sql = "SELECT Other_PreparasiSpermaImgID as xid, + Other_PreparasiSpermaImgType as type, + CONCAT('/one-media/one-image-nonlab/',Other_PreparasiSpermaImgNewName) as image_url + FROM t_orderdetail + JOIN other_preparasisperma_img ON Other_PreparasiSpermaImgT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND + Other_PreparasiSpermaImgIsActive = 'Y' + WHERE + T_OrderDetailID = {$id} AND + T_OrderDetailIsActive = 'Y' + GROUP BY Other_PreparasiSpermaImgID"; + //echo $sql; + $images = $this->db_smartone->query($sql)->result_array(); + + $rst = array('doctors'=>$doctors,'methodes'=>$methodes,'results'=>$rows,'images'=>$images); + $this->sys_ok(["records"=>$rst]); + } + else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + + function uploadimage_preparasi_sperma(){ + if (! $this->isLogin) { + $this->sys_error("Invalid Token"); + exit; + } + + $userid = $this->sys_user["M_UserID"]; + $data = []; + //print_r($_SERVER); + + $prm = $this->sys_input; + $orderid = $this->input->post('orderid'); + $type = $this->input->post('type'); + $labnumber = $this->input->post('labnumber'); + $sql = "UPDATE other_preparasisperma_img SET + Other_PreparasiSpermaImgIsActive = 'N', + Other_PreparasiSpermaImgUserID = {$userid} + WHERE + Other_PreparasiSpermaImgT_OrderHeaderID = {$orderid} AND + Other_PreparasiSpermaImgType = '{$type}'"; + //echo $sql; + $this->db_onedev->query($sql); + //$config['upload_path'] = 'assets/'; + + $path = '/home/one/project/one/one-media/one-image-nonlab/'; + //echo $path; + $config['upload_path'] = $path; + $config['allowed_types'] = 'jpg|jpeg|png|gif'; + + $config['max_size'] = '10000'; + $count = count($_FILES['files']['name']); + //echo $count; + $this->load->library('upload',$config); + + $error = []; + for($i=0;$i<$count;$i++){ + + + if(!empty($_FILES['files']['name'][$i])){ + + + + $_FILES['file']['name'] = $_FILES['files']['name'][$i]; + + $_FILES['file']['type'] = $_FILES['files']['type'][$i]; + + $_FILES['file']['tmp_name'] = $_FILES['files']['tmp_name'][$i]; + + $_FILES['file']['error'] = $_FILES['files']['error'][$i]; + + $_FILES['file']['size'] = $_FILES['files']['size'][$i]; + + + + $namex = $orderid.'-'.$labnumber.'-'.$this->generateRandomString(5); + //echo $namex; + + $config['file_name'] = $namex; + $this->upload->initialize($config); + //echo $config['file_name'] ; + + + + + + if($this->upload->do_upload('file')){ + + $uploadData = $this->upload->data(); + + $filename = $uploadData['file_name']; + //echo $filename; + + + $sql = "INSERT INTO other_preparasisperma_img ( + Other_PreparasiSpermaImgT_OrderHeaderID, + Other_PreparasiSpermaImgType, + Other_PreparasiSpermaImgOldName, + Other_PreparasiSpermaImgNewName, + Other_PreparasiSpermaImgCreated, + Other_PreparasiSpermaImgUserID + ) + VALUES( + {$orderid}, + '{$type}', + '{$_FILES['files']['name'][$i]}', + '{$filename}', + NOW(), + {$userid} + + )"; + //echo $sql; + $this->db_onedev->query($sql); + $xlast_id = $this->db_onedev->insert_id(); + $data['totalFiles'][] = array('xid' => $xlast_id ,'type'=>$type,'image_url' => '/one-media/one-image-nonlab/'.$filename); + + } + else{ + $error = array('error' => $this->upload->display_errors()); + } + + } + + + + } + + $result = array("total" =>count( $data['totalFiles']), "records" => $data['totalFiles'],'errors'=>$error); + $this->sys_ok($result); + } + + + function saveresult_preparasi_sperma() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = $inp['doctor']; + $orderdetail_id = $inp['orderdetailid']; + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + if($prm['xid'] == '0'){ + $sql = "INSERT INTO other_preparasisperma( + Other_PreparasiSpermaM_DoctorID, + Other_PreparasiSpermaT_OrderDetailID, + Other_PreparasiSpermaPreMotilitasA, + Other_PreparasiSpermaPreMotilitasB, + Other_PreparasiSpermaPreMotilitasC, + Other_PreparasiSpermaPreKonsentrasi, + Other_PreparasiSpermaPreKontaminan, + Other_PreparasiSpermaPostMotilitasA, + Other_PreparasiSpermaPostMotilitasB, + Other_PreparasiSpermaPostMotilitasC, + Other_PreparasiSpermaPostKonsentrasi, + Other_PreparasiSpermaPostKontaminan, + Other_PreparasiSpermaPreVolume, + Other_PreparasiSpermaPostVolume, + Other_PreparasiSpermaM_MethodeSpermaID, + Other_PreparasiSpermaNote, + Other_PreparasiSpermaUserID, + Other_PreparasiSpermaCreated + ) + VALUES( + {$doctor_id}, + {$orderdetail_id}, + '{$prm['Other_PreparasiSpermaPreMotilitasA']}', + '{$prm['Other_PreparasiSpermaPreMotilitasB']}', + '{$prm['Other_PreparasiSpermaPreMotilitasC']}', + '{$prm['Other_PreparasiSpermaPreKonsentrasi']}', + '{$prm['Other_PreparasiSpermaPreKontaminan']}', + '{$prm['Other_PreparasiSpermaPostMotilitasA']}', + '{$prm['Other_PreparasiSpermaPostMotilitasB']}', + '{$prm['Other_PreparasiSpermaPostMotilitasC']}', + '{$prm['Other_PreparasiSpermaPostKonsentrasi']}', + '{$prm['Other_PreparasiSpermaPostKontaminan']}', + '{$prm['Other_PreparasiSpermaPreVolume']}', + '{$prm['Other_PreparasiSpermaPostVolume']}', + '{$prm['Other_PreparasiSpermaM_MethodeSpermaID']}', + '{$prm['Other_PreparasiSpermaNote']}', + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } + else{ + $sql = "SELECT * FROM other_preparasisperma WHERE Other_PreparasiSpermaT_OrderDetailID = {$orderdetail_id} AND Other_PreparasiSpermaIsActive = 'Y'"; + $data_header = $this->db_smartone->query($sql)->row_array(); + $header_id = $data_header['Other_PreparasiSpermaID']; + $sql = "UPDATE other_preparasisperma SET + Other_PreparasiSpermaM_DoctorID = {$doctor_id}, + Other_PreparasiSpermaPreMotilitasA = '{$prm['Other_PreparasiSpermaPreMotilitasA']}', + Other_PreparasiSpermaPreMotilitasB = '{$prm['Other_PreparasiSpermaPreMotilitasB']}', + Other_PreparasiSpermaPreMotilitasC = '{$prm['Other_PreparasiSpermaPreMotilitasC']}', + Other_PreparasiSpermaPreKonsentrasi = '{$prm['Other_PreparasiSpermaPreKonsentrasi']}', + Other_PreparasiSpermaPreKontaminan = '{$prm['Other_PreparasiSpermaPreKontaminan']}', + Other_PreparasiSpermaPostMotilitasA = '{$prm['Other_PreparasiSpermaPostMotilitasA']}', + Other_PreparasiSpermaPostMotilitasB = '{$prm['Other_PreparasiSpermaPostMotilitasB']}', + Other_PreparasiSpermaPostMotilitasC = '{$prm['Other_PreparasiSpermaPostMotilitasC']}', + Other_PreparasiSpermaPostKonsentrasi = '{$prm['Other_PreparasiSpermaPostKonsentrasi']}', + Other_PreparasiSpermaPostKontaminan = '{$prm['Other_PreparasiSpermaPostKontaminan']}', + Other_PreparasiSpermaPreVolume = '{$prm['Other_PreparasiSpermaPreVolume']}', + Other_PreparasiSpermaPostVolume = '{$prm['Other_PreparasiSpermaPostVolume']}', + Other_PreparasiSpermaM_MethodeSpermaID = '{$prm['Other_PreparasiSpermaM_MethodeSpermaID']}', + Other_PreparasiSpermaNote = '{$prm['Other_PreparasiSpermaNote']}', + Other_PreparasiSpermaUserID = {$userid} + WHERE + Other_PreparasiSpermaID = {$header_id}"; + $this->db_smartone->query($sql); + } + + + $result = array("total" => 1, "records" => array(), "sql"=> ''); + $this->sys_ok($result); + exit; + } + + function getdnafragmentasiresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT other_dnafragmentasi.*, + Other_DnaFragmentasiID as xid, + Other_DnaFragmentasiT_OrderDetailID as orderdetail_id, + IFNULL(Other_DnaFragmentasiM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_DnaFragmentasiM_DoctorID) OR Other_DnaFragmentasiM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name, + IFNULL(Other_DnaFragmentasiOther_DnaFragmentasiMethodeID,0) as methode_id, + IFNULL(Other_DnaFragmentasiMethodeName,'') as methode_name, + Other_DnaFragmentasiHaloLuas as halo_luas, + Other_DnaFragmentasiHaloSedang as halo_sedang, + Other_DnaFragmentasiHaloSempit as halo_sempit, + Other_DnaFragmentasiTanpaHalo as tanpa_halo, + Other_DnaFragmentasiDFI as dfi, + Other_DnaFragmentasiKesimpulan as kesimpulan, + Other_DnaFragmentasiCatatan as catatan + FROM other_dnafragmentasi + LEFT JOIN m_doctor ON Other_DnaFragmentasiM_DoctorID = M_DoctorID + LEFT JOIN other_dnafragmentasimethode ON Other_DnaFragmentasiOther_DnaFragmentasiMethodeID = Other_DnaFragmentasiMethodeID + WHERE + Other_DnaFragmentasiT_OrderDetailID = {$id} AND Other_DnaFragmentasiIsActive = 'Y' + GROUP BY Other_DnaFragmentasiID + LIMIT 1"; + //echo $sql; + $query = $this->db_smartone->query($sql); + + if ($query) + { + $rows = $query->row_array(); + if(!$rows){ + $rows = array( + 'xid' => 0, + 'orderdetail_id' =>$id, + 'doctor_id' => 0, + 'doctor_name' => '', + 'methode_id' => 0, + 'methode_name' => '', + 'halo_luas' => '', + 'halo_sedang' => '', + 'tanpa_halo' => '', + 'dfi' => '', + 'kesimpulan' => '', + 'catatan' => '' + ); + } + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID + WHERE + M_DoctorSONat_SubGroupID = 4 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + + $sql = " + SELECT '0' as id, 'Belum memilih metode' as name + UNION + SELECT Other_DnaFragmentasiMethodeID as id, Other_DnaFragmentasiMethodeName as name + FROM other_dnafragmentasimethode + WHERE + Other_DnaFragmentasiMethodeIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $methodes = $this->db_smartone->query($sql)->result_array(); + + + $rst = array('doctors'=>$doctors,'methodes'=>$methodes,'results'=>$rows); + $this->sys_ok(["records"=>$rst]); + } + else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + function saveresult_dnafragmentasi() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = $inp['doctor']['id']; + $methode_id = $inp['methode']['id']; + $orderdetail_id = $inp['results']['orderdetail_id']; + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + if(intval($prm['xid']) == 0){ + $sql = "INSERT INTO other_dnafragmentasi( + Other_DnaFragmentasiT_OrderDetailID, + Other_DnaFragmentasiM_DoctorID, + Other_DnaFragmentasiOther_DnaFragmentasiMethodeID, + Other_DnaFragmentasiHaloLuas, + Other_DnaFragmentasiHaloSedang, + Other_DnaFragmentasiHaloSempit, + Other_DnaFragmentasiTanpaHalo, + Other_DnaFragmentasiDFI, + Other_DnaFragmentasiKesimpulan, + Other_DnaFragmentasiCatatan, + Other_DnaFragmentasiUserID, + Other_DnaFragmentasiLastUpdated + ) + VALUES( + {$orderdetail_id}, + {$doctor_id}, + {$methode_id}, + '{$prm['halo_luas']}', + '{$prm['halo_sedang']}', + '{$prm['halo_sempit']}', + '{$prm['tanpa_halo']}', + '{$prm['dfi']}', + '{$prm['kesimpulan']}', + '{$prm['catatan']}', + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } + else{ + $sql = "UPDATE other_dnafragmentasi SET + Other_DnaFragmentasiT_OrderDetailID = {$orderdetail_id}, + Other_DnaFragmentasiM_DoctorID = {$doctor_id}, + Other_DnaFragmentasiOther_DnaFragmentasiMethodeID = '{$methode_id}', + Other_DnaFragmentasiHaloLuas = '{$prm['halo_luas']}', + Other_DnaFragmentasiHaloSedang = '{$prm['halo_sedang']}', + Other_DnaFragmentasiHaloSempit = '{$prm['halo_sempit']}', + Other_DnaFragmentasiTanpaHalo = '{$prm['tanpa_halo']}', + Other_DnaFragmentasiDFI = '{$prm['dfi']}', + Other_DnaFragmentasiKesimpulan = '{$prm['kesimpulan']}', + Other_DnaFragmentasiCatatan = '{$prm['catatan']}', + Other_DnaFragmentasiLastUpdated = NOW(), + Other_DnaFragmentasiUserID = {$userid} + WHERE + Other_DnaFragmentasiID = {$prm['xid']}"; + //echo $sql; + $this->db_smartone->query($sql); + } + + + $result = array("total" => 1, "records" => array(), "sql"=> ''); + $this->sys_ok($result); + exit; + } + + +} + diff --git a/application/controllers/mockup/process/resultvalidation-v23/Re_px.php b/application/controllers/mockup/process/resultvalidation-v23/Re_px.php index 34a3086b..2d75999a 100644 --- a/application/controllers/mockup/process/resultvalidation-v23/Re_px.php +++ b/application/controllers/mockup/process/resultvalidation-v23/Re_px.php @@ -1,2549 +1,2546 @@ -db_smartone = $this->load->database("onedev", true); - $this->load->helper(array('form', 'url')); - } - function getMethodeID($natTestID) { - $sql = "select M_MethodePriorityNat_MethodeID MethodeID, Nat_MethodeName - from - m_methode_priority - join nat_methode on Nat_MethodeID = M_MethodePriorityNat_MethodeID - and Nat_MethodeIsActive = 'Y' - join m_instrumentmethode on M_InstrumentMethodeNat_MethodeID = Nat_MethodeID and M_InstrumentMethodeIsActive = 'Y' - join nat_instrument on M_InstrumentMethodeNat_InstrumentID = Nat_InstrumentID - and Nat_InstrumentIsActive ='Y' - where M_MethodePriorityIsActive = 'Y' - and M_MethodePriorityNat_TestID = $natTestID - and M_MethodePriorityM_DayOfWeekID = dayofweek(now()) - order by M_MethodePriorityNumber desc - limit 0,1 "; - $qry = $this->db->query($sql); - if ($qry) { - $rows = $qry->result_array(); - if (count($rows) > 0 ) return array($rows[0]["MethodeID"],$rows[0]["Nat_MethodeName"]); - } - //2nd - $sql= "select - M_InstrumentMethodeNat_MethodeID MethodeID, Nat_MethodeName - from m_instrumentmethode - join nat_methode on M_InstrumentMethodeNat_MethodeID = Nat_MethodeID - and Nat_MethodeIsActive = 'Y' - join nat_instrument on M_InstrumentMethodeNat_InstrumentID = Nat_InstrumentID - and Nat_InstrumentIsActive ='Y' - where M_InstrumentMethodeNat_TestID = $natTestID - and M_InstrumentMethodeIsActive = 'Y' - order by M_InstrumentMethodePriority desc - limit 0,1"; - $qry = $this->db->query($sql); - if ($qry) { - $rows = $qry->result_array(); - if (count($rows) > 0 ) return array($rows[0]["MethodeID"],$rows[0]["Nat_MethodeName"]); - } - // - $sql = "select Nat_NormalValueNat_MethodeID MethodeID, Nat_MethodeName - from - nat_normalvalue - join nat_methode on Nat_NormalValueNat_MethodeID = Nat_MethodeID - and Nat_MethodeIsActive = 'Y' - where Nat_NormalValueNat_TestID = $natTestID - and Nat_NormalValueIsActive = 'Y' - order by Nat_NormalValueID - limit 0,1"; - $qry = $this->db->query($sql); - if ($qry) { - $rows = $qry->result_array(); - if (count($rows) > 0 ) return array($rows[0]["MethodeID"],$rows[0]["Nat_MethodeName"]); - } - return array(0,""); - } - function get_normal_value($methodeID, $natTestID, $sexID, $ageInDay ) { - $sql = "select fn_sampling_get_normal($methodeID, $natTestID, $sexID, $ageInDay) as normalValueID"; - $qry = $this->db->query($sql); - if ($qry) { - $rows = $qry->result_array(); - if (count($rows) > 0 ) return $rows[0]["normalValueID"]; - } - return 0; - } - function fn_fix_normal($order_id) { - $sql = "select - T_OrderDetailID, M_PatientM_SexID, fn_global_age_count_day(M_PatientDOB, date(T_OrderHeaderDate)) Dob , - T_TestNat_TestID - from t_orderheader - join m_patient on T_OrderHeaderID = $order_id and T_OrderHeaderM_PatientID = M_PatientID - join t_orderdetail on T_OrderDetailT_OrderHeaderID = T_OrderHeaderID - and T_OrderDetailIsACtive = 'Y' - and ( T_OrderDetailNat_NormalValueID is null or T_OrderDetailNat_NormalValueID = 0 ) - join t_test on T_OrderDetailT_TestID = T_TestID and T_TestIsResult = 'Y' "; - $qry = $this->db->query($sql); - if(! $qry) { - return; - } - $rows = $qry->result_array(); - if(count($rows) == 0 ) return; - $sql_u = "update t_orderdetail - join nat_normalvalue on T_OrderDetailID = ? and Nat_NormalValueID = ? - set - T_OrderDetailNat_NormalValueID = Nat_NormalValueID, - T_OrderDetailNormalValueNote = Nat_NormalValueNote, - T_OrderDetailNormalValueDescription = Nat_NormalValueDescription, - T_OrderDetailMinValue = Nat_NormalValueMinValue, - T_OrderDetailMaxValue = Nat_NormalValueMaxValue, - T_OrderDetailMinValueInclusive = Nat_NormalValueMinValueInclusive, - T_OrderDetailMaxValueInclusive = Nat_NormalValueMaxValueInclusive, - T_OrderDetailNat_MethodeID = ?, - T_OrderdetailNat_MethodeName =?"; - - foreach($rows as $r) { - $T_OrderDetailID = $r["T_OrderDetailID"]; - $sexID = $r["M_PatientM_SexID"]; - $ageInDay = $r["Dob"]; - $natTestID = $r["T_TestNat_TestID"]; - list($methodeID,$methodeName) = $this->getMethodeID($natTestID); - if ($methodeID == 0 ) continue; - $normalValueID = $this->get_normal_value($methodeID, $natTestID, $sexID, $ageInDay); - if ($normalValueID == 0) return; - $this->db->query($sql_u, array($T_OrderDetailID, $normalValueID, $methodeID, $methodeName)); - } - } - function update_order_sample($targetID, $sourceID) { - $sql = "update t_ordersample target - join t_ordersample source on - target.T_OrderSampleID = ? - and target.T_OrderSampleWorklistReceive = 'N' - and source.T_OrderSampleID = ? - set - target.T_OrderSampleSampling = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSampling, source.T_OrderSampleSampling), - target.T_OrderSampleSamplingDate = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingDate, source.T_OrderSampleSamplingDate), - target.T_OrderSampleSamplingTime = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingTime, source.T_OrderSampleSamplingTime), - target.T_OrderSampleSamplingUserID = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingUserID, source.T_OrderSampleSamplingUserID), - - target.T_OrderSampleReceive = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceive, source.T_OrderSampleReceive), - target.T_OrderSampleReceiveDate = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveDate, source.T_OrderSampleReceiveDate), - target.T_OrderSampleReceiveTime = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveTime, source.T_OrderSampleReceiveTime), - target.T_OrderSampleReceiveUserID = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveUserID, source.T_OrderSampleReceiveUserID), - - target.T_OrderSampleVerification = if(target.T_OrderSampleVerification='Y',target.T_OrderSampleVerification, source.T_OrderSampleVerification), - target.T_OrderSampleVerificationDate =if(target.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationDate, source.T_OrderSampleVerificationDate), - target.T_OrderSampleVerificationTime =if(source.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationTime, source.T_OrderSampleVerificationTime), - target.T_OrderSampleVerificationUserID =if(source.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationUserID, source.T_OrderSampleVerificationUserID), - - target.T_OrderSampleProcessing = if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessing, source.T_OrderSampleProcessing), - target.T_OrderSampleProcessingDate= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingDate, source.T_OrderSampleProcessingDate), - target.T_OrderSampleProcessingTime= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingTime, source.T_OrderSampleProcessingTime), - target.T_OrderSampleProcessingUserID= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingUserID, source.T_OrderSampleProcessingUserID), - - target.T_OrderSampleReceiveHandling =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandling, source.T_OrderSampleReceiveHandling ), - target.T_OrderSampleReceiveHandlingDate =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingDate, source.T_OrderSampleReceiveHandlingDate), - target.T_OrderSampleReceiveHandlingTime =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingTime, source.T_OrderSampleReceiveHandlingTime), - target.T_OrderSampleReceiveHandlingUserID =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingUserID, source.T_OrderSampleReceiveHandlingUserID), - - target.T_OrderSampleHandling = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandling, source.T_OrderSampleHandling), - target.T_OrderSampleHandlingDate = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingDate, source.T_OrderSampleHandlingDate), - target.T_OrderSampleHandlingTime = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingTime, source.T_OrderSampleHandlingTime), - target.T_OrderSampleHandlingUserID = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingUserID, source.T_OrderSampleHandlingUserID), - - target.T_OrderSampleWorklistReceive = source.T_OrderSampleWorklistReceive, - target.T_OrderSampleWorklistReceiveDatetime = source.T_OrderSampleWorklistReceiveDateTime, - target.T_OrderSampleWorklistReceiveUserID = source.T_OrderSampleWorklistReceiveUserID - "; - $qry = $this->db->query($sql,array($targetID,$sourceID)); - if(! $qry ) { - echo json_encode(array( "status" => "ERR" , "message" => print_r($this->db->error(),true))); - exit; - } - } - function fix_sample_serum($headerID) { - //cari t_ordersample yg belum worklist receive dengan code 017% - $sql = "select T_OrderSampleID - from t_ordersample - join t_sampletype on - T_OrderSampleT_OrderHeaderID = ? - and T_OrderSampleWorklistReceive = 'N' - and T_OrderSampleIsActive = 'Y' - and T_OrderSampleT_SampleTypeID = T_SampletypeID - and T_SampleTypeCode like '017%' - "; - $qry = $this->db->query($sql, array($headerID)); - if(!$qry) { - echo json_encode(array( "status" => "ERR" , "message" => print_r($this->db->error(),true))); - exit; - } - $rows = $qry->result_array(); - if (count($rows) == 0 ) return; - //cari T_OrderSample yang sudah di receive yg terakhir - $sql = "select T_OrderSampleID - from t_ordersample - join t_sampletype on - T_OrderSampleT_OrderHeaderID = ? - and T_OrderSampleWorklistReceive = 'Y' - and T_OrderSampleIsActive = 'Y' - and T_OrderSampleT_SampleTypeID = T_SampletypeID - and T_SampleTypeCode like '017%' - order by T_OrderSampleWorklistReceiveDatetime desc - limit 0,1 - "; - $qry = $this->db->query($sql, array($headerID)); - if(!$qry) { - echo json_encode(array( "status" => "ERR" , "message" => print_r($this->db->error(),true))); - exit; - } - $rcv_rows = $qry->result_array(); - if (count($rcv_rows) == 0 ) return; - - //print_r($rows); - //print_r($rcv_rows); - $rcv_T_OrderSampleID = $rcv_rows[0]["T_OrderSampleID"]; - //ada yg belum di receive - foreach($rows as $r) { - $T_OrderSampleID = $r["T_OrderSampleID"]; - $this->update_order_sample($T_OrderSampleID,$rcv_T_OrderSampleID); - } - } - public function search() - { - $prm = $this->sys_input; - $max_rst = 99; - - $id = $prm["order_id"]; - if ($id > 0 ) { - $this->fix_sample_serum($id); - $this->fn_fix_normal($id); - } - $lang = $this->lang_default_code; - $lang_id = isset($prm['lang_id']) ? $prm['lang_id'] : '0'; - - if ($lang_id != 0) - { - $l = $this->db_smartone->where("Nat_LangID", $lang_id)->get("nat_lang")->row(); - $lang = $l->Nat_LangCode; - } - - //tambahan fajri - $sql = " UPDATE t_orderdetail - JOIN t_test ON T_OrderDetailT_TestID = T_TestID - SET T_OrderDetailT_TestIsResult = T_TestIsResult - WHERE - T_OrderDetailT_OrderHeaderID = {$id} AND - T_OrderDetailT_TestIsResult = '' AND - T_OrderDetailIsActive = 'Y'"; - $this->db_smartone->query($sql); - - $tot_count = 0; - $lq = ""; - $group_id = 0; - if (isset($prm['group_id'])) - $group_id = $prm['group_id']; - - if ($group_id != 0) - { - $sql = "select distinct T_WorklistDetailNat_TestID Nat_TestID - from t_worklistdetailv2 - where T_WorklistDetailT_WorklistID = {$group_id}"; - $qry = $this->db_smartone->query($sql); - $rows = $qry->result_array(); - $nat_test_ids = "0"; - foreach($rows as $r) { - $nat_test_ids .= ", " . $r["Nat_TestID"]; - } - $q_group = " ( $nat_test_ids ) "; - - $sql = " - SELECT a1.*, cOUNT(a2.T_OrderDetailID) level - FROM ( - SELECT IFNULL(y.T_OrderDetailT_TestID, x.T_OrderDetailT_TestID) t_testid, - IFNULL(y.T_OrderDetailT_TestName, y.T_OrderDetailT_TestName) t_testname, - y.T_OrderDetailResult result, y.T_OrderDetailResult result_old, y.T_OrderDetailNote note, y.T_OrderDetailNote note_old, - y.T_OrderDetailID id, - y.T_OrderDetailT_TestIsResult is_result, a.T_TestIsQuantitative is_quantitative, - y.T_OrderDetailResultFlag result_flag, - y.T_OrderDetailNat_NormalValueID normal_id, - y.T_OrderDetailNormalValueNote normal_note, y.T_OrderDetailNat_UnitName unit_name, - y.T_OrderdetailNat_MethodeID methode_id, y.T_OrderdetailNat_MethodeName methode_name, - a.T_TestNat_TestID nattest_id, a.T_TestID tx_id, count(T_ResultInstrumentID) as result_instrument_n, - y.T_OrderDetailVerification, T_OrderSampleReceive sample_receive, - T_OrderSampleProcessing sample_processing, T_OrderSampleWorklistReceive sample_worklist_receive, - IF(T_OrderDetailAddOnPreAnalytic = 'Y', T_OrderDetailAddOnPreAnalytic, PreAnalyticIsOk) pre_analytic, - T_OrderDetailAddOnPreAnalytic, - T_OrderHeaderID order_id, y.T_OrderDetailT_TestSasCode test_sas_code, - tx.T_TestSasCode, - T_OrderDetailAddOnResample `resample`, T_OrderDetailAddOnResampleStatus resample_status, - T_OrderDetailAddOnRef ref, y.T_OrderDetailVerification verification, y.T_OrderDetailValidation validation, - T_OrderPromiseDateTime, Group_ResultName as ResultGroupName - FROM t_orderdetail x - left join t_orderpromise on x.T_OrderDetailT_OrderPromiseID = T_OrderPromiseID - JOIN t_test tx ON x.T_OrderDetailT_TestID = T_TestID - JOIN t_test tcheck on tcheck.T_TestNat_TestID in {$q_group} - and ( tx.T_TestID = tcheck.T_TestID or tx.T_TestSasCode like concat(tcheck.T_TestSasCode,'%')) - LEFT JOIN group_resultdetail ON Group_ResultDetailT_TestID = x.T_OrderDetailT_TestID AND Group_ResultDetailIsActive = 'Y' - LEFT JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND Group_ResultFlagNonLab = 'N' - LEFT JOIN t_orderdetail y ON x.T_OrderDetailT_TestSasCode LIKE CONCAT(y.T_OrderDetailT_TestSasCode, '%') - AND x.T_OrderDetailT_OrderHeaderID = y.T_OrderDetailT_OrderHeaderID - AND y.T_OrderDetailIsActive = 'Y' - LEFT JOIN t_orderdetailaddon ON x.T_OrderDetailID = T_OrderDetailAddOnT_OrderDetailID - JOIN t_orderheader ON y.T_OrderDetailT_OrderHeaderID = T_OrderHeaderID - LEFT JOIN t_test a ON y.T_OrderDetailT_TestID = a.T_TestID - AND a.T_TestIsNonLab = '' - LEFT JOIN (SELECT T_OrderSampleT_SampleTypeID, T_OrderSampleReceive, T_OrderSampleProcessing, T_OrderSampleWorklistReceive - FROM t_ordersample WHERE T_OrderSampleT_OrderHeaderID = {$id} - AND T_OrderSampleIsactive = 'Y' - GROUP BY T_OrderSampleT_SampleTypeID) os ON a.T_TestT_SampleTypeID = os.T_OrderSampleT_SampleTypeID - or os.T_OrderSampleT_SampleTypeID = fn_sampletype_from_local(a.T_TestNat_TestID) - - LEFT JOIN t_resultinstrument ON T_ResultInstrumentT_OrderDetailID = x.T_OrderDetailID - LEFT JOIN pre_analytic ON PreAnalyticNat_TestID = a.T_TestNat_TestID AND PreAnalyticDate = date(now()) and PreAnalyticIsActive = 'Y' - WHERE x.T_OrderDetailT_OrderHeaderID = {$id} - AND x.T_OrderDetailIsActive = 'Y' - GROUP BY y.T_OrderDetailT_TestID - ORDER BY y.T_OrderDetailT_TestSasCode ASC - ) a1 - - LEFT JOIN t_orderdetail a2 ON a2.T_OrderDetailT_OrderHeaderID = a1.order_id - AND a2.T_OrderDetailIsActive = 'Y' - AND a1.test_sas_code LIKE CONCAT(a2.T_OrderDetailT_testSasCode, '%') - GROUP BY a1.t_testid - order by a1.test_sas_code -"; - $query = $this->db_smartone->query($sql); - $lq = $this->db_smartone->last_query(); - } - else - { - $sql = " - SELECT a1.*, cOUNT(a2.T_OrderDetailID) level - FROM ( - SELECT IFNULL(y.T_OrderDetailT_TestID, x.T_OrderDetailT_TestID) t_testid, - IFNULL(y.T_OrderDetailT_TestName, y.T_OrderDetailT_TestName) t_testname, - y.T_OrderDetailResult result, y.T_OrderDetailResult result_old, y.T_OrderDetailNote note, y.T_OrderDetailNote note_old, - y.T_OrderDetailID id, - y.T_OrderDetailT_TestIsResult is_result, a.T_TestIsQuantitative is_quantitative, - y.T_OrderDetailResultFlag result_flag, - y.T_OrderDetailNat_NormalValueID normal_id, - y.T_OrderDetailNormalValueNote normal_note, y.T_OrderDetailNat_UnitName unit_name, - y.T_OrderdetailNat_MethodeID methode_id, y.T_OrderdetailNat_MethodeName methode_name, - a.T_TestNat_TestID nattest_id, a.T_TestID tx_id, count(T_ResultInstrumentID) as result_instrument_n, - y.T_OrderDetailVerification, T_OrderSampleReceive sample_receive, - T_OrderSampleProcessing sample_processing, T_OrderSampleWorklistReceive sample_worklist_receive, - IF(T_OrderDetailAddOnPreAnalytic = 'Y', T_OrderDetailAddOnPreAnalytic, PreAnalyticIsOk) pre_analytic, - T_OrderDetailAddOnPreAnalytic, - T_OrderHeaderID order_id, y.T_OrderDetailT_TestSasCode test_sas_code, - tx.T_TestSasCode, - T_OrderDetailAddOnResample `resample`, T_OrderDetailAddOnResampleStatus resample_status, - T_OrderDetailAddOnRef ref, y.T_OrderDetailVerification verification, y.T_OrderDetailValidation validation, - T_OrderPromiseDateTime , Group_ResultName as ResultGroupName - FROM t_orderdetail x - left join t_orderpromise on x.T_OrderDetailT_OrderPromiseID = T_OrderPromiseID - JOIN t_test tx ON x.T_OrderDetailT_TestID = T_TestID - LEFT JOIN group_resultdetail ON Group_ResultDetailT_TestID = x.T_OrderDetailT_TestID AND Group_ResultDetailIsActive = 'Y' - LEFT JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND Group_ResultFlagNonLab = 'N' - LEFT JOIN t_orderdetail y ON x.T_OrderDetailT_TestSasCode LIKE CONCAT(y.T_OrderDetailT_TestSasCode, '%') - AND x.T_OrderDetailT_OrderHeaderID = y.T_OrderDetailT_OrderHeaderID - AND y.T_OrderDetailIsActive = 'Y' - - LEFT JOIN t_orderdetailaddon ON x.T_OrderDetailID = T_OrderDetailAddOnT_OrderDetailID - - JOIN t_orderheader ON y.T_OrderDetailT_OrderHeaderID = T_OrderHeaderID - LEFT JOIN t_test a ON y.T_OrderDetailT_TestID = a.T_TestID - AND a.T_TestIsNonLab = '' - LEFT JOIN (SELECT T_OrderSampleT_SampleTypeID, T_OrderSampleReceive, T_OrderSampleProcessing, T_OrderSampleWorklistReceive - FROM t_ordersample WHERE T_OrderSampleT_OrderHeaderID = {$id} - AND T_OrderSampleIsactive = 'Y' - GROUP BY T_OrderSampleT_SampleTypeID) os ON a.T_TestT_SampleTypeID = os.T_OrderSampleT_SampleTypeID - or os.T_OrderSampleT_SampleTypeID = fn_sampletype_from_local(a.T_TestNat_TestID) - - LEFT JOIN t_resultinstrument ON T_ResultInstrumentT_OrderDetailID = x.T_OrderDetailID - LEFT JOIN pre_analytic ON PreAnalyticNat_TestID = a.T_TestNat_TestID AND PreAnalyticDate = date(now()) and PreAnalyticIsActive = 'Y' - WHERE x.T_OrderDetailT_OrderHeaderID = {$id} - AND x.T_OrderDetailIsActive = 'Y' - GROUP BY y.T_OrderDetailT_TestID - ORDER BY y.T_OrderDetailT_TestSasCode ASC - ) a1 - - LEFT JOIN t_orderdetail a2 ON a2.T_OrderDetailT_OrderHeaderID = a1.order_id - AND a2.T_OrderDetailIsActive = 'Y' - AND a1.test_sas_code LIKE CONCAT(a2.T_OrderDetailT_testSasCode, '%') - GROUP BY a1.t_testid - order by a1.test_sas_code -"; -//echo $sql; - $query = $this->db_smartone->query($sql); - $lq = $this->db_smartone->last_query(); - } - // file_put_contents("/xtmp/re-query.sql",$lq); - - if ($query) { - $rst = []; - $rows = $query->result_array(); - - foreach($rows as $k => $v) - { - - if ($v['is_result'] == "Y" && $v['is_quantitative'] == "N") - { - $v['template'] = []; - $x = $this->db_smartone->query("CALL sp_master_resulttemplate_get('{$v['t_testid']}')"); - $this->clean_mysqli_connection($this->db_smartone->conn_id); - if ($x) - $v['template'] = $x->result_array(); - } - - // IF Rujukan, by pas Pre Analytik - if ($v['ref'] == 'Y') - $v['pre_analytic'] = 'Y'; - if ($v["id"] == "885455" ) - { - //sipe workaround - //$v["sample_receive"] = "Y"; - $v["sample_worklist_receive"] = "Y"; - } - $rst[] = $v; - } - - $result = array("total" => $tot_count, "records" => $rst, "total_display" => sizeof($rows), "q" => $lq); - $this->sys_ok($result); - } - else { - $this->sys_error_db("RE Px rows", $this->db_smartone); - exit; - } - } - - public function save() - { - $prm = $this->sys_input; - $data = json_decode($prm["data"]); - $lang = $this->lang_default_code; - $lang_id = isset($prm['lang_id']) ? $prm['lang_id'] : '0'; - - if ($lang_id != 0) - { - $l = $this->db_smartone->where("Nat_LangID", $lang_id)->get("nat_lang")->row(); - $lang = $l->Nat_LangCode; - } - - $sql_norm = "select T_OrderDetailMinValue, T_OrderDetailMaxValue, - T_OrderDetailMinValueInclusive, T_OrderDetailMaxValueInclusive, - Nat_TestFlagLow, Nat_TestFlagHigh - from t_orderdetail - join t_test on T_OrderDetailT_TestID = T_TestID - join nat_test on T_TestNat_TestID = Nat_TestID and T_TestIsActive = 'Y' - where T_OrderDetailID = ? "; - - $ids = []; - foreach ($data as $k => $v) - { - if ( $v->resultInstrumentID > 0 ) { - $sql_i = "select T_ResultInstrumentNat_NormalValueID normalValueID - from t_resultinstrument - where T_ResultInstrumentID = ?"; - $qry_i = $this->db_smartone->query($sql_i, array($v->resultInstrumentID)); - if ($qry_i) { - $rows_i = $qry_i->result_array(); - - if (count($rows_i) > 0 ) { - $sql_iu = "update t_orderdetail, nat_normalvalue , nat_methode - set T_OrderDetailMinValue = Nat_NormalValueMinValue, - T_OrderDetailMinValueInclusive = Nat_NormalValueMinValueInclusive, - T_OrderDetailMaxValue = Nat_NormalValueMaxValue , - T_OrderDetailMaxValueInclusive = Nat_NormalValueMaxValueInclusive, - T_OrderDetailNormalValueNote = Nat_NormalValueNote, - T_OrderDetailNormalValueDescription = Nat_NormalValueDescription, - T_OrderDetailNat_NormalValueID = Nat_NormalValueID, - T_OrderDetailNat_MethodeID = Nat_NormalValueNat_MethodeID, - T_OrderDetailNat_MethodeName = Nat_MethodeName - where T_OrderDetailID = ? and Nat_NormalValueID = ? - and Nat_NormalValueNat_MethodeID = Nat_MethodeID - "; - $this->db_smartone->query($sql_iu, array($v->id, $rows_i[0]["normalValueID"])); - //file_put_contents("/xtmp/update-nilai-normal", $this->db_smartone->last_query() . "\n", FILE_APPEND); - } - } - } - $y = $this->db_smartone->query("SELECT fn_process_sample_handling_perfect('{$v->order_id}', '{$v->test_id}') c") - ->row(); - $req_status = $y->c; - $qry_norm = $this->db_smartone->query($sql_norm,$v->id); - $result_flag = ""; - if ($qry_norm) { - $rows_norm = $qry_norm->result_array(); - if (count($rows_norm) > 0 ) { - $r = $rows_norm[0]; - if (is_numeric($v->result)) { - - if ( $r["T_OrderDetailMinValueInclusive"] == "Y" && $v->result < $r["T_OrderDetailMinValue"] ) { - $result_flag = $r["Nat_TestFlagLow"]; - } - if ( $r["T_OrderDetailMinValueInclusive"] == "N" && $v->result <= $r["T_OrderDetailMinValue"] ) { - $result_flag = $r["Nat_TestFlagLow"]; - } - if ( $r["T_OrderDetailMaxValueInclusive"] == "Y" && $v->result > $r["T_OrderDetailMaxValue"] ) { - $result_flag = $r["Nat_TestFlagHigh"]; - } - if ( $r["T_OrderDetailMaxValueInclusive"] == "N" && $v->result >= $r["T_OrderDetailMaxValue"] ) { - $result_flag = $r["Nat_TestFlagHigh"]; - } - } - } - } - if ($lang == $this->lang_default_code) - { - $this->db_smartone->set('T_OrderDetailResult', $v->result) - ->set('T_OrderDetailResultFlag', $result_flag) - ->set('T_OrderDetailNote', $v->note) - ->set('T_OrderDetailReqStatus', $req_status) - ->where('T_OrderDetailID', $v->id) - ->update('t_orderdetail'); - } - else - { - $this->db_smartone->set('T_OrderDetailLangResult', $v->result) - ->set('T_OrderDetailLangNote', $v->note) - ->where('T_OrderDetailLangID', $v->id) - ->update('t_orderdetaillang'); - } - - $ids[] = $v->id; - } - - // LOG Process - $order = $this->db_smartone->select('T_OrderDetailT_OrderHeaderID id, T_OrderHeaderLabNumber lab_number', false) - ->join('t_orderheader', 'T_OrderHeaderID = T_OrderDetailT_OrderHeaderID') - ->where('T_OrderDetailID', $data[0]->id) - ->get('t_orderdetail') - ->row(); - - $dblog = $this->load->database("onelog", true); - $dblog->set('Log_ProcessCode', 'PROCESS.Result.Entry') - ->set('Log_ProcessOrderID', $order->id) - ->set('Log_ProcessOrderNumber', $order->lab_number) - ->set('Log_ProcessJson', json_encode($data)) - ->set('Log_ProcessUserID', $this->sys_user['M_UserID']) - ->insert('log_process'); - // END OF Log Process - //auto calculation - $this->load->library("Resultcalc"); - $rows = $this->resultcalc->auto($order->id); - - try { - foreach($ids as $id ) { - $this->db_smartone->query("call sp_set_normal_value_flag($id)"); - $this->clean_mysqli_connection($this->db_smartone->conn_id); - } - } catch(Exception $e) { - } - - $this->sys_ok($ids); - } - - public function save_template() - { - $prm = $this->sys_input; - - $n = $this->db_smartone->select("COUNT(T_ResultTemplateID) n") - ->where("T_ResultTemplateT_TestID", $prm['test_id']) - ->where("T_ResultTemplateIsActive", "Y") - ->where("T_ResultTemplateValue", $prm['value']) - ->get('t_resulttemplate') - ->row(); - if ($n->n > 0) - { - $this->sys_error_db("Insert Result Template", $this->db_smartone); - return; - } - - $r = $this->db_smartone->set("T_ResultTemplateT_TestID", $prm['test_id']) - ->set("T_ResultTemplateValue", $prm['value']) - ->insert('t_resulttemplate'); - if ($r) - { - $template = []; - $x = $this->db_smartone->query("CALL sp_master_resulttemplate_get('{$prm['test_id']}')"); - $this->clean_mysqli_connection($this->db_smartone->conn_id); - if ($x) - $template = $x->result_array(); - - $this->sys_ok($template); - } - } - - public function export() - { - $prm = $this->sys_input; - - $sql = "CALL sp_process_result_lang(?, ?, ?, ?)"; - $query = $this->db_smartone->query($sql, [$prm['order_id'], $prm['lang_id'], $prm['is_si'], $this->sys_user['M_UserID']]); - if ($query) - { - $r = $query->row(); - if ($r->status == "OK") - { - $this->sys_ok($r->data); - return; - } - - $this->sys_error_db("Message : " . $r->message, $this->db_smartone); - } - else - { - $this->sys_error_db("Lang Result", $this->db_smartone); - return; - } - } - - public function search_group() - { - $prm = $this->sys_input; - $max_rst = 100; - - // QUERY TOTAL - $sql = "select count(*) total - from t_worklist - where T_WorklistIsActive = 'Y' - order by T_WorklistName ASC"; - $query = $this->db_smartone->query($sql); - - if ($query) { - $tot_count = $query->result_array()[0]["total"]; - } - else { - $this->sys_error_db("worklist count", $this->db_smartone); - exit; - } - - $sql = "select T_WorklistID group_id, T_WorklistName group_name - from t_worklist - where T_WorklistIsActive = 'Y' - order by T_WorklistName ASC - limit 0, {$max_rst}"; - $query = $this->db_smartone->query($sql); - - if ($query) { - $rows = $query->result_array(); - foreach ($rows as $k => $v) - $rows[$k]['data'] = json_decode($v['data']); - $result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows), "q" => $this->db_smartone->last_query()); - $this->sys_ok($result); - } - else { - $this->sys_error_db("worklist rows", $this->db_smartone); - exit; - } - } - - public function search_rerun() - { - $prm = $this->sys_input; - $id = $prm["detail_id"]; - - $sql = "CALL sp_process_result_rerun(?)"; - $query = $this->db_smartone->query($sql, [$id]); - - if ($query) - { - $rows = $query->result_array(); - $this->sys_ok(["records"=>$rows]); - } - else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - - - function getdoctorsfna() - { - $prm = $this->sys_input; - // $id = $prm["id"]; - - $sql = " SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY M_DoctorName ASC"; - //echo $sql; - $query = $this->db_smartone->query($sql); - - if ($query) - { - $rows = $query->result_array(); - $this->sys_ok(["records"=>$rows]); - } - else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - function getfnaresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT Other_FNADetailsID as xid, - Other_FNAT_OrderDetailID as orderdetail_id, - Other_FNADetailsCode as code, - Other_FNADetailsLabel as label, - Other_FNADetailsResult as result, - IFNULL(Other_FNAM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_FNAM_DoctorID) OR Other_FNAM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_fna - JOIN other_fnadetails ON Other_FNADetailsOther_FNAID = Other_FNAID AND Other_FNADetailsIsActive = 'Y' - LEFT JOIN m_doctor ON Other_FNAM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_FNAT_OrderDetailID = {$id} AND Other_FNAIsActive = 'Y' - GROUP BY Other_FNADetailsID - ORDER BY Other_FNADetailsCode ASC"; - $query = $this->db_smartone->query($sql); - - if ($query) - { - $rows = $query->result_array(); - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $images = array(); - $sql = "SELECT So_ImageUploadID as xid, - CONCAT('/one-media/one-image-nonlab/',So_ImageUploadNewName) as image_url - FROM t_orderdetail - JOIN so_imageupload ON So_ImageUploadT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND - So_ImageUploadIsActive = 'Y' - WHERE - T_OrderDetailID = {$id} AND - T_OrderDetailIsActive = 'Y' - GROUP BY So_ImageUploadID"; - $images = $this->db_smartone->query($sql)->result_array(); - - $rst = array('doctors'=>$doctors,'results'=>$rows,'images'=>$images); - $this->sys_ok(["records"=>$rst]); - } - else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - - function uploadimage(){ - if (! $this->isLogin) { - $this->sys_error("Invalid Token"); - exit; - } - - $userid = $this->sys_user["M_UserID"]; - $data = []; - //print_r($_SERVER); - - $prm = $this->sys_input; - $orderid = $this->input->post('orderid'); - $labnumber = $this->input->post('labnumber'); - $sql = "UPDATE so_imageupload SET - So_ImageUploadIsActive = 'N', - So_ImageUploadUserID = {$userid} - WHERE - So_ImageUploadT_OrderHeaderID = {$orderid}"; - //echo $sql; - $this->db_onedev->query($sql); - //$config['upload_path'] = 'assets/'; - - $path = '/home/one/project/one/one-media/one-image-nonlab/'; - //echo $path; - $config['upload_path'] = $path; - $config['allowed_types'] = 'jpg|jpeg|png|gif'; - - $config['max_size'] = '10000'; - $count = count($_FILES['files']['name']); - //echo $count; - $this->load->library('upload',$config); - - $error = []; - for($i=0;$i<$count;$i++){ - - - if(!empty($_FILES['files']['name'][$i])){ - - - - $_FILES['file']['name'] = $_FILES['files']['name'][$i]; - - $_FILES['file']['type'] = $_FILES['files']['type'][$i]; - - $_FILES['file']['tmp_name'] = $_FILES['files']['tmp_name'][$i]; - - $_FILES['file']['error'] = $_FILES['files']['error'][$i]; - - $_FILES['file']['size'] = $_FILES['files']['size'][$i]; - - - - $namex = $orderid.'-'.$labnumber.'-'.$this->generateRandomString(5); - //echo $namex; - - $config['file_name'] = $namex; - $this->upload->initialize($config); - //echo $config['file_name'] ; - - - - - - if($this->upload->do_upload('file')){ - - $uploadData = $this->upload->data(); - - $filename = $uploadData['file_name']; - //echo $filename; - - - $sql = "INSERT INTO so_imageupload ( - So_ImageUploadT_OrderHeaderID, - So_ImageUploadT_OrderHeaderLabNumber, - So_ImageUploadT_SampleTypeID, - So_ImageUploadOldName, - So_ImageUploadNewName, - So_ImageUploadCreated, - So_ImageUploadUserID - ) - VALUES( - {$orderid}, - '{$labnumber}', - '150', - '{$_FILES['files']['name'][$i]}', - '{$filename}', - NOW(), - {$userid} - - )"; - //echo $sql; - $this->db_onedev->query($sql); - $xlast_id = $this->db_onedev->insert_id(); - $data['totalFiles'][] = array('xid' => $xlast_id ,'image_url' => '/one-media/one-image-nonlab/'.$filename); - - } - else{ - $error = array('error' => $this->upload->display_errors()); - } - - } - - - - } - - $result = array("total" =>count( $data['totalFiles']), "records" => $data['totalFiles'],'errors'=>$error); - $this->sys_ok($result); - } - - - function getpatologianatomyresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT Other_PatologiAnatomyID as xid, - Other_PatologiAnatomyT_OrderDetailID as orderdetail_id, - Other_PatologiAnatomyNoSediaan as no_sediaan, - Other_PatologiAnatomyDiagnosaKlinis as diagnosa, - Other_PatologiAnatomyKeteranganKlinis as klinis, - Other_PatologiAnatomyLokasiOrgan as lokasi, - Other_PatologiAnatomyMakroskopik as makroskopik, - Other_PatologiAnatomyMikroskopik as mikroskopik, - Other_PatologiAnatomyKesimpulan as kesimpulan, - IFNULL(Other_PatologiAnatomyM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_PatologiAnatomyM_DoctorID) OR Other_PatologiAnatomyM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_patologi_anatomy - LEFT JOIN m_doctor ON Other_PatologiAnatomyM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_PatologiAnatomyT_OrderDetailID = {$id} AND Other_PatologiAnatomyIsActive = 'Y' - GROUP BY Other_PatologiAnatomyID - ORDER BY Other_PatologiAnatomyID ASC - LIMIT 1"; - $query = $this->db_smartone->query($sql); - - if ($query) - { - $rows = $query->row_array(); - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - - $rst = array('doctors'=>$doctors,'result'=>$rows); - $this->sys_ok(["records"=>$rst]); - } - else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - - - function generateRandomString($length = 10) { - $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; - $charactersLength = strlen($characters); - $randomString = ''; - for ($i = 0; $i < $length; $i++) { - $randomString .= $characters[rand(0, $charactersLength - 1)]; - } - return $randomString; - } - - function getcytologiresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT Other_CytologiDetailsID as xid, - Other_CytologiT_OrderDetailID as orderdetail_id, - Other_CytologiDetailsCode as code, - Other_CytologiDetailsLabel as label, - Other_CytologiDetailsResult as result, - IFNULL(Other_CytologiM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_CytologiM_DoctorID) OR Other_CytologiM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_cytologi - JOIN other_cytologidetails ON Other_CytologiDetailsOther_CytologiID = Other_CytologiID AND Other_CytologiDetailsIsActive = 'Y' - LEFT JOIN m_doctor ON Other_CytologiM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_CytologiT_OrderDetailID = {$id} AND Other_CytologiIsActive = 'Y' - GROUP BY Other_CytologiDetailsID - ORDER BY Other_CytologiDetailsCode ASC"; - //echo $sql; - $query = $this->db_smartone->query($sql); - - if ($query) - { - $rows = $query->result_array(); - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $rst = array('doctors'=>$doctors,'results'=>$rows); - $this->sys_ok(["records"=>$rst]); - } - else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - function getmikroresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT - Other_MikroID as xid, - Other_MikroHasilBiakan as hasil_biakan, - Other_MikroSampleTypeName as sample_name, - Other_MikroT_OrderDetailID as orderdetail_id, - Other_MikroResult as result_value, - '' as result_other, - IFNULL(T_BacteriaID,0) as T_BacteriaID, - IFNULL(T_BacteriaName,'') as T_BacteriaName, - '' as details, - IFNULL(Other_MikroM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_MikroM_DoctorID) OR Other_MikroM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_mikro - LEFT JOIN t_bacteria ON Other_MikroT_BacteriaID = T_BacteriaID - LEFT JOIN m_doctor ON Other_MikroM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_MikroT_OrderDetailID = {$id} AND Other_MikroIsActive = 'Y' - GROUP BY Other_MikroID"; - //echo $sql; - $query = $this->db_smartone->query($sql); - - if ($query) - { - $row = $query->row_array(); - if($row){ - if($row['result_value'] != 'Positif' && $row['result_value'] != 'Negatif'){ - $row['result_other'] = $row['result_value']; - $row['result_value'] = 'other'; - } - $sql = "SELECT '' as xno, - Other_MikroDetailsID as xid, - Other_MikroDetailsValue as value, - IF(Other_MikroDetailsNote = 'R','Y','N') as chx_r, - IF(Other_MikroDetailsNote = 'I','Y','N') as chx_i, - IF(Other_MikroDetailsNote = 'S','Y','N') as chx_s, - Other_MikroDetailsNote as note, - t_antibiotic.* - FROM other_mikrodetails - LEFT JOIN t_antibiotic ON Other_MikroDetailsT_AntibioticID = T_AntibioticID - WHERE - Other_MikroDetailsOther_MikroID = {$row['xid']} AND Other_MikroDetailsIsActive = 'Y' - GROUP BY Other_MikroDetailsID - ORDER BY T_AntibioticName ASC"; - //echo $sql; - $details = $this->db_smartone->query($sql)->result_array(); - if(details){ - foreach($details as $k => $v){ - $details[$k]['xno'] = $k + 1; - } - } - $row['details'] = $details; - } - else{ - $row = array('xid'=>'0','hasil_biakan' => '','result_value'=>'Negatif','sample_name' => '','orderdetail_id'=>$id, 'T_BacteriaID'=>'0','T_BacteriaName'=>'0','details'=>array(),'doctor_id'=>'0','doctor_name'=>'0'); - } - } - else{ - $row = array('xid'=>'0','hasil_biakan' => '','result_value'=>'Negatif','sample_name' => '','orderdetail_id'=>$id, 'T_BacteriaID'=>'0','T_BacteriaName'=>'0','details'=>array(),'doctor_id'=>'0','doctor_name'=>'0'); - } - //print_r($row); - - - - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 7 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $sql = " - SELECT '0' as id, 'Belum memilih bakteria' as name - UNION - SELECT T_BacteriaID as id, T_BacteriaName as name - FROM t_bacteria - WHERE - T_BacteriaIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $bacteries = $this->db_smartone->query($sql)->result_array(); - $rst = array('doctors'=>$doctors,'bacteries'=>$bacteries,'results'=>$row); - $this->sys_ok(["records"=>$rst]); - } - function getantibiotics(){ - $prm = $this->sys_input; - $id = $prm["id"]; - $sql = " SELECT '' as xno, - 0 as xid, - '' as hasil_biakan, - '' as sample_name, - 0 as value, - 'Y' as chx_r, - 'N' as chx_i, - 'N' as chx_s, - 'R' as note, - t_antibiotic.* - FROM t_antibiotic - WHERE - T_AntibioticT_BacteriaID = {$prm['id']} AND T_AntibioticIsActive= 'Y' - ORDER BY T_AntibioticName ASC"; - //echo $sql; - $rows = $this->db_smartone->query($sql)->result_array(); - if(rows){ - foreach($rows as $k => $v){ - $rows[$k]['xno'] = $k + 1; - } - } - - $this->sys_ok(["records"=>$rows]); - } - function getlcprepresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - $sql = " SELECT Other_LcprepDetailsID as xid, - Other_LcprepID as header_id, - Other_LcprepT_orderDetailID as orderdetail_id, - Other_LcprepDetailsCode as code, - Other_LcprepDetailsLabel as label, - Other_LcprepDetailsResult as result, - IFNULL(Other_LcprepM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_LcprepM_DoctorID) OR Other_LcprepM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_lcprep - JOIN other_lcprepdetails ON Other_LcprepDetailsOther_LcprepID = Other_LcprepID AND Other_LcprepDetailsIsActive = 'Y' - LEFT JOIN m_doctor ON Other_LcprepM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_LcprepT_orderDetailID = {$id} AND Other_LcprepIsActive = 'Y' - GROUP BY Other_LcprepDetailsOther_LcprepID, Other_LcprepDetailsCode - ORDER BY Other_LcprepDetailsCode ASC"; - //echo $sql; - $rows = $this->db_smartone->query($sql)->result_array(); - if(!$rows){ - $rows = array( - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'A', - 'label' => 'DESKRIPSI', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ), - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'B', - 'label' => 'KESIMPULAN', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ) - ); - } - - $header_id = $rows[0]['header_id']; - $sql = "SELECT IFNULL(Other_LcprepAdekuasiID,0) as xid, - Lcprep_AdekuasiID as id, - Lcprep_AdekuasiLabel as name, - IF(ISNULL(Other_LcprepAdekuasiID),'N',Other_LcprepAdekuasiChex) as chex - FROM lcprep_adekuasi - LEFT JOIN other_lcprepadekuasi ON Other_LcprepAdekuasiLcprep_AdekuasiID = Lcprep_AdekuasiID AND - Other_LcprepAdekuasiOther_LcprepID = {$header_id} AND - Other_LcprepAdekuasiIsActive = 'Y' - WHERE - Lcprep_AdekuasiIsActive = 'Y' - GROUP BY Lcprep_AdekuasiID - ORDER BY Lcprep_AdekuasiOrder ASC - "; - //echo $sql; - $adeakuasi = $this->db_smartone->query($sql)->result_array(); - foreach($adeakuasi as $kc => $vc){ - $adeakuasi[$kc]['chex'] = $vc['chex'] == 'N'?false:true; - } - - $sql = "SELECT IFNULL(Other_LcprepKategoriUmumID,0) as xid, - Lcprep_KategoriUmumID as id, - Lcprep_KategoriUmumLabel as name, - IF(ISNULL(Other_LcprepKategoriUmumID),'N',Other_LcprepKategoriUmumChex) as chex - FROM lcprep_kategoriumum - LEFT JOIN other_lcprepkategoriumum ON Other_LcprepKategoriUmumLcprep_KategoriUmumID = Lcprep_KategoriUmumID AND - Other_LcprepKategoriUmumOther_LcprepID = {$header_id} AND - Other_LcprepKategoriUmumIsActive = 'Y' - WHERE - Lcprep_KategoriUmumIsActive = 'Y' - GROUP BY Lcprep_KategoriUmumID - "; - //echo $sql; - $kategoriumum = $this->db_smartone->query($sql)->result_array(); - foreach($kategoriumum as $kc => $vc){ - $kategoriumum[$kc]['chex'] = $vc['chex'] == 'N'?false:true; - } - - $sql = " - SELECT Lcprep_InterpretasiGroupID as group_id, - Lcprep_InterpretasiGroupName as group_name, - '' as subgroups - FROM lcprep_interpretasigroup - WHERE - Lcprep_InterpretasiGroupIsActive = 'Y' - "; - //echo $sql; - $interpretasi = $this->db_smartone->query($sql)->result_array(); - foreach($interpretasi as $k => $v){ - $subgroups = array(); - $sql = "SELECT Lcprep_InterpretasiSubgroupID as subgroup_id, - Lcprep_InterpretasiSubgroupName as subgroup_name, - '' as childs - FROM lcprep_interpretasisubgroup - WHERE - Lcprep_InterpretasiSubgroupLcprep_InterpretasiGroupID = {$v['group_id']} AND Lcprep_InterpretasiSubgroupIsActive = 'Y'"; - //echo $sql; - $subgroups = $this->db_smartone->query($sql)->result_array(); - if(count($subgroups) > 0){ - foreach($subgroups as $ki => $vi){ - $childs = array(); - $sql = "SELECT IFNULL(Other_LcprepInterpretasiID,0) as xid, - IFNULL(Other_LcprepInterpretasiChex,'N') as chex, - IFNULL(Other_LcprepInterpretasiValue,'') as value, - Lcprep_InterpretasiID as id, - Lcprep_InterpretasiLcprep_InterpretasiSubgroupID as subgroup_id, - Lcprep_InterpretasiCode as code, - Lcprep_InterpretasiName as name, - Lcprep_InterpretasiParentID as parent_id, - Lcprep_InterpretasiIsParent as is_parent, - Lcprep_InterpretasiHasResult as has_result, - Lcprep_InterpretasiTypeResult as type_result - FROM lcprep_interpretasi - LEFT JOIN other_lcprepinterpretasi ON Other_LcprepInterpretasiOther_LcprepID = {$header_id} AND - Other_LcprepInterpretasiLcprep_InterpretasiID = Lcprep_InterpretasiID AND - Other_LcprepInterpretasiIsActive = 'Y' - WHERE - Lcprep_InterpretasiLcprep_InterpretasiSubgroupID = {$vi['subgroup_id']} AND Lcprep_InterpretasiIsActive = 'Y' - GROUP BY Lcprep_InterpretasiID Order BY Lcprep_InterpretasiCode ASC"; - $childs = $this->db_smartone->query($sql)->result_array(); - if($childs){ - foreach($childs as $kc => $vc){ - $childs[$kc]['chex'] = $vc['chex'] == 'N'?false:true; - } - } - $subgroups[$ki]['childs'] = $childs; - } - } - - $interpretasi[$k]['subgroups'] = $subgroups; - } - - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $rst = array('doctors'=>$doctors,'results'=>$rows,'adekuasi'=>$adeakuasi,'kategoriumum'=>$kategoriumum,'interpretasi'=>$interpretasi); - $this->sys_ok(["records"=>$rst]); - } - - function getpapsmearresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT Other_PapSmearDetailsID as xid, - Other_PapSmearID as header_id, - Other_PapSmearT_OrderDetailID as orderdetail_id, - Other_PapSmearDetailsCode as code, - Other_PapSmearDetailsLabel as label, - Other_PapSmearDetailsResult as result, - IFNULL(Other_PapSmearM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_PapSmearM_DoctorID) OR Other_PapSmearM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_papsmear - JOIN other_papsmeardetails ON Other_PapSmearDetailsOther_PapSmearID = Other_PapSmearID AND Other_PapSmearDetailsIsActive = 'Y' - LEFT JOIN m_doctor ON Other_PapSmearM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_PapSmearT_OrderDetailID = {$id} AND Other_PapSmearIsActive = 'Y' - GROUP BY Other_PapSmearDetailsID - ORDER BY Other_PapSmearDetailsCode ASC"; - //echo $sql; - $rows = $this->db_smartone->query($sql)->result_array(); - if(!$rows){ - $rows = array( - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'A', - 'label' => 'Makroskopik', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ), - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'B', - 'label' => 'Mikroskopik', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ), - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'C', - 'label' => 'Kesimpulan', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ) - ); - } - - $header_id = $rows[0]['header_id']; - $sql = "SELECT Other_PapSmearMaturasiID as xid, - Other_PapSmearMaturasiValue as value - FROM other_papsmearmaturasi - WHERE - Other_PapSmearMaturasiOther_PapSmearID = {$header_id} AND - Other_PapSmearMaturasiIsActive = 'Y' - "; - //echo $sql; - $dt_maturasi = $this->db_smartone->query($sql)->row_array(); - if(!$dt_maturasi){ - $maturasi = array('xid'=>'0','value'=> array('','','')); - } - else{ - $value = explode('/',$dt_maturasi['value']); - $maturasi = array('xid'=>$dt_maturasi['xid'],'value'=> $value); - } - - $sql = "SELECT IFNULL(Other_PapSmearBahanID,0) as xid, - M_PapSmearBahanID as bahan_id, - M_PapSmearBahanName as name, - IF(ISNULL(Other_PapSmearBahanID),'N','Y') as selected - FROM m_papsmearbahan - LEFT JOIN other_papsmearbahan ON Other_PapSmearBahanM_PapSmearBahanID = M_PapSmearBahanID AND - Other_PapSmearBahanOther_PapSmearID = {$header_id} AND - Other_PapSmearBahanIsActive = 'Y' - WHERE - M_PapSmearBahanIsActive = 'Y' - ORDER BY M_PapSmearBahanID ASC - "; - //echo $sql; - $bahans = $this->db_smartone->query($sql)->result_array(); - - $sql = "SELECT IFNULL(Other_PapsmearCategoryID,0) as xid, - M_PapSmearCategoryID as category_id, - M_PapSmearCategoryName as name, - IF(ISNULL(Other_PapsmearCategoryID),'N','Y') as selected - FROM m_papsmearcategory - LEFT JOIN other_papsmearcategory ON Other_PapsmearCategoryM_PapSmearCategoryID = M_PapSmearCategoryID AND - Other_PapsmearCategoryOther_PapSmearID = {$header_id} AND - Other_PapsmearCategoryIsActive = 'Y' - WHERE - M_PapSmearCategoryIsActive = 'Y' - ORDER BY M_PapSmearCategoryID ASC - "; - //echo $sql; - $categories = $this->db_smartone->query($sql)->result_array(); - - $sql = "SELECT IFNULL(Other_PapSmearCheckID,0) as xid, - M_PapSmearCheckID as check_id, - M_PapSmearCheckLabel as name, - IF(ISNULL(Other_PapSmearCheckID),'N','Y') as selected, - Other_PapSmearCheckNote as note - FROM m_papsmearcheck - LEFT JOIN other_papsmearcheck ON Other_PapSmearCheckM_PapSmearCheckID = M_PapSmearCheckID AND - Other_PapSmearCheckOther_PapSmearID = {$header_id} AND - Other_PapSmearCheckIsActive = 'Y' - WHERE - M_PapSmearCheckIsActive = 'Y' - ORDER BY M_PapSmearCheckCode ASC - "; - $checks = $this->db_smartone->query($sql)->result_array(); - - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $rst = array('doctors'=>$doctors,'checks'=>$checks,'bahans'=>$bahans,'categories'=>$categories,'maturasi'=>$maturasi,'results'=>$rows); - $this->sys_ok(["records"=>$rst]); - - } - - function saveresult_lcprep() - { - $prm = $this->sys_input; - $detail_id = $prm['detail_id']; - $doctor_id = $prm['doctor']; - $adekuasi = $prm['adekuasi']; - $kategoriumum = $prm['kategoriumum']; - $interpretasi = $prm['interpretasi']; - $results = $prm['results']; - - $userid = $this->sys_user['M_UserID']; - - $header_id = 0; - $sql = "SELECT * FROM other_lcprep WHERE Other_LcprepT_orderDetailID = {$detail_id} AND Other_LcprepIsActive = 'Y'"; - $dt_header = $this->db_smartone->query($sql)->row_array(); - if($dt_header){ - $header_id = $dt_header['Other_LcprepID']; - } - if($header_id == 0){ - $sql = "INSERT INTO other_lcprep( - Other_LcprepT_orderDetailID, - Other_LcprepM_DoctorID, - Other_LcprepUserID, - Other_LcprepCreated - ) - VALUES( - {$detail_id}, - {$doctor_id}, - {$userid}, - NOW() - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - }else{ - $sql = "UPDATE other_lcprep SET Other_LcprepM_DoctorID = {$doctor_id}, Other_LcprepUserID = {$userid} WHERE Other_LcprepID = {$header_id}"; - $this->db_smartone->query($sql); - } - - if($adekuasi){ - foreach($adekuasi as $k =>$v){ - $selected = $v['chex']?'Y':'N'; - if(intval($v['xid'] == 0)){ - $sql = "UPDATE other_lcprepadekuasi SET Other_LcprepAdekuasiIsActive = 'N' - WHERE - Other_LcprepAdekuasiOther_LcprepID = {$header_id} AND - Other_LcprepAdekuasiIsActive = 'Y' AND - Other_LcprepAdekuasiLcprep_AdekuasiID = {$v['id']}"; - $this->db_smartone->query($sql); - $sql = "INSERT INTO other_lcprepadekuasi ( - Other_LcprepAdekuasiOther_LcprepID, - Other_LcprepAdekuasiLcprep_AdekuasiID, - Other_LcprepAdekuasiChex, - Other_LcprepAdekuasiUserID, - Other_LcprepAdekuasiCreated - ) - VALUES( - {$header_id}, - {$v['id']}, - '{$selected}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - //echo $sql; - } - if(intval($v['xid'] != 0)){ - - $sql = "UPDATE other_lcprepadekuasi SET - Other_LcprepAdekuasiChex = '{$selected}', - Other_LcprepAdekuasiUserID = {$userid} - WHERE - Other_LcprepAdekuasiID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - - //echo $sql; - } - } - - if($kategoriumum){ - foreach($kategoriumum as $k =>$v){ - $selected = $v['chex']?'Y':'N'; - if(intval($v['xid'] == 0)){ - $sql = "UPDATE other_lcprepkategoriumum SET Other_LcprepKategoriUmumIsActive = 'N' - WHERE - Other_LcprepKategoriUmumOther_LcprepID = {$header_id} AND - Other_LcprepKategoriUmumLcprep_KategoriUmumID = {$v['id']} AND - Other_LcprepKategoriUmumIsActive = 'Y' - "; - $this->db_smartone->query($sql); - $sql = "INSERT INTO other_lcprepkategoriumum ( - Other_LcprepKategoriUmumOther_LcprepID, - Other_LcprepKategoriUmumLcprep_KategoriUmumID, - Other_LcprepKategoriUmumChex, - Other_LcprepKategoriUmumUserID, - Other_LcprepKategoriUmumCreated - ) - VALUES( - {$header_id}, - {$v['id']}, - '{$selected}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if(intval($v['xid'] != 0)){ - $sql = "UPDATE other_lcprepkategoriumum SET - Other_LcprepKategoriUmumChex = '{$selected }', - Other_LcprepKategoriUmumUserID = {$userid} - WHERE - Other_LcprepKategoriUmumID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - - //echo $sql; - } - } - - if($results){ - foreach($results as $k =>$v){ - if(intval($v['xid'] == 0)){ - $sql = "UPDATE other_lcprepdetails SET Other_LcprepDetailsIsActive = 'N' - WHERE - Other_LcprepDetailsOther_LcprepID = {$header_id} AND - Other_LcprepDetailsCode = '{$v['code']}' AND - Other_LcprepDetailsIsActive = 'Y'"; - $this->db_smartone->query($sql); - $sql = "INSERT INTO other_lcprepdetails ( - Other_LcprepDetailsOther_LcprepID, - Other_LcprepDetailsCode, - Other_LcprepDetailsLabel, - Other_LcprepDetailsResult, - Other_LcprepDetailsUserID, - Other_LcprepDetailsCreated - ) - VALUES( - {$header_id}, - '{$v['code']}', - '{$v['label']}', - '{$v['result']}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if(intval($v['xid'] != 0)){ - $sql = "UPDATE other_lcprepdetails SET - Other_LcprepDetailsCode = '{$v['code']}', - Other_LcprepDetailsLabel = '{$v['label']}', - Other_LcprepDetailsResult = '{$v['result']}', - Other_LcprepDetailsUserID = {$userid} - WHERE - Other_LcprepDetailsID = {$v['xid']}"; - $this->db_smartone->query($sql); - - } - //echo $sql; - } - } - - if($interpretasi){ - foreach($interpretasi as $k =>$v){ - if(count($v['subgroups']) > 0){ - foreach($v['subgroups'] as $ik => $iv){ - if(count($iv['childs']) > 0){ - foreach($iv['childs'] as $iik => $iiv){ - if(intval($iiv['xid'] == 0)){ - $chex = $iiv['chex'] ? 'Y':'N'; - $sql = "UPDATE other_lcprepinterpretasi SET Other_LcprepInterpretasiIsActive = 'N' - WHERE - Other_LcprepInterpretasiOther_LcprepID = {$header_id} AND - Other_LcprepInterpretasiLcprep_InterpretasiID = '{$iiv['id']}' AND - Other_LcprepInterpretasiIsActive = 'Y'"; - $this->db_smartone->query($sql); - $sql = "INSERT INTO other_lcprepinterpretasi ( - Other_LcprepInterpretasiOther_LcprepID, - Other_LcprepInterpretasiLcprep_InterpretasiID, - Other_LcprepInterpretasiChex, - Other_LcprepInterpretasiValue, - Other_LcprepInterpretasiUserID, - Other_LcprepInterpretasiCreated - ) - VALUES( - {$header_id}, - '{$iiv['id']}', - '{$chex}', - '{$iiv['value']}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - - if(intval($iiv['xid'] != 0)){ - $chex = $iiv['chex'] ? 'Y':'N'; - $sql = "UPDATE other_lcprepinterpretasi SET - Other_LcprepInterpretasiChex = '{$chex}', - Other_LcprepInterpretasiValue = '{$iiv['value']}', - Other_LcprepInterpretasiUserID = {$userid} - WHERE - Other_LcprepInterpretasiID = {$iiv['xid']}"; - $this->db_smartone->query($sql); - //echo $sql; - - } - - } - } - } - } - //echo $sql; - } - } - - - $result = array("total" => 1, "records" => array(), "sql"=> ''); - $this->sys_ok($result); - exit; - } - - function saveresult_papsmear() - { - $prm = $this->sys_input; - $detail_id = $prm['detail_id']; - $doctor_id = $prm['doctor']; - $checks = $prm['checks']; - $maturasi = $prm['maturasi']; - $bahans = $prm['bahans']; - $categories = $prm['categories']; - $results = $prm['results']; - - $userid = $this->sys_user['M_UserID']; - - $header_id = 0; - $sql = "SELECT * FROM other_papsmear WHERE Other_PapSmearT_OrderDetailID = {$detail_id} AND Other_PapSmearIsActive = 'Y'"; - $dt_header = $this->db_smartone->query($sql)->row_array(); - if($dt_header){ - $header_id = $dt_header['Other_PapSmearID']; - } - if($header_id == 0){ - $sql = "INSERT INTO other_papsmear( - Other_PapSmearT_OrderDetailID, - Other_PapSmearM_DoctorID, - Other_PapSmearUserID, - Other_PapSmearCreated - ) - VALUES( - {$detail_id}, - {$doctor_id}, - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } - else{ - $sql = "UPDATE other_papsmear SET Other_PapSmearM_DoctorID = {$doctor_id}, Other_PapSmearUserID = {$userid} WHERE Other_PapSmearID = {$header_id}"; - $this->db_smartone->query($sql); - } - - if($checks){ - foreach($checks as $k =>$v){ - if(intval($v['xid']) == 0 && $v['selected'] === 'Y'){ - $sql = "INSERT INTO other_papsmearcheck ( - Other_PapSmearCheckOther_PapSmearID, - Other_PapSmearCheckM_PapSmearCheckID, - Other_PapSmearCheckNote, - Other_PapSmearCheckUserID, - Other_PapSmearCheckCreated - ) - VALUES( - {$header_id}, - {$v['check_id']}, - '{$v['note']}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if(intval($v['xid']) != 0 && $v['selected'] === 'N'){ - $sql = "UPDATE other_papsmearcheck SET - Other_PapSmearCheckIsActive = 'N', - Other_PapSmearCheckUserID = {$userid} - WHERE - Other_PapSmearCheckID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - if(intval($v['xid']) != 0 && $v['selected'] === 'Y'){ - $sql = "UPDATE other_papsmearcheck SET - Other_PapSmearCheckNote = '{$v['note']}', - Other_PapSmearCheckUserID = {$userid} - WHERE - Other_PapSmearCheckID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - //echo $sql; - } - } - - if($maturasi){ - if(intval($maturasi['xid']) == 0){ - $value = join("/",$maturasi['value']); - $sql = "INSERT INTO other_papsmearmaturasi ( - Other_PapSmearMaturasiOther_PapSmearID, - Other_PapSmearMaturasiValue, - Other_PapSmearMaturasiUserID, - Other_PapSmearMaturasiCreated - ) - VALUE( - {$header_id}, - '{$value}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - //echo $sql; - } - if(intval($maturasi['xid']) != 0){ - $value = join("/",$maturasi['value']); - $sql = "UPDATE other_papsmearmaturasi SET - Other_PapSmearMaturasiValue = '{$value}', - Other_PapSmearMaturasiUserID = {$userid} - WHERE - Other_PapSmearMaturasiID = {$maturasi['xid']}"; - // echo $sql; - $this->db_smartone->query($sql); - } - } - - if($bahans){ - foreach($bahans as $k =>$v){ - if(intval($v['xid']) == 0 && $v['selected'] === 'Y'){ - $sql = "INSERT INTO other_papsmearbahan ( - Other_PapSmearBahanOther_PapSmearID, - Other_PapSmearBahanM_PapSmearBahanID, - Other_PapSmearBahanUserID, - Other_PapSmearBahanCreated - ) - VALUES( - {$header_id}, - {$v['bahan_id']}, - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if(intval($v['xid']) != 0 && $v['selected'] === 'N'){ - $sql = "UPDATE other_papsmearbahan SET - Other_PapSmearBahanIsActive = 'N', - Other_PapsmearCategoryUserID = {$userid} - WHERE - Other_PapSmearBahanID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - if(intval($v['xid']) != 0 && $v['selected'] === 'Y'){ - $sql = "UPDATE other_papsmearbahan SET - Other_PapSmearBahanIsActive = 'Y', - Other_PapsmearCategoryUserID = {$userid} - WHERE - Other_PapSmearBahanID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - //echo $sql; - } - } - - if($categories){ - foreach($categories as $k =>$v){ - if(intval($v['xid']) == 0 && $v['selected'] === 'Y'){ - $sql = "INSERT INTO other_papsmearcategory ( - Other_PapsmearCategoryOther_PapSmearID, - Other_PapsmearCategoryM_PapSmearCategoryID, - Other_PapsmearCategoryUserID, - Other_PapsmearCategoryCreated - ) - VALUES( - {$header_id}, - {$v['category_id']}, - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if(intval($v['xid']) != 0 && $v['selected'] === 'N'){ - $sql = "UPDATE other_papsmearcategory SET - Other_PapsmearCategoryIsActive = 'N', - Other_PapsmearCategoryUserID = {$userid} - WHERE - Other_PapsmearCategoryID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - //echo $sql; - if(intval($v['xid']) != 0 && $v['selected'] === 'Y'){ - $sql = "UPDATE other_papsmearcategory SET - Other_PapsmearCategoryIsActive = 'Y', - Other_PapsmearCategoryUserID = {$userid} - WHERE - Other_PapsmearCategoryID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - } - } - - if($results){ - foreach($results as $k =>$v){ - if(intval($v['xid']) == 0){ - $sql = "INSERT INTO other_papsmeardetails ( - Other_PapSmearDetailsOther_PapSmearID, - Other_PapSmearDetailsCode, - Other_PapSmearDetailsLabel, - Other_PapSmearDetailsResult, - Other_PapSmearDetailsUserID, - Other_PapSmearDetailsCreated - ) - VALUES( - {$header_id}, - '{$v['code']}', - '{$v['label']}', - '{$v['result']}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if(intval($v['xid']) != 0){ - $sql = "UPDATE other_papsmeardetails SET - Other_PapSmearDetailsCode = '{$v['code']}', - Other_PapSmearDetailsLabel = '{$v['label']}', - Other_PapSmearDetailsResult = '{$v['result']}', - Other_PapSmearDetailsUserID = {$userid} - WHERE - Other_PapSmearDetailsID = {$v['xid']}"; - $this->db_smartone->query($sql); - - } - //echo $sql; - } - } - - $result = array("total" => 1, "records" => array(), "sql"=> ''); - $this->sys_ok($result); - exit; - } - - function saveresult_fna() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = $inp['doctor']; - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - if($prm[0]['xid'] == '0'){ - $sql = "INSERT INTO other_fna( - Other_FNAM_DoctorID, - Other_FNAT_OrderDetailID, - Other_FNAUserID, - Other_FNACreated - ) - VALUES( - {$doctor_id}, - {$prm[0]['orderdetail_id']}, - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } - else{ - $sql = "SELECT * FROM other_fna WHERE Other_FNAT_OrderDetailID = {$prm[0]['orderdetail_id']} AND Other_FNAIsActive = 'Y'"; - $data_header = $this->db_smartone->query($sql)->row_array(); - $header_id = $data_header['Other_FNAID']; - $sql = "UPDATE other_fna SET - Other_FNAM_DoctorID = {$doctor_id}, - Other_FNAUserID = {$userid} - WHERE - Other_FNAID = {$header_id}"; - $this->db_smartone->query($sql); - } - foreach($prm as $k => $v){ - if($v['xid'] == '0'){ - $results = str_replace("'", "\\'", $v['result']); - $sql = "INSERT INTO other_fnadetails( - Other_FNADetailsOther_FNAID , - Other_FNADetailsCode, - Other_FNADetailsLabel, - Other_FNADetailsResult, - Other_FNADetailsCreated, - Other_FNADetailsUserID - ) - VALUES( - {$header_id}, - '{$v['code']}', - '{$v['label']}', - '{$results}', - NOW(), - {$userid} - )"; - $query = $this->db_smartone->query($sql); - } - else{ - $results = str_replace("'", "\\'", $v['result']); - $sql = "UPDATE other_fnadetails SET - Other_FNADetailsResult = '{$results}', - Other_FNADetailsUserID = {$userid} - WHERE - Other_FNADetailsID = {$v['xid']}"; - $query = $this->db_smartone->query($sql); - } - } - - $result = array("total" => 1, "records" => array(), "sql"=> ''); - $this->sys_ok($result); - exit; - } - - function saveresult_cytologi() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = $inp['doctor']; - - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - if($prm[0]['xid'] == '0'){ - $sql = "INSERT INTO other_cytologi( - Other_CytologiT_OrderDetailID, - Other_CytologiM_DoctorID, - Other_CytologiUserID, - Other_CytologiCreated - ) - VALUES( - {$prm[0]['orderdetail_id']}, - {$doctor_id}, - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } - else{ - $sql = "SELECT * FROM other_cytologi WHERE Other_CytologiT_OrderDetailID = {$prm[0]['orderdetail_id']} AND Other_CytologiIsActive = 'Y'"; - $data_header = $this->db_smartone->query($sql)->row_array(); - $header_id = $data_header['Other_CytologiID']; - $sql = "UPDATE other_cytologi SET - Other_CytologiM_DoctorID = {$doctor_id}, - Other_CytologiUserID = {$userid} - WHERE - Other_CytologiID = {$header_id}"; - $this->db_smartone->query($sql); - } - foreach($prm as $k => $v){ - if($v['xid'] == '0'){ - $results = str_replace("'", "\\'", $v['result']); - $sql = "INSERT INTO other_cytologidetails( - Other_CytologiDetailsOther_CytologiID , - Other_CytologiDetailsCode, - Other_CytologiDetailsLabel, - Other_CytologiDetailsResult, - Other_CytologiDetailsCreated, - Other_CytologiDetailsUserID - ) - VALUES( - {$header_id}, - '{$v['code']}', - '{$v['label']}', - '{$results}', - NOW(), - {$userid} - )"; - $query = $this->db_smartone->query($sql); - } - else{ - $results = str_replace("'", "\\'", $v['result']); - $sql = "UPDATE other_cytologidetails SET - Other_CytologiDetailsResult = '{$results}', - Other_CytologiDetailsUserID = {$userid} - WHERE - Other_CytologiDetailsID = {$v['xid']}"; - $query = $this->db_smartone->query($sql); - } - } - - $result = array("total" => 1, "records" => array(), "sql"=> ''); - $this->sys_ok($result); - exit; - } - - function saveresult_mikro() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = $inp['doctor']; - $backteria_id = $inp['bacteria']; - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - - if($inp['result_value'] != 'Negatif' && $inp['result_value'] != 'Positif'){ - $prm['result_value'] = $prm['result_other']; - } - else{ - $prm['result_value'] = $inp['result_value']; - } - - if($prm['xid'] == '0'){ - $sql = "INSERT INTO other_mikro( - Other_MikroM_DoctorID, - Other_MikroResult, - Other_MikroT_BacteriaID, - Other_MikroT_OrderDetailID, - Other_MikroHasilBiakan, - Other_MikroSampleTypeName, - Other_MikroUserID, - Other_MikroCreated - ) - VALUES( - {$doctor_id}, - '{$prm['result_value']}', - {$backteria_id}, - {$prm['orderdetail_id']}, - '{$prm['hasil_biakan']}', - '{$prm['sample_name']}', - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } - else{ - $sql = "SELECT * FROM other_mikro WHERE Other_MikroT_OrderDetailID = {$prm['orderdetail_id']} AND Other_MikroIsActive = 'Y'"; - $data_header = $this->db_smartone->query($sql)->row_array(); - $header_id = $data_header['Other_MikroID']; - $sql = "UPDATE other_mikro SET - Other_MikroResult = '{$prm['result_value']}', - Other_MikroM_DoctorID = {$doctor_id}, - Other_MikroT_BacteriaID = {$backteria_id}, - Other_MikroHasilBiakan = '{$prm['hasil_biakan']}', - Other_MikroSampleTypeName = '{$prm['sample_name']}', - Other_MikroUserID = {$userid} - WHERE - Other_MikroID = {$header_id}"; - //echo $sql; - $this->db_smartone->query($sql); - } - - - - $sql = "UPDATE other_mikrodetails SET Other_MikroDetailsIsActive = 'N', Other_MikroDetailsUserID = 0 WHERE Other_MikroDetailsOther_MikroID = {$header_id}"; - $this->db_smartone->query($sql); - - $results = $prm['details']; - if($inp['result_value'] == 'Positif'){ - foreach($results as $k => $v){ - if($v['xid'] == '0'){ - $sql = "INSERT INTO other_mikrodetails( - Other_MikroDetailsOther_MikroID , - Other_MikroDetailsT_AntibioticID, - Other_MikroDetailsValue, - Other_MikroDetailsNote, - Other_MikroDetailsCreated, - Other_MikroDetailsUserID - ) - VALUES( - {$header_id}, - '{$v['T_AntibioticID']}', - '{$v['value']}', - '{$v['note']}', - NOW(), - {$userid} - )"; - $query = $this->db_smartone->query($sql); - } - else{ - $sql = "UPDATE other_mikrodetails SET - Other_MikroDetailsT_AntibioticID = '{$v['T_AntibioticID']}', - Other_MikroDetailsValue = '{$v['value']}', - Other_MikroDetailsNote = '{$v['note']}', - Other_MikroDetailsIsActive = 'Y', - Other_MikroDetailsUserID = {$userid} - WHERE - Other_MikroDetailsID = {$v['xid']}"; - //echo $sql; - $query = $this->db_smartone->query($sql); - } - } - } - - - $result = array("total" => 1, "records" => array(), "sql"=> ''); - $this->sys_ok($result); - exit; - } - - - function get_doctors_preparasi_sperma() - { - $prm = $this->sys_input; - // $id = $prm["id"]; - - $sql = " SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 10 AND - M_DoctorSOIsActive = 'Y' - ORDER BY M_DoctorName ASC"; - //echo $sql; - $query = $this->db_smartone->query($sql); - $rows = $query->result_array(); - $sql = " - SELECT '0' as id, 'Belum memilih metode' as name - UNION - SELECT M_MethodeSpermaID as id, M_MethodeSpermaName as name - FROM m_methodesperma - WHERE - M_MethodeSpermaIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $methodes = $this->db_smartone->query($sql)->result_array(); - - - $this->sys_ok(["records"=>$rows,"methodes"=>$methodes]); - - } - - - function getpreparasispermaresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT other_preparasisperma.*, - Other_PreparasiSpermaID as xid, - Other_PreparasiSpermaT_OrderDetailID as orderdetail_id, - IFNULL(Other_PreparasiSpermaM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_PreparasiSpermaM_DoctorID) OR Other_PreparasiSpermaM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name, - IFNULL(M_MethodeSpermaID,0) as methode_id, - IFNULL(M_MethodeSpermaName,'') as methode_name - FROM other_preparasisperma - LEFT JOIN m_doctor ON Other_PreparasiSpermaM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - LEFT JOIN m_methodesperma ON Other_PreparasiSpermaM_MethodeSpermaID = M_MethodeSpermaID AND - M_MethodeSpermaIsActive = 'Y' - WHERE - Other_PreparasiSpermaT_OrderDetailID = {$id} AND Other_PreparasiSpermaIsActive = 'Y' - GROUP BY Other_PreparasiSpermaID"; - $query = $this->db_smartone->query($sql); - - if ($query) - { - $rows = $query->row_array(); - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 10 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $sql = " - SELECT '0' as id, 'Belum memilih metode' as name - UNION - SELECT M_MethodeSpermaID as id, M_MethodeSpermaName as name - FROM m_methodesperma - WHERE - M_MethodeSpermaIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $methodes = $this->db_smartone->query($sql)->result_array(); - $images = array(); - $sql = "SELECT Other_PreparasiSpermaImgID as xid, - Other_PreparasiSpermaImgType as type, - CONCAT('/one-media/one-image-nonlab/',Other_PreparasiSpermaImgNewName) as image_url - FROM t_orderdetail - JOIN other_preparasisperma_img ON Other_PreparasiSpermaImgT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND - Other_PreparasiSpermaImgIsActive = 'Y' - WHERE - T_OrderDetailID = {$id} AND - T_OrderDetailIsActive = 'Y' - GROUP BY Other_PreparasiSpermaImgID"; - //echo $sql; - $images = $this->db_smartone->query($sql)->result_array(); - - $rst = array('doctors'=>$doctors,'methodes'=>$methodes,'results'=>$rows,'images'=>$images); - $this->sys_ok(["records"=>$rst]); - } - else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - - function uploadimage_preparasi_sperma(){ - if (! $this->isLogin) { - $this->sys_error("Invalid Token"); - exit; - } - - $userid = $this->sys_user["M_UserID"]; - $data = []; - //print_r($_SERVER); - - $prm = $this->sys_input; - $orderid = $this->input->post('orderid'); - $type = $this->input->post('type'); - $labnumber = $this->input->post('labnumber'); - $sql = "UPDATE other_preparasisperma_img SET - Other_PreparasiSpermaImgIsActive = 'N', - Other_PreparasiSpermaImgUserID = {$userid} - WHERE - Other_PreparasiSpermaImgT_OrderHeaderID = {$orderid} AND - Other_PreparasiSpermaImgType = '{$type}'"; - //echo $sql; - $this->db_onedev->query($sql); - //$config['upload_path'] = 'assets/'; - - $path = '/home/one/project/one/one-media/one-image-nonlab/'; - //echo $path; - $config['upload_path'] = $path; - $config['allowed_types'] = 'jpg|jpeg|png|gif'; - - $config['max_size'] = '10000'; - $count = count($_FILES['files']['name']); - //echo $count; - $this->load->library('upload',$config); - - $error = []; - for($i=0;$i<$count;$i++){ - - - if(!empty($_FILES['files']['name'][$i])){ - - - - $_FILES['file']['name'] = $_FILES['files']['name'][$i]; - - $_FILES['file']['type'] = $_FILES['files']['type'][$i]; - - $_FILES['file']['tmp_name'] = $_FILES['files']['tmp_name'][$i]; - - $_FILES['file']['error'] = $_FILES['files']['error'][$i]; - - $_FILES['file']['size'] = $_FILES['files']['size'][$i]; - - - - $namex = $orderid.'-'.$labnumber.'-'.$this->generateRandomString(5); - //echo $namex; - - $config['file_name'] = $namex; - $this->upload->initialize($config); - //echo $config['file_name'] ; - - - - - - if($this->upload->do_upload('file')){ - - $uploadData = $this->upload->data(); - - $filename = $uploadData['file_name']; - //echo $filename; - - - $sql = "INSERT INTO other_preparasisperma_img ( - Other_PreparasiSpermaImgT_OrderHeaderID, - Other_PreparasiSpermaImgType, - Other_PreparasiSpermaImgOldName, - Other_PreparasiSpermaImgNewName, - Other_PreparasiSpermaImgCreated, - Other_PreparasiSpermaImgUserID - ) - VALUES( - {$orderid}, - '{$type}', - '{$_FILES['files']['name'][$i]}', - '{$filename}', - NOW(), - {$userid} - - )"; - //echo $sql; - $this->db_onedev->query($sql); - $xlast_id = $this->db_onedev->insert_id(); - $data['totalFiles'][] = array('xid' => $xlast_id ,'type'=>$type,'image_url' => '/one-media/one-image-nonlab/'.$filename); - - } - else{ - $error = array('error' => $this->upload->display_errors()); - } - - } - - - - } - - $result = array("total" =>count( $data['totalFiles']), "records" => $data['totalFiles'],'errors'=>$error); - $this->sys_ok($result); - } - - - function saveresult_preparasi_sperma() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = $inp['doctor']; - $orderdetail_id = $inp['orderdetailid']; - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - if($prm['xid'] == '0'){ - $sql = "INSERT INTO other_preparasisperma( - Other_PreparasiSpermaM_DoctorID, - Other_PreparasiSpermaT_OrderDetailID, - Other_PreparasiSpermaPreMotilitasA, - Other_PreparasiSpermaPreMotilitasB, - Other_PreparasiSpermaPreMotilitasC, - Other_PreparasiSpermaPreKonsentrasi, - Other_PreparasiSpermaPreKontaminan, - Other_PreparasiSpermaPostMotilitasA, - Other_PreparasiSpermaPostMotilitasB, - Other_PreparasiSpermaPostMotilitasC, - Other_PreparasiSpermaPostKonsentrasi, - Other_PreparasiSpermaPostKontaminan, - Other_PreparasiSpermaPreVolume, - Other_PreparasiSpermaPostVolume, - Other_PreparasiSpermaM_MethodeSpermaID, - Other_PreparasiSpermaNote, - Other_PreparasiSpermaUserID, - Other_PreparasiSpermaCreated - ) - VALUES( - {$doctor_id}, - {$orderdetail_id}, - '{$prm['Other_PreparasiSpermaPreMotilitasA']}', - '{$prm['Other_PreparasiSpermaPreMotilitasB']}', - '{$prm['Other_PreparasiSpermaPreMotilitasC']}', - '{$prm['Other_PreparasiSpermaPreKonsentrasi']}', - '{$prm['Other_PreparasiSpermaPreKontaminan']}', - '{$prm['Other_PreparasiSpermaPostMotilitasA']}', - '{$prm['Other_PreparasiSpermaPostMotilitasB']}', - '{$prm['Other_PreparasiSpermaPostMotilitasC']}', - '{$prm['Other_PreparasiSpermaPostKonsentrasi']}', - '{$prm['Other_PreparasiSpermaPostKontaminan']}', - '{$prm['Other_PreparasiSpermaPreVolume']}', - '{$prm['Other_PreparasiSpermaPostVolume']}', - '{$prm['Other_PreparasiSpermaM_MethodeSpermaID']}', - '{$prm['Other_PreparasiSpermaNote']}', - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } - else{ - $sql = "SELECT * FROM other_preparasisperma WHERE Other_PreparasiSpermaT_OrderDetailID = {$orderdetail_id} AND Other_PreparasiSpermaIsActive = 'Y'"; - $data_header = $this->db_smartone->query($sql)->row_array(); - $header_id = $data_header['Other_PreparasiSpermaID']; - $sql = "UPDATE other_preparasisperma SET - Other_PreparasiSpermaM_DoctorID = {$doctor_id}, - Other_PreparasiSpermaPreMotilitasA = '{$prm['Other_PreparasiSpermaPreMotilitasA']}', - Other_PreparasiSpermaPreMotilitasB = '{$prm['Other_PreparasiSpermaPreMotilitasB']}', - Other_PreparasiSpermaPreMotilitasC = '{$prm['Other_PreparasiSpermaPreMotilitasC']}', - Other_PreparasiSpermaPreKonsentrasi = '{$prm['Other_PreparasiSpermaPreKonsentrasi']}', - Other_PreparasiSpermaPreKontaminan = '{$prm['Other_PreparasiSpermaPreKontaminan']}', - Other_PreparasiSpermaPostMotilitasA = '{$prm['Other_PreparasiSpermaPostMotilitasA']}', - Other_PreparasiSpermaPostMotilitasB = '{$prm['Other_PreparasiSpermaPostMotilitasB']}', - Other_PreparasiSpermaPostMotilitasC = '{$prm['Other_PreparasiSpermaPostMotilitasC']}', - Other_PreparasiSpermaPostKonsentrasi = '{$prm['Other_PreparasiSpermaPostKonsentrasi']}', - Other_PreparasiSpermaPostKontaminan = '{$prm['Other_PreparasiSpermaPostKontaminan']}', - Other_PreparasiSpermaPreVolume = '{$prm['Other_PreparasiSpermaPreVolume']}', - Other_PreparasiSpermaPostVolume = '{$prm['Other_PreparasiSpermaPostVolume']}', - Other_PreparasiSpermaM_MethodeSpermaID = '{$prm['Other_PreparasiSpermaM_MethodeSpermaID']}', - Other_PreparasiSpermaNote = '{$prm['Other_PreparasiSpermaNote']}', - Other_PreparasiSpermaUserID = {$userid} - WHERE - Other_PreparasiSpermaID = {$header_id}"; - $this->db_smartone->query($sql); - } - - - $result = array("total" => 1, "records" => array(), "sql"=> ''); - $this->sys_ok($result); - exit; - } - - function getdnafragmentasiresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT other_dnafragmentasi.*, - Other_DnaFragmentasiID as xid, - Other_DnaFragmentasiT_OrderDetailID as orderdetail_id, - IFNULL(Other_DnaFragmentasiM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_DnaFragmentasiM_DoctorID) OR Other_DnaFragmentasiM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name, - IFNULL(Other_DnaFragmentasiOther_DnaFragmentasiMethodeID,0) as methode_id, - IFNULL(Other_DnaFragmentasiMethodeName,'') as methode_name, - Other_DnaFragmentasiHaloLuas as halo_luas, - Other_DnaFragmentasiHaloSedang as halo_sedang, - Other_DnaFragmentasiHaloSempit as halo_sempit, - Other_DnaFragmentasiTanpaHalo as tanpa_halo, - Other_DnaFragmentasiDFI as dfi, - Other_DnaFragmentasiKesimpulan as kesimpulan, - Other_DnaFragmentasiCatatan as catatan - FROM other_dnafragmentasi - LEFT JOIN m_doctor ON Other_DnaFragmentasiM_DoctorID = M_DoctorID - LEFT JOIN other_dnafragmentasimethode ON Other_DnaFragmentasiOther_DnaFragmentasiMethodeID = Other_DnaFragmentasiMethodeID - WHERE - Other_DnaFragmentasiT_OrderDetailID = {$id} AND Other_DnaFragmentasiIsActive = 'Y' - GROUP BY Other_DnaFragmentasiID - LIMIT 1"; - //echo $sql; - $query = $this->db_smartone->query($sql); - - if ($query) - { - $rows = $query->row_array(); - if(!$rows){ - $rows = array( - 'xid' => 0, - 'orderdetail_id' =>$id, - 'doctor_id' => 0, - 'doctor_name' => '', - 'methode_id' => 0, - 'methode_name' => '', - 'halo_luas' => '', - 'halo_sedang' => '', - 'tanpa_halo' => '', - 'dfi' => '', - 'kesimpulan' => '', - 'catatan' => '' - ); - } - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID - WHERE - M_DoctorSONat_SubGroupID = 4 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - - $sql = " - SELECT '0' as id, 'Belum memilih metode' as name - UNION - SELECT Other_DnaFragmentasiMethodeID as id, Other_DnaFragmentasiMethodeName as name - FROM other_dnafragmentasimethode - WHERE - Other_DnaFragmentasiMethodeIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $methodes = $this->db_smartone->query($sql)->result_array(); - - - $rst = array('doctors'=>$doctors,'methodes'=>$methodes,'results'=>$rows); - $this->sys_ok(["records"=>$rst]); - } - else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - function saveresult_dnafragmentasi() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = $inp['doctor']['id']; - $methode_id = $inp['methode']['id']; - $orderdetail_id = $inp['results']['orderdetail_id']; - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - if(intval($prm['xid']) == 0){ - $sql = "INSERT INTO other_dnafragmentasi( - Other_DnaFragmentasiT_OrderDetailID, - Other_DnaFragmentasiM_DoctorID, - Other_DnaFragmentasiOther_DnaFragmentasiMethodeID, - Other_DnaFragmentasiHaloLuas, - Other_DnaFragmentasiHaloSedang, - Other_DnaFragmentasiHaloSempit, - Other_DnaFragmentasiTanpaHalo, - Other_DnaFragmentasiDFI, - Other_DnaFragmentasiKesimpulan, - Other_DnaFragmentasiCatatan, - Other_DnaFragmentasiUserID, - Other_DnaFragmentasiLastUpdated - ) - VALUES( - {$orderdetail_id}, - {$doctor_id}, - {$methode_id}, - '{$prm['halo_luas']}', - '{$prm['halo_sedang']}', - '{$prm['halo_sempit']}', - '{$prm['tanpa_halo']}', - '{$prm['dfi']}', - '{$prm['kesimpulan']}', - '{$prm['catatan']}', - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } - else{ - $sql = "UPDATE other_dnafragmentasi SET - Other_DnaFragmentasiT_OrderDetailID = {$orderdetail_id}, - Other_DnaFragmentasiM_DoctorID = {$doctor_id}, - Other_DnaFragmentasiOther_DnaFragmentasiMethodeID = '{$methode_id}', - Other_DnaFragmentasiHaloLuas = '{$prm['halo_luas']}', - Other_DnaFragmentasiHaloSedang = '{$prm['halo_sedang']}', - Other_DnaFragmentasiHaloSempit = '{$prm['halo_sempit']}', - Other_DnaFragmentasiTanpaHalo = '{$prm['tanpa_halo']}', - Other_DnaFragmentasiDFI = '{$prm['dfi']}', - Other_DnaFragmentasiKesimpulan = '{$prm['kesimpulan']}', - Other_DnaFragmentasiCatatan = '{$prm['catatan']}', - Other_DnaFragmentasiLastUpdated = NOW(), - Other_DnaFragmentasiUserID = {$userid} - WHERE - Other_DnaFragmentasiID = {$prm['xid']}"; - //echo $sql; - $this->db_smartone->query($sql); - } - - - $result = array("total" => 1, "records" => array(), "sql"=> ''); - $this->sys_ok($result); - exit; - } - - -} - +db_smartone = $this->load->database("onedev", true); + $this->load->helper(array('form', 'url')); + } + function getMethodeID($natTestID) { + $sql = "select M_MethodePriorityNat_MethodeID MethodeID, Nat_MethodeName + from + m_methode_priority + join nat_methode on Nat_MethodeID = M_MethodePriorityNat_MethodeID + and Nat_MethodeIsActive = 'Y' + join m_instrumentmethode on M_InstrumentMethodeNat_MethodeID = Nat_MethodeID and M_InstrumentMethodeIsActive = 'Y' + join nat_instrument on M_InstrumentMethodeNat_InstrumentID = Nat_InstrumentID + and Nat_InstrumentIsActive ='Y' + where M_MethodePriorityIsActive = 'Y' + and M_MethodePriorityNat_TestID = $natTestID + and M_MethodePriorityM_DayOfWeekID = dayofweek(now()) + order by M_MethodePriorityNumber desc + limit 0,1 "; + $qry = $this->db->query($sql); + if ($qry) { + $rows = $qry->result_array(); + if (count($rows) > 0 ) return array($rows[0]["MethodeID"],$rows[0]["Nat_MethodeName"]); + } + //2nd + $sql= "select + M_InstrumentMethodeNat_MethodeID MethodeID, Nat_MethodeName + from m_instrumentmethode + join nat_methode on M_InstrumentMethodeNat_MethodeID = Nat_MethodeID + and Nat_MethodeIsActive = 'Y' + join nat_instrument on M_InstrumentMethodeNat_InstrumentID = Nat_InstrumentID + and Nat_InstrumentIsActive ='Y' + where M_InstrumentMethodeNat_TestID = $natTestID + and M_InstrumentMethodeIsActive = 'Y' + order by M_InstrumentMethodePriority desc + limit 0,1"; + $qry = $this->db->query($sql); + if ($qry) { + $rows = $qry->result_array(); + if (count($rows) > 0 ) return array($rows[0]["MethodeID"],$rows[0]["Nat_MethodeName"]); + } + // + $sql = "select Nat_NormalValueNat_MethodeID MethodeID, Nat_MethodeName + from + nat_normalvalue + join nat_methode on Nat_NormalValueNat_MethodeID = Nat_MethodeID + and Nat_MethodeIsActive = 'Y' + where Nat_NormalValueNat_TestID = $natTestID + and Nat_NormalValueIsActive = 'Y' + order by Nat_NormalValueID + limit 0,1"; + $qry = $this->db->query($sql); + if ($qry) { + $rows = $qry->result_array(); + if (count($rows) > 0 ) return array($rows[0]["MethodeID"],$rows[0]["Nat_MethodeName"]); + } + return array(0,""); + } + function get_normal_value($methodeID, $natTestID, $sexID, $ageInDay ) { + $this->load->library('ibl_sampling_normal'); + return $this->ibl_sampling_normal->get_normal_value_id($methodeID, $natTestID, $sexID, $ageInDay); + } + return 0; + } + function fn_fix_normal($order_id) { + $sql = "select + T_OrderDetailID, M_PatientM_SexID, fn_global_age_count_day(M_PatientDOB, date(T_OrderHeaderDate)) Dob , + T_TestNat_TestID + from t_orderheader + join m_patient on T_OrderHeaderID = $order_id and T_OrderHeaderM_PatientID = M_PatientID + join t_orderdetail on T_OrderDetailT_OrderHeaderID = T_OrderHeaderID + and T_OrderDetailIsACtive = 'Y' + and ( T_OrderDetailNat_NormalValueID is null or T_OrderDetailNat_NormalValueID = 0 ) + join t_test on T_OrderDetailT_TestID = T_TestID and T_TestIsResult = 'Y' "; + $qry = $this->db->query($sql); + if(! $qry) { + return; + } + $rows = $qry->result_array(); + if(count($rows) == 0 ) return; + $sql_u = "update t_orderdetail + join nat_normalvalue on T_OrderDetailID = ? and Nat_NormalValueID = ? + set + T_OrderDetailNat_NormalValueID = Nat_NormalValueID, + T_OrderDetailNormalValueNote = Nat_NormalValueNote, + T_OrderDetailNormalValueDescription = Nat_NormalValueDescription, + T_OrderDetailMinValue = Nat_NormalValueMinValue, + T_OrderDetailMaxValue = Nat_NormalValueMaxValue, + T_OrderDetailMinValueInclusive = Nat_NormalValueMinValueInclusive, + T_OrderDetailMaxValueInclusive = Nat_NormalValueMaxValueInclusive, + T_OrderDetailNat_MethodeID = ?, + T_OrderdetailNat_MethodeName =?"; + + foreach($rows as $r) { + $T_OrderDetailID = $r["T_OrderDetailID"]; + $sexID = $r["M_PatientM_SexID"]; + $ageInDay = $r["Dob"]; + $natTestID = $r["T_TestNat_TestID"]; + list($methodeID,$methodeName) = $this->getMethodeID($natTestID); + if ($methodeID == 0 ) continue; + $normalValueID = $this->get_normal_value($methodeID, $natTestID, $sexID, $ageInDay); + if ($normalValueID == 0) return; + $this->db->query($sql_u, array($T_OrderDetailID, $normalValueID, $methodeID, $methodeName)); + } + } + function update_order_sample($targetID, $sourceID) { + $sql = "update t_ordersample target + join t_ordersample source on + target.T_OrderSampleID = ? + and target.T_OrderSampleWorklistReceive = 'N' + and source.T_OrderSampleID = ? + set + target.T_OrderSampleSampling = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSampling, source.T_OrderSampleSampling), + target.T_OrderSampleSamplingDate = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingDate, source.T_OrderSampleSamplingDate), + target.T_OrderSampleSamplingTime = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingTime, source.T_OrderSampleSamplingTime), + target.T_OrderSampleSamplingUserID = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingUserID, source.T_OrderSampleSamplingUserID), + + target.T_OrderSampleReceive = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceive, source.T_OrderSampleReceive), + target.T_OrderSampleReceiveDate = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveDate, source.T_OrderSampleReceiveDate), + target.T_OrderSampleReceiveTime = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveTime, source.T_OrderSampleReceiveTime), + target.T_OrderSampleReceiveUserID = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveUserID, source.T_OrderSampleReceiveUserID), + + target.T_OrderSampleVerification = if(target.T_OrderSampleVerification='Y',target.T_OrderSampleVerification, source.T_OrderSampleVerification), + target.T_OrderSampleVerificationDate =if(target.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationDate, source.T_OrderSampleVerificationDate), + target.T_OrderSampleVerificationTime =if(source.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationTime, source.T_OrderSampleVerificationTime), + target.T_OrderSampleVerificationUserID =if(source.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationUserID, source.T_OrderSampleVerificationUserID), + + target.T_OrderSampleProcessing = if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessing, source.T_OrderSampleProcessing), + target.T_OrderSampleProcessingDate= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingDate, source.T_OrderSampleProcessingDate), + target.T_OrderSampleProcessingTime= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingTime, source.T_OrderSampleProcessingTime), + target.T_OrderSampleProcessingUserID= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingUserID, source.T_OrderSampleProcessingUserID), + + target.T_OrderSampleReceiveHandling =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandling, source.T_OrderSampleReceiveHandling ), + target.T_OrderSampleReceiveHandlingDate =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingDate, source.T_OrderSampleReceiveHandlingDate), + target.T_OrderSampleReceiveHandlingTime =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingTime, source.T_OrderSampleReceiveHandlingTime), + target.T_OrderSampleReceiveHandlingUserID =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingUserID, source.T_OrderSampleReceiveHandlingUserID), + + target.T_OrderSampleHandling = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandling, source.T_OrderSampleHandling), + target.T_OrderSampleHandlingDate = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingDate, source.T_OrderSampleHandlingDate), + target.T_OrderSampleHandlingTime = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingTime, source.T_OrderSampleHandlingTime), + target.T_OrderSampleHandlingUserID = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingUserID, source.T_OrderSampleHandlingUserID), + + target.T_OrderSampleWorklistReceive = source.T_OrderSampleWorklistReceive, + target.T_OrderSampleWorklistReceiveDatetime = source.T_OrderSampleWorklistReceiveDateTime, + target.T_OrderSampleWorklistReceiveUserID = source.T_OrderSampleWorklistReceiveUserID + "; + $qry = $this->db->query($sql,array($targetID,$sourceID)); + if(! $qry ) { + echo json_encode(array( "status" => "ERR" , "message" => print_r($this->db->error(),true))); + exit; + } + } + function fix_sample_serum($headerID) { + //cari t_ordersample yg belum worklist receive dengan code 017% + $sql = "select T_OrderSampleID + from t_ordersample + join t_sampletype on + T_OrderSampleT_OrderHeaderID = ? + and T_OrderSampleWorklistReceive = 'N' + and T_OrderSampleIsActive = 'Y' + and T_OrderSampleT_SampleTypeID = T_SampletypeID + and T_SampleTypeCode like '017%' + "; + $qry = $this->db->query($sql, array($headerID)); + if(!$qry) { + echo json_encode(array( "status" => "ERR" , "message" => print_r($this->db->error(),true))); + exit; + } + $rows = $qry->result_array(); + if (count($rows) == 0 ) return; + //cari T_OrderSample yang sudah di receive yg terakhir + $sql = "select T_OrderSampleID + from t_ordersample + join t_sampletype on + T_OrderSampleT_OrderHeaderID = ? + and T_OrderSampleWorklistReceive = 'Y' + and T_OrderSampleIsActive = 'Y' + and T_OrderSampleT_SampleTypeID = T_SampletypeID + and T_SampleTypeCode like '017%' + order by T_OrderSampleWorklistReceiveDatetime desc + limit 0,1 + "; + $qry = $this->db->query($sql, array($headerID)); + if(!$qry) { + echo json_encode(array( "status" => "ERR" , "message" => print_r($this->db->error(),true))); + exit; + } + $rcv_rows = $qry->result_array(); + if (count($rcv_rows) == 0 ) return; + + //print_r($rows); + //print_r($rcv_rows); + $rcv_T_OrderSampleID = $rcv_rows[0]["T_OrderSampleID"]; + //ada yg belum di receive + foreach($rows as $r) { + $T_OrderSampleID = $r["T_OrderSampleID"]; + $this->update_order_sample($T_OrderSampleID,$rcv_T_OrderSampleID); + } + } + public function search() + { + $prm = $this->sys_input; + $max_rst = 99; + + $id = $prm["order_id"]; + if ($id > 0 ) { + $this->fix_sample_serum($id); + $this->fn_fix_normal($id); + } + $lang = $this->lang_default_code; + $lang_id = isset($prm['lang_id']) ? $prm['lang_id'] : '0'; + + if ($lang_id != 0) + { + $l = $this->db_smartone->where("Nat_LangID", $lang_id)->get("nat_lang")->row(); + $lang = $l->Nat_LangCode; + } + + //tambahan fajri + $sql = " UPDATE t_orderdetail + JOIN t_test ON T_OrderDetailT_TestID = T_TestID + SET T_OrderDetailT_TestIsResult = T_TestIsResult + WHERE + T_OrderDetailT_OrderHeaderID = {$id} AND + T_OrderDetailT_TestIsResult = '' AND + T_OrderDetailIsActive = 'Y'"; + $this->db_smartone->query($sql); + + $tot_count = 0; + $lq = ""; + $group_id = 0; + if (isset($prm['group_id'])) + $group_id = $prm['group_id']; + + if ($group_id != 0) + { + $sql = "select distinct T_WorklistDetailNat_TestID Nat_TestID + from t_worklistdetailv2 + where T_WorklistDetailT_WorklistID = {$group_id}"; + $qry = $this->db_smartone->query($sql); + $rows = $qry->result_array(); + $nat_test_ids = "0"; + foreach($rows as $r) { + $nat_test_ids .= ", " . $r["Nat_TestID"]; + } + $q_group = " ( $nat_test_ids ) "; + + $sql = " + SELECT a1.*, cOUNT(a2.T_OrderDetailID) level + FROM ( + SELECT IFNULL(y.T_OrderDetailT_TestID, x.T_OrderDetailT_TestID) t_testid, + IFNULL(y.T_OrderDetailT_TestName, y.T_OrderDetailT_TestName) t_testname, + y.T_OrderDetailResult result, y.T_OrderDetailResult result_old, y.T_OrderDetailNote note, y.T_OrderDetailNote note_old, + y.T_OrderDetailID id, + y.T_OrderDetailT_TestIsResult is_result, a.T_TestIsQuantitative is_quantitative, + y.T_OrderDetailResultFlag result_flag, + y.T_OrderDetailNat_NormalValueID normal_id, + y.T_OrderDetailNormalValueNote normal_note, y.T_OrderDetailNat_UnitName unit_name, + y.T_OrderdetailNat_MethodeID methode_id, y.T_OrderdetailNat_MethodeName methode_name, + a.T_TestNat_TestID nattest_id, a.T_TestID tx_id, count(T_ResultInstrumentID) as result_instrument_n, + y.T_OrderDetailVerification, T_OrderSampleReceive sample_receive, + T_OrderSampleProcessing sample_processing, T_OrderSampleWorklistReceive sample_worklist_receive, + IF(T_OrderDetailAddOnPreAnalytic = 'Y', T_OrderDetailAddOnPreAnalytic, PreAnalyticIsOk) pre_analytic, + T_OrderDetailAddOnPreAnalytic, + T_OrderHeaderID order_id, y.T_OrderDetailT_TestSasCode test_sas_code, + tx.T_TestSasCode, + T_OrderDetailAddOnResample `resample`, T_OrderDetailAddOnResampleStatus resample_status, + T_OrderDetailAddOnRef ref, y.T_OrderDetailVerification verification, y.T_OrderDetailValidation validation, + T_OrderPromiseDateTime, Group_ResultName as ResultGroupName + FROM t_orderdetail x + left join t_orderpromise on x.T_OrderDetailT_OrderPromiseID = T_OrderPromiseID + JOIN t_test tx ON x.T_OrderDetailT_TestID = T_TestID + JOIN t_test tcheck on tcheck.T_TestNat_TestID in {$q_group} + and ( tx.T_TestID = tcheck.T_TestID or tx.T_TestSasCode like concat(tcheck.T_TestSasCode,'%')) + LEFT JOIN group_resultdetail ON Group_ResultDetailT_TestID = x.T_OrderDetailT_TestID AND Group_ResultDetailIsActive = 'Y' + LEFT JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND Group_ResultFlagNonLab = 'N' + LEFT JOIN t_orderdetail y ON x.T_OrderDetailT_TestSasCode LIKE CONCAT(y.T_OrderDetailT_TestSasCode, '%') + AND x.T_OrderDetailT_OrderHeaderID = y.T_OrderDetailT_OrderHeaderID + AND y.T_OrderDetailIsActive = 'Y' + LEFT JOIN t_orderdetailaddon ON x.T_OrderDetailID = T_OrderDetailAddOnT_OrderDetailID + JOIN t_orderheader ON y.T_OrderDetailT_OrderHeaderID = T_OrderHeaderID + LEFT JOIN t_test a ON y.T_OrderDetailT_TestID = a.T_TestID + AND a.T_TestIsNonLab = '' + LEFT JOIN (SELECT T_OrderSampleT_SampleTypeID, T_OrderSampleReceive, T_OrderSampleProcessing, T_OrderSampleWorklistReceive + FROM t_ordersample WHERE T_OrderSampleT_OrderHeaderID = {$id} + AND T_OrderSampleIsactive = 'Y' + GROUP BY T_OrderSampleT_SampleTypeID) os ON a.T_TestT_SampleTypeID = os.T_OrderSampleT_SampleTypeID + or os.T_OrderSampleT_SampleTypeID = fn_sampletype_from_local(a.T_TestNat_TestID) + + LEFT JOIN t_resultinstrument ON T_ResultInstrumentT_OrderDetailID = x.T_OrderDetailID + LEFT JOIN pre_analytic ON PreAnalyticNat_TestID = a.T_TestNat_TestID AND PreAnalyticDate = date(now()) and PreAnalyticIsActive = 'Y' + WHERE x.T_OrderDetailT_OrderHeaderID = {$id} + AND x.T_OrderDetailIsActive = 'Y' + GROUP BY y.T_OrderDetailT_TestID + ORDER BY y.T_OrderDetailT_TestSasCode ASC + ) a1 + + LEFT JOIN t_orderdetail a2 ON a2.T_OrderDetailT_OrderHeaderID = a1.order_id + AND a2.T_OrderDetailIsActive = 'Y' + AND a1.test_sas_code LIKE CONCAT(a2.T_OrderDetailT_testSasCode, '%') + GROUP BY a1.t_testid + order by a1.test_sas_code +"; + $query = $this->db_smartone->query($sql); + $lq = $this->db_smartone->last_query(); + } + else + { + $sql = " + SELECT a1.*, cOUNT(a2.T_OrderDetailID) level + FROM ( + SELECT IFNULL(y.T_OrderDetailT_TestID, x.T_OrderDetailT_TestID) t_testid, + IFNULL(y.T_OrderDetailT_TestName, y.T_OrderDetailT_TestName) t_testname, + y.T_OrderDetailResult result, y.T_OrderDetailResult result_old, y.T_OrderDetailNote note, y.T_OrderDetailNote note_old, + y.T_OrderDetailID id, + y.T_OrderDetailT_TestIsResult is_result, a.T_TestIsQuantitative is_quantitative, + y.T_OrderDetailResultFlag result_flag, + y.T_OrderDetailNat_NormalValueID normal_id, + y.T_OrderDetailNormalValueNote normal_note, y.T_OrderDetailNat_UnitName unit_name, + y.T_OrderdetailNat_MethodeID methode_id, y.T_OrderdetailNat_MethodeName methode_name, + a.T_TestNat_TestID nattest_id, a.T_TestID tx_id, count(T_ResultInstrumentID) as result_instrument_n, + y.T_OrderDetailVerification, T_OrderSampleReceive sample_receive, + T_OrderSampleProcessing sample_processing, T_OrderSampleWorklistReceive sample_worklist_receive, + IF(T_OrderDetailAddOnPreAnalytic = 'Y', T_OrderDetailAddOnPreAnalytic, PreAnalyticIsOk) pre_analytic, + T_OrderDetailAddOnPreAnalytic, + T_OrderHeaderID order_id, y.T_OrderDetailT_TestSasCode test_sas_code, + tx.T_TestSasCode, + T_OrderDetailAddOnResample `resample`, T_OrderDetailAddOnResampleStatus resample_status, + T_OrderDetailAddOnRef ref, y.T_OrderDetailVerification verification, y.T_OrderDetailValidation validation, + T_OrderPromiseDateTime , Group_ResultName as ResultGroupName + FROM t_orderdetail x + left join t_orderpromise on x.T_OrderDetailT_OrderPromiseID = T_OrderPromiseID + JOIN t_test tx ON x.T_OrderDetailT_TestID = T_TestID + LEFT JOIN group_resultdetail ON Group_ResultDetailT_TestID = x.T_OrderDetailT_TestID AND Group_ResultDetailIsActive = 'Y' + LEFT JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND Group_ResultFlagNonLab = 'N' + LEFT JOIN t_orderdetail y ON x.T_OrderDetailT_TestSasCode LIKE CONCAT(y.T_OrderDetailT_TestSasCode, '%') + AND x.T_OrderDetailT_OrderHeaderID = y.T_OrderDetailT_OrderHeaderID + AND y.T_OrderDetailIsActive = 'Y' + + LEFT JOIN t_orderdetailaddon ON x.T_OrderDetailID = T_OrderDetailAddOnT_OrderDetailID + + JOIN t_orderheader ON y.T_OrderDetailT_OrderHeaderID = T_OrderHeaderID + LEFT JOIN t_test a ON y.T_OrderDetailT_TestID = a.T_TestID + AND a.T_TestIsNonLab = '' + LEFT JOIN (SELECT T_OrderSampleT_SampleTypeID, T_OrderSampleReceive, T_OrderSampleProcessing, T_OrderSampleWorklistReceive + FROM t_ordersample WHERE T_OrderSampleT_OrderHeaderID = {$id} + AND T_OrderSampleIsactive = 'Y' + GROUP BY T_OrderSampleT_SampleTypeID) os ON a.T_TestT_SampleTypeID = os.T_OrderSampleT_SampleTypeID + or os.T_OrderSampleT_SampleTypeID = fn_sampletype_from_local(a.T_TestNat_TestID) + + LEFT JOIN t_resultinstrument ON T_ResultInstrumentT_OrderDetailID = x.T_OrderDetailID + LEFT JOIN pre_analytic ON PreAnalyticNat_TestID = a.T_TestNat_TestID AND PreAnalyticDate = date(now()) and PreAnalyticIsActive = 'Y' + WHERE x.T_OrderDetailT_OrderHeaderID = {$id} + AND x.T_OrderDetailIsActive = 'Y' + GROUP BY y.T_OrderDetailT_TestID + ORDER BY y.T_OrderDetailT_TestSasCode ASC + ) a1 + + LEFT JOIN t_orderdetail a2 ON a2.T_OrderDetailT_OrderHeaderID = a1.order_id + AND a2.T_OrderDetailIsActive = 'Y' + AND a1.test_sas_code LIKE CONCAT(a2.T_OrderDetailT_testSasCode, '%') + GROUP BY a1.t_testid + order by a1.test_sas_code +"; +//echo $sql; + $query = $this->db_smartone->query($sql); + $lq = $this->db_smartone->last_query(); + } + // file_put_contents("/xtmp/re-query.sql",$lq); + + if ($query) { + $rst = []; + $rows = $query->result_array(); + + foreach($rows as $k => $v) + { + + if ($v['is_result'] == "Y" && $v['is_quantitative'] == "N") + { + $v['template'] = []; + $x = $this->db_smartone->query("CALL sp_master_resulttemplate_get('{$v['t_testid']}')"); + $this->clean_mysqli_connection($this->db_smartone->conn_id); + if ($x) + $v['template'] = $x->result_array(); + } + + // IF Rujukan, by pas Pre Analytik + if ($v['ref'] == 'Y') + $v['pre_analytic'] = 'Y'; + if ($v["id"] == "885455" ) + { + //sipe workaround + //$v["sample_receive"] = "Y"; + $v["sample_worklist_receive"] = "Y"; + } + $rst[] = $v; + } + + $result = array("total" => $tot_count, "records" => $rst, "total_display" => sizeof($rows), "q" => $lq); + $this->sys_ok($result); + } + else { + $this->sys_error_db("RE Px rows", $this->db_smartone); + exit; + } + } + + public function save() + { + $prm = $this->sys_input; + $data = json_decode($prm["data"]); + $lang = $this->lang_default_code; + $lang_id = isset($prm['lang_id']) ? $prm['lang_id'] : '0'; + + if ($lang_id != 0) + { + $l = $this->db_smartone->where("Nat_LangID", $lang_id)->get("nat_lang")->row(); + $lang = $l->Nat_LangCode; + } + + $sql_norm = "select T_OrderDetailMinValue, T_OrderDetailMaxValue, + T_OrderDetailMinValueInclusive, T_OrderDetailMaxValueInclusive, + Nat_TestFlagLow, Nat_TestFlagHigh + from t_orderdetail + join t_test on T_OrderDetailT_TestID = T_TestID + join nat_test on T_TestNat_TestID = Nat_TestID and T_TestIsActive = 'Y' + where T_OrderDetailID = ? "; + + $ids = []; + foreach ($data as $k => $v) + { + if ( $v->resultInstrumentID > 0 ) { + $sql_i = "select T_ResultInstrumentNat_NormalValueID normalValueID + from t_resultinstrument + where T_ResultInstrumentID = ?"; + $qry_i = $this->db_smartone->query($sql_i, array($v->resultInstrumentID)); + if ($qry_i) { + $rows_i = $qry_i->result_array(); + + if (count($rows_i) > 0 ) { + $sql_iu = "update t_orderdetail, nat_normalvalue , nat_methode + set T_OrderDetailMinValue = Nat_NormalValueMinValue, + T_OrderDetailMinValueInclusive = Nat_NormalValueMinValueInclusive, + T_OrderDetailMaxValue = Nat_NormalValueMaxValue , + T_OrderDetailMaxValueInclusive = Nat_NormalValueMaxValueInclusive, + T_OrderDetailNormalValueNote = Nat_NormalValueNote, + T_OrderDetailNormalValueDescription = Nat_NormalValueDescription, + T_OrderDetailNat_NormalValueID = Nat_NormalValueID, + T_OrderDetailNat_MethodeID = Nat_NormalValueNat_MethodeID, + T_OrderDetailNat_MethodeName = Nat_MethodeName + where T_OrderDetailID = ? and Nat_NormalValueID = ? + and Nat_NormalValueNat_MethodeID = Nat_MethodeID + "; + $this->db_smartone->query($sql_iu, array($v->id, $rows_i[0]["normalValueID"])); + //file_put_contents("/xtmp/update-nilai-normal", $this->db_smartone->last_query() . "\n", FILE_APPEND); + } + } + } + $y = $this->db_smartone->query("SELECT fn_process_sample_handling_perfect('{$v->order_id}', '{$v->test_id}') c") + ->row(); + $req_status = $y->c; + $qry_norm = $this->db_smartone->query($sql_norm,$v->id); + $result_flag = ""; + if ($qry_norm) { + $rows_norm = $qry_norm->result_array(); + if (count($rows_norm) > 0 ) { + $r = $rows_norm[0]; + if (is_numeric($v->result)) { + + if ( $r["T_OrderDetailMinValueInclusive"] == "Y" && $v->result < $r["T_OrderDetailMinValue"] ) { + $result_flag = $r["Nat_TestFlagLow"]; + } + if ( $r["T_OrderDetailMinValueInclusive"] == "N" && $v->result <= $r["T_OrderDetailMinValue"] ) { + $result_flag = $r["Nat_TestFlagLow"]; + } + if ( $r["T_OrderDetailMaxValueInclusive"] == "Y" && $v->result > $r["T_OrderDetailMaxValue"] ) { + $result_flag = $r["Nat_TestFlagHigh"]; + } + if ( $r["T_OrderDetailMaxValueInclusive"] == "N" && $v->result >= $r["T_OrderDetailMaxValue"] ) { + $result_flag = $r["Nat_TestFlagHigh"]; + } + } + } + } + if ($lang == $this->lang_default_code) + { + $this->db_smartone->set('T_OrderDetailResult', $v->result) + ->set('T_OrderDetailResultFlag', $result_flag) + ->set('T_OrderDetailNote', $v->note) + ->set('T_OrderDetailReqStatus', $req_status) + ->where('T_OrderDetailID', $v->id) + ->update('t_orderdetail'); + } + else + { + $this->db_smartone->set('T_OrderDetailLangResult', $v->result) + ->set('T_OrderDetailLangNote', $v->note) + ->where('T_OrderDetailLangID', $v->id) + ->update('t_orderdetaillang'); + } + + $ids[] = $v->id; + } + + // LOG Process + $order = $this->db_smartone->select('T_OrderDetailT_OrderHeaderID id, T_OrderHeaderLabNumber lab_number', false) + ->join('t_orderheader', 'T_OrderHeaderID = T_OrderDetailT_OrderHeaderID') + ->where('T_OrderDetailID', $data[0]->id) + ->get('t_orderdetail') + ->row(); + + $dblog = $this->load->database("onelog", true); + $dblog->set('Log_ProcessCode', 'PROCESS.Result.Entry') + ->set('Log_ProcessOrderID', $order->id) + ->set('Log_ProcessOrderNumber', $order->lab_number) + ->set('Log_ProcessJson', json_encode($data)) + ->set('Log_ProcessUserID', $this->sys_user['M_UserID']) + ->insert('log_process'); + // END OF Log Process + //auto calculation + $this->load->library("Resultcalc"); + $rows = $this->resultcalc->auto($order->id); + + try { + foreach($ids as $id ) { + $this->db_smartone->query("call sp_set_normal_value_flag($id)"); + $this->clean_mysqli_connection($this->db_smartone->conn_id); + } + } catch(Exception $e) { + } + + $this->sys_ok($ids); + } + + public function save_template() + { + $prm = $this->sys_input; + + $n = $this->db_smartone->select("COUNT(T_ResultTemplateID) n") + ->where("T_ResultTemplateT_TestID", $prm['test_id']) + ->where("T_ResultTemplateIsActive", "Y") + ->where("T_ResultTemplateValue", $prm['value']) + ->get('t_resulttemplate') + ->row(); + if ($n->n > 0) + { + $this->sys_error_db("Insert Result Template", $this->db_smartone); + return; + } + + $r = $this->db_smartone->set("T_ResultTemplateT_TestID", $prm['test_id']) + ->set("T_ResultTemplateValue", $prm['value']) + ->insert('t_resulttemplate'); + if ($r) + { + $template = []; + $x = $this->db_smartone->query("CALL sp_master_resulttemplate_get('{$prm['test_id']}')"); + $this->clean_mysqli_connection($this->db_smartone->conn_id); + if ($x) + $template = $x->result_array(); + + $this->sys_ok($template); + } + } + + public function export() + { + $prm = $this->sys_input; + + $sql = "CALL sp_process_result_lang(?, ?, ?, ?)"; + $query = $this->db_smartone->query($sql, [$prm['order_id'], $prm['lang_id'], $prm['is_si'], $this->sys_user['M_UserID']]); + if ($query) + { + $r = $query->row(); + if ($r->status == "OK") + { + $this->sys_ok($r->data); + return; + } + + $this->sys_error_db("Message : " . $r->message, $this->db_smartone); + } + else + { + $this->sys_error_db("Lang Result", $this->db_smartone); + return; + } + } + + public function search_group() + { + $prm = $this->sys_input; + $max_rst = 100; + + // QUERY TOTAL + $sql = "select count(*) total + from t_worklist + where T_WorklistIsActive = 'Y' + order by T_WorklistName ASC"; + $query = $this->db_smartone->query($sql); + + if ($query) { + $tot_count = $query->result_array()[0]["total"]; + } + else { + $this->sys_error_db("worklist count", $this->db_smartone); + exit; + } + + $sql = "select T_WorklistID group_id, T_WorklistName group_name + from t_worklist + where T_WorklistIsActive = 'Y' + order by T_WorklistName ASC + limit 0, {$max_rst}"; + $query = $this->db_smartone->query($sql); + + if ($query) { + $rows = $query->result_array(); + foreach ($rows as $k => $v) + $rows[$k]['data'] = json_decode($v['data']); + $result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows), "q" => $this->db_smartone->last_query()); + $this->sys_ok($result); + } + else { + $this->sys_error_db("worklist rows", $this->db_smartone); + exit; + } + } + + public function search_rerun() + { + $prm = $this->sys_input; + $id = $prm["detail_id"]; + + $sql = "CALL sp_process_result_rerun(?)"; + $query = $this->db_smartone->query($sql, [$id]); + + if ($query) + { + $rows = $query->result_array(); + $this->sys_ok(["records"=>$rows]); + } + else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + + + function getdoctorsfna() + { + $prm = $this->sys_input; + // $id = $prm["id"]; + + $sql = " SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY M_DoctorName ASC"; + //echo $sql; + $query = $this->db_smartone->query($sql); + + if ($query) + { + $rows = $query->result_array(); + $this->sys_ok(["records"=>$rows]); + } + else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + function getfnaresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT Other_FNADetailsID as xid, + Other_FNAT_OrderDetailID as orderdetail_id, + Other_FNADetailsCode as code, + Other_FNADetailsLabel as label, + Other_FNADetailsResult as result, + IFNULL(Other_FNAM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_FNAM_DoctorID) OR Other_FNAM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_fna + JOIN other_fnadetails ON Other_FNADetailsOther_FNAID = Other_FNAID AND Other_FNADetailsIsActive = 'Y' + LEFT JOIN m_doctor ON Other_FNAM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_FNAT_OrderDetailID = {$id} AND Other_FNAIsActive = 'Y' + GROUP BY Other_FNADetailsID + ORDER BY Other_FNADetailsCode ASC"; + $query = $this->db_smartone->query($sql); + + if ($query) + { + $rows = $query->result_array(); + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $images = array(); + $sql = "SELECT So_ImageUploadID as xid, + CONCAT('/one-media/one-image-nonlab/',So_ImageUploadNewName) as image_url + FROM t_orderdetail + JOIN so_imageupload ON So_ImageUploadT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND + So_ImageUploadIsActive = 'Y' + WHERE + T_OrderDetailID = {$id} AND + T_OrderDetailIsActive = 'Y' + GROUP BY So_ImageUploadID"; + $images = $this->db_smartone->query($sql)->result_array(); + + $rst = array('doctors'=>$doctors,'results'=>$rows,'images'=>$images); + $this->sys_ok(["records"=>$rst]); + } + else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + + function uploadimage(){ + if (! $this->isLogin) { + $this->sys_error("Invalid Token"); + exit; + } + + $userid = $this->sys_user["M_UserID"]; + $data = []; + //print_r($_SERVER); + + $prm = $this->sys_input; + $orderid = $this->input->post('orderid'); + $labnumber = $this->input->post('labnumber'); + $sql = "UPDATE so_imageupload SET + So_ImageUploadIsActive = 'N', + So_ImageUploadUserID = {$userid} + WHERE + So_ImageUploadT_OrderHeaderID = {$orderid}"; + //echo $sql; + $this->db_onedev->query($sql); + //$config['upload_path'] = 'assets/'; + + $path = '/home/one/project/one/one-media/one-image-nonlab/'; + //echo $path; + $config['upload_path'] = $path; + $config['allowed_types'] = 'jpg|jpeg|png|gif'; + + $config['max_size'] = '10000'; + $count = count($_FILES['files']['name']); + //echo $count; + $this->load->library('upload',$config); + + $error = []; + for($i=0;$i<$count;$i++){ + + + if(!empty($_FILES['files']['name'][$i])){ + + + + $_FILES['file']['name'] = $_FILES['files']['name'][$i]; + + $_FILES['file']['type'] = $_FILES['files']['type'][$i]; + + $_FILES['file']['tmp_name'] = $_FILES['files']['tmp_name'][$i]; + + $_FILES['file']['error'] = $_FILES['files']['error'][$i]; + + $_FILES['file']['size'] = $_FILES['files']['size'][$i]; + + + + $namex = $orderid.'-'.$labnumber.'-'.$this->generateRandomString(5); + //echo $namex; + + $config['file_name'] = $namex; + $this->upload->initialize($config); + //echo $config['file_name'] ; + + + + + + if($this->upload->do_upload('file')){ + + $uploadData = $this->upload->data(); + + $filename = $uploadData['file_name']; + //echo $filename; + + + $sql = "INSERT INTO so_imageupload ( + So_ImageUploadT_OrderHeaderID, + So_ImageUploadT_OrderHeaderLabNumber, + So_ImageUploadT_SampleTypeID, + So_ImageUploadOldName, + So_ImageUploadNewName, + So_ImageUploadCreated, + So_ImageUploadUserID + ) + VALUES( + {$orderid}, + '{$labnumber}', + '150', + '{$_FILES['files']['name'][$i]}', + '{$filename}', + NOW(), + {$userid} + + )"; + //echo $sql; + $this->db_onedev->query($sql); + $xlast_id = $this->db_onedev->insert_id(); + $data['totalFiles'][] = array('xid' => $xlast_id ,'image_url' => '/one-media/one-image-nonlab/'.$filename); + + } + else{ + $error = array('error' => $this->upload->display_errors()); + } + + } + + + + } + + $result = array("total" =>count( $data['totalFiles']), "records" => $data['totalFiles'],'errors'=>$error); + $this->sys_ok($result); + } + + + function getpatologianatomyresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT Other_PatologiAnatomyID as xid, + Other_PatologiAnatomyT_OrderDetailID as orderdetail_id, + Other_PatologiAnatomyNoSediaan as no_sediaan, + Other_PatologiAnatomyDiagnosaKlinis as diagnosa, + Other_PatologiAnatomyKeteranganKlinis as klinis, + Other_PatologiAnatomyLokasiOrgan as lokasi, + Other_PatologiAnatomyMakroskopik as makroskopik, + Other_PatologiAnatomyMikroskopik as mikroskopik, + Other_PatologiAnatomyKesimpulan as kesimpulan, + IFNULL(Other_PatologiAnatomyM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_PatologiAnatomyM_DoctorID) OR Other_PatologiAnatomyM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_patologi_anatomy + LEFT JOIN m_doctor ON Other_PatologiAnatomyM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_PatologiAnatomyT_OrderDetailID = {$id} AND Other_PatologiAnatomyIsActive = 'Y' + GROUP BY Other_PatologiAnatomyID + ORDER BY Other_PatologiAnatomyID ASC + LIMIT 1"; + $query = $this->db_smartone->query($sql); + + if ($query) + { + $rows = $query->row_array(); + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + + $rst = array('doctors'=>$doctors,'result'=>$rows); + $this->sys_ok(["records"=>$rst]); + } + else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + + + function generateRandomString($length = 10) { + $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; + $charactersLength = strlen($characters); + $randomString = ''; + for ($i = 0; $i < $length; $i++) { + $randomString .= $characters[rand(0, $charactersLength - 1)]; + } + return $randomString; + } + + function getcytologiresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT Other_CytologiDetailsID as xid, + Other_CytologiT_OrderDetailID as orderdetail_id, + Other_CytologiDetailsCode as code, + Other_CytologiDetailsLabel as label, + Other_CytologiDetailsResult as result, + IFNULL(Other_CytologiM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_CytologiM_DoctorID) OR Other_CytologiM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_cytologi + JOIN other_cytologidetails ON Other_CytologiDetailsOther_CytologiID = Other_CytologiID AND Other_CytologiDetailsIsActive = 'Y' + LEFT JOIN m_doctor ON Other_CytologiM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_CytologiT_OrderDetailID = {$id} AND Other_CytologiIsActive = 'Y' + GROUP BY Other_CytologiDetailsID + ORDER BY Other_CytologiDetailsCode ASC"; + //echo $sql; + $query = $this->db_smartone->query($sql); + + if ($query) + { + $rows = $query->result_array(); + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $rst = array('doctors'=>$doctors,'results'=>$rows); + $this->sys_ok(["records"=>$rst]); + } + else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + function getmikroresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT + Other_MikroID as xid, + Other_MikroHasilBiakan as hasil_biakan, + Other_MikroSampleTypeName as sample_name, + Other_MikroT_OrderDetailID as orderdetail_id, + Other_MikroResult as result_value, + '' as result_other, + IFNULL(T_BacteriaID,0) as T_BacteriaID, + IFNULL(T_BacteriaName,'') as T_BacteriaName, + '' as details, + IFNULL(Other_MikroM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_MikroM_DoctorID) OR Other_MikroM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_mikro + LEFT JOIN t_bacteria ON Other_MikroT_BacteriaID = T_BacteriaID + LEFT JOIN m_doctor ON Other_MikroM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_MikroT_OrderDetailID = {$id} AND Other_MikroIsActive = 'Y' + GROUP BY Other_MikroID"; + //echo $sql; + $query = $this->db_smartone->query($sql); + + if ($query) + { + $row = $query->row_array(); + if($row){ + if($row['result_value'] != 'Positif' && $row['result_value'] != 'Negatif'){ + $row['result_other'] = $row['result_value']; + $row['result_value'] = 'other'; + } + $sql = "SELECT '' as xno, + Other_MikroDetailsID as xid, + Other_MikroDetailsValue as value, + IF(Other_MikroDetailsNote = 'R','Y','N') as chx_r, + IF(Other_MikroDetailsNote = 'I','Y','N') as chx_i, + IF(Other_MikroDetailsNote = 'S','Y','N') as chx_s, + Other_MikroDetailsNote as note, + t_antibiotic.* + FROM other_mikrodetails + LEFT JOIN t_antibiotic ON Other_MikroDetailsT_AntibioticID = T_AntibioticID + WHERE + Other_MikroDetailsOther_MikroID = {$row['xid']} AND Other_MikroDetailsIsActive = 'Y' + GROUP BY Other_MikroDetailsID + ORDER BY T_AntibioticName ASC"; + //echo $sql; + $details = $this->db_smartone->query($sql)->result_array(); + if(details){ + foreach($details as $k => $v){ + $details[$k]['xno'] = $k + 1; + } + } + $row['details'] = $details; + } + else{ + $row = array('xid'=>'0','hasil_biakan' => '','result_value'=>'Negatif','sample_name' => '','orderdetail_id'=>$id, 'T_BacteriaID'=>'0','T_BacteriaName'=>'0','details'=>array(),'doctor_id'=>'0','doctor_name'=>'0'); + } + } + else{ + $row = array('xid'=>'0','hasil_biakan' => '','result_value'=>'Negatif','sample_name' => '','orderdetail_id'=>$id, 'T_BacteriaID'=>'0','T_BacteriaName'=>'0','details'=>array(),'doctor_id'=>'0','doctor_name'=>'0'); + } + //print_r($row); + + + + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 7 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $sql = " + SELECT '0' as id, 'Belum memilih bakteria' as name + UNION + SELECT T_BacteriaID as id, T_BacteriaName as name + FROM t_bacteria + WHERE + T_BacteriaIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $bacteries = $this->db_smartone->query($sql)->result_array(); + $rst = array('doctors'=>$doctors,'bacteries'=>$bacteries,'results'=>$row); + $this->sys_ok(["records"=>$rst]); + } + function getantibiotics(){ + $prm = $this->sys_input; + $id = $prm["id"]; + $sql = " SELECT '' as xno, + 0 as xid, + '' as hasil_biakan, + '' as sample_name, + 0 as value, + 'Y' as chx_r, + 'N' as chx_i, + 'N' as chx_s, + 'R' as note, + t_antibiotic.* + FROM t_antibiotic + WHERE + T_AntibioticT_BacteriaID = {$prm['id']} AND T_AntibioticIsActive= 'Y' + ORDER BY T_AntibioticName ASC"; + //echo $sql; + $rows = $this->db_smartone->query($sql)->result_array(); + if(rows){ + foreach($rows as $k => $v){ + $rows[$k]['xno'] = $k + 1; + } + } + + $this->sys_ok(["records"=>$rows]); + } + function getlcprepresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + $sql = " SELECT Other_LcprepDetailsID as xid, + Other_LcprepID as header_id, + Other_LcprepT_orderDetailID as orderdetail_id, + Other_LcprepDetailsCode as code, + Other_LcprepDetailsLabel as label, + Other_LcprepDetailsResult as result, + IFNULL(Other_LcprepM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_LcprepM_DoctorID) OR Other_LcprepM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_lcprep + JOIN other_lcprepdetails ON Other_LcprepDetailsOther_LcprepID = Other_LcprepID AND Other_LcprepDetailsIsActive = 'Y' + LEFT JOIN m_doctor ON Other_LcprepM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_LcprepT_orderDetailID = {$id} AND Other_LcprepIsActive = 'Y' + GROUP BY Other_LcprepDetailsOther_LcprepID, Other_LcprepDetailsCode + ORDER BY Other_LcprepDetailsCode ASC"; + //echo $sql; + $rows = $this->db_smartone->query($sql)->result_array(); + if(!$rows){ + $rows = array( + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'A', + 'label' => 'DESKRIPSI', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ), + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'B', + 'label' => 'KESIMPULAN', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ) + ); + } + + $header_id = $rows[0]['header_id']; + $sql = "SELECT IFNULL(Other_LcprepAdekuasiID,0) as xid, + Lcprep_AdekuasiID as id, + Lcprep_AdekuasiLabel as name, + IF(ISNULL(Other_LcprepAdekuasiID),'N',Other_LcprepAdekuasiChex) as chex + FROM lcprep_adekuasi + LEFT JOIN other_lcprepadekuasi ON Other_LcprepAdekuasiLcprep_AdekuasiID = Lcprep_AdekuasiID AND + Other_LcprepAdekuasiOther_LcprepID = {$header_id} AND + Other_LcprepAdekuasiIsActive = 'Y' + WHERE + Lcprep_AdekuasiIsActive = 'Y' + GROUP BY Lcprep_AdekuasiID + ORDER BY Lcprep_AdekuasiOrder ASC + "; + //echo $sql; + $adeakuasi = $this->db_smartone->query($sql)->result_array(); + foreach($adeakuasi as $kc => $vc){ + $adeakuasi[$kc]['chex'] = $vc['chex'] == 'N'?false:true; + } + + $sql = "SELECT IFNULL(Other_LcprepKategoriUmumID,0) as xid, + Lcprep_KategoriUmumID as id, + Lcprep_KategoriUmumLabel as name, + IF(ISNULL(Other_LcprepKategoriUmumID),'N',Other_LcprepKategoriUmumChex) as chex + FROM lcprep_kategoriumum + LEFT JOIN other_lcprepkategoriumum ON Other_LcprepKategoriUmumLcprep_KategoriUmumID = Lcprep_KategoriUmumID AND + Other_LcprepKategoriUmumOther_LcprepID = {$header_id} AND + Other_LcprepKategoriUmumIsActive = 'Y' + WHERE + Lcprep_KategoriUmumIsActive = 'Y' + GROUP BY Lcprep_KategoriUmumID + "; + //echo $sql; + $kategoriumum = $this->db_smartone->query($sql)->result_array(); + foreach($kategoriumum as $kc => $vc){ + $kategoriumum[$kc]['chex'] = $vc['chex'] == 'N'?false:true; + } + + $sql = " + SELECT Lcprep_InterpretasiGroupID as group_id, + Lcprep_InterpretasiGroupName as group_name, + '' as subgroups + FROM lcprep_interpretasigroup + WHERE + Lcprep_InterpretasiGroupIsActive = 'Y' + "; + //echo $sql; + $interpretasi = $this->db_smartone->query($sql)->result_array(); + foreach($interpretasi as $k => $v){ + $subgroups = array(); + $sql = "SELECT Lcprep_InterpretasiSubgroupID as subgroup_id, + Lcprep_InterpretasiSubgroupName as subgroup_name, + '' as childs + FROM lcprep_interpretasisubgroup + WHERE + Lcprep_InterpretasiSubgroupLcprep_InterpretasiGroupID = {$v['group_id']} AND Lcprep_InterpretasiSubgroupIsActive = 'Y'"; + //echo $sql; + $subgroups = $this->db_smartone->query($sql)->result_array(); + if(count($subgroups) > 0){ + foreach($subgroups as $ki => $vi){ + $childs = array(); + $sql = "SELECT IFNULL(Other_LcprepInterpretasiID,0) as xid, + IFNULL(Other_LcprepInterpretasiChex,'N') as chex, + IFNULL(Other_LcprepInterpretasiValue,'') as value, + Lcprep_InterpretasiID as id, + Lcprep_InterpretasiLcprep_InterpretasiSubgroupID as subgroup_id, + Lcprep_InterpretasiCode as code, + Lcprep_InterpretasiName as name, + Lcprep_InterpretasiParentID as parent_id, + Lcprep_InterpretasiIsParent as is_parent, + Lcprep_InterpretasiHasResult as has_result, + Lcprep_InterpretasiTypeResult as type_result + FROM lcprep_interpretasi + LEFT JOIN other_lcprepinterpretasi ON Other_LcprepInterpretasiOther_LcprepID = {$header_id} AND + Other_LcprepInterpretasiLcprep_InterpretasiID = Lcprep_InterpretasiID AND + Other_LcprepInterpretasiIsActive = 'Y' + WHERE + Lcprep_InterpretasiLcprep_InterpretasiSubgroupID = {$vi['subgroup_id']} AND Lcprep_InterpretasiIsActive = 'Y' + GROUP BY Lcprep_InterpretasiID Order BY Lcprep_InterpretasiCode ASC"; + $childs = $this->db_smartone->query($sql)->result_array(); + if($childs){ + foreach($childs as $kc => $vc){ + $childs[$kc]['chex'] = $vc['chex'] == 'N'?false:true; + } + } + $subgroups[$ki]['childs'] = $childs; + } + } + + $interpretasi[$k]['subgroups'] = $subgroups; + } + + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $rst = array('doctors'=>$doctors,'results'=>$rows,'adekuasi'=>$adeakuasi,'kategoriumum'=>$kategoriumum,'interpretasi'=>$interpretasi); + $this->sys_ok(["records"=>$rst]); + } + + function getpapsmearresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT Other_PapSmearDetailsID as xid, + Other_PapSmearID as header_id, + Other_PapSmearT_OrderDetailID as orderdetail_id, + Other_PapSmearDetailsCode as code, + Other_PapSmearDetailsLabel as label, + Other_PapSmearDetailsResult as result, + IFNULL(Other_PapSmearM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_PapSmearM_DoctorID) OR Other_PapSmearM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_papsmear + JOIN other_papsmeardetails ON Other_PapSmearDetailsOther_PapSmearID = Other_PapSmearID AND Other_PapSmearDetailsIsActive = 'Y' + LEFT JOIN m_doctor ON Other_PapSmearM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_PapSmearT_OrderDetailID = {$id} AND Other_PapSmearIsActive = 'Y' + GROUP BY Other_PapSmearDetailsID + ORDER BY Other_PapSmearDetailsCode ASC"; + //echo $sql; + $rows = $this->db_smartone->query($sql)->result_array(); + if(!$rows){ + $rows = array( + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'A', + 'label' => 'Makroskopik', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ), + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'B', + 'label' => 'Mikroskopik', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ), + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'C', + 'label' => 'Kesimpulan', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ) + ); + } + + $header_id = $rows[0]['header_id']; + $sql = "SELECT Other_PapSmearMaturasiID as xid, + Other_PapSmearMaturasiValue as value + FROM other_papsmearmaturasi + WHERE + Other_PapSmearMaturasiOther_PapSmearID = {$header_id} AND + Other_PapSmearMaturasiIsActive = 'Y' + "; + //echo $sql; + $dt_maturasi = $this->db_smartone->query($sql)->row_array(); + if(!$dt_maturasi){ + $maturasi = array('xid'=>'0','value'=> array('','','')); + } + else{ + $value = explode('/',$dt_maturasi['value']); + $maturasi = array('xid'=>$dt_maturasi['xid'],'value'=> $value); + } + + $sql = "SELECT IFNULL(Other_PapSmearBahanID,0) as xid, + M_PapSmearBahanID as bahan_id, + M_PapSmearBahanName as name, + IF(ISNULL(Other_PapSmearBahanID),'N','Y') as selected + FROM m_papsmearbahan + LEFT JOIN other_papsmearbahan ON Other_PapSmearBahanM_PapSmearBahanID = M_PapSmearBahanID AND + Other_PapSmearBahanOther_PapSmearID = {$header_id} AND + Other_PapSmearBahanIsActive = 'Y' + WHERE + M_PapSmearBahanIsActive = 'Y' + ORDER BY M_PapSmearBahanID ASC + "; + //echo $sql; + $bahans = $this->db_smartone->query($sql)->result_array(); + + $sql = "SELECT IFNULL(Other_PapsmearCategoryID,0) as xid, + M_PapSmearCategoryID as category_id, + M_PapSmearCategoryName as name, + IF(ISNULL(Other_PapsmearCategoryID),'N','Y') as selected + FROM m_papsmearcategory + LEFT JOIN other_papsmearcategory ON Other_PapsmearCategoryM_PapSmearCategoryID = M_PapSmearCategoryID AND + Other_PapsmearCategoryOther_PapSmearID = {$header_id} AND + Other_PapsmearCategoryIsActive = 'Y' + WHERE + M_PapSmearCategoryIsActive = 'Y' + ORDER BY M_PapSmearCategoryID ASC + "; + //echo $sql; + $categories = $this->db_smartone->query($sql)->result_array(); + + $sql = "SELECT IFNULL(Other_PapSmearCheckID,0) as xid, + M_PapSmearCheckID as check_id, + M_PapSmearCheckLabel as name, + IF(ISNULL(Other_PapSmearCheckID),'N','Y') as selected, + Other_PapSmearCheckNote as note + FROM m_papsmearcheck + LEFT JOIN other_papsmearcheck ON Other_PapSmearCheckM_PapSmearCheckID = M_PapSmearCheckID AND + Other_PapSmearCheckOther_PapSmearID = {$header_id} AND + Other_PapSmearCheckIsActive = 'Y' + WHERE + M_PapSmearCheckIsActive = 'Y' + ORDER BY M_PapSmearCheckCode ASC + "; + $checks = $this->db_smartone->query($sql)->result_array(); + + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $rst = array('doctors'=>$doctors,'checks'=>$checks,'bahans'=>$bahans,'categories'=>$categories,'maturasi'=>$maturasi,'results'=>$rows); + $this->sys_ok(["records"=>$rst]); + + } + + function saveresult_lcprep() + { + $prm = $this->sys_input; + $detail_id = $prm['detail_id']; + $doctor_id = $prm['doctor']; + $adekuasi = $prm['adekuasi']; + $kategoriumum = $prm['kategoriumum']; + $interpretasi = $prm['interpretasi']; + $results = $prm['results']; + + $userid = $this->sys_user['M_UserID']; + + $header_id = 0; + $sql = "SELECT * FROM other_lcprep WHERE Other_LcprepT_orderDetailID = {$detail_id} AND Other_LcprepIsActive = 'Y'"; + $dt_header = $this->db_smartone->query($sql)->row_array(); + if($dt_header){ + $header_id = $dt_header['Other_LcprepID']; + } + if($header_id == 0){ + $sql = "INSERT INTO other_lcprep( + Other_LcprepT_orderDetailID, + Other_LcprepM_DoctorID, + Other_LcprepUserID, + Other_LcprepCreated + ) + VALUES( + {$detail_id}, + {$doctor_id}, + {$userid}, + NOW() + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + }else{ + $sql = "UPDATE other_lcprep SET Other_LcprepM_DoctorID = {$doctor_id}, Other_LcprepUserID = {$userid} WHERE Other_LcprepID = {$header_id}"; + $this->db_smartone->query($sql); + } + + if($adekuasi){ + foreach($adekuasi as $k =>$v){ + $selected = $v['chex']?'Y':'N'; + if(intval($v['xid'] == 0)){ + $sql = "UPDATE other_lcprepadekuasi SET Other_LcprepAdekuasiIsActive = 'N' + WHERE + Other_LcprepAdekuasiOther_LcprepID = {$header_id} AND + Other_LcprepAdekuasiIsActive = 'Y' AND + Other_LcprepAdekuasiLcprep_AdekuasiID = {$v['id']}"; + $this->db_smartone->query($sql); + $sql = "INSERT INTO other_lcprepadekuasi ( + Other_LcprepAdekuasiOther_LcprepID, + Other_LcprepAdekuasiLcprep_AdekuasiID, + Other_LcprepAdekuasiChex, + Other_LcprepAdekuasiUserID, + Other_LcprepAdekuasiCreated + ) + VALUES( + {$header_id}, + {$v['id']}, + '{$selected}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + //echo $sql; + } + if(intval($v['xid'] != 0)){ + + $sql = "UPDATE other_lcprepadekuasi SET + Other_LcprepAdekuasiChex = '{$selected}', + Other_LcprepAdekuasiUserID = {$userid} + WHERE + Other_LcprepAdekuasiID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + + //echo $sql; + } + } + + if($kategoriumum){ + foreach($kategoriumum as $k =>$v){ + $selected = $v['chex']?'Y':'N'; + if(intval($v['xid'] == 0)){ + $sql = "UPDATE other_lcprepkategoriumum SET Other_LcprepKategoriUmumIsActive = 'N' + WHERE + Other_LcprepKategoriUmumOther_LcprepID = {$header_id} AND + Other_LcprepKategoriUmumLcprep_KategoriUmumID = {$v['id']} AND + Other_LcprepKategoriUmumIsActive = 'Y' + "; + $this->db_smartone->query($sql); + $sql = "INSERT INTO other_lcprepkategoriumum ( + Other_LcprepKategoriUmumOther_LcprepID, + Other_LcprepKategoriUmumLcprep_KategoriUmumID, + Other_LcprepKategoriUmumChex, + Other_LcprepKategoriUmumUserID, + Other_LcprepKategoriUmumCreated + ) + VALUES( + {$header_id}, + {$v['id']}, + '{$selected}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if(intval($v['xid'] != 0)){ + $sql = "UPDATE other_lcprepkategoriumum SET + Other_LcprepKategoriUmumChex = '{$selected }', + Other_LcprepKategoriUmumUserID = {$userid} + WHERE + Other_LcprepKategoriUmumID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + + //echo $sql; + } + } + + if($results){ + foreach($results as $k =>$v){ + if(intval($v['xid'] == 0)){ + $sql = "UPDATE other_lcprepdetails SET Other_LcprepDetailsIsActive = 'N' + WHERE + Other_LcprepDetailsOther_LcprepID = {$header_id} AND + Other_LcprepDetailsCode = '{$v['code']}' AND + Other_LcprepDetailsIsActive = 'Y'"; + $this->db_smartone->query($sql); + $sql = "INSERT INTO other_lcprepdetails ( + Other_LcprepDetailsOther_LcprepID, + Other_LcprepDetailsCode, + Other_LcprepDetailsLabel, + Other_LcprepDetailsResult, + Other_LcprepDetailsUserID, + Other_LcprepDetailsCreated + ) + VALUES( + {$header_id}, + '{$v['code']}', + '{$v['label']}', + '{$v['result']}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if(intval($v['xid'] != 0)){ + $sql = "UPDATE other_lcprepdetails SET + Other_LcprepDetailsCode = '{$v['code']}', + Other_LcprepDetailsLabel = '{$v['label']}', + Other_LcprepDetailsResult = '{$v['result']}', + Other_LcprepDetailsUserID = {$userid} + WHERE + Other_LcprepDetailsID = {$v['xid']}"; + $this->db_smartone->query($sql); + + } + //echo $sql; + } + } + + if($interpretasi){ + foreach($interpretasi as $k =>$v){ + if(count($v['subgroups']) > 0){ + foreach($v['subgroups'] as $ik => $iv){ + if(count($iv['childs']) > 0){ + foreach($iv['childs'] as $iik => $iiv){ + if(intval($iiv['xid'] == 0)){ + $chex = $iiv['chex'] ? 'Y':'N'; + $sql = "UPDATE other_lcprepinterpretasi SET Other_LcprepInterpretasiIsActive = 'N' + WHERE + Other_LcprepInterpretasiOther_LcprepID = {$header_id} AND + Other_LcprepInterpretasiLcprep_InterpretasiID = '{$iiv['id']}' AND + Other_LcprepInterpretasiIsActive = 'Y'"; + $this->db_smartone->query($sql); + $sql = "INSERT INTO other_lcprepinterpretasi ( + Other_LcprepInterpretasiOther_LcprepID, + Other_LcprepInterpretasiLcprep_InterpretasiID, + Other_LcprepInterpretasiChex, + Other_LcprepInterpretasiValue, + Other_LcprepInterpretasiUserID, + Other_LcprepInterpretasiCreated + ) + VALUES( + {$header_id}, + '{$iiv['id']}', + '{$chex}', + '{$iiv['value']}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + + if(intval($iiv['xid'] != 0)){ + $chex = $iiv['chex'] ? 'Y':'N'; + $sql = "UPDATE other_lcprepinterpretasi SET + Other_LcprepInterpretasiChex = '{$chex}', + Other_LcprepInterpretasiValue = '{$iiv['value']}', + Other_LcprepInterpretasiUserID = {$userid} + WHERE + Other_LcprepInterpretasiID = {$iiv['xid']}"; + $this->db_smartone->query($sql); + //echo $sql; + + } + + } + } + } + } + //echo $sql; + } + } + + + $result = array("total" => 1, "records" => array(), "sql"=> ''); + $this->sys_ok($result); + exit; + } + + function saveresult_papsmear() + { + $prm = $this->sys_input; + $detail_id = $prm['detail_id']; + $doctor_id = $prm['doctor']; + $checks = $prm['checks']; + $maturasi = $prm['maturasi']; + $bahans = $prm['bahans']; + $categories = $prm['categories']; + $results = $prm['results']; + + $userid = $this->sys_user['M_UserID']; + + $header_id = 0; + $sql = "SELECT * FROM other_papsmear WHERE Other_PapSmearT_OrderDetailID = {$detail_id} AND Other_PapSmearIsActive = 'Y'"; + $dt_header = $this->db_smartone->query($sql)->row_array(); + if($dt_header){ + $header_id = $dt_header['Other_PapSmearID']; + } + if($header_id == 0){ + $sql = "INSERT INTO other_papsmear( + Other_PapSmearT_OrderDetailID, + Other_PapSmearM_DoctorID, + Other_PapSmearUserID, + Other_PapSmearCreated + ) + VALUES( + {$detail_id}, + {$doctor_id}, + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } + else{ + $sql = "UPDATE other_papsmear SET Other_PapSmearM_DoctorID = {$doctor_id}, Other_PapSmearUserID = {$userid} WHERE Other_PapSmearID = {$header_id}"; + $this->db_smartone->query($sql); + } + + if($checks){ + foreach($checks as $k =>$v){ + if(intval($v['xid']) == 0 && $v['selected'] === 'Y'){ + $sql = "INSERT INTO other_papsmearcheck ( + Other_PapSmearCheckOther_PapSmearID, + Other_PapSmearCheckM_PapSmearCheckID, + Other_PapSmearCheckNote, + Other_PapSmearCheckUserID, + Other_PapSmearCheckCreated + ) + VALUES( + {$header_id}, + {$v['check_id']}, + '{$v['note']}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if(intval($v['xid']) != 0 && $v['selected'] === 'N'){ + $sql = "UPDATE other_papsmearcheck SET + Other_PapSmearCheckIsActive = 'N', + Other_PapSmearCheckUserID = {$userid} + WHERE + Other_PapSmearCheckID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + if(intval($v['xid']) != 0 && $v['selected'] === 'Y'){ + $sql = "UPDATE other_papsmearcheck SET + Other_PapSmearCheckNote = '{$v['note']}', + Other_PapSmearCheckUserID = {$userid} + WHERE + Other_PapSmearCheckID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + //echo $sql; + } + } + + if($maturasi){ + if(intval($maturasi['xid']) == 0){ + $value = join("/",$maturasi['value']); + $sql = "INSERT INTO other_papsmearmaturasi ( + Other_PapSmearMaturasiOther_PapSmearID, + Other_PapSmearMaturasiValue, + Other_PapSmearMaturasiUserID, + Other_PapSmearMaturasiCreated + ) + VALUE( + {$header_id}, + '{$value}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + //echo $sql; + } + if(intval($maturasi['xid']) != 0){ + $value = join("/",$maturasi['value']); + $sql = "UPDATE other_papsmearmaturasi SET + Other_PapSmearMaturasiValue = '{$value}', + Other_PapSmearMaturasiUserID = {$userid} + WHERE + Other_PapSmearMaturasiID = {$maturasi['xid']}"; + // echo $sql; + $this->db_smartone->query($sql); + } + } + + if($bahans){ + foreach($bahans as $k =>$v){ + if(intval($v['xid']) == 0 && $v['selected'] === 'Y'){ + $sql = "INSERT INTO other_papsmearbahan ( + Other_PapSmearBahanOther_PapSmearID, + Other_PapSmearBahanM_PapSmearBahanID, + Other_PapSmearBahanUserID, + Other_PapSmearBahanCreated + ) + VALUES( + {$header_id}, + {$v['bahan_id']}, + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if(intval($v['xid']) != 0 && $v['selected'] === 'N'){ + $sql = "UPDATE other_papsmearbahan SET + Other_PapSmearBahanIsActive = 'N', + Other_PapsmearCategoryUserID = {$userid} + WHERE + Other_PapSmearBahanID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + if(intval($v['xid']) != 0 && $v['selected'] === 'Y'){ + $sql = "UPDATE other_papsmearbahan SET + Other_PapSmearBahanIsActive = 'Y', + Other_PapsmearCategoryUserID = {$userid} + WHERE + Other_PapSmearBahanID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + //echo $sql; + } + } + + if($categories){ + foreach($categories as $k =>$v){ + if(intval($v['xid']) == 0 && $v['selected'] === 'Y'){ + $sql = "INSERT INTO other_papsmearcategory ( + Other_PapsmearCategoryOther_PapSmearID, + Other_PapsmearCategoryM_PapSmearCategoryID, + Other_PapsmearCategoryUserID, + Other_PapsmearCategoryCreated + ) + VALUES( + {$header_id}, + {$v['category_id']}, + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if(intval($v['xid']) != 0 && $v['selected'] === 'N'){ + $sql = "UPDATE other_papsmearcategory SET + Other_PapsmearCategoryIsActive = 'N', + Other_PapsmearCategoryUserID = {$userid} + WHERE + Other_PapsmearCategoryID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + //echo $sql; + if(intval($v['xid']) != 0 && $v['selected'] === 'Y'){ + $sql = "UPDATE other_papsmearcategory SET + Other_PapsmearCategoryIsActive = 'Y', + Other_PapsmearCategoryUserID = {$userid} + WHERE + Other_PapsmearCategoryID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + } + } + + if($results){ + foreach($results as $k =>$v){ + if(intval($v['xid']) == 0){ + $sql = "INSERT INTO other_papsmeardetails ( + Other_PapSmearDetailsOther_PapSmearID, + Other_PapSmearDetailsCode, + Other_PapSmearDetailsLabel, + Other_PapSmearDetailsResult, + Other_PapSmearDetailsUserID, + Other_PapSmearDetailsCreated + ) + VALUES( + {$header_id}, + '{$v['code']}', + '{$v['label']}', + '{$v['result']}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if(intval($v['xid']) != 0){ + $sql = "UPDATE other_papsmeardetails SET + Other_PapSmearDetailsCode = '{$v['code']}', + Other_PapSmearDetailsLabel = '{$v['label']}', + Other_PapSmearDetailsResult = '{$v['result']}', + Other_PapSmearDetailsUserID = {$userid} + WHERE + Other_PapSmearDetailsID = {$v['xid']}"; + $this->db_smartone->query($sql); + + } + //echo $sql; + } + } + + $result = array("total" => 1, "records" => array(), "sql"=> ''); + $this->sys_ok($result); + exit; + } + + function saveresult_fna() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = $inp['doctor']; + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + if($prm[0]['xid'] == '0'){ + $sql = "INSERT INTO other_fna( + Other_FNAM_DoctorID, + Other_FNAT_OrderDetailID, + Other_FNAUserID, + Other_FNACreated + ) + VALUES( + {$doctor_id}, + {$prm[0]['orderdetail_id']}, + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } + else{ + $sql = "SELECT * FROM other_fna WHERE Other_FNAT_OrderDetailID = {$prm[0]['orderdetail_id']} AND Other_FNAIsActive = 'Y'"; + $data_header = $this->db_smartone->query($sql)->row_array(); + $header_id = $data_header['Other_FNAID']; + $sql = "UPDATE other_fna SET + Other_FNAM_DoctorID = {$doctor_id}, + Other_FNAUserID = {$userid} + WHERE + Other_FNAID = {$header_id}"; + $this->db_smartone->query($sql); + } + foreach($prm as $k => $v){ + if($v['xid'] == '0'){ + $results = str_replace("'", "\\'", $v['result']); + $sql = "INSERT INTO other_fnadetails( + Other_FNADetailsOther_FNAID , + Other_FNADetailsCode, + Other_FNADetailsLabel, + Other_FNADetailsResult, + Other_FNADetailsCreated, + Other_FNADetailsUserID + ) + VALUES( + {$header_id}, + '{$v['code']}', + '{$v['label']}', + '{$results}', + NOW(), + {$userid} + )"; + $query = $this->db_smartone->query($sql); + } + else{ + $results = str_replace("'", "\\'", $v['result']); + $sql = "UPDATE other_fnadetails SET + Other_FNADetailsResult = '{$results}', + Other_FNADetailsUserID = {$userid} + WHERE + Other_FNADetailsID = {$v['xid']}"; + $query = $this->db_smartone->query($sql); + } + } + + $result = array("total" => 1, "records" => array(), "sql"=> ''); + $this->sys_ok($result); + exit; + } + + function saveresult_cytologi() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = $inp['doctor']; + + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + if($prm[0]['xid'] == '0'){ + $sql = "INSERT INTO other_cytologi( + Other_CytologiT_OrderDetailID, + Other_CytologiM_DoctorID, + Other_CytologiUserID, + Other_CytologiCreated + ) + VALUES( + {$prm[0]['orderdetail_id']}, + {$doctor_id}, + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } + else{ + $sql = "SELECT * FROM other_cytologi WHERE Other_CytologiT_OrderDetailID = {$prm[0]['orderdetail_id']} AND Other_CytologiIsActive = 'Y'"; + $data_header = $this->db_smartone->query($sql)->row_array(); + $header_id = $data_header['Other_CytologiID']; + $sql = "UPDATE other_cytologi SET + Other_CytologiM_DoctorID = {$doctor_id}, + Other_CytologiUserID = {$userid} + WHERE + Other_CytologiID = {$header_id}"; + $this->db_smartone->query($sql); + } + foreach($prm as $k => $v){ + if($v['xid'] == '0'){ + $results = str_replace("'", "\\'", $v['result']); + $sql = "INSERT INTO other_cytologidetails( + Other_CytologiDetailsOther_CytologiID , + Other_CytologiDetailsCode, + Other_CytologiDetailsLabel, + Other_CytologiDetailsResult, + Other_CytologiDetailsCreated, + Other_CytologiDetailsUserID + ) + VALUES( + {$header_id}, + '{$v['code']}', + '{$v['label']}', + '{$results}', + NOW(), + {$userid} + )"; + $query = $this->db_smartone->query($sql); + } + else{ + $results = str_replace("'", "\\'", $v['result']); + $sql = "UPDATE other_cytologidetails SET + Other_CytologiDetailsResult = '{$results}', + Other_CytologiDetailsUserID = {$userid} + WHERE + Other_CytologiDetailsID = {$v['xid']}"; + $query = $this->db_smartone->query($sql); + } + } + + $result = array("total" => 1, "records" => array(), "sql"=> ''); + $this->sys_ok($result); + exit; + } + + function saveresult_mikro() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = $inp['doctor']; + $backteria_id = $inp['bacteria']; + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + + if($inp['result_value'] != 'Negatif' && $inp['result_value'] != 'Positif'){ + $prm['result_value'] = $prm['result_other']; + } + else{ + $prm['result_value'] = $inp['result_value']; + } + + if($prm['xid'] == '0'){ + $sql = "INSERT INTO other_mikro( + Other_MikroM_DoctorID, + Other_MikroResult, + Other_MikroT_BacteriaID, + Other_MikroT_OrderDetailID, + Other_MikroHasilBiakan, + Other_MikroSampleTypeName, + Other_MikroUserID, + Other_MikroCreated + ) + VALUES( + {$doctor_id}, + '{$prm['result_value']}', + {$backteria_id}, + {$prm['orderdetail_id']}, + '{$prm['hasil_biakan']}', + '{$prm['sample_name']}', + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } + else{ + $sql = "SELECT * FROM other_mikro WHERE Other_MikroT_OrderDetailID = {$prm['orderdetail_id']} AND Other_MikroIsActive = 'Y'"; + $data_header = $this->db_smartone->query($sql)->row_array(); + $header_id = $data_header['Other_MikroID']; + $sql = "UPDATE other_mikro SET + Other_MikroResult = '{$prm['result_value']}', + Other_MikroM_DoctorID = {$doctor_id}, + Other_MikroT_BacteriaID = {$backteria_id}, + Other_MikroHasilBiakan = '{$prm['hasil_biakan']}', + Other_MikroSampleTypeName = '{$prm['sample_name']}', + Other_MikroUserID = {$userid} + WHERE + Other_MikroID = {$header_id}"; + //echo $sql; + $this->db_smartone->query($sql); + } + + + + $sql = "UPDATE other_mikrodetails SET Other_MikroDetailsIsActive = 'N', Other_MikroDetailsUserID = 0 WHERE Other_MikroDetailsOther_MikroID = {$header_id}"; + $this->db_smartone->query($sql); + + $results = $prm['details']; + if($inp['result_value'] == 'Positif'){ + foreach($results as $k => $v){ + if($v['xid'] == '0'){ + $sql = "INSERT INTO other_mikrodetails( + Other_MikroDetailsOther_MikroID , + Other_MikroDetailsT_AntibioticID, + Other_MikroDetailsValue, + Other_MikroDetailsNote, + Other_MikroDetailsCreated, + Other_MikroDetailsUserID + ) + VALUES( + {$header_id}, + '{$v['T_AntibioticID']}', + '{$v['value']}', + '{$v['note']}', + NOW(), + {$userid} + )"; + $query = $this->db_smartone->query($sql); + } + else{ + $sql = "UPDATE other_mikrodetails SET + Other_MikroDetailsT_AntibioticID = '{$v['T_AntibioticID']}', + Other_MikroDetailsValue = '{$v['value']}', + Other_MikroDetailsNote = '{$v['note']}', + Other_MikroDetailsIsActive = 'Y', + Other_MikroDetailsUserID = {$userid} + WHERE + Other_MikroDetailsID = {$v['xid']}"; + //echo $sql; + $query = $this->db_smartone->query($sql); + } + } + } + + + $result = array("total" => 1, "records" => array(), "sql"=> ''); + $this->sys_ok($result); + exit; + } + + + function get_doctors_preparasi_sperma() + { + $prm = $this->sys_input; + // $id = $prm["id"]; + + $sql = " SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 10 AND + M_DoctorSOIsActive = 'Y' + ORDER BY M_DoctorName ASC"; + //echo $sql; + $query = $this->db_smartone->query($sql); + $rows = $query->result_array(); + $sql = " + SELECT '0' as id, 'Belum memilih metode' as name + UNION + SELECT M_MethodeSpermaID as id, M_MethodeSpermaName as name + FROM m_methodesperma + WHERE + M_MethodeSpermaIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $methodes = $this->db_smartone->query($sql)->result_array(); + + + $this->sys_ok(["records"=>$rows,"methodes"=>$methodes]); + + } + + + function getpreparasispermaresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT other_preparasisperma.*, + Other_PreparasiSpermaID as xid, + Other_PreparasiSpermaT_OrderDetailID as orderdetail_id, + IFNULL(Other_PreparasiSpermaM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_PreparasiSpermaM_DoctorID) OR Other_PreparasiSpermaM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name, + IFNULL(M_MethodeSpermaID,0) as methode_id, + IFNULL(M_MethodeSpermaName,'') as methode_name + FROM other_preparasisperma + LEFT JOIN m_doctor ON Other_PreparasiSpermaM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + LEFT JOIN m_methodesperma ON Other_PreparasiSpermaM_MethodeSpermaID = M_MethodeSpermaID AND + M_MethodeSpermaIsActive = 'Y' + WHERE + Other_PreparasiSpermaT_OrderDetailID = {$id} AND Other_PreparasiSpermaIsActive = 'Y' + GROUP BY Other_PreparasiSpermaID"; + $query = $this->db_smartone->query($sql); + + if ($query) + { + $rows = $query->row_array(); + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 10 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $sql = " + SELECT '0' as id, 'Belum memilih metode' as name + UNION + SELECT M_MethodeSpermaID as id, M_MethodeSpermaName as name + FROM m_methodesperma + WHERE + M_MethodeSpermaIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $methodes = $this->db_smartone->query($sql)->result_array(); + $images = array(); + $sql = "SELECT Other_PreparasiSpermaImgID as xid, + Other_PreparasiSpermaImgType as type, + CONCAT('/one-media/one-image-nonlab/',Other_PreparasiSpermaImgNewName) as image_url + FROM t_orderdetail + JOIN other_preparasisperma_img ON Other_PreparasiSpermaImgT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND + Other_PreparasiSpermaImgIsActive = 'Y' + WHERE + T_OrderDetailID = {$id} AND + T_OrderDetailIsActive = 'Y' + GROUP BY Other_PreparasiSpermaImgID"; + //echo $sql; + $images = $this->db_smartone->query($sql)->result_array(); + + $rst = array('doctors'=>$doctors,'methodes'=>$methodes,'results'=>$rows,'images'=>$images); + $this->sys_ok(["records"=>$rst]); + } + else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + + function uploadimage_preparasi_sperma(){ + if (! $this->isLogin) { + $this->sys_error("Invalid Token"); + exit; + } + + $userid = $this->sys_user["M_UserID"]; + $data = []; + //print_r($_SERVER); + + $prm = $this->sys_input; + $orderid = $this->input->post('orderid'); + $type = $this->input->post('type'); + $labnumber = $this->input->post('labnumber'); + $sql = "UPDATE other_preparasisperma_img SET + Other_PreparasiSpermaImgIsActive = 'N', + Other_PreparasiSpermaImgUserID = {$userid} + WHERE + Other_PreparasiSpermaImgT_OrderHeaderID = {$orderid} AND + Other_PreparasiSpermaImgType = '{$type}'"; + //echo $sql; + $this->db_onedev->query($sql); + //$config['upload_path'] = 'assets/'; + + $path = '/home/one/project/one/one-media/one-image-nonlab/'; + //echo $path; + $config['upload_path'] = $path; + $config['allowed_types'] = 'jpg|jpeg|png|gif'; + + $config['max_size'] = '10000'; + $count = count($_FILES['files']['name']); + //echo $count; + $this->load->library('upload',$config); + + $error = []; + for($i=0;$i<$count;$i++){ + + + if(!empty($_FILES['files']['name'][$i])){ + + + + $_FILES['file']['name'] = $_FILES['files']['name'][$i]; + + $_FILES['file']['type'] = $_FILES['files']['type'][$i]; + + $_FILES['file']['tmp_name'] = $_FILES['files']['tmp_name'][$i]; + + $_FILES['file']['error'] = $_FILES['files']['error'][$i]; + + $_FILES['file']['size'] = $_FILES['files']['size'][$i]; + + + + $namex = $orderid.'-'.$labnumber.'-'.$this->generateRandomString(5); + //echo $namex; + + $config['file_name'] = $namex; + $this->upload->initialize($config); + //echo $config['file_name'] ; + + + + + + if($this->upload->do_upload('file')){ + + $uploadData = $this->upload->data(); + + $filename = $uploadData['file_name']; + //echo $filename; + + + $sql = "INSERT INTO other_preparasisperma_img ( + Other_PreparasiSpermaImgT_OrderHeaderID, + Other_PreparasiSpermaImgType, + Other_PreparasiSpermaImgOldName, + Other_PreparasiSpermaImgNewName, + Other_PreparasiSpermaImgCreated, + Other_PreparasiSpermaImgUserID + ) + VALUES( + {$orderid}, + '{$type}', + '{$_FILES['files']['name'][$i]}', + '{$filename}', + NOW(), + {$userid} + + )"; + //echo $sql; + $this->db_onedev->query($sql); + $xlast_id = $this->db_onedev->insert_id(); + $data['totalFiles'][] = array('xid' => $xlast_id ,'type'=>$type,'image_url' => '/one-media/one-image-nonlab/'.$filename); + + } + else{ + $error = array('error' => $this->upload->display_errors()); + } + + } + + + + } + + $result = array("total" =>count( $data['totalFiles']), "records" => $data['totalFiles'],'errors'=>$error); + $this->sys_ok($result); + } + + + function saveresult_preparasi_sperma() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = $inp['doctor']; + $orderdetail_id = $inp['orderdetailid']; + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + if($prm['xid'] == '0'){ + $sql = "INSERT INTO other_preparasisperma( + Other_PreparasiSpermaM_DoctorID, + Other_PreparasiSpermaT_OrderDetailID, + Other_PreparasiSpermaPreMotilitasA, + Other_PreparasiSpermaPreMotilitasB, + Other_PreparasiSpermaPreMotilitasC, + Other_PreparasiSpermaPreKonsentrasi, + Other_PreparasiSpermaPreKontaminan, + Other_PreparasiSpermaPostMotilitasA, + Other_PreparasiSpermaPostMotilitasB, + Other_PreparasiSpermaPostMotilitasC, + Other_PreparasiSpermaPostKonsentrasi, + Other_PreparasiSpermaPostKontaminan, + Other_PreparasiSpermaPreVolume, + Other_PreparasiSpermaPostVolume, + Other_PreparasiSpermaM_MethodeSpermaID, + Other_PreparasiSpermaNote, + Other_PreparasiSpermaUserID, + Other_PreparasiSpermaCreated + ) + VALUES( + {$doctor_id}, + {$orderdetail_id}, + '{$prm['Other_PreparasiSpermaPreMotilitasA']}', + '{$prm['Other_PreparasiSpermaPreMotilitasB']}', + '{$prm['Other_PreparasiSpermaPreMotilitasC']}', + '{$prm['Other_PreparasiSpermaPreKonsentrasi']}', + '{$prm['Other_PreparasiSpermaPreKontaminan']}', + '{$prm['Other_PreparasiSpermaPostMotilitasA']}', + '{$prm['Other_PreparasiSpermaPostMotilitasB']}', + '{$prm['Other_PreparasiSpermaPostMotilitasC']}', + '{$prm['Other_PreparasiSpermaPostKonsentrasi']}', + '{$prm['Other_PreparasiSpermaPostKontaminan']}', + '{$prm['Other_PreparasiSpermaPreVolume']}', + '{$prm['Other_PreparasiSpermaPostVolume']}', + '{$prm['Other_PreparasiSpermaM_MethodeSpermaID']}', + '{$prm['Other_PreparasiSpermaNote']}', + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } + else{ + $sql = "SELECT * FROM other_preparasisperma WHERE Other_PreparasiSpermaT_OrderDetailID = {$orderdetail_id} AND Other_PreparasiSpermaIsActive = 'Y'"; + $data_header = $this->db_smartone->query($sql)->row_array(); + $header_id = $data_header['Other_PreparasiSpermaID']; + $sql = "UPDATE other_preparasisperma SET + Other_PreparasiSpermaM_DoctorID = {$doctor_id}, + Other_PreparasiSpermaPreMotilitasA = '{$prm['Other_PreparasiSpermaPreMotilitasA']}', + Other_PreparasiSpermaPreMotilitasB = '{$prm['Other_PreparasiSpermaPreMotilitasB']}', + Other_PreparasiSpermaPreMotilitasC = '{$prm['Other_PreparasiSpermaPreMotilitasC']}', + Other_PreparasiSpermaPreKonsentrasi = '{$prm['Other_PreparasiSpermaPreKonsentrasi']}', + Other_PreparasiSpermaPreKontaminan = '{$prm['Other_PreparasiSpermaPreKontaminan']}', + Other_PreparasiSpermaPostMotilitasA = '{$prm['Other_PreparasiSpermaPostMotilitasA']}', + Other_PreparasiSpermaPostMotilitasB = '{$prm['Other_PreparasiSpermaPostMotilitasB']}', + Other_PreparasiSpermaPostMotilitasC = '{$prm['Other_PreparasiSpermaPostMotilitasC']}', + Other_PreparasiSpermaPostKonsentrasi = '{$prm['Other_PreparasiSpermaPostKonsentrasi']}', + Other_PreparasiSpermaPostKontaminan = '{$prm['Other_PreparasiSpermaPostKontaminan']}', + Other_PreparasiSpermaPreVolume = '{$prm['Other_PreparasiSpermaPreVolume']}', + Other_PreparasiSpermaPostVolume = '{$prm['Other_PreparasiSpermaPostVolume']}', + Other_PreparasiSpermaM_MethodeSpermaID = '{$prm['Other_PreparasiSpermaM_MethodeSpermaID']}', + Other_PreparasiSpermaNote = '{$prm['Other_PreparasiSpermaNote']}', + Other_PreparasiSpermaUserID = {$userid} + WHERE + Other_PreparasiSpermaID = {$header_id}"; + $this->db_smartone->query($sql); + } + + + $result = array("total" => 1, "records" => array(), "sql"=> ''); + $this->sys_ok($result); + exit; + } + + function getdnafragmentasiresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT other_dnafragmentasi.*, + Other_DnaFragmentasiID as xid, + Other_DnaFragmentasiT_OrderDetailID as orderdetail_id, + IFNULL(Other_DnaFragmentasiM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_DnaFragmentasiM_DoctorID) OR Other_DnaFragmentasiM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name, + IFNULL(Other_DnaFragmentasiOther_DnaFragmentasiMethodeID,0) as methode_id, + IFNULL(Other_DnaFragmentasiMethodeName,'') as methode_name, + Other_DnaFragmentasiHaloLuas as halo_luas, + Other_DnaFragmentasiHaloSedang as halo_sedang, + Other_DnaFragmentasiHaloSempit as halo_sempit, + Other_DnaFragmentasiTanpaHalo as tanpa_halo, + Other_DnaFragmentasiDFI as dfi, + Other_DnaFragmentasiKesimpulan as kesimpulan, + Other_DnaFragmentasiCatatan as catatan + FROM other_dnafragmentasi + LEFT JOIN m_doctor ON Other_DnaFragmentasiM_DoctorID = M_DoctorID + LEFT JOIN other_dnafragmentasimethode ON Other_DnaFragmentasiOther_DnaFragmentasiMethodeID = Other_DnaFragmentasiMethodeID + WHERE + Other_DnaFragmentasiT_OrderDetailID = {$id} AND Other_DnaFragmentasiIsActive = 'Y' + GROUP BY Other_DnaFragmentasiID + LIMIT 1"; + //echo $sql; + $query = $this->db_smartone->query($sql); + + if ($query) + { + $rows = $query->row_array(); + if(!$rows){ + $rows = array( + 'xid' => 0, + 'orderdetail_id' =>$id, + 'doctor_id' => 0, + 'doctor_name' => '', + 'methode_id' => 0, + 'methode_name' => '', + 'halo_luas' => '', + 'halo_sedang' => '', + 'tanpa_halo' => '', + 'dfi' => '', + 'kesimpulan' => '', + 'catatan' => '' + ); + } + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID + WHERE + M_DoctorSONat_SubGroupID = 4 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + + $sql = " + SELECT '0' as id, 'Belum memilih metode' as name + UNION + SELECT Other_DnaFragmentasiMethodeID as id, Other_DnaFragmentasiMethodeName as name + FROM other_dnafragmentasimethode + WHERE + Other_DnaFragmentasiMethodeIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $methodes = $this->db_smartone->query($sql)->result_array(); + + + $rst = array('doctors'=>$doctors,'methodes'=>$methodes,'results'=>$rows); + $this->sys_ok(["records"=>$rst]); + } + else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + function saveresult_dnafragmentasi() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = $inp['doctor']['id']; + $methode_id = $inp['methode']['id']; + $orderdetail_id = $inp['results']['orderdetail_id']; + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + if(intval($prm['xid']) == 0){ + $sql = "INSERT INTO other_dnafragmentasi( + Other_DnaFragmentasiT_OrderDetailID, + Other_DnaFragmentasiM_DoctorID, + Other_DnaFragmentasiOther_DnaFragmentasiMethodeID, + Other_DnaFragmentasiHaloLuas, + Other_DnaFragmentasiHaloSedang, + Other_DnaFragmentasiHaloSempit, + Other_DnaFragmentasiTanpaHalo, + Other_DnaFragmentasiDFI, + Other_DnaFragmentasiKesimpulan, + Other_DnaFragmentasiCatatan, + Other_DnaFragmentasiUserID, + Other_DnaFragmentasiLastUpdated + ) + VALUES( + {$orderdetail_id}, + {$doctor_id}, + {$methode_id}, + '{$prm['halo_luas']}', + '{$prm['halo_sedang']}', + '{$prm['halo_sempit']}', + '{$prm['tanpa_halo']}', + '{$prm['dfi']}', + '{$prm['kesimpulan']}', + '{$prm['catatan']}', + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } + else{ + $sql = "UPDATE other_dnafragmentasi SET + Other_DnaFragmentasiT_OrderDetailID = {$orderdetail_id}, + Other_DnaFragmentasiM_DoctorID = {$doctor_id}, + Other_DnaFragmentasiOther_DnaFragmentasiMethodeID = '{$methode_id}', + Other_DnaFragmentasiHaloLuas = '{$prm['halo_luas']}', + Other_DnaFragmentasiHaloSedang = '{$prm['halo_sedang']}', + Other_DnaFragmentasiHaloSempit = '{$prm['halo_sempit']}', + Other_DnaFragmentasiTanpaHalo = '{$prm['tanpa_halo']}', + Other_DnaFragmentasiDFI = '{$prm['dfi']}', + Other_DnaFragmentasiKesimpulan = '{$prm['kesimpulan']}', + Other_DnaFragmentasiCatatan = '{$prm['catatan']}', + Other_DnaFragmentasiLastUpdated = NOW(), + Other_DnaFragmentasiUserID = {$userid} + WHERE + Other_DnaFragmentasiID = {$prm['xid']}"; + //echo $sql; + $this->db_smartone->query($sql); + } + + + $result = array("total" => 1, "records" => array(), "sql"=> ''); + $this->sys_ok($result); + exit; + } + + +} + diff --git a/application/controllers/mockup/process/resultvalidation-v24/Re_px.php b/application/controllers/mockup/process/resultvalidation-v24/Re_px.php index 8e1cbe21..dca767be 100644 --- a/application/controllers/mockup/process/resultvalidation-v24/Re_px.php +++ b/application/controllers/mockup/process/resultvalidation-v24/Re_px.php @@ -1,2513 +1,2510 @@ -db_smartone = $this->load->database("onedev", true); - $this->load->helper(array('form', 'url')); - } - function getMethodeID($natTestID) - { - $sql = "select M_MethodePriorityNat_MethodeID MethodeID, Nat_MethodeName - from - m_methode_priority - join nat_methode on Nat_MethodeID = M_MethodePriorityNat_MethodeID - and Nat_MethodeIsActive = 'Y' - join m_instrumentmethode on M_InstrumentMethodeNat_MethodeID = Nat_MethodeID and M_InstrumentMethodeIsActive = 'Y' - join nat_instrument on M_InstrumentMethodeNat_InstrumentID = Nat_InstrumentID - and Nat_InstrumentIsActive ='Y' - where M_MethodePriorityIsActive = 'Y' - and M_MethodePriorityNat_TestID = $natTestID - and M_MethodePriorityM_DayOfWeekID = dayofweek(now()) - order by M_MethodePriorityNumber desc - limit 0,1 "; - $qry = $this->db->query($sql); - if ($qry) { - $rows = $qry->result_array(); - if (count($rows) > 0) return array($rows[0]["MethodeID"], $rows[0]["Nat_MethodeName"]); - } - //2nd - $sql = "select - M_InstrumentMethodeNat_MethodeID MethodeID, Nat_MethodeName - from m_instrumentmethode - join nat_methode on M_InstrumentMethodeNat_MethodeID = Nat_MethodeID - and Nat_MethodeIsActive = 'Y' - join nat_instrument on M_InstrumentMethodeNat_InstrumentID = Nat_InstrumentID - and Nat_InstrumentIsActive ='Y' - where M_InstrumentMethodeNat_TestID = $natTestID - and M_InstrumentMethodeIsActive = 'Y' - order by M_InstrumentMethodePriority desc - limit 0,1"; - $qry = $this->db->query($sql); - if ($qry) { - $rows = $qry->result_array(); - if (count($rows) > 0) return array($rows[0]["MethodeID"], $rows[0]["Nat_MethodeName"]); - } - // - $sql = "select Nat_NormalValueNat_MethodeID MethodeID, Nat_MethodeName - from - nat_normalvalue - join nat_methode on Nat_NormalValueNat_MethodeID = Nat_MethodeID - and Nat_MethodeIsActive = 'Y' - where Nat_NormalValueNat_TestID = $natTestID - and Nat_NormalValueIsActive = 'Y' - order by Nat_NormalValueID - limit 0,1"; - $qry = $this->db->query($sql); - if ($qry) { - $rows = $qry->result_array(); - if (count($rows) > 0) return array($rows[0]["MethodeID"], $rows[0]["Nat_MethodeName"]); - } - return array(0, ""); - } - function get_normal_value($methodeID, $natTestID, $sexID, $ageInDay) - { - $sql = "select fn_sampling_get_normal($methodeID, $natTestID, $sexID, $ageInDay) as normalValueID"; - $qry = $this->db->query($sql); - if ($qry) { - $rows = $qry->result_array(); - if (count($rows) > 0) return $rows[0]["normalValueID"]; - } - return 0; - } - function fn_fix_normal($order_id) - { - $sql = "select - T_OrderDetailID, M_PatientM_SexID, fn_global_age_count_day(M_PatientDOB, date(T_OrderHeaderDate)) Dob , - T_TestNat_TestID - from t_orderheader - join m_patient on T_OrderHeaderID = $order_id and T_OrderHeaderM_PatientID = M_PatientID - join t_orderdetail on T_OrderDetailT_OrderHeaderID = T_OrderHeaderID - and T_OrderDetailIsACtive = 'Y' - and ( T_OrderDetailNat_NormalValueID is null or T_OrderDetailNat_NormalValueID = 0 ) - join t_test on T_OrderDetailT_TestID = T_TestID and T_TestIsResult = 'Y' "; - $qry = $this->db->query($sql); - if (! $qry) { - return; - } - $rows = $qry->result_array(); - if (count($rows) == 0) return; - $sql_u = "update t_orderdetail - join nat_normalvalue on T_OrderDetailID = ? and Nat_NormalValueID = ? - set - T_OrderDetailNat_NormalValueID = Nat_NormalValueID, - T_OrderDetailNormalValueNote = Nat_NormalValueNote, - T_OrderDetailNormalValueDescription = Nat_NormalValueDescription, - T_OrderDetailMinValue = Nat_NormalValueMinValue, - T_OrderDetailMaxValue = Nat_NormalValueMaxValue, - T_OrderDetailMinValueInclusive = Nat_NormalValueMinValueInclusive, - T_OrderDetailMaxValueInclusive = Nat_NormalValueMaxValueInclusive, - T_OrderDetailNat_MethodeID = ?, - T_OrderdetailNat_MethodeName =?"; - - foreach ($rows as $r) { - $T_OrderDetailID = $r["T_OrderDetailID"]; - $sexID = $r["M_PatientM_SexID"]; - $ageInDay = $r["Dob"]; - $natTestID = $r["T_TestNat_TestID"]; - list($methodeID, $methodeName) = $this->getMethodeID($natTestID); - if ($methodeID == 0) continue; - $normalValueID = $this->get_normal_value($methodeID, $natTestID, $sexID, $ageInDay); - if ($normalValueID == 0) return; - $this->db->query($sql_u, array($T_OrderDetailID, $normalValueID, $methodeID, $methodeName)); - } - } - function update_order_sample($targetID, $sourceID) - { - $sql = "update t_ordersample target - join t_ordersample source on - target.T_OrderSampleID = ? - and target.T_OrderSampleWorklistReceive = 'N' - and source.T_OrderSampleID = ? - set - target.T_OrderSampleSampling = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSampling, source.T_OrderSampleSampling), - target.T_OrderSampleSamplingDate = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingDate, source.T_OrderSampleSamplingDate), - target.T_OrderSampleSamplingTime = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingTime, source.T_OrderSampleSamplingTime), - target.T_OrderSampleSamplingUserID = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingUserID, source.T_OrderSampleSamplingUserID), - - target.T_OrderSampleReceive = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceive, source.T_OrderSampleReceive), - target.T_OrderSampleReceiveDate = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveDate, source.T_OrderSampleReceiveDate), - target.T_OrderSampleReceiveTime = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveTime, source.T_OrderSampleReceiveTime), - target.T_OrderSampleReceiveUserID = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveUserID, source.T_OrderSampleReceiveUserID), - - target.T_OrderSampleVerification = if(target.T_OrderSampleVerification='Y',target.T_OrderSampleVerification, source.T_OrderSampleVerification), - target.T_OrderSampleVerificationDate =if(target.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationDate, source.T_OrderSampleVerificationDate), - target.T_OrderSampleVerificationTime =if(source.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationTime, source.T_OrderSampleVerificationTime), - target.T_OrderSampleVerificationUserID =if(source.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationUserID, source.T_OrderSampleVerificationUserID), - - target.T_OrderSampleProcessing = if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessing, source.T_OrderSampleProcessing), - target.T_OrderSampleProcessingDate= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingDate, source.T_OrderSampleProcessingDate), - target.T_OrderSampleProcessingTime= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingTime, source.T_OrderSampleProcessingTime), - target.T_OrderSampleProcessingUserID= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingUserID, source.T_OrderSampleProcessingUserID), - - target.T_OrderSampleReceiveHandling =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandling, source.T_OrderSampleReceiveHandling ), - target.T_OrderSampleReceiveHandlingDate =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingDate, source.T_OrderSampleReceiveHandlingDate), - target.T_OrderSampleReceiveHandlingTime =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingTime, source.T_OrderSampleReceiveHandlingTime), - target.T_OrderSampleReceiveHandlingUserID =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingUserID, source.T_OrderSampleReceiveHandlingUserID), - - target.T_OrderSampleHandling = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandling, source.T_OrderSampleHandling), - target.T_OrderSampleHandlingDate = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingDate, source.T_OrderSampleHandlingDate), - target.T_OrderSampleHandlingTime = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingTime, source.T_OrderSampleHandlingTime), - target.T_OrderSampleHandlingUserID = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingUserID, source.T_OrderSampleHandlingUserID), - - target.T_OrderSampleWorklistReceive = source.T_OrderSampleWorklistReceive, - target.T_OrderSampleWorklistReceiveDatetime = source.T_OrderSampleWorklistReceiveDateTime, - target.T_OrderSampleWorklistReceiveUserID = source.T_OrderSampleWorklistReceiveUserID - "; - $qry = $this->db->query($sql, array($targetID, $sourceID)); - if (! $qry) { - echo json_encode(array("status" => "ERR", "message" => print_r($this->db->error(), true))); - exit; - } - } - function fix_sample_serum($headerID) - { - //cari t_ordersample yg belum worklist receive dengan code 017% - $sql = "select T_OrderSampleID - from t_ordersample - join t_sampletype on - T_OrderSampleT_OrderHeaderID = ? - and T_OrderSampleWorklistReceive = 'N' - and T_OrderSampleIsActive = 'Y' - and T_OrderSampleT_SampleTypeID = T_SampletypeID - and T_SampleTypeCode like '017%' - "; - $qry = $this->db->query($sql, array($headerID)); - if (!$qry) { - echo json_encode(array("status" => "ERR", "message" => print_r($this->db->error(), true))); - exit; - } - $rows = $qry->result_array(); - if (count($rows) == 0) return; - //cari T_OrderSample yang sudah di receive yg terakhir - $sql = "select T_OrderSampleID - from t_ordersample - join t_sampletype on - T_OrderSampleT_OrderHeaderID = ? - and T_OrderSampleWorklistReceive = 'Y' - and T_OrderSampleIsActive = 'Y' - and T_OrderSampleT_SampleTypeID = T_SampletypeID - and T_SampleTypeCode like '017%' - order by T_OrderSampleWorklistReceiveDatetime desc - limit 0,1 - "; - $qry = $this->db->query($sql, array($headerID)); - if (!$qry) { - echo json_encode(array("status" => "ERR", "message" => print_r($this->db->error(), true))); - exit; - } - $rcv_rows = $qry->result_array(); - if (count($rcv_rows) == 0) return; - - //print_r($rows); - //print_r($rcv_rows); - $rcv_T_OrderSampleID = $rcv_rows[0]["T_OrderSampleID"]; - //ada yg belum di receive - foreach ($rows as $r) { - $T_OrderSampleID = $r["T_OrderSampleID"]; - $this->update_order_sample($T_OrderSampleID, $rcv_T_OrderSampleID); - } - } - public function search() - { - $prm = $this->sys_input; - $max_rst = 99; - - $id = $prm["order_id"]; - if ($id > 0) { - $this->fix_sample_serum($id); - $this->fn_fix_normal($id); - } - $lang = $this->lang_default_code; - $lang_id = isset($prm['lang_id']) ? $prm['lang_id'] : '0'; - - if ($lang_id != 0) { - $l = $this->db_smartone->where("Nat_LangID", $lang_id)->get("nat_lang")->row(); - $lang = $l->Nat_LangCode; - } - - //tambahan fajri - $sql = " UPDATE t_orderdetail - JOIN t_test ON T_OrderDetailT_TestID = T_TestID - SET T_OrderDetailT_TestIsResult = T_TestIsResult - WHERE - T_OrderDetailT_OrderHeaderID = {$id} AND - T_OrderDetailT_TestIsResult = '' AND - T_OrderDetailIsActive = 'Y'"; - $this->db_smartone->query($sql); - - $tot_count = 0; - $lq = ""; - $group_id = 0; - if (isset($prm['group_id'])) - $group_id = $prm['group_id']; - - if ($group_id != 0) { - $sql = "select distinct T_WorklistDetailNat_TestID Nat_TestID - from t_worklistdetailv2 - where T_WorklistDetailT_WorklistID = {$group_id}"; - $qry = $this->db_smartone->query($sql); - $rows = $qry->result_array(); - $nat_test_ids = "0"; - foreach ($rows as $r) { - $nat_test_ids .= ", " . $r["Nat_TestID"]; - } - $q_group = " ( $nat_test_ids ) "; - - $sql = " - SELECT a1.*, cOUNT(a2.T_OrderDetailID) level - FROM ( - SELECT IFNULL(y.T_OrderDetailT_TestID, x.T_OrderDetailT_TestID) t_testid, - IFNULL(y.T_OrderDetailT_TestName, y.T_OrderDetailT_TestName) t_testname, - y.T_OrderDetailResult result, y.T_OrderDetailResult result_old, y.T_OrderDetailNote note, y.T_OrderDetailNote note_old, - y.T_OrderDetailID id, - y.T_OrderDetailT_TestIsResult is_result, a.T_TestIsQuantitative is_quantitative, - y.T_OrderDetailResultFlag result_flag, - y.T_OrderDetailNat_NormalValueID normal_id, - y.T_OrderDetailNormalValueNote normal_note, y.T_OrderDetailNat_UnitName unit_name, - y.T_OrderdetailNat_MethodeID methode_id, y.T_OrderdetailNat_MethodeName methode_name, - a.T_TestNat_TestID nattest_id, a.T_TestID tx_id, count(T_ResultInstrumentID) as result_instrument_n, - y.T_OrderDetailVerification, T_OrderSampleReceive sample_receive, - T_OrderSampleProcessing sample_processing, T_OrderSampleWorklistReceive sample_worklist_receive, - IF(T_OrderDetailAddOnPreAnalytic = 'Y', T_OrderDetailAddOnPreAnalytic, PreAnalyticIsOk) pre_analytic, - T_OrderDetailAddOnPreAnalytic, - T_OrderHeaderID order_id, y.T_OrderDetailT_TestSasCode test_sas_code, - tx.T_TestSasCode, - T_OrderDetailAddOnResample `resample`, T_OrderDetailAddOnResampleStatus resample_status, - T_OrderDetailAddOnRef ref, y.T_OrderDetailVerification verification, y.T_OrderDetailValidation validation, - T_OrderPromiseDateTime, Group_ResultName as ResultGroupName - FROM t_orderdetail x - left join t_orderpromise on x.T_OrderDetailT_OrderPromiseID = T_OrderPromiseID - JOIN t_test tx ON x.T_OrderDetailT_TestID = T_TestID - JOIN t_test tcheck on tcheck.T_TestNat_TestID in {$q_group} - and ( tx.T_TestID = tcheck.T_TestID or tx.T_TestSasCode like concat(tcheck.T_TestSasCode,'%')) - LEFT JOIN group_resultdetail ON Group_ResultDetailT_TestID = x.T_OrderDetailT_TestID AND Group_ResultDetailIsActive = 'Y' - LEFT JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND Group_ResultFlagNonLab = 'N' - LEFT JOIN t_orderdetail y ON x.T_OrderDetailT_TestSasCode LIKE CONCAT(y.T_OrderDetailT_TestSasCode, '%') - AND x.T_OrderDetailT_OrderHeaderID = y.T_OrderDetailT_OrderHeaderID - AND y.T_OrderDetailIsActive = 'Y' - LEFT JOIN t_orderdetailaddon ON x.T_OrderDetailID = T_OrderDetailAddOnT_OrderDetailID - JOIN t_orderheader ON y.T_OrderDetailT_OrderHeaderID = T_OrderHeaderID - LEFT JOIN t_test a ON y.T_OrderDetailT_TestID = a.T_TestID - AND a.T_TestIsNonLab = '' - LEFT JOIN (SELECT T_OrderSampleT_SampleTypeID, T_OrderSampleReceive, T_OrderSampleProcessing, T_OrderSampleWorklistReceive - FROM t_ordersample WHERE T_OrderSampleT_OrderHeaderID = {$id} - AND T_OrderSampleIsactive = 'Y' - GROUP BY T_OrderSampleT_SampleTypeID) os ON a.T_TestT_SampleTypeID = os.T_OrderSampleT_SampleTypeID - or os.T_OrderSampleT_SampleTypeID = fn_sampletype_from_local(a.T_TestNat_TestID) - - LEFT JOIN t_resultinstrument ON T_ResultInstrumentT_OrderDetailID = x.T_OrderDetailID - LEFT JOIN pre_analytic ON PreAnalyticNat_TestID = a.T_TestNat_TestID AND PreAnalyticDate = date(now()) and PreAnalyticIsActive = 'Y' - WHERE x.T_OrderDetailT_OrderHeaderID = {$id} - AND x.T_OrderDetailIsActive = 'Y' - GROUP BY y.T_OrderDetailT_TestID - ORDER BY y.T_OrderDetailT_TestSasCode ASC - ) a1 - - LEFT JOIN t_orderdetail a2 ON a2.T_OrderDetailT_OrderHeaderID = a1.order_id - AND a2.T_OrderDetailIsActive = 'Y' - AND a1.test_sas_code LIKE CONCAT(a2.T_OrderDetailT_testSasCode, '%') - GROUP BY a1.t_testid - order by a1.test_sas_code -"; - $query = $this->db_smartone->query($sql); - $lq = $this->db_smartone->last_query(); - } else { - $sql = " - SELECT a1.*, cOUNT(a2.T_OrderDetailID) level - FROM ( - SELECT IFNULL(y.T_OrderDetailT_TestID, x.T_OrderDetailT_TestID) t_testid, - IFNULL(y.T_OrderDetailT_TestName, y.T_OrderDetailT_TestName) t_testname, - y.T_OrderDetailResult result, y.T_OrderDetailResult result_old, y.T_OrderDetailNote note, y.T_OrderDetailNote note_old, - y.T_OrderDetailID id, - y.T_OrderDetailT_TestIsResult is_result, a.T_TestIsQuantitative is_quantitative, - y.T_OrderDetailResultFlag result_flag, - y.T_OrderDetailNat_NormalValueID normal_id, - y.T_OrderDetailNormalValueNote normal_note, y.T_OrderDetailNat_UnitName unit_name, - y.T_OrderdetailNat_MethodeID methode_id, y.T_OrderdetailNat_MethodeName methode_name, - a.T_TestNat_TestID nattest_id, a.T_TestID tx_id, count(T_ResultInstrumentID) as result_instrument_n, - y.T_OrderDetailVerification, T_OrderSampleReceive sample_receive, - T_OrderSampleProcessing sample_processing, T_OrderSampleWorklistReceive sample_worklist_receive, - IF(T_OrderDetailAddOnPreAnalytic = 'Y', T_OrderDetailAddOnPreAnalytic, PreAnalyticIsOk) pre_analytic, - T_OrderDetailAddOnPreAnalytic, - T_OrderHeaderID order_id, y.T_OrderDetailT_TestSasCode test_sas_code, - tx.T_TestSasCode, - T_OrderDetailAddOnResample `resample`, T_OrderDetailAddOnResampleStatus resample_status, - T_OrderDetailAddOnRef ref, y.T_OrderDetailVerification verification, y.T_OrderDetailValidation validation, - T_OrderPromiseDateTime , Group_ResultName as ResultGroupName - FROM t_orderdetail x - left join t_orderpromise on x.T_OrderDetailT_OrderPromiseID = T_OrderPromiseID - JOIN t_test tx ON x.T_OrderDetailT_TestID = T_TestID - LEFT JOIN group_resultdetail ON Group_ResultDetailT_TestID = x.T_OrderDetailT_TestID AND Group_ResultDetailIsActive = 'Y' - LEFT JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND Group_ResultFlagNonLab = 'N' - LEFT JOIN t_orderdetail y ON x.T_OrderDetailT_TestSasCode LIKE CONCAT(y.T_OrderDetailT_TestSasCode, '%') - AND x.T_OrderDetailT_OrderHeaderID = y.T_OrderDetailT_OrderHeaderID - AND y.T_OrderDetailIsActive = 'Y' - - LEFT JOIN t_orderdetailaddon ON x.T_OrderDetailID = T_OrderDetailAddOnT_OrderDetailID - - JOIN t_orderheader ON y.T_OrderDetailT_OrderHeaderID = T_OrderHeaderID - LEFT JOIN t_test a ON y.T_OrderDetailT_TestID = a.T_TestID - AND a.T_TestIsNonLab = '' - LEFT JOIN (SELECT T_OrderSampleT_SampleTypeID, T_OrderSampleReceive, T_OrderSampleProcessing, T_OrderSampleWorklistReceive - FROM t_ordersample WHERE T_OrderSampleT_OrderHeaderID = {$id} - AND T_OrderSampleIsactive = 'Y' - GROUP BY T_OrderSampleT_SampleTypeID) os ON a.T_TestT_SampleTypeID = os.T_OrderSampleT_SampleTypeID - or os.T_OrderSampleT_SampleTypeID = fn_sampletype_from_local(a.T_TestNat_TestID) - - LEFT JOIN t_resultinstrument ON T_ResultInstrumentT_OrderDetailID = x.T_OrderDetailID - LEFT JOIN pre_analytic ON PreAnalyticNat_TestID = a.T_TestNat_TestID AND PreAnalyticDate = date(now()) and PreAnalyticIsActive = 'Y' - WHERE x.T_OrderDetailT_OrderHeaderID = {$id} - AND x.T_OrderDetailIsActive = 'Y' - GROUP BY y.T_OrderDetailT_TestID - ORDER BY y.T_OrderDetailT_TestSasCode ASC - ) a1 - - LEFT JOIN t_orderdetail a2 ON a2.T_OrderDetailT_OrderHeaderID = a1.order_id - AND a2.T_OrderDetailIsActive = 'Y' - AND a1.test_sas_code LIKE CONCAT(a2.T_OrderDetailT_testSasCode, '%') - GROUP BY a1.t_testid - order by a1.test_sas_code -"; - //echo $sql; - $query = $this->db_smartone->query($sql); - $lq = $this->db_smartone->last_query(); - } - // file_put_contents("/xtmp/re-query.sql",$lq); - - if ($query) { - $rst = []; - $rows = $query->result_array(); - - foreach ($rows as $k => $v) { - - if ($v['is_result'] == "Y" && $v['is_quantitative'] == "N") { - $v['template'] = []; - $x = $this->db_smartone->query("CALL sp_master_resulttemplate_get('{$v['t_testid']}')"); - $this->clean_mysqli_connection($this->db_smartone->conn_id); - if ($x) - $v['template'] = $x->result_array(); - } - - // IF Rujukan, by pas Pre Analytik - if ($v['ref'] == 'Y') - $v['pre_analytic'] = 'Y'; - if ($v["id"] == "885455") { - //sipe workaround - //$v["sample_receive"] = "Y"; - $v["sample_worklist_receive"] = "Y"; - } - $rst[] = $v; - } - - $result = array("total" => $tot_count, "records" => $rst, "total_display" => sizeof($rows), "q" => $lq); - $this->sys_ok($result); - } else { - $this->sys_error_db("RE Px rows", $this->db_smartone); - exit; - } - } - - public function save() - { - $prm = $this->sys_input; - $data = json_decode($prm["data"]); - $lang = $this->lang_default_code; - $lang_id = isset($prm['lang_id']) ? $prm['lang_id'] : '0'; - - if ($lang_id != 0) { - $l = $this->db_smartone->where("Nat_LangID", $lang_id)->get("nat_lang")->row(); - $lang = $l->Nat_LangCode; - } - - $sql_norm = "select T_OrderDetailMinValue, T_OrderDetailMaxValue, - T_OrderDetailMinValueInclusive, T_OrderDetailMaxValueInclusive, - Nat_TestFlagLow, Nat_TestFlagHigh - from t_orderdetail - join t_test on T_OrderDetailT_TestID = T_TestID - join nat_test on T_TestNat_TestID = Nat_TestID and T_TestIsActive = 'Y' - where T_OrderDetailID = ? "; - - $ids = []; - foreach ($data as $k => $v) { - if ($v->resultInstrumentID > 0) { - $sql_i = "select T_ResultInstrumentNat_NormalValueID normalValueID - from t_resultinstrument - where T_ResultInstrumentID = ?"; - $qry_i = $this->db_smartone->query($sql_i, array($v->resultInstrumentID)); - if ($qry_i) { - $rows_i = $qry_i->result_array(); - - if (count($rows_i) > 0) { - $sql_iu = "update t_orderdetail, nat_normalvalue , nat_methode - set T_OrderDetailMinValue = Nat_NormalValueMinValue, - T_OrderDetailMinValueInclusive = Nat_NormalValueMinValueInclusive, - T_OrderDetailMaxValue = Nat_NormalValueMaxValue , - T_OrderDetailMaxValueInclusive = Nat_NormalValueMaxValueInclusive, - T_OrderDetailNormalValueNote = Nat_NormalValueNote, - T_OrderDetailNormalValueDescription = Nat_NormalValueDescription, - T_OrderDetailNat_NormalValueID = Nat_NormalValueID, - T_OrderDetailNat_MethodeID = Nat_NormalValueNat_MethodeID, - T_OrderDetailNat_MethodeName = Nat_MethodeName - where T_OrderDetailID = ? and Nat_NormalValueID = ? - and Nat_NormalValueNat_MethodeID = Nat_MethodeID - "; - $this->db_smartone->query($sql_iu, array($v->id, $rows_i[0]["normalValueID"])); - //file_put_contents("/xtmp/update-nilai-normal", $this->db_smartone->last_query() . "\n", FILE_APPEND); - } - } - } - $y = $this->db_smartone->query("SELECT fn_process_sample_handling_perfect('{$v->order_id}', '{$v->test_id}') c") - ->row(); - $req_status = $y->c; - $qry_norm = $this->db_smartone->query($sql_norm, $v->id); - $result_flag = ""; - if ($qry_norm) { - $rows_norm = $qry_norm->result_array(); - if (count($rows_norm) > 0) { - $r = $rows_norm[0]; - if (is_numeric($v->result)) { - - if ($r["T_OrderDetailMinValueInclusive"] == "Y" && $v->result < $r["T_OrderDetailMinValue"]) { - $result_flag = $r["Nat_TestFlagLow"]; - } - if ($r["T_OrderDetailMinValueInclusive"] == "N" && $v->result <= $r["T_OrderDetailMinValue"]) { - $result_flag = $r["Nat_TestFlagLow"]; - } - if ($r["T_OrderDetailMaxValueInclusive"] == "Y" && $v->result > $r["T_OrderDetailMaxValue"]) { - $result_flag = $r["Nat_TestFlagHigh"]; - } - if ($r["T_OrderDetailMaxValueInclusive"] == "N" && $v->result >= $r["T_OrderDetailMaxValue"]) { - $result_flag = $r["Nat_TestFlagHigh"]; - } - } - } - } - if ($lang == $this->lang_default_code) { - $this->db_smartone->set('T_OrderDetailResult', $v->result) - ->set('T_OrderDetailResultFlag', $result_flag) - ->set('T_OrderDetailNote', $v->note) - ->set('T_OrderDetailReqStatus', $req_status) - ->where('T_OrderDetailID', $v->id) - ->update('t_orderdetail'); - } else { - $this->db_smartone->set('T_OrderDetailLangResult', $v->result) - ->set('T_OrderDetailLangNote', $v->note) - ->where('T_OrderDetailLangID', $v->id) - ->update('t_orderdetaillang'); - } - - $ids[] = $v->id; - } - - // LOG Process - $order = $this->db_smartone->select('T_OrderDetailT_OrderHeaderID id, T_OrderHeaderLabNumber lab_number', false) - ->join('t_orderheader', 'T_OrderHeaderID = T_OrderDetailT_OrderHeaderID') - ->where('T_OrderDetailID', $data[0]->id) - ->get('t_orderdetail') - ->row(); - - $dblog = $this->load->database("onelog", true); - $dblog->set('Log_ProcessCode', 'PROCESS.Result.Entry') - ->set('Log_ProcessOrderID', $order->id) - ->set('Log_ProcessOrderNumber', $order->lab_number) - ->set('Log_ProcessJson', json_encode($data)) - ->set('Log_ProcessUserID', $this->sys_user['M_UserID']) - ->insert('log_process'); - // END OF Log Process - //auto calculation - $this->load->library("Resultcalc"); - $rows = $this->resultcalc->auto($order->id); - - try { - foreach ($ids as $id) { - $this->db_smartone->query("call sp_set_normal_value_flag($id)"); - $this->clean_mysqli_connection($this->db_smartone->conn_id); - } - } catch (Exception $e) { - } - - $this->sys_ok($ids); - } - - public function save_template() - { - $prm = $this->sys_input; - - $n = $this->db_smartone->select("COUNT(T_ResultTemplateID) n") - ->where("T_ResultTemplateT_TestID", $prm['test_id']) - ->where("T_ResultTemplateIsActive", "Y") - ->where("T_ResultTemplateValue", $prm['value']) - ->get('t_resulttemplate') - ->row(); - if ($n->n > 0) { - $this->sys_error_db("Insert Result Template", $this->db_smartone); - return; - } - - $r = $this->db_smartone->set("T_ResultTemplateT_TestID", $prm['test_id']) - ->set("T_ResultTemplateValue", $prm['value']) - ->insert('t_resulttemplate'); - if ($r) { - $template = []; - $x = $this->db_smartone->query("CALL sp_master_resulttemplate_get('{$prm['test_id']}')"); - $this->clean_mysqli_connection($this->db_smartone->conn_id); - if ($x) - $template = $x->result_array(); - - $this->sys_ok($template); - } - } - - public function export() - { - $prm = $this->sys_input; - - $sql = "CALL sp_process_result_lang(?, ?, ?, ?)"; - $query = $this->db_smartone->query($sql, [$prm['order_id'], $prm['lang_id'], $prm['is_si'], $this->sys_user['M_UserID']]); - if ($query) { - $r = $query->row(); - if ($r->status == "OK") { - $this->sys_ok($r->data); - return; - } - - $this->sys_error_db("Message : " . $r->message, $this->db_smartone); - } else { - $this->sys_error_db("Lang Result", $this->db_smartone); - return; - } - } - - public function search_group() - { - $prm = $this->sys_input; - $max_rst = 100; - - // QUERY TOTAL - $sql = "select count(*) total - from t_worklist - where T_WorklistIsActive = 'Y' - order by T_WorklistName ASC"; - $query = $this->db_smartone->query($sql); - - if ($query) { - $tot_count = $query->result_array()[0]["total"]; - } else { - $this->sys_error_db("worklist count", $this->db_smartone); - exit; - } - - $sql = "select T_WorklistID group_id, T_WorklistName group_name - from t_worklist - where T_WorklistIsActive = 'Y' - order by T_WorklistName ASC - limit 0, {$max_rst}"; - $query = $this->db_smartone->query($sql); - - if ($query) { - $rows = $query->result_array(); - foreach ($rows as $k => $v) - $rows[$k]['data'] = json_decode($v['data']); - $result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows), "q" => $this->db_smartone->last_query()); - $this->sys_ok($result); - } else { - $this->sys_error_db("worklist rows", $this->db_smartone); - exit; - } - } - - public function search_rerun() - { - $prm = $this->sys_input; - $id = $prm["detail_id"]; - - $sql = "CALL sp_process_result_rerun(?)"; - $query = $this->db_smartone->query($sql, [$id]); - - if ($query) { - $rows = $query->result_array(); - $this->sys_ok(["records" => $rows]); - } else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - - - function getdoctorsfna() - { - $prm = $this->sys_input; - // $id = $prm["id"]; - - $sql = " SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY M_DoctorName ASC"; - //echo $sql; - $query = $this->db_smartone->query($sql); - - if ($query) { - $rows = $query->result_array(); - $this->sys_ok(["records" => $rows]); - } else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - function getfnaresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT Other_FNADetailsID as xid, - Other_FNAT_OrderDetailID as orderdetail_id, - Other_FNADetailsCode as code, - Other_FNADetailsLabel as label, - Other_FNADetailsResult as result, - IFNULL(Other_FNAM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_FNAM_DoctorID) OR Other_FNAM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_fna - JOIN other_fnadetails ON Other_FNADetailsOther_FNAID = Other_FNAID AND Other_FNADetailsIsActive = 'Y' - LEFT JOIN m_doctor ON Other_FNAM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_FNAT_OrderDetailID = {$id} AND Other_FNAIsActive = 'Y' - GROUP BY Other_FNADetailsID - ORDER BY Other_FNADetailsCode ASC"; - $query = $this->db_smartone->query($sql); - - if ($query) { - $rows = $query->result_array(); - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $images = array(); - $sql = "SELECT So_ImageUploadID as xid, - CONCAT('/one-media/one-image-nonlab/',So_ImageUploadNewName) as image_url - FROM t_orderdetail - JOIN so_imageupload ON So_ImageUploadT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND - So_ImageUploadIsActive = 'Y' - WHERE - T_OrderDetailID = {$id} AND - T_OrderDetailIsActive = 'Y' - GROUP BY So_ImageUploadID"; - $images = $this->db_smartone->query($sql)->result_array(); - - $rst = array('doctors' => $doctors, 'results' => $rows, 'images' => $images); - $this->sys_ok(["records" => $rst]); - } else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - - function uploadimage() - { - if (! $this->isLogin) { - $this->sys_error("Invalid Token"); - exit; - } - - $userid = $this->sys_user["M_UserID"]; - $data = []; - //print_r($_SERVER); - - $prm = $this->sys_input; - $orderid = $this->input->post('orderid'); - $labnumber = $this->input->post('labnumber'); - $sql = "UPDATE so_imageupload SET - So_ImageUploadIsActive = 'N', - So_ImageUploadUserID = {$userid} - WHERE - So_ImageUploadT_OrderHeaderID = {$orderid}"; - //echo $sql; - $this->db_onedev->query($sql); - //$config['upload_path'] = 'assets/'; - - $path = '/home/one/project/one/one-media/one-image-nonlab/'; - //echo $path; - $config['upload_path'] = $path; - $config['allowed_types'] = 'jpg|jpeg|png|gif'; - - $config['max_size'] = '10000'; - $count = count($_FILES['files']['name']); - //echo $count; - $this->load->library('upload', $config); - - $error = []; - for ($i = 0; $i < $count; $i++) { - - - if (!empty($_FILES['files']['name'][$i])) { - - - - $_FILES['file']['name'] = $_FILES['files']['name'][$i]; - - $_FILES['file']['type'] = $_FILES['files']['type'][$i]; - - $_FILES['file']['tmp_name'] = $_FILES['files']['tmp_name'][$i]; - - $_FILES['file']['error'] = $_FILES['files']['error'][$i]; - - $_FILES['file']['size'] = $_FILES['files']['size'][$i]; - - - - $namex = $orderid . '-' . $labnumber . '-' . $this->generateRandomString(5); - //echo $namex; - - $config['file_name'] = $namex; - $this->upload->initialize($config); - //echo $config['file_name'] ; - - - - - - if ($this->upload->do_upload('file')) { - - $uploadData = $this->upload->data(); - - $filename = $uploadData['file_name']; - //echo $filename; - - - $sql = "INSERT INTO so_imageupload ( - So_ImageUploadT_OrderHeaderID, - So_ImageUploadT_OrderHeaderLabNumber, - So_ImageUploadT_SampleTypeID, - So_ImageUploadOldName, - So_ImageUploadNewName, - So_ImageUploadCreated, - So_ImageUploadUserID - ) - VALUES( - {$orderid}, - '{$labnumber}', - '150', - '{$_FILES['files']['name'][$i]}', - '{$filename}', - NOW(), - {$userid} - - )"; - //echo $sql; - $this->db_onedev->query($sql); - $xlast_id = $this->db_onedev->insert_id(); - $data['totalFiles'][] = array('xid' => $xlast_id, 'image_url' => '/one-media/one-image-nonlab/' . $filename); - } else { - $error = array('error' => $this->upload->display_errors()); - } - } - } - - $result = array("total" => count($data['totalFiles']), "records" => $data['totalFiles'], 'errors' => $error); - $this->sys_ok($result); - } - - - function getpatologianatomyresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT Other_PatologiAnatomyID as xid, - Other_PatologiAnatomyT_OrderDetailID as orderdetail_id, - Other_PatologiAnatomyNoSediaan as no_sediaan, - Other_PatologiAnatomyDiagnosaKlinis as diagnosa, - Other_PatologiAnatomyKeteranganKlinis as klinis, - Other_PatologiAnatomyLokasiOrgan as lokasi, - Other_PatologiAnatomyMakroskopik as makroskopik, - Other_PatologiAnatomyMikroskopik as mikroskopik, - Other_PatologiAnatomyKesimpulan as kesimpulan, - IFNULL(Other_PatologiAnatomyM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_PatologiAnatomyM_DoctorID) OR Other_PatologiAnatomyM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_patologi_anatomy - LEFT JOIN m_doctor ON Other_PatologiAnatomyM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_PatologiAnatomyT_OrderDetailID = {$id} AND Other_PatologiAnatomyIsActive = 'Y' - GROUP BY Other_PatologiAnatomyID - ORDER BY Other_PatologiAnatomyID ASC - LIMIT 1"; - $query = $this->db_smartone->query($sql); - - if ($query) { - $rows = $query->row_array(); - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - - $sql = "SELECT So_ImageUploadPatologyAnatomyID as xid, - CONCAT('/one-media/one-image-nonlab/',So_ImageUploadPatologyAnatomyNewName) as image_url, - So_ImageUploadPatologyAnatomyType as type - FROM t_orderdetail - JOIN so_imageupload_patology_anatomy ON So_ImageUploadPatologyAnatomyT_OrderHeaderID= T_OrderDetailT_OrderHeaderID AND - So_ImageUploadPatologyAnatomyIsActive= 'Y' - WHERE - T_OrderDetailID = {$id} AND - T_OrderDetailIsActive = 'Y' - GROUP BY So_ImageUploadPatologyAnatomyID"; - $images = $this->db_smartone->query($sql)->result_array(); - $mikro = []; - $makro = []; - - foreach ($images as $key => $value) { - - if ($value['type'] == 'mikro') { - $mikro[] = $value; - } - if ($value['type'] == 'makro') { - $makro[] = $value; - } - } - - $rst = array('doctors' => $doctors, 'result' => $rows, 'mikro' => $mikro, 'makro' => $makro); - $this->sys_ok(["records" => $rst]); - } else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - - - function generateRandomString($length = 10) - { - $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; - $charactersLength = strlen($characters); - $randomString = ''; - for ($i = 0; $i < $length; $i++) { - $randomString .= $characters[rand(0, $charactersLength - 1)]; - } - return $randomString; - } - - function getcytologiresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT Other_CytologiDetailsID as xid, - Other_CytologiT_OrderDetailID as orderdetail_id, - Other_CytologiDetailsCode as code, - Other_CytologiDetailsLabel as label, - Other_CytologiDetailsResult as result, - IFNULL(Other_CytologiM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_CytologiM_DoctorID) OR Other_CytologiM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_cytologi - JOIN other_cytologidetails ON Other_CytologiDetailsOther_CytologiID = Other_CytologiID AND Other_CytologiDetailsIsActive = 'Y' - LEFT JOIN m_doctor ON Other_CytologiM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_CytologiT_OrderDetailID = {$id} AND Other_CytologiIsActive = 'Y' - GROUP BY Other_CytologiDetailsID - ORDER BY Other_CytologiDetailsCode ASC"; - //echo $sql; - $query = $this->db_smartone->query($sql); - - if ($query) { - $rows = $query->result_array(); - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $rst = array('doctors' => $doctors, 'results' => $rows); - $this->sys_ok(["records" => $rst]); - } else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - function getmikroresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT - Other_MikroID as xid, - Other_MikroHasilBiakan as hasil_biakan, - Other_MikroSampleTypeName as sample_name, - Other_MikroT_OrderDetailID as orderdetail_id, - Other_MikroResult as result_value, - '' as result_other, - IFNULL(T_BacteriaID,0) as T_BacteriaID, - IFNULL(T_BacteriaName,'') as T_BacteriaName, - '' as details, - IFNULL(Other_MikroM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_MikroM_DoctorID) OR Other_MikroM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_mikro - LEFT JOIN t_bacteria ON Other_MikroT_BacteriaID = T_BacteriaID - LEFT JOIN m_doctor ON Other_MikroM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_MikroT_OrderDetailID = {$id} AND Other_MikroIsActive = 'Y' - GROUP BY Other_MikroID"; - //echo $sql; - $query = $this->db_smartone->query($sql); - - if ($query) { - $row = $query->row_array(); - if ($row) { - if ($row['result_value'] != 'Positif' && $row['result_value'] != 'Negatif') { - $row['result_other'] = $row['result_value']; - $row['result_value'] = 'other'; - } - $sql = "SELECT '' as xno, - Other_MikroDetailsID as xid, - Other_MikroDetailsValue as value, - IF(Other_MikroDetailsNote = 'R','Y','N') as chx_r, - IF(Other_MikroDetailsNote = 'I','Y','N') as chx_i, - IF(Other_MikroDetailsNote = 'S','Y','N') as chx_s, - Other_MikroDetailsNote as note, - t_antibiotic.* - FROM other_mikrodetails - LEFT JOIN t_antibiotic ON Other_MikroDetailsT_AntibioticID = T_AntibioticID - WHERE - Other_MikroDetailsOther_MikroID = {$row['xid']} AND Other_MikroDetailsIsActive = 'Y' - GROUP BY Other_MikroDetailsID - ORDER BY T_AntibioticName ASC"; - //echo $sql; - $details = $this->db_smartone->query($sql)->result_array(); - if (details) { - foreach ($details as $k => $v) { - $details[$k]['xno'] = $k + 1; - } - } - $row['details'] = $details; - } else { - $row = array('xid' => '0', 'hasil_biakan' => '', 'result_value' => 'Negatif', 'sample_name' => '', 'orderdetail_id' => $id, 'T_BacteriaID' => '0', 'T_BacteriaName' => '0', 'details' => array(), 'doctor_id' => '0', 'doctor_name' => '0'); - } - } else { - $row = array('xid' => '0', 'hasil_biakan' => '', 'result_value' => 'Negatif', 'sample_name' => '', 'orderdetail_id' => $id, 'T_BacteriaID' => '0', 'T_BacteriaName' => '0', 'details' => array(), 'doctor_id' => '0', 'doctor_name' => '0'); - } - //print_r($row); - - - - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 7 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $sql = " - SELECT '0' as id, 'Belum memilih bakteria' as name - UNION - SELECT T_BacteriaID as id, T_BacteriaName as name - FROM t_bacteria - WHERE - T_BacteriaIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $bacteries = $this->db_smartone->query($sql)->result_array(); - $rst = array('doctors' => $doctors, 'bacteries' => $bacteries, 'results' => $row); - $this->sys_ok(["records" => $rst]); - } - function getantibiotics() - { - $prm = $this->sys_input; - $id = $prm["id"]; - $sql = " SELECT '' as xno, - 0 as xid, - '' as hasil_biakan, - '' as sample_name, - 0 as value, - 'Y' as chx_r, - 'N' as chx_i, - 'N' as chx_s, - 'R' as note, - t_antibiotic.* - FROM t_antibiotic - WHERE - T_AntibioticT_BacteriaID = {$prm['id']} AND T_AntibioticIsActive= 'Y' - ORDER BY T_AntibioticName ASC"; - //echo $sql; - $rows = $this->db_smartone->query($sql)->result_array(); - if (rows) { - foreach ($rows as $k => $v) { - $rows[$k]['xno'] = $k + 1; - } - } - - $this->sys_ok(["records" => $rows]); - } - function getlcprepresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - $sql = " SELECT Other_LcprepDetailsID as xid, - Other_LcprepID as header_id, - Other_LcprepT_orderDetailID as orderdetail_id, - Other_LcprepDetailsCode as code, - Other_LcprepDetailsLabel as label, - Other_LcprepDetailsResult as result, - IFNULL(Other_LcprepM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_LcprepM_DoctorID) OR Other_LcprepM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_lcprep - JOIN other_lcprepdetails ON Other_LcprepDetailsOther_LcprepID = Other_LcprepID AND Other_LcprepDetailsIsActive = 'Y' - LEFT JOIN m_doctor ON Other_LcprepM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_LcprepT_orderDetailID = {$id} AND Other_LcprepIsActive = 'Y' - GROUP BY Other_LcprepDetailsOther_LcprepID, Other_LcprepDetailsCode - ORDER BY Other_LcprepDetailsCode ASC"; - //echo $sql; - $rows = $this->db_smartone->query($sql)->result_array(); - if (!$rows) { - $rows = array( - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'A', - 'label' => 'DESKRIPSI', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ), - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'B', - 'label' => 'KESIMPULAN', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ) - ); - } - - $header_id = $rows[0]['header_id']; - $sql = "SELECT IFNULL(Other_LcprepAdekuasiID,0) as xid, - Lcprep_AdekuasiID as id, - Lcprep_AdekuasiLabel as name, - IF(ISNULL(Other_LcprepAdekuasiID),'N',Other_LcprepAdekuasiChex) as chex - FROM lcprep_adekuasi - LEFT JOIN other_lcprepadekuasi ON Other_LcprepAdekuasiLcprep_AdekuasiID = Lcprep_AdekuasiID AND - Other_LcprepAdekuasiOther_LcprepID = {$header_id} AND - Other_LcprepAdekuasiIsActive = 'Y' - WHERE - Lcprep_AdekuasiIsActive = 'Y' - GROUP BY Lcprep_AdekuasiID - ORDER BY Lcprep_AdekuasiOrder ASC - "; - //echo $sql; - $adeakuasi = $this->db_smartone->query($sql)->result_array(); - foreach ($adeakuasi as $kc => $vc) { - $adeakuasi[$kc]['chex'] = $vc['chex'] == 'N' ? false : true; - } - - $sql = "SELECT IFNULL(Other_LcprepKategoriUmumID,0) as xid, - Lcprep_KategoriUmumID as id, - Lcprep_KategoriUmumLabel as name, - IF(ISNULL(Other_LcprepKategoriUmumID),'N',Other_LcprepKategoriUmumChex) as chex - FROM lcprep_kategoriumum - LEFT JOIN other_lcprepkategoriumum ON Other_LcprepKategoriUmumLcprep_KategoriUmumID = Lcprep_KategoriUmumID AND - Other_LcprepKategoriUmumOther_LcprepID = {$header_id} AND - Other_LcprepKategoriUmumIsActive = 'Y' - WHERE - Lcprep_KategoriUmumIsActive = 'Y' - GROUP BY Lcprep_KategoriUmumID - "; - //echo $sql; - $kategoriumum = $this->db_smartone->query($sql)->result_array(); - foreach ($kategoriumum as $kc => $vc) { - $kategoriumum[$kc]['chex'] = $vc['chex'] == 'N' ? false : true; - } - - $sql = " - SELECT Lcprep_InterpretasiGroupID as group_id, - Lcprep_InterpretasiGroupName as group_name, - '' as subgroups - FROM lcprep_interpretasigroup - WHERE - Lcprep_InterpretasiGroupIsActive = 'Y' - "; - //echo $sql; - $interpretasi = $this->db_smartone->query($sql)->result_array(); - foreach ($interpretasi as $k => $v) { - $subgroups = array(); - $sql = "SELECT Lcprep_InterpretasiSubgroupID as subgroup_id, - Lcprep_InterpretasiSubgroupName as subgroup_name, - '' as childs - FROM lcprep_interpretasisubgroup - WHERE - Lcprep_InterpretasiSubgroupLcprep_InterpretasiGroupID = {$v['group_id']} AND Lcprep_InterpretasiSubgroupIsActive = 'Y'"; - //echo $sql; - $subgroups = $this->db_smartone->query($sql)->result_array(); - if (count($subgroups) > 0) { - foreach ($subgroups as $ki => $vi) { - $childs = array(); - $sql = "SELECT IFNULL(Other_LcprepInterpretasiID,0) as xid, - IFNULL(Other_LcprepInterpretasiChex,'N') as chex, - IFNULL(Other_LcprepInterpretasiValue,'') as value, - Lcprep_InterpretasiID as id, - Lcprep_InterpretasiLcprep_InterpretasiSubgroupID as subgroup_id, - Lcprep_InterpretasiCode as code, - Lcprep_InterpretasiName as name, - Lcprep_InterpretasiParentID as parent_id, - Lcprep_InterpretasiIsParent as is_parent, - Lcprep_InterpretasiHasResult as has_result, - Lcprep_InterpretasiTypeResult as type_result - FROM lcprep_interpretasi - LEFT JOIN other_lcprepinterpretasi ON Other_LcprepInterpretasiOther_LcprepID = {$header_id} AND - Other_LcprepInterpretasiLcprep_InterpretasiID = Lcprep_InterpretasiID AND - Other_LcprepInterpretasiIsActive = 'Y' - WHERE - Lcprep_InterpretasiLcprep_InterpretasiSubgroupID = {$vi['subgroup_id']} AND Lcprep_InterpretasiIsActive = 'Y' - GROUP BY Lcprep_InterpretasiID Order BY Lcprep_InterpretasiCode ASC"; - $childs = $this->db_smartone->query($sql)->result_array(); - if ($childs) { - foreach ($childs as $kc => $vc) { - $childs[$kc]['chex'] = $vc['chex'] == 'N' ? false : true; - } - } - $subgroups[$ki]['childs'] = $childs; - } - } - - $interpretasi[$k]['subgroups'] = $subgroups; - } - - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $rst = array('doctors' => $doctors, 'results' => $rows, 'adekuasi' => $adeakuasi, 'kategoriumum' => $kategoriumum, 'interpretasi' => $interpretasi); - $this->sys_ok(["records" => $rst]); - } - - function getpapsmearresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT Other_PapSmearDetailsID as xid, - Other_PapSmearID as header_id, - Other_PapSmearT_OrderDetailID as orderdetail_id, - Other_PapSmearDetailsCode as code, - Other_PapSmearDetailsLabel as label, - Other_PapSmearDetailsResult as result, - IFNULL(Other_PapSmearM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_PapSmearM_DoctorID) OR Other_PapSmearM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_papsmear - JOIN other_papsmeardetails ON Other_PapSmearDetailsOther_PapSmearID = Other_PapSmearID AND Other_PapSmearDetailsIsActive = 'Y' - LEFT JOIN m_doctor ON Other_PapSmearM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_PapSmearT_OrderDetailID = {$id} AND Other_PapSmearIsActive = 'Y' - GROUP BY Other_PapSmearDetailsID - ORDER BY Other_PapSmearDetailsCode ASC"; - //echo $sql; - $rows = $this->db_smartone->query($sql)->result_array(); - if (!$rows) { - $rows = array( - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'A', - 'label' => 'Makroskopik', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ), - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'B', - 'label' => 'Mikroskopik', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ), - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'C', - 'label' => 'Kesimpulan', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ) - ); - } - - $header_id = $rows[0]['header_id']; - $sql = "SELECT Other_PapSmearMaturasiID as xid, - Other_PapSmearMaturasiValue as value - FROM other_papsmearmaturasi - WHERE - Other_PapSmearMaturasiOther_PapSmearID = {$header_id} AND - Other_PapSmearMaturasiIsActive = 'Y' - "; - //echo $sql; - $dt_maturasi = $this->db_smartone->query($sql)->row_array(); - if (!$dt_maturasi) { - $maturasi = array('xid' => '0', 'value' => array('', '', '')); - } else { - $value = explode('/', $dt_maturasi['value']); - $maturasi = array('xid' => $dt_maturasi['xid'], 'value' => $value); - } - - $sql = "SELECT IFNULL(Other_PapSmearBahanID,0) as xid, - M_PapSmearBahanID as bahan_id, - M_PapSmearBahanName as name, - IF(ISNULL(Other_PapSmearBahanID),'N','Y') as selected - FROM m_papsmearbahan - LEFT JOIN other_papsmearbahan ON Other_PapSmearBahanM_PapSmearBahanID = M_PapSmearBahanID AND - Other_PapSmearBahanOther_PapSmearID = {$header_id} AND - Other_PapSmearBahanIsActive = 'Y' - WHERE - M_PapSmearBahanIsActive = 'Y' - ORDER BY M_PapSmearBahanID ASC - "; - //echo $sql; - $bahans = $this->db_smartone->query($sql)->result_array(); - - $sql = "SELECT IFNULL(Other_PapsmearCategoryID,0) as xid, - M_PapSmearCategoryID as category_id, - M_PapSmearCategoryName as name, - IF(ISNULL(Other_PapsmearCategoryID),'N','Y') as selected - FROM m_papsmearcategory - LEFT JOIN other_papsmearcategory ON Other_PapsmearCategoryM_PapSmearCategoryID = M_PapSmearCategoryID AND - Other_PapsmearCategoryOther_PapSmearID = {$header_id} AND - Other_PapsmearCategoryIsActive = 'Y' - WHERE - M_PapSmearCategoryIsActive = 'Y' - ORDER BY M_PapSmearCategoryID ASC - "; - //echo $sql; - $categories = $this->db_smartone->query($sql)->result_array(); - - $sql = "SELECT IFNULL(Other_PapSmearCheckID,0) as xid, - M_PapSmearCheckID as check_id, - M_PapSmearCheckLabel as name, - IF(ISNULL(Other_PapSmearCheckID),'N','Y') as selected, - Other_PapSmearCheckNote as note - FROM m_papsmearcheck - LEFT JOIN other_papsmearcheck ON Other_PapSmearCheckM_PapSmearCheckID = M_PapSmearCheckID AND - Other_PapSmearCheckOther_PapSmearID = {$header_id} AND - Other_PapSmearCheckIsActive = 'Y' - WHERE - M_PapSmearCheckIsActive = 'Y' - ORDER BY M_PapSmearCheckCode ASC - "; - $checks = $this->db_smartone->query($sql)->result_array(); - - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $rst = array('doctors' => $doctors, 'checks' => $checks, 'bahans' => $bahans, 'categories' => $categories, 'maturasi' => $maturasi, 'results' => $rows); - $this->sys_ok(["records" => $rst]); - } - - function saveresult_lcprep() - { - $prm = $this->sys_input; - $detail_id = $prm['detail_id']; - $doctor_id = $prm['doctor']; - $adekuasi = $prm['adekuasi']; - $kategoriumum = $prm['kategoriumum']; - $interpretasi = $prm['interpretasi']; - $results = $prm['results']; - - $userid = $this->sys_user['M_UserID']; - - $header_id = 0; - $sql = "SELECT * FROM other_lcprep WHERE Other_LcprepT_orderDetailID = {$detail_id} AND Other_LcprepIsActive = 'Y'"; - $dt_header = $this->db_smartone->query($sql)->row_array(); - if ($dt_header) { - $header_id = $dt_header['Other_LcprepID']; - } - if ($header_id == 0) { - $sql = "INSERT INTO other_lcprep( - Other_LcprepT_orderDetailID, - Other_LcprepM_DoctorID, - Other_LcprepUserID, - Other_LcprepCreated - ) - VALUES( - {$detail_id}, - {$doctor_id}, - {$userid}, - NOW() - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } else { - $sql = "UPDATE other_lcprep SET Other_LcprepM_DoctorID = {$doctor_id}, Other_LcprepUserID = {$userid} WHERE Other_LcprepID = {$header_id}"; - $this->db_smartone->query($sql); - } - - if ($adekuasi) { - foreach ($adekuasi as $k => $v) { - $selected = $v['chex'] ? 'Y' : 'N'; - if (intval($v['xid'] == 0)) { - $sql = "UPDATE other_lcprepadekuasi SET Other_LcprepAdekuasiIsActive = 'N' - WHERE - Other_LcprepAdekuasiOther_LcprepID = {$header_id} AND - Other_LcprepAdekuasiIsActive = 'Y' AND - Other_LcprepAdekuasiLcprep_AdekuasiID = {$v['id']}"; - $this->db_smartone->query($sql); - $sql = "INSERT INTO other_lcprepadekuasi ( - Other_LcprepAdekuasiOther_LcprepID, - Other_LcprepAdekuasiLcprep_AdekuasiID, - Other_LcprepAdekuasiChex, - Other_LcprepAdekuasiUserID, - Other_LcprepAdekuasiCreated - ) - VALUES( - {$header_id}, - {$v['id']}, - '{$selected}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - //echo $sql; - } - if (intval($v['xid'] != 0)) { - - $sql = "UPDATE other_lcprepadekuasi SET - Other_LcprepAdekuasiChex = '{$selected}', - Other_LcprepAdekuasiUserID = {$userid} - WHERE - Other_LcprepAdekuasiID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - - //echo $sql; - } - } - - if ($kategoriumum) { - foreach ($kategoriumum as $k => $v) { - $selected = $v['chex'] ? 'Y' : 'N'; - if (intval($v['xid'] == 0)) { - $sql = "UPDATE other_lcprepkategoriumum SET Other_LcprepKategoriUmumIsActive = 'N' - WHERE - Other_LcprepKategoriUmumOther_LcprepID = {$header_id} AND - Other_LcprepKategoriUmumLcprep_KategoriUmumID = {$v['id']} AND - Other_LcprepKategoriUmumIsActive = 'Y' - "; - $this->db_smartone->query($sql); - $sql = "INSERT INTO other_lcprepkategoriumum ( - Other_LcprepKategoriUmumOther_LcprepID, - Other_LcprepKategoriUmumLcprep_KategoriUmumID, - Other_LcprepKategoriUmumChex, - Other_LcprepKategoriUmumUserID, - Other_LcprepKategoriUmumCreated - ) - VALUES( - {$header_id}, - {$v['id']}, - '{$selected}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if (intval($v['xid'] != 0)) { - $sql = "UPDATE other_lcprepkategoriumum SET - Other_LcprepKategoriUmumChex = '{$selected}', - Other_LcprepKategoriUmumUserID = {$userid} - WHERE - Other_LcprepKategoriUmumID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - - //echo $sql; - } - } - - if ($results) { - foreach ($results as $k => $v) { - if (intval($v['xid'] == 0)) { - $sql = "UPDATE other_lcprepdetails SET Other_LcprepDetailsIsActive = 'N' - WHERE - Other_LcprepDetailsOther_LcprepID = {$header_id} AND - Other_LcprepDetailsCode = '{$v['code']}' AND - Other_LcprepDetailsIsActive = 'Y'"; - $this->db_smartone->query($sql); - $sql = "INSERT INTO other_lcprepdetails ( - Other_LcprepDetailsOther_LcprepID, - Other_LcprepDetailsCode, - Other_LcprepDetailsLabel, - Other_LcprepDetailsResult, - Other_LcprepDetailsUserID, - Other_LcprepDetailsCreated - ) - VALUES( - {$header_id}, - '{$v['code']}', - '{$v['label']}', - '{$v['result']}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if (intval($v['xid'] != 0)) { - $sql = "UPDATE other_lcprepdetails SET - Other_LcprepDetailsCode = '{$v['code']}', - Other_LcprepDetailsLabel = '{$v['label']}', - Other_LcprepDetailsResult = '{$v['result']}', - Other_LcprepDetailsUserID = {$userid} - WHERE - Other_LcprepDetailsID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - //echo $sql; - } - } - - if ($interpretasi) { - foreach ($interpretasi as $k => $v) { - if (count($v['subgroups']) > 0) { - foreach ($v['subgroups'] as $ik => $iv) { - if (count($iv['childs']) > 0) { - foreach ($iv['childs'] as $iik => $iiv) { - if (intval($iiv['xid'] == 0)) { - $chex = $iiv['chex'] ? 'Y' : 'N'; - $sql = "UPDATE other_lcprepinterpretasi SET Other_LcprepInterpretasiIsActive = 'N' - WHERE - Other_LcprepInterpretasiOther_LcprepID = {$header_id} AND - Other_LcprepInterpretasiLcprep_InterpretasiID = '{$iiv['id']}' AND - Other_LcprepInterpretasiIsActive = 'Y'"; - $this->db_smartone->query($sql); - $sql = "INSERT INTO other_lcprepinterpretasi ( - Other_LcprepInterpretasiOther_LcprepID, - Other_LcprepInterpretasiLcprep_InterpretasiID, - Other_LcprepInterpretasiChex, - Other_LcprepInterpretasiValue, - Other_LcprepInterpretasiUserID, - Other_LcprepInterpretasiCreated - ) - VALUES( - {$header_id}, - '{$iiv['id']}', - '{$chex}', - '{$iiv['value']}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - - if (intval($iiv['xid'] != 0)) { - $chex = $iiv['chex'] ? 'Y' : 'N'; - $sql = "UPDATE other_lcprepinterpretasi SET - Other_LcprepInterpretasiChex = '{$chex}', - Other_LcprepInterpretasiValue = '{$iiv['value']}', - Other_LcprepInterpretasiUserID = {$userid} - WHERE - Other_LcprepInterpretasiID = {$iiv['xid']}"; - $this->db_smartone->query($sql); - //echo $sql; - - } - } - } - } - } - //echo $sql; - } - } - - - $result = array("total" => 1, "records" => array(), "sql" => ''); - $this->sys_ok($result); - exit; - } - - function saveresult_papsmear() - { - $prm = $this->sys_input; - $detail_id = $prm['detail_id']; - $doctor_id = $prm['doctor']; - $checks = $prm['checks']; - $maturasi = $prm['maturasi']; - $bahans = $prm['bahans']; - $categories = $prm['categories']; - $results = $prm['results']; - - $userid = $this->sys_user['M_UserID']; - - $header_id = 0; - $sql = "SELECT * FROM other_papsmear WHERE Other_PapSmearT_OrderDetailID = {$detail_id} AND Other_PapSmearIsActive = 'Y'"; - $dt_header = $this->db_smartone->query($sql)->row_array(); - if ($dt_header) { - $header_id = $dt_header['Other_PapSmearID']; - } - if ($header_id == 0) { - $sql = "INSERT INTO other_papsmear( - Other_PapSmearT_OrderDetailID, - Other_PapSmearM_DoctorID, - Other_PapSmearUserID, - Other_PapSmearCreated - ) - VALUES( - {$detail_id}, - {$doctor_id}, - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } else { - $sql = "UPDATE other_papsmear SET Other_PapSmearM_DoctorID = {$doctor_id}, Other_PapSmearUserID = {$userid} WHERE Other_PapSmearID = {$header_id}"; - $this->db_smartone->query($sql); - } - - if ($checks) { - foreach ($checks as $k => $v) { - if (intval($v['xid']) == 0 && $v['selected'] === 'Y') { - $sql = "INSERT INTO other_papsmearcheck ( - Other_PapSmearCheckOther_PapSmearID, - Other_PapSmearCheckM_PapSmearCheckID, - Other_PapSmearCheckNote, - Other_PapSmearCheckUserID, - Other_PapSmearCheckCreated - ) - VALUES( - {$header_id}, - {$v['check_id']}, - '{$v['note']}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if (intval($v['xid']) != 0 && $v['selected'] === 'N') { - $sql = "UPDATE other_papsmearcheck SET - Other_PapSmearCheckIsActive = 'N', - Other_PapSmearCheckUserID = {$userid} - WHERE - Other_PapSmearCheckID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - if (intval($v['xid']) != 0 && $v['selected'] === 'Y') { - $sql = "UPDATE other_papsmearcheck SET - Other_PapSmearCheckNote = '{$v['note']}', - Other_PapSmearCheckUserID = {$userid} - WHERE - Other_PapSmearCheckID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - //echo $sql; - } - } - - if ($maturasi) { - if (intval($maturasi['xid']) == 0) { - $value = join("/", $maturasi['value']); - $sql = "INSERT INTO other_papsmearmaturasi ( - Other_PapSmearMaturasiOther_PapSmearID, - Other_PapSmearMaturasiValue, - Other_PapSmearMaturasiUserID, - Other_PapSmearMaturasiCreated - ) - VALUE( - {$header_id}, - '{$value}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - //echo $sql; - } - if (intval($maturasi['xid']) != 0) { - $value = join("/", $maturasi['value']); - $sql = "UPDATE other_papsmearmaturasi SET - Other_PapSmearMaturasiValue = '{$value}', - Other_PapSmearMaturasiUserID = {$userid} - WHERE - Other_PapSmearMaturasiID = {$maturasi['xid']}"; - // echo $sql; - $this->db_smartone->query($sql); - } - } - - if ($bahans) { - foreach ($bahans as $k => $v) { - if (intval($v['xid']) == 0 && $v['selected'] === 'Y') { - $sql = "INSERT INTO other_papsmearbahan ( - Other_PapSmearBahanOther_PapSmearID, - Other_PapSmearBahanM_PapSmearBahanID, - Other_PapSmearBahanUserID, - Other_PapSmearBahanCreated - ) - VALUES( - {$header_id}, - {$v['bahan_id']}, - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if (intval($v['xid']) != 0 && $v['selected'] === 'N') { - $sql = "UPDATE other_papsmearbahan SET - Other_PapSmearBahanIsActive = 'N', - Other_PapsmearCategoryUserID = {$userid} - WHERE - Other_PapSmearBahanID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - if (intval($v['xid']) != 0 && $v['selected'] === 'Y') { - $sql = "UPDATE other_papsmearbahan SET - Other_PapSmearBahanIsActive = 'Y', - Other_PapsmearCategoryUserID = {$userid} - WHERE - Other_PapSmearBahanID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - //echo $sql; - } - } - - if ($categories) { - foreach ($categories as $k => $v) { - if (intval($v['xid']) == 0 && $v['selected'] === 'Y') { - $sql = "INSERT INTO other_papsmearcategory ( - Other_PapsmearCategoryOther_PapSmearID, - Other_PapsmearCategoryM_PapSmearCategoryID, - Other_PapsmearCategoryUserID, - Other_PapsmearCategoryCreated - ) - VALUES( - {$header_id}, - {$v['category_id']}, - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if (intval($v['xid']) != 0 && $v['selected'] === 'N') { - $sql = "UPDATE other_papsmearcategory SET - Other_PapsmearCategoryIsActive = 'N', - Other_PapsmearCategoryUserID = {$userid} - WHERE - Other_PapsmearCategoryID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - //echo $sql; - if (intval($v['xid']) != 0 && $v['selected'] === 'Y') { - $sql = "UPDATE other_papsmearcategory SET - Other_PapsmearCategoryIsActive = 'Y', - Other_PapsmearCategoryUserID = {$userid} - WHERE - Other_PapsmearCategoryID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - } - } - - if ($results) { - foreach ($results as $k => $v) { - if (intval($v['xid']) == 0) { - $sql = "INSERT INTO other_papsmeardetails ( - Other_PapSmearDetailsOther_PapSmearID, - Other_PapSmearDetailsCode, - Other_PapSmearDetailsLabel, - Other_PapSmearDetailsResult, - Other_PapSmearDetailsUserID, - Other_PapSmearDetailsCreated - ) - VALUES( - {$header_id}, - '{$v['code']}', - '{$v['label']}', - '{$v['result']}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if (intval($v['xid']) != 0) { - $sql = "UPDATE other_papsmeardetails SET - Other_PapSmearDetailsCode = '{$v['code']}', - Other_PapSmearDetailsLabel = '{$v['label']}', - Other_PapSmearDetailsResult = '{$v['result']}', - Other_PapSmearDetailsUserID = {$userid} - WHERE - Other_PapSmearDetailsID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - //echo $sql; - } - } - - $result = array("total" => 1, "records" => array(), "sql" => ''); - $this->sys_ok($result); - exit; - } - - function saveresult_fna() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = $inp['doctor']; - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - if ($prm[0]['xid'] == '0') { - $sql = "INSERT INTO other_fna( - Other_FNAM_DoctorID, - Other_FNAT_OrderDetailID, - Other_FNAUserID, - Other_FNACreated - ) - VALUES( - {$doctor_id}, - {$prm[0]['orderdetail_id']}, - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } else { - $sql = "SELECT * FROM other_fna WHERE Other_FNAT_OrderDetailID = {$prm[0]['orderdetail_id']} AND Other_FNAIsActive = 'Y'"; - $data_header = $this->db_smartone->query($sql)->row_array(); - $header_id = $data_header['Other_FNAID']; - $sql = "UPDATE other_fna SET - Other_FNAM_DoctorID = {$doctor_id}, - Other_FNAUserID = {$userid} - WHERE - Other_FNAID = {$header_id}"; - $this->db_smartone->query($sql); - } - foreach ($prm as $k => $v) { - if ($v['xid'] == '0') { - $results = str_replace("'", "\\'", $v['result']); - $sql = "INSERT INTO other_fnadetails( - Other_FNADetailsOther_FNAID , - Other_FNADetailsCode, - Other_FNADetailsLabel, - Other_FNADetailsResult, - Other_FNADetailsCreated, - Other_FNADetailsUserID - ) - VALUES( - {$header_id}, - '{$v['code']}', - '{$v['label']}', - '{$results}', - NOW(), - {$userid} - )"; - $query = $this->db_smartone->query($sql); - } else { - $results = str_replace("'", "\\'", $v['result']); - $sql = "UPDATE other_fnadetails SET - Other_FNADetailsResult = '{$results}', - Other_FNADetailsUserID = {$userid} - WHERE - Other_FNADetailsID = {$v['xid']}"; - $query = $this->db_smartone->query($sql); - } - } - - $result = array("total" => 1, "records" => array(), "sql" => ''); - $this->sys_ok($result); - exit; - } - - function saveresult_cytologi() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = $inp['doctor']; - - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - if ($prm[0]['xid'] == '0') { - $sql = "INSERT INTO other_cytologi( - Other_CytologiT_OrderDetailID, - Other_CytologiM_DoctorID, - Other_CytologiUserID, - Other_CytologiCreated - ) - VALUES( - {$prm[0]['orderdetail_id']}, - {$doctor_id}, - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } else { - $sql = "SELECT * FROM other_cytologi WHERE Other_CytologiT_OrderDetailID = {$prm[0]['orderdetail_id']} AND Other_CytologiIsActive = 'Y'"; - $data_header = $this->db_smartone->query($sql)->row_array(); - $header_id = $data_header['Other_CytologiID']; - $sql = "UPDATE other_cytologi SET - Other_CytologiM_DoctorID = {$doctor_id}, - Other_CytologiUserID = {$userid} - WHERE - Other_CytologiID = {$header_id}"; - $this->db_smartone->query($sql); - } - foreach ($prm as $k => $v) { - if ($v['xid'] == '0') { - $results = str_replace("'", "\\'", $v['result']); - $sql = "INSERT INTO other_cytologidetails( - Other_CytologiDetailsOther_CytologiID , - Other_CytologiDetailsCode, - Other_CytologiDetailsLabel, - Other_CytologiDetailsResult, - Other_CytologiDetailsCreated, - Other_CytologiDetailsUserID - ) - VALUES( - {$header_id}, - '{$v['code']}', - '{$v['label']}', - '{$results}', - NOW(), - {$userid} - )"; - $query = $this->db_smartone->query($sql); - } else { - $results = str_replace("'", "\\'", $v['result']); - $sql = "UPDATE other_cytologidetails SET - Other_CytologiDetailsResult = '{$results}', - Other_CytologiDetailsUserID = {$userid} - WHERE - Other_CytologiDetailsID = {$v['xid']}"; - $query = $this->db_smartone->query($sql); - } - } - - $result = array("total" => 1, "records" => array(), "sql" => ''); - $this->sys_ok($result); - exit; - } - - function saveresult_mikro() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = $inp['doctor']; - $backteria_id = $inp['bacteria']; - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - - if ($inp['result_value'] != 'Negatif' && $inp['result_value'] != 'Positif') { - $prm['result_value'] = $prm['result_other']; - } else { - $prm['result_value'] = $inp['result_value']; - } - - if ($prm['xid'] == '0') { - $sql = "INSERT INTO other_mikro( - Other_MikroM_DoctorID, - Other_MikroResult, - Other_MikroT_BacteriaID, - Other_MikroT_OrderDetailID, - Other_MikroHasilBiakan, - Other_MikroSampleTypeName, - Other_MikroUserID, - Other_MikroCreated - ) - VALUES( - {$doctor_id}, - '{$prm['result_value']}', - {$backteria_id}, - {$prm['orderdetail_id']}, - '{$prm['hasil_biakan']}', - '{$prm['sample_name']}', - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } else { - $sql = "SELECT * FROM other_mikro WHERE Other_MikroT_OrderDetailID = {$prm['orderdetail_id']} AND Other_MikroIsActive = 'Y'"; - $data_header = $this->db_smartone->query($sql)->row_array(); - $header_id = $data_header['Other_MikroID']; - $sql = "UPDATE other_mikro SET - Other_MikroResult = '{$prm['result_value']}', - Other_MikroM_DoctorID = {$doctor_id}, - Other_MikroT_BacteriaID = {$backteria_id}, - Other_MikroHasilBiakan = '{$prm['hasil_biakan']}', - Other_MikroSampleTypeName = '{$prm['sample_name']}', - Other_MikroUserID = {$userid} - WHERE - Other_MikroID = {$header_id}"; - //echo $sql; - $this->db_smartone->query($sql); - } - - - - $sql = "UPDATE other_mikrodetails SET Other_MikroDetailsIsActive = 'N', Other_MikroDetailsUserID = 0 WHERE Other_MikroDetailsOther_MikroID = {$header_id}"; - $this->db_smartone->query($sql); - - $results = $prm['details']; - if ($inp['result_value'] == 'Positif') { - foreach ($results as $k => $v) { - if ($v['xid'] == '0') { - $sql = "INSERT INTO other_mikrodetails( - Other_MikroDetailsOther_MikroID , - Other_MikroDetailsT_AntibioticID, - Other_MikroDetailsValue, - Other_MikroDetailsNote, - Other_MikroDetailsCreated, - Other_MikroDetailsUserID - ) - VALUES( - {$header_id}, - '{$v['T_AntibioticID']}', - '{$v['value']}', - '{$v['note']}', - NOW(), - {$userid} - )"; - $query = $this->db_smartone->query($sql); - } else { - $sql = "UPDATE other_mikrodetails SET - Other_MikroDetailsT_AntibioticID = '{$v['T_AntibioticID']}', - Other_MikroDetailsValue = '{$v['value']}', - Other_MikroDetailsNote = '{$v['note']}', - Other_MikroDetailsIsActive = 'Y', - Other_MikroDetailsUserID = {$userid} - WHERE - Other_MikroDetailsID = {$v['xid']}"; - //echo $sql; - $query = $this->db_smartone->query($sql); - } - } - } - - - $result = array("total" => 1, "records" => array(), "sql" => ''); - $this->sys_ok($result); - exit; - } - - - function get_doctors_preparasi_sperma() - { - $prm = $this->sys_input; - // $id = $prm["id"]; - - $sql = " SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 10 AND - M_DoctorSOIsActive = 'Y' - ORDER BY M_DoctorName ASC"; - //echo $sql; - $query = $this->db_smartone->query($sql); - $rows = $query->result_array(); - $sql = " - SELECT '0' as id, 'Belum memilih metode' as name - UNION - SELECT M_MethodeSpermaID as id, M_MethodeSpermaName as name - FROM m_methodesperma - WHERE - M_MethodeSpermaIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $methodes = $this->db_smartone->query($sql)->result_array(); - - - $this->sys_ok(["records" => $rows, "methodes" => $methodes]); - } - - - function getpreparasispermaresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT other_preparasisperma.*, - Other_PreparasiSpermaID as xid, - Other_PreparasiSpermaT_OrderDetailID as orderdetail_id, - IFNULL(Other_PreparasiSpermaM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_PreparasiSpermaM_DoctorID) OR Other_PreparasiSpermaM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name, - IFNULL(M_MethodeSpermaID,0) as methode_id, - IFNULL(M_MethodeSpermaName,'') as methode_name - FROM other_preparasisperma - LEFT JOIN m_doctor ON Other_PreparasiSpermaM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - LEFT JOIN m_methodesperma ON Other_PreparasiSpermaM_MethodeSpermaID = M_MethodeSpermaID AND - M_MethodeSpermaIsActive = 'Y' - WHERE - Other_PreparasiSpermaT_OrderDetailID = {$id} AND Other_PreparasiSpermaIsActive = 'Y' - GROUP BY Other_PreparasiSpermaID"; - $query = $this->db_smartone->query($sql); - - if ($query) { - $rows = $query->row_array(); - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 10 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $sql = " - SELECT '0' as id, 'Belum memilih metode' as name - UNION - SELECT M_MethodeSpermaID as id, M_MethodeSpermaName as name - FROM m_methodesperma - WHERE - M_MethodeSpermaIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $methodes = $this->db_smartone->query($sql)->result_array(); - $images = array(); - $sql = "SELECT Other_PreparasiSpermaImgID as xid, - Other_PreparasiSpermaImgType as type, - CONCAT('/one-media/one-image-nonlab/',Other_PreparasiSpermaImgNewName) as image_url - FROM t_orderdetail - JOIN other_preparasisperma_img ON Other_PreparasiSpermaImgT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND - Other_PreparasiSpermaImgIsActive = 'Y' - WHERE - T_OrderDetailID = {$id} AND - T_OrderDetailIsActive = 'Y' - GROUP BY Other_PreparasiSpermaImgID"; - //echo $sql; - $images = $this->db_smartone->query($sql)->result_array(); - - $rst = array('doctors' => $doctors, 'methodes' => $methodes, 'results' => $rows, 'images' => $images); - $this->sys_ok(["records" => $rst]); - } else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - - function uploadimage_preparasi_sperma() - { - if (! $this->isLogin) { - $this->sys_error("Invalid Token"); - exit; - } - - $userid = $this->sys_user["M_UserID"]; - $data = []; - //print_r($_SERVER); - - $prm = $this->sys_input; - $orderid = $this->input->post('orderid'); - $type = $this->input->post('type'); - $labnumber = $this->input->post('labnumber'); - $sql = "UPDATE other_preparasisperma_img SET - Other_PreparasiSpermaImgIsActive = 'N', - Other_PreparasiSpermaImgUserID = {$userid} - WHERE - Other_PreparasiSpermaImgT_OrderHeaderID = {$orderid} AND - Other_PreparasiSpermaImgType = '{$type}'"; - //echo $sql; - $this->db_onedev->query($sql); - //$config['upload_path'] = 'assets/'; - - $path = '/home/one/project/one/one-media/one-image-nonlab/'; - //echo $path; - $config['upload_path'] = $path; - $config['allowed_types'] = 'jpg|jpeg|png|gif'; - - $config['max_size'] = '10000'; - $count = count($_FILES['files']['name']); - //echo $count; - $this->load->library('upload', $config); - - $error = []; - for ($i = 0; $i < $count; $i++) { - - - if (!empty($_FILES['files']['name'][$i])) { - - - - $_FILES['file']['name'] = $_FILES['files']['name'][$i]; - - $_FILES['file']['type'] = $_FILES['files']['type'][$i]; - - $_FILES['file']['tmp_name'] = $_FILES['files']['tmp_name'][$i]; - - $_FILES['file']['error'] = $_FILES['files']['error'][$i]; - - $_FILES['file']['size'] = $_FILES['files']['size'][$i]; - - - - $namex = $orderid . '-' . $labnumber . '-' . $this->generateRandomString(5); - //echo $namex; - - $config['file_name'] = $namex; - $this->upload->initialize($config); - //echo $config['file_name'] ; - - - - - - if ($this->upload->do_upload('file')) { - - $uploadData = $this->upload->data(); - - $filename = $uploadData['file_name']; - //echo $filename; - - - $sql = "INSERT INTO other_preparasisperma_img ( - Other_PreparasiSpermaImgT_OrderHeaderID, - Other_PreparasiSpermaImgType, - Other_PreparasiSpermaImgOldName, - Other_PreparasiSpermaImgNewName, - Other_PreparasiSpermaImgCreated, - Other_PreparasiSpermaImgUserID - ) - VALUES( - {$orderid}, - '{$type}', - '{$_FILES['files']['name'][$i]}', - '{$filename}', - NOW(), - {$userid} - - )"; - //echo $sql; - $this->db_onedev->query($sql); - $xlast_id = $this->db_onedev->insert_id(); - $data['totalFiles'][] = array('xid' => $xlast_id, 'type' => $type, 'image_url' => '/one-media/one-image-nonlab/' . $filename); - } else { - $error = array('error' => $this->upload->display_errors()); - } - } - } - - $result = array("total" => count($data['totalFiles']), "records" => $data['totalFiles'], 'errors' => $error); - $this->sys_ok($result); - } - - - function saveresult_preparasi_sperma() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = $inp['doctor']; - $orderdetail_id = $inp['orderdetailid']; - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - if ($prm['xid'] == '0') { - $sql = "INSERT INTO other_preparasisperma( - Other_PreparasiSpermaM_DoctorID, - Other_PreparasiSpermaT_OrderDetailID, - Other_PreparasiSpermaPreMotilitasA, - Other_PreparasiSpermaPreMotilitasB, - Other_PreparasiSpermaPreMotilitasC, - Other_PreparasiSpermaPreKonsentrasi, - Other_PreparasiSpermaPreKontaminan, - Other_PreparasiSpermaPostMotilitasA, - Other_PreparasiSpermaPostMotilitasB, - Other_PreparasiSpermaPostMotilitasC, - Other_PreparasiSpermaPostKonsentrasi, - Other_PreparasiSpermaPostKontaminan, - Other_PreparasiSpermaPreVolume, - Other_PreparasiSpermaPostVolume, - Other_PreparasiSpermaM_MethodeSpermaID, - Other_PreparasiSpermaNote, - Other_PreparasiSpermaUserID, - Other_PreparasiSpermaCreated - ) - VALUES( - {$doctor_id}, - {$orderdetail_id}, - '{$prm['Other_PreparasiSpermaPreMotilitasA']}', - '{$prm['Other_PreparasiSpermaPreMotilitasB']}', - '{$prm['Other_PreparasiSpermaPreMotilitasC']}', - '{$prm['Other_PreparasiSpermaPreKonsentrasi']}', - '{$prm['Other_PreparasiSpermaPreKontaminan']}', - '{$prm['Other_PreparasiSpermaPostMotilitasA']}', - '{$prm['Other_PreparasiSpermaPostMotilitasB']}', - '{$prm['Other_PreparasiSpermaPostMotilitasC']}', - '{$prm['Other_PreparasiSpermaPostKonsentrasi']}', - '{$prm['Other_PreparasiSpermaPostKontaminan']}', - '{$prm['Other_PreparasiSpermaPreVolume']}', - '{$prm['Other_PreparasiSpermaPostVolume']}', - '{$prm['Other_PreparasiSpermaM_MethodeSpermaID']}', - '{$prm['Other_PreparasiSpermaNote']}', - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } else { - $sql = "SELECT * FROM other_preparasisperma WHERE Other_PreparasiSpermaT_OrderDetailID = {$orderdetail_id} AND Other_PreparasiSpermaIsActive = 'Y'"; - $data_header = $this->db_smartone->query($sql)->row_array(); - $header_id = $data_header['Other_PreparasiSpermaID']; - $sql = "UPDATE other_preparasisperma SET - Other_PreparasiSpermaM_DoctorID = {$doctor_id}, - Other_PreparasiSpermaPreMotilitasA = '{$prm['Other_PreparasiSpermaPreMotilitasA']}', - Other_PreparasiSpermaPreMotilitasB = '{$prm['Other_PreparasiSpermaPreMotilitasB']}', - Other_PreparasiSpermaPreMotilitasC = '{$prm['Other_PreparasiSpermaPreMotilitasC']}', - Other_PreparasiSpermaPreKonsentrasi = '{$prm['Other_PreparasiSpermaPreKonsentrasi']}', - Other_PreparasiSpermaPreKontaminan = '{$prm['Other_PreparasiSpermaPreKontaminan']}', - Other_PreparasiSpermaPostMotilitasA = '{$prm['Other_PreparasiSpermaPostMotilitasA']}', - Other_PreparasiSpermaPostMotilitasB = '{$prm['Other_PreparasiSpermaPostMotilitasB']}', - Other_PreparasiSpermaPostMotilitasC = '{$prm['Other_PreparasiSpermaPostMotilitasC']}', - Other_PreparasiSpermaPostKonsentrasi = '{$prm['Other_PreparasiSpermaPostKonsentrasi']}', - Other_PreparasiSpermaPostKontaminan = '{$prm['Other_PreparasiSpermaPostKontaminan']}', - Other_PreparasiSpermaPreVolume = '{$prm['Other_PreparasiSpermaPreVolume']}', - Other_PreparasiSpermaPostVolume = '{$prm['Other_PreparasiSpermaPostVolume']}', - Other_PreparasiSpermaM_MethodeSpermaID = '{$prm['Other_PreparasiSpermaM_MethodeSpermaID']}', - Other_PreparasiSpermaNote = '{$prm['Other_PreparasiSpermaNote']}', - Other_PreparasiSpermaUserID = {$userid} - WHERE - Other_PreparasiSpermaID = {$header_id}"; - $this->db_smartone->query($sql); - } - - - $result = array("total" => 1, "records" => array(), "sql" => ''); - $this->sys_ok($result); - exit; - } - - function getdnafragmentasiresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT other_dnafragmentasi.*, - Other_DnaFragmentasiID as xid, - Other_DnaFragmentasiT_OrderDetailID as orderdetail_id, - IFNULL(Other_DnaFragmentasiM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_DnaFragmentasiM_DoctorID) OR Other_DnaFragmentasiM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name, - IFNULL(Other_DnaFragmentasiOther_DnaFragmentasiMethodeID,0) as methode_id, - IFNULL(Other_DnaFragmentasiMethodeName,'') as methode_name, - Other_DnaFragmentasiHaloLuas as halo_luas, - Other_DnaFragmentasiHaloSedang as halo_sedang, - Other_DnaFragmentasiHaloSempit as halo_sempit, - Other_DnaFragmentasiTanpaHalo as tanpa_halo, - Other_DnaFragmentasiDFI as dfi, - Other_DnaFragmentasiKesimpulan as kesimpulan, - Other_DnaFragmentasiCatatan as catatan - FROM other_dnafragmentasi - LEFT JOIN m_doctor ON Other_DnaFragmentasiM_DoctorID = M_DoctorID - LEFT JOIN other_dnafragmentasimethode ON Other_DnaFragmentasiOther_DnaFragmentasiMethodeID = Other_DnaFragmentasiMethodeID - WHERE - Other_DnaFragmentasiT_OrderDetailID = {$id} AND Other_DnaFragmentasiIsActive = 'Y' - GROUP BY Other_DnaFragmentasiID - LIMIT 1"; - //echo $sql; - $query = $this->db_smartone->query($sql); - - if ($query) { - $rows = $query->row_array(); - if (!$rows) { - $rows = array( - 'xid' => 0, - 'orderdetail_id' => $id, - 'doctor_id' => 0, - 'doctor_name' => '', - 'methode_id' => 0, - 'methode_name' => '', - 'halo_luas' => '', - 'halo_sedang' => '', - 'tanpa_halo' => '', - 'dfi' => '', - 'kesimpulan' => '', - 'catatan' => '' - ); - } - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID - WHERE - M_DoctorSONat_SubGroupID = 4 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - - $sql = " - SELECT '0' as id, 'Belum memilih metode' as name - UNION - SELECT Other_DnaFragmentasiMethodeID as id, Other_DnaFragmentasiMethodeName as name - FROM other_dnafragmentasimethode - WHERE - Other_DnaFragmentasiMethodeIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $methodes = $this->db_smartone->query($sql)->result_array(); - - - $rst = array('doctors' => $doctors, 'methodes' => $methodes, 'results' => $rows); - $this->sys_ok(["records" => $rst]); - } else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - function saveresult_dnafragmentasi() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = $inp['doctor']['id']; - $methode_id = $inp['methode']['id']; - $orderdetail_id = $inp['results']['orderdetail_id']; - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - if (intval($prm['xid']) == 0) { - $sql = "INSERT INTO other_dnafragmentasi( - Other_DnaFragmentasiT_OrderDetailID, - Other_DnaFragmentasiM_DoctorID, - Other_DnaFragmentasiOther_DnaFragmentasiMethodeID, - Other_DnaFragmentasiHaloLuas, - Other_DnaFragmentasiHaloSedang, - Other_DnaFragmentasiHaloSempit, - Other_DnaFragmentasiTanpaHalo, - Other_DnaFragmentasiDFI, - Other_DnaFragmentasiKesimpulan, - Other_DnaFragmentasiCatatan, - Other_DnaFragmentasiUserID, - Other_DnaFragmentasiLastUpdated - ) - VALUES( - {$orderdetail_id}, - {$doctor_id}, - {$methode_id}, - '{$prm['halo_luas']}', - '{$prm['halo_sedang']}', - '{$prm['halo_sempit']}', - '{$prm['tanpa_halo']}', - '{$prm['dfi']}', - '{$prm['kesimpulan']}', - '{$prm['catatan']}', - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } else { - $sql = "UPDATE other_dnafragmentasi SET - Other_DnaFragmentasiT_OrderDetailID = {$orderdetail_id}, - Other_DnaFragmentasiM_DoctorID = {$doctor_id}, - Other_DnaFragmentasiOther_DnaFragmentasiMethodeID = '{$methode_id}', - Other_DnaFragmentasiHaloLuas = '{$prm['halo_luas']}', - Other_DnaFragmentasiHaloSedang = '{$prm['halo_sedang']}', - Other_DnaFragmentasiHaloSempit = '{$prm['halo_sempit']}', - Other_DnaFragmentasiTanpaHalo = '{$prm['tanpa_halo']}', - Other_DnaFragmentasiDFI = '{$prm['dfi']}', - Other_DnaFragmentasiKesimpulan = '{$prm['kesimpulan']}', - Other_DnaFragmentasiCatatan = '{$prm['catatan']}', - Other_DnaFragmentasiLastUpdated = NOW(), - Other_DnaFragmentasiUserID = {$userid} - WHERE - Other_DnaFragmentasiID = {$prm['xid']}"; - //echo $sql; - $this->db_smartone->query($sql); - } - - - $result = array("total" => 1, "records" => array(), "sql" => ''); - $this->sys_ok($result); - exit; - } -} +db_smartone = $this->load->database("onedev", true); + $this->load->helper(array('form', 'url')); + } + function getMethodeID($natTestID) + { + $sql = "select M_MethodePriorityNat_MethodeID MethodeID, Nat_MethodeName + from + m_methode_priority + join nat_methode on Nat_MethodeID = M_MethodePriorityNat_MethodeID + and Nat_MethodeIsActive = 'Y' + join m_instrumentmethode on M_InstrumentMethodeNat_MethodeID = Nat_MethodeID and M_InstrumentMethodeIsActive = 'Y' + join nat_instrument on M_InstrumentMethodeNat_InstrumentID = Nat_InstrumentID + and Nat_InstrumentIsActive ='Y' + where M_MethodePriorityIsActive = 'Y' + and M_MethodePriorityNat_TestID = $natTestID + and M_MethodePriorityM_DayOfWeekID = dayofweek(now()) + order by M_MethodePriorityNumber desc + limit 0,1 "; + $qry = $this->db->query($sql); + if ($qry) { + $rows = $qry->result_array(); + if (count($rows) > 0) return array($rows[0]["MethodeID"], $rows[0]["Nat_MethodeName"]); + } + //2nd + $sql = "select + M_InstrumentMethodeNat_MethodeID MethodeID, Nat_MethodeName + from m_instrumentmethode + join nat_methode on M_InstrumentMethodeNat_MethodeID = Nat_MethodeID + and Nat_MethodeIsActive = 'Y' + join nat_instrument on M_InstrumentMethodeNat_InstrumentID = Nat_InstrumentID + and Nat_InstrumentIsActive ='Y' + where M_InstrumentMethodeNat_TestID = $natTestID + and M_InstrumentMethodeIsActive = 'Y' + order by M_InstrumentMethodePriority desc + limit 0,1"; + $qry = $this->db->query($sql); + if ($qry) { + $rows = $qry->result_array(); + if (count($rows) > 0) return array($rows[0]["MethodeID"], $rows[0]["Nat_MethodeName"]); + } + // + $sql = "select Nat_NormalValueNat_MethodeID MethodeID, Nat_MethodeName + from + nat_normalvalue + join nat_methode on Nat_NormalValueNat_MethodeID = Nat_MethodeID + and Nat_MethodeIsActive = 'Y' + where Nat_NormalValueNat_TestID = $natTestID + and Nat_NormalValueIsActive = 'Y' + order by Nat_NormalValueID + limit 0,1"; + $qry = $this->db->query($sql); + if ($qry) { + $rows = $qry->result_array(); + if (count($rows) > 0) return array($rows[0]["MethodeID"], $rows[0]["Nat_MethodeName"]); + } + return array(0, ""); + } + function get_normal_value($methodeID, $natTestID, $sexID, $ageInDay) + { + $this->load->library('ibl_sampling_normal'); + return $this->ibl_sampling_normal->get_normal_value_id($methodeID, $natTestID, $sexID, $ageInDay); + } + return 0; + } + function fn_fix_normal($order_id) + { + $sql = "select + T_OrderDetailID, M_PatientM_SexID, fn_global_age_count_day(M_PatientDOB, date(T_OrderHeaderDate)) Dob , + T_TestNat_TestID + from t_orderheader + join m_patient on T_OrderHeaderID = $order_id and T_OrderHeaderM_PatientID = M_PatientID + join t_orderdetail on T_OrderDetailT_OrderHeaderID = T_OrderHeaderID + and T_OrderDetailIsACtive = 'Y' + and ( T_OrderDetailNat_NormalValueID is null or T_OrderDetailNat_NormalValueID = 0 ) + join t_test on T_OrderDetailT_TestID = T_TestID and T_TestIsResult = 'Y' "; + $qry = $this->db->query($sql); + if (! $qry) { + return; + } + $rows = $qry->result_array(); + if (count($rows) == 0) return; + $sql_u = "update t_orderdetail + join nat_normalvalue on T_OrderDetailID = ? and Nat_NormalValueID = ? + set + T_OrderDetailNat_NormalValueID = Nat_NormalValueID, + T_OrderDetailNormalValueNote = Nat_NormalValueNote, + T_OrderDetailNormalValueDescription = Nat_NormalValueDescription, + T_OrderDetailMinValue = Nat_NormalValueMinValue, + T_OrderDetailMaxValue = Nat_NormalValueMaxValue, + T_OrderDetailMinValueInclusive = Nat_NormalValueMinValueInclusive, + T_OrderDetailMaxValueInclusive = Nat_NormalValueMaxValueInclusive, + T_OrderDetailNat_MethodeID = ?, + T_OrderdetailNat_MethodeName =?"; + + foreach ($rows as $r) { + $T_OrderDetailID = $r["T_OrderDetailID"]; + $sexID = $r["M_PatientM_SexID"]; + $ageInDay = $r["Dob"]; + $natTestID = $r["T_TestNat_TestID"]; + list($methodeID, $methodeName) = $this->getMethodeID($natTestID); + if ($methodeID == 0) continue; + $normalValueID = $this->get_normal_value($methodeID, $natTestID, $sexID, $ageInDay); + if ($normalValueID == 0) return; + $this->db->query($sql_u, array($T_OrderDetailID, $normalValueID, $methodeID, $methodeName)); + } + } + function update_order_sample($targetID, $sourceID) + { + $sql = "update t_ordersample target + join t_ordersample source on + target.T_OrderSampleID = ? + and target.T_OrderSampleWorklistReceive = 'N' + and source.T_OrderSampleID = ? + set + target.T_OrderSampleSampling = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSampling, source.T_OrderSampleSampling), + target.T_OrderSampleSamplingDate = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingDate, source.T_OrderSampleSamplingDate), + target.T_OrderSampleSamplingTime = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingTime, source.T_OrderSampleSamplingTime), + target.T_OrderSampleSamplingUserID = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingUserID, source.T_OrderSampleSamplingUserID), + + target.T_OrderSampleReceive = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceive, source.T_OrderSampleReceive), + target.T_OrderSampleReceiveDate = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveDate, source.T_OrderSampleReceiveDate), + target.T_OrderSampleReceiveTime = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveTime, source.T_OrderSampleReceiveTime), + target.T_OrderSampleReceiveUserID = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveUserID, source.T_OrderSampleReceiveUserID), + + target.T_OrderSampleVerification = if(target.T_OrderSampleVerification='Y',target.T_OrderSampleVerification, source.T_OrderSampleVerification), + target.T_OrderSampleVerificationDate =if(target.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationDate, source.T_OrderSampleVerificationDate), + target.T_OrderSampleVerificationTime =if(source.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationTime, source.T_OrderSampleVerificationTime), + target.T_OrderSampleVerificationUserID =if(source.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationUserID, source.T_OrderSampleVerificationUserID), + + target.T_OrderSampleProcessing = if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessing, source.T_OrderSampleProcessing), + target.T_OrderSampleProcessingDate= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingDate, source.T_OrderSampleProcessingDate), + target.T_OrderSampleProcessingTime= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingTime, source.T_OrderSampleProcessingTime), + target.T_OrderSampleProcessingUserID= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingUserID, source.T_OrderSampleProcessingUserID), + + target.T_OrderSampleReceiveHandling =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandling, source.T_OrderSampleReceiveHandling ), + target.T_OrderSampleReceiveHandlingDate =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingDate, source.T_OrderSampleReceiveHandlingDate), + target.T_OrderSampleReceiveHandlingTime =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingTime, source.T_OrderSampleReceiveHandlingTime), + target.T_OrderSampleReceiveHandlingUserID =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingUserID, source.T_OrderSampleReceiveHandlingUserID), + + target.T_OrderSampleHandling = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandling, source.T_OrderSampleHandling), + target.T_OrderSampleHandlingDate = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingDate, source.T_OrderSampleHandlingDate), + target.T_OrderSampleHandlingTime = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingTime, source.T_OrderSampleHandlingTime), + target.T_OrderSampleHandlingUserID = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingUserID, source.T_OrderSampleHandlingUserID), + + target.T_OrderSampleWorklistReceive = source.T_OrderSampleWorklistReceive, + target.T_OrderSampleWorklistReceiveDatetime = source.T_OrderSampleWorklistReceiveDateTime, + target.T_OrderSampleWorklistReceiveUserID = source.T_OrderSampleWorklistReceiveUserID + "; + $qry = $this->db->query($sql, array($targetID, $sourceID)); + if (! $qry) { + echo json_encode(array("status" => "ERR", "message" => print_r($this->db->error(), true))); + exit; + } + } + function fix_sample_serum($headerID) + { + //cari t_ordersample yg belum worklist receive dengan code 017% + $sql = "select T_OrderSampleID + from t_ordersample + join t_sampletype on + T_OrderSampleT_OrderHeaderID = ? + and T_OrderSampleWorklistReceive = 'N' + and T_OrderSampleIsActive = 'Y' + and T_OrderSampleT_SampleTypeID = T_SampletypeID + and T_SampleTypeCode like '017%' + "; + $qry = $this->db->query($sql, array($headerID)); + if (!$qry) { + echo json_encode(array("status" => "ERR", "message" => print_r($this->db->error(), true))); + exit; + } + $rows = $qry->result_array(); + if (count($rows) == 0) return; + //cari T_OrderSample yang sudah di receive yg terakhir + $sql = "select T_OrderSampleID + from t_ordersample + join t_sampletype on + T_OrderSampleT_OrderHeaderID = ? + and T_OrderSampleWorklistReceive = 'Y' + and T_OrderSampleIsActive = 'Y' + and T_OrderSampleT_SampleTypeID = T_SampletypeID + and T_SampleTypeCode like '017%' + order by T_OrderSampleWorklistReceiveDatetime desc + limit 0,1 + "; + $qry = $this->db->query($sql, array($headerID)); + if (!$qry) { + echo json_encode(array("status" => "ERR", "message" => print_r($this->db->error(), true))); + exit; + } + $rcv_rows = $qry->result_array(); + if (count($rcv_rows) == 0) return; + + //print_r($rows); + //print_r($rcv_rows); + $rcv_T_OrderSampleID = $rcv_rows[0]["T_OrderSampleID"]; + //ada yg belum di receive + foreach ($rows as $r) { + $T_OrderSampleID = $r["T_OrderSampleID"]; + $this->update_order_sample($T_OrderSampleID, $rcv_T_OrderSampleID); + } + } + public function search() + { + $prm = $this->sys_input; + $max_rst = 99; + + $id = $prm["order_id"]; + if ($id > 0) { + $this->fix_sample_serum($id); + $this->fn_fix_normal($id); + } + $lang = $this->lang_default_code; + $lang_id = isset($prm['lang_id']) ? $prm['lang_id'] : '0'; + + if ($lang_id != 0) { + $l = $this->db_smartone->where("Nat_LangID", $lang_id)->get("nat_lang")->row(); + $lang = $l->Nat_LangCode; + } + + //tambahan fajri + $sql = " UPDATE t_orderdetail + JOIN t_test ON T_OrderDetailT_TestID = T_TestID + SET T_OrderDetailT_TestIsResult = T_TestIsResult + WHERE + T_OrderDetailT_OrderHeaderID = {$id} AND + T_OrderDetailT_TestIsResult = '' AND + T_OrderDetailIsActive = 'Y'"; + $this->db_smartone->query($sql); + + $tot_count = 0; + $lq = ""; + $group_id = 0; + if (isset($prm['group_id'])) + $group_id = $prm['group_id']; + + if ($group_id != 0) { + $sql = "select distinct T_WorklistDetailNat_TestID Nat_TestID + from t_worklistdetailv2 + where T_WorklistDetailT_WorklistID = {$group_id}"; + $qry = $this->db_smartone->query($sql); + $rows = $qry->result_array(); + $nat_test_ids = "0"; + foreach ($rows as $r) { + $nat_test_ids .= ", " . $r["Nat_TestID"]; + } + $q_group = " ( $nat_test_ids ) "; + + $sql = " + SELECT a1.*, cOUNT(a2.T_OrderDetailID) level + FROM ( + SELECT IFNULL(y.T_OrderDetailT_TestID, x.T_OrderDetailT_TestID) t_testid, + IFNULL(y.T_OrderDetailT_TestName, y.T_OrderDetailT_TestName) t_testname, + y.T_OrderDetailResult result, y.T_OrderDetailResult result_old, y.T_OrderDetailNote note, y.T_OrderDetailNote note_old, + y.T_OrderDetailID id, + y.T_OrderDetailT_TestIsResult is_result, a.T_TestIsQuantitative is_quantitative, + y.T_OrderDetailResultFlag result_flag, + y.T_OrderDetailNat_NormalValueID normal_id, + y.T_OrderDetailNormalValueNote normal_note, y.T_OrderDetailNat_UnitName unit_name, + y.T_OrderdetailNat_MethodeID methode_id, y.T_OrderdetailNat_MethodeName methode_name, + a.T_TestNat_TestID nattest_id, a.T_TestID tx_id, count(T_ResultInstrumentID) as result_instrument_n, + y.T_OrderDetailVerification, T_OrderSampleReceive sample_receive, + T_OrderSampleProcessing sample_processing, T_OrderSampleWorklistReceive sample_worklist_receive, + IF(T_OrderDetailAddOnPreAnalytic = 'Y', T_OrderDetailAddOnPreAnalytic, PreAnalyticIsOk) pre_analytic, + T_OrderDetailAddOnPreAnalytic, + T_OrderHeaderID order_id, y.T_OrderDetailT_TestSasCode test_sas_code, + tx.T_TestSasCode, + T_OrderDetailAddOnResample `resample`, T_OrderDetailAddOnResampleStatus resample_status, + T_OrderDetailAddOnRef ref, y.T_OrderDetailVerification verification, y.T_OrderDetailValidation validation, + T_OrderPromiseDateTime, Group_ResultName as ResultGroupName + FROM t_orderdetail x + left join t_orderpromise on x.T_OrderDetailT_OrderPromiseID = T_OrderPromiseID + JOIN t_test tx ON x.T_OrderDetailT_TestID = T_TestID + JOIN t_test tcheck on tcheck.T_TestNat_TestID in {$q_group} + and ( tx.T_TestID = tcheck.T_TestID or tx.T_TestSasCode like concat(tcheck.T_TestSasCode,'%')) + LEFT JOIN group_resultdetail ON Group_ResultDetailT_TestID = x.T_OrderDetailT_TestID AND Group_ResultDetailIsActive = 'Y' + LEFT JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND Group_ResultFlagNonLab = 'N' + LEFT JOIN t_orderdetail y ON x.T_OrderDetailT_TestSasCode LIKE CONCAT(y.T_OrderDetailT_TestSasCode, '%') + AND x.T_OrderDetailT_OrderHeaderID = y.T_OrderDetailT_OrderHeaderID + AND y.T_OrderDetailIsActive = 'Y' + LEFT JOIN t_orderdetailaddon ON x.T_OrderDetailID = T_OrderDetailAddOnT_OrderDetailID + JOIN t_orderheader ON y.T_OrderDetailT_OrderHeaderID = T_OrderHeaderID + LEFT JOIN t_test a ON y.T_OrderDetailT_TestID = a.T_TestID + AND a.T_TestIsNonLab = '' + LEFT JOIN (SELECT T_OrderSampleT_SampleTypeID, T_OrderSampleReceive, T_OrderSampleProcessing, T_OrderSampleWorklistReceive + FROM t_ordersample WHERE T_OrderSampleT_OrderHeaderID = {$id} + AND T_OrderSampleIsactive = 'Y' + GROUP BY T_OrderSampleT_SampleTypeID) os ON a.T_TestT_SampleTypeID = os.T_OrderSampleT_SampleTypeID + or os.T_OrderSampleT_SampleTypeID = fn_sampletype_from_local(a.T_TestNat_TestID) + + LEFT JOIN t_resultinstrument ON T_ResultInstrumentT_OrderDetailID = x.T_OrderDetailID + LEFT JOIN pre_analytic ON PreAnalyticNat_TestID = a.T_TestNat_TestID AND PreAnalyticDate = date(now()) and PreAnalyticIsActive = 'Y' + WHERE x.T_OrderDetailT_OrderHeaderID = {$id} + AND x.T_OrderDetailIsActive = 'Y' + GROUP BY y.T_OrderDetailT_TestID + ORDER BY y.T_OrderDetailT_TestSasCode ASC + ) a1 + + LEFT JOIN t_orderdetail a2 ON a2.T_OrderDetailT_OrderHeaderID = a1.order_id + AND a2.T_OrderDetailIsActive = 'Y' + AND a1.test_sas_code LIKE CONCAT(a2.T_OrderDetailT_testSasCode, '%') + GROUP BY a1.t_testid + order by a1.test_sas_code +"; + $query = $this->db_smartone->query($sql); + $lq = $this->db_smartone->last_query(); + } else { + $sql = " + SELECT a1.*, cOUNT(a2.T_OrderDetailID) level + FROM ( + SELECT IFNULL(y.T_OrderDetailT_TestID, x.T_OrderDetailT_TestID) t_testid, + IFNULL(y.T_OrderDetailT_TestName, y.T_OrderDetailT_TestName) t_testname, + y.T_OrderDetailResult result, y.T_OrderDetailResult result_old, y.T_OrderDetailNote note, y.T_OrderDetailNote note_old, + y.T_OrderDetailID id, + y.T_OrderDetailT_TestIsResult is_result, a.T_TestIsQuantitative is_quantitative, + y.T_OrderDetailResultFlag result_flag, + y.T_OrderDetailNat_NormalValueID normal_id, + y.T_OrderDetailNormalValueNote normal_note, y.T_OrderDetailNat_UnitName unit_name, + y.T_OrderdetailNat_MethodeID methode_id, y.T_OrderdetailNat_MethodeName methode_name, + a.T_TestNat_TestID nattest_id, a.T_TestID tx_id, count(T_ResultInstrumentID) as result_instrument_n, + y.T_OrderDetailVerification, T_OrderSampleReceive sample_receive, + T_OrderSampleProcessing sample_processing, T_OrderSampleWorklistReceive sample_worklist_receive, + IF(T_OrderDetailAddOnPreAnalytic = 'Y', T_OrderDetailAddOnPreAnalytic, PreAnalyticIsOk) pre_analytic, + T_OrderDetailAddOnPreAnalytic, + T_OrderHeaderID order_id, y.T_OrderDetailT_TestSasCode test_sas_code, + tx.T_TestSasCode, + T_OrderDetailAddOnResample `resample`, T_OrderDetailAddOnResampleStatus resample_status, + T_OrderDetailAddOnRef ref, y.T_OrderDetailVerification verification, y.T_OrderDetailValidation validation, + T_OrderPromiseDateTime , Group_ResultName as ResultGroupName + FROM t_orderdetail x + left join t_orderpromise on x.T_OrderDetailT_OrderPromiseID = T_OrderPromiseID + JOIN t_test tx ON x.T_OrderDetailT_TestID = T_TestID + LEFT JOIN group_resultdetail ON Group_ResultDetailT_TestID = x.T_OrderDetailT_TestID AND Group_ResultDetailIsActive = 'Y' + LEFT JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND Group_ResultFlagNonLab = 'N' + LEFT JOIN t_orderdetail y ON x.T_OrderDetailT_TestSasCode LIKE CONCAT(y.T_OrderDetailT_TestSasCode, '%') + AND x.T_OrderDetailT_OrderHeaderID = y.T_OrderDetailT_OrderHeaderID + AND y.T_OrderDetailIsActive = 'Y' + + LEFT JOIN t_orderdetailaddon ON x.T_OrderDetailID = T_OrderDetailAddOnT_OrderDetailID + + JOIN t_orderheader ON y.T_OrderDetailT_OrderHeaderID = T_OrderHeaderID + LEFT JOIN t_test a ON y.T_OrderDetailT_TestID = a.T_TestID + AND a.T_TestIsNonLab = '' + LEFT JOIN (SELECT T_OrderSampleT_SampleTypeID, T_OrderSampleReceive, T_OrderSampleProcessing, T_OrderSampleWorklistReceive + FROM t_ordersample WHERE T_OrderSampleT_OrderHeaderID = {$id} + AND T_OrderSampleIsactive = 'Y' + GROUP BY T_OrderSampleT_SampleTypeID) os ON a.T_TestT_SampleTypeID = os.T_OrderSampleT_SampleTypeID + or os.T_OrderSampleT_SampleTypeID = fn_sampletype_from_local(a.T_TestNat_TestID) + + LEFT JOIN t_resultinstrument ON T_ResultInstrumentT_OrderDetailID = x.T_OrderDetailID + LEFT JOIN pre_analytic ON PreAnalyticNat_TestID = a.T_TestNat_TestID AND PreAnalyticDate = date(now()) and PreAnalyticIsActive = 'Y' + WHERE x.T_OrderDetailT_OrderHeaderID = {$id} + AND x.T_OrderDetailIsActive = 'Y' + GROUP BY y.T_OrderDetailT_TestID + ORDER BY y.T_OrderDetailT_TestSasCode ASC + ) a1 + + LEFT JOIN t_orderdetail a2 ON a2.T_OrderDetailT_OrderHeaderID = a1.order_id + AND a2.T_OrderDetailIsActive = 'Y' + AND a1.test_sas_code LIKE CONCAT(a2.T_OrderDetailT_testSasCode, '%') + GROUP BY a1.t_testid + order by a1.test_sas_code +"; + //echo $sql; + $query = $this->db_smartone->query($sql); + $lq = $this->db_smartone->last_query(); + } + // file_put_contents("/xtmp/re-query.sql",$lq); + + if ($query) { + $rst = []; + $rows = $query->result_array(); + + foreach ($rows as $k => $v) { + + if ($v['is_result'] == "Y" && $v['is_quantitative'] == "N") { + $v['template'] = []; + $x = $this->db_smartone->query("CALL sp_master_resulttemplate_get('{$v['t_testid']}')"); + $this->clean_mysqli_connection($this->db_smartone->conn_id); + if ($x) + $v['template'] = $x->result_array(); + } + + // IF Rujukan, by pas Pre Analytik + if ($v['ref'] == 'Y') + $v['pre_analytic'] = 'Y'; + if ($v["id"] == "885455") { + //sipe workaround + //$v["sample_receive"] = "Y"; + $v["sample_worklist_receive"] = "Y"; + } + $rst[] = $v; + } + + $result = array("total" => $tot_count, "records" => $rst, "total_display" => sizeof($rows), "q" => $lq); + $this->sys_ok($result); + } else { + $this->sys_error_db("RE Px rows", $this->db_smartone); + exit; + } + } + + public function save() + { + $prm = $this->sys_input; + $data = json_decode($prm["data"]); + $lang = $this->lang_default_code; + $lang_id = isset($prm['lang_id']) ? $prm['lang_id'] : '0'; + + if ($lang_id != 0) { + $l = $this->db_smartone->where("Nat_LangID", $lang_id)->get("nat_lang")->row(); + $lang = $l->Nat_LangCode; + } + + $sql_norm = "select T_OrderDetailMinValue, T_OrderDetailMaxValue, + T_OrderDetailMinValueInclusive, T_OrderDetailMaxValueInclusive, + Nat_TestFlagLow, Nat_TestFlagHigh + from t_orderdetail + join t_test on T_OrderDetailT_TestID = T_TestID + join nat_test on T_TestNat_TestID = Nat_TestID and T_TestIsActive = 'Y' + where T_OrderDetailID = ? "; + + $ids = []; + foreach ($data as $k => $v) { + if ($v->resultInstrumentID > 0) { + $sql_i = "select T_ResultInstrumentNat_NormalValueID normalValueID + from t_resultinstrument + where T_ResultInstrumentID = ?"; + $qry_i = $this->db_smartone->query($sql_i, array($v->resultInstrumentID)); + if ($qry_i) { + $rows_i = $qry_i->result_array(); + + if (count($rows_i) > 0) { + $sql_iu = "update t_orderdetail, nat_normalvalue , nat_methode + set T_OrderDetailMinValue = Nat_NormalValueMinValue, + T_OrderDetailMinValueInclusive = Nat_NormalValueMinValueInclusive, + T_OrderDetailMaxValue = Nat_NormalValueMaxValue , + T_OrderDetailMaxValueInclusive = Nat_NormalValueMaxValueInclusive, + T_OrderDetailNormalValueNote = Nat_NormalValueNote, + T_OrderDetailNormalValueDescription = Nat_NormalValueDescription, + T_OrderDetailNat_NormalValueID = Nat_NormalValueID, + T_OrderDetailNat_MethodeID = Nat_NormalValueNat_MethodeID, + T_OrderDetailNat_MethodeName = Nat_MethodeName + where T_OrderDetailID = ? and Nat_NormalValueID = ? + and Nat_NormalValueNat_MethodeID = Nat_MethodeID + "; + $this->db_smartone->query($sql_iu, array($v->id, $rows_i[0]["normalValueID"])); + //file_put_contents("/xtmp/update-nilai-normal", $this->db_smartone->last_query() . "\n", FILE_APPEND); + } + } + } + $y = $this->db_smartone->query("SELECT fn_process_sample_handling_perfect('{$v->order_id}', '{$v->test_id}') c") + ->row(); + $req_status = $y->c; + $qry_norm = $this->db_smartone->query($sql_norm, $v->id); + $result_flag = ""; + if ($qry_norm) { + $rows_norm = $qry_norm->result_array(); + if (count($rows_norm) > 0) { + $r = $rows_norm[0]; + if (is_numeric($v->result)) { + + if ($r["T_OrderDetailMinValueInclusive"] == "Y" && $v->result < $r["T_OrderDetailMinValue"]) { + $result_flag = $r["Nat_TestFlagLow"]; + } + if ($r["T_OrderDetailMinValueInclusive"] == "N" && $v->result <= $r["T_OrderDetailMinValue"]) { + $result_flag = $r["Nat_TestFlagLow"]; + } + if ($r["T_OrderDetailMaxValueInclusive"] == "Y" && $v->result > $r["T_OrderDetailMaxValue"]) { + $result_flag = $r["Nat_TestFlagHigh"]; + } + if ($r["T_OrderDetailMaxValueInclusive"] == "N" && $v->result >= $r["T_OrderDetailMaxValue"]) { + $result_flag = $r["Nat_TestFlagHigh"]; + } + } + } + } + if ($lang == $this->lang_default_code) { + $this->db_smartone->set('T_OrderDetailResult', $v->result) + ->set('T_OrderDetailResultFlag', $result_flag) + ->set('T_OrderDetailNote', $v->note) + ->set('T_OrderDetailReqStatus', $req_status) + ->where('T_OrderDetailID', $v->id) + ->update('t_orderdetail'); + } else { + $this->db_smartone->set('T_OrderDetailLangResult', $v->result) + ->set('T_OrderDetailLangNote', $v->note) + ->where('T_OrderDetailLangID', $v->id) + ->update('t_orderdetaillang'); + } + + $ids[] = $v->id; + } + + // LOG Process + $order = $this->db_smartone->select('T_OrderDetailT_OrderHeaderID id, T_OrderHeaderLabNumber lab_number', false) + ->join('t_orderheader', 'T_OrderHeaderID = T_OrderDetailT_OrderHeaderID') + ->where('T_OrderDetailID', $data[0]->id) + ->get('t_orderdetail') + ->row(); + + $dblog = $this->load->database("onelog", true); + $dblog->set('Log_ProcessCode', 'PROCESS.Result.Entry') + ->set('Log_ProcessOrderID', $order->id) + ->set('Log_ProcessOrderNumber', $order->lab_number) + ->set('Log_ProcessJson', json_encode($data)) + ->set('Log_ProcessUserID', $this->sys_user['M_UserID']) + ->insert('log_process'); + // END OF Log Process + //auto calculation + $this->load->library("Resultcalc"); + $rows = $this->resultcalc->auto($order->id); + + try { + foreach ($ids as $id) { + $this->db_smartone->query("call sp_set_normal_value_flag($id)"); + $this->clean_mysqli_connection($this->db_smartone->conn_id); + } + } catch (Exception $e) { + } + + $this->sys_ok($ids); + } + + public function save_template() + { + $prm = $this->sys_input; + + $n = $this->db_smartone->select("COUNT(T_ResultTemplateID) n") + ->where("T_ResultTemplateT_TestID", $prm['test_id']) + ->where("T_ResultTemplateIsActive", "Y") + ->where("T_ResultTemplateValue", $prm['value']) + ->get('t_resulttemplate') + ->row(); + if ($n->n > 0) { + $this->sys_error_db("Insert Result Template", $this->db_smartone); + return; + } + + $r = $this->db_smartone->set("T_ResultTemplateT_TestID", $prm['test_id']) + ->set("T_ResultTemplateValue", $prm['value']) + ->insert('t_resulttemplate'); + if ($r) { + $template = []; + $x = $this->db_smartone->query("CALL sp_master_resulttemplate_get('{$prm['test_id']}')"); + $this->clean_mysqli_connection($this->db_smartone->conn_id); + if ($x) + $template = $x->result_array(); + + $this->sys_ok($template); + } + } + + public function export() + { + $prm = $this->sys_input; + + $sql = "CALL sp_process_result_lang(?, ?, ?, ?)"; + $query = $this->db_smartone->query($sql, [$prm['order_id'], $prm['lang_id'], $prm['is_si'], $this->sys_user['M_UserID']]); + if ($query) { + $r = $query->row(); + if ($r->status == "OK") { + $this->sys_ok($r->data); + return; + } + + $this->sys_error_db("Message : " . $r->message, $this->db_smartone); + } else { + $this->sys_error_db("Lang Result", $this->db_smartone); + return; + } + } + + public function search_group() + { + $prm = $this->sys_input; + $max_rst = 100; + + // QUERY TOTAL + $sql = "select count(*) total + from t_worklist + where T_WorklistIsActive = 'Y' + order by T_WorklistName ASC"; + $query = $this->db_smartone->query($sql); + + if ($query) { + $tot_count = $query->result_array()[0]["total"]; + } else { + $this->sys_error_db("worklist count", $this->db_smartone); + exit; + } + + $sql = "select T_WorklistID group_id, T_WorklistName group_name + from t_worklist + where T_WorklistIsActive = 'Y' + order by T_WorklistName ASC + limit 0, {$max_rst}"; + $query = $this->db_smartone->query($sql); + + if ($query) { + $rows = $query->result_array(); + foreach ($rows as $k => $v) + $rows[$k]['data'] = json_decode($v['data']); + $result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows), "q" => $this->db_smartone->last_query()); + $this->sys_ok($result); + } else { + $this->sys_error_db("worklist rows", $this->db_smartone); + exit; + } + } + + public function search_rerun() + { + $prm = $this->sys_input; + $id = $prm["detail_id"]; + + $sql = "CALL sp_process_result_rerun(?)"; + $query = $this->db_smartone->query($sql, [$id]); + + if ($query) { + $rows = $query->result_array(); + $this->sys_ok(["records" => $rows]); + } else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + + + function getdoctorsfna() + { + $prm = $this->sys_input; + // $id = $prm["id"]; + + $sql = " SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY M_DoctorName ASC"; + //echo $sql; + $query = $this->db_smartone->query($sql); + + if ($query) { + $rows = $query->result_array(); + $this->sys_ok(["records" => $rows]); + } else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + function getfnaresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT Other_FNADetailsID as xid, + Other_FNAT_OrderDetailID as orderdetail_id, + Other_FNADetailsCode as code, + Other_FNADetailsLabel as label, + Other_FNADetailsResult as result, + IFNULL(Other_FNAM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_FNAM_DoctorID) OR Other_FNAM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_fna + JOIN other_fnadetails ON Other_FNADetailsOther_FNAID = Other_FNAID AND Other_FNADetailsIsActive = 'Y' + LEFT JOIN m_doctor ON Other_FNAM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_FNAT_OrderDetailID = {$id} AND Other_FNAIsActive = 'Y' + GROUP BY Other_FNADetailsID + ORDER BY Other_FNADetailsCode ASC"; + $query = $this->db_smartone->query($sql); + + if ($query) { + $rows = $query->result_array(); + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $images = array(); + $sql = "SELECT So_ImageUploadID as xid, + CONCAT('/one-media/one-image-nonlab/',So_ImageUploadNewName) as image_url + FROM t_orderdetail + JOIN so_imageupload ON So_ImageUploadT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND + So_ImageUploadIsActive = 'Y' + WHERE + T_OrderDetailID = {$id} AND + T_OrderDetailIsActive = 'Y' + GROUP BY So_ImageUploadID"; + $images = $this->db_smartone->query($sql)->result_array(); + + $rst = array('doctors' => $doctors, 'results' => $rows, 'images' => $images); + $this->sys_ok(["records" => $rst]); + } else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + + function uploadimage() + { + if (! $this->isLogin) { + $this->sys_error("Invalid Token"); + exit; + } + + $userid = $this->sys_user["M_UserID"]; + $data = []; + //print_r($_SERVER); + + $prm = $this->sys_input; + $orderid = $this->input->post('orderid'); + $labnumber = $this->input->post('labnumber'); + $sql = "UPDATE so_imageupload SET + So_ImageUploadIsActive = 'N', + So_ImageUploadUserID = {$userid} + WHERE + So_ImageUploadT_OrderHeaderID = {$orderid}"; + //echo $sql; + $this->db_onedev->query($sql); + //$config['upload_path'] = 'assets/'; + + $path = '/home/one/project/one/one-media/one-image-nonlab/'; + //echo $path; + $config['upload_path'] = $path; + $config['allowed_types'] = 'jpg|jpeg|png|gif'; + + $config['max_size'] = '10000'; + $count = count($_FILES['files']['name']); + //echo $count; + $this->load->library('upload', $config); + + $error = []; + for ($i = 0; $i < $count; $i++) { + + + if (!empty($_FILES['files']['name'][$i])) { + + + + $_FILES['file']['name'] = $_FILES['files']['name'][$i]; + + $_FILES['file']['type'] = $_FILES['files']['type'][$i]; + + $_FILES['file']['tmp_name'] = $_FILES['files']['tmp_name'][$i]; + + $_FILES['file']['error'] = $_FILES['files']['error'][$i]; + + $_FILES['file']['size'] = $_FILES['files']['size'][$i]; + + + + $namex = $orderid . '-' . $labnumber . '-' . $this->generateRandomString(5); + //echo $namex; + + $config['file_name'] = $namex; + $this->upload->initialize($config); + //echo $config['file_name'] ; + + + + + + if ($this->upload->do_upload('file')) { + + $uploadData = $this->upload->data(); + + $filename = $uploadData['file_name']; + //echo $filename; + + + $sql = "INSERT INTO so_imageupload ( + So_ImageUploadT_OrderHeaderID, + So_ImageUploadT_OrderHeaderLabNumber, + So_ImageUploadT_SampleTypeID, + So_ImageUploadOldName, + So_ImageUploadNewName, + So_ImageUploadCreated, + So_ImageUploadUserID + ) + VALUES( + {$orderid}, + '{$labnumber}', + '150', + '{$_FILES['files']['name'][$i]}', + '{$filename}', + NOW(), + {$userid} + + )"; + //echo $sql; + $this->db_onedev->query($sql); + $xlast_id = $this->db_onedev->insert_id(); + $data['totalFiles'][] = array('xid' => $xlast_id, 'image_url' => '/one-media/one-image-nonlab/' . $filename); + } else { + $error = array('error' => $this->upload->display_errors()); + } + } + } + + $result = array("total" => count($data['totalFiles']), "records" => $data['totalFiles'], 'errors' => $error); + $this->sys_ok($result); + } + + + function getpatologianatomyresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT Other_PatologiAnatomyID as xid, + Other_PatologiAnatomyT_OrderDetailID as orderdetail_id, + Other_PatologiAnatomyNoSediaan as no_sediaan, + Other_PatologiAnatomyDiagnosaKlinis as diagnosa, + Other_PatologiAnatomyKeteranganKlinis as klinis, + Other_PatologiAnatomyLokasiOrgan as lokasi, + Other_PatologiAnatomyMakroskopik as makroskopik, + Other_PatologiAnatomyMikroskopik as mikroskopik, + Other_PatologiAnatomyKesimpulan as kesimpulan, + IFNULL(Other_PatologiAnatomyM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_PatologiAnatomyM_DoctorID) OR Other_PatologiAnatomyM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_patologi_anatomy + LEFT JOIN m_doctor ON Other_PatologiAnatomyM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_PatologiAnatomyT_OrderDetailID = {$id} AND Other_PatologiAnatomyIsActive = 'Y' + GROUP BY Other_PatologiAnatomyID + ORDER BY Other_PatologiAnatomyID ASC + LIMIT 1"; + $query = $this->db_smartone->query($sql); + + if ($query) { + $rows = $query->row_array(); + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + + $sql = "SELECT So_ImageUploadPatologyAnatomyID as xid, + CONCAT('/one-media/one-image-nonlab/',So_ImageUploadPatologyAnatomyNewName) as image_url, + So_ImageUploadPatologyAnatomyType as type + FROM t_orderdetail + JOIN so_imageupload_patology_anatomy ON So_ImageUploadPatologyAnatomyT_OrderHeaderID= T_OrderDetailT_OrderHeaderID AND + So_ImageUploadPatologyAnatomyIsActive= 'Y' + WHERE + T_OrderDetailID = {$id} AND + T_OrderDetailIsActive = 'Y' + GROUP BY So_ImageUploadPatologyAnatomyID"; + $images = $this->db_smartone->query($sql)->result_array(); + $mikro = []; + $makro = []; + + foreach ($images as $key => $value) { + + if ($value['type'] == 'mikro') { + $mikro[] = $value; + } + if ($value['type'] == 'makro') { + $makro[] = $value; + } + } + + $rst = array('doctors' => $doctors, 'result' => $rows, 'mikro' => $mikro, 'makro' => $makro); + $this->sys_ok(["records" => $rst]); + } else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + + + function generateRandomString($length = 10) + { + $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; + $charactersLength = strlen($characters); + $randomString = ''; + for ($i = 0; $i < $length; $i++) { + $randomString .= $characters[rand(0, $charactersLength - 1)]; + } + return $randomString; + } + + function getcytologiresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT Other_CytologiDetailsID as xid, + Other_CytologiT_OrderDetailID as orderdetail_id, + Other_CytologiDetailsCode as code, + Other_CytologiDetailsLabel as label, + Other_CytologiDetailsResult as result, + IFNULL(Other_CytologiM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_CytologiM_DoctorID) OR Other_CytologiM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_cytologi + JOIN other_cytologidetails ON Other_CytologiDetailsOther_CytologiID = Other_CytologiID AND Other_CytologiDetailsIsActive = 'Y' + LEFT JOIN m_doctor ON Other_CytologiM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_CytologiT_OrderDetailID = {$id} AND Other_CytologiIsActive = 'Y' + GROUP BY Other_CytologiDetailsID + ORDER BY Other_CytologiDetailsCode ASC"; + //echo $sql; + $query = $this->db_smartone->query($sql); + + if ($query) { + $rows = $query->result_array(); + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $rst = array('doctors' => $doctors, 'results' => $rows); + $this->sys_ok(["records" => $rst]); + } else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + function getmikroresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT + Other_MikroID as xid, + Other_MikroHasilBiakan as hasil_biakan, + Other_MikroSampleTypeName as sample_name, + Other_MikroT_OrderDetailID as orderdetail_id, + Other_MikroResult as result_value, + '' as result_other, + IFNULL(T_BacteriaID,0) as T_BacteriaID, + IFNULL(T_BacteriaName,'') as T_BacteriaName, + '' as details, + IFNULL(Other_MikroM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_MikroM_DoctorID) OR Other_MikroM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_mikro + LEFT JOIN t_bacteria ON Other_MikroT_BacteriaID = T_BacteriaID + LEFT JOIN m_doctor ON Other_MikroM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_MikroT_OrderDetailID = {$id} AND Other_MikroIsActive = 'Y' + GROUP BY Other_MikroID"; + //echo $sql; + $query = $this->db_smartone->query($sql); + + if ($query) { + $row = $query->row_array(); + if ($row) { + if ($row['result_value'] != 'Positif' && $row['result_value'] != 'Negatif') { + $row['result_other'] = $row['result_value']; + $row['result_value'] = 'other'; + } + $sql = "SELECT '' as xno, + Other_MikroDetailsID as xid, + Other_MikroDetailsValue as value, + IF(Other_MikroDetailsNote = 'R','Y','N') as chx_r, + IF(Other_MikroDetailsNote = 'I','Y','N') as chx_i, + IF(Other_MikroDetailsNote = 'S','Y','N') as chx_s, + Other_MikroDetailsNote as note, + t_antibiotic.* + FROM other_mikrodetails + LEFT JOIN t_antibiotic ON Other_MikroDetailsT_AntibioticID = T_AntibioticID + WHERE + Other_MikroDetailsOther_MikroID = {$row['xid']} AND Other_MikroDetailsIsActive = 'Y' + GROUP BY Other_MikroDetailsID + ORDER BY T_AntibioticName ASC"; + //echo $sql; + $details = $this->db_smartone->query($sql)->result_array(); + if (details) { + foreach ($details as $k => $v) { + $details[$k]['xno'] = $k + 1; + } + } + $row['details'] = $details; + } else { + $row = array('xid' => '0', 'hasil_biakan' => '', 'result_value' => 'Negatif', 'sample_name' => '', 'orderdetail_id' => $id, 'T_BacteriaID' => '0', 'T_BacteriaName' => '0', 'details' => array(), 'doctor_id' => '0', 'doctor_name' => '0'); + } + } else { + $row = array('xid' => '0', 'hasil_biakan' => '', 'result_value' => 'Negatif', 'sample_name' => '', 'orderdetail_id' => $id, 'T_BacteriaID' => '0', 'T_BacteriaName' => '0', 'details' => array(), 'doctor_id' => '0', 'doctor_name' => '0'); + } + //print_r($row); + + + + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 7 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $sql = " + SELECT '0' as id, 'Belum memilih bakteria' as name + UNION + SELECT T_BacteriaID as id, T_BacteriaName as name + FROM t_bacteria + WHERE + T_BacteriaIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $bacteries = $this->db_smartone->query($sql)->result_array(); + $rst = array('doctors' => $doctors, 'bacteries' => $bacteries, 'results' => $row); + $this->sys_ok(["records" => $rst]); + } + function getantibiotics() + { + $prm = $this->sys_input; + $id = $prm["id"]; + $sql = " SELECT '' as xno, + 0 as xid, + '' as hasil_biakan, + '' as sample_name, + 0 as value, + 'Y' as chx_r, + 'N' as chx_i, + 'N' as chx_s, + 'R' as note, + t_antibiotic.* + FROM t_antibiotic + WHERE + T_AntibioticT_BacteriaID = {$prm['id']} AND T_AntibioticIsActive= 'Y' + ORDER BY T_AntibioticName ASC"; + //echo $sql; + $rows = $this->db_smartone->query($sql)->result_array(); + if (rows) { + foreach ($rows as $k => $v) { + $rows[$k]['xno'] = $k + 1; + } + } + + $this->sys_ok(["records" => $rows]); + } + function getlcprepresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + $sql = " SELECT Other_LcprepDetailsID as xid, + Other_LcprepID as header_id, + Other_LcprepT_orderDetailID as orderdetail_id, + Other_LcprepDetailsCode as code, + Other_LcprepDetailsLabel as label, + Other_LcprepDetailsResult as result, + IFNULL(Other_LcprepM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_LcprepM_DoctorID) OR Other_LcprepM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_lcprep + JOIN other_lcprepdetails ON Other_LcprepDetailsOther_LcprepID = Other_LcprepID AND Other_LcprepDetailsIsActive = 'Y' + LEFT JOIN m_doctor ON Other_LcprepM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_LcprepT_orderDetailID = {$id} AND Other_LcprepIsActive = 'Y' + GROUP BY Other_LcprepDetailsOther_LcprepID, Other_LcprepDetailsCode + ORDER BY Other_LcprepDetailsCode ASC"; + //echo $sql; + $rows = $this->db_smartone->query($sql)->result_array(); + if (!$rows) { + $rows = array( + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'A', + 'label' => 'DESKRIPSI', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ), + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'B', + 'label' => 'KESIMPULAN', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ) + ); + } + + $header_id = $rows[0]['header_id']; + $sql = "SELECT IFNULL(Other_LcprepAdekuasiID,0) as xid, + Lcprep_AdekuasiID as id, + Lcprep_AdekuasiLabel as name, + IF(ISNULL(Other_LcprepAdekuasiID),'N',Other_LcprepAdekuasiChex) as chex + FROM lcprep_adekuasi + LEFT JOIN other_lcprepadekuasi ON Other_LcprepAdekuasiLcprep_AdekuasiID = Lcprep_AdekuasiID AND + Other_LcprepAdekuasiOther_LcprepID = {$header_id} AND + Other_LcprepAdekuasiIsActive = 'Y' + WHERE + Lcprep_AdekuasiIsActive = 'Y' + GROUP BY Lcprep_AdekuasiID + ORDER BY Lcprep_AdekuasiOrder ASC + "; + //echo $sql; + $adeakuasi = $this->db_smartone->query($sql)->result_array(); + foreach ($adeakuasi as $kc => $vc) { + $adeakuasi[$kc]['chex'] = $vc['chex'] == 'N' ? false : true; + } + + $sql = "SELECT IFNULL(Other_LcprepKategoriUmumID,0) as xid, + Lcprep_KategoriUmumID as id, + Lcprep_KategoriUmumLabel as name, + IF(ISNULL(Other_LcprepKategoriUmumID),'N',Other_LcprepKategoriUmumChex) as chex + FROM lcprep_kategoriumum + LEFT JOIN other_lcprepkategoriumum ON Other_LcprepKategoriUmumLcprep_KategoriUmumID = Lcprep_KategoriUmumID AND + Other_LcprepKategoriUmumOther_LcprepID = {$header_id} AND + Other_LcprepKategoriUmumIsActive = 'Y' + WHERE + Lcprep_KategoriUmumIsActive = 'Y' + GROUP BY Lcprep_KategoriUmumID + "; + //echo $sql; + $kategoriumum = $this->db_smartone->query($sql)->result_array(); + foreach ($kategoriumum as $kc => $vc) { + $kategoriumum[$kc]['chex'] = $vc['chex'] == 'N' ? false : true; + } + + $sql = " + SELECT Lcprep_InterpretasiGroupID as group_id, + Lcprep_InterpretasiGroupName as group_name, + '' as subgroups + FROM lcprep_interpretasigroup + WHERE + Lcprep_InterpretasiGroupIsActive = 'Y' + "; + //echo $sql; + $interpretasi = $this->db_smartone->query($sql)->result_array(); + foreach ($interpretasi as $k => $v) { + $subgroups = array(); + $sql = "SELECT Lcprep_InterpretasiSubgroupID as subgroup_id, + Lcprep_InterpretasiSubgroupName as subgroup_name, + '' as childs + FROM lcprep_interpretasisubgroup + WHERE + Lcprep_InterpretasiSubgroupLcprep_InterpretasiGroupID = {$v['group_id']} AND Lcprep_InterpretasiSubgroupIsActive = 'Y'"; + //echo $sql; + $subgroups = $this->db_smartone->query($sql)->result_array(); + if (count($subgroups) > 0) { + foreach ($subgroups as $ki => $vi) { + $childs = array(); + $sql = "SELECT IFNULL(Other_LcprepInterpretasiID,0) as xid, + IFNULL(Other_LcprepInterpretasiChex,'N') as chex, + IFNULL(Other_LcprepInterpretasiValue,'') as value, + Lcprep_InterpretasiID as id, + Lcprep_InterpretasiLcprep_InterpretasiSubgroupID as subgroup_id, + Lcprep_InterpretasiCode as code, + Lcprep_InterpretasiName as name, + Lcprep_InterpretasiParentID as parent_id, + Lcprep_InterpretasiIsParent as is_parent, + Lcprep_InterpretasiHasResult as has_result, + Lcprep_InterpretasiTypeResult as type_result + FROM lcprep_interpretasi + LEFT JOIN other_lcprepinterpretasi ON Other_LcprepInterpretasiOther_LcprepID = {$header_id} AND + Other_LcprepInterpretasiLcprep_InterpretasiID = Lcprep_InterpretasiID AND + Other_LcprepInterpretasiIsActive = 'Y' + WHERE + Lcprep_InterpretasiLcprep_InterpretasiSubgroupID = {$vi['subgroup_id']} AND Lcprep_InterpretasiIsActive = 'Y' + GROUP BY Lcprep_InterpretasiID Order BY Lcprep_InterpretasiCode ASC"; + $childs = $this->db_smartone->query($sql)->result_array(); + if ($childs) { + foreach ($childs as $kc => $vc) { + $childs[$kc]['chex'] = $vc['chex'] == 'N' ? false : true; + } + } + $subgroups[$ki]['childs'] = $childs; + } + } + + $interpretasi[$k]['subgroups'] = $subgroups; + } + + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $rst = array('doctors' => $doctors, 'results' => $rows, 'adekuasi' => $adeakuasi, 'kategoriumum' => $kategoriumum, 'interpretasi' => $interpretasi); + $this->sys_ok(["records" => $rst]); + } + + function getpapsmearresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT Other_PapSmearDetailsID as xid, + Other_PapSmearID as header_id, + Other_PapSmearT_OrderDetailID as orderdetail_id, + Other_PapSmearDetailsCode as code, + Other_PapSmearDetailsLabel as label, + Other_PapSmearDetailsResult as result, + IFNULL(Other_PapSmearM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_PapSmearM_DoctorID) OR Other_PapSmearM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_papsmear + JOIN other_papsmeardetails ON Other_PapSmearDetailsOther_PapSmearID = Other_PapSmearID AND Other_PapSmearDetailsIsActive = 'Y' + LEFT JOIN m_doctor ON Other_PapSmearM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_PapSmearT_OrderDetailID = {$id} AND Other_PapSmearIsActive = 'Y' + GROUP BY Other_PapSmearDetailsID + ORDER BY Other_PapSmearDetailsCode ASC"; + //echo $sql; + $rows = $this->db_smartone->query($sql)->result_array(); + if (!$rows) { + $rows = array( + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'A', + 'label' => 'Makroskopik', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ), + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'B', + 'label' => 'Mikroskopik', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ), + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'C', + 'label' => 'Kesimpulan', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ) + ); + } + + $header_id = $rows[0]['header_id']; + $sql = "SELECT Other_PapSmearMaturasiID as xid, + Other_PapSmearMaturasiValue as value + FROM other_papsmearmaturasi + WHERE + Other_PapSmearMaturasiOther_PapSmearID = {$header_id} AND + Other_PapSmearMaturasiIsActive = 'Y' + "; + //echo $sql; + $dt_maturasi = $this->db_smartone->query($sql)->row_array(); + if (!$dt_maturasi) { + $maturasi = array('xid' => '0', 'value' => array('', '', '')); + } else { + $value = explode('/', $dt_maturasi['value']); + $maturasi = array('xid' => $dt_maturasi['xid'], 'value' => $value); + } + + $sql = "SELECT IFNULL(Other_PapSmearBahanID,0) as xid, + M_PapSmearBahanID as bahan_id, + M_PapSmearBahanName as name, + IF(ISNULL(Other_PapSmearBahanID),'N','Y') as selected + FROM m_papsmearbahan + LEFT JOIN other_papsmearbahan ON Other_PapSmearBahanM_PapSmearBahanID = M_PapSmearBahanID AND + Other_PapSmearBahanOther_PapSmearID = {$header_id} AND + Other_PapSmearBahanIsActive = 'Y' + WHERE + M_PapSmearBahanIsActive = 'Y' + ORDER BY M_PapSmearBahanID ASC + "; + //echo $sql; + $bahans = $this->db_smartone->query($sql)->result_array(); + + $sql = "SELECT IFNULL(Other_PapsmearCategoryID,0) as xid, + M_PapSmearCategoryID as category_id, + M_PapSmearCategoryName as name, + IF(ISNULL(Other_PapsmearCategoryID),'N','Y') as selected + FROM m_papsmearcategory + LEFT JOIN other_papsmearcategory ON Other_PapsmearCategoryM_PapSmearCategoryID = M_PapSmearCategoryID AND + Other_PapsmearCategoryOther_PapSmearID = {$header_id} AND + Other_PapsmearCategoryIsActive = 'Y' + WHERE + M_PapSmearCategoryIsActive = 'Y' + ORDER BY M_PapSmearCategoryID ASC + "; + //echo $sql; + $categories = $this->db_smartone->query($sql)->result_array(); + + $sql = "SELECT IFNULL(Other_PapSmearCheckID,0) as xid, + M_PapSmearCheckID as check_id, + M_PapSmearCheckLabel as name, + IF(ISNULL(Other_PapSmearCheckID),'N','Y') as selected, + Other_PapSmearCheckNote as note + FROM m_papsmearcheck + LEFT JOIN other_papsmearcheck ON Other_PapSmearCheckM_PapSmearCheckID = M_PapSmearCheckID AND + Other_PapSmearCheckOther_PapSmearID = {$header_id} AND + Other_PapSmearCheckIsActive = 'Y' + WHERE + M_PapSmearCheckIsActive = 'Y' + ORDER BY M_PapSmearCheckCode ASC + "; + $checks = $this->db_smartone->query($sql)->result_array(); + + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $rst = array('doctors' => $doctors, 'checks' => $checks, 'bahans' => $bahans, 'categories' => $categories, 'maturasi' => $maturasi, 'results' => $rows); + $this->sys_ok(["records" => $rst]); + } + + function saveresult_lcprep() + { + $prm = $this->sys_input; + $detail_id = $prm['detail_id']; + $doctor_id = $prm['doctor']; + $adekuasi = $prm['adekuasi']; + $kategoriumum = $prm['kategoriumum']; + $interpretasi = $prm['interpretasi']; + $results = $prm['results']; + + $userid = $this->sys_user['M_UserID']; + + $header_id = 0; + $sql = "SELECT * FROM other_lcprep WHERE Other_LcprepT_orderDetailID = {$detail_id} AND Other_LcprepIsActive = 'Y'"; + $dt_header = $this->db_smartone->query($sql)->row_array(); + if ($dt_header) { + $header_id = $dt_header['Other_LcprepID']; + } + if ($header_id == 0) { + $sql = "INSERT INTO other_lcprep( + Other_LcprepT_orderDetailID, + Other_LcprepM_DoctorID, + Other_LcprepUserID, + Other_LcprepCreated + ) + VALUES( + {$detail_id}, + {$doctor_id}, + {$userid}, + NOW() + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } else { + $sql = "UPDATE other_lcprep SET Other_LcprepM_DoctorID = {$doctor_id}, Other_LcprepUserID = {$userid} WHERE Other_LcprepID = {$header_id}"; + $this->db_smartone->query($sql); + } + + if ($adekuasi) { + foreach ($adekuasi as $k => $v) { + $selected = $v['chex'] ? 'Y' : 'N'; + if (intval($v['xid'] == 0)) { + $sql = "UPDATE other_lcprepadekuasi SET Other_LcprepAdekuasiIsActive = 'N' + WHERE + Other_LcprepAdekuasiOther_LcprepID = {$header_id} AND + Other_LcprepAdekuasiIsActive = 'Y' AND + Other_LcprepAdekuasiLcprep_AdekuasiID = {$v['id']}"; + $this->db_smartone->query($sql); + $sql = "INSERT INTO other_lcprepadekuasi ( + Other_LcprepAdekuasiOther_LcprepID, + Other_LcprepAdekuasiLcprep_AdekuasiID, + Other_LcprepAdekuasiChex, + Other_LcprepAdekuasiUserID, + Other_LcprepAdekuasiCreated + ) + VALUES( + {$header_id}, + {$v['id']}, + '{$selected}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + //echo $sql; + } + if (intval($v['xid'] != 0)) { + + $sql = "UPDATE other_lcprepadekuasi SET + Other_LcprepAdekuasiChex = '{$selected}', + Other_LcprepAdekuasiUserID = {$userid} + WHERE + Other_LcprepAdekuasiID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + + //echo $sql; + } + } + + if ($kategoriumum) { + foreach ($kategoriumum as $k => $v) { + $selected = $v['chex'] ? 'Y' : 'N'; + if (intval($v['xid'] == 0)) { + $sql = "UPDATE other_lcprepkategoriumum SET Other_LcprepKategoriUmumIsActive = 'N' + WHERE + Other_LcprepKategoriUmumOther_LcprepID = {$header_id} AND + Other_LcprepKategoriUmumLcprep_KategoriUmumID = {$v['id']} AND + Other_LcprepKategoriUmumIsActive = 'Y' + "; + $this->db_smartone->query($sql); + $sql = "INSERT INTO other_lcprepkategoriumum ( + Other_LcprepKategoriUmumOther_LcprepID, + Other_LcprepKategoriUmumLcprep_KategoriUmumID, + Other_LcprepKategoriUmumChex, + Other_LcprepKategoriUmumUserID, + Other_LcprepKategoriUmumCreated + ) + VALUES( + {$header_id}, + {$v['id']}, + '{$selected}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if (intval($v['xid'] != 0)) { + $sql = "UPDATE other_lcprepkategoriumum SET + Other_LcprepKategoriUmumChex = '{$selected}', + Other_LcprepKategoriUmumUserID = {$userid} + WHERE + Other_LcprepKategoriUmumID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + + //echo $sql; + } + } + + if ($results) { + foreach ($results as $k => $v) { + if (intval($v['xid'] == 0)) { + $sql = "UPDATE other_lcprepdetails SET Other_LcprepDetailsIsActive = 'N' + WHERE + Other_LcprepDetailsOther_LcprepID = {$header_id} AND + Other_LcprepDetailsCode = '{$v['code']}' AND + Other_LcprepDetailsIsActive = 'Y'"; + $this->db_smartone->query($sql); + $sql = "INSERT INTO other_lcprepdetails ( + Other_LcprepDetailsOther_LcprepID, + Other_LcprepDetailsCode, + Other_LcprepDetailsLabel, + Other_LcprepDetailsResult, + Other_LcprepDetailsUserID, + Other_LcprepDetailsCreated + ) + VALUES( + {$header_id}, + '{$v['code']}', + '{$v['label']}', + '{$v['result']}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if (intval($v['xid'] != 0)) { + $sql = "UPDATE other_lcprepdetails SET + Other_LcprepDetailsCode = '{$v['code']}', + Other_LcprepDetailsLabel = '{$v['label']}', + Other_LcprepDetailsResult = '{$v['result']}', + Other_LcprepDetailsUserID = {$userid} + WHERE + Other_LcprepDetailsID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + //echo $sql; + } + } + + if ($interpretasi) { + foreach ($interpretasi as $k => $v) { + if (count($v['subgroups']) > 0) { + foreach ($v['subgroups'] as $ik => $iv) { + if (count($iv['childs']) > 0) { + foreach ($iv['childs'] as $iik => $iiv) { + if (intval($iiv['xid'] == 0)) { + $chex = $iiv['chex'] ? 'Y' : 'N'; + $sql = "UPDATE other_lcprepinterpretasi SET Other_LcprepInterpretasiIsActive = 'N' + WHERE + Other_LcprepInterpretasiOther_LcprepID = {$header_id} AND + Other_LcprepInterpretasiLcprep_InterpretasiID = '{$iiv['id']}' AND + Other_LcprepInterpretasiIsActive = 'Y'"; + $this->db_smartone->query($sql); + $sql = "INSERT INTO other_lcprepinterpretasi ( + Other_LcprepInterpretasiOther_LcprepID, + Other_LcprepInterpretasiLcprep_InterpretasiID, + Other_LcprepInterpretasiChex, + Other_LcprepInterpretasiValue, + Other_LcprepInterpretasiUserID, + Other_LcprepInterpretasiCreated + ) + VALUES( + {$header_id}, + '{$iiv['id']}', + '{$chex}', + '{$iiv['value']}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + + if (intval($iiv['xid'] != 0)) { + $chex = $iiv['chex'] ? 'Y' : 'N'; + $sql = "UPDATE other_lcprepinterpretasi SET + Other_LcprepInterpretasiChex = '{$chex}', + Other_LcprepInterpretasiValue = '{$iiv['value']}', + Other_LcprepInterpretasiUserID = {$userid} + WHERE + Other_LcprepInterpretasiID = {$iiv['xid']}"; + $this->db_smartone->query($sql); + //echo $sql; + + } + } + } + } + } + //echo $sql; + } + } + + + $result = array("total" => 1, "records" => array(), "sql" => ''); + $this->sys_ok($result); + exit; + } + + function saveresult_papsmear() + { + $prm = $this->sys_input; + $detail_id = $prm['detail_id']; + $doctor_id = $prm['doctor']; + $checks = $prm['checks']; + $maturasi = $prm['maturasi']; + $bahans = $prm['bahans']; + $categories = $prm['categories']; + $results = $prm['results']; + + $userid = $this->sys_user['M_UserID']; + + $header_id = 0; + $sql = "SELECT * FROM other_papsmear WHERE Other_PapSmearT_OrderDetailID = {$detail_id} AND Other_PapSmearIsActive = 'Y'"; + $dt_header = $this->db_smartone->query($sql)->row_array(); + if ($dt_header) { + $header_id = $dt_header['Other_PapSmearID']; + } + if ($header_id == 0) { + $sql = "INSERT INTO other_papsmear( + Other_PapSmearT_OrderDetailID, + Other_PapSmearM_DoctorID, + Other_PapSmearUserID, + Other_PapSmearCreated + ) + VALUES( + {$detail_id}, + {$doctor_id}, + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } else { + $sql = "UPDATE other_papsmear SET Other_PapSmearM_DoctorID = {$doctor_id}, Other_PapSmearUserID = {$userid} WHERE Other_PapSmearID = {$header_id}"; + $this->db_smartone->query($sql); + } + + if ($checks) { + foreach ($checks as $k => $v) { + if (intval($v['xid']) == 0 && $v['selected'] === 'Y') { + $sql = "INSERT INTO other_papsmearcheck ( + Other_PapSmearCheckOther_PapSmearID, + Other_PapSmearCheckM_PapSmearCheckID, + Other_PapSmearCheckNote, + Other_PapSmearCheckUserID, + Other_PapSmearCheckCreated + ) + VALUES( + {$header_id}, + {$v['check_id']}, + '{$v['note']}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if (intval($v['xid']) != 0 && $v['selected'] === 'N') { + $sql = "UPDATE other_papsmearcheck SET + Other_PapSmearCheckIsActive = 'N', + Other_PapSmearCheckUserID = {$userid} + WHERE + Other_PapSmearCheckID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + if (intval($v['xid']) != 0 && $v['selected'] === 'Y') { + $sql = "UPDATE other_papsmearcheck SET + Other_PapSmearCheckNote = '{$v['note']}', + Other_PapSmearCheckUserID = {$userid} + WHERE + Other_PapSmearCheckID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + //echo $sql; + } + } + + if ($maturasi) { + if (intval($maturasi['xid']) == 0) { + $value = join("/", $maturasi['value']); + $sql = "INSERT INTO other_papsmearmaturasi ( + Other_PapSmearMaturasiOther_PapSmearID, + Other_PapSmearMaturasiValue, + Other_PapSmearMaturasiUserID, + Other_PapSmearMaturasiCreated + ) + VALUE( + {$header_id}, + '{$value}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + //echo $sql; + } + if (intval($maturasi['xid']) != 0) { + $value = join("/", $maturasi['value']); + $sql = "UPDATE other_papsmearmaturasi SET + Other_PapSmearMaturasiValue = '{$value}', + Other_PapSmearMaturasiUserID = {$userid} + WHERE + Other_PapSmearMaturasiID = {$maturasi['xid']}"; + // echo $sql; + $this->db_smartone->query($sql); + } + } + + if ($bahans) { + foreach ($bahans as $k => $v) { + if (intval($v['xid']) == 0 && $v['selected'] === 'Y') { + $sql = "INSERT INTO other_papsmearbahan ( + Other_PapSmearBahanOther_PapSmearID, + Other_PapSmearBahanM_PapSmearBahanID, + Other_PapSmearBahanUserID, + Other_PapSmearBahanCreated + ) + VALUES( + {$header_id}, + {$v['bahan_id']}, + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if (intval($v['xid']) != 0 && $v['selected'] === 'N') { + $sql = "UPDATE other_papsmearbahan SET + Other_PapSmearBahanIsActive = 'N', + Other_PapsmearCategoryUserID = {$userid} + WHERE + Other_PapSmearBahanID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + if (intval($v['xid']) != 0 && $v['selected'] === 'Y') { + $sql = "UPDATE other_papsmearbahan SET + Other_PapSmearBahanIsActive = 'Y', + Other_PapsmearCategoryUserID = {$userid} + WHERE + Other_PapSmearBahanID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + //echo $sql; + } + } + + if ($categories) { + foreach ($categories as $k => $v) { + if (intval($v['xid']) == 0 && $v['selected'] === 'Y') { + $sql = "INSERT INTO other_papsmearcategory ( + Other_PapsmearCategoryOther_PapSmearID, + Other_PapsmearCategoryM_PapSmearCategoryID, + Other_PapsmearCategoryUserID, + Other_PapsmearCategoryCreated + ) + VALUES( + {$header_id}, + {$v['category_id']}, + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if (intval($v['xid']) != 0 && $v['selected'] === 'N') { + $sql = "UPDATE other_papsmearcategory SET + Other_PapsmearCategoryIsActive = 'N', + Other_PapsmearCategoryUserID = {$userid} + WHERE + Other_PapsmearCategoryID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + //echo $sql; + if (intval($v['xid']) != 0 && $v['selected'] === 'Y') { + $sql = "UPDATE other_papsmearcategory SET + Other_PapsmearCategoryIsActive = 'Y', + Other_PapsmearCategoryUserID = {$userid} + WHERE + Other_PapsmearCategoryID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + } + } + + if ($results) { + foreach ($results as $k => $v) { + if (intval($v['xid']) == 0) { + $sql = "INSERT INTO other_papsmeardetails ( + Other_PapSmearDetailsOther_PapSmearID, + Other_PapSmearDetailsCode, + Other_PapSmearDetailsLabel, + Other_PapSmearDetailsResult, + Other_PapSmearDetailsUserID, + Other_PapSmearDetailsCreated + ) + VALUES( + {$header_id}, + '{$v['code']}', + '{$v['label']}', + '{$v['result']}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if (intval($v['xid']) != 0) { + $sql = "UPDATE other_papsmeardetails SET + Other_PapSmearDetailsCode = '{$v['code']}', + Other_PapSmearDetailsLabel = '{$v['label']}', + Other_PapSmearDetailsResult = '{$v['result']}', + Other_PapSmearDetailsUserID = {$userid} + WHERE + Other_PapSmearDetailsID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + //echo $sql; + } + } + + $result = array("total" => 1, "records" => array(), "sql" => ''); + $this->sys_ok($result); + exit; + } + + function saveresult_fna() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = $inp['doctor']; + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + if ($prm[0]['xid'] == '0') { + $sql = "INSERT INTO other_fna( + Other_FNAM_DoctorID, + Other_FNAT_OrderDetailID, + Other_FNAUserID, + Other_FNACreated + ) + VALUES( + {$doctor_id}, + {$prm[0]['orderdetail_id']}, + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } else { + $sql = "SELECT * FROM other_fna WHERE Other_FNAT_OrderDetailID = {$prm[0]['orderdetail_id']} AND Other_FNAIsActive = 'Y'"; + $data_header = $this->db_smartone->query($sql)->row_array(); + $header_id = $data_header['Other_FNAID']; + $sql = "UPDATE other_fna SET + Other_FNAM_DoctorID = {$doctor_id}, + Other_FNAUserID = {$userid} + WHERE + Other_FNAID = {$header_id}"; + $this->db_smartone->query($sql); + } + foreach ($prm as $k => $v) { + if ($v['xid'] == '0') { + $results = str_replace("'", "\\'", $v['result']); + $sql = "INSERT INTO other_fnadetails( + Other_FNADetailsOther_FNAID , + Other_FNADetailsCode, + Other_FNADetailsLabel, + Other_FNADetailsResult, + Other_FNADetailsCreated, + Other_FNADetailsUserID + ) + VALUES( + {$header_id}, + '{$v['code']}', + '{$v['label']}', + '{$results}', + NOW(), + {$userid} + )"; + $query = $this->db_smartone->query($sql); + } else { + $results = str_replace("'", "\\'", $v['result']); + $sql = "UPDATE other_fnadetails SET + Other_FNADetailsResult = '{$results}', + Other_FNADetailsUserID = {$userid} + WHERE + Other_FNADetailsID = {$v['xid']}"; + $query = $this->db_smartone->query($sql); + } + } + + $result = array("total" => 1, "records" => array(), "sql" => ''); + $this->sys_ok($result); + exit; + } + + function saveresult_cytologi() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = $inp['doctor']; + + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + if ($prm[0]['xid'] == '0') { + $sql = "INSERT INTO other_cytologi( + Other_CytologiT_OrderDetailID, + Other_CytologiM_DoctorID, + Other_CytologiUserID, + Other_CytologiCreated + ) + VALUES( + {$prm[0]['orderdetail_id']}, + {$doctor_id}, + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } else { + $sql = "SELECT * FROM other_cytologi WHERE Other_CytologiT_OrderDetailID = {$prm[0]['orderdetail_id']} AND Other_CytologiIsActive = 'Y'"; + $data_header = $this->db_smartone->query($sql)->row_array(); + $header_id = $data_header['Other_CytologiID']; + $sql = "UPDATE other_cytologi SET + Other_CytologiM_DoctorID = {$doctor_id}, + Other_CytologiUserID = {$userid} + WHERE + Other_CytologiID = {$header_id}"; + $this->db_smartone->query($sql); + } + foreach ($prm as $k => $v) { + if ($v['xid'] == '0') { + $results = str_replace("'", "\\'", $v['result']); + $sql = "INSERT INTO other_cytologidetails( + Other_CytologiDetailsOther_CytologiID , + Other_CytologiDetailsCode, + Other_CytologiDetailsLabel, + Other_CytologiDetailsResult, + Other_CytologiDetailsCreated, + Other_CytologiDetailsUserID + ) + VALUES( + {$header_id}, + '{$v['code']}', + '{$v['label']}', + '{$results}', + NOW(), + {$userid} + )"; + $query = $this->db_smartone->query($sql); + } else { + $results = str_replace("'", "\\'", $v['result']); + $sql = "UPDATE other_cytologidetails SET + Other_CytologiDetailsResult = '{$results}', + Other_CytologiDetailsUserID = {$userid} + WHERE + Other_CytologiDetailsID = {$v['xid']}"; + $query = $this->db_smartone->query($sql); + } + } + + $result = array("total" => 1, "records" => array(), "sql" => ''); + $this->sys_ok($result); + exit; + } + + function saveresult_mikro() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = $inp['doctor']; + $backteria_id = $inp['bacteria']; + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + + if ($inp['result_value'] != 'Negatif' && $inp['result_value'] != 'Positif') { + $prm['result_value'] = $prm['result_other']; + } else { + $prm['result_value'] = $inp['result_value']; + } + + if ($prm['xid'] == '0') { + $sql = "INSERT INTO other_mikro( + Other_MikroM_DoctorID, + Other_MikroResult, + Other_MikroT_BacteriaID, + Other_MikroT_OrderDetailID, + Other_MikroHasilBiakan, + Other_MikroSampleTypeName, + Other_MikroUserID, + Other_MikroCreated + ) + VALUES( + {$doctor_id}, + '{$prm['result_value']}', + {$backteria_id}, + {$prm['orderdetail_id']}, + '{$prm['hasil_biakan']}', + '{$prm['sample_name']}', + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } else { + $sql = "SELECT * FROM other_mikro WHERE Other_MikroT_OrderDetailID = {$prm['orderdetail_id']} AND Other_MikroIsActive = 'Y'"; + $data_header = $this->db_smartone->query($sql)->row_array(); + $header_id = $data_header['Other_MikroID']; + $sql = "UPDATE other_mikro SET + Other_MikroResult = '{$prm['result_value']}', + Other_MikroM_DoctorID = {$doctor_id}, + Other_MikroT_BacteriaID = {$backteria_id}, + Other_MikroHasilBiakan = '{$prm['hasil_biakan']}', + Other_MikroSampleTypeName = '{$prm['sample_name']}', + Other_MikroUserID = {$userid} + WHERE + Other_MikroID = {$header_id}"; + //echo $sql; + $this->db_smartone->query($sql); + } + + + + $sql = "UPDATE other_mikrodetails SET Other_MikroDetailsIsActive = 'N', Other_MikroDetailsUserID = 0 WHERE Other_MikroDetailsOther_MikroID = {$header_id}"; + $this->db_smartone->query($sql); + + $results = $prm['details']; + if ($inp['result_value'] == 'Positif') { + foreach ($results as $k => $v) { + if ($v['xid'] == '0') { + $sql = "INSERT INTO other_mikrodetails( + Other_MikroDetailsOther_MikroID , + Other_MikroDetailsT_AntibioticID, + Other_MikroDetailsValue, + Other_MikroDetailsNote, + Other_MikroDetailsCreated, + Other_MikroDetailsUserID + ) + VALUES( + {$header_id}, + '{$v['T_AntibioticID']}', + '{$v['value']}', + '{$v['note']}', + NOW(), + {$userid} + )"; + $query = $this->db_smartone->query($sql); + } else { + $sql = "UPDATE other_mikrodetails SET + Other_MikroDetailsT_AntibioticID = '{$v['T_AntibioticID']}', + Other_MikroDetailsValue = '{$v['value']}', + Other_MikroDetailsNote = '{$v['note']}', + Other_MikroDetailsIsActive = 'Y', + Other_MikroDetailsUserID = {$userid} + WHERE + Other_MikroDetailsID = {$v['xid']}"; + //echo $sql; + $query = $this->db_smartone->query($sql); + } + } + } + + + $result = array("total" => 1, "records" => array(), "sql" => ''); + $this->sys_ok($result); + exit; + } + + + function get_doctors_preparasi_sperma() + { + $prm = $this->sys_input; + // $id = $prm["id"]; + + $sql = " SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 10 AND + M_DoctorSOIsActive = 'Y' + ORDER BY M_DoctorName ASC"; + //echo $sql; + $query = $this->db_smartone->query($sql); + $rows = $query->result_array(); + $sql = " + SELECT '0' as id, 'Belum memilih metode' as name + UNION + SELECT M_MethodeSpermaID as id, M_MethodeSpermaName as name + FROM m_methodesperma + WHERE + M_MethodeSpermaIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $methodes = $this->db_smartone->query($sql)->result_array(); + + + $this->sys_ok(["records" => $rows, "methodes" => $methodes]); + } + + + function getpreparasispermaresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT other_preparasisperma.*, + Other_PreparasiSpermaID as xid, + Other_PreparasiSpermaT_OrderDetailID as orderdetail_id, + IFNULL(Other_PreparasiSpermaM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_PreparasiSpermaM_DoctorID) OR Other_PreparasiSpermaM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name, + IFNULL(M_MethodeSpermaID,0) as methode_id, + IFNULL(M_MethodeSpermaName,'') as methode_name + FROM other_preparasisperma + LEFT JOIN m_doctor ON Other_PreparasiSpermaM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + LEFT JOIN m_methodesperma ON Other_PreparasiSpermaM_MethodeSpermaID = M_MethodeSpermaID AND + M_MethodeSpermaIsActive = 'Y' + WHERE + Other_PreparasiSpermaT_OrderDetailID = {$id} AND Other_PreparasiSpermaIsActive = 'Y' + GROUP BY Other_PreparasiSpermaID"; + $query = $this->db_smartone->query($sql); + + if ($query) { + $rows = $query->row_array(); + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 10 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $sql = " + SELECT '0' as id, 'Belum memilih metode' as name + UNION + SELECT M_MethodeSpermaID as id, M_MethodeSpermaName as name + FROM m_methodesperma + WHERE + M_MethodeSpermaIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $methodes = $this->db_smartone->query($sql)->result_array(); + $images = array(); + $sql = "SELECT Other_PreparasiSpermaImgID as xid, + Other_PreparasiSpermaImgType as type, + CONCAT('/one-media/one-image-nonlab/',Other_PreparasiSpermaImgNewName) as image_url + FROM t_orderdetail + JOIN other_preparasisperma_img ON Other_PreparasiSpermaImgT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND + Other_PreparasiSpermaImgIsActive = 'Y' + WHERE + T_OrderDetailID = {$id} AND + T_OrderDetailIsActive = 'Y' + GROUP BY Other_PreparasiSpermaImgID"; + //echo $sql; + $images = $this->db_smartone->query($sql)->result_array(); + + $rst = array('doctors' => $doctors, 'methodes' => $methodes, 'results' => $rows, 'images' => $images); + $this->sys_ok(["records" => $rst]); + } else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + + function uploadimage_preparasi_sperma() + { + if (! $this->isLogin) { + $this->sys_error("Invalid Token"); + exit; + } + + $userid = $this->sys_user["M_UserID"]; + $data = []; + //print_r($_SERVER); + + $prm = $this->sys_input; + $orderid = $this->input->post('orderid'); + $type = $this->input->post('type'); + $labnumber = $this->input->post('labnumber'); + $sql = "UPDATE other_preparasisperma_img SET + Other_PreparasiSpermaImgIsActive = 'N', + Other_PreparasiSpermaImgUserID = {$userid} + WHERE + Other_PreparasiSpermaImgT_OrderHeaderID = {$orderid} AND + Other_PreparasiSpermaImgType = '{$type}'"; + //echo $sql; + $this->db_onedev->query($sql); + //$config['upload_path'] = 'assets/'; + + $path = '/home/one/project/one/one-media/one-image-nonlab/'; + //echo $path; + $config['upload_path'] = $path; + $config['allowed_types'] = 'jpg|jpeg|png|gif'; + + $config['max_size'] = '10000'; + $count = count($_FILES['files']['name']); + //echo $count; + $this->load->library('upload', $config); + + $error = []; + for ($i = 0; $i < $count; $i++) { + + + if (!empty($_FILES['files']['name'][$i])) { + + + + $_FILES['file']['name'] = $_FILES['files']['name'][$i]; + + $_FILES['file']['type'] = $_FILES['files']['type'][$i]; + + $_FILES['file']['tmp_name'] = $_FILES['files']['tmp_name'][$i]; + + $_FILES['file']['error'] = $_FILES['files']['error'][$i]; + + $_FILES['file']['size'] = $_FILES['files']['size'][$i]; + + + + $namex = $orderid . '-' . $labnumber . '-' . $this->generateRandomString(5); + //echo $namex; + + $config['file_name'] = $namex; + $this->upload->initialize($config); + //echo $config['file_name'] ; + + + + + + if ($this->upload->do_upload('file')) { + + $uploadData = $this->upload->data(); + + $filename = $uploadData['file_name']; + //echo $filename; + + + $sql = "INSERT INTO other_preparasisperma_img ( + Other_PreparasiSpermaImgT_OrderHeaderID, + Other_PreparasiSpermaImgType, + Other_PreparasiSpermaImgOldName, + Other_PreparasiSpermaImgNewName, + Other_PreparasiSpermaImgCreated, + Other_PreparasiSpermaImgUserID + ) + VALUES( + {$orderid}, + '{$type}', + '{$_FILES['files']['name'][$i]}', + '{$filename}', + NOW(), + {$userid} + + )"; + //echo $sql; + $this->db_onedev->query($sql); + $xlast_id = $this->db_onedev->insert_id(); + $data['totalFiles'][] = array('xid' => $xlast_id, 'type' => $type, 'image_url' => '/one-media/one-image-nonlab/' . $filename); + } else { + $error = array('error' => $this->upload->display_errors()); + } + } + } + + $result = array("total" => count($data['totalFiles']), "records" => $data['totalFiles'], 'errors' => $error); + $this->sys_ok($result); + } + + + function saveresult_preparasi_sperma() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = $inp['doctor']; + $orderdetail_id = $inp['orderdetailid']; + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + if ($prm['xid'] == '0') { + $sql = "INSERT INTO other_preparasisperma( + Other_PreparasiSpermaM_DoctorID, + Other_PreparasiSpermaT_OrderDetailID, + Other_PreparasiSpermaPreMotilitasA, + Other_PreparasiSpermaPreMotilitasB, + Other_PreparasiSpermaPreMotilitasC, + Other_PreparasiSpermaPreKonsentrasi, + Other_PreparasiSpermaPreKontaminan, + Other_PreparasiSpermaPostMotilitasA, + Other_PreparasiSpermaPostMotilitasB, + Other_PreparasiSpermaPostMotilitasC, + Other_PreparasiSpermaPostKonsentrasi, + Other_PreparasiSpermaPostKontaminan, + Other_PreparasiSpermaPreVolume, + Other_PreparasiSpermaPostVolume, + Other_PreparasiSpermaM_MethodeSpermaID, + Other_PreparasiSpermaNote, + Other_PreparasiSpermaUserID, + Other_PreparasiSpermaCreated + ) + VALUES( + {$doctor_id}, + {$orderdetail_id}, + '{$prm['Other_PreparasiSpermaPreMotilitasA']}', + '{$prm['Other_PreparasiSpermaPreMotilitasB']}', + '{$prm['Other_PreparasiSpermaPreMotilitasC']}', + '{$prm['Other_PreparasiSpermaPreKonsentrasi']}', + '{$prm['Other_PreparasiSpermaPreKontaminan']}', + '{$prm['Other_PreparasiSpermaPostMotilitasA']}', + '{$prm['Other_PreparasiSpermaPostMotilitasB']}', + '{$prm['Other_PreparasiSpermaPostMotilitasC']}', + '{$prm['Other_PreparasiSpermaPostKonsentrasi']}', + '{$prm['Other_PreparasiSpermaPostKontaminan']}', + '{$prm['Other_PreparasiSpermaPreVolume']}', + '{$prm['Other_PreparasiSpermaPostVolume']}', + '{$prm['Other_PreparasiSpermaM_MethodeSpermaID']}', + '{$prm['Other_PreparasiSpermaNote']}', + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } else { + $sql = "SELECT * FROM other_preparasisperma WHERE Other_PreparasiSpermaT_OrderDetailID = {$orderdetail_id} AND Other_PreparasiSpermaIsActive = 'Y'"; + $data_header = $this->db_smartone->query($sql)->row_array(); + $header_id = $data_header['Other_PreparasiSpermaID']; + $sql = "UPDATE other_preparasisperma SET + Other_PreparasiSpermaM_DoctorID = {$doctor_id}, + Other_PreparasiSpermaPreMotilitasA = '{$prm['Other_PreparasiSpermaPreMotilitasA']}', + Other_PreparasiSpermaPreMotilitasB = '{$prm['Other_PreparasiSpermaPreMotilitasB']}', + Other_PreparasiSpermaPreMotilitasC = '{$prm['Other_PreparasiSpermaPreMotilitasC']}', + Other_PreparasiSpermaPreKonsentrasi = '{$prm['Other_PreparasiSpermaPreKonsentrasi']}', + Other_PreparasiSpermaPreKontaminan = '{$prm['Other_PreparasiSpermaPreKontaminan']}', + Other_PreparasiSpermaPostMotilitasA = '{$prm['Other_PreparasiSpermaPostMotilitasA']}', + Other_PreparasiSpermaPostMotilitasB = '{$prm['Other_PreparasiSpermaPostMotilitasB']}', + Other_PreparasiSpermaPostMotilitasC = '{$prm['Other_PreparasiSpermaPostMotilitasC']}', + Other_PreparasiSpermaPostKonsentrasi = '{$prm['Other_PreparasiSpermaPostKonsentrasi']}', + Other_PreparasiSpermaPostKontaminan = '{$prm['Other_PreparasiSpermaPostKontaminan']}', + Other_PreparasiSpermaPreVolume = '{$prm['Other_PreparasiSpermaPreVolume']}', + Other_PreparasiSpermaPostVolume = '{$prm['Other_PreparasiSpermaPostVolume']}', + Other_PreparasiSpermaM_MethodeSpermaID = '{$prm['Other_PreparasiSpermaM_MethodeSpermaID']}', + Other_PreparasiSpermaNote = '{$prm['Other_PreparasiSpermaNote']}', + Other_PreparasiSpermaUserID = {$userid} + WHERE + Other_PreparasiSpermaID = {$header_id}"; + $this->db_smartone->query($sql); + } + + + $result = array("total" => 1, "records" => array(), "sql" => ''); + $this->sys_ok($result); + exit; + } + + function getdnafragmentasiresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT other_dnafragmentasi.*, + Other_DnaFragmentasiID as xid, + Other_DnaFragmentasiT_OrderDetailID as orderdetail_id, + IFNULL(Other_DnaFragmentasiM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_DnaFragmentasiM_DoctorID) OR Other_DnaFragmentasiM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name, + IFNULL(Other_DnaFragmentasiOther_DnaFragmentasiMethodeID,0) as methode_id, + IFNULL(Other_DnaFragmentasiMethodeName,'') as methode_name, + Other_DnaFragmentasiHaloLuas as halo_luas, + Other_DnaFragmentasiHaloSedang as halo_sedang, + Other_DnaFragmentasiHaloSempit as halo_sempit, + Other_DnaFragmentasiTanpaHalo as tanpa_halo, + Other_DnaFragmentasiDFI as dfi, + Other_DnaFragmentasiKesimpulan as kesimpulan, + Other_DnaFragmentasiCatatan as catatan + FROM other_dnafragmentasi + LEFT JOIN m_doctor ON Other_DnaFragmentasiM_DoctorID = M_DoctorID + LEFT JOIN other_dnafragmentasimethode ON Other_DnaFragmentasiOther_DnaFragmentasiMethodeID = Other_DnaFragmentasiMethodeID + WHERE + Other_DnaFragmentasiT_OrderDetailID = {$id} AND Other_DnaFragmentasiIsActive = 'Y' + GROUP BY Other_DnaFragmentasiID + LIMIT 1"; + //echo $sql; + $query = $this->db_smartone->query($sql); + + if ($query) { + $rows = $query->row_array(); + if (!$rows) { + $rows = array( + 'xid' => 0, + 'orderdetail_id' => $id, + 'doctor_id' => 0, + 'doctor_name' => '', + 'methode_id' => 0, + 'methode_name' => '', + 'halo_luas' => '', + 'halo_sedang' => '', + 'tanpa_halo' => '', + 'dfi' => '', + 'kesimpulan' => '', + 'catatan' => '' + ); + } + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID + WHERE + M_DoctorSONat_SubGroupID = 4 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + + $sql = " + SELECT '0' as id, 'Belum memilih metode' as name + UNION + SELECT Other_DnaFragmentasiMethodeID as id, Other_DnaFragmentasiMethodeName as name + FROM other_dnafragmentasimethode + WHERE + Other_DnaFragmentasiMethodeIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $methodes = $this->db_smartone->query($sql)->result_array(); + + + $rst = array('doctors' => $doctors, 'methodes' => $methodes, 'results' => $rows); + $this->sys_ok(["records" => $rst]); + } else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + function saveresult_dnafragmentasi() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = $inp['doctor']['id']; + $methode_id = $inp['methode']['id']; + $orderdetail_id = $inp['results']['orderdetail_id']; + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + if (intval($prm['xid']) == 0) { + $sql = "INSERT INTO other_dnafragmentasi( + Other_DnaFragmentasiT_OrderDetailID, + Other_DnaFragmentasiM_DoctorID, + Other_DnaFragmentasiOther_DnaFragmentasiMethodeID, + Other_DnaFragmentasiHaloLuas, + Other_DnaFragmentasiHaloSedang, + Other_DnaFragmentasiHaloSempit, + Other_DnaFragmentasiTanpaHalo, + Other_DnaFragmentasiDFI, + Other_DnaFragmentasiKesimpulan, + Other_DnaFragmentasiCatatan, + Other_DnaFragmentasiUserID, + Other_DnaFragmentasiLastUpdated + ) + VALUES( + {$orderdetail_id}, + {$doctor_id}, + {$methode_id}, + '{$prm['halo_luas']}', + '{$prm['halo_sedang']}', + '{$prm['halo_sempit']}', + '{$prm['tanpa_halo']}', + '{$prm['dfi']}', + '{$prm['kesimpulan']}', + '{$prm['catatan']}', + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } else { + $sql = "UPDATE other_dnafragmentasi SET + Other_DnaFragmentasiT_OrderDetailID = {$orderdetail_id}, + Other_DnaFragmentasiM_DoctorID = {$doctor_id}, + Other_DnaFragmentasiOther_DnaFragmentasiMethodeID = '{$methode_id}', + Other_DnaFragmentasiHaloLuas = '{$prm['halo_luas']}', + Other_DnaFragmentasiHaloSedang = '{$prm['halo_sedang']}', + Other_DnaFragmentasiHaloSempit = '{$prm['halo_sempit']}', + Other_DnaFragmentasiTanpaHalo = '{$prm['tanpa_halo']}', + Other_DnaFragmentasiDFI = '{$prm['dfi']}', + Other_DnaFragmentasiKesimpulan = '{$prm['kesimpulan']}', + Other_DnaFragmentasiCatatan = '{$prm['catatan']}', + Other_DnaFragmentasiLastUpdated = NOW(), + Other_DnaFragmentasiUserID = {$userid} + WHERE + Other_DnaFragmentasiID = {$prm['xid']}"; + //echo $sql; + $this->db_smartone->query($sql); + } + + + $result = array("total" => 1, "records" => array(), "sql" => ''); + $this->sys_ok($result); + exit; + } +} diff --git a/application/controllers/mockup/process/resultverification-v21/Re_px.php b/application/controllers/mockup/process/resultverification-v21/Re_px.php index d2c44b96..df562286 100644 --- a/application/controllers/mockup/process/resultverification-v21/Re_px.php +++ b/application/controllers/mockup/process/resultverification-v21/Re_px.php @@ -1,2495 +1,2492 @@ -db_smartone = $this->load->database("onedev", true); - $this->load->helper(array('form', 'url')); - } - function getMethodeID($natTestID) { - $sql = "select M_MethodePriorityNat_MethodeID MethodeID, Nat_MethodeName - from - m_methode_priority - join nat_methode on Nat_MethodeID = M_MethodePriorityNat_MethodeID - and Nat_MethodeIsActive = 'Y' - join m_instrumentmethode on M_InstrumentMethodeNat_MethodeID = Nat_MethodeID and M_InstrumentMethodeIsActive = 'Y' - join nat_instrument on M_InstrumentMethodeNat_InstrumentID = Nat_InstrumentID - and Nat_InstrumentIsActive ='Y' - where M_MethodePriorityIsActive = 'Y' - and M_MethodePriorityNat_TestID = $natTestID - and M_MethodePriorityM_DayOfWeekID = dayofweek(now()) - order by M_MethodePriorityNumber desc - limit 0,1 "; - $qry = $this->db->query($sql); - if ($qry) { - $rows = $qry->result_array(); - if (count($rows) > 0 ) return array($rows[0]["MethodeID"],$rows[0]["Nat_MethodeName"]); - } - //2nd - $sql= "select - M_InstrumentMethodeNat_MethodeID MethodeID, Nat_MethodeName - from m_instrumentmethode - join nat_methode on M_InstrumentMethodeNat_MethodeID = Nat_MethodeID - and Nat_MethodeIsActive = 'Y' - join nat_instrument on M_InstrumentMethodeNat_InstrumentID = Nat_InstrumentID - and Nat_InstrumentIsActive ='Y' - where M_InstrumentMethodeNat_TestID = $natTestID - and M_InstrumentMethodeIsActive = 'Y' - order by M_InstrumentMethodePriority desc - limit 0,1"; - $qry = $this->db->query($sql); - if ($qry) { - $rows = $qry->result_array(); - if (count($rows) > 0 ) return array($rows[0]["MethodeID"],$rows[0]["Nat_MethodeName"]); - } - // - $sql = "select Nat_NormalValueNat_MethodeID MethodeID, Nat_MethodeName - from - nat_normalvalue - join nat_methode on Nat_NormalValueNat_MethodeID = Nat_MethodeID - and Nat_MethodeIsActive = 'Y' - where Nat_NormalValueNat_TestID = $natTestID - and Nat_NormalValueIsActive = 'Y' - order by Nat_NormalValueID - limit 0,1"; - $qry = $this->db->query($sql); - if ($qry) { - $rows = $qry->result_array(); - if (count($rows) > 0 ) return array($rows[0]["MethodeID"],$rows[0]["Nat_MethodeName"]); - } - return array(0,""); - } - function get_normal_value($methodeID, $natTestID, $sexID, $ageInDay ) { - $sql = "select fn_sampling_get_normal($methodeID, $natTestID, $sexID, $ageInDay) as normalValueID"; - $qry = $this->db->query($sql); - if ($qry) { - $rows = $qry->result_array(); - if (count($rows) > 0 ) return $rows[0]["normalValueID"]; - } - return 0; - } - function fn_fix_normal($order_id) { - $sql = "select - T_OrderDetailID, M_PatientM_SexID, fn_global_age_count_day(M_PatientDOB, date(T_OrderHeaderDate)) Dob , - T_TestNat_TestID - from t_orderheader - join m_patient on T_OrderHeaderID = $order_id and T_OrderHeaderM_PatientID = M_PatientID - join t_orderdetail on T_OrderDetailT_OrderHeaderID = T_OrderHeaderID - and T_OrderDetailIsACtive = 'Y' - and ( T_OrderDetailNat_NormalValueID is null or T_OrderDetailNat_NormalValueID = 0 ) - join t_test on T_OrderDetailT_TestID = T_TestID and T_TestIsResult = 'Y' "; - $qry = $this->db->query($sql); - if(! $qry) { - return; - } - $rows = $qry->result_array(); - if(count($rows) == 0 ) return; - $sql_u = "update t_orderdetail - join nat_normalvalue on T_OrderDetailID = ? and Nat_NormalValueID = ? - set - T_OrderDetailNat_NormalValueID = Nat_NormalValueID, - T_OrderDetailNormalValueNote = Nat_NormalValueNote, - T_OrderDetailNormalValueDescription = Nat_NormalValueDescription, - T_OrderDetailMinValue = Nat_NormalValueMinValue, - T_OrderDetailMaxValue = Nat_NormalValueMaxValue, - T_OrderDetailMinValueInclusive = Nat_NormalValueMinValueInclusive, - T_OrderDetailMaxValueInclusive = Nat_NormalValueMaxValueInclusive, - T_OrderDetailNat_MethodeID = ?, - T_OrderdetailNat_MethodeName =?"; - - foreach($rows as $r) { - $T_OrderDetailID = $r["T_OrderDetailID"]; - $sexID = $r["M_PatientM_SexID"]; - $ageInDay = $r["Dob"]; - $natTestID = $r["T_TestNat_TestID"]; - list($methodeID,$methodeName) = $this->getMethodeID($natTestID); - if ($methodeID == 0 ) continue; - $normalValueID = $this->get_normal_value($methodeID, $natTestID, $sexID, $ageInDay); - if ($normalValueID == 0) return; - $this->db->query($sql_u, array($T_OrderDetailID, $normalValueID, $methodeID, $methodeName)); - } - } - function update_order_sample($targetID, $sourceID) { - $sql = "update t_ordersample target - join t_ordersample source on - target.T_OrderSampleID = ? - and target.T_OrderSampleWorklistReceive = 'N' - and source.T_OrderSampleID = ? - set - target.T_OrderSampleSampling = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSampling, source.T_OrderSampleSampling), - target.T_OrderSampleSamplingDate = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingDate, source.T_OrderSampleSamplingDate), - target.T_OrderSampleSamplingTime = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingTime, source.T_OrderSampleSamplingTime), - target.T_OrderSampleSamplingUserID = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingUserID, source.T_OrderSampleSamplingUserID), - - target.T_OrderSampleReceive = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceive, source.T_OrderSampleReceive), - target.T_OrderSampleReceiveDate = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveDate, source.T_OrderSampleReceiveDate), - target.T_OrderSampleReceiveTime = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveTime, source.T_OrderSampleReceiveTime), - target.T_OrderSampleReceiveUserID = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveUserID, source.T_OrderSampleReceiveUserID), - - target.T_OrderSampleVerification = if(target.T_OrderSampleVerification='Y',target.T_OrderSampleVerification, source.T_OrderSampleVerification), - target.T_OrderSampleVerificationDate =if(target.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationDate, source.T_OrderSampleVerificationDate), - target.T_OrderSampleVerificationTime =if(source.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationTime, source.T_OrderSampleVerificationTime), - target.T_OrderSampleVerificationUserID =if(source.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationUserID, source.T_OrderSampleVerificationUserID), - - target.T_OrderSampleProcessing = if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessing, source.T_OrderSampleProcessing), - target.T_OrderSampleProcessingDate= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingDate, source.T_OrderSampleProcessingDate), - target.T_OrderSampleProcessingTime= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingTime, source.T_OrderSampleProcessingTime), - target.T_OrderSampleProcessingUserID= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingUserID, source.T_OrderSampleProcessingUserID), - - target.T_OrderSampleReceiveHandling =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandling, source.T_OrderSampleReceiveHandling ), - target.T_OrderSampleReceiveHandlingDate =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingDate, source.T_OrderSampleReceiveHandlingDate), - target.T_OrderSampleReceiveHandlingTime =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingTime, source.T_OrderSampleReceiveHandlingTime), - target.T_OrderSampleReceiveHandlingUserID =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingUserID, source.T_OrderSampleReceiveHandlingUserID), - - target.T_OrderSampleHandling = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandling, source.T_OrderSampleHandling), - target.T_OrderSampleHandlingDate = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingDate, source.T_OrderSampleHandlingDate), - target.T_OrderSampleHandlingTime = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingTime, source.T_OrderSampleHandlingTime), - target.T_OrderSampleHandlingUserID = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingUserID, source.T_OrderSampleHandlingUserID), - - target.T_OrderSampleWorklistReceive = source.T_OrderSampleWorklistReceive, - target.T_OrderSampleWorklistReceiveDatetime = source.T_OrderSampleWorklistReceiveDateTime, - target.T_OrderSampleWorklistReceiveUserID = source.T_OrderSampleWorklistReceiveUserID - "; - $qry = $this->db->query($sql,array($targetID,$sourceID)); - if(! $qry ) { - echo json_encode(array( "status" => "ERR" , "message" => print_r($this->db->error(),true))); - exit; - } - } - function fix_sample_serum($headerID) { - //cari t_ordersample yg belum worklist receive dengan code 017% - $sql = "select T_OrderSampleID - from t_ordersample - join t_sampletype on - T_OrderSampleT_OrderHeaderID = ? - and T_OrderSampleWorklistReceive = 'N' - and T_OrderSampleIsActive = 'Y' - and T_OrderSampleT_SampleTypeID = T_SampletypeID - and T_SampleTypeCode like '017%' - "; - $qry = $this->db->query($sql, array($headerID)); - if(!$qry) { - echo json_encode(array( "status" => "ERR" , "message" => print_r($this->db->error(),true))); - exit; - } - $rows = $qry->result_array(); - if (count($rows) == 0 ) return; - //cari T_OrderSample yang sudah di receive yg terakhir - $sql = "select T_OrderSampleID - from t_ordersample - join t_sampletype on - T_OrderSampleT_OrderHeaderID = ? - and T_OrderSampleWorklistReceive = 'Y' - and T_OrderSampleIsActive = 'Y' - and T_OrderSampleT_SampleTypeID = T_SampletypeID - and T_SampleTypeCode like '017%' - order by T_OrderSampleWorklistReceiveDatetime desc - limit 0,1 - "; - $qry = $this->db->query($sql, array($headerID)); - if(!$qry) { - echo json_encode(array( "status" => "ERR" , "message" => print_r($this->db->error(),true))); - exit; - } - $rcv_rows = $qry->result_array(); - if (count($rcv_rows) == 0 ) return; - - //print_r($rows); - //print_r($rcv_rows); - $rcv_T_OrderSampleID = $rcv_rows[0]["T_OrderSampleID"]; - //ada yg belum di receive - foreach($rows as $r) { - $T_OrderSampleID = $r["T_OrderSampleID"]; - $this->update_order_sample($T_OrderSampleID,$rcv_T_OrderSampleID); - } - } - public function search() - { - $prm = $this->sys_input; - $max_rst = 99; - - $id = $prm["order_id"]; - if ($id > 0 ) { - $this->fix_sample_serum($id); - $this->fn_fix_normal($id); - } - $lang = $this->lang_default_code; - $lang_id = isset($prm['lang_id']) ? $prm['lang_id'] : '0'; - - if ($lang_id != 0) - { - $l = $this->db_smartone->where("Nat_LangID", $lang_id)->get("nat_lang")->row(); - $lang = $l->Nat_LangCode; - } - - //tambahan fajri - $sql = " UPDATE t_orderdetail - JOIN t_test ON T_OrderDetailT_TestID = T_TestID - SET T_OrderDetailT_TestIsResult = T_TestIsResult - WHERE - T_OrderDetailT_OrderHeaderID = {$id} AND - T_OrderDetailT_TestIsResult = '' AND - T_OrderDetailIsActive = 'Y'"; - $this->db_smartone->query($sql); - - $tot_count = 0; - $lq = ""; - $group_id = 0; - if (isset($prm['group_id'])) - $group_id = $prm['group_id']; - - if ($group_id != 0) - { - $sql = "select distinct T_WorklistDetailNat_TestID Nat_TestID - from t_worklistdetailv2 - where T_WorklistDetailT_WorklistID = {$group_id}"; - $qry = $this->db_smartone->query($sql); - $rows = $qry->result_array(); - $nat_test_ids = "0"; - foreach($rows as $r) { - $nat_test_ids .= ", " . $r["Nat_TestID"]; - } - $q_group = " ( $nat_test_ids ) "; - - $sql = " - SELECT a1.*, cOUNT(a2.T_OrderDetailID) level - FROM ( - SELECT IFNULL(y.T_OrderDetailT_TestID, x.T_OrderDetailT_TestID) t_testid, - IFNULL(y.T_OrderDetailT_TestName, y.T_OrderDetailT_TestName) t_testname, - y.T_OrderDetailResult result, y.T_OrderDetailResult result_old, y.T_OrderDetailNote note, y.T_OrderDetailNote note_old, - y.T_OrderDetailID id, - y.T_OrderDetailT_TestIsResult is_result, a.T_TestIsQuantitative is_quantitative, - y.T_OrderDetailResultFlag result_flag, - y.T_OrderDetailNat_NormalValueID normal_id, - y.T_OrderDetailNormalValueNote normal_note, y.T_OrderDetailNat_UnitName unit_name, - y.T_OrderdetailNat_MethodeID methode_id, y.T_OrderdetailNat_MethodeName methode_name, - a.T_TestNat_TestID nattest_id, a.T_TestID tx_id, count(T_ResultInstrumentID) as result_instrument_n, - y.T_OrderDetailVerification, T_OrderSampleReceive sample_receive, - T_OrderSampleProcessing sample_processing, T_OrderSampleWorklistReceive sample_worklist_receive, - IF(T_OrderDetailAddOnPreAnalytic = 'Y', T_OrderDetailAddOnPreAnalytic, PreAnalyticIsOk) pre_analytic, - T_OrderDetailAddOnPreAnalytic, - T_OrderHeaderID order_id, y.T_OrderDetailT_TestSasCode test_sas_code, - tx.T_TestSasCode, - T_OrderDetailAddOnResample `resample`, T_OrderDetailAddOnResampleStatus resample_status, - T_OrderDetailAddOnRef ref, y.T_OrderDetailVerification verification, y.T_OrderDetailValidation validation, - T_OrderPromiseDateTime, Group_ResultName as ResultGroupName - FROM t_orderdetail x - left join t_orderpromise on x.T_OrderDetailT_OrderPromiseID = T_OrderPromiseID - JOIN t_test tx ON x.T_OrderDetailT_TestID = T_TestID - JOIN t_test tcheck on tcheck.T_TestNat_TestID in {$q_group} - and ( tx.T_TestID = tcheck.T_TestID or tx.T_TestSasCode like concat(tcheck.T_TestSasCode,'%')) - LEFT JOIN group_resultdetail ON Group_ResultDetailT_TestID = x.T_OrderDetailT_TestID AND Group_ResultDetailIsActive = 'Y' - LEFT JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND Group_ResultFlagNonLab = 'N' - LEFT JOIN t_orderdetail y ON x.T_OrderDetailT_TestSasCode LIKE CONCAT(y.T_OrderDetailT_TestSasCode, '%') - AND x.T_OrderDetailT_OrderHeaderID = y.T_OrderDetailT_OrderHeaderID - AND y.T_OrderDetailIsActive = 'Y' - LEFT JOIN t_orderdetailaddon ON x.T_OrderDetailID = T_OrderDetailAddOnT_OrderDetailID - JOIN t_orderheader ON y.T_OrderDetailT_OrderHeaderID = T_OrderHeaderID - LEFT JOIN t_test a ON y.T_OrderDetailT_TestID = a.T_TestID - AND a.T_TestIsNonLab = '' - LEFT JOIN (SELECT T_OrderSampleT_SampleTypeID, T_OrderSampleReceive, T_OrderSampleProcessing, T_OrderSampleWorklistReceive - FROM t_ordersample WHERE T_OrderSampleT_OrderHeaderID = {$id} - AND T_OrderSampleIsactive = 'Y' - GROUP BY T_OrderSampleT_SampleTypeID) os ON a.T_TestT_SampleTypeID = os.T_OrderSampleT_SampleTypeID - or os.T_OrderSampleT_SampleTypeID = fn_sampletype_from_local(a.T_TestNat_TestID) - - LEFT JOIN t_resultinstrument ON T_ResultInstrumentT_OrderDetailID = x.T_OrderDetailID - LEFT JOIN pre_analytic ON PreAnalyticNat_TestID = a.T_TestNat_TestID AND PreAnalyticDate = date(now()) and PreAnalyticIsActive = 'Y' - WHERE x.T_OrderDetailT_OrderHeaderID = {$id} - AND x.T_OrderDetailIsActive = 'Y' - GROUP BY y.T_OrderDetailT_TestID - ORDER BY y.T_OrderDetailT_TestSasCode ASC - ) a1 - - LEFT JOIN t_orderdetail a2 ON a2.T_OrderDetailT_OrderHeaderID = a1.order_id - AND a2.T_OrderDetailIsActive = 'Y' - AND a1.test_sas_code LIKE CONCAT(a2.T_OrderDetailT_testSasCode, '%') - GROUP BY a1.t_testid - order by a1.test_sas_code -"; - $query = $this->db_smartone->query($sql); - $lq = $this->db_smartone->last_query(); - } - else - { - $sql = " - SELECT a1.*, cOUNT(a2.T_OrderDetailID) level - FROM ( - SELECT IFNULL(y.T_OrderDetailT_TestID, x.T_OrderDetailT_TestID) t_testid, - IFNULL(y.T_OrderDetailT_TestName, y.T_OrderDetailT_TestName) t_testname, - y.T_OrderDetailResult result, y.T_OrderDetailResult result_old, y.T_OrderDetailNote note, y.T_OrderDetailNote note_old, - y.T_OrderDetailID id, - y.T_OrderDetailT_TestIsResult is_result, a.T_TestIsQuantitative is_quantitative, - y.T_OrderDetailResultFlag result_flag, - y.T_OrderDetailNat_NormalValueID normal_id, - y.T_OrderDetailNormalValueNote normal_note, y.T_OrderDetailNat_UnitName unit_name, - y.T_OrderdetailNat_MethodeID methode_id, y.T_OrderdetailNat_MethodeName methode_name, - a.T_TestNat_TestID nattest_id, a.T_TestID tx_id, count(T_ResultInstrumentID) as result_instrument_n, - y.T_OrderDetailVerification, T_OrderSampleReceive sample_receive, - T_OrderSampleProcessing sample_processing, T_OrderSampleWorklistReceive sample_worklist_receive, - IF(T_OrderDetailAddOnPreAnalytic = 'Y', T_OrderDetailAddOnPreAnalytic, PreAnalyticIsOk) pre_analytic, - T_OrderDetailAddOnPreAnalytic, - T_OrderHeaderID order_id, y.T_OrderDetailT_TestSasCode test_sas_code, - tx.T_TestSasCode, - T_OrderDetailAddOnResample `resample`, T_OrderDetailAddOnResampleStatus resample_status, - T_OrderDetailAddOnRef ref, y.T_OrderDetailVerification verification, y.T_OrderDetailValidation validation, - T_OrderPromiseDateTime , Group_ResultName as ResultGroupName - FROM t_orderdetail x - left join t_orderpromise on x.T_OrderDetailT_OrderPromiseID = T_OrderPromiseID - JOIN t_test tx ON x.T_OrderDetailT_TestID = T_TestID - LEFT JOIN group_resultdetail ON Group_ResultDetailT_TestID = x.T_OrderDetailT_TestID AND Group_ResultDetailIsActive = 'Y' - LEFT JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND Group_ResultFlagNonLab = 'N' - LEFT JOIN t_orderdetail y ON x.T_OrderDetailT_TestSasCode LIKE CONCAT(y.T_OrderDetailT_TestSasCode, '%') - AND x.T_OrderDetailT_OrderHeaderID = y.T_OrderDetailT_OrderHeaderID - AND y.T_OrderDetailIsActive = 'Y' - - LEFT JOIN t_orderdetailaddon ON x.T_OrderDetailID = T_OrderDetailAddOnT_OrderDetailID - - JOIN t_orderheader ON y.T_OrderDetailT_OrderHeaderID = T_OrderHeaderID - LEFT JOIN t_test a ON y.T_OrderDetailT_TestID = a.T_TestID - AND a.T_TestIsNonLab = '' - LEFT JOIN (SELECT T_OrderSampleT_SampleTypeID, T_OrderSampleReceive, T_OrderSampleProcessing, T_OrderSampleWorklistReceive - FROM t_ordersample WHERE T_OrderSampleT_OrderHeaderID = {$id} - AND T_OrderSampleIsactive = 'Y' - GROUP BY T_OrderSampleT_SampleTypeID) os ON a.T_TestT_SampleTypeID = os.T_OrderSampleT_SampleTypeID - or os.T_OrderSampleT_SampleTypeID = fn_sampletype_from_local(a.T_TestNat_TestID) - - LEFT JOIN t_resultinstrument ON T_ResultInstrumentT_OrderDetailID = x.T_OrderDetailID - LEFT JOIN pre_analytic ON PreAnalyticNat_TestID = a.T_TestNat_TestID AND PreAnalyticDate = date(now()) and PreAnalyticIsActive = 'Y' - WHERE x.T_OrderDetailT_OrderHeaderID = {$id} - AND x.T_OrderDetailIsActive = 'Y' - GROUP BY y.T_OrderDetailT_TestID - ORDER BY y.T_OrderDetailT_TestSasCode ASC - ) a1 - - LEFT JOIN t_orderdetail a2 ON a2.T_OrderDetailT_OrderHeaderID = a1.order_id - AND a2.T_OrderDetailIsActive = 'Y' - AND a1.test_sas_code LIKE CONCAT(a2.T_OrderDetailT_testSasCode, '%') - GROUP BY a1.t_testid - order by a1.test_sas_code -"; -//echo $sql; - $query = $this->db_smartone->query($sql); - $lq = $this->db_smartone->last_query(); - } - // file_put_contents("/xtmp/re-query.sql",$lq); - - if ($query) { - $rst = []; - $rows = $query->result_array(); - - foreach($rows as $k => $v) - { - - if ($v['is_result'] == "Y" && $v['is_quantitative'] == "N") - { - $v['template'] = []; - $x = $this->db_smartone->query("CALL sp_master_resulttemplate_get('{$v['t_testid']}')"); - $this->clean_mysqli_connection($this->db_smartone->conn_id); - if ($x) - $v['template'] = $x->result_array(); - } - - // IF Rujukan, by pas Pre Analytik - if ($v['ref'] == 'Y') - $v['pre_analytic'] = 'Y'; - if ($v["id"] == "885455" ) - { - //sipe workaround - //$v["sample_receive"] = "Y"; - $v["sample_worklist_receive"] = "Y"; - } - $rst[] = $v; - } - - $result = array("total" => $tot_count, "records" => $rst, "total_display" => sizeof($rows), "q" => $lq); - $this->sys_ok($result); - } - else { - $this->sys_error_db("RE Px rows", $this->db_smartone); - exit; - } - } - - public function save() - { - $prm = $this->sys_input; - $data = json_decode($prm["data"]); - $lang = $this->lang_default_code; - $lang_id = isset($prm['lang_id']) ? $prm['lang_id'] : '0'; - - if ($lang_id != 0) - { - $l = $this->db_smartone->where("Nat_LangID", $lang_id)->get("nat_lang")->row(); - $lang = $l->Nat_LangCode; - } - - $sql_norm = "select T_OrderDetailMinValue, T_OrderDetailMaxValue, - T_OrderDetailMinValueInclusive, T_OrderDetailMaxValueInclusive, - Nat_TestFlagLow, Nat_TestFlagHigh - from t_orderdetail - join t_test on T_OrderDetailT_TestID = T_TestID - join nat_test on T_TestNat_TestID = Nat_TestID and T_TestIsActive = 'Y' - where T_OrderDetailID = ? "; - - $ids = []; - foreach ($data as $k => $v) - { - if ( $v->resultInstrumentID > 0 ) { - $sql_i = "select T_ResultInstrumentNat_NormalValueID normalValueID - from t_resultinstrument - where T_ResultInstrumentID = ?"; - $qry_i = $this->db_smartone->query($sql_i, array($v->resultInstrumentID)); - if ($qry_i) { - $rows_i = $qry_i->result_array(); - - if (count($rows_i) > 0 ) { - $sql_iu = "update t_orderdetail, nat_normalvalue , nat_methode - set T_OrderDetailMinValue = Nat_NormalValueMinValue, - T_OrderDetailMinValueInclusive = Nat_NormalValueMinValueInclusive, - T_OrderDetailMaxValue = Nat_NormalValueMaxValue , - T_OrderDetailMaxValueInclusive = Nat_NormalValueMaxValueInclusive, - T_OrderDetailNormalValueNote = Nat_NormalValueNote, - T_OrderDetailNormalValueDescription = Nat_NormalValueDescription, - T_OrderDetailNat_NormalValueID = Nat_NormalValueID, - T_OrderDetailNat_MethodeID = Nat_NormalValueNat_MethodeID, - T_OrderDetailNat_MethodeName = Nat_MethodeName - where T_OrderDetailID = ? and Nat_NormalValueID = ? - and Nat_NormalValueNat_MethodeID = Nat_MethodeID - "; - $this->db_smartone->query($sql_iu, array($v->id, $rows_i[0]["normalValueID"])); - //file_put_contents("/xtmp/update-nilai-normal", $this->db_smartone->last_query() . "\n", FILE_APPEND); - } - } - } - $y = $this->db_smartone->query("SELECT fn_process_sample_handling_perfect('{$v->order_id}', '{$v->test_id}') c") - ->row(); - $req_status = $y->c; - $qry_norm = $this->db_smartone->query($sql_norm,$v->id); - $result_flag = ""; - if ($qry_norm) { - $rows_norm = $qry_norm->result_array(); - if (count($rows_norm) > 0 ) { - $r = $rows_norm[0]; - if (is_numeric($v->result)) { - - if ( $r["T_OrderDetailMinValueInclusive"] == "Y" && $v->result < $r["T_OrderDetailMinValue"] ) { - $result_flag = $r["Nat_TestFlagLow"]; - } - if ( $r["T_OrderDetailMinValueInclusive"] == "N" && $v->result <= $r["T_OrderDetailMinValue"] ) { - $result_flag = $r["Nat_TestFlagLow"]; - } - if ( $r["T_OrderDetailMaxValueInclusive"] == "Y" && $v->result > $r["T_OrderDetailMaxValue"] ) { - $result_flag = $r["Nat_TestFlagHigh"]; - } - if ( $r["T_OrderDetailMaxValueInclusive"] == "N" && $v->result >= $r["T_OrderDetailMaxValue"] ) { - $result_flag = $r["Nat_TestFlagHigh"]; - } - } - } - } - if ($lang == $this->lang_default_code) - { - $this->db_smartone->set('T_OrderDetailResult', $v->result) - ->set('T_OrderDetailResultFlag', $result_flag) - ->set('T_OrderDetailNote', $v->note) - ->set('T_OrderDetailReqStatus', $req_status) - ->where('T_OrderDetailID', $v->id) - ->update('t_orderdetail'); - } - else - { - $this->db_smartone->set('T_OrderDetailLangResult', $v->result) - ->set('T_OrderDetailLangNote', $v->note) - ->where('T_OrderDetailLangID', $v->id) - ->update('t_orderdetaillang'); - } - - $ids[] = $v->id; - } - - // LOG Process - $order = $this->db_smartone->select('T_OrderDetailT_OrderHeaderID id, T_OrderHeaderLabNumber lab_number', false) - ->join('t_orderheader', 'T_OrderHeaderID = T_OrderDetailT_OrderHeaderID') - ->where('T_OrderDetailID', $data[0]->id) - ->get('t_orderdetail') - ->row(); - - $dblog = $this->load->database("onelog", true); - $dblog->set('Log_ProcessCode', 'PROCESS.Result.Entry') - ->set('Log_ProcessOrderID', $order->id) - ->set('Log_ProcessOrderNumber', $order->lab_number) - ->set('Log_ProcessJson', json_encode($data)) - ->set('Log_ProcessUserID', $this->sys_user['M_UserID']) - ->insert('log_process'); - // END OF Log Process - //auto calculation - $this->load->library("Resultcalc"); - $rows = $this->resultcalc->auto($order->id); - - try { - foreach($ids as $id ) { - $this->db_smartone->query("call sp_set_normal_value_flag($id)"); - $this->clean_mysqli_connection($this->db_smartone->conn_id); - } - } catch(Exception $e) { - } - - $this->sys_ok($ids); - } - - public function save_template() - { - $prm = $this->sys_input; - - $n = $this->db_smartone->select("COUNT(T_ResultTemplateID) n") - ->where("T_ResultTemplateT_TestID", $prm['test_id']) - ->where("T_ResultTemplateIsActive", "Y") - ->where("T_ResultTemplateValue", $prm['value']) - ->get('t_resulttemplate') - ->row(); - if ($n->n > 0) - { - $this->sys_error_db("Insert Result Template", $this->db_smartone); - return; - } - - $r = $this->db_smartone->set("T_ResultTemplateT_TestID", $prm['test_id']) - ->set("T_ResultTemplateValue", $prm['value']) - ->insert('t_resulttemplate'); - if ($r) - { - $template = []; - $x = $this->db_smartone->query("CALL sp_master_resulttemplate_get('{$prm['test_id']}')"); - $this->clean_mysqli_connection($this->db_smartone->conn_id); - if ($x) - $template = $x->result_array(); - - $this->sys_ok($template); - } - } - - public function export() - { - $prm = $this->sys_input; - - $sql = "CALL sp_process_result_lang(?, ?, ?, ?)"; - $query = $this->db_smartone->query($sql, [$prm['order_id'], $prm['lang_id'], $prm['is_si'], $this->sys_user['M_UserID']]); - if ($query) - { - $r = $query->row(); - if ($r->status == "OK") - { - $this->sys_ok($r->data); - return; - } - - $this->sys_error_db("Message : " . $r->message, $this->db_smartone); - } - else - { - $this->sys_error_db("Lang Result", $this->db_smartone); - return; - } - } - - public function search_group() - { - $prm = $this->sys_input; - $max_rst = 100; - - // QUERY TOTAL - $sql = "select count(*) total - from t_worklist - where T_WorklistIsActive = 'Y' - order by T_WorklistName ASC"; - $query = $this->db_smartone->query($sql); - - if ($query) { - $tot_count = $query->result_array()[0]["total"]; - } - else { - $this->sys_error_db("worklist count", $this->db_smartone); - exit; - } - - $sql = "select T_WorklistID group_id, T_WorklistName group_name - from t_worklist - where T_WorklistIsActive = 'Y' - order by T_WorklistName ASC - limit 0, {$max_rst}"; - $query = $this->db_smartone->query($sql); - - if ($query) { - $rows = $query->result_array(); - foreach ($rows as $k => $v) - $rows[$k]['data'] = json_decode($v['data']); - $result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows), "q" => $this->db_smartone->last_query()); - $this->sys_ok($result); - } - else { - $this->sys_error_db("worklist rows", $this->db_smartone); - exit; - } - } - - public function search_rerun() - { - $prm = $this->sys_input; - $id = $prm["detail_id"]; - - $sql = "CALL sp_process_result_rerun(?)"; - $query = $this->db_smartone->query($sql, [$id]); - - if ($query) - { - $rows = $query->result_array(); - $this->sys_ok(["records"=>$rows]); - } - else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - - - function getdoctorsfna() - { - $prm = $this->sys_input; - // $id = $prm["id"]; - - $sql = " SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY M_DoctorName ASC"; - //echo $sql; - $query = $this->db_smartone->query($sql); - - if ($query) - { - $rows = $query->result_array(); - $this->sys_ok(["records"=>$rows]); - } - else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - function getfnaresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT Other_FNADetailsID as xid, - Other_FNAT_OrderDetailID as orderdetail_id, - Other_FNADetailsCode as code, - Other_FNADetailsLabel as label, - Other_FNADetailsResult as result, - IFNULL(Other_FNAM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_FNAM_DoctorID) OR Other_FNAM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_fna - JOIN other_fnadetails ON Other_FNADetailsOther_FNAID = Other_FNAID AND Other_FNADetailsIsActive = 'Y' - LEFT JOIN m_doctor ON Other_FNAM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_FNAT_OrderDetailID = {$id} AND Other_FNAIsActive = 'Y' - GROUP BY Other_FNADetailsID - ORDER BY Other_FNADetailsCode ASC"; - $query = $this->db_smartone->query($sql); - - if ($query) - { - $rows = $query->result_array(); - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $images = array(); - $sql = "SELECT So_ImageUploadID as xid, - CONCAT('/one-media/one-image-nonlab/',So_ImageUploadNewName) as image_url - FROM t_orderdetail - JOIN so_imageupload ON So_ImageUploadT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND - So_ImageUploadIsActive = 'Y' - WHERE - T_OrderDetailID = {$id} AND - T_OrderDetailIsActive = 'Y' - GROUP BY So_ImageUploadID"; - $images = $this->db_smartone->query($sql)->result_array(); - - $rst = array('doctors'=>$doctors,'results'=>$rows,'images'=>$images); - $this->sys_ok(["records"=>$rst]); - } - else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - - function uploadimage(){ - if (! $this->isLogin) { - $this->sys_error("Invalid Token"); - exit; - } - - $userid = $this->sys_user["M_UserID"]; - $data = []; - //print_r($_SERVER); - - $prm = $this->sys_input; - $orderid = $this->input->post('orderid'); - $labnumber = $this->input->post('labnumber'); - $sql = "UPDATE so_imageupload SET - So_ImageUploadIsActive = 'N', - So_ImageUploadUserID = {$userid} - WHERE - So_ImageUploadT_OrderHeaderID = {$orderid}"; - //echo $sql; - $this->db_onedev->query($sql); - //$config['upload_path'] = 'assets/'; - - $path = '/home/one/project/one/one-media/one-image-nonlab/'; - //echo $path; - $config['upload_path'] = $path; - $config['allowed_types'] = 'jpg|jpeg|png|gif'; - - $config['max_size'] = '10000'; - $count = count($_FILES['files']['name']); - //echo $count; - $this->load->library('upload',$config); - - $error = []; - for($i=0;$i<$count;$i++){ - - - if(!empty($_FILES['files']['name'][$i])){ - - - - $_FILES['file']['name'] = $_FILES['files']['name'][$i]; - - $_FILES['file']['type'] = $_FILES['files']['type'][$i]; - - $_FILES['file']['tmp_name'] = $_FILES['files']['tmp_name'][$i]; - - $_FILES['file']['error'] = $_FILES['files']['error'][$i]; - - $_FILES['file']['size'] = $_FILES['files']['size'][$i]; - - - - $namex = $orderid.'-'.$labnumber.'-'.$this->generateRandomString(5); - //echo $namex; - - $config['file_name'] = $namex; - $this->upload->initialize($config); - //echo $config['file_name'] ; - - - - - - if($this->upload->do_upload('file')){ - - $uploadData = $this->upload->data(); - - $filename = $uploadData['file_name']; - //echo $filename; - - - $sql = "INSERT INTO so_imageupload ( - So_ImageUploadT_OrderHeaderID, - So_ImageUploadT_OrderHeaderLabNumber, - So_ImageUploadT_SampleTypeID, - So_ImageUploadOldName, - So_ImageUploadNewName, - So_ImageUploadCreated, - So_ImageUploadUserID - ) - VALUES( - {$orderid}, - '{$labnumber}', - '150', - '{$_FILES['files']['name'][$i]}', - '{$filename}', - NOW(), - {$userid} - - )"; - //echo $sql; - $this->db_onedev->query($sql); - $xlast_id = $this->db_onedev->insert_id(); - $data['totalFiles'][] = array('xid' => $xlast_id ,'image_url' => '/one-media/one-image-nonlab/'.$filename); - - } - else{ - $error = array('error' => $this->upload->display_errors()); - } - - } - - - - } - - $result = array("total" =>count( $data['totalFiles']), "records" => $data['totalFiles'],'errors'=>$error); - $this->sys_ok($result); - } - - - function generateRandomString($length = 10) { - $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; - $charactersLength = strlen($characters); - $randomString = ''; - for ($i = 0; $i < $length; $i++) { - $randomString .= $characters[rand(0, $charactersLength - 1)]; - } - return $randomString; - } - - function getcytologiresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT Other_CytologiDetailsID as xid, - Other_CytologiT_OrderDetailID as orderdetail_id, - Other_CytologiDetailsCode as code, - Other_CytologiDetailsLabel as label, - Other_CytologiDetailsResult as result, - IFNULL(Other_CytologiM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_CytologiM_DoctorID) OR Other_CytologiM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_cytologi - JOIN other_cytologidetails ON Other_CytologiDetailsOther_CytologiID = Other_CytologiID AND Other_CytologiDetailsIsActive = 'Y' - LEFT JOIN m_doctor ON Other_CytologiM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_CytologiT_OrderDetailID = {$id} AND Other_CytologiIsActive = 'Y' - GROUP BY Other_CytologiDetailsID - ORDER BY Other_CytologiDetailsCode ASC"; - //echo $sql; - $query = $this->db_smartone->query($sql); - - if ($query) - { - $rows = $query->result_array(); - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $rst = array('doctors'=>$doctors,'results'=>$rows); - $this->sys_ok(["records"=>$rst]); - } - else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - function getmikroresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT - Other_MikroID as xid, - Other_MikroHasilBiakan as hasil_biakan, - Other_MikroSampleTypeName as sample_name, - Other_MikroT_OrderDetailID as orderdetail_id, - Other_MikroResult as result_value, - '' as result_other, - IFNULL(T_BacteriaID,0) as T_BacteriaID, - IFNULL(T_BacteriaName,'') as T_BacteriaName, - '' as details, - IFNULL(Other_MikroM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_MikroM_DoctorID) OR Other_MikroM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_mikro - LEFT JOIN t_bacteria ON Other_MikroT_BacteriaID = T_BacteriaID - LEFT JOIN m_doctor ON Other_MikroM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_MikroT_OrderDetailID = {$id} AND Other_MikroIsActive = 'Y' - GROUP BY Other_MikroID"; - //echo $sql; - $query = $this->db_smartone->query($sql); - - if ($query) - { - $row = $query->row_array(); - if($row){ - if($row['result_value'] != 'Positif' && $row['result_value'] != 'Negatif'){ - $row['result_other'] = $row['result_value']; - $row['result_value'] = 'other'; - } - $sql = "SELECT '' as xno, - Other_MikroDetailsID as xid, - Other_MikroDetailsValue as value, - IF(Other_MikroDetailsNote = 'R','Y','N') as chx_r, - IF(Other_MikroDetailsNote = 'I','Y','N') as chx_i, - IF(Other_MikroDetailsNote = 'S','Y','N') as chx_s, - Other_MikroDetailsNote as note, - t_antibiotic.* - FROM other_mikrodetails - LEFT JOIN t_antibiotic ON Other_MikroDetailsT_AntibioticID = T_AntibioticID - WHERE - Other_MikroDetailsOther_MikroID = {$row['xid']} AND Other_MikroDetailsIsActive = 'Y' - GROUP BY Other_MikroDetailsID - ORDER BY T_AntibioticName ASC"; - //echo $sql; - $details = $this->db_smartone->query($sql)->result_array(); - if(details){ - foreach($details as $k => $v){ - $details[$k]['xno'] = $k + 1; - } - } - $row['details'] = $details; - } - else{ - $row = array('xid'=>'0','hasil_biakan' => '','result_value'=>'Negatif','sample_name' => '','orderdetail_id'=>$id, 'T_BacteriaID'=>'0','T_BacteriaName'=>'0','details'=>array(),'doctor_id'=>'0','doctor_name'=>'0'); - } - } - else{ - $row = array('xid'=>'0','hasil_biakan' => '','result_value'=>'Negatif','sample_name' => '','orderdetail_id'=>$id, 'T_BacteriaID'=>'0','T_BacteriaName'=>'0','details'=>array(),'doctor_id'=>'0','doctor_name'=>'0'); - } - //print_r($row); - - - - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 7 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $sql = " - SELECT '0' as id, 'Belum memilih bakteria' as name - UNION - SELECT T_BacteriaID as id, T_BacteriaName as name - FROM t_bacteria - WHERE - T_BacteriaIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $bacteries = $this->db_smartone->query($sql)->result_array(); - $rst = array('doctors'=>$doctors,'bacteries'=>$bacteries,'results'=>$row); - $this->sys_ok(["records"=>$rst]); - } - function getantibiotics(){ - $prm = $this->sys_input; - $id = $prm["id"]; - $sql = " SELECT '' as xno, - 0 as xid, - '' as hasil_biakan, - '' as sample_name, - 0 as value, - 'Y' as chx_r, - 'N' as chx_i, - 'N' as chx_s, - 'R' as note, - t_antibiotic.* - FROM t_antibiotic - WHERE - T_AntibioticT_BacteriaID = {$prm['id']} AND T_AntibioticIsActive= 'Y' - ORDER BY T_AntibioticName ASC"; - //echo $sql; - $rows = $this->db_smartone->query($sql)->result_array(); - if(rows){ - foreach($rows as $k => $v){ - $rows[$k]['xno'] = $k + 1; - } - } - - $this->sys_ok(["records"=>$rows]); - } - function getlcprepresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - $sql = " SELECT Other_LcprepDetailsID as xid, - Other_LcprepID as header_id, - Other_LcprepT_orderDetailID as orderdetail_id, - Other_LcprepDetailsCode as code, - Other_LcprepDetailsLabel as label, - Other_LcprepDetailsResult as result, - IFNULL(Other_LcprepM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_LcprepM_DoctorID) OR Other_LcprepM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_lcprep - JOIN other_lcprepdetails ON Other_LcprepDetailsOther_LcprepID = Other_LcprepID AND Other_LcprepDetailsIsActive = 'Y' - LEFT JOIN m_doctor ON Other_LcprepM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_LcprepT_orderDetailID = {$id} AND Other_LcprepIsActive = 'Y' - GROUP BY Other_LcprepDetailsOther_LcprepID, Other_LcprepDetailsCode - ORDER BY Other_LcprepDetailsCode ASC"; - //echo $sql; - $rows = $this->db_smartone->query($sql)->result_array(); - if(!$rows){ - $rows = array( - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'A', - 'label' => 'DESKRIPSI', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ), - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'B', - 'label' => 'KESIMPULAN', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ) - ); - } - - $header_id = $rows[0]['header_id']; - $sql = "SELECT IFNULL(Other_LcprepAdekuasiID,0) as xid, - Lcprep_AdekuasiID as id, - Lcprep_AdekuasiLabel as name, - IF(ISNULL(Other_LcprepAdekuasiID),'N',Other_LcprepAdekuasiChex) as chex - FROM lcprep_adekuasi - LEFT JOIN other_lcprepadekuasi ON Other_LcprepAdekuasiLcprep_AdekuasiID = Lcprep_AdekuasiID AND - Other_LcprepAdekuasiOther_LcprepID = {$header_id} AND - Other_LcprepAdekuasiIsActive = 'Y' - WHERE - Lcprep_AdekuasiIsActive = 'Y' - GROUP BY Lcprep_AdekuasiID - ORDER BY Lcprep_AdekuasiOrder ASC - "; - //echo $sql; - $adeakuasi = $this->db_smartone->query($sql)->result_array(); - foreach($adeakuasi as $kc => $vc){ - $adeakuasi[$kc]['chex'] = $vc['chex'] == 'N'?false:true; - } - - $sql = "SELECT IFNULL(Other_LcprepKategoriUmumID,0) as xid, - Lcprep_KategoriUmumID as id, - Lcprep_KategoriUmumLabel as name, - IF(ISNULL(Other_LcprepKategoriUmumID),'N',Other_LcprepKategoriUmumChex) as chex - FROM lcprep_kategoriumum - LEFT JOIN other_lcprepkategoriumum ON Other_LcprepKategoriUmumLcprep_KategoriUmumID = Lcprep_KategoriUmumID AND - Other_LcprepKategoriUmumOther_LcprepID = {$header_id} AND - Other_LcprepKategoriUmumIsActive = 'Y' - WHERE - Lcprep_KategoriUmumIsActive = 'Y' - GROUP BY Lcprep_KategoriUmumID - "; - //echo $sql; - $kategoriumum = $this->db_smartone->query($sql)->result_array(); - foreach($kategoriumum as $kc => $vc){ - $kategoriumum[$kc]['chex'] = $vc['chex'] == 'N'?false:true; - } - - $sql = " - SELECT Lcprep_InterpretasiGroupID as group_id, - Lcprep_InterpretasiGroupName as group_name, - '' as subgroups - FROM lcprep_interpretasigroup - WHERE - Lcprep_InterpretasiGroupIsActive = 'Y' - "; - //echo $sql; - $interpretasi = $this->db_smartone->query($sql)->result_array(); - foreach($interpretasi as $k => $v){ - $subgroups = array(); - $sql = "SELECT Lcprep_InterpretasiSubgroupID as subgroup_id, - Lcprep_InterpretasiSubgroupName as subgroup_name, - '' as childs - FROM lcprep_interpretasisubgroup - WHERE - Lcprep_InterpretasiSubgroupLcprep_InterpretasiGroupID = {$v['group_id']} AND Lcprep_InterpretasiSubgroupIsActive = 'Y'"; - //echo $sql; - $subgroups = $this->db_smartone->query($sql)->result_array(); - if(count($subgroups) > 0){ - foreach($subgroups as $ki => $vi){ - $childs = array(); - $sql = "SELECT IFNULL(Other_LcprepInterpretasiID,0) as xid, - IFNULL(Other_LcprepInterpretasiChex,'N') as chex, - IFNULL(Other_LcprepInterpretasiValue,'') as value, - Lcprep_InterpretasiID as id, - Lcprep_InterpretasiLcprep_InterpretasiSubgroupID as subgroup_id, - Lcprep_InterpretasiCode as code, - Lcprep_InterpretasiName as name, - Lcprep_InterpretasiParentID as parent_id, - Lcprep_InterpretasiIsParent as is_parent, - Lcprep_InterpretasiHasResult as has_result, - Lcprep_InterpretasiTypeResult as type_result - FROM lcprep_interpretasi - LEFT JOIN other_lcprepinterpretasi ON Other_LcprepInterpretasiOther_LcprepID = {$header_id} AND - Other_LcprepInterpretasiLcprep_InterpretasiID = Lcprep_InterpretasiID AND - Other_LcprepInterpretasiIsActive = 'Y' - WHERE - Lcprep_InterpretasiLcprep_InterpretasiSubgroupID = {$vi['subgroup_id']} AND Lcprep_InterpretasiIsActive = 'Y' - GROUP BY Lcprep_InterpretasiID Order BY Lcprep_InterpretasiCode ASC"; - $childs = $this->db_smartone->query($sql)->result_array(); - if($childs){ - foreach($childs as $kc => $vc){ - $childs[$kc]['chex'] = $vc['chex'] == 'N'?false:true; - } - } - $subgroups[$ki]['childs'] = $childs; - } - } - - $interpretasi[$k]['subgroups'] = $subgroups; - } - - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $rst = array('doctors'=>$doctors,'results'=>$rows,'adekuasi'=>$adeakuasi,'kategoriumum'=>$kategoriumum,'interpretasi'=>$interpretasi); - $this->sys_ok(["records"=>$rst]); - } - - function getpapsmearresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT Other_PapSmearDetailsID as xid, - Other_PapSmearID as header_id, - Other_PapSmearT_OrderDetailID as orderdetail_id, - Other_PapSmearDetailsCode as code, - Other_PapSmearDetailsLabel as label, - Other_PapSmearDetailsResult as result, - IFNULL(Other_PapSmearM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_PapSmearM_DoctorID) OR Other_PapSmearM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_papsmear - JOIN other_papsmeardetails ON Other_PapSmearDetailsOther_PapSmearID = Other_PapSmearID AND Other_PapSmearDetailsIsActive = 'Y' - LEFT JOIN m_doctor ON Other_PapSmearM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_PapSmearT_OrderDetailID = {$id} AND Other_PapSmearIsActive = 'Y' - GROUP BY Other_PapSmearDetailsID - ORDER BY Other_PapSmearDetailsCode ASC"; - //echo $sql; - $rows = $this->db_smartone->query($sql)->result_array(); - if(!$rows){ - $rows = array( - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'A', - 'label' => 'Makroskopik', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ), - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'B', - 'label' => 'Mikroskopik', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ), - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'C', - 'label' => 'Kesimpulan', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ) - ); - } - - $header_id = $rows[0]['header_id']; - $sql = "SELECT Other_PapSmearMaturasiID as xid, - Other_PapSmearMaturasiValue as value - FROM other_papsmearmaturasi - WHERE - Other_PapSmearMaturasiOther_PapSmearID = {$header_id} AND - Other_PapSmearMaturasiIsActive = 'Y' - "; - //echo $sql; - $dt_maturasi = $this->db_smartone->query($sql)->row_array(); - if(!$dt_maturasi){ - $maturasi = array('xid'=>'0','value'=> array('','','')); - } - else{ - $value = explode('/',$dt_maturasi['value']); - $maturasi = array('xid'=>$dt_maturasi['xid'],'value'=> $value); - } - - $sql = "SELECT IFNULL(Other_PapSmearBahanID,0) as xid, - M_PapSmearBahanID as bahan_id, - M_PapSmearBahanName as name, - IF(ISNULL(Other_PapSmearBahanID),'N','Y') as selected - FROM m_papsmearbahan - LEFT JOIN other_papsmearbahan ON Other_PapSmearBahanM_PapSmearBahanID = M_PapSmearBahanID AND - Other_PapSmearBahanOther_PapSmearID = {$header_id} AND - Other_PapSmearBahanIsActive = 'Y' - WHERE - M_PapSmearBahanIsActive = 'Y' - ORDER BY M_PapSmearBahanID ASC - "; - //echo $sql; - $bahans = $this->db_smartone->query($sql)->result_array(); - - $sql = "SELECT IFNULL(Other_PapsmearCategoryID,0) as xid, - M_PapSmearCategoryID as category_id, - M_PapSmearCategoryName as name, - IF(ISNULL(Other_PapsmearCategoryID),'N','Y') as selected - FROM m_papsmearcategory - LEFT JOIN other_papsmearcategory ON Other_PapsmearCategoryM_PapSmearCategoryID = M_PapSmearCategoryID AND - Other_PapsmearCategoryOther_PapSmearID = {$header_id} AND - Other_PapsmearCategoryIsActive = 'Y' - WHERE - M_PapSmearCategoryIsActive = 'Y' - ORDER BY M_PapSmearCategoryID ASC - "; - //echo $sql; - $categories = $this->db_smartone->query($sql)->result_array(); - - $sql = "SELECT IFNULL(Other_PapSmearCheckID,0) as xid, - M_PapSmearCheckID as check_id, - M_PapSmearCheckLabel as name, - IF(ISNULL(Other_PapSmearCheckID),'N','Y') as selected, - Other_PapSmearCheckNote as note - FROM m_papsmearcheck - LEFT JOIN other_papsmearcheck ON Other_PapSmearCheckM_PapSmearCheckID = M_PapSmearCheckID AND - Other_PapSmearCheckOther_PapSmearID = {$header_id} AND - Other_PapSmearCheckIsActive = 'Y' - WHERE - M_PapSmearCheckIsActive = 'Y' - ORDER BY M_PapSmearCheckCode ASC - "; - $checks = $this->db_smartone->query($sql)->result_array(); - - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $rst = array('doctors'=>$doctors,'checks'=>$checks,'bahans'=>$bahans,'categories'=>$categories,'maturasi'=>$maturasi,'results'=>$rows); - $this->sys_ok(["records"=>$rst]); - - } - - function saveresult_lcprep() - { - $prm = $this->sys_input; - $detail_id = $prm['detail_id']; - $doctor_id = $prm['doctor']; - $adekuasi = $prm['adekuasi']; - $kategoriumum = $prm['kategoriumum']; - $interpretasi = $prm['interpretasi']; - $results = $prm['results']; - - $userid = $this->sys_user['M_UserID']; - - $header_id = 0; - $sql = "SELECT * FROM other_lcprep WHERE Other_LcprepT_orderDetailID = {$detail_id} AND Other_LcprepIsActive = 'Y'"; - $dt_header = $this->db_smartone->query($sql)->row_array(); - if($dt_header){ - $header_id = $dt_header['Other_LcprepID']; - } - if($header_id == 0){ - $sql = "INSERT INTO other_lcprep( - Other_LcprepT_orderDetailID, - Other_LcprepM_DoctorID, - Other_LcprepUserID, - Other_LcprepCreated - ) - VALUES( - {$detail_id}, - {$doctor_id}, - {$userid}, - NOW() - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - }else{ - $sql = "UPDATE other_lcprep SET Other_LcprepM_DoctorID = {$doctor_id}, Other_LcprepUserID = {$userid} WHERE Other_LcprepID = {$header_id}"; - $this->db_smartone->query($sql); - } - - if($adekuasi){ - foreach($adekuasi as $k =>$v){ - $selected = $v['chex']?'Y':'N'; - if(intval($v['xid'] == 0)){ - $sql = "UPDATE other_lcprepadekuasi SET Other_LcprepAdekuasiIsActive = 'N' - WHERE - Other_LcprepAdekuasiOther_LcprepID = {$header_id} AND - Other_LcprepAdekuasiIsActive = 'Y' AND - Other_LcprepAdekuasiLcprep_AdekuasiID = {$v['id']}"; - $this->db_smartone->query($sql); - $sql = "INSERT INTO other_lcprepadekuasi ( - Other_LcprepAdekuasiOther_LcprepID, - Other_LcprepAdekuasiLcprep_AdekuasiID, - Other_LcprepAdekuasiChex, - Other_LcprepAdekuasiUserID, - Other_LcprepAdekuasiCreated - ) - VALUES( - {$header_id}, - {$v['id']}, - '{$selected}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - //echo $sql; - } - if(intval($v['xid'] != 0)){ - - $sql = "UPDATE other_lcprepadekuasi SET - Other_LcprepAdekuasiChex = '{$selected}', - Other_LcprepAdekuasiUserID = {$userid} - WHERE - Other_LcprepAdekuasiID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - - //echo $sql; - } - } - - if($kategoriumum){ - foreach($kategoriumum as $k =>$v){ - $selected = $v['chex']?'Y':'N'; - if(intval($v['xid'] == 0)){ - $sql = "UPDATE other_lcprepkategoriumum SET Other_LcprepKategoriUmumIsActive = 'N' - WHERE - Other_LcprepKategoriUmumOther_LcprepID = {$header_id} AND - Other_LcprepKategoriUmumLcprep_KategoriUmumID = {$v['id']} AND - Other_LcprepKategoriUmumIsActive = 'Y' - "; - $this->db_smartone->query($sql); - $sql = "INSERT INTO other_lcprepkategoriumum ( - Other_LcprepKategoriUmumOther_LcprepID, - Other_LcprepKategoriUmumLcprep_KategoriUmumID, - Other_LcprepKategoriUmumChex, - Other_LcprepKategoriUmumUserID, - Other_LcprepKategoriUmumCreated - ) - VALUES( - {$header_id}, - {$v['id']}, - '{$selected}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if(intval($v['xid'] != 0)){ - $sql = "UPDATE other_lcprepkategoriumum SET - Other_LcprepKategoriUmumChex = '{$selected }', - Other_LcprepKategoriUmumUserID = {$userid} - WHERE - Other_LcprepKategoriUmumID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - - //echo $sql; - } - } - - if($results){ - foreach($results as $k =>$v){ - if(intval($v['xid'] == 0)){ - $sql = "UPDATE other_lcprepdetails SET Other_LcprepDetailsIsActive = 'N' - WHERE - Other_LcprepDetailsOther_LcprepID = {$header_id} AND - Other_LcprepDetailsCode = '{$v['code']}' AND - Other_LcprepDetailsIsActive = 'Y'"; - $this->db_smartone->query($sql); - $sql = "INSERT INTO other_lcprepdetails ( - Other_LcprepDetailsOther_LcprepID, - Other_LcprepDetailsCode, - Other_LcprepDetailsLabel, - Other_LcprepDetailsResult, - Other_LcprepDetailsUserID, - Other_LcprepDetailsCreated - ) - VALUES( - {$header_id}, - '{$v['code']}', - '{$v['label']}', - '{$v['result']}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if(intval($v['xid'] != 0)){ - $sql = "UPDATE other_lcprepdetails SET - Other_LcprepDetailsCode = '{$v['code']}', - Other_LcprepDetailsLabel = '{$v['label']}', - Other_LcprepDetailsResult = '{$v['result']}', - Other_LcprepDetailsUserID = {$userid} - WHERE - Other_LcprepDetailsID = {$v['xid']}"; - $this->db_smartone->query($sql); - - } - //echo $sql; - } - } - - if($interpretasi){ - foreach($interpretasi as $k =>$v){ - if(count($v['subgroups']) > 0){ - foreach($v['subgroups'] as $ik => $iv){ - if(count($iv['childs']) > 0){ - foreach($iv['childs'] as $iik => $iiv){ - if(intval($iiv['xid'] == 0)){ - $chex = $iiv['chex'] ? 'Y':'N'; - $sql = "UPDATE other_lcprepinterpretasi SET Other_LcprepInterpretasiIsActive = 'N' - WHERE - Other_LcprepInterpretasiOther_LcprepID = {$header_id} AND - Other_LcprepInterpretasiLcprep_InterpretasiID = '{$iiv['id']}' AND - Other_LcprepInterpretasiIsActive = 'Y'"; - $this->db_smartone->query($sql); - $sql = "INSERT INTO other_lcprepinterpretasi ( - Other_LcprepInterpretasiOther_LcprepID, - Other_LcprepInterpretasiLcprep_InterpretasiID, - Other_LcprepInterpretasiChex, - Other_LcprepInterpretasiValue, - Other_LcprepInterpretasiUserID, - Other_LcprepInterpretasiCreated - ) - VALUES( - {$header_id}, - '{$iiv['id']}', - '{$chex}', - '{$iiv['value']}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - - if(intval($iiv['xid'] != 0)){ - $chex = $iiv['chex'] ? 'Y':'N'; - $sql = "UPDATE other_lcprepinterpretasi SET - Other_LcprepInterpretasiChex = '{$chex}', - Other_LcprepInterpretasiValue = '{$iiv['value']}', - Other_LcprepInterpretasiUserID = {$userid} - WHERE - Other_LcprepInterpretasiID = {$iiv['xid']}"; - $this->db_smartone->query($sql); - //echo $sql; - - } - - } - } - } - } - //echo $sql; - } - } - - - $result = array("total" => 1, "records" => array(), "sql"=> ''); - $this->sys_ok($result); - exit; - } - - function saveresult_papsmear() - { - $prm = $this->sys_input; - $detail_id = $prm['detail_id']; - $doctor_id = $prm['doctor']; - $checks = $prm['checks']; - $maturasi = $prm['maturasi']; - $bahans = $prm['bahans']; - $categories = $prm['categories']; - $results = $prm['results']; - - $userid = $this->sys_user['M_UserID']; - - $header_id = 0; - $sql = "SELECT * FROM other_papsmear WHERE Other_PapSmearT_OrderDetailID = {$detail_id} AND Other_PapSmearIsActive = 'Y'"; - $dt_header = $this->db_smartone->query($sql)->row_array(); - if($dt_header){ - $header_id = $dt_header['Other_PapSmearID']; - } - if($header_id == 0){ - $sql = "INSERT INTO other_papsmear( - Other_PapSmearT_OrderDetailID, - Other_PapSmearM_DoctorID, - Other_PapSmearUserID, - Other_PapSmearCreated - ) - VALUES( - {$detail_id}, - {$doctor_id}, - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } - else{ - $sql = "UPDATE other_papsmear SET Other_PapSmearM_DoctorID = {$doctor_id}, Other_PapSmearUserID = {$userid} WHERE Other_PapSmearID = {$header_id}"; - $this->db_smartone->query($sql); - } - - if($checks){ - foreach($checks as $k =>$v){ - if(intval($v['xid']) == 0 && $v['selected'] === 'Y'){ - $sql = "INSERT INTO other_papsmearcheck ( - Other_PapSmearCheckOther_PapSmearID, - Other_PapSmearCheckM_PapSmearCheckID, - Other_PapSmearCheckNote, - Other_PapSmearCheckUserID, - Other_PapSmearCheckCreated - ) - VALUES( - {$header_id}, - {$v['check_id']}, - '{$v['note']}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if(intval($v['xid']) != 0 && $v['selected'] === 'N'){ - $sql = "UPDATE other_papsmearcheck SET - Other_PapSmearCheckIsActive = 'N', - Other_PapSmearCheckUserID = {$userid} - WHERE - Other_PapSmearCheckID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - if(intval($v['xid']) != 0 && $v['selected'] === 'Y'){ - $sql = "UPDATE other_papsmearcheck SET - Other_PapSmearCheckNote = '{$v['note']}', - Other_PapSmearCheckUserID = {$userid} - WHERE - Other_PapSmearCheckID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - //echo $sql; - } - } - - if($maturasi){ - if(intval($maturasi['xid']) == 0){ - $value = join("/",$maturasi['value']); - $sql = "INSERT INTO other_papsmearmaturasi ( - Other_PapSmearMaturasiOther_PapSmearID, - Other_PapSmearMaturasiValue, - Other_PapSmearMaturasiUserID, - Other_PapSmearMaturasiCreated - ) - VALUE( - {$header_id}, - '{$value}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - //echo $sql; - } - if(intval($maturasi['xid']) != 0){ - $value = join("/",$maturasi['value']); - $sql = "UPDATE other_papsmearmaturasi SET - Other_PapSmearMaturasiValue = '{$value}', - Other_PapSmearMaturasiUserID = {$userid} - WHERE - Other_PapSmearMaturasiID = {$maturasi['xid']}"; - // echo $sql; - $this->db_smartone->query($sql); - } - } - - if($bahans){ - foreach($bahans as $k =>$v){ - if(intval($v['xid']) == 0 && $v['selected'] === 'Y'){ - $sql = "INSERT INTO other_papsmearbahan ( - Other_PapSmearBahanOther_PapSmearID, - Other_PapSmearBahanM_PapSmearBahanID, - Other_PapSmearBahanUserID, - Other_PapSmearBahanCreated - ) - VALUES( - {$header_id}, - {$v['bahan_id']}, - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if(intval($v['xid']) != 0 && $v['selected'] === 'N'){ - $sql = "UPDATE other_papsmearbahan SET - Other_PapSmearBahanIsActive = 'N', - Other_PapsmearCategoryUserID = {$userid} - WHERE - Other_PapSmearBahanID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - if(intval($v['xid']) != 0 && $v['selected'] === 'Y'){ - $sql = "UPDATE other_papsmearbahan SET - Other_PapSmearBahanIsActive = 'Y', - Other_PapsmearCategoryUserID = {$userid} - WHERE - Other_PapSmearBahanID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - //echo $sql; - } - } - - if($categories){ - foreach($categories as $k =>$v){ - if(intval($v['xid']) == 0 && $v['selected'] === 'Y'){ - $sql = "INSERT INTO other_papsmearcategory ( - Other_PapsmearCategoryOther_PapSmearID, - Other_PapsmearCategoryM_PapSmearCategoryID, - Other_PapsmearCategoryUserID, - Other_PapsmearCategoryCreated - ) - VALUES( - {$header_id}, - {$v['category_id']}, - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if(intval($v['xid']) != 0 && $v['selected'] === 'N'){ - $sql = "UPDATE other_papsmearcategory SET - Other_PapsmearCategoryIsActive = 'N', - Other_PapsmearCategoryUserID = {$userid} - WHERE - Other_PapsmearCategoryID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - //echo $sql; - if(intval($v['xid']) != 0 && $v['selected'] === 'Y'){ - $sql = "UPDATE other_papsmearcategory SET - Other_PapsmearCategoryIsActive = 'Y', - Other_PapsmearCategoryUserID = {$userid} - WHERE - Other_PapsmearCategoryID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - } - } - - if($results){ - foreach($results as $k =>$v){ - if(intval($v['xid']) == 0){ - $sql = "INSERT INTO other_papsmeardetails ( - Other_PapSmearDetailsOther_PapSmearID, - Other_PapSmearDetailsCode, - Other_PapSmearDetailsLabel, - Other_PapSmearDetailsResult, - Other_PapSmearDetailsUserID, - Other_PapSmearDetailsCreated - ) - VALUES( - {$header_id}, - '{$v['code']}', - '{$v['label']}', - '{$v['result']}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if(intval($v['xid']) != 0){ - $sql = "UPDATE other_papsmeardetails SET - Other_PapSmearDetailsCode = '{$v['code']}', - Other_PapSmearDetailsLabel = '{$v['label']}', - Other_PapSmearDetailsResult = '{$v['result']}', - Other_PapSmearDetailsUserID = {$userid} - WHERE - Other_PapSmearDetailsID = {$v['xid']}"; - $this->db_smartone->query($sql); - - } - //echo $sql; - } - } - - $result = array("total" => 1, "records" => array(), "sql"=> ''); - $this->sys_ok($result); - exit; - } - - function saveresult_fna() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = $inp['doctor']; - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - if($prm[0]['xid'] == '0'){ - $sql = "INSERT INTO other_fna( - Other_FNAM_DoctorID, - Other_FNAT_OrderDetailID, - Other_FNAUserID, - Other_FNACreated - ) - VALUES( - {$doctor_id}, - {$prm[0]['orderdetail_id']}, - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } - else{ - $sql = "SELECT * FROM other_fna WHERE Other_FNAT_OrderDetailID = {$prm[0]['orderdetail_id']} AND Other_FNAIsActive = 'Y'"; - $data_header = $this->db_smartone->query($sql)->row_array(); - $header_id = $data_header['Other_FNAID']; - $sql = "UPDATE other_fna SET - Other_FNAM_DoctorID = {$doctor_id}, - Other_FNAUserID = {$userid} - WHERE - Other_FNAID = {$header_id}"; - $this->db_smartone->query($sql); - } - foreach($prm as $k => $v){ - if($v['xid'] == '0'){ - $results = str_replace("'", "\\'", $v['result']); - $sql = "INSERT INTO other_fnadetails( - Other_FNADetailsOther_FNAID , - Other_FNADetailsCode, - Other_FNADetailsLabel, - Other_FNADetailsResult, - Other_FNADetailsCreated, - Other_FNADetailsUserID - ) - VALUES( - {$header_id}, - '{$v['code']}', - '{$v['label']}', - '{$results}', - NOW(), - {$userid} - )"; - $query = $this->db_smartone->query($sql); - } - else{ - $results = str_replace("'", "\\'", $v['result']); - $sql = "UPDATE other_fnadetails SET - Other_FNADetailsResult = '{$results}', - Other_FNADetailsUserID = {$userid} - WHERE - Other_FNADetailsID = {$v['xid']}"; - $query = $this->db_smartone->query($sql); - } - } - - $result = array("total" => 1, "records" => array(), "sql"=> ''); - $this->sys_ok($result); - exit; - } - - function saveresult_cytologi() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = $inp['doctor']; - - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - if($prm[0]['xid'] == '0'){ - $sql = "INSERT INTO other_cytologi( - Other_CytologiT_OrderDetailID, - Other_CytologiM_DoctorID, - Other_CytologiUserID, - Other_CytologiCreated - ) - VALUES( - {$prm[0]['orderdetail_id']}, - {$doctor_id}, - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } - else{ - $sql = "SELECT * FROM other_cytologi WHERE Other_CytologiT_OrderDetailID = {$prm[0]['orderdetail_id']} AND Other_CytologiIsActive = 'Y'"; - $data_header = $this->db_smartone->query($sql)->row_array(); - $header_id = $data_header['Other_CytologiID']; - $sql = "UPDATE other_cytologi SET - Other_CytologiM_DoctorID = {$doctor_id}, - Other_CytologiUserID = {$userid} - WHERE - Other_CytologiID = {$header_id}"; - $this->db_smartone->query($sql); - } - foreach($prm as $k => $v){ - if($v['xid'] == '0'){ - $results = str_replace("'", "\\'", $v['result']); - $sql = "INSERT INTO other_cytologidetails( - Other_CytologiDetailsOther_CytologiID , - Other_CytologiDetailsCode, - Other_CytologiDetailsLabel, - Other_CytologiDetailsResult, - Other_CytologiDetailsCreated, - Other_CytologiDetailsUserID - ) - VALUES( - {$header_id}, - '{$v['code']}', - '{$v['label']}', - '{$results}', - NOW(), - {$userid} - )"; - $query = $this->db_smartone->query($sql); - } - else{ - $results = str_replace("'", "\\'", $v['result']); - $sql = "UPDATE other_cytologidetails SET - Other_CytologiDetailsResult = '{$results}', - Other_CytologiDetailsUserID = {$userid} - WHERE - Other_CytologiDetailsID = {$v['xid']}"; - $query = $this->db_smartone->query($sql); - } - } - - $result = array("total" => 1, "records" => array(), "sql"=> ''); - $this->sys_ok($result); - exit; - } - - function saveresult_mikro() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = $inp['doctor']; - $backteria_id = $inp['bacteria']; - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - - if($inp['result_value'] != 'Negatif' && $inp['result_value'] != 'Positif'){ - $prm['result_value'] = $prm['result_other']; - } - else{ - $prm['result_value'] = $inp['result_value']; - } - - if($prm['xid'] == '0'){ - $sql = "INSERT INTO other_mikro( - Other_MikroM_DoctorID, - Other_MikroResult, - Other_MikroT_BacteriaID, - Other_MikroT_OrderDetailID, - Other_MikroHasilBiakan, - Other_MikroSampleTypeName, - Other_MikroUserID, - Other_MikroCreated - ) - VALUES( - {$doctor_id}, - '{$prm['result_value']}', - {$backteria_id}, - {$prm['orderdetail_id']}, - '{$prm['hasil_biakan']}', - '{$prm['sample_name']}', - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } - else{ - $sql = "SELECT * FROM other_mikro WHERE Other_MikroT_OrderDetailID = {$prm['orderdetail_id']} AND Other_MikroIsActive = 'Y'"; - $data_header = $this->db_smartone->query($sql)->row_array(); - $header_id = $data_header['Other_MikroID']; - $sql = "UPDATE other_mikro SET - Other_MikroResult = '{$prm['result_value']}', - Other_MikroM_DoctorID = {$doctor_id}, - Other_MikroT_BacteriaID = {$backteria_id}, - Other_MikroHasilBiakan = '{$prm['hasil_biakan']}', - Other_MikroSampleTypeName = '{$prm['sample_name']}', - Other_MikroUserID = {$userid} - WHERE - Other_MikroID = {$header_id}"; - //echo $sql; - $this->db_smartone->query($sql); - } - - - - $sql = "UPDATE other_mikrodetails SET Other_MikroDetailsIsActive = 'N', Other_MikroDetailsUserID = 0 WHERE Other_MikroDetailsOther_MikroID = {$header_id}"; - $this->db_smartone->query($sql); - - $results = $prm['details']; - if($inp['result_value'] == 'Positif'){ - foreach($results as $k => $v){ - if($v['xid'] == '0'){ - $sql = "INSERT INTO other_mikrodetails( - Other_MikroDetailsOther_MikroID , - Other_MikroDetailsT_AntibioticID, - Other_MikroDetailsValue, - Other_MikroDetailsNote, - Other_MikroDetailsCreated, - Other_MikroDetailsUserID - ) - VALUES( - {$header_id}, - '{$v['T_AntibioticID']}', - '{$v['value']}', - '{$v['note']}', - NOW(), - {$userid} - )"; - $query = $this->db_smartone->query($sql); - } - else{ - $sql = "UPDATE other_mikrodetails SET - Other_MikroDetailsT_AntibioticID = '{$v['T_AntibioticID']}', - Other_MikroDetailsValue = '{$v['value']}', - Other_MikroDetailsNote = '{$v['note']}', - Other_MikroDetailsIsActive = 'Y', - Other_MikroDetailsUserID = {$userid} - WHERE - Other_MikroDetailsID = {$v['xid']}"; - //echo $sql; - $query = $this->db_smartone->query($sql); - } - } - } - - - $result = array("total" => 1, "records" => array(), "sql"=> ''); - $this->sys_ok($result); - exit; - } - - - function get_doctors_preparasi_sperma() - { - $prm = $this->sys_input; - // $id = $prm["id"]; - - $sql = " SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 10 AND - M_DoctorSOIsActive = 'Y' - ORDER BY M_DoctorName ASC"; - //echo $sql; - $query = $this->db_smartone->query($sql); - $rows = $query->result_array(); - $sql = " - SELECT '0' as id, 'Belum memilih metode' as name - UNION - SELECT M_MethodeSpermaID as id, M_MethodeSpermaName as name - FROM m_methodesperma - WHERE - M_MethodeSpermaIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $methodes = $this->db_smartone->query($sql)->result_array(); - - - $this->sys_ok(["records"=>$rows,"methodes"=>$methodes]); - - } - - - function getpreparasispermaresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT other_preparasisperma.*, - Other_PreparasiSpermaID as xid, - Other_PreparasiSpermaT_OrderDetailID as orderdetail_id, - IFNULL(Other_PreparasiSpermaM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_PreparasiSpermaM_DoctorID) OR Other_PreparasiSpermaM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name, - IFNULL(M_MethodeSpermaID,0) as methode_id, - IFNULL(M_MethodeSpermaName,'') as methode_name - FROM other_preparasisperma - LEFT JOIN m_doctor ON Other_PreparasiSpermaM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - LEFT JOIN m_methodesperma ON Other_PreparasiSpermaM_MethodeSpermaID = M_MethodeSpermaID AND - M_MethodeSpermaIsActive = 'Y' - WHERE - Other_PreparasiSpermaT_OrderDetailID = {$id} AND Other_PreparasiSpermaIsActive = 'Y' - GROUP BY Other_PreparasiSpermaID"; - $query = $this->db_smartone->query($sql); - - if ($query) - { - $rows = $query->row_array(); - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 10 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $sql = " - SELECT '0' as id, 'Belum memilih metode' as name - UNION - SELECT M_MethodeSpermaID as id, M_MethodeSpermaName as name - FROM m_methodesperma - WHERE - M_MethodeSpermaIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $methodes = $this->db_smartone->query($sql)->result_array(); - $images = array(); - $sql = "SELECT Other_PreparasiSpermaImgID as xid, - Other_PreparasiSpermaImgType as type, - CONCAT('/one-media/one-image-nonlab/',Other_PreparasiSpermaImgNewName) as image_url - FROM t_orderdetail - JOIN other_preparasisperma_img ON Other_PreparasiSpermaImgT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND - Other_PreparasiSpermaImgIsActive = 'Y' - WHERE - T_OrderDetailID = {$id} AND - T_OrderDetailIsActive = 'Y' - GROUP BY Other_PreparasiSpermaImgID"; - //echo $sql; - $images = $this->db_smartone->query($sql)->result_array(); - - $rst = array('doctors'=>$doctors,'methodes'=>$methodes,'results'=>$rows,'images'=>$images); - $this->sys_ok(["records"=>$rst]); - } - else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - - function uploadimage_preparasi_sperma(){ - if (! $this->isLogin) { - $this->sys_error("Invalid Token"); - exit; - } - - $userid = $this->sys_user["M_UserID"]; - $data = []; - //print_r($_SERVER); - - $prm = $this->sys_input; - $orderid = $this->input->post('orderid'); - $type = $this->input->post('type'); - $labnumber = $this->input->post('labnumber'); - $sql = "UPDATE other_preparasisperma_img SET - Other_PreparasiSpermaImgIsActive = 'N', - Other_PreparasiSpermaImgUserID = {$userid} - WHERE - Other_PreparasiSpermaImgT_OrderHeaderID = {$orderid} AND - Other_PreparasiSpermaImgType = '{$type}'"; - //echo $sql; - $this->db_onedev->query($sql); - //$config['upload_path'] = 'assets/'; - - $path = '/home/one/project/one/one-media/one-image-nonlab/'; - //echo $path; - $config['upload_path'] = $path; - $config['allowed_types'] = 'jpg|jpeg|png|gif'; - - $config['max_size'] = '10000'; - $count = count($_FILES['files']['name']); - //echo $count; - $this->load->library('upload',$config); - - $error = []; - for($i=0;$i<$count;$i++){ - - - if(!empty($_FILES['files']['name'][$i])){ - - - - $_FILES['file']['name'] = $_FILES['files']['name'][$i]; - - $_FILES['file']['type'] = $_FILES['files']['type'][$i]; - - $_FILES['file']['tmp_name'] = $_FILES['files']['tmp_name'][$i]; - - $_FILES['file']['error'] = $_FILES['files']['error'][$i]; - - $_FILES['file']['size'] = $_FILES['files']['size'][$i]; - - - - $namex = $orderid.'-'.$labnumber.'-'.$this->generateRandomString(5); - //echo $namex; - - $config['file_name'] = $namex; - $this->upload->initialize($config); - //echo $config['file_name'] ; - - - - - - if($this->upload->do_upload('file')){ - - $uploadData = $this->upload->data(); - - $filename = $uploadData['file_name']; - //echo $filename; - - - $sql = "INSERT INTO other_preparasisperma_img ( - Other_PreparasiSpermaImgT_OrderHeaderID, - Other_PreparasiSpermaImgType, - Other_PreparasiSpermaImgOldName, - Other_PreparasiSpermaImgNewName, - Other_PreparasiSpermaImgCreated, - Other_PreparasiSpermaImgUserID - ) - VALUES( - {$orderid}, - '{$type}', - '{$_FILES['files']['name'][$i]}', - '{$filename}', - NOW(), - {$userid} - - )"; - //echo $sql; - $this->db_onedev->query($sql); - $xlast_id = $this->db_onedev->insert_id(); - $data['totalFiles'][] = array('xid' => $xlast_id ,'type'=>$type,'image_url' => '/one-media/one-image-nonlab/'.$filename); - - } - else{ - $error = array('error' => $this->upload->display_errors()); - } - - } - - - - } - - $result = array("total" =>count( $data['totalFiles']), "records" => $data['totalFiles'],'errors'=>$error); - $this->sys_ok($result); - } - - - function saveresult_preparasi_sperma() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = $inp['doctor']; - $orderdetail_id = $inp['orderdetailid']; - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - if($prm['xid'] == '0'){ - $sql = "INSERT INTO other_preparasisperma( - Other_PreparasiSpermaM_DoctorID, - Other_PreparasiSpermaT_OrderDetailID, - Other_PreparasiSpermaPreMotilitasA, - Other_PreparasiSpermaPreMotilitasB, - Other_PreparasiSpermaPreMotilitasC, - Other_PreparasiSpermaPreKonsentrasi, - Other_PreparasiSpermaPreKontaminan, - Other_PreparasiSpermaPostMotilitasA, - Other_PreparasiSpermaPostMotilitasB, - Other_PreparasiSpermaPostMotilitasC, - Other_PreparasiSpermaPostKonsentrasi, - Other_PreparasiSpermaPostKontaminan, - Other_PreparasiSpermaPreVolume, - Other_PreparasiSpermaPostVolume, - Other_PreparasiSpermaM_MethodeSpermaID, - Other_PreparasiSpermaNote, - Other_PreparasiSpermaUserID, - Other_PreparasiSpermaCreated - ) - VALUES( - {$doctor_id}, - {$orderdetail_id}, - '{$prm['Other_PreparasiSpermaPreMotilitasA']}', - '{$prm['Other_PreparasiSpermaPreMotilitasB']}', - '{$prm['Other_PreparasiSpermaPreMotilitasC']}', - '{$prm['Other_PreparasiSpermaPreKonsentrasi']}', - '{$prm['Other_PreparasiSpermaPreKontaminan']}', - '{$prm['Other_PreparasiSpermaPostMotilitasA']}', - '{$prm['Other_PreparasiSpermaPostMotilitasB']}', - '{$prm['Other_PreparasiSpermaPostMotilitasC']}', - '{$prm['Other_PreparasiSpermaPostKonsentrasi']}', - '{$prm['Other_PreparasiSpermaPostKontaminan']}', - '{$prm['Other_PreparasiSpermaPreVolume']}', - '{$prm['Other_PreparasiSpermaPostVolume']}', - '{$prm['Other_PreparasiSpermaM_MethodeSpermaID']}', - '{$prm['Other_PreparasiSpermaNote']}', - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } - else{ - $sql = "SELECT * FROM other_preparasisperma WHERE Other_PreparasiSpermaT_OrderDetailID = {$orderdetail_id} AND Other_PreparasiSpermaIsActive = 'Y'"; - $data_header = $this->db_smartone->query($sql)->row_array(); - $header_id = $data_header['Other_PreparasiSpermaID']; - $sql = "UPDATE other_preparasisperma SET - Other_PreparasiSpermaM_DoctorID = {$doctor_id}, - Other_PreparasiSpermaPreMotilitasA = '{$prm['Other_PreparasiSpermaPreMotilitasA']}', - Other_PreparasiSpermaPreMotilitasB = '{$prm['Other_PreparasiSpermaPreMotilitasB']}', - Other_PreparasiSpermaPreMotilitasC = '{$prm['Other_PreparasiSpermaPreMotilitasC']}', - Other_PreparasiSpermaPreKonsentrasi = '{$prm['Other_PreparasiSpermaPreKonsentrasi']}', - Other_PreparasiSpermaPreKontaminan = '{$prm['Other_PreparasiSpermaPreKontaminan']}', - Other_PreparasiSpermaPostMotilitasA = '{$prm['Other_PreparasiSpermaPostMotilitasA']}', - Other_PreparasiSpermaPostMotilitasB = '{$prm['Other_PreparasiSpermaPostMotilitasB']}', - Other_PreparasiSpermaPostMotilitasC = '{$prm['Other_PreparasiSpermaPostMotilitasC']}', - Other_PreparasiSpermaPostKonsentrasi = '{$prm['Other_PreparasiSpermaPostKonsentrasi']}', - Other_PreparasiSpermaPostKontaminan = '{$prm['Other_PreparasiSpermaPostKontaminan']}', - Other_PreparasiSpermaPreVolume = '{$prm['Other_PreparasiSpermaPreVolume']}', - Other_PreparasiSpermaPostVolume = '{$prm['Other_PreparasiSpermaPostVolume']}', - Other_PreparasiSpermaM_MethodeSpermaID = '{$prm['Other_PreparasiSpermaM_MethodeSpermaID']}', - Other_PreparasiSpermaNote = '{$prm['Other_PreparasiSpermaNote']}', - Other_PreparasiSpermaUserID = {$userid} - WHERE - Other_PreparasiSpermaID = {$header_id}"; - $this->db_smartone->query($sql); - } - - - $result = array("total" => 1, "records" => array(), "sql"=> ''); - $this->sys_ok($result); - exit; - } - - function getdnafragmentasiresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT other_dnafragmentasi.*, - Other_DnaFragmentasiID as xid, - Other_DnaFragmentasiT_OrderDetailID as orderdetail_id, - IFNULL(Other_DnaFragmentasiM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_DnaFragmentasiM_DoctorID) OR Other_DnaFragmentasiM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name, - IFNULL(Other_DnaFragmentasiOther_DnaFragmentasiMethodeID,0) as methode_id, - IFNULL(Other_DnaFragmentasiMethodeName,'') as methode_name, - Other_DnaFragmentasiHaloLuas as halo_luas, - Other_DnaFragmentasiHaloSedang as halo_sedang, - Other_DnaFragmentasiHaloSempit as halo_sempit, - Other_DnaFragmentasiTanpaHalo as tanpa_halo, - Other_DnaFragmentasiDFI as dfi, - Other_DnaFragmentasiKesimpulan as kesimpulan, - Other_DnaFragmentasiCatatan as catatan - FROM other_dnafragmentasi - LEFT JOIN m_doctor ON Other_DnaFragmentasiM_DoctorID = M_DoctorID - LEFT JOIN other_dnafragmentasimethode ON Other_DnaFragmentasiOther_DnaFragmentasiMethodeID = Other_DnaFragmentasiMethodeID - WHERE - Other_DnaFragmentasiT_OrderDetailID = {$id} AND Other_DnaFragmentasiIsActive = 'Y' - GROUP BY Other_DnaFragmentasiID - LIMIT 1"; - //echo $sql; - $query = $this->db_smartone->query($sql); - - if ($query) - { - $rows = $query->row_array(); - if(!$rows){ - $rows = array( - 'xid' => 0, - 'orderdetail_id' =>$id, - 'doctor_id' => 0, - 'doctor_name' => '', - 'methode_id' => 0, - 'methode_name' => '', - 'halo_luas' => '', - 'halo_sedang' => '', - 'tanpa_halo' => '', - 'dfi' => '', - 'kesimpulan' => '', - 'catatan' => '' - ); - } - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID - WHERE - M_DoctorSONat_SubGroupID = 4 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - - $sql = " - SELECT '0' as id, 'Belum memilih metode' as name - UNION - SELECT Other_DnaFragmentasiMethodeID as id, Other_DnaFragmentasiMethodeName as name - FROM other_dnafragmentasimethode - WHERE - Other_DnaFragmentasiMethodeIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $methodes = $this->db_smartone->query($sql)->result_array(); - - - $rst = array('doctors'=>$doctors,'methodes'=>$methodes,'results'=>$rows); - $this->sys_ok(["records"=>$rst]); - } - else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - function saveresult_dnafragmentasi() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = $inp['doctor']['id']; - $methode_id = $inp['methode']['id']; - $orderdetail_id = $inp['results']['orderdetail_id']; - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - if(intval($prm['xid']) == 0){ - $sql = "INSERT INTO other_dnafragmentasi( - Other_DnaFragmentasiT_OrderDetailID, - Other_DnaFragmentasiM_DoctorID, - Other_DnaFragmentasiOther_DnaFragmentasiMethodeID, - Other_DnaFragmentasiHaloLuas, - Other_DnaFragmentasiHaloSedang, - Other_DnaFragmentasiHaloSempit, - Other_DnaFragmentasiTanpaHalo, - Other_DnaFragmentasiDFI, - Other_DnaFragmentasiKesimpulan, - Other_DnaFragmentasiCatatan, - Other_DnaFragmentasiUserID, - Other_DnaFragmentasiLastUpdated - ) - VALUES( - {$orderdetail_id}, - {$doctor_id}, - {$methode_id}, - '{$prm['halo_luas']}', - '{$prm['halo_sedang']}', - '{$prm['halo_sempit']}', - '{$prm['tanpa_halo']}', - '{$prm['dfi']}', - '{$prm['kesimpulan']}', - '{$prm['catatan']}', - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } - else{ - $sql = "UPDATE other_dnafragmentasi SET - Other_DnaFragmentasiT_OrderDetailID = {$orderdetail_id}, - Other_DnaFragmentasiM_DoctorID = {$doctor_id}, - Other_DnaFragmentasiOther_DnaFragmentasiMethodeID = '{$methode_id}', - Other_DnaFragmentasiHaloLuas = '{$prm['halo_luas']}', - Other_DnaFragmentasiHaloSedang = '{$prm['halo_sedang']}', - Other_DnaFragmentasiHaloSempit = '{$prm['halo_sempit']}', - Other_DnaFragmentasiTanpaHalo = '{$prm['tanpa_halo']}', - Other_DnaFragmentasiDFI = '{$prm['dfi']}', - Other_DnaFragmentasiKesimpulan = '{$prm['kesimpulan']}', - Other_DnaFragmentasiCatatan = '{$prm['catatan']}', - Other_DnaFragmentasiLastUpdated = NOW(), - Other_DnaFragmentasiUserID = {$userid} - WHERE - Other_DnaFragmentasiID = {$prm['xid']}"; - //echo $sql; - $this->db_smartone->query($sql); - } - - - $result = array("total" => 1, "records" => array(), "sql"=> ''); - $this->sys_ok($result); - exit; - } - - -} - +db_smartone = $this->load->database("onedev", true); + $this->load->helper(array('form', 'url')); + } + function getMethodeID($natTestID) { + $sql = "select M_MethodePriorityNat_MethodeID MethodeID, Nat_MethodeName + from + m_methode_priority + join nat_methode on Nat_MethodeID = M_MethodePriorityNat_MethodeID + and Nat_MethodeIsActive = 'Y' + join m_instrumentmethode on M_InstrumentMethodeNat_MethodeID = Nat_MethodeID and M_InstrumentMethodeIsActive = 'Y' + join nat_instrument on M_InstrumentMethodeNat_InstrumentID = Nat_InstrumentID + and Nat_InstrumentIsActive ='Y' + where M_MethodePriorityIsActive = 'Y' + and M_MethodePriorityNat_TestID = $natTestID + and M_MethodePriorityM_DayOfWeekID = dayofweek(now()) + order by M_MethodePriorityNumber desc + limit 0,1 "; + $qry = $this->db->query($sql); + if ($qry) { + $rows = $qry->result_array(); + if (count($rows) > 0 ) return array($rows[0]["MethodeID"],$rows[0]["Nat_MethodeName"]); + } + //2nd + $sql= "select + M_InstrumentMethodeNat_MethodeID MethodeID, Nat_MethodeName + from m_instrumentmethode + join nat_methode on M_InstrumentMethodeNat_MethodeID = Nat_MethodeID + and Nat_MethodeIsActive = 'Y' + join nat_instrument on M_InstrumentMethodeNat_InstrumentID = Nat_InstrumentID + and Nat_InstrumentIsActive ='Y' + where M_InstrumentMethodeNat_TestID = $natTestID + and M_InstrumentMethodeIsActive = 'Y' + order by M_InstrumentMethodePriority desc + limit 0,1"; + $qry = $this->db->query($sql); + if ($qry) { + $rows = $qry->result_array(); + if (count($rows) > 0 ) return array($rows[0]["MethodeID"],$rows[0]["Nat_MethodeName"]); + } + // + $sql = "select Nat_NormalValueNat_MethodeID MethodeID, Nat_MethodeName + from + nat_normalvalue + join nat_methode on Nat_NormalValueNat_MethodeID = Nat_MethodeID + and Nat_MethodeIsActive = 'Y' + where Nat_NormalValueNat_TestID = $natTestID + and Nat_NormalValueIsActive = 'Y' + order by Nat_NormalValueID + limit 0,1"; + $qry = $this->db->query($sql); + if ($qry) { + $rows = $qry->result_array(); + if (count($rows) > 0 ) return array($rows[0]["MethodeID"],$rows[0]["Nat_MethodeName"]); + } + return array(0,""); + } + function get_normal_value($methodeID, $natTestID, $sexID, $ageInDay ) { + $this->load->library('ibl_sampling_normal'); + return $this->ibl_sampling_normal->get_normal_value_id($methodeID, $natTestID, $sexID, $ageInDay); + } + return 0; + } + function fn_fix_normal($order_id) { + $sql = "select + T_OrderDetailID, M_PatientM_SexID, fn_global_age_count_day(M_PatientDOB, date(T_OrderHeaderDate)) Dob , + T_TestNat_TestID + from t_orderheader + join m_patient on T_OrderHeaderID = $order_id and T_OrderHeaderM_PatientID = M_PatientID + join t_orderdetail on T_OrderDetailT_OrderHeaderID = T_OrderHeaderID + and T_OrderDetailIsACtive = 'Y' + and ( T_OrderDetailNat_NormalValueID is null or T_OrderDetailNat_NormalValueID = 0 ) + join t_test on T_OrderDetailT_TestID = T_TestID and T_TestIsResult = 'Y' "; + $qry = $this->db->query($sql); + if(! $qry) { + return; + } + $rows = $qry->result_array(); + if(count($rows) == 0 ) return; + $sql_u = "update t_orderdetail + join nat_normalvalue on T_OrderDetailID = ? and Nat_NormalValueID = ? + set + T_OrderDetailNat_NormalValueID = Nat_NormalValueID, + T_OrderDetailNormalValueNote = Nat_NormalValueNote, + T_OrderDetailNormalValueDescription = Nat_NormalValueDescription, + T_OrderDetailMinValue = Nat_NormalValueMinValue, + T_OrderDetailMaxValue = Nat_NormalValueMaxValue, + T_OrderDetailMinValueInclusive = Nat_NormalValueMinValueInclusive, + T_OrderDetailMaxValueInclusive = Nat_NormalValueMaxValueInclusive, + T_OrderDetailNat_MethodeID = ?, + T_OrderdetailNat_MethodeName =?"; + + foreach($rows as $r) { + $T_OrderDetailID = $r["T_OrderDetailID"]; + $sexID = $r["M_PatientM_SexID"]; + $ageInDay = $r["Dob"]; + $natTestID = $r["T_TestNat_TestID"]; + list($methodeID,$methodeName) = $this->getMethodeID($natTestID); + if ($methodeID == 0 ) continue; + $normalValueID = $this->get_normal_value($methodeID, $natTestID, $sexID, $ageInDay); + if ($normalValueID == 0) return; + $this->db->query($sql_u, array($T_OrderDetailID, $normalValueID, $methodeID, $methodeName)); + } + } + function update_order_sample($targetID, $sourceID) { + $sql = "update t_ordersample target + join t_ordersample source on + target.T_OrderSampleID = ? + and target.T_OrderSampleWorklistReceive = 'N' + and source.T_OrderSampleID = ? + set + target.T_OrderSampleSampling = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSampling, source.T_OrderSampleSampling), + target.T_OrderSampleSamplingDate = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingDate, source.T_OrderSampleSamplingDate), + target.T_OrderSampleSamplingTime = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingTime, source.T_OrderSampleSamplingTime), + target.T_OrderSampleSamplingUserID = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingUserID, source.T_OrderSampleSamplingUserID), + + target.T_OrderSampleReceive = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceive, source.T_OrderSampleReceive), + target.T_OrderSampleReceiveDate = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveDate, source.T_OrderSampleReceiveDate), + target.T_OrderSampleReceiveTime = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveTime, source.T_OrderSampleReceiveTime), + target.T_OrderSampleReceiveUserID = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveUserID, source.T_OrderSampleReceiveUserID), + + target.T_OrderSampleVerification = if(target.T_OrderSampleVerification='Y',target.T_OrderSampleVerification, source.T_OrderSampleVerification), + target.T_OrderSampleVerificationDate =if(target.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationDate, source.T_OrderSampleVerificationDate), + target.T_OrderSampleVerificationTime =if(source.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationTime, source.T_OrderSampleVerificationTime), + target.T_OrderSampleVerificationUserID =if(source.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationUserID, source.T_OrderSampleVerificationUserID), + + target.T_OrderSampleProcessing = if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessing, source.T_OrderSampleProcessing), + target.T_OrderSampleProcessingDate= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingDate, source.T_OrderSampleProcessingDate), + target.T_OrderSampleProcessingTime= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingTime, source.T_OrderSampleProcessingTime), + target.T_OrderSampleProcessingUserID= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingUserID, source.T_OrderSampleProcessingUserID), + + target.T_OrderSampleReceiveHandling =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandling, source.T_OrderSampleReceiveHandling ), + target.T_OrderSampleReceiveHandlingDate =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingDate, source.T_OrderSampleReceiveHandlingDate), + target.T_OrderSampleReceiveHandlingTime =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingTime, source.T_OrderSampleReceiveHandlingTime), + target.T_OrderSampleReceiveHandlingUserID =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingUserID, source.T_OrderSampleReceiveHandlingUserID), + + target.T_OrderSampleHandling = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandling, source.T_OrderSampleHandling), + target.T_OrderSampleHandlingDate = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingDate, source.T_OrderSampleHandlingDate), + target.T_OrderSampleHandlingTime = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingTime, source.T_OrderSampleHandlingTime), + target.T_OrderSampleHandlingUserID = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingUserID, source.T_OrderSampleHandlingUserID), + + target.T_OrderSampleWorklistReceive = source.T_OrderSampleWorklistReceive, + target.T_OrderSampleWorklistReceiveDatetime = source.T_OrderSampleWorklistReceiveDateTime, + target.T_OrderSampleWorklistReceiveUserID = source.T_OrderSampleWorklistReceiveUserID + "; + $qry = $this->db->query($sql,array($targetID,$sourceID)); + if(! $qry ) { + echo json_encode(array( "status" => "ERR" , "message" => print_r($this->db->error(),true))); + exit; + } + } + function fix_sample_serum($headerID) { + //cari t_ordersample yg belum worklist receive dengan code 017% + $sql = "select T_OrderSampleID + from t_ordersample + join t_sampletype on + T_OrderSampleT_OrderHeaderID = ? + and T_OrderSampleWorklistReceive = 'N' + and T_OrderSampleIsActive = 'Y' + and T_OrderSampleT_SampleTypeID = T_SampletypeID + and T_SampleTypeCode like '017%' + "; + $qry = $this->db->query($sql, array($headerID)); + if(!$qry) { + echo json_encode(array( "status" => "ERR" , "message" => print_r($this->db->error(),true))); + exit; + } + $rows = $qry->result_array(); + if (count($rows) == 0 ) return; + //cari T_OrderSample yang sudah di receive yg terakhir + $sql = "select T_OrderSampleID + from t_ordersample + join t_sampletype on + T_OrderSampleT_OrderHeaderID = ? + and T_OrderSampleWorklistReceive = 'Y' + and T_OrderSampleIsActive = 'Y' + and T_OrderSampleT_SampleTypeID = T_SampletypeID + and T_SampleTypeCode like '017%' + order by T_OrderSampleWorklistReceiveDatetime desc + limit 0,1 + "; + $qry = $this->db->query($sql, array($headerID)); + if(!$qry) { + echo json_encode(array( "status" => "ERR" , "message" => print_r($this->db->error(),true))); + exit; + } + $rcv_rows = $qry->result_array(); + if (count($rcv_rows) == 0 ) return; + + //print_r($rows); + //print_r($rcv_rows); + $rcv_T_OrderSampleID = $rcv_rows[0]["T_OrderSampleID"]; + //ada yg belum di receive + foreach($rows as $r) { + $T_OrderSampleID = $r["T_OrderSampleID"]; + $this->update_order_sample($T_OrderSampleID,$rcv_T_OrderSampleID); + } + } + public function search() + { + $prm = $this->sys_input; + $max_rst = 99; + + $id = $prm["order_id"]; + if ($id > 0 ) { + $this->fix_sample_serum($id); + $this->fn_fix_normal($id); + } + $lang = $this->lang_default_code; + $lang_id = isset($prm['lang_id']) ? $prm['lang_id'] : '0'; + + if ($lang_id != 0) + { + $l = $this->db_smartone->where("Nat_LangID", $lang_id)->get("nat_lang")->row(); + $lang = $l->Nat_LangCode; + } + + //tambahan fajri + $sql = " UPDATE t_orderdetail + JOIN t_test ON T_OrderDetailT_TestID = T_TestID + SET T_OrderDetailT_TestIsResult = T_TestIsResult + WHERE + T_OrderDetailT_OrderHeaderID = {$id} AND + T_OrderDetailT_TestIsResult = '' AND + T_OrderDetailIsActive = 'Y'"; + $this->db_smartone->query($sql); + + $tot_count = 0; + $lq = ""; + $group_id = 0; + if (isset($prm['group_id'])) + $group_id = $prm['group_id']; + + if ($group_id != 0) + { + $sql = "select distinct T_WorklistDetailNat_TestID Nat_TestID + from t_worklistdetailv2 + where T_WorklistDetailT_WorklistID = {$group_id}"; + $qry = $this->db_smartone->query($sql); + $rows = $qry->result_array(); + $nat_test_ids = "0"; + foreach($rows as $r) { + $nat_test_ids .= ", " . $r["Nat_TestID"]; + } + $q_group = " ( $nat_test_ids ) "; + + $sql = " + SELECT a1.*, cOUNT(a2.T_OrderDetailID) level + FROM ( + SELECT IFNULL(y.T_OrderDetailT_TestID, x.T_OrderDetailT_TestID) t_testid, + IFNULL(y.T_OrderDetailT_TestName, y.T_OrderDetailT_TestName) t_testname, + y.T_OrderDetailResult result, y.T_OrderDetailResult result_old, y.T_OrderDetailNote note, y.T_OrderDetailNote note_old, + y.T_OrderDetailID id, + y.T_OrderDetailT_TestIsResult is_result, a.T_TestIsQuantitative is_quantitative, + y.T_OrderDetailResultFlag result_flag, + y.T_OrderDetailNat_NormalValueID normal_id, + y.T_OrderDetailNormalValueNote normal_note, y.T_OrderDetailNat_UnitName unit_name, + y.T_OrderdetailNat_MethodeID methode_id, y.T_OrderdetailNat_MethodeName methode_name, + a.T_TestNat_TestID nattest_id, a.T_TestID tx_id, count(T_ResultInstrumentID) as result_instrument_n, + y.T_OrderDetailVerification, T_OrderSampleReceive sample_receive, + T_OrderSampleProcessing sample_processing, T_OrderSampleWorklistReceive sample_worklist_receive, + IF(T_OrderDetailAddOnPreAnalytic = 'Y', T_OrderDetailAddOnPreAnalytic, PreAnalyticIsOk) pre_analytic, + T_OrderDetailAddOnPreAnalytic, + T_OrderHeaderID order_id, y.T_OrderDetailT_TestSasCode test_sas_code, + tx.T_TestSasCode, + T_OrderDetailAddOnResample `resample`, T_OrderDetailAddOnResampleStatus resample_status, + T_OrderDetailAddOnRef ref, y.T_OrderDetailVerification verification, y.T_OrderDetailValidation validation, + T_OrderPromiseDateTime, Group_ResultName as ResultGroupName + FROM t_orderdetail x + left join t_orderpromise on x.T_OrderDetailT_OrderPromiseID = T_OrderPromiseID + JOIN t_test tx ON x.T_OrderDetailT_TestID = T_TestID + JOIN t_test tcheck on tcheck.T_TestNat_TestID in {$q_group} + and ( tx.T_TestID = tcheck.T_TestID or tx.T_TestSasCode like concat(tcheck.T_TestSasCode,'%')) + LEFT JOIN group_resultdetail ON Group_ResultDetailT_TestID = x.T_OrderDetailT_TestID AND Group_ResultDetailIsActive = 'Y' + LEFT JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND Group_ResultFlagNonLab = 'N' + LEFT JOIN t_orderdetail y ON x.T_OrderDetailT_TestSasCode LIKE CONCAT(y.T_OrderDetailT_TestSasCode, '%') + AND x.T_OrderDetailT_OrderHeaderID = y.T_OrderDetailT_OrderHeaderID + AND y.T_OrderDetailIsActive = 'Y' + LEFT JOIN t_orderdetailaddon ON x.T_OrderDetailID = T_OrderDetailAddOnT_OrderDetailID + JOIN t_orderheader ON y.T_OrderDetailT_OrderHeaderID = T_OrderHeaderID + LEFT JOIN t_test a ON y.T_OrderDetailT_TestID = a.T_TestID + AND a.T_TestIsNonLab = '' + LEFT JOIN (SELECT T_OrderSampleT_SampleTypeID, T_OrderSampleReceive, T_OrderSampleProcessing, T_OrderSampleWorklistReceive + FROM t_ordersample WHERE T_OrderSampleT_OrderHeaderID = {$id} + AND T_OrderSampleIsactive = 'Y' + GROUP BY T_OrderSampleT_SampleTypeID) os ON a.T_TestT_SampleTypeID = os.T_OrderSampleT_SampleTypeID + or os.T_OrderSampleT_SampleTypeID = fn_sampletype_from_local(a.T_TestNat_TestID) + + LEFT JOIN t_resultinstrument ON T_ResultInstrumentT_OrderDetailID = x.T_OrderDetailID + LEFT JOIN pre_analytic ON PreAnalyticNat_TestID = a.T_TestNat_TestID AND PreAnalyticDate = date(now()) and PreAnalyticIsActive = 'Y' + WHERE x.T_OrderDetailT_OrderHeaderID = {$id} + AND x.T_OrderDetailIsActive = 'Y' + GROUP BY y.T_OrderDetailT_TestID + ORDER BY y.T_OrderDetailT_TestSasCode ASC + ) a1 + + LEFT JOIN t_orderdetail a2 ON a2.T_OrderDetailT_OrderHeaderID = a1.order_id + AND a2.T_OrderDetailIsActive = 'Y' + AND a1.test_sas_code LIKE CONCAT(a2.T_OrderDetailT_testSasCode, '%') + GROUP BY a1.t_testid + order by a1.test_sas_code +"; + $query = $this->db_smartone->query($sql); + $lq = $this->db_smartone->last_query(); + } + else + { + $sql = " + SELECT a1.*, cOUNT(a2.T_OrderDetailID) level + FROM ( + SELECT IFNULL(y.T_OrderDetailT_TestID, x.T_OrderDetailT_TestID) t_testid, + IFNULL(y.T_OrderDetailT_TestName, y.T_OrderDetailT_TestName) t_testname, + y.T_OrderDetailResult result, y.T_OrderDetailResult result_old, y.T_OrderDetailNote note, y.T_OrderDetailNote note_old, + y.T_OrderDetailID id, + y.T_OrderDetailT_TestIsResult is_result, a.T_TestIsQuantitative is_quantitative, + y.T_OrderDetailResultFlag result_flag, + y.T_OrderDetailNat_NormalValueID normal_id, + y.T_OrderDetailNormalValueNote normal_note, y.T_OrderDetailNat_UnitName unit_name, + y.T_OrderdetailNat_MethodeID methode_id, y.T_OrderdetailNat_MethodeName methode_name, + a.T_TestNat_TestID nattest_id, a.T_TestID tx_id, count(T_ResultInstrumentID) as result_instrument_n, + y.T_OrderDetailVerification, T_OrderSampleReceive sample_receive, + T_OrderSampleProcessing sample_processing, T_OrderSampleWorklistReceive sample_worklist_receive, + IF(T_OrderDetailAddOnPreAnalytic = 'Y', T_OrderDetailAddOnPreAnalytic, PreAnalyticIsOk) pre_analytic, + T_OrderDetailAddOnPreAnalytic, + T_OrderHeaderID order_id, y.T_OrderDetailT_TestSasCode test_sas_code, + tx.T_TestSasCode, + T_OrderDetailAddOnResample `resample`, T_OrderDetailAddOnResampleStatus resample_status, + T_OrderDetailAddOnRef ref, y.T_OrderDetailVerification verification, y.T_OrderDetailValidation validation, + T_OrderPromiseDateTime , Group_ResultName as ResultGroupName + FROM t_orderdetail x + left join t_orderpromise on x.T_OrderDetailT_OrderPromiseID = T_OrderPromiseID + JOIN t_test tx ON x.T_OrderDetailT_TestID = T_TestID + LEFT JOIN group_resultdetail ON Group_ResultDetailT_TestID = x.T_OrderDetailT_TestID AND Group_ResultDetailIsActive = 'Y' + LEFT JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND Group_ResultFlagNonLab = 'N' + LEFT JOIN t_orderdetail y ON x.T_OrderDetailT_TestSasCode LIKE CONCAT(y.T_OrderDetailT_TestSasCode, '%') + AND x.T_OrderDetailT_OrderHeaderID = y.T_OrderDetailT_OrderHeaderID + AND y.T_OrderDetailIsActive = 'Y' + + LEFT JOIN t_orderdetailaddon ON x.T_OrderDetailID = T_OrderDetailAddOnT_OrderDetailID + + JOIN t_orderheader ON y.T_OrderDetailT_OrderHeaderID = T_OrderHeaderID + LEFT JOIN t_test a ON y.T_OrderDetailT_TestID = a.T_TestID + AND a.T_TestIsNonLab = '' + LEFT JOIN (SELECT T_OrderSampleT_SampleTypeID, T_OrderSampleReceive, T_OrderSampleProcessing, T_OrderSampleWorklistReceive + FROM t_ordersample WHERE T_OrderSampleT_OrderHeaderID = {$id} + AND T_OrderSampleIsactive = 'Y' + GROUP BY T_OrderSampleT_SampleTypeID) os ON a.T_TestT_SampleTypeID = os.T_OrderSampleT_SampleTypeID + or os.T_OrderSampleT_SampleTypeID = fn_sampletype_from_local(a.T_TestNat_TestID) + + LEFT JOIN t_resultinstrument ON T_ResultInstrumentT_OrderDetailID = x.T_OrderDetailID + LEFT JOIN pre_analytic ON PreAnalyticNat_TestID = a.T_TestNat_TestID AND PreAnalyticDate = date(now()) and PreAnalyticIsActive = 'Y' + WHERE x.T_OrderDetailT_OrderHeaderID = {$id} + AND x.T_OrderDetailIsActive = 'Y' + GROUP BY y.T_OrderDetailT_TestID + ORDER BY y.T_OrderDetailT_TestSasCode ASC + ) a1 + + LEFT JOIN t_orderdetail a2 ON a2.T_OrderDetailT_OrderHeaderID = a1.order_id + AND a2.T_OrderDetailIsActive = 'Y' + AND a1.test_sas_code LIKE CONCAT(a2.T_OrderDetailT_testSasCode, '%') + GROUP BY a1.t_testid + order by a1.test_sas_code +"; +//echo $sql; + $query = $this->db_smartone->query($sql); + $lq = $this->db_smartone->last_query(); + } + // file_put_contents("/xtmp/re-query.sql",$lq); + + if ($query) { + $rst = []; + $rows = $query->result_array(); + + foreach($rows as $k => $v) + { + + if ($v['is_result'] == "Y" && $v['is_quantitative'] == "N") + { + $v['template'] = []; + $x = $this->db_smartone->query("CALL sp_master_resulttemplate_get('{$v['t_testid']}')"); + $this->clean_mysqli_connection($this->db_smartone->conn_id); + if ($x) + $v['template'] = $x->result_array(); + } + + // IF Rujukan, by pas Pre Analytik + if ($v['ref'] == 'Y') + $v['pre_analytic'] = 'Y'; + if ($v["id"] == "885455" ) + { + //sipe workaround + //$v["sample_receive"] = "Y"; + $v["sample_worklist_receive"] = "Y"; + } + $rst[] = $v; + } + + $result = array("total" => $tot_count, "records" => $rst, "total_display" => sizeof($rows), "q" => $lq); + $this->sys_ok($result); + } + else { + $this->sys_error_db("RE Px rows", $this->db_smartone); + exit; + } + } + + public function save() + { + $prm = $this->sys_input; + $data = json_decode($prm["data"]); + $lang = $this->lang_default_code; + $lang_id = isset($prm['lang_id']) ? $prm['lang_id'] : '0'; + + if ($lang_id != 0) + { + $l = $this->db_smartone->where("Nat_LangID", $lang_id)->get("nat_lang")->row(); + $lang = $l->Nat_LangCode; + } + + $sql_norm = "select T_OrderDetailMinValue, T_OrderDetailMaxValue, + T_OrderDetailMinValueInclusive, T_OrderDetailMaxValueInclusive, + Nat_TestFlagLow, Nat_TestFlagHigh + from t_orderdetail + join t_test on T_OrderDetailT_TestID = T_TestID + join nat_test on T_TestNat_TestID = Nat_TestID and T_TestIsActive = 'Y' + where T_OrderDetailID = ? "; + + $ids = []; + foreach ($data as $k => $v) + { + if ( $v->resultInstrumentID > 0 ) { + $sql_i = "select T_ResultInstrumentNat_NormalValueID normalValueID + from t_resultinstrument + where T_ResultInstrumentID = ?"; + $qry_i = $this->db_smartone->query($sql_i, array($v->resultInstrumentID)); + if ($qry_i) { + $rows_i = $qry_i->result_array(); + + if (count($rows_i) > 0 ) { + $sql_iu = "update t_orderdetail, nat_normalvalue , nat_methode + set T_OrderDetailMinValue = Nat_NormalValueMinValue, + T_OrderDetailMinValueInclusive = Nat_NormalValueMinValueInclusive, + T_OrderDetailMaxValue = Nat_NormalValueMaxValue , + T_OrderDetailMaxValueInclusive = Nat_NormalValueMaxValueInclusive, + T_OrderDetailNormalValueNote = Nat_NormalValueNote, + T_OrderDetailNormalValueDescription = Nat_NormalValueDescription, + T_OrderDetailNat_NormalValueID = Nat_NormalValueID, + T_OrderDetailNat_MethodeID = Nat_NormalValueNat_MethodeID, + T_OrderDetailNat_MethodeName = Nat_MethodeName + where T_OrderDetailID = ? and Nat_NormalValueID = ? + and Nat_NormalValueNat_MethodeID = Nat_MethodeID + "; + $this->db_smartone->query($sql_iu, array($v->id, $rows_i[0]["normalValueID"])); + //file_put_contents("/xtmp/update-nilai-normal", $this->db_smartone->last_query() . "\n", FILE_APPEND); + } + } + } + $y = $this->db_smartone->query("SELECT fn_process_sample_handling_perfect('{$v->order_id}', '{$v->test_id}') c") + ->row(); + $req_status = $y->c; + $qry_norm = $this->db_smartone->query($sql_norm,$v->id); + $result_flag = ""; + if ($qry_norm) { + $rows_norm = $qry_norm->result_array(); + if (count($rows_norm) > 0 ) { + $r = $rows_norm[0]; + if (is_numeric($v->result)) { + + if ( $r["T_OrderDetailMinValueInclusive"] == "Y" && $v->result < $r["T_OrderDetailMinValue"] ) { + $result_flag = $r["Nat_TestFlagLow"]; + } + if ( $r["T_OrderDetailMinValueInclusive"] == "N" && $v->result <= $r["T_OrderDetailMinValue"] ) { + $result_flag = $r["Nat_TestFlagLow"]; + } + if ( $r["T_OrderDetailMaxValueInclusive"] == "Y" && $v->result > $r["T_OrderDetailMaxValue"] ) { + $result_flag = $r["Nat_TestFlagHigh"]; + } + if ( $r["T_OrderDetailMaxValueInclusive"] == "N" && $v->result >= $r["T_OrderDetailMaxValue"] ) { + $result_flag = $r["Nat_TestFlagHigh"]; + } + } + } + } + if ($lang == $this->lang_default_code) + { + $this->db_smartone->set('T_OrderDetailResult', $v->result) + ->set('T_OrderDetailResultFlag', $result_flag) + ->set('T_OrderDetailNote', $v->note) + ->set('T_OrderDetailReqStatus', $req_status) + ->where('T_OrderDetailID', $v->id) + ->update('t_orderdetail'); + } + else + { + $this->db_smartone->set('T_OrderDetailLangResult', $v->result) + ->set('T_OrderDetailLangNote', $v->note) + ->where('T_OrderDetailLangID', $v->id) + ->update('t_orderdetaillang'); + } + + $ids[] = $v->id; + } + + // LOG Process + $order = $this->db_smartone->select('T_OrderDetailT_OrderHeaderID id, T_OrderHeaderLabNumber lab_number', false) + ->join('t_orderheader', 'T_OrderHeaderID = T_OrderDetailT_OrderHeaderID') + ->where('T_OrderDetailID', $data[0]->id) + ->get('t_orderdetail') + ->row(); + + $dblog = $this->load->database("onelog", true); + $dblog->set('Log_ProcessCode', 'PROCESS.Result.Entry') + ->set('Log_ProcessOrderID', $order->id) + ->set('Log_ProcessOrderNumber', $order->lab_number) + ->set('Log_ProcessJson', json_encode($data)) + ->set('Log_ProcessUserID', $this->sys_user['M_UserID']) + ->insert('log_process'); + // END OF Log Process + //auto calculation + $this->load->library("Resultcalc"); + $rows = $this->resultcalc->auto($order->id); + + try { + foreach($ids as $id ) { + $this->db_smartone->query("call sp_set_normal_value_flag($id)"); + $this->clean_mysqli_connection($this->db_smartone->conn_id); + } + } catch(Exception $e) { + } + + $this->sys_ok($ids); + } + + public function save_template() + { + $prm = $this->sys_input; + + $n = $this->db_smartone->select("COUNT(T_ResultTemplateID) n") + ->where("T_ResultTemplateT_TestID", $prm['test_id']) + ->where("T_ResultTemplateIsActive", "Y") + ->where("T_ResultTemplateValue", $prm['value']) + ->get('t_resulttemplate') + ->row(); + if ($n->n > 0) + { + $this->sys_error_db("Insert Result Template", $this->db_smartone); + return; + } + + $r = $this->db_smartone->set("T_ResultTemplateT_TestID", $prm['test_id']) + ->set("T_ResultTemplateValue", $prm['value']) + ->insert('t_resulttemplate'); + if ($r) + { + $template = []; + $x = $this->db_smartone->query("CALL sp_master_resulttemplate_get('{$prm['test_id']}')"); + $this->clean_mysqli_connection($this->db_smartone->conn_id); + if ($x) + $template = $x->result_array(); + + $this->sys_ok($template); + } + } + + public function export() + { + $prm = $this->sys_input; + + $sql = "CALL sp_process_result_lang(?, ?, ?, ?)"; + $query = $this->db_smartone->query($sql, [$prm['order_id'], $prm['lang_id'], $prm['is_si'], $this->sys_user['M_UserID']]); + if ($query) + { + $r = $query->row(); + if ($r->status == "OK") + { + $this->sys_ok($r->data); + return; + } + + $this->sys_error_db("Message : " . $r->message, $this->db_smartone); + } + else + { + $this->sys_error_db("Lang Result", $this->db_smartone); + return; + } + } + + public function search_group() + { + $prm = $this->sys_input; + $max_rst = 100; + + // QUERY TOTAL + $sql = "select count(*) total + from t_worklist + where T_WorklistIsActive = 'Y' + order by T_WorklistName ASC"; + $query = $this->db_smartone->query($sql); + + if ($query) { + $tot_count = $query->result_array()[0]["total"]; + } + else { + $this->sys_error_db("worklist count", $this->db_smartone); + exit; + } + + $sql = "select T_WorklistID group_id, T_WorklistName group_name + from t_worklist + where T_WorklistIsActive = 'Y' + order by T_WorklistName ASC + limit 0, {$max_rst}"; + $query = $this->db_smartone->query($sql); + + if ($query) { + $rows = $query->result_array(); + foreach ($rows as $k => $v) + $rows[$k]['data'] = json_decode($v['data']); + $result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows), "q" => $this->db_smartone->last_query()); + $this->sys_ok($result); + } + else { + $this->sys_error_db("worklist rows", $this->db_smartone); + exit; + } + } + + public function search_rerun() + { + $prm = $this->sys_input; + $id = $prm["detail_id"]; + + $sql = "CALL sp_process_result_rerun(?)"; + $query = $this->db_smartone->query($sql, [$id]); + + if ($query) + { + $rows = $query->result_array(); + $this->sys_ok(["records"=>$rows]); + } + else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + + + function getdoctorsfna() + { + $prm = $this->sys_input; + // $id = $prm["id"]; + + $sql = " SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY M_DoctorName ASC"; + //echo $sql; + $query = $this->db_smartone->query($sql); + + if ($query) + { + $rows = $query->result_array(); + $this->sys_ok(["records"=>$rows]); + } + else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + function getfnaresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT Other_FNADetailsID as xid, + Other_FNAT_OrderDetailID as orderdetail_id, + Other_FNADetailsCode as code, + Other_FNADetailsLabel as label, + Other_FNADetailsResult as result, + IFNULL(Other_FNAM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_FNAM_DoctorID) OR Other_FNAM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_fna + JOIN other_fnadetails ON Other_FNADetailsOther_FNAID = Other_FNAID AND Other_FNADetailsIsActive = 'Y' + LEFT JOIN m_doctor ON Other_FNAM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_FNAT_OrderDetailID = {$id} AND Other_FNAIsActive = 'Y' + GROUP BY Other_FNADetailsID + ORDER BY Other_FNADetailsCode ASC"; + $query = $this->db_smartone->query($sql); + + if ($query) + { + $rows = $query->result_array(); + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $images = array(); + $sql = "SELECT So_ImageUploadID as xid, + CONCAT('/one-media/one-image-nonlab/',So_ImageUploadNewName) as image_url + FROM t_orderdetail + JOIN so_imageupload ON So_ImageUploadT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND + So_ImageUploadIsActive = 'Y' + WHERE + T_OrderDetailID = {$id} AND + T_OrderDetailIsActive = 'Y' + GROUP BY So_ImageUploadID"; + $images = $this->db_smartone->query($sql)->result_array(); + + $rst = array('doctors'=>$doctors,'results'=>$rows,'images'=>$images); + $this->sys_ok(["records"=>$rst]); + } + else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + + function uploadimage(){ + if (! $this->isLogin) { + $this->sys_error("Invalid Token"); + exit; + } + + $userid = $this->sys_user["M_UserID"]; + $data = []; + //print_r($_SERVER); + + $prm = $this->sys_input; + $orderid = $this->input->post('orderid'); + $labnumber = $this->input->post('labnumber'); + $sql = "UPDATE so_imageupload SET + So_ImageUploadIsActive = 'N', + So_ImageUploadUserID = {$userid} + WHERE + So_ImageUploadT_OrderHeaderID = {$orderid}"; + //echo $sql; + $this->db_onedev->query($sql); + //$config['upload_path'] = 'assets/'; + + $path = '/home/one/project/one/one-media/one-image-nonlab/'; + //echo $path; + $config['upload_path'] = $path; + $config['allowed_types'] = 'jpg|jpeg|png|gif'; + + $config['max_size'] = '10000'; + $count = count($_FILES['files']['name']); + //echo $count; + $this->load->library('upload',$config); + + $error = []; + for($i=0;$i<$count;$i++){ + + + if(!empty($_FILES['files']['name'][$i])){ + + + + $_FILES['file']['name'] = $_FILES['files']['name'][$i]; + + $_FILES['file']['type'] = $_FILES['files']['type'][$i]; + + $_FILES['file']['tmp_name'] = $_FILES['files']['tmp_name'][$i]; + + $_FILES['file']['error'] = $_FILES['files']['error'][$i]; + + $_FILES['file']['size'] = $_FILES['files']['size'][$i]; + + + + $namex = $orderid.'-'.$labnumber.'-'.$this->generateRandomString(5); + //echo $namex; + + $config['file_name'] = $namex; + $this->upload->initialize($config); + //echo $config['file_name'] ; + + + + + + if($this->upload->do_upload('file')){ + + $uploadData = $this->upload->data(); + + $filename = $uploadData['file_name']; + //echo $filename; + + + $sql = "INSERT INTO so_imageupload ( + So_ImageUploadT_OrderHeaderID, + So_ImageUploadT_OrderHeaderLabNumber, + So_ImageUploadT_SampleTypeID, + So_ImageUploadOldName, + So_ImageUploadNewName, + So_ImageUploadCreated, + So_ImageUploadUserID + ) + VALUES( + {$orderid}, + '{$labnumber}', + '150', + '{$_FILES['files']['name'][$i]}', + '{$filename}', + NOW(), + {$userid} + + )"; + //echo $sql; + $this->db_onedev->query($sql); + $xlast_id = $this->db_onedev->insert_id(); + $data['totalFiles'][] = array('xid' => $xlast_id ,'image_url' => '/one-media/one-image-nonlab/'.$filename); + + } + else{ + $error = array('error' => $this->upload->display_errors()); + } + + } + + + + } + + $result = array("total" =>count( $data['totalFiles']), "records" => $data['totalFiles'],'errors'=>$error); + $this->sys_ok($result); + } + + + function generateRandomString($length = 10) { + $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; + $charactersLength = strlen($characters); + $randomString = ''; + for ($i = 0; $i < $length; $i++) { + $randomString .= $characters[rand(0, $charactersLength - 1)]; + } + return $randomString; + } + + function getcytologiresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT Other_CytologiDetailsID as xid, + Other_CytologiT_OrderDetailID as orderdetail_id, + Other_CytologiDetailsCode as code, + Other_CytologiDetailsLabel as label, + Other_CytologiDetailsResult as result, + IFNULL(Other_CytologiM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_CytologiM_DoctorID) OR Other_CytologiM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_cytologi + JOIN other_cytologidetails ON Other_CytologiDetailsOther_CytologiID = Other_CytologiID AND Other_CytologiDetailsIsActive = 'Y' + LEFT JOIN m_doctor ON Other_CytologiM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_CytologiT_OrderDetailID = {$id} AND Other_CytologiIsActive = 'Y' + GROUP BY Other_CytologiDetailsID + ORDER BY Other_CytologiDetailsCode ASC"; + //echo $sql; + $query = $this->db_smartone->query($sql); + + if ($query) + { + $rows = $query->result_array(); + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $rst = array('doctors'=>$doctors,'results'=>$rows); + $this->sys_ok(["records"=>$rst]); + } + else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + function getmikroresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT + Other_MikroID as xid, + Other_MikroHasilBiakan as hasil_biakan, + Other_MikroSampleTypeName as sample_name, + Other_MikroT_OrderDetailID as orderdetail_id, + Other_MikroResult as result_value, + '' as result_other, + IFNULL(T_BacteriaID,0) as T_BacteriaID, + IFNULL(T_BacteriaName,'') as T_BacteriaName, + '' as details, + IFNULL(Other_MikroM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_MikroM_DoctorID) OR Other_MikroM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_mikro + LEFT JOIN t_bacteria ON Other_MikroT_BacteriaID = T_BacteriaID + LEFT JOIN m_doctor ON Other_MikroM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_MikroT_OrderDetailID = {$id} AND Other_MikroIsActive = 'Y' + GROUP BY Other_MikroID"; + //echo $sql; + $query = $this->db_smartone->query($sql); + + if ($query) + { + $row = $query->row_array(); + if($row){ + if($row['result_value'] != 'Positif' && $row['result_value'] != 'Negatif'){ + $row['result_other'] = $row['result_value']; + $row['result_value'] = 'other'; + } + $sql = "SELECT '' as xno, + Other_MikroDetailsID as xid, + Other_MikroDetailsValue as value, + IF(Other_MikroDetailsNote = 'R','Y','N') as chx_r, + IF(Other_MikroDetailsNote = 'I','Y','N') as chx_i, + IF(Other_MikroDetailsNote = 'S','Y','N') as chx_s, + Other_MikroDetailsNote as note, + t_antibiotic.* + FROM other_mikrodetails + LEFT JOIN t_antibiotic ON Other_MikroDetailsT_AntibioticID = T_AntibioticID + WHERE + Other_MikroDetailsOther_MikroID = {$row['xid']} AND Other_MikroDetailsIsActive = 'Y' + GROUP BY Other_MikroDetailsID + ORDER BY T_AntibioticName ASC"; + //echo $sql; + $details = $this->db_smartone->query($sql)->result_array(); + if(details){ + foreach($details as $k => $v){ + $details[$k]['xno'] = $k + 1; + } + } + $row['details'] = $details; + } + else{ + $row = array('xid'=>'0','hasil_biakan' => '','result_value'=>'Negatif','sample_name' => '','orderdetail_id'=>$id, 'T_BacteriaID'=>'0','T_BacteriaName'=>'0','details'=>array(),'doctor_id'=>'0','doctor_name'=>'0'); + } + } + else{ + $row = array('xid'=>'0','hasil_biakan' => '','result_value'=>'Negatif','sample_name' => '','orderdetail_id'=>$id, 'T_BacteriaID'=>'0','T_BacteriaName'=>'0','details'=>array(),'doctor_id'=>'0','doctor_name'=>'0'); + } + //print_r($row); + + + + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 7 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $sql = " + SELECT '0' as id, 'Belum memilih bakteria' as name + UNION + SELECT T_BacteriaID as id, T_BacteriaName as name + FROM t_bacteria + WHERE + T_BacteriaIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $bacteries = $this->db_smartone->query($sql)->result_array(); + $rst = array('doctors'=>$doctors,'bacteries'=>$bacteries,'results'=>$row); + $this->sys_ok(["records"=>$rst]); + } + function getantibiotics(){ + $prm = $this->sys_input; + $id = $prm["id"]; + $sql = " SELECT '' as xno, + 0 as xid, + '' as hasil_biakan, + '' as sample_name, + 0 as value, + 'Y' as chx_r, + 'N' as chx_i, + 'N' as chx_s, + 'R' as note, + t_antibiotic.* + FROM t_antibiotic + WHERE + T_AntibioticT_BacteriaID = {$prm['id']} AND T_AntibioticIsActive= 'Y' + ORDER BY T_AntibioticName ASC"; + //echo $sql; + $rows = $this->db_smartone->query($sql)->result_array(); + if(rows){ + foreach($rows as $k => $v){ + $rows[$k]['xno'] = $k + 1; + } + } + + $this->sys_ok(["records"=>$rows]); + } + function getlcprepresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + $sql = " SELECT Other_LcprepDetailsID as xid, + Other_LcprepID as header_id, + Other_LcprepT_orderDetailID as orderdetail_id, + Other_LcprepDetailsCode as code, + Other_LcprepDetailsLabel as label, + Other_LcprepDetailsResult as result, + IFNULL(Other_LcprepM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_LcprepM_DoctorID) OR Other_LcprepM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_lcprep + JOIN other_lcprepdetails ON Other_LcprepDetailsOther_LcprepID = Other_LcprepID AND Other_LcprepDetailsIsActive = 'Y' + LEFT JOIN m_doctor ON Other_LcprepM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_LcprepT_orderDetailID = {$id} AND Other_LcprepIsActive = 'Y' + GROUP BY Other_LcprepDetailsOther_LcprepID, Other_LcprepDetailsCode + ORDER BY Other_LcprepDetailsCode ASC"; + //echo $sql; + $rows = $this->db_smartone->query($sql)->result_array(); + if(!$rows){ + $rows = array( + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'A', + 'label' => 'DESKRIPSI', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ), + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'B', + 'label' => 'KESIMPULAN', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ) + ); + } + + $header_id = $rows[0]['header_id']; + $sql = "SELECT IFNULL(Other_LcprepAdekuasiID,0) as xid, + Lcprep_AdekuasiID as id, + Lcprep_AdekuasiLabel as name, + IF(ISNULL(Other_LcprepAdekuasiID),'N',Other_LcprepAdekuasiChex) as chex + FROM lcprep_adekuasi + LEFT JOIN other_lcprepadekuasi ON Other_LcprepAdekuasiLcprep_AdekuasiID = Lcprep_AdekuasiID AND + Other_LcprepAdekuasiOther_LcprepID = {$header_id} AND + Other_LcprepAdekuasiIsActive = 'Y' + WHERE + Lcprep_AdekuasiIsActive = 'Y' + GROUP BY Lcprep_AdekuasiID + ORDER BY Lcprep_AdekuasiOrder ASC + "; + //echo $sql; + $adeakuasi = $this->db_smartone->query($sql)->result_array(); + foreach($adeakuasi as $kc => $vc){ + $adeakuasi[$kc]['chex'] = $vc['chex'] == 'N'?false:true; + } + + $sql = "SELECT IFNULL(Other_LcprepKategoriUmumID,0) as xid, + Lcprep_KategoriUmumID as id, + Lcprep_KategoriUmumLabel as name, + IF(ISNULL(Other_LcprepKategoriUmumID),'N',Other_LcprepKategoriUmumChex) as chex + FROM lcprep_kategoriumum + LEFT JOIN other_lcprepkategoriumum ON Other_LcprepKategoriUmumLcprep_KategoriUmumID = Lcprep_KategoriUmumID AND + Other_LcprepKategoriUmumOther_LcprepID = {$header_id} AND + Other_LcprepKategoriUmumIsActive = 'Y' + WHERE + Lcprep_KategoriUmumIsActive = 'Y' + GROUP BY Lcprep_KategoriUmumID + "; + //echo $sql; + $kategoriumum = $this->db_smartone->query($sql)->result_array(); + foreach($kategoriumum as $kc => $vc){ + $kategoriumum[$kc]['chex'] = $vc['chex'] == 'N'?false:true; + } + + $sql = " + SELECT Lcprep_InterpretasiGroupID as group_id, + Lcprep_InterpretasiGroupName as group_name, + '' as subgroups + FROM lcprep_interpretasigroup + WHERE + Lcprep_InterpretasiGroupIsActive = 'Y' + "; + //echo $sql; + $interpretasi = $this->db_smartone->query($sql)->result_array(); + foreach($interpretasi as $k => $v){ + $subgroups = array(); + $sql = "SELECT Lcprep_InterpretasiSubgroupID as subgroup_id, + Lcprep_InterpretasiSubgroupName as subgroup_name, + '' as childs + FROM lcprep_interpretasisubgroup + WHERE + Lcprep_InterpretasiSubgroupLcprep_InterpretasiGroupID = {$v['group_id']} AND Lcprep_InterpretasiSubgroupIsActive = 'Y'"; + //echo $sql; + $subgroups = $this->db_smartone->query($sql)->result_array(); + if(count($subgroups) > 0){ + foreach($subgroups as $ki => $vi){ + $childs = array(); + $sql = "SELECT IFNULL(Other_LcprepInterpretasiID,0) as xid, + IFNULL(Other_LcprepInterpretasiChex,'N') as chex, + IFNULL(Other_LcprepInterpretasiValue,'') as value, + Lcprep_InterpretasiID as id, + Lcprep_InterpretasiLcprep_InterpretasiSubgroupID as subgroup_id, + Lcprep_InterpretasiCode as code, + Lcprep_InterpretasiName as name, + Lcprep_InterpretasiParentID as parent_id, + Lcprep_InterpretasiIsParent as is_parent, + Lcprep_InterpretasiHasResult as has_result, + Lcprep_InterpretasiTypeResult as type_result + FROM lcprep_interpretasi + LEFT JOIN other_lcprepinterpretasi ON Other_LcprepInterpretasiOther_LcprepID = {$header_id} AND + Other_LcprepInterpretasiLcprep_InterpretasiID = Lcprep_InterpretasiID AND + Other_LcprepInterpretasiIsActive = 'Y' + WHERE + Lcprep_InterpretasiLcprep_InterpretasiSubgroupID = {$vi['subgroup_id']} AND Lcprep_InterpretasiIsActive = 'Y' + GROUP BY Lcprep_InterpretasiID Order BY Lcprep_InterpretasiCode ASC"; + $childs = $this->db_smartone->query($sql)->result_array(); + if($childs){ + foreach($childs as $kc => $vc){ + $childs[$kc]['chex'] = $vc['chex'] == 'N'?false:true; + } + } + $subgroups[$ki]['childs'] = $childs; + } + } + + $interpretasi[$k]['subgroups'] = $subgroups; + } + + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $rst = array('doctors'=>$doctors,'results'=>$rows,'adekuasi'=>$adeakuasi,'kategoriumum'=>$kategoriumum,'interpretasi'=>$interpretasi); + $this->sys_ok(["records"=>$rst]); + } + + function getpapsmearresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT Other_PapSmearDetailsID as xid, + Other_PapSmearID as header_id, + Other_PapSmearT_OrderDetailID as orderdetail_id, + Other_PapSmearDetailsCode as code, + Other_PapSmearDetailsLabel as label, + Other_PapSmearDetailsResult as result, + IFNULL(Other_PapSmearM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_PapSmearM_DoctorID) OR Other_PapSmearM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_papsmear + JOIN other_papsmeardetails ON Other_PapSmearDetailsOther_PapSmearID = Other_PapSmearID AND Other_PapSmearDetailsIsActive = 'Y' + LEFT JOIN m_doctor ON Other_PapSmearM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_PapSmearT_OrderDetailID = {$id} AND Other_PapSmearIsActive = 'Y' + GROUP BY Other_PapSmearDetailsID + ORDER BY Other_PapSmearDetailsCode ASC"; + //echo $sql; + $rows = $this->db_smartone->query($sql)->result_array(); + if(!$rows){ + $rows = array( + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'A', + 'label' => 'Makroskopik', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ), + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'B', + 'label' => 'Mikroskopik', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ), + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'C', + 'label' => 'Kesimpulan', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ) + ); + } + + $header_id = $rows[0]['header_id']; + $sql = "SELECT Other_PapSmearMaturasiID as xid, + Other_PapSmearMaturasiValue as value + FROM other_papsmearmaturasi + WHERE + Other_PapSmearMaturasiOther_PapSmearID = {$header_id} AND + Other_PapSmearMaturasiIsActive = 'Y' + "; + //echo $sql; + $dt_maturasi = $this->db_smartone->query($sql)->row_array(); + if(!$dt_maturasi){ + $maturasi = array('xid'=>'0','value'=> array('','','')); + } + else{ + $value = explode('/',$dt_maturasi['value']); + $maturasi = array('xid'=>$dt_maturasi['xid'],'value'=> $value); + } + + $sql = "SELECT IFNULL(Other_PapSmearBahanID,0) as xid, + M_PapSmearBahanID as bahan_id, + M_PapSmearBahanName as name, + IF(ISNULL(Other_PapSmearBahanID),'N','Y') as selected + FROM m_papsmearbahan + LEFT JOIN other_papsmearbahan ON Other_PapSmearBahanM_PapSmearBahanID = M_PapSmearBahanID AND + Other_PapSmearBahanOther_PapSmearID = {$header_id} AND + Other_PapSmearBahanIsActive = 'Y' + WHERE + M_PapSmearBahanIsActive = 'Y' + ORDER BY M_PapSmearBahanID ASC + "; + //echo $sql; + $bahans = $this->db_smartone->query($sql)->result_array(); + + $sql = "SELECT IFNULL(Other_PapsmearCategoryID,0) as xid, + M_PapSmearCategoryID as category_id, + M_PapSmearCategoryName as name, + IF(ISNULL(Other_PapsmearCategoryID),'N','Y') as selected + FROM m_papsmearcategory + LEFT JOIN other_papsmearcategory ON Other_PapsmearCategoryM_PapSmearCategoryID = M_PapSmearCategoryID AND + Other_PapsmearCategoryOther_PapSmearID = {$header_id} AND + Other_PapsmearCategoryIsActive = 'Y' + WHERE + M_PapSmearCategoryIsActive = 'Y' + ORDER BY M_PapSmearCategoryID ASC + "; + //echo $sql; + $categories = $this->db_smartone->query($sql)->result_array(); + + $sql = "SELECT IFNULL(Other_PapSmearCheckID,0) as xid, + M_PapSmearCheckID as check_id, + M_PapSmearCheckLabel as name, + IF(ISNULL(Other_PapSmearCheckID),'N','Y') as selected, + Other_PapSmearCheckNote as note + FROM m_papsmearcheck + LEFT JOIN other_papsmearcheck ON Other_PapSmearCheckM_PapSmearCheckID = M_PapSmearCheckID AND + Other_PapSmearCheckOther_PapSmearID = {$header_id} AND + Other_PapSmearCheckIsActive = 'Y' + WHERE + M_PapSmearCheckIsActive = 'Y' + ORDER BY M_PapSmearCheckCode ASC + "; + $checks = $this->db_smartone->query($sql)->result_array(); + + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $rst = array('doctors'=>$doctors,'checks'=>$checks,'bahans'=>$bahans,'categories'=>$categories,'maturasi'=>$maturasi,'results'=>$rows); + $this->sys_ok(["records"=>$rst]); + + } + + function saveresult_lcprep() + { + $prm = $this->sys_input; + $detail_id = $prm['detail_id']; + $doctor_id = $prm['doctor']; + $adekuasi = $prm['adekuasi']; + $kategoriumum = $prm['kategoriumum']; + $interpretasi = $prm['interpretasi']; + $results = $prm['results']; + + $userid = $this->sys_user['M_UserID']; + + $header_id = 0; + $sql = "SELECT * FROM other_lcprep WHERE Other_LcprepT_orderDetailID = {$detail_id} AND Other_LcprepIsActive = 'Y'"; + $dt_header = $this->db_smartone->query($sql)->row_array(); + if($dt_header){ + $header_id = $dt_header['Other_LcprepID']; + } + if($header_id == 0){ + $sql = "INSERT INTO other_lcprep( + Other_LcprepT_orderDetailID, + Other_LcprepM_DoctorID, + Other_LcprepUserID, + Other_LcprepCreated + ) + VALUES( + {$detail_id}, + {$doctor_id}, + {$userid}, + NOW() + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + }else{ + $sql = "UPDATE other_lcprep SET Other_LcprepM_DoctorID = {$doctor_id}, Other_LcprepUserID = {$userid} WHERE Other_LcprepID = {$header_id}"; + $this->db_smartone->query($sql); + } + + if($adekuasi){ + foreach($adekuasi as $k =>$v){ + $selected = $v['chex']?'Y':'N'; + if(intval($v['xid'] == 0)){ + $sql = "UPDATE other_lcprepadekuasi SET Other_LcprepAdekuasiIsActive = 'N' + WHERE + Other_LcprepAdekuasiOther_LcprepID = {$header_id} AND + Other_LcprepAdekuasiIsActive = 'Y' AND + Other_LcprepAdekuasiLcprep_AdekuasiID = {$v['id']}"; + $this->db_smartone->query($sql); + $sql = "INSERT INTO other_lcprepadekuasi ( + Other_LcprepAdekuasiOther_LcprepID, + Other_LcprepAdekuasiLcprep_AdekuasiID, + Other_LcprepAdekuasiChex, + Other_LcprepAdekuasiUserID, + Other_LcprepAdekuasiCreated + ) + VALUES( + {$header_id}, + {$v['id']}, + '{$selected}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + //echo $sql; + } + if(intval($v['xid'] != 0)){ + + $sql = "UPDATE other_lcprepadekuasi SET + Other_LcprepAdekuasiChex = '{$selected}', + Other_LcprepAdekuasiUserID = {$userid} + WHERE + Other_LcprepAdekuasiID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + + //echo $sql; + } + } + + if($kategoriumum){ + foreach($kategoriumum as $k =>$v){ + $selected = $v['chex']?'Y':'N'; + if(intval($v['xid'] == 0)){ + $sql = "UPDATE other_lcprepkategoriumum SET Other_LcprepKategoriUmumIsActive = 'N' + WHERE + Other_LcprepKategoriUmumOther_LcprepID = {$header_id} AND + Other_LcprepKategoriUmumLcprep_KategoriUmumID = {$v['id']} AND + Other_LcprepKategoriUmumIsActive = 'Y' + "; + $this->db_smartone->query($sql); + $sql = "INSERT INTO other_lcprepkategoriumum ( + Other_LcprepKategoriUmumOther_LcprepID, + Other_LcprepKategoriUmumLcprep_KategoriUmumID, + Other_LcprepKategoriUmumChex, + Other_LcprepKategoriUmumUserID, + Other_LcprepKategoriUmumCreated + ) + VALUES( + {$header_id}, + {$v['id']}, + '{$selected}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if(intval($v['xid'] != 0)){ + $sql = "UPDATE other_lcprepkategoriumum SET + Other_LcprepKategoriUmumChex = '{$selected }', + Other_LcprepKategoriUmumUserID = {$userid} + WHERE + Other_LcprepKategoriUmumID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + + //echo $sql; + } + } + + if($results){ + foreach($results as $k =>$v){ + if(intval($v['xid'] == 0)){ + $sql = "UPDATE other_lcprepdetails SET Other_LcprepDetailsIsActive = 'N' + WHERE + Other_LcprepDetailsOther_LcprepID = {$header_id} AND + Other_LcprepDetailsCode = '{$v['code']}' AND + Other_LcprepDetailsIsActive = 'Y'"; + $this->db_smartone->query($sql); + $sql = "INSERT INTO other_lcprepdetails ( + Other_LcprepDetailsOther_LcprepID, + Other_LcprepDetailsCode, + Other_LcprepDetailsLabel, + Other_LcprepDetailsResult, + Other_LcprepDetailsUserID, + Other_LcprepDetailsCreated + ) + VALUES( + {$header_id}, + '{$v['code']}', + '{$v['label']}', + '{$v['result']}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if(intval($v['xid'] != 0)){ + $sql = "UPDATE other_lcprepdetails SET + Other_LcprepDetailsCode = '{$v['code']}', + Other_LcprepDetailsLabel = '{$v['label']}', + Other_LcprepDetailsResult = '{$v['result']}', + Other_LcprepDetailsUserID = {$userid} + WHERE + Other_LcprepDetailsID = {$v['xid']}"; + $this->db_smartone->query($sql); + + } + //echo $sql; + } + } + + if($interpretasi){ + foreach($interpretasi as $k =>$v){ + if(count($v['subgroups']) > 0){ + foreach($v['subgroups'] as $ik => $iv){ + if(count($iv['childs']) > 0){ + foreach($iv['childs'] as $iik => $iiv){ + if(intval($iiv['xid'] == 0)){ + $chex = $iiv['chex'] ? 'Y':'N'; + $sql = "UPDATE other_lcprepinterpretasi SET Other_LcprepInterpretasiIsActive = 'N' + WHERE + Other_LcprepInterpretasiOther_LcprepID = {$header_id} AND + Other_LcprepInterpretasiLcprep_InterpretasiID = '{$iiv['id']}' AND + Other_LcprepInterpretasiIsActive = 'Y'"; + $this->db_smartone->query($sql); + $sql = "INSERT INTO other_lcprepinterpretasi ( + Other_LcprepInterpretasiOther_LcprepID, + Other_LcprepInterpretasiLcprep_InterpretasiID, + Other_LcprepInterpretasiChex, + Other_LcprepInterpretasiValue, + Other_LcprepInterpretasiUserID, + Other_LcprepInterpretasiCreated + ) + VALUES( + {$header_id}, + '{$iiv['id']}', + '{$chex}', + '{$iiv['value']}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + + if(intval($iiv['xid'] != 0)){ + $chex = $iiv['chex'] ? 'Y':'N'; + $sql = "UPDATE other_lcprepinterpretasi SET + Other_LcprepInterpretasiChex = '{$chex}', + Other_LcprepInterpretasiValue = '{$iiv['value']}', + Other_LcprepInterpretasiUserID = {$userid} + WHERE + Other_LcprepInterpretasiID = {$iiv['xid']}"; + $this->db_smartone->query($sql); + //echo $sql; + + } + + } + } + } + } + //echo $sql; + } + } + + + $result = array("total" => 1, "records" => array(), "sql"=> ''); + $this->sys_ok($result); + exit; + } + + function saveresult_papsmear() + { + $prm = $this->sys_input; + $detail_id = $prm['detail_id']; + $doctor_id = $prm['doctor']; + $checks = $prm['checks']; + $maturasi = $prm['maturasi']; + $bahans = $prm['bahans']; + $categories = $prm['categories']; + $results = $prm['results']; + + $userid = $this->sys_user['M_UserID']; + + $header_id = 0; + $sql = "SELECT * FROM other_papsmear WHERE Other_PapSmearT_OrderDetailID = {$detail_id} AND Other_PapSmearIsActive = 'Y'"; + $dt_header = $this->db_smartone->query($sql)->row_array(); + if($dt_header){ + $header_id = $dt_header['Other_PapSmearID']; + } + if($header_id == 0){ + $sql = "INSERT INTO other_papsmear( + Other_PapSmearT_OrderDetailID, + Other_PapSmearM_DoctorID, + Other_PapSmearUserID, + Other_PapSmearCreated + ) + VALUES( + {$detail_id}, + {$doctor_id}, + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } + else{ + $sql = "UPDATE other_papsmear SET Other_PapSmearM_DoctorID = {$doctor_id}, Other_PapSmearUserID = {$userid} WHERE Other_PapSmearID = {$header_id}"; + $this->db_smartone->query($sql); + } + + if($checks){ + foreach($checks as $k =>$v){ + if(intval($v['xid']) == 0 && $v['selected'] === 'Y'){ + $sql = "INSERT INTO other_papsmearcheck ( + Other_PapSmearCheckOther_PapSmearID, + Other_PapSmearCheckM_PapSmearCheckID, + Other_PapSmearCheckNote, + Other_PapSmearCheckUserID, + Other_PapSmearCheckCreated + ) + VALUES( + {$header_id}, + {$v['check_id']}, + '{$v['note']}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if(intval($v['xid']) != 0 && $v['selected'] === 'N'){ + $sql = "UPDATE other_papsmearcheck SET + Other_PapSmearCheckIsActive = 'N', + Other_PapSmearCheckUserID = {$userid} + WHERE + Other_PapSmearCheckID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + if(intval($v['xid']) != 0 && $v['selected'] === 'Y'){ + $sql = "UPDATE other_papsmearcheck SET + Other_PapSmearCheckNote = '{$v['note']}', + Other_PapSmearCheckUserID = {$userid} + WHERE + Other_PapSmearCheckID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + //echo $sql; + } + } + + if($maturasi){ + if(intval($maturasi['xid']) == 0){ + $value = join("/",$maturasi['value']); + $sql = "INSERT INTO other_papsmearmaturasi ( + Other_PapSmearMaturasiOther_PapSmearID, + Other_PapSmearMaturasiValue, + Other_PapSmearMaturasiUserID, + Other_PapSmearMaturasiCreated + ) + VALUE( + {$header_id}, + '{$value}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + //echo $sql; + } + if(intval($maturasi['xid']) != 0){ + $value = join("/",$maturasi['value']); + $sql = "UPDATE other_papsmearmaturasi SET + Other_PapSmearMaturasiValue = '{$value}', + Other_PapSmearMaturasiUserID = {$userid} + WHERE + Other_PapSmearMaturasiID = {$maturasi['xid']}"; + // echo $sql; + $this->db_smartone->query($sql); + } + } + + if($bahans){ + foreach($bahans as $k =>$v){ + if(intval($v['xid']) == 0 && $v['selected'] === 'Y'){ + $sql = "INSERT INTO other_papsmearbahan ( + Other_PapSmearBahanOther_PapSmearID, + Other_PapSmearBahanM_PapSmearBahanID, + Other_PapSmearBahanUserID, + Other_PapSmearBahanCreated + ) + VALUES( + {$header_id}, + {$v['bahan_id']}, + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if(intval($v['xid']) != 0 && $v['selected'] === 'N'){ + $sql = "UPDATE other_papsmearbahan SET + Other_PapSmearBahanIsActive = 'N', + Other_PapsmearCategoryUserID = {$userid} + WHERE + Other_PapSmearBahanID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + if(intval($v['xid']) != 0 && $v['selected'] === 'Y'){ + $sql = "UPDATE other_papsmearbahan SET + Other_PapSmearBahanIsActive = 'Y', + Other_PapsmearCategoryUserID = {$userid} + WHERE + Other_PapSmearBahanID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + //echo $sql; + } + } + + if($categories){ + foreach($categories as $k =>$v){ + if(intval($v['xid']) == 0 && $v['selected'] === 'Y'){ + $sql = "INSERT INTO other_papsmearcategory ( + Other_PapsmearCategoryOther_PapSmearID, + Other_PapsmearCategoryM_PapSmearCategoryID, + Other_PapsmearCategoryUserID, + Other_PapsmearCategoryCreated + ) + VALUES( + {$header_id}, + {$v['category_id']}, + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if(intval($v['xid']) != 0 && $v['selected'] === 'N'){ + $sql = "UPDATE other_papsmearcategory SET + Other_PapsmearCategoryIsActive = 'N', + Other_PapsmearCategoryUserID = {$userid} + WHERE + Other_PapsmearCategoryID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + //echo $sql; + if(intval($v['xid']) != 0 && $v['selected'] === 'Y'){ + $sql = "UPDATE other_papsmearcategory SET + Other_PapsmearCategoryIsActive = 'Y', + Other_PapsmearCategoryUserID = {$userid} + WHERE + Other_PapsmearCategoryID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + } + } + + if($results){ + foreach($results as $k =>$v){ + if(intval($v['xid']) == 0){ + $sql = "INSERT INTO other_papsmeardetails ( + Other_PapSmearDetailsOther_PapSmearID, + Other_PapSmearDetailsCode, + Other_PapSmearDetailsLabel, + Other_PapSmearDetailsResult, + Other_PapSmearDetailsUserID, + Other_PapSmearDetailsCreated + ) + VALUES( + {$header_id}, + '{$v['code']}', + '{$v['label']}', + '{$v['result']}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if(intval($v['xid']) != 0){ + $sql = "UPDATE other_papsmeardetails SET + Other_PapSmearDetailsCode = '{$v['code']}', + Other_PapSmearDetailsLabel = '{$v['label']}', + Other_PapSmearDetailsResult = '{$v['result']}', + Other_PapSmearDetailsUserID = {$userid} + WHERE + Other_PapSmearDetailsID = {$v['xid']}"; + $this->db_smartone->query($sql); + + } + //echo $sql; + } + } + + $result = array("total" => 1, "records" => array(), "sql"=> ''); + $this->sys_ok($result); + exit; + } + + function saveresult_fna() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = $inp['doctor']; + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + if($prm[0]['xid'] == '0'){ + $sql = "INSERT INTO other_fna( + Other_FNAM_DoctorID, + Other_FNAT_OrderDetailID, + Other_FNAUserID, + Other_FNACreated + ) + VALUES( + {$doctor_id}, + {$prm[0]['orderdetail_id']}, + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } + else{ + $sql = "SELECT * FROM other_fna WHERE Other_FNAT_OrderDetailID = {$prm[0]['orderdetail_id']} AND Other_FNAIsActive = 'Y'"; + $data_header = $this->db_smartone->query($sql)->row_array(); + $header_id = $data_header['Other_FNAID']; + $sql = "UPDATE other_fna SET + Other_FNAM_DoctorID = {$doctor_id}, + Other_FNAUserID = {$userid} + WHERE + Other_FNAID = {$header_id}"; + $this->db_smartone->query($sql); + } + foreach($prm as $k => $v){ + if($v['xid'] == '0'){ + $results = str_replace("'", "\\'", $v['result']); + $sql = "INSERT INTO other_fnadetails( + Other_FNADetailsOther_FNAID , + Other_FNADetailsCode, + Other_FNADetailsLabel, + Other_FNADetailsResult, + Other_FNADetailsCreated, + Other_FNADetailsUserID + ) + VALUES( + {$header_id}, + '{$v['code']}', + '{$v['label']}', + '{$results}', + NOW(), + {$userid} + )"; + $query = $this->db_smartone->query($sql); + } + else{ + $results = str_replace("'", "\\'", $v['result']); + $sql = "UPDATE other_fnadetails SET + Other_FNADetailsResult = '{$results}', + Other_FNADetailsUserID = {$userid} + WHERE + Other_FNADetailsID = {$v['xid']}"; + $query = $this->db_smartone->query($sql); + } + } + + $result = array("total" => 1, "records" => array(), "sql"=> ''); + $this->sys_ok($result); + exit; + } + + function saveresult_cytologi() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = $inp['doctor']; + + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + if($prm[0]['xid'] == '0'){ + $sql = "INSERT INTO other_cytologi( + Other_CytologiT_OrderDetailID, + Other_CytologiM_DoctorID, + Other_CytologiUserID, + Other_CytologiCreated + ) + VALUES( + {$prm[0]['orderdetail_id']}, + {$doctor_id}, + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } + else{ + $sql = "SELECT * FROM other_cytologi WHERE Other_CytologiT_OrderDetailID = {$prm[0]['orderdetail_id']} AND Other_CytologiIsActive = 'Y'"; + $data_header = $this->db_smartone->query($sql)->row_array(); + $header_id = $data_header['Other_CytologiID']; + $sql = "UPDATE other_cytologi SET + Other_CytologiM_DoctorID = {$doctor_id}, + Other_CytologiUserID = {$userid} + WHERE + Other_CytologiID = {$header_id}"; + $this->db_smartone->query($sql); + } + foreach($prm as $k => $v){ + if($v['xid'] == '0'){ + $results = str_replace("'", "\\'", $v['result']); + $sql = "INSERT INTO other_cytologidetails( + Other_CytologiDetailsOther_CytologiID , + Other_CytologiDetailsCode, + Other_CytologiDetailsLabel, + Other_CytologiDetailsResult, + Other_CytologiDetailsCreated, + Other_CytologiDetailsUserID + ) + VALUES( + {$header_id}, + '{$v['code']}', + '{$v['label']}', + '{$results}', + NOW(), + {$userid} + )"; + $query = $this->db_smartone->query($sql); + } + else{ + $results = str_replace("'", "\\'", $v['result']); + $sql = "UPDATE other_cytologidetails SET + Other_CytologiDetailsResult = '{$results}', + Other_CytologiDetailsUserID = {$userid} + WHERE + Other_CytologiDetailsID = {$v['xid']}"; + $query = $this->db_smartone->query($sql); + } + } + + $result = array("total" => 1, "records" => array(), "sql"=> ''); + $this->sys_ok($result); + exit; + } + + function saveresult_mikro() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = $inp['doctor']; + $backteria_id = $inp['bacteria']; + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + + if($inp['result_value'] != 'Negatif' && $inp['result_value'] != 'Positif'){ + $prm['result_value'] = $prm['result_other']; + } + else{ + $prm['result_value'] = $inp['result_value']; + } + + if($prm['xid'] == '0'){ + $sql = "INSERT INTO other_mikro( + Other_MikroM_DoctorID, + Other_MikroResult, + Other_MikroT_BacteriaID, + Other_MikroT_OrderDetailID, + Other_MikroHasilBiakan, + Other_MikroSampleTypeName, + Other_MikroUserID, + Other_MikroCreated + ) + VALUES( + {$doctor_id}, + '{$prm['result_value']}', + {$backteria_id}, + {$prm['orderdetail_id']}, + '{$prm['hasil_biakan']}', + '{$prm['sample_name']}', + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } + else{ + $sql = "SELECT * FROM other_mikro WHERE Other_MikroT_OrderDetailID = {$prm['orderdetail_id']} AND Other_MikroIsActive = 'Y'"; + $data_header = $this->db_smartone->query($sql)->row_array(); + $header_id = $data_header['Other_MikroID']; + $sql = "UPDATE other_mikro SET + Other_MikroResult = '{$prm['result_value']}', + Other_MikroM_DoctorID = {$doctor_id}, + Other_MikroT_BacteriaID = {$backteria_id}, + Other_MikroHasilBiakan = '{$prm['hasil_biakan']}', + Other_MikroSampleTypeName = '{$prm['sample_name']}', + Other_MikroUserID = {$userid} + WHERE + Other_MikroID = {$header_id}"; + //echo $sql; + $this->db_smartone->query($sql); + } + + + + $sql = "UPDATE other_mikrodetails SET Other_MikroDetailsIsActive = 'N', Other_MikroDetailsUserID = 0 WHERE Other_MikroDetailsOther_MikroID = {$header_id}"; + $this->db_smartone->query($sql); + + $results = $prm['details']; + if($inp['result_value'] == 'Positif'){ + foreach($results as $k => $v){ + if($v['xid'] == '0'){ + $sql = "INSERT INTO other_mikrodetails( + Other_MikroDetailsOther_MikroID , + Other_MikroDetailsT_AntibioticID, + Other_MikroDetailsValue, + Other_MikroDetailsNote, + Other_MikroDetailsCreated, + Other_MikroDetailsUserID + ) + VALUES( + {$header_id}, + '{$v['T_AntibioticID']}', + '{$v['value']}', + '{$v['note']}', + NOW(), + {$userid} + )"; + $query = $this->db_smartone->query($sql); + } + else{ + $sql = "UPDATE other_mikrodetails SET + Other_MikroDetailsT_AntibioticID = '{$v['T_AntibioticID']}', + Other_MikroDetailsValue = '{$v['value']}', + Other_MikroDetailsNote = '{$v['note']}', + Other_MikroDetailsIsActive = 'Y', + Other_MikroDetailsUserID = {$userid} + WHERE + Other_MikroDetailsID = {$v['xid']}"; + //echo $sql; + $query = $this->db_smartone->query($sql); + } + } + } + + + $result = array("total" => 1, "records" => array(), "sql"=> ''); + $this->sys_ok($result); + exit; + } + + + function get_doctors_preparasi_sperma() + { + $prm = $this->sys_input; + // $id = $prm["id"]; + + $sql = " SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 10 AND + M_DoctorSOIsActive = 'Y' + ORDER BY M_DoctorName ASC"; + //echo $sql; + $query = $this->db_smartone->query($sql); + $rows = $query->result_array(); + $sql = " + SELECT '0' as id, 'Belum memilih metode' as name + UNION + SELECT M_MethodeSpermaID as id, M_MethodeSpermaName as name + FROM m_methodesperma + WHERE + M_MethodeSpermaIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $methodes = $this->db_smartone->query($sql)->result_array(); + + + $this->sys_ok(["records"=>$rows,"methodes"=>$methodes]); + + } + + + function getpreparasispermaresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT other_preparasisperma.*, + Other_PreparasiSpermaID as xid, + Other_PreparasiSpermaT_OrderDetailID as orderdetail_id, + IFNULL(Other_PreparasiSpermaM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_PreparasiSpermaM_DoctorID) OR Other_PreparasiSpermaM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name, + IFNULL(M_MethodeSpermaID,0) as methode_id, + IFNULL(M_MethodeSpermaName,'') as methode_name + FROM other_preparasisperma + LEFT JOIN m_doctor ON Other_PreparasiSpermaM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + LEFT JOIN m_methodesperma ON Other_PreparasiSpermaM_MethodeSpermaID = M_MethodeSpermaID AND + M_MethodeSpermaIsActive = 'Y' + WHERE + Other_PreparasiSpermaT_OrderDetailID = {$id} AND Other_PreparasiSpermaIsActive = 'Y' + GROUP BY Other_PreparasiSpermaID"; + $query = $this->db_smartone->query($sql); + + if ($query) + { + $rows = $query->row_array(); + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 10 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $sql = " + SELECT '0' as id, 'Belum memilih metode' as name + UNION + SELECT M_MethodeSpermaID as id, M_MethodeSpermaName as name + FROM m_methodesperma + WHERE + M_MethodeSpermaIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $methodes = $this->db_smartone->query($sql)->result_array(); + $images = array(); + $sql = "SELECT Other_PreparasiSpermaImgID as xid, + Other_PreparasiSpermaImgType as type, + CONCAT('/one-media/one-image-nonlab/',Other_PreparasiSpermaImgNewName) as image_url + FROM t_orderdetail + JOIN other_preparasisperma_img ON Other_PreparasiSpermaImgT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND + Other_PreparasiSpermaImgIsActive = 'Y' + WHERE + T_OrderDetailID = {$id} AND + T_OrderDetailIsActive = 'Y' + GROUP BY Other_PreparasiSpermaImgID"; + //echo $sql; + $images = $this->db_smartone->query($sql)->result_array(); + + $rst = array('doctors'=>$doctors,'methodes'=>$methodes,'results'=>$rows,'images'=>$images); + $this->sys_ok(["records"=>$rst]); + } + else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + + function uploadimage_preparasi_sperma(){ + if (! $this->isLogin) { + $this->sys_error("Invalid Token"); + exit; + } + + $userid = $this->sys_user["M_UserID"]; + $data = []; + //print_r($_SERVER); + + $prm = $this->sys_input; + $orderid = $this->input->post('orderid'); + $type = $this->input->post('type'); + $labnumber = $this->input->post('labnumber'); + $sql = "UPDATE other_preparasisperma_img SET + Other_PreparasiSpermaImgIsActive = 'N', + Other_PreparasiSpermaImgUserID = {$userid} + WHERE + Other_PreparasiSpermaImgT_OrderHeaderID = {$orderid} AND + Other_PreparasiSpermaImgType = '{$type}'"; + //echo $sql; + $this->db_onedev->query($sql); + //$config['upload_path'] = 'assets/'; + + $path = '/home/one/project/one/one-media/one-image-nonlab/'; + //echo $path; + $config['upload_path'] = $path; + $config['allowed_types'] = 'jpg|jpeg|png|gif'; + + $config['max_size'] = '10000'; + $count = count($_FILES['files']['name']); + //echo $count; + $this->load->library('upload',$config); + + $error = []; + for($i=0;$i<$count;$i++){ + + + if(!empty($_FILES['files']['name'][$i])){ + + + + $_FILES['file']['name'] = $_FILES['files']['name'][$i]; + + $_FILES['file']['type'] = $_FILES['files']['type'][$i]; + + $_FILES['file']['tmp_name'] = $_FILES['files']['tmp_name'][$i]; + + $_FILES['file']['error'] = $_FILES['files']['error'][$i]; + + $_FILES['file']['size'] = $_FILES['files']['size'][$i]; + + + + $namex = $orderid.'-'.$labnumber.'-'.$this->generateRandomString(5); + //echo $namex; + + $config['file_name'] = $namex; + $this->upload->initialize($config); + //echo $config['file_name'] ; + + + + + + if($this->upload->do_upload('file')){ + + $uploadData = $this->upload->data(); + + $filename = $uploadData['file_name']; + //echo $filename; + + + $sql = "INSERT INTO other_preparasisperma_img ( + Other_PreparasiSpermaImgT_OrderHeaderID, + Other_PreparasiSpermaImgType, + Other_PreparasiSpermaImgOldName, + Other_PreparasiSpermaImgNewName, + Other_PreparasiSpermaImgCreated, + Other_PreparasiSpermaImgUserID + ) + VALUES( + {$orderid}, + '{$type}', + '{$_FILES['files']['name'][$i]}', + '{$filename}', + NOW(), + {$userid} + + )"; + //echo $sql; + $this->db_onedev->query($sql); + $xlast_id = $this->db_onedev->insert_id(); + $data['totalFiles'][] = array('xid' => $xlast_id ,'type'=>$type,'image_url' => '/one-media/one-image-nonlab/'.$filename); + + } + else{ + $error = array('error' => $this->upload->display_errors()); + } + + } + + + + } + + $result = array("total" =>count( $data['totalFiles']), "records" => $data['totalFiles'],'errors'=>$error); + $this->sys_ok($result); + } + + + function saveresult_preparasi_sperma() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = $inp['doctor']; + $orderdetail_id = $inp['orderdetailid']; + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + if($prm['xid'] == '0'){ + $sql = "INSERT INTO other_preparasisperma( + Other_PreparasiSpermaM_DoctorID, + Other_PreparasiSpermaT_OrderDetailID, + Other_PreparasiSpermaPreMotilitasA, + Other_PreparasiSpermaPreMotilitasB, + Other_PreparasiSpermaPreMotilitasC, + Other_PreparasiSpermaPreKonsentrasi, + Other_PreparasiSpermaPreKontaminan, + Other_PreparasiSpermaPostMotilitasA, + Other_PreparasiSpermaPostMotilitasB, + Other_PreparasiSpermaPostMotilitasC, + Other_PreparasiSpermaPostKonsentrasi, + Other_PreparasiSpermaPostKontaminan, + Other_PreparasiSpermaPreVolume, + Other_PreparasiSpermaPostVolume, + Other_PreparasiSpermaM_MethodeSpermaID, + Other_PreparasiSpermaNote, + Other_PreparasiSpermaUserID, + Other_PreparasiSpermaCreated + ) + VALUES( + {$doctor_id}, + {$orderdetail_id}, + '{$prm['Other_PreparasiSpermaPreMotilitasA']}', + '{$prm['Other_PreparasiSpermaPreMotilitasB']}', + '{$prm['Other_PreparasiSpermaPreMotilitasC']}', + '{$prm['Other_PreparasiSpermaPreKonsentrasi']}', + '{$prm['Other_PreparasiSpermaPreKontaminan']}', + '{$prm['Other_PreparasiSpermaPostMotilitasA']}', + '{$prm['Other_PreparasiSpermaPostMotilitasB']}', + '{$prm['Other_PreparasiSpermaPostMotilitasC']}', + '{$prm['Other_PreparasiSpermaPostKonsentrasi']}', + '{$prm['Other_PreparasiSpermaPostKontaminan']}', + '{$prm['Other_PreparasiSpermaPreVolume']}', + '{$prm['Other_PreparasiSpermaPostVolume']}', + '{$prm['Other_PreparasiSpermaM_MethodeSpermaID']}', + '{$prm['Other_PreparasiSpermaNote']}', + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } + else{ + $sql = "SELECT * FROM other_preparasisperma WHERE Other_PreparasiSpermaT_OrderDetailID = {$orderdetail_id} AND Other_PreparasiSpermaIsActive = 'Y'"; + $data_header = $this->db_smartone->query($sql)->row_array(); + $header_id = $data_header['Other_PreparasiSpermaID']; + $sql = "UPDATE other_preparasisperma SET + Other_PreparasiSpermaM_DoctorID = {$doctor_id}, + Other_PreparasiSpermaPreMotilitasA = '{$prm['Other_PreparasiSpermaPreMotilitasA']}', + Other_PreparasiSpermaPreMotilitasB = '{$prm['Other_PreparasiSpermaPreMotilitasB']}', + Other_PreparasiSpermaPreMotilitasC = '{$prm['Other_PreparasiSpermaPreMotilitasC']}', + Other_PreparasiSpermaPreKonsentrasi = '{$prm['Other_PreparasiSpermaPreKonsentrasi']}', + Other_PreparasiSpermaPreKontaminan = '{$prm['Other_PreparasiSpermaPreKontaminan']}', + Other_PreparasiSpermaPostMotilitasA = '{$prm['Other_PreparasiSpermaPostMotilitasA']}', + Other_PreparasiSpermaPostMotilitasB = '{$prm['Other_PreparasiSpermaPostMotilitasB']}', + Other_PreparasiSpermaPostMotilitasC = '{$prm['Other_PreparasiSpermaPostMotilitasC']}', + Other_PreparasiSpermaPostKonsentrasi = '{$prm['Other_PreparasiSpermaPostKonsentrasi']}', + Other_PreparasiSpermaPostKontaminan = '{$prm['Other_PreparasiSpermaPostKontaminan']}', + Other_PreparasiSpermaPreVolume = '{$prm['Other_PreparasiSpermaPreVolume']}', + Other_PreparasiSpermaPostVolume = '{$prm['Other_PreparasiSpermaPostVolume']}', + Other_PreparasiSpermaM_MethodeSpermaID = '{$prm['Other_PreparasiSpermaM_MethodeSpermaID']}', + Other_PreparasiSpermaNote = '{$prm['Other_PreparasiSpermaNote']}', + Other_PreparasiSpermaUserID = {$userid} + WHERE + Other_PreparasiSpermaID = {$header_id}"; + $this->db_smartone->query($sql); + } + + + $result = array("total" => 1, "records" => array(), "sql"=> ''); + $this->sys_ok($result); + exit; + } + + function getdnafragmentasiresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT other_dnafragmentasi.*, + Other_DnaFragmentasiID as xid, + Other_DnaFragmentasiT_OrderDetailID as orderdetail_id, + IFNULL(Other_DnaFragmentasiM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_DnaFragmentasiM_DoctorID) OR Other_DnaFragmentasiM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name, + IFNULL(Other_DnaFragmentasiOther_DnaFragmentasiMethodeID,0) as methode_id, + IFNULL(Other_DnaFragmentasiMethodeName,'') as methode_name, + Other_DnaFragmentasiHaloLuas as halo_luas, + Other_DnaFragmentasiHaloSedang as halo_sedang, + Other_DnaFragmentasiHaloSempit as halo_sempit, + Other_DnaFragmentasiTanpaHalo as tanpa_halo, + Other_DnaFragmentasiDFI as dfi, + Other_DnaFragmentasiKesimpulan as kesimpulan, + Other_DnaFragmentasiCatatan as catatan + FROM other_dnafragmentasi + LEFT JOIN m_doctor ON Other_DnaFragmentasiM_DoctorID = M_DoctorID + LEFT JOIN other_dnafragmentasimethode ON Other_DnaFragmentasiOther_DnaFragmentasiMethodeID = Other_DnaFragmentasiMethodeID + WHERE + Other_DnaFragmentasiT_OrderDetailID = {$id} AND Other_DnaFragmentasiIsActive = 'Y' + GROUP BY Other_DnaFragmentasiID + LIMIT 1"; + //echo $sql; + $query = $this->db_smartone->query($sql); + + if ($query) + { + $rows = $query->row_array(); + if(!$rows){ + $rows = array( + 'xid' => 0, + 'orderdetail_id' =>$id, + 'doctor_id' => 0, + 'doctor_name' => '', + 'methode_id' => 0, + 'methode_name' => '', + 'halo_luas' => '', + 'halo_sedang' => '', + 'tanpa_halo' => '', + 'dfi' => '', + 'kesimpulan' => '', + 'catatan' => '' + ); + } + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID + WHERE + M_DoctorSONat_SubGroupID = 4 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + + $sql = " + SELECT '0' as id, 'Belum memilih metode' as name + UNION + SELECT Other_DnaFragmentasiMethodeID as id, Other_DnaFragmentasiMethodeName as name + FROM other_dnafragmentasimethode + WHERE + Other_DnaFragmentasiMethodeIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $methodes = $this->db_smartone->query($sql)->result_array(); + + + $rst = array('doctors'=>$doctors,'methodes'=>$methodes,'results'=>$rows); + $this->sys_ok(["records"=>$rst]); + } + else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + function saveresult_dnafragmentasi() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = $inp['doctor']['id']; + $methode_id = $inp['methode']['id']; + $orderdetail_id = $inp['results']['orderdetail_id']; + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + if(intval($prm['xid']) == 0){ + $sql = "INSERT INTO other_dnafragmentasi( + Other_DnaFragmentasiT_OrderDetailID, + Other_DnaFragmentasiM_DoctorID, + Other_DnaFragmentasiOther_DnaFragmentasiMethodeID, + Other_DnaFragmentasiHaloLuas, + Other_DnaFragmentasiHaloSedang, + Other_DnaFragmentasiHaloSempit, + Other_DnaFragmentasiTanpaHalo, + Other_DnaFragmentasiDFI, + Other_DnaFragmentasiKesimpulan, + Other_DnaFragmentasiCatatan, + Other_DnaFragmentasiUserID, + Other_DnaFragmentasiLastUpdated + ) + VALUES( + {$orderdetail_id}, + {$doctor_id}, + {$methode_id}, + '{$prm['halo_luas']}', + '{$prm['halo_sedang']}', + '{$prm['halo_sempit']}', + '{$prm['tanpa_halo']}', + '{$prm['dfi']}', + '{$prm['kesimpulan']}', + '{$prm['catatan']}', + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } + else{ + $sql = "UPDATE other_dnafragmentasi SET + Other_DnaFragmentasiT_OrderDetailID = {$orderdetail_id}, + Other_DnaFragmentasiM_DoctorID = {$doctor_id}, + Other_DnaFragmentasiOther_DnaFragmentasiMethodeID = '{$methode_id}', + Other_DnaFragmentasiHaloLuas = '{$prm['halo_luas']}', + Other_DnaFragmentasiHaloSedang = '{$prm['halo_sedang']}', + Other_DnaFragmentasiHaloSempit = '{$prm['halo_sempit']}', + Other_DnaFragmentasiTanpaHalo = '{$prm['tanpa_halo']}', + Other_DnaFragmentasiDFI = '{$prm['dfi']}', + Other_DnaFragmentasiKesimpulan = '{$prm['kesimpulan']}', + Other_DnaFragmentasiCatatan = '{$prm['catatan']}', + Other_DnaFragmentasiLastUpdated = NOW(), + Other_DnaFragmentasiUserID = {$userid} + WHERE + Other_DnaFragmentasiID = {$prm['xid']}"; + //echo $sql; + $this->db_smartone->query($sql); + } + + + $result = array("total" => 1, "records" => array(), "sql"=> ''); + $this->sys_ok($result); + exit; + } + + +} + diff --git a/application/controllers/mockup/process/resultverification-v22/Re_px.php b/application/controllers/mockup/process/resultverification-v22/Re_px.php index cc0624f9..4cfb2c5d 100644 --- a/application/controllers/mockup/process/resultverification-v22/Re_px.php +++ b/application/controllers/mockup/process/resultverification-v22/Re_px.php @@ -1,2548 +1,2545 @@ -db_smartone = $this->load->database("onedev", true); - $this->load->helper(array('form', 'url')); - } - function getMethodeID($natTestID) { - $sql = "select M_MethodePriorityNat_MethodeID MethodeID, Nat_MethodeName - from - m_methode_priority - join nat_methode on Nat_MethodeID = M_MethodePriorityNat_MethodeID - and Nat_MethodeIsActive = 'Y' - join m_instrumentmethode on M_InstrumentMethodeNat_MethodeID = Nat_MethodeID and M_InstrumentMethodeIsActive = 'Y' - join nat_instrument on M_InstrumentMethodeNat_InstrumentID = Nat_InstrumentID - and Nat_InstrumentIsActive ='Y' - where M_MethodePriorityIsActive = 'Y' - and M_MethodePriorityNat_TestID = $natTestID - and M_MethodePriorityM_DayOfWeekID = dayofweek(now()) - order by M_MethodePriorityNumber desc - limit 0,1 "; - $qry = $this->db->query($sql); - if ($qry) { - $rows = $qry->result_array(); - if (count($rows) > 0 ) return array($rows[0]["MethodeID"],$rows[0]["Nat_MethodeName"]); - } - //2nd - $sql= "select - M_InstrumentMethodeNat_MethodeID MethodeID, Nat_MethodeName - from m_instrumentmethode - join nat_methode on M_InstrumentMethodeNat_MethodeID = Nat_MethodeID - and Nat_MethodeIsActive = 'Y' - join nat_instrument on M_InstrumentMethodeNat_InstrumentID = Nat_InstrumentID - and Nat_InstrumentIsActive ='Y' - where M_InstrumentMethodeNat_TestID = $natTestID - and M_InstrumentMethodeIsActive = 'Y' - order by M_InstrumentMethodePriority desc - limit 0,1"; - $qry = $this->db->query($sql); - if ($qry) { - $rows = $qry->result_array(); - if (count($rows) > 0 ) return array($rows[0]["MethodeID"],$rows[0]["Nat_MethodeName"]); - } - // - $sql = "select Nat_NormalValueNat_MethodeID MethodeID, Nat_MethodeName - from - nat_normalvalue - join nat_methode on Nat_NormalValueNat_MethodeID = Nat_MethodeID - and Nat_MethodeIsActive = 'Y' - where Nat_NormalValueNat_TestID = $natTestID - and Nat_NormalValueIsActive = 'Y' - order by Nat_NormalValueID - limit 0,1"; - $qry = $this->db->query($sql); - if ($qry) { - $rows = $qry->result_array(); - if (count($rows) > 0 ) return array($rows[0]["MethodeID"],$rows[0]["Nat_MethodeName"]); - } - return array(0,""); - } - function get_normal_value($methodeID, $natTestID, $sexID, $ageInDay ) { - $sql = "select fn_sampling_get_normal($methodeID, $natTestID, $sexID, $ageInDay) as normalValueID"; - $qry = $this->db->query($sql); - if ($qry) { - $rows = $qry->result_array(); - if (count($rows) > 0 ) return $rows[0]["normalValueID"]; - } - return 0; - } - function fn_fix_normal($order_id) { - $sql = "select - T_OrderDetailID, M_PatientM_SexID, fn_global_age_count_day(M_PatientDOB, date(T_OrderHeaderDate)) Dob , - T_TestNat_TestID - from t_orderheader - join m_patient on T_OrderHeaderID = $order_id and T_OrderHeaderM_PatientID = M_PatientID - join t_orderdetail on T_OrderDetailT_OrderHeaderID = T_OrderHeaderID - and T_OrderDetailIsACtive = 'Y' - and ( T_OrderDetailNat_NormalValueID is null or T_OrderDetailNat_NormalValueID = 0 ) - join t_test on T_OrderDetailT_TestID = T_TestID and T_TestIsResult = 'Y' "; - $qry = $this->db->query($sql); - if(! $qry) { - return; - } - $rows = $qry->result_array(); - if(count($rows) == 0 ) return; - $sql_u = "update t_orderdetail - join nat_normalvalue on T_OrderDetailID = ? and Nat_NormalValueID = ? - set - T_OrderDetailNat_NormalValueID = Nat_NormalValueID, - T_OrderDetailNormalValueNote = Nat_NormalValueNote, - T_OrderDetailNormalValueDescription = Nat_NormalValueDescription, - T_OrderDetailMinValue = Nat_NormalValueMinValue, - T_OrderDetailMaxValue = Nat_NormalValueMaxValue, - T_OrderDetailMinValueInclusive = Nat_NormalValueMinValueInclusive, - T_OrderDetailMaxValueInclusive = Nat_NormalValueMaxValueInclusive, - T_OrderDetailNat_MethodeID = ?, - T_OrderdetailNat_MethodeName =?"; - - foreach($rows as $r) { - $T_OrderDetailID = $r["T_OrderDetailID"]; - $sexID = $r["M_PatientM_SexID"]; - $ageInDay = $r["Dob"]; - $natTestID = $r["T_TestNat_TestID"]; - list($methodeID,$methodeName) = $this->getMethodeID($natTestID); - if ($methodeID == 0 ) continue; - $normalValueID = $this->get_normal_value($methodeID, $natTestID, $sexID, $ageInDay); - if ($normalValueID == 0) return; - $this->db->query($sql_u, array($T_OrderDetailID, $normalValueID, $methodeID, $methodeName)); - } - } - - function update_order_sample($targetID, $sourceID) { - $sql = "update t_ordersample target - join t_ordersample source on - target.T_OrderSampleID = ? - and target.T_OrderSampleWorklistReceive = 'N' - and source.T_OrderSampleID = ? - set - target.T_OrderSampleSampling = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSampling, source.T_OrderSampleSampling), - target.T_OrderSampleSamplingDate = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingDate, source.T_OrderSampleSamplingDate), - target.T_OrderSampleSamplingTime = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingTime, source.T_OrderSampleSamplingTime), - target.T_OrderSampleSamplingUserID = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingUserID, source.T_OrderSampleSamplingUserID), - - target.T_OrderSampleReceive = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceive, source.T_OrderSampleReceive), - target.T_OrderSampleReceiveDate = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveDate, source.T_OrderSampleReceiveDate), - target.T_OrderSampleReceiveTime = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveTime, source.T_OrderSampleReceiveTime), - target.T_OrderSampleReceiveUserID = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveUserID, source.T_OrderSampleReceiveUserID), - - target.T_OrderSampleVerification = if(target.T_OrderSampleVerification='Y',target.T_OrderSampleVerification, source.T_OrderSampleVerification), - target.T_OrderSampleVerificationDate =if(target.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationDate, source.T_OrderSampleVerificationDate), - target.T_OrderSampleVerificationTime =if(source.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationTime, source.T_OrderSampleVerificationTime), - target.T_OrderSampleVerificationUserID =if(source.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationUserID, source.T_OrderSampleVerificationUserID), - - target.T_OrderSampleProcessing = if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessing, source.T_OrderSampleProcessing), - target.T_OrderSampleProcessingDate= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingDate, source.T_OrderSampleProcessingDate), - target.T_OrderSampleProcessingTime= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingTime, source.T_OrderSampleProcessingTime), - target.T_OrderSampleProcessingUserID= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingUserID, source.T_OrderSampleProcessingUserID), - - target.T_OrderSampleReceiveHandling =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandling, source.T_OrderSampleReceiveHandling ), - target.T_OrderSampleReceiveHandlingDate =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingDate, source.T_OrderSampleReceiveHandlingDate), - target.T_OrderSampleReceiveHandlingTime =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingTime, source.T_OrderSampleReceiveHandlingTime), - target.T_OrderSampleReceiveHandlingUserID =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingUserID, source.T_OrderSampleReceiveHandlingUserID), - - target.T_OrderSampleHandling = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandling, source.T_OrderSampleHandling), - target.T_OrderSampleHandlingDate = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingDate, source.T_OrderSampleHandlingDate), - target.T_OrderSampleHandlingTime = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingTime, source.T_OrderSampleHandlingTime), - target.T_OrderSampleHandlingUserID = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingUserID, source.T_OrderSampleHandlingUserID), - - target.T_OrderSampleWorklistReceive = source.T_OrderSampleWorklistReceive, - target.T_OrderSampleWorklistReceiveDatetime = source.T_OrderSampleWorklistReceiveDateTime, - target.T_OrderSampleWorklistReceiveUserID = source.T_OrderSampleWorklistReceiveUserID - "; - $qry = $this->db->query($sql,array($targetID,$sourceID)); - if(! $qry ) { - echo json_encode(array( "status" => "ERR" , "message" => print_r($this->db->error(),true))); - exit; - } - } - function fix_sample_serum($headerID) { - //cari t_ordersample yg belum worklist receive dengan code 017% - $sql = "select T_OrderSampleID - from t_ordersample - join t_sampletype on - T_OrderSampleT_OrderHeaderID = ? - and T_OrderSampleWorklistReceive = 'N' - and T_OrderSampleIsActive = 'Y' - and T_OrderSampleT_SampleTypeID = T_SampletypeID - and T_SampleTypeCode like '017%' - "; - $qry = $this->db->query($sql, array($headerID)); - if(!$qry) { - echo json_encode(array( "status" => "ERR" , "message" => print_r($this->db->error(),true))); - exit; - } - $rows = $qry->result_array(); - if (count($rows) == 0 ) return; - //cari T_OrderSample yang sudah di receive yg terakhir - $sql = "select T_OrderSampleID - from t_ordersample - join t_sampletype on - T_OrderSampleT_OrderHeaderID = ? - and T_OrderSampleWorklistReceive = 'Y' - and T_OrderSampleIsActive = 'Y' - and T_OrderSampleT_SampleTypeID = T_SampletypeID - and T_SampleTypeCode like '017%' - order by T_OrderSampleWorklistReceiveDatetime desc - limit 0,1 - "; - $qry = $this->db->query($sql, array($headerID)); - if(!$qry) { - echo json_encode(array( "status" => "ERR" , "message" => print_r($this->db->error(),true))); - exit; - } - $rcv_rows = $qry->result_array(); - if (count($rcv_rows) == 0 ) return; - - //print_r($rows); - //print_r($rcv_rows); - $rcv_T_OrderSampleID = $rcv_rows[0]["T_OrderSampleID"]; - //ada yg belum di receive - foreach($rows as $r) { - $T_OrderSampleID = $r["T_OrderSampleID"]; - $this->update_order_sample($T_OrderSampleID,$rcv_T_OrderSampleID); - } - } - public function search() - { - $prm = $this->sys_input; - $max_rst = 99; - - $id = $prm["order_id"]; - if ($id > 0 ) { - $this->fix_sample_serum($id); - $this->fn_fix_normal($id); - } - $lang = $this->lang_default_code; - $lang_id = isset($prm['lang_id']) ? $prm['lang_id'] : '0'; - - if ($lang_id != 0) - { - $l = $this->db_smartone->where("Nat_LangID", $lang_id)->get("nat_lang")->row(); - $lang = $l->Nat_LangCode; - } - - //tambahan fajri - $sql = " UPDATE t_orderdetail - JOIN t_test ON T_OrderDetailT_TestID = T_TestID - SET T_OrderDetailT_TestIsResult = T_TestIsResult - WHERE - T_OrderDetailT_OrderHeaderID = {$id} AND - T_OrderDetailT_TestIsResult = '' AND - T_OrderDetailIsActive = 'Y'"; - $this->db_smartone->query($sql); - - $tot_count = 0; - $lq = ""; - $group_id = 0; - if (isset($prm['group_id'])) - $group_id = $prm['group_id']; - - if ($group_id != 0) - { - $sql = "select distinct T_WorklistDetailNat_TestID Nat_TestID - from t_worklistdetailv2 - where T_WorklistDetailT_WorklistID = {$group_id}"; - $qry = $this->db_smartone->query($sql); - $rows = $qry->result_array(); - $nat_test_ids = "0"; - foreach($rows as $r) { - $nat_test_ids .= ", " . $r["Nat_TestID"]; - } - $q_group = " ( $nat_test_ids ) "; - - $sql = " - SELECT a1.*, cOUNT(a2.T_OrderDetailID) level - FROM ( - SELECT IFNULL(y.T_OrderDetailT_TestID, x.T_OrderDetailT_TestID) t_testid, - IFNULL(y.T_OrderDetailT_TestName, y.T_OrderDetailT_TestName) t_testname, - y.T_OrderDetailResult result, y.T_OrderDetailResult result_old, y.T_OrderDetailNote note, y.T_OrderDetailNote note_old, - y.T_OrderDetailID id, - y.T_OrderDetailT_TestIsResult is_result, a.T_TestIsQuantitative is_quantitative, - y.T_OrderDetailResultFlag result_flag, - y.T_OrderDetailNat_NormalValueID normal_id, - y.T_OrderDetailNormalValueNote normal_note, y.T_OrderDetailNat_UnitName unit_name, - y.T_OrderdetailNat_MethodeID methode_id, y.T_OrderdetailNat_MethodeName methode_name, - a.T_TestNat_TestID nattest_id, a.T_TestID tx_id, count(T_ResultInstrumentID) as result_instrument_n, - y.T_OrderDetailVerification, T_OrderSampleReceive sample_receive, - T_OrderSampleProcessing sample_processing, T_OrderSampleWorklistReceive sample_worklist_receive, - IF(T_OrderDetailAddOnPreAnalytic = 'Y', T_OrderDetailAddOnPreAnalytic, PreAnalyticIsOk) pre_analytic, - T_OrderDetailAddOnPreAnalytic, - T_OrderHeaderID order_id, y.T_OrderDetailT_TestSasCode test_sas_code, - tx.T_TestSasCode, - T_OrderDetailAddOnResample `resample`, T_OrderDetailAddOnResampleStatus resample_status, - T_OrderDetailAddOnRef ref, y.T_OrderDetailVerification verification, y.T_OrderDetailValidation validation, - T_OrderPromiseDateTime, Group_ResultName as ResultGroupName - FROM t_orderdetail x - left join t_orderpromise on x.T_OrderDetailT_OrderPromiseID = T_OrderPromiseID - JOIN t_test tx ON x.T_OrderDetailT_TestID = T_TestID - JOIN t_test tcheck on tcheck.T_TestNat_TestID in {$q_group} - and ( tx.T_TestID = tcheck.T_TestID or tx.T_TestSasCode like concat(tcheck.T_TestSasCode,'%')) - LEFT JOIN group_resultdetail ON Group_ResultDetailT_TestID = x.T_OrderDetailT_TestID AND Group_ResultDetailIsActive = 'Y' - LEFT JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND Group_ResultFlagNonLab = 'N' - LEFT JOIN t_orderdetail y ON x.T_OrderDetailT_TestSasCode LIKE CONCAT(y.T_OrderDetailT_TestSasCode, '%') - AND x.T_OrderDetailT_OrderHeaderID = y.T_OrderDetailT_OrderHeaderID - AND y.T_OrderDetailIsActive = 'Y' - LEFT JOIN t_orderdetailaddon ON x.T_OrderDetailID = T_OrderDetailAddOnT_OrderDetailID - JOIN t_orderheader ON y.T_OrderDetailT_OrderHeaderID = T_OrderHeaderID - LEFT JOIN t_test a ON y.T_OrderDetailT_TestID = a.T_TestID - AND a.T_TestIsNonLab = '' - LEFT JOIN (SELECT T_OrderSampleT_SampleTypeID, T_OrderSampleReceive, T_OrderSampleProcessing, T_OrderSampleWorklistReceive - FROM t_ordersample WHERE T_OrderSampleT_OrderHeaderID = {$id} - AND T_OrderSampleIsactive = 'Y' - GROUP BY T_OrderSampleT_SampleTypeID) os ON a.T_TestT_SampleTypeID = os.T_OrderSampleT_SampleTypeID - or os.T_OrderSampleT_SampleTypeID = fn_sampletype_from_local(a.T_TestNat_TestID) - - LEFT JOIN t_resultinstrument ON T_ResultInstrumentT_OrderDetailID = x.T_OrderDetailID - LEFT JOIN pre_analytic ON PreAnalyticNat_TestID = a.T_TestNat_TestID AND PreAnalyticDate = date(now()) and PreAnalyticIsActive = 'Y' - WHERE x.T_OrderDetailT_OrderHeaderID = {$id} - AND x.T_OrderDetailIsActive = 'Y' - GROUP BY y.T_OrderDetailT_TestID - ORDER BY y.T_OrderDetailT_TestSasCode ASC - ) a1 - - LEFT JOIN t_orderdetail a2 ON a2.T_OrderDetailT_OrderHeaderID = a1.order_id - AND a2.T_OrderDetailIsActive = 'Y' - AND a1.test_sas_code LIKE CONCAT(a2.T_OrderDetailT_testSasCode, '%') - GROUP BY a1.t_testid - order by a1.test_sas_code -"; - $query = $this->db_smartone->query($sql); - $lq = $this->db_smartone->last_query(); - } - else - { - $sql = " - SELECT a1.*, cOUNT(a2.T_OrderDetailID) level - FROM ( - SELECT IFNULL(y.T_OrderDetailT_TestID, x.T_OrderDetailT_TestID) t_testid, - IFNULL(y.T_OrderDetailT_TestName, y.T_OrderDetailT_TestName) t_testname, - y.T_OrderDetailResult result, y.T_OrderDetailResult result_old, y.T_OrderDetailNote note, y.T_OrderDetailNote note_old, - y.T_OrderDetailID id, - y.T_OrderDetailT_TestIsResult is_result, a.T_TestIsQuantitative is_quantitative, - y.T_OrderDetailResultFlag result_flag, - y.T_OrderDetailNat_NormalValueID normal_id, - y.T_OrderDetailNormalValueNote normal_note, y.T_OrderDetailNat_UnitName unit_name, - y.T_OrderdetailNat_MethodeID methode_id, y.T_OrderdetailNat_MethodeName methode_name, - a.T_TestNat_TestID nattest_id, a.T_TestID tx_id, count(T_ResultInstrumentID) as result_instrument_n, - y.T_OrderDetailVerification, T_OrderSampleReceive sample_receive, - T_OrderSampleProcessing sample_processing, T_OrderSampleWorklistReceive sample_worklist_receive, - IF(T_OrderDetailAddOnPreAnalytic = 'Y', T_OrderDetailAddOnPreAnalytic, PreAnalyticIsOk) pre_analytic, - T_OrderDetailAddOnPreAnalytic, - T_OrderHeaderID order_id, y.T_OrderDetailT_TestSasCode test_sas_code, - tx.T_TestSasCode, - T_OrderDetailAddOnResample `resample`, T_OrderDetailAddOnResampleStatus resample_status, - T_OrderDetailAddOnRef ref, y.T_OrderDetailVerification verification, y.T_OrderDetailValidation validation, - T_OrderPromiseDateTime , Group_ResultName as ResultGroupName - FROM t_orderdetail x - left join t_orderpromise on x.T_OrderDetailT_OrderPromiseID = T_OrderPromiseID - JOIN t_test tx ON x.T_OrderDetailT_TestID = T_TestID - LEFT JOIN group_resultdetail ON Group_ResultDetailT_TestID = x.T_OrderDetailT_TestID AND Group_ResultDetailIsActive = 'Y' - LEFT JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND Group_ResultFlagNonLab = 'N' - LEFT JOIN t_orderdetail y ON x.T_OrderDetailT_TestSasCode LIKE CONCAT(y.T_OrderDetailT_TestSasCode, '%') - AND x.T_OrderDetailT_OrderHeaderID = y.T_OrderDetailT_OrderHeaderID - AND y.T_OrderDetailIsActive = 'Y' - - LEFT JOIN t_orderdetailaddon ON x.T_OrderDetailID = T_OrderDetailAddOnT_OrderDetailID - - JOIN t_orderheader ON y.T_OrderDetailT_OrderHeaderID = T_OrderHeaderID - LEFT JOIN t_test a ON y.T_OrderDetailT_TestID = a.T_TestID - AND a.T_TestIsNonLab = '' - LEFT JOIN (SELECT T_OrderSampleT_SampleTypeID, T_OrderSampleReceive, T_OrderSampleProcessing, T_OrderSampleWorklistReceive - FROM t_ordersample WHERE T_OrderSampleT_OrderHeaderID = {$id} - AND T_OrderSampleIsactive = 'Y' - GROUP BY T_OrderSampleT_SampleTypeID) os ON a.T_TestT_SampleTypeID = os.T_OrderSampleT_SampleTypeID - or os.T_OrderSampleT_SampleTypeID = fn_sampletype_from_local(a.T_TestNat_TestID) - - LEFT JOIN t_resultinstrument ON T_ResultInstrumentT_OrderDetailID = x.T_OrderDetailID - LEFT JOIN pre_analytic ON PreAnalyticNat_TestID = a.T_TestNat_TestID AND PreAnalyticDate = date(now()) and PreAnalyticIsActive = 'Y' - WHERE x.T_OrderDetailT_OrderHeaderID = {$id} - AND x.T_OrderDetailIsActive = 'Y' - GROUP BY y.T_OrderDetailT_TestID - ORDER BY y.T_OrderDetailT_TestSasCode ASC - ) a1 - - LEFT JOIN t_orderdetail a2 ON a2.T_OrderDetailT_OrderHeaderID = a1.order_id - AND a2.T_OrderDetailIsActive = 'Y' - AND a1.test_sas_code LIKE CONCAT(a2.T_OrderDetailT_testSasCode, '%') - GROUP BY a1.t_testid - order by a1.test_sas_code -"; -//echo $sql; - $query = $this->db_smartone->query($sql); - $lq = $this->db_smartone->last_query(); - } - // file_put_contents("/xtmp/re-query.sql",$lq); - - if ($query) { - $rst = []; - $rows = $query->result_array(); - - foreach($rows as $k => $v) - { - - if ($v['is_result'] == "Y" && $v['is_quantitative'] == "N") - { - $v['template'] = []; - $x = $this->db_smartone->query("CALL sp_master_resulttemplate_get('{$v['t_testid']}')"); - $this->clean_mysqli_connection($this->db_smartone->conn_id); - if ($x) - $v['template'] = $x->result_array(); - } - - // IF Rujukan, by pas Pre Analytik - if ($v['ref'] == 'Y') - $v['pre_analytic'] = 'Y'; - if ($v["id"] == "885455" ) - { - //sipe workaround - //$v["sample_receive"] = "Y"; - $v["sample_worklist_receive"] = "Y"; - } - $rst[] = $v; - } - - $result = array("total" => $tot_count, "records" => $rst, "total_display" => sizeof($rows), "q" => $lq); - $this->sys_ok($result); - } - else { - $this->sys_error_db("RE Px rows", $this->db_smartone); - exit; - } - } - - public function save() - { - $prm = $this->sys_input; - $data = json_decode($prm["data"]); - $lang = $this->lang_default_code; - $lang_id = isset($prm['lang_id']) ? $prm['lang_id'] : '0'; - - if ($lang_id != 0) - { - $l = $this->db_smartone->where("Nat_LangID", $lang_id)->get("nat_lang")->row(); - $lang = $l->Nat_LangCode; - } - - $sql_norm = "select T_OrderDetailMinValue, T_OrderDetailMaxValue, - T_OrderDetailMinValueInclusive, T_OrderDetailMaxValueInclusive, - Nat_TestFlagLow, Nat_TestFlagHigh - from t_orderdetail - join t_test on T_OrderDetailT_TestID = T_TestID - join nat_test on T_TestNat_TestID = Nat_TestID and T_TestIsActive = 'Y' - where T_OrderDetailID = ? "; - - $ids = []; - foreach ($data as $k => $v) - { - if ( $v->resultInstrumentID > 0 ) { - $sql_i = "select T_ResultInstrumentNat_NormalValueID normalValueID - from t_resultinstrument - where T_ResultInstrumentID = ?"; - $qry_i = $this->db_smartone->query($sql_i, array($v->resultInstrumentID)); - if ($qry_i) { - $rows_i = $qry_i->result_array(); - - if (count($rows_i) > 0 ) { - $sql_iu = "update t_orderdetail, nat_normalvalue , nat_methode - set T_OrderDetailMinValue = Nat_NormalValueMinValue, - T_OrderDetailMinValueInclusive = Nat_NormalValueMinValueInclusive, - T_OrderDetailMaxValue = Nat_NormalValueMaxValue , - T_OrderDetailMaxValueInclusive = Nat_NormalValueMaxValueInclusive, - T_OrderDetailNormalValueNote = Nat_NormalValueNote, - T_OrderDetailNormalValueDescription = Nat_NormalValueDescription, - T_OrderDetailNat_NormalValueID = Nat_NormalValueID, - T_OrderDetailNat_MethodeID = Nat_NormalValueNat_MethodeID, - T_OrderDetailNat_MethodeName = Nat_MethodeName - where T_OrderDetailID = ? and Nat_NormalValueID = ? - and Nat_NormalValueNat_MethodeID = Nat_MethodeID - "; - $this->db_smartone->query($sql_iu, array($v->id, $rows_i[0]["normalValueID"])); - //file_put_contents("/xtmp/update-nilai-normal", $this->db_smartone->last_query() . "\n", FILE_APPEND); - } - } - } - $y = $this->db_smartone->query("SELECT fn_process_sample_handling_perfect('{$v->order_id}', '{$v->test_id}') c") - ->row(); - $req_status = $y->c; - $qry_norm = $this->db_smartone->query($sql_norm,$v->id); - $result_flag = ""; - if ($qry_norm) { - $rows_norm = $qry_norm->result_array(); - if (count($rows_norm) > 0 ) { - $r = $rows_norm[0]; - if (is_numeric($v->result)) { - - if ( $r["T_OrderDetailMinValueInclusive"] == "Y" && $v->result < $r["T_OrderDetailMinValue"] ) { - $result_flag = $r["Nat_TestFlagLow"]; - } - if ( $r["T_OrderDetailMinValueInclusive"] == "N" && $v->result <= $r["T_OrderDetailMinValue"] ) { - $result_flag = $r["Nat_TestFlagLow"]; - } - if ( $r["T_OrderDetailMaxValueInclusive"] == "Y" && $v->result > $r["T_OrderDetailMaxValue"] ) { - $result_flag = $r["Nat_TestFlagHigh"]; - } - if ( $r["T_OrderDetailMaxValueInclusive"] == "N" && $v->result >= $r["T_OrderDetailMaxValue"] ) { - $result_flag = $r["Nat_TestFlagHigh"]; - } - } - } - } - if ($lang == $this->lang_default_code) - { - $this->db_smartone->set('T_OrderDetailResult', $v->result) - ->set('T_OrderDetailResultFlag', $result_flag) - ->set('T_OrderDetailNote', $v->note) - ->set('T_OrderDetailReqStatus', $req_status) - ->where('T_OrderDetailID', $v->id) - ->update('t_orderdetail'); - } - else - { - $this->db_smartone->set('T_OrderDetailLangResult', $v->result) - ->set('T_OrderDetailLangNote', $v->note) - ->where('T_OrderDetailLangID', $v->id) - ->update('t_orderdetaillang'); - } - - $ids[] = $v->id; - } - - // LOG Process - $order = $this->db_smartone->select('T_OrderDetailT_OrderHeaderID id, T_OrderHeaderLabNumber lab_number', false) - ->join('t_orderheader', 'T_OrderHeaderID = T_OrderDetailT_OrderHeaderID') - ->where('T_OrderDetailID', $data[0]->id) - ->get('t_orderdetail') - ->row(); - - $dblog = $this->load->database("onelog", true); - $dblog->set('Log_ProcessCode', 'PROCESS.Result.Entry') - ->set('Log_ProcessOrderID', $order->id) - ->set('Log_ProcessOrderNumber', $order->lab_number) - ->set('Log_ProcessJson', json_encode($data)) - ->set('Log_ProcessUserID', $this->sys_user['M_UserID']) - ->insert('log_process'); - // END OF Log Process - //auto calculation - $this->load->library("Resultcalc"); - $rows = $this->resultcalc->auto($order->id); - - try { - foreach($ids as $id ) { - $this->db_smartone->query("call sp_set_normal_value_flag($id)"); - $this->clean_mysqli_connection($this->db_smartone->conn_id); - } - } catch(Exception $e) { - } - - $this->sys_ok($ids); - } - - public function save_template() - { - $prm = $this->sys_input; - - $n = $this->db_smartone->select("COUNT(T_ResultTemplateID) n") - ->where("T_ResultTemplateT_TestID", $prm['test_id']) - ->where("T_ResultTemplateIsActive", "Y") - ->where("T_ResultTemplateValue", $prm['value']) - ->get('t_resulttemplate') - ->row(); - if ($n->n > 0) - { - $this->sys_error_db("Insert Result Template", $this->db_smartone); - return; - } - - $r = $this->db_smartone->set("T_ResultTemplateT_TestID", $prm['test_id']) - ->set("T_ResultTemplateValue", $prm['value']) - ->insert('t_resulttemplate'); - if ($r) - { - $template = []; - $x = $this->db_smartone->query("CALL sp_master_resulttemplate_get('{$prm['test_id']}')"); - $this->clean_mysqli_connection($this->db_smartone->conn_id); - if ($x) - $template = $x->result_array(); - - $this->sys_ok($template); - } - } - - public function export() - { - $prm = $this->sys_input; - - $sql = "CALL sp_process_result_lang(?, ?, ?, ?)"; - $query = $this->db_smartone->query($sql, [$prm['order_id'], $prm['lang_id'], $prm['is_si'], $this->sys_user['M_UserID']]); - if ($query) - { - $r = $query->row(); - if ($r->status == "OK") - { - $this->sys_ok($r->data); - return; - } - - $this->sys_error_db("Message : " . $r->message, $this->db_smartone); - } - else - { - $this->sys_error_db("Lang Result", $this->db_smartone); - return; - } - } - - public function search_group() - { - $prm = $this->sys_input; - $max_rst = 100; - - // QUERY TOTAL - $sql = "select count(*) total - from t_worklist - where T_WorklistIsActive = 'Y' - order by T_WorklistName ASC"; - $query = $this->db_smartone->query($sql); - - if ($query) { - $tot_count = $query->result_array()[0]["total"]; - } - else { - $this->sys_error_db("worklist count", $this->db_smartone); - exit; - } - - $sql = "select T_WorklistID group_id, T_WorklistName group_name - from t_worklist - where T_WorklistIsActive = 'Y' - order by T_WorklistName ASC - limit 0, {$max_rst}"; - $query = $this->db_smartone->query($sql); - - if ($query) { - $rows = $query->result_array(); - foreach ($rows as $k => $v) - $rows[$k]['data'] = json_decode($v['data']); - $result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows), "q" => $this->db_smartone->last_query()); - $this->sys_ok($result); - } - else { - $this->sys_error_db("worklist rows", $this->db_smartone); - exit; - } - } - - public function search_rerun() - { - $prm = $this->sys_input; - $id = $prm["detail_id"]; - - $sql = "CALL sp_process_result_rerun(?)"; - $query = $this->db_smartone->query($sql, [$id]); - - if ($query) - { - $rows = $query->result_array(); - $this->sys_ok(["records"=>$rows]); - } - else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - - - function getdoctorsfna() - { - $prm = $this->sys_input; - // $id = $prm["id"]; - - $sql = " SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY M_DoctorName ASC"; - //echo $sql; - $query = $this->db_smartone->query($sql); - - if ($query) - { - $rows = $query->result_array(); - $this->sys_ok(["records"=>$rows]); - } - else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - function getfnaresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT Other_FNADetailsID as xid, - Other_FNAT_OrderDetailID as orderdetail_id, - Other_FNADetailsCode as code, - Other_FNADetailsLabel as label, - Other_FNADetailsResult as result, - IFNULL(Other_FNAM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_FNAM_DoctorID) OR Other_FNAM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_fna - JOIN other_fnadetails ON Other_FNADetailsOther_FNAID = Other_FNAID AND Other_FNADetailsIsActive = 'Y' - LEFT JOIN m_doctor ON Other_FNAM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_FNAT_OrderDetailID = {$id} AND Other_FNAIsActive = 'Y' - GROUP BY Other_FNADetailsID - ORDER BY Other_FNADetailsCode ASC"; - $query = $this->db_smartone->query($sql); - - if ($query) - { - $rows = $query->result_array(); - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $images = array(); - $sql = "SELECT So_ImageUploadID as xid, - CONCAT('/one-media/one-image-nonlab/',So_ImageUploadNewName) as image_url - FROM t_orderdetail - JOIN so_imageupload ON So_ImageUploadT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND - So_ImageUploadIsActive = 'Y' - WHERE - T_OrderDetailID = {$id} AND - T_OrderDetailIsActive = 'Y' - GROUP BY So_ImageUploadID"; - $images = $this->db_smartone->query($sql)->result_array(); - - $rst = array('doctors'=>$doctors,'results'=>$rows,'images'=>$images); - $this->sys_ok(["records"=>$rst]); - } - else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - function getpatologianatomyresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT Other_PatologiAnatomyID as xid, - Other_PatologiAnatomyT_OrderDetailID as orderdetail_id, - Other_PatologiAnatomyNoSediaan as no_sediaan, - Other_PatologiAnatomyDiagnosaKlinis as diagnosa, - Other_PatologiAnatomyKeteranganKlinis as klinis, - Other_PatologiAnatomyLokasiOrgan as lokasi, - Other_PatologiAnatomyMakroskopik as makroskopik, - Other_PatologiAnatomyMikroskopik as mikroskopik, - Other_PatologiAnatomyKesimpulan as kesimpulan, - IFNULL(Other_PatologiAnatomyM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_PatologiAnatomyM_DoctorID) OR Other_PatologiAnatomyM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_patologi_anatomy - LEFT JOIN m_doctor ON Other_PatologiAnatomyM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_PatologiAnatomyT_OrderDetailID = {$id} AND Other_PatologiAnatomyIsActive = 'Y' - GROUP BY Other_PatologiAnatomyID - ORDER BY Other_PatologiAnatomyID ASC - LIMIT 1"; - $query = $this->db_smartone->query($sql); - - if ($query) - { - $rows = $query->row_array(); - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - - $rst = array('doctors'=>$doctors,'result'=>$rows); - $this->sys_ok(["records"=>$rst]); - } - else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - - function uploadimage(){ - if (! $this->isLogin) { - $this->sys_error("Invalid Token"); - exit; - } - - $userid = $this->sys_user["M_UserID"]; - $data = []; - //print_r($_SERVER); - - $prm = $this->sys_input; - $orderid = $this->input->post('orderid'); - $labnumber = $this->input->post('labnumber'); - $sql = "UPDATE so_imageupload SET - So_ImageUploadIsActive = 'N', - So_ImageUploadUserID = {$userid} - WHERE - So_ImageUploadT_OrderHeaderID = {$orderid}"; - //echo $sql; - $this->db_onedev->query($sql); - //$config['upload_path'] = 'assets/'; - - $path = '/home/one/project/one/one-media/one-image-nonlab/'; - //echo $path; - $config['upload_path'] = $path; - $config['allowed_types'] = 'jpg|jpeg|png|gif'; - - $config['max_size'] = '10000'; - $count = count($_FILES['files']['name']); - //echo $count; - $this->load->library('upload',$config); - - $error = []; - for($i=0;$i<$count;$i++){ - - - if(!empty($_FILES['files']['name'][$i])){ - - - - $_FILES['file']['name'] = $_FILES['files']['name'][$i]; - - $_FILES['file']['type'] = $_FILES['files']['type'][$i]; - - $_FILES['file']['tmp_name'] = $_FILES['files']['tmp_name'][$i]; - - $_FILES['file']['error'] = $_FILES['files']['error'][$i]; - - $_FILES['file']['size'] = $_FILES['files']['size'][$i]; - - - - $namex = $orderid.'-'.$labnumber.'-'.$this->generateRandomString(5); - //echo $namex; - - $config['file_name'] = $namex; - $this->upload->initialize($config); - //echo $config['file_name'] ; - - - - - - if($this->upload->do_upload('file')){ - - $uploadData = $this->upload->data(); - - $filename = $uploadData['file_name']; - //echo $filename; - - - $sql = "INSERT INTO so_imageupload ( - So_ImageUploadT_OrderHeaderID, - So_ImageUploadT_OrderHeaderLabNumber, - So_ImageUploadT_SampleTypeID, - So_ImageUploadOldName, - So_ImageUploadNewName, - So_ImageUploadCreated, - So_ImageUploadUserID - ) - VALUES( - {$orderid}, - '{$labnumber}', - '150', - '{$_FILES['files']['name'][$i]}', - '{$filename}', - NOW(), - {$userid} - - )"; - //echo $sql; - $this->db_onedev->query($sql); - $xlast_id = $this->db_onedev->insert_id(); - $data['totalFiles'][] = array('xid' => $xlast_id ,'image_url' => '/one-media/one-image-nonlab/'.$filename); - - } - else{ - $error = array('error' => $this->upload->display_errors()); - } - - } - - - - } - - $result = array("total" =>count( $data['totalFiles']), "records" => $data['totalFiles'],'errors'=>$error); - $this->sys_ok($result); - } - - - function generateRandomString($length = 10) { - $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; - $charactersLength = strlen($characters); - $randomString = ''; - for ($i = 0; $i < $length; $i++) { - $randomString .= $characters[rand(0, $charactersLength - 1)]; - } - return $randomString; - } - - function getcytologiresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT Other_CytologiDetailsID as xid, - Other_CytologiT_OrderDetailID as orderdetail_id, - Other_CytologiDetailsCode as code, - Other_CytologiDetailsLabel as label, - Other_CytologiDetailsResult as result, - IFNULL(Other_CytologiM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_CytologiM_DoctorID) OR Other_CytologiM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_cytologi - JOIN other_cytologidetails ON Other_CytologiDetailsOther_CytologiID = Other_CytologiID AND Other_CytologiDetailsIsActive = 'Y' - LEFT JOIN m_doctor ON Other_CytologiM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_CytologiT_OrderDetailID = {$id} AND Other_CytologiIsActive = 'Y' - GROUP BY Other_CytologiDetailsID - ORDER BY Other_CytologiDetailsCode ASC"; - //echo $sql; - $query = $this->db_smartone->query($sql); - - if ($query) - { - $rows = $query->result_array(); - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $rst = array('doctors'=>$doctors,'results'=>$rows); - $this->sys_ok(["records"=>$rst]); - } - else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - function getmikroresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT - Other_MikroID as xid, - Other_MikroHasilBiakan as hasil_biakan, - Other_MikroSampleTypeName as sample_name, - Other_MikroT_OrderDetailID as orderdetail_id, - Other_MikroResult as result_value, - '' as result_other, - IFNULL(T_BacteriaID,0) as T_BacteriaID, - IFNULL(T_BacteriaName,'') as T_BacteriaName, - '' as details, - IFNULL(Other_MikroM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_MikroM_DoctorID) OR Other_MikroM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_mikro - LEFT JOIN t_bacteria ON Other_MikroT_BacteriaID = T_BacteriaID - LEFT JOIN m_doctor ON Other_MikroM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_MikroT_OrderDetailID = {$id} AND Other_MikroIsActive = 'Y' - GROUP BY Other_MikroID"; - //echo $sql; - $query = $this->db_smartone->query($sql); - - if ($query) - { - $row = $query->row_array(); - if($row){ - if($row['result_value'] != 'Positif' && $row['result_value'] != 'Negatif'){ - $row['result_other'] = $row['result_value']; - $row['result_value'] = 'other'; - } - $sql = "SELECT '' as xno, - Other_MikroDetailsID as xid, - Other_MikroDetailsValue as value, - IF(Other_MikroDetailsNote = 'R','Y','N') as chx_r, - IF(Other_MikroDetailsNote = 'I','Y','N') as chx_i, - IF(Other_MikroDetailsNote = 'S','Y','N') as chx_s, - Other_MikroDetailsNote as note, - t_antibiotic.* - FROM other_mikrodetails - LEFT JOIN t_antibiotic ON Other_MikroDetailsT_AntibioticID = T_AntibioticID - WHERE - Other_MikroDetailsOther_MikroID = {$row['xid']} AND Other_MikroDetailsIsActive = 'Y' - GROUP BY Other_MikroDetailsID - ORDER BY T_AntibioticName ASC"; - //echo $sql; - $details = $this->db_smartone->query($sql)->result_array(); - if(details){ - foreach($details as $k => $v){ - $details[$k]['xno'] = $k + 1; - } - } - $row['details'] = $details; - } - else{ - $row = array('xid'=>'0','hasil_biakan' => '','result_value'=>'Negatif','sample_name' => '','orderdetail_id'=>$id, 'T_BacteriaID'=>'0','T_BacteriaName'=>'0','details'=>array(),'doctor_id'=>'0','doctor_name'=>'0'); - } - } - else{ - $row = array('xid'=>'0','hasil_biakan' => '','result_value'=>'Negatif','sample_name' => '','orderdetail_id'=>$id, 'T_BacteriaID'=>'0','T_BacteriaName'=>'0','details'=>array(),'doctor_id'=>'0','doctor_name'=>'0'); - } - //print_r($row); - - - - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 7 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $sql = " - SELECT '0' as id, 'Belum memilih bakteria' as name - UNION - SELECT T_BacteriaID as id, T_BacteriaName as name - FROM t_bacteria - WHERE - T_BacteriaIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $bacteries = $this->db_smartone->query($sql)->result_array(); - $rst = array('doctors'=>$doctors,'bacteries'=>$bacteries,'results'=>$row); - $this->sys_ok(["records"=>$rst]); - } - function getantibiotics(){ - $prm = $this->sys_input; - $id = $prm["id"]; - $sql = " SELECT '' as xno, - 0 as xid, - '' as hasil_biakan, - '' as sample_name, - 0 as value, - 'Y' as chx_r, - 'N' as chx_i, - 'N' as chx_s, - 'R' as note, - t_antibiotic.* - FROM t_antibiotic - WHERE - T_AntibioticT_BacteriaID = {$prm['id']} AND T_AntibioticIsActive= 'Y' - ORDER BY T_AntibioticName ASC"; - //echo $sql; - $rows = $this->db_smartone->query($sql)->result_array(); - if(rows){ - foreach($rows as $k => $v){ - $rows[$k]['xno'] = $k + 1; - } - } - - $this->sys_ok(["records"=>$rows]); - } - function getlcprepresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - $sql = " SELECT Other_LcprepDetailsID as xid, - Other_LcprepID as header_id, - Other_LcprepT_orderDetailID as orderdetail_id, - Other_LcprepDetailsCode as code, - Other_LcprepDetailsLabel as label, - Other_LcprepDetailsResult as result, - IFNULL(Other_LcprepM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_LcprepM_DoctorID) OR Other_LcprepM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_lcprep - JOIN other_lcprepdetails ON Other_LcprepDetailsOther_LcprepID = Other_LcprepID AND Other_LcprepDetailsIsActive = 'Y' - LEFT JOIN m_doctor ON Other_LcprepM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_LcprepT_orderDetailID = {$id} AND Other_LcprepIsActive = 'Y' - GROUP BY Other_LcprepDetailsOther_LcprepID, Other_LcprepDetailsCode - ORDER BY Other_LcprepDetailsCode ASC"; - //echo $sql; - $rows = $this->db_smartone->query($sql)->result_array(); - if(!$rows){ - $rows = array( - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'A', - 'label' => 'DESKRIPSI', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ), - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'B', - 'label' => 'KESIMPULAN', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ) - ); - } - - $header_id = $rows[0]['header_id']; - $sql = "SELECT IFNULL(Other_LcprepAdekuasiID,0) as xid, - Lcprep_AdekuasiID as id, - Lcprep_AdekuasiLabel as name, - IF(ISNULL(Other_LcprepAdekuasiID),'N',Other_LcprepAdekuasiChex) as chex - FROM lcprep_adekuasi - LEFT JOIN other_lcprepadekuasi ON Other_LcprepAdekuasiLcprep_AdekuasiID = Lcprep_AdekuasiID AND - Other_LcprepAdekuasiOther_LcprepID = {$header_id} AND - Other_LcprepAdekuasiIsActive = 'Y' - WHERE - Lcprep_AdekuasiIsActive = 'Y' - GROUP BY Lcprep_AdekuasiID - ORDER BY Lcprep_AdekuasiOrder ASC - "; - //echo $sql; - $adeakuasi = $this->db_smartone->query($sql)->result_array(); - foreach($adeakuasi as $kc => $vc){ - $adeakuasi[$kc]['chex'] = $vc['chex'] == 'N'?false:true; - } - - $sql = "SELECT IFNULL(Other_LcprepKategoriUmumID,0) as xid, - Lcprep_KategoriUmumID as id, - Lcprep_KategoriUmumLabel as name, - IF(ISNULL(Other_LcprepKategoriUmumID),'N',Other_LcprepKategoriUmumChex) as chex - FROM lcprep_kategoriumum - LEFT JOIN other_lcprepkategoriumum ON Other_LcprepKategoriUmumLcprep_KategoriUmumID = Lcprep_KategoriUmumID AND - Other_LcprepKategoriUmumOther_LcprepID = {$header_id} AND - Other_LcprepKategoriUmumIsActive = 'Y' - WHERE - Lcprep_KategoriUmumIsActive = 'Y' - GROUP BY Lcprep_KategoriUmumID - "; - //echo $sql; - $kategoriumum = $this->db_smartone->query($sql)->result_array(); - foreach($kategoriumum as $kc => $vc){ - $kategoriumum[$kc]['chex'] = $vc['chex'] == 'N'?false:true; - } - - $sql = " - SELECT Lcprep_InterpretasiGroupID as group_id, - Lcprep_InterpretasiGroupName as group_name, - '' as subgroups - FROM lcprep_interpretasigroup - WHERE - Lcprep_InterpretasiGroupIsActive = 'Y' - "; - //echo $sql; - $interpretasi = $this->db_smartone->query($sql)->result_array(); - foreach($interpretasi as $k => $v){ - $subgroups = array(); - $sql = "SELECT Lcprep_InterpretasiSubgroupID as subgroup_id, - Lcprep_InterpretasiSubgroupName as subgroup_name, - '' as childs - FROM lcprep_interpretasisubgroup - WHERE - Lcprep_InterpretasiSubgroupLcprep_InterpretasiGroupID = {$v['group_id']} AND Lcprep_InterpretasiSubgroupIsActive = 'Y'"; - //echo $sql; - $subgroups = $this->db_smartone->query($sql)->result_array(); - if(count($subgroups) > 0){ - foreach($subgroups as $ki => $vi){ - $childs = array(); - $sql = "SELECT IFNULL(Other_LcprepInterpretasiID,0) as xid, - IFNULL(Other_LcprepInterpretasiChex,'N') as chex, - IFNULL(Other_LcprepInterpretasiValue,'') as value, - Lcprep_InterpretasiID as id, - Lcprep_InterpretasiLcprep_InterpretasiSubgroupID as subgroup_id, - Lcprep_InterpretasiCode as code, - Lcprep_InterpretasiName as name, - Lcprep_InterpretasiParentID as parent_id, - Lcprep_InterpretasiIsParent as is_parent, - Lcprep_InterpretasiHasResult as has_result, - Lcprep_InterpretasiTypeResult as type_result - FROM lcprep_interpretasi - LEFT JOIN other_lcprepinterpretasi ON Other_LcprepInterpretasiOther_LcprepID = {$header_id} AND - Other_LcprepInterpretasiLcprep_InterpretasiID = Lcprep_InterpretasiID AND - Other_LcprepInterpretasiIsActive = 'Y' - WHERE - Lcprep_InterpretasiLcprep_InterpretasiSubgroupID = {$vi['subgroup_id']} AND Lcprep_InterpretasiIsActive = 'Y' - GROUP BY Lcprep_InterpretasiID Order BY Lcprep_InterpretasiCode ASC"; - $childs = $this->db_smartone->query($sql)->result_array(); - if($childs){ - foreach($childs as $kc => $vc){ - $childs[$kc]['chex'] = $vc['chex'] == 'N'?false:true; - } - } - $subgroups[$ki]['childs'] = $childs; - } - } - - $interpretasi[$k]['subgroups'] = $subgroups; - } - - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $rst = array('doctors'=>$doctors,'results'=>$rows,'adekuasi'=>$adeakuasi,'kategoriumum'=>$kategoriumum,'interpretasi'=>$interpretasi); - $this->sys_ok(["records"=>$rst]); - } - - function getpapsmearresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT Other_PapSmearDetailsID as xid, - Other_PapSmearID as header_id, - Other_PapSmearT_OrderDetailID as orderdetail_id, - Other_PapSmearDetailsCode as code, - Other_PapSmearDetailsLabel as label, - Other_PapSmearDetailsResult as result, - IFNULL(Other_PapSmearM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_PapSmearM_DoctorID) OR Other_PapSmearM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_papsmear - JOIN other_papsmeardetails ON Other_PapSmearDetailsOther_PapSmearID = Other_PapSmearID AND Other_PapSmearDetailsIsActive = 'Y' - LEFT JOIN m_doctor ON Other_PapSmearM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_PapSmearT_OrderDetailID = {$id} AND Other_PapSmearIsActive = 'Y' - GROUP BY Other_PapSmearDetailsID - ORDER BY Other_PapSmearDetailsCode ASC"; - //echo $sql; - $rows = $this->db_smartone->query($sql)->result_array(); - if(!$rows){ - $rows = array( - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'A', - 'label' => 'Makroskopik', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ), - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'B', - 'label' => 'Mikroskopik', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ), - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'C', - 'label' => 'Kesimpulan', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ) - ); - } - - $header_id = $rows[0]['header_id']; - $sql = "SELECT Other_PapSmearMaturasiID as xid, - Other_PapSmearMaturasiValue as value - FROM other_papsmearmaturasi - WHERE - Other_PapSmearMaturasiOther_PapSmearID = {$header_id} AND - Other_PapSmearMaturasiIsActive = 'Y' - "; - //echo $sql; - $dt_maturasi = $this->db_smartone->query($sql)->row_array(); - if(!$dt_maturasi){ - $maturasi = array('xid'=>'0','value'=> array('','','')); - } - else{ - $value = explode('/',$dt_maturasi['value']); - $maturasi = array('xid'=>$dt_maturasi['xid'],'value'=> $value); - } - - $sql = "SELECT IFNULL(Other_PapSmearBahanID,0) as xid, - M_PapSmearBahanID as bahan_id, - M_PapSmearBahanName as name, - IF(ISNULL(Other_PapSmearBahanID),'N','Y') as selected - FROM m_papsmearbahan - LEFT JOIN other_papsmearbahan ON Other_PapSmearBahanM_PapSmearBahanID = M_PapSmearBahanID AND - Other_PapSmearBahanOther_PapSmearID = {$header_id} AND - Other_PapSmearBahanIsActive = 'Y' - WHERE - M_PapSmearBahanIsActive = 'Y' - ORDER BY M_PapSmearBahanID ASC - "; - //echo $sql; - $bahans = $this->db_smartone->query($sql)->result_array(); - - $sql = "SELECT IFNULL(Other_PapsmearCategoryID,0) as xid, - M_PapSmearCategoryID as category_id, - M_PapSmearCategoryName as name, - IF(ISNULL(Other_PapsmearCategoryID),'N','Y') as selected - FROM m_papsmearcategory - LEFT JOIN other_papsmearcategory ON Other_PapsmearCategoryM_PapSmearCategoryID = M_PapSmearCategoryID AND - Other_PapsmearCategoryOther_PapSmearID = {$header_id} AND - Other_PapsmearCategoryIsActive = 'Y' - WHERE - M_PapSmearCategoryIsActive = 'Y' - ORDER BY M_PapSmearCategoryID ASC - "; - //echo $sql; - $categories = $this->db_smartone->query($sql)->result_array(); - - $sql = "SELECT IFNULL(Other_PapSmearCheckID,0) as xid, - M_PapSmearCheckID as check_id, - M_PapSmearCheckLabel as name, - IF(ISNULL(Other_PapSmearCheckID),'N','Y') as selected, - Other_PapSmearCheckNote as note - FROM m_papsmearcheck - LEFT JOIN other_papsmearcheck ON Other_PapSmearCheckM_PapSmearCheckID = M_PapSmearCheckID AND - Other_PapSmearCheckOther_PapSmearID = {$header_id} AND - Other_PapSmearCheckIsActive = 'Y' - WHERE - M_PapSmearCheckIsActive = 'Y' - ORDER BY M_PapSmearCheckCode ASC - "; - $checks = $this->db_smartone->query($sql)->result_array(); - - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $rst = array('doctors'=>$doctors,'checks'=>$checks,'bahans'=>$bahans,'categories'=>$categories,'maturasi'=>$maturasi,'results'=>$rows); - $this->sys_ok(["records"=>$rst]); - - } - - function saveresult_lcprep() - { - $prm = $this->sys_input; - $detail_id = $prm['detail_id']; - $doctor_id = $prm['doctor']; - $adekuasi = $prm['adekuasi']; - $kategoriumum = $prm['kategoriumum']; - $interpretasi = $prm['interpretasi']; - $results = $prm['results']; - - $userid = $this->sys_user['M_UserID']; - - $header_id = 0; - $sql = "SELECT * FROM other_lcprep WHERE Other_LcprepT_orderDetailID = {$detail_id} AND Other_LcprepIsActive = 'Y'"; - $dt_header = $this->db_smartone->query($sql)->row_array(); - if($dt_header){ - $header_id = $dt_header['Other_LcprepID']; - } - if($header_id == 0){ - $sql = "INSERT INTO other_lcprep( - Other_LcprepT_orderDetailID, - Other_LcprepM_DoctorID, - Other_LcprepUserID, - Other_LcprepCreated - ) - VALUES( - {$detail_id}, - {$doctor_id}, - {$userid}, - NOW() - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - }else{ - $sql = "UPDATE other_lcprep SET Other_LcprepM_DoctorID = {$doctor_id}, Other_LcprepUserID = {$userid} WHERE Other_LcprepID = {$header_id}"; - $this->db_smartone->query($sql); - } - - if($adekuasi){ - foreach($adekuasi as $k =>$v){ - $selected = $v['chex']?'Y':'N'; - if(intval($v['xid'] == 0)){ - $sql = "UPDATE other_lcprepadekuasi SET Other_LcprepAdekuasiIsActive = 'N' - WHERE - Other_LcprepAdekuasiOther_LcprepID = {$header_id} AND - Other_LcprepAdekuasiIsActive = 'Y' AND - Other_LcprepAdekuasiLcprep_AdekuasiID = {$v['id']}"; - $this->db_smartone->query($sql); - $sql = "INSERT INTO other_lcprepadekuasi ( - Other_LcprepAdekuasiOther_LcprepID, - Other_LcprepAdekuasiLcprep_AdekuasiID, - Other_LcprepAdekuasiChex, - Other_LcprepAdekuasiUserID, - Other_LcprepAdekuasiCreated - ) - VALUES( - {$header_id}, - {$v['id']}, - '{$selected}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - //echo $sql; - } - if(intval($v['xid'] != 0)){ - - $sql = "UPDATE other_lcprepadekuasi SET - Other_LcprepAdekuasiChex = '{$selected}', - Other_LcprepAdekuasiUserID = {$userid} - WHERE - Other_LcprepAdekuasiID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - - //echo $sql; - } - } - - if($kategoriumum){ - foreach($kategoriumum as $k =>$v){ - $selected = $v['chex']?'Y':'N'; - if(intval($v['xid'] == 0)){ - $sql = "UPDATE other_lcprepkategoriumum SET Other_LcprepKategoriUmumIsActive = 'N' - WHERE - Other_LcprepKategoriUmumOther_LcprepID = {$header_id} AND - Other_LcprepKategoriUmumLcprep_KategoriUmumID = {$v['id']} AND - Other_LcprepKategoriUmumIsActive = 'Y' - "; - $this->db_smartone->query($sql); - $sql = "INSERT INTO other_lcprepkategoriumum ( - Other_LcprepKategoriUmumOther_LcprepID, - Other_LcprepKategoriUmumLcprep_KategoriUmumID, - Other_LcprepKategoriUmumChex, - Other_LcprepKategoriUmumUserID, - Other_LcprepKategoriUmumCreated - ) - VALUES( - {$header_id}, - {$v['id']}, - '{$selected}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if(intval($v['xid'] != 0)){ - $sql = "UPDATE other_lcprepkategoriumum SET - Other_LcprepKategoriUmumChex = '{$selected }', - Other_LcprepKategoriUmumUserID = {$userid} - WHERE - Other_LcprepKategoriUmumID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - - //echo $sql; - } - } - - if($results){ - foreach($results as $k =>$v){ - if(intval($v['xid'] == 0)){ - $sql = "UPDATE other_lcprepdetails SET Other_LcprepDetailsIsActive = 'N' - WHERE - Other_LcprepDetailsOther_LcprepID = {$header_id} AND - Other_LcprepDetailsCode = '{$v['code']}' AND - Other_LcprepDetailsIsActive = 'Y'"; - $this->db_smartone->query($sql); - $sql = "INSERT INTO other_lcprepdetails ( - Other_LcprepDetailsOther_LcprepID, - Other_LcprepDetailsCode, - Other_LcprepDetailsLabel, - Other_LcprepDetailsResult, - Other_LcprepDetailsUserID, - Other_LcprepDetailsCreated - ) - VALUES( - {$header_id}, - '{$v['code']}', - '{$v['label']}', - '{$v['result']}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if(intval($v['xid'] != 0)){ - $sql = "UPDATE other_lcprepdetails SET - Other_LcprepDetailsCode = '{$v['code']}', - Other_LcprepDetailsLabel = '{$v['label']}', - Other_LcprepDetailsResult = '{$v['result']}', - Other_LcprepDetailsUserID = {$userid} - WHERE - Other_LcprepDetailsID = {$v['xid']}"; - $this->db_smartone->query($sql); - - } - //echo $sql; - } - } - - if($interpretasi){ - foreach($interpretasi as $k =>$v){ - if(count($v['subgroups']) > 0){ - foreach($v['subgroups'] as $ik => $iv){ - if(count($iv['childs']) > 0){ - foreach($iv['childs'] as $iik => $iiv){ - if(intval($iiv['xid'] == 0)){ - $chex = $iiv['chex'] ? 'Y':'N'; - $sql = "UPDATE other_lcprepinterpretasi SET Other_LcprepInterpretasiIsActive = 'N' - WHERE - Other_LcprepInterpretasiOther_LcprepID = {$header_id} AND - Other_LcprepInterpretasiLcprep_InterpretasiID = '{$iiv['id']}' AND - Other_LcprepInterpretasiIsActive = 'Y'"; - $this->db_smartone->query($sql); - $sql = "INSERT INTO other_lcprepinterpretasi ( - Other_LcprepInterpretasiOther_LcprepID, - Other_LcprepInterpretasiLcprep_InterpretasiID, - Other_LcprepInterpretasiChex, - Other_LcprepInterpretasiValue, - Other_LcprepInterpretasiUserID, - Other_LcprepInterpretasiCreated - ) - VALUES( - {$header_id}, - '{$iiv['id']}', - '{$chex}', - '{$iiv['value']}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - - if(intval($iiv['xid'] != 0)){ - $chex = $iiv['chex'] ? 'Y':'N'; - $sql = "UPDATE other_lcprepinterpretasi SET - Other_LcprepInterpretasiChex = '{$chex}', - Other_LcprepInterpretasiValue = '{$iiv['value']}', - Other_LcprepInterpretasiUserID = {$userid} - WHERE - Other_LcprepInterpretasiID = {$iiv['xid']}"; - $this->db_smartone->query($sql); - //echo $sql; - - } - - } - } - } - } - //echo $sql; - } - } - - - $result = array("total" => 1, "records" => array(), "sql"=> ''); - $this->sys_ok($result); - exit; - } - - function saveresult_papsmear() - { - $prm = $this->sys_input; - $detail_id = $prm['detail_id']; - $doctor_id = $prm['doctor']; - $checks = $prm['checks']; - $maturasi = $prm['maturasi']; - $bahans = $prm['bahans']; - $categories = $prm['categories']; - $results = $prm['results']; - - $userid = $this->sys_user['M_UserID']; - - $header_id = 0; - $sql = "SELECT * FROM other_papsmear WHERE Other_PapSmearT_OrderDetailID = {$detail_id} AND Other_PapSmearIsActive = 'Y'"; - $dt_header = $this->db_smartone->query($sql)->row_array(); - if($dt_header){ - $header_id = $dt_header['Other_PapSmearID']; - } - if($header_id == 0){ - $sql = "INSERT INTO other_papsmear( - Other_PapSmearT_OrderDetailID, - Other_PapSmearM_DoctorID, - Other_PapSmearUserID, - Other_PapSmearCreated - ) - VALUES( - {$detail_id}, - {$doctor_id}, - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } - else{ - $sql = "UPDATE other_papsmear SET Other_PapSmearM_DoctorID = {$doctor_id}, Other_PapSmearUserID = {$userid} WHERE Other_PapSmearID = {$header_id}"; - $this->db_smartone->query($sql); - } - - if($checks){ - foreach($checks as $k =>$v){ - if(intval($v['xid']) == 0 && $v['selected'] === 'Y'){ - $sql = "INSERT INTO other_papsmearcheck ( - Other_PapSmearCheckOther_PapSmearID, - Other_PapSmearCheckM_PapSmearCheckID, - Other_PapSmearCheckNote, - Other_PapSmearCheckUserID, - Other_PapSmearCheckCreated - ) - VALUES( - {$header_id}, - {$v['check_id']}, - '{$v['note']}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if(intval($v['xid']) != 0 && $v['selected'] === 'N'){ - $sql = "UPDATE other_papsmearcheck SET - Other_PapSmearCheckIsActive = 'N', - Other_PapSmearCheckUserID = {$userid} - WHERE - Other_PapSmearCheckID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - if(intval($v['xid']) != 0 && $v['selected'] === 'Y'){ - $sql = "UPDATE other_papsmearcheck SET - Other_PapSmearCheckNote = '{$v['note']}', - Other_PapSmearCheckUserID = {$userid} - WHERE - Other_PapSmearCheckID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - //echo $sql; - } - } - - if($maturasi){ - if(intval($maturasi['xid']) == 0){ - $value = join("/",$maturasi['value']); - $sql = "INSERT INTO other_papsmearmaturasi ( - Other_PapSmearMaturasiOther_PapSmearID, - Other_PapSmearMaturasiValue, - Other_PapSmearMaturasiUserID, - Other_PapSmearMaturasiCreated - ) - VALUE( - {$header_id}, - '{$value}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - //echo $sql; - } - if(intval($maturasi['xid']) != 0){ - $value = join("/",$maturasi['value']); - $sql = "UPDATE other_papsmearmaturasi SET - Other_PapSmearMaturasiValue = '{$value}', - Other_PapSmearMaturasiUserID = {$userid} - WHERE - Other_PapSmearMaturasiID = {$maturasi['xid']}"; - // echo $sql; - $this->db_smartone->query($sql); - } - } - - if($bahans){ - foreach($bahans as $k =>$v){ - if(intval($v['xid']) == 0 && $v['selected'] === 'Y'){ - $sql = "INSERT INTO other_papsmearbahan ( - Other_PapSmearBahanOther_PapSmearID, - Other_PapSmearBahanM_PapSmearBahanID, - Other_PapSmearBahanUserID, - Other_PapSmearBahanCreated - ) - VALUES( - {$header_id}, - {$v['bahan_id']}, - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if(intval($v['xid']) != 0 && $v['selected'] === 'N'){ - $sql = "UPDATE other_papsmearbahan SET - Other_PapSmearBahanIsActive = 'N', - Other_PapsmearCategoryUserID = {$userid} - WHERE - Other_PapSmearBahanID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - if(intval($v['xid']) != 0 && $v['selected'] === 'Y'){ - $sql = "UPDATE other_papsmearbahan SET - Other_PapSmearBahanIsActive = 'Y', - Other_PapsmearCategoryUserID = {$userid} - WHERE - Other_PapSmearBahanID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - //echo $sql; - } - } - - if($categories){ - foreach($categories as $k =>$v){ - if(intval($v['xid']) == 0 && $v['selected'] === 'Y'){ - $sql = "INSERT INTO other_papsmearcategory ( - Other_PapsmearCategoryOther_PapSmearID, - Other_PapsmearCategoryM_PapSmearCategoryID, - Other_PapsmearCategoryUserID, - Other_PapsmearCategoryCreated - ) - VALUES( - {$header_id}, - {$v['category_id']}, - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if(intval($v['xid']) != 0 && $v['selected'] === 'N'){ - $sql = "UPDATE other_papsmearcategory SET - Other_PapsmearCategoryIsActive = 'N', - Other_PapsmearCategoryUserID = {$userid} - WHERE - Other_PapsmearCategoryID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - //echo $sql; - if(intval($v['xid']) != 0 && $v['selected'] === 'Y'){ - $sql = "UPDATE other_papsmearcategory SET - Other_PapsmearCategoryIsActive = 'Y', - Other_PapsmearCategoryUserID = {$userid} - WHERE - Other_PapsmearCategoryID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - } - } - - if($results){ - foreach($results as $k =>$v){ - if(intval($v['xid']) == 0){ - $sql = "INSERT INTO other_papsmeardetails ( - Other_PapSmearDetailsOther_PapSmearID, - Other_PapSmearDetailsCode, - Other_PapSmearDetailsLabel, - Other_PapSmearDetailsResult, - Other_PapSmearDetailsUserID, - Other_PapSmearDetailsCreated - ) - VALUES( - {$header_id}, - '{$v['code']}', - '{$v['label']}', - '{$v['result']}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if(intval($v['xid']) != 0){ - $sql = "UPDATE other_papsmeardetails SET - Other_PapSmearDetailsCode = '{$v['code']}', - Other_PapSmearDetailsLabel = '{$v['label']}', - Other_PapSmearDetailsResult = '{$v['result']}', - Other_PapSmearDetailsUserID = {$userid} - WHERE - Other_PapSmearDetailsID = {$v['xid']}"; - $this->db_smartone->query($sql); - - } - //echo $sql; - } - } - - $result = array("total" => 1, "records" => array(), "sql"=> ''); - $this->sys_ok($result); - exit; - } - - function saveresult_fna() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = $inp['doctor']; - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - if($prm[0]['xid'] == '0'){ - $sql = "INSERT INTO other_fna( - Other_FNAM_DoctorID, - Other_FNAT_OrderDetailID, - Other_FNAUserID, - Other_FNACreated - ) - VALUES( - {$doctor_id}, - {$prm[0]['orderdetail_id']}, - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } - else{ - $sql = "SELECT * FROM other_fna WHERE Other_FNAT_OrderDetailID = {$prm[0]['orderdetail_id']} AND Other_FNAIsActive = 'Y'"; - $data_header = $this->db_smartone->query($sql)->row_array(); - $header_id = $data_header['Other_FNAID']; - $sql = "UPDATE other_fna SET - Other_FNAM_DoctorID = {$doctor_id}, - Other_FNAUserID = {$userid} - WHERE - Other_FNAID = {$header_id}"; - $this->db_smartone->query($sql); - } - foreach($prm as $k => $v){ - if($v['xid'] == '0'){ - $results = str_replace("'", "\\'", $v['result']); - $sql = "INSERT INTO other_fnadetails( - Other_FNADetailsOther_FNAID , - Other_FNADetailsCode, - Other_FNADetailsLabel, - Other_FNADetailsResult, - Other_FNADetailsCreated, - Other_FNADetailsUserID - ) - VALUES( - {$header_id}, - '{$v['code']}', - '{$v['label']}', - '{$results}', - NOW(), - {$userid} - )"; - $query = $this->db_smartone->query($sql); - } - else{ - $results = str_replace("'", "\\'", $v['result']); - $sql = "UPDATE other_fnadetails SET - Other_FNADetailsResult = '{$results}', - Other_FNADetailsUserID = {$userid} - WHERE - Other_FNADetailsID = {$v['xid']}"; - $query = $this->db_smartone->query($sql); - } - } - - $result = array("total" => 1, "records" => array(), "sql"=> ''); - $this->sys_ok($result); - exit; - } - - function saveresult_cytologi() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = $inp['doctor']; - - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - if($prm[0]['xid'] == '0'){ - $sql = "INSERT INTO other_cytologi( - Other_CytologiT_OrderDetailID, - Other_CytologiM_DoctorID, - Other_CytologiUserID, - Other_CytologiCreated - ) - VALUES( - {$prm[0]['orderdetail_id']}, - {$doctor_id}, - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } - else{ - $sql = "SELECT * FROM other_cytologi WHERE Other_CytologiT_OrderDetailID = {$prm[0]['orderdetail_id']} AND Other_CytologiIsActive = 'Y'"; - $data_header = $this->db_smartone->query($sql)->row_array(); - $header_id = $data_header['Other_CytologiID']; - $sql = "UPDATE other_cytologi SET - Other_CytologiM_DoctorID = {$doctor_id}, - Other_CytologiUserID = {$userid} - WHERE - Other_CytologiID = {$header_id}"; - $this->db_smartone->query($sql); - } - foreach($prm as $k => $v){ - if($v['xid'] == '0'){ - $results = str_replace("'", "\\'", $v['result']); - $sql = "INSERT INTO other_cytologidetails( - Other_CytologiDetailsOther_CytologiID , - Other_CytologiDetailsCode, - Other_CytologiDetailsLabel, - Other_CytologiDetailsResult, - Other_CytologiDetailsCreated, - Other_CytologiDetailsUserID - ) - VALUES( - {$header_id}, - '{$v['code']}', - '{$v['label']}', - '{$results}', - NOW(), - {$userid} - )"; - $query = $this->db_smartone->query($sql); - } - else{ - $results = str_replace("'", "\\'", $v['result']); - $sql = "UPDATE other_cytologidetails SET - Other_CytologiDetailsResult = '{$results}', - Other_CytologiDetailsUserID = {$userid} - WHERE - Other_CytologiDetailsID = {$v['xid']}"; - $query = $this->db_smartone->query($sql); - } - } - - $result = array("total" => 1, "records" => array(), "sql"=> ''); - $this->sys_ok($result); - exit; - } - - function saveresult_mikro() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = $inp['doctor']; - $backteria_id = $inp['bacteria']; - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - - if($inp['result_value'] != 'Negatif' && $inp['result_value'] != 'Positif'){ - $prm['result_value'] = $prm['result_other']; - } - else{ - $prm['result_value'] = $inp['result_value']; - } - - if($prm['xid'] == '0'){ - $sql = "INSERT INTO other_mikro( - Other_MikroM_DoctorID, - Other_MikroResult, - Other_MikroT_BacteriaID, - Other_MikroT_OrderDetailID, - Other_MikroHasilBiakan, - Other_MikroSampleTypeName, - Other_MikroUserID, - Other_MikroCreated - ) - VALUES( - {$doctor_id}, - '{$prm['result_value']}', - {$backteria_id}, - {$prm['orderdetail_id']}, - '{$prm['hasil_biakan']}', - '{$prm['sample_name']}', - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } - else{ - $sql = "SELECT * FROM other_mikro WHERE Other_MikroT_OrderDetailID = {$prm['orderdetail_id']} AND Other_MikroIsActive = 'Y'"; - $data_header = $this->db_smartone->query($sql)->row_array(); - $header_id = $data_header['Other_MikroID']; - $sql = "UPDATE other_mikro SET - Other_MikroResult = '{$prm['result_value']}', - Other_MikroM_DoctorID = {$doctor_id}, - Other_MikroT_BacteriaID = {$backteria_id}, - Other_MikroHasilBiakan = '{$prm['hasil_biakan']}', - Other_MikroSampleTypeName = '{$prm['sample_name']}', - Other_MikroUserID = {$userid} - WHERE - Other_MikroID = {$header_id}"; - //echo $sql; - $this->db_smartone->query($sql); - } - - - - $sql = "UPDATE other_mikrodetails SET Other_MikroDetailsIsActive = 'N', Other_MikroDetailsUserID = 0 WHERE Other_MikroDetailsOther_MikroID = {$header_id}"; - $this->db_smartone->query($sql); - - $results = $prm['details']; - if($inp['result_value'] == 'Positif'){ - foreach($results as $k => $v){ - if($v['xid'] == '0'){ - $sql = "INSERT INTO other_mikrodetails( - Other_MikroDetailsOther_MikroID , - Other_MikroDetailsT_AntibioticID, - Other_MikroDetailsValue, - Other_MikroDetailsNote, - Other_MikroDetailsCreated, - Other_MikroDetailsUserID - ) - VALUES( - {$header_id}, - '{$v['T_AntibioticID']}', - '{$v['value']}', - '{$v['note']}', - NOW(), - {$userid} - )"; - $query = $this->db_smartone->query($sql); - } - else{ - $sql = "UPDATE other_mikrodetails SET - Other_MikroDetailsT_AntibioticID = '{$v['T_AntibioticID']}', - Other_MikroDetailsValue = '{$v['value']}', - Other_MikroDetailsNote = '{$v['note']}', - Other_MikroDetailsIsActive = 'Y', - Other_MikroDetailsUserID = {$userid} - WHERE - Other_MikroDetailsID = {$v['xid']}"; - //echo $sql; - $query = $this->db_smartone->query($sql); - } - } - } - - - $result = array("total" => 1, "records" => array(), "sql"=> ''); - $this->sys_ok($result); - exit; - } - - - function get_doctors_preparasi_sperma() - { - $prm = $this->sys_input; - // $id = $prm["id"]; - - $sql = " SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 10 AND - M_DoctorSOIsActive = 'Y' - ORDER BY M_DoctorName ASC"; - //echo $sql; - $query = $this->db_smartone->query($sql); - $rows = $query->result_array(); - $sql = " - SELECT '0' as id, 'Belum memilih metode' as name - UNION - SELECT M_MethodeSpermaID as id, M_MethodeSpermaName as name - FROM m_methodesperma - WHERE - M_MethodeSpermaIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $methodes = $this->db_smartone->query($sql)->result_array(); - - - $this->sys_ok(["records"=>$rows,"methodes"=>$methodes]); - - } - - - function getpreparasispermaresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT other_preparasisperma.*, - Other_PreparasiSpermaID as xid, - Other_PreparasiSpermaT_OrderDetailID as orderdetail_id, - IFNULL(Other_PreparasiSpermaM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_PreparasiSpermaM_DoctorID) OR Other_PreparasiSpermaM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name, - IFNULL(M_MethodeSpermaID,0) as methode_id, - IFNULL(M_MethodeSpermaName,'') as methode_name - FROM other_preparasisperma - LEFT JOIN m_doctor ON Other_PreparasiSpermaM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - LEFT JOIN m_methodesperma ON Other_PreparasiSpermaM_MethodeSpermaID = M_MethodeSpermaID AND - M_MethodeSpermaIsActive = 'Y' - WHERE - Other_PreparasiSpermaT_OrderDetailID = {$id} AND Other_PreparasiSpermaIsActive = 'Y' - GROUP BY Other_PreparasiSpermaID"; - $query = $this->db_smartone->query($sql); - - if ($query) - { - $rows = $query->row_array(); - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 10 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $sql = " - SELECT '0' as id, 'Belum memilih metode' as name - UNION - SELECT M_MethodeSpermaID as id, M_MethodeSpermaName as name - FROM m_methodesperma - WHERE - M_MethodeSpermaIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $methodes = $this->db_smartone->query($sql)->result_array(); - $images = array(); - $sql = "SELECT Other_PreparasiSpermaImgID as xid, - Other_PreparasiSpermaImgType as type, - CONCAT('/one-media/one-image-nonlab/',Other_PreparasiSpermaImgNewName) as image_url - FROM t_orderdetail - JOIN other_preparasisperma_img ON Other_PreparasiSpermaImgT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND - Other_PreparasiSpermaImgIsActive = 'Y' - WHERE - T_OrderDetailID = {$id} AND - T_OrderDetailIsActive = 'Y' - GROUP BY Other_PreparasiSpermaImgID"; - //echo $sql; - $images = $this->db_smartone->query($sql)->result_array(); - - $rst = array('doctors'=>$doctors,'methodes'=>$methodes,'results'=>$rows,'images'=>$images); - $this->sys_ok(["records"=>$rst]); - } - else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - - function uploadimage_preparasi_sperma(){ - if (! $this->isLogin) { - $this->sys_error("Invalid Token"); - exit; - } - - $userid = $this->sys_user["M_UserID"]; - $data = []; - //print_r($_SERVER); - - $prm = $this->sys_input; - $orderid = $this->input->post('orderid'); - $type = $this->input->post('type'); - $labnumber = $this->input->post('labnumber'); - $sql = "UPDATE other_preparasisperma_img SET - Other_PreparasiSpermaImgIsActive = 'N', - Other_PreparasiSpermaImgUserID = {$userid} - WHERE - Other_PreparasiSpermaImgT_OrderHeaderID = {$orderid} AND - Other_PreparasiSpermaImgType = '{$type}'"; - //echo $sql; - $this->db_onedev->query($sql); - //$config['upload_path'] = 'assets/'; - - $path = '/home/one/project/one/one-media/one-image-nonlab/'; - //echo $path; - $config['upload_path'] = $path; - $config['allowed_types'] = 'jpg|jpeg|png|gif'; - - $config['max_size'] = '10000'; - $count = count($_FILES['files']['name']); - //echo $count; - $this->load->library('upload',$config); - - $error = []; - for($i=0;$i<$count;$i++){ - - - if(!empty($_FILES['files']['name'][$i])){ - - - - $_FILES['file']['name'] = $_FILES['files']['name'][$i]; - - $_FILES['file']['type'] = $_FILES['files']['type'][$i]; - - $_FILES['file']['tmp_name'] = $_FILES['files']['tmp_name'][$i]; - - $_FILES['file']['error'] = $_FILES['files']['error'][$i]; - - $_FILES['file']['size'] = $_FILES['files']['size'][$i]; - - - - $namex = $orderid.'-'.$labnumber.'-'.$this->generateRandomString(5); - //echo $namex; - - $config['file_name'] = $namex; - $this->upload->initialize($config); - //echo $config['file_name'] ; - - - - - - if($this->upload->do_upload('file')){ - - $uploadData = $this->upload->data(); - - $filename = $uploadData['file_name']; - //echo $filename; - - - $sql = "INSERT INTO other_preparasisperma_img ( - Other_PreparasiSpermaImgT_OrderHeaderID, - Other_PreparasiSpermaImgType, - Other_PreparasiSpermaImgOldName, - Other_PreparasiSpermaImgNewName, - Other_PreparasiSpermaImgCreated, - Other_PreparasiSpermaImgUserID - ) - VALUES( - {$orderid}, - '{$type}', - '{$_FILES['files']['name'][$i]}', - '{$filename}', - NOW(), - {$userid} - - )"; - //echo $sql; - $this->db_onedev->query($sql); - $xlast_id = $this->db_onedev->insert_id(); - $data['totalFiles'][] = array('xid' => $xlast_id ,'type'=>$type,'image_url' => '/one-media/one-image-nonlab/'.$filename); - - } - else{ - $error = array('error' => $this->upload->display_errors()); - } - - } - - - - } - - $result = array("total" =>count( $data['totalFiles']), "records" => $data['totalFiles'],'errors'=>$error); - $this->sys_ok($result); - } - - - function saveresult_preparasi_sperma() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = $inp['doctor']; - $orderdetail_id = $inp['orderdetailid']; - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - if($prm['xid'] == '0'){ - $sql = "INSERT INTO other_preparasisperma( - Other_PreparasiSpermaM_DoctorID, - Other_PreparasiSpermaT_OrderDetailID, - Other_PreparasiSpermaPreMotilitasA, - Other_PreparasiSpermaPreMotilitasB, - Other_PreparasiSpermaPreMotilitasC, - Other_PreparasiSpermaPreKonsentrasi, - Other_PreparasiSpermaPreKontaminan, - Other_PreparasiSpermaPostMotilitasA, - Other_PreparasiSpermaPostMotilitasB, - Other_PreparasiSpermaPostMotilitasC, - Other_PreparasiSpermaPostKonsentrasi, - Other_PreparasiSpermaPostKontaminan, - Other_PreparasiSpermaPreVolume, - Other_PreparasiSpermaPostVolume, - Other_PreparasiSpermaM_MethodeSpermaID, - Other_PreparasiSpermaNote, - Other_PreparasiSpermaUserID, - Other_PreparasiSpermaCreated - ) - VALUES( - {$doctor_id}, - {$orderdetail_id}, - '{$prm['Other_PreparasiSpermaPreMotilitasA']}', - '{$prm['Other_PreparasiSpermaPreMotilitasB']}', - '{$prm['Other_PreparasiSpermaPreMotilitasC']}', - '{$prm['Other_PreparasiSpermaPreKonsentrasi']}', - '{$prm['Other_PreparasiSpermaPreKontaminan']}', - '{$prm['Other_PreparasiSpermaPostMotilitasA']}', - '{$prm['Other_PreparasiSpermaPostMotilitasB']}', - '{$prm['Other_PreparasiSpermaPostMotilitasC']}', - '{$prm['Other_PreparasiSpermaPostKonsentrasi']}', - '{$prm['Other_PreparasiSpermaPostKontaminan']}', - '{$prm['Other_PreparasiSpermaPreVolume']}', - '{$prm['Other_PreparasiSpermaPostVolume']}', - '{$prm['Other_PreparasiSpermaM_MethodeSpermaID']}', - '{$prm['Other_PreparasiSpermaNote']}', - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } - else{ - $sql = "SELECT * FROM other_preparasisperma WHERE Other_PreparasiSpermaT_OrderDetailID = {$orderdetail_id} AND Other_PreparasiSpermaIsActive = 'Y'"; - $data_header = $this->db_smartone->query($sql)->row_array(); - $header_id = $data_header['Other_PreparasiSpermaID']; - $sql = "UPDATE other_preparasisperma SET - Other_PreparasiSpermaM_DoctorID = {$doctor_id}, - Other_PreparasiSpermaPreMotilitasA = '{$prm['Other_PreparasiSpermaPreMotilitasA']}', - Other_PreparasiSpermaPreMotilitasB = '{$prm['Other_PreparasiSpermaPreMotilitasB']}', - Other_PreparasiSpermaPreMotilitasC = '{$prm['Other_PreparasiSpermaPreMotilitasC']}', - Other_PreparasiSpermaPreKonsentrasi = '{$prm['Other_PreparasiSpermaPreKonsentrasi']}', - Other_PreparasiSpermaPreKontaminan = '{$prm['Other_PreparasiSpermaPreKontaminan']}', - Other_PreparasiSpermaPostMotilitasA = '{$prm['Other_PreparasiSpermaPostMotilitasA']}', - Other_PreparasiSpermaPostMotilitasB = '{$prm['Other_PreparasiSpermaPostMotilitasB']}', - Other_PreparasiSpermaPostMotilitasC = '{$prm['Other_PreparasiSpermaPostMotilitasC']}', - Other_PreparasiSpermaPostKonsentrasi = '{$prm['Other_PreparasiSpermaPostKonsentrasi']}', - Other_PreparasiSpermaPostKontaminan = '{$prm['Other_PreparasiSpermaPostKontaminan']}', - Other_PreparasiSpermaPreVolume = '{$prm['Other_PreparasiSpermaPreVolume']}', - Other_PreparasiSpermaPostVolume = '{$prm['Other_PreparasiSpermaPostVolume']}', - Other_PreparasiSpermaM_MethodeSpermaID = '{$prm['Other_PreparasiSpermaM_MethodeSpermaID']}', - Other_PreparasiSpermaNote = '{$prm['Other_PreparasiSpermaNote']}', - Other_PreparasiSpermaUserID = {$userid} - WHERE - Other_PreparasiSpermaID = {$header_id}"; - $this->db_smartone->query($sql); - } - - - $result = array("total" => 1, "records" => array(), "sql"=> ''); - $this->sys_ok($result); - exit; - } - - function getdnafragmentasiresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT other_dnafragmentasi.*, - Other_DnaFragmentasiID as xid, - Other_DnaFragmentasiT_OrderDetailID as orderdetail_id, - IFNULL(Other_DnaFragmentasiM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_DnaFragmentasiM_DoctorID) OR Other_DnaFragmentasiM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name, - IFNULL(Other_DnaFragmentasiOther_DnaFragmentasiMethodeID,0) as methode_id, - IFNULL(Other_DnaFragmentasiMethodeName,'') as methode_name, - Other_DnaFragmentasiHaloLuas as halo_luas, - Other_DnaFragmentasiHaloSedang as halo_sedang, - Other_DnaFragmentasiHaloSempit as halo_sempit, - Other_DnaFragmentasiTanpaHalo as tanpa_halo, - Other_DnaFragmentasiDFI as dfi, - Other_DnaFragmentasiKesimpulan as kesimpulan, - Other_DnaFragmentasiCatatan as catatan - FROM other_dnafragmentasi - LEFT JOIN m_doctor ON Other_DnaFragmentasiM_DoctorID = M_DoctorID - LEFT JOIN other_dnafragmentasimethode ON Other_DnaFragmentasiOther_DnaFragmentasiMethodeID = Other_DnaFragmentasiMethodeID - WHERE - Other_DnaFragmentasiT_OrderDetailID = {$id} AND Other_DnaFragmentasiIsActive = 'Y' - GROUP BY Other_DnaFragmentasiID - LIMIT 1"; - //echo $sql; - $query = $this->db_smartone->query($sql); - - if ($query) - { - $rows = $query->row_array(); - if(!$rows){ - $rows = array( - 'xid' => 0, - 'orderdetail_id' =>$id, - 'doctor_id' => 0, - 'doctor_name' => '', - 'methode_id' => 0, - 'methode_name' => '', - 'halo_luas' => '', - 'halo_sedang' => '', - 'tanpa_halo' => '', - 'dfi' => '', - 'kesimpulan' => '', - 'catatan' => '' - ); - } - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID - WHERE - M_DoctorSONat_SubGroupID = 4 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - - $sql = " - SELECT '0' as id, 'Belum memilih metode' as name - UNION - SELECT Other_DnaFragmentasiMethodeID as id, Other_DnaFragmentasiMethodeName as name - FROM other_dnafragmentasimethode - WHERE - Other_DnaFragmentasiMethodeIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $methodes = $this->db_smartone->query($sql)->result_array(); - - - $rst = array('doctors'=>$doctors,'methodes'=>$methodes,'results'=>$rows); - $this->sys_ok(["records"=>$rst]); - } - else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - function saveresult_dnafragmentasi() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = $inp['doctor']['id']; - $methode_id = $inp['methode']['id']; - $orderdetail_id = $inp['results']['orderdetail_id']; - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - if(intval($prm['xid']) == 0){ - $sql = "INSERT INTO other_dnafragmentasi( - Other_DnaFragmentasiT_OrderDetailID, - Other_DnaFragmentasiM_DoctorID, - Other_DnaFragmentasiOther_DnaFragmentasiMethodeID, - Other_DnaFragmentasiHaloLuas, - Other_DnaFragmentasiHaloSedang, - Other_DnaFragmentasiHaloSempit, - Other_DnaFragmentasiTanpaHalo, - Other_DnaFragmentasiDFI, - Other_DnaFragmentasiKesimpulan, - Other_DnaFragmentasiCatatan, - Other_DnaFragmentasiUserID, - Other_DnaFragmentasiLastUpdated - ) - VALUES( - {$orderdetail_id}, - {$doctor_id}, - {$methode_id}, - '{$prm['halo_luas']}', - '{$prm['halo_sedang']}', - '{$prm['halo_sempit']}', - '{$prm['tanpa_halo']}', - '{$prm['dfi']}', - '{$prm['kesimpulan']}', - '{$prm['catatan']}', - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } - else{ - $sql = "UPDATE other_dnafragmentasi SET - Other_DnaFragmentasiT_OrderDetailID = {$orderdetail_id}, - Other_DnaFragmentasiM_DoctorID = {$doctor_id}, - Other_DnaFragmentasiOther_DnaFragmentasiMethodeID = '{$methode_id}', - Other_DnaFragmentasiHaloLuas = '{$prm['halo_luas']}', - Other_DnaFragmentasiHaloSedang = '{$prm['halo_sedang']}', - Other_DnaFragmentasiHaloSempit = '{$prm['halo_sempit']}', - Other_DnaFragmentasiTanpaHalo = '{$prm['tanpa_halo']}', - Other_DnaFragmentasiDFI = '{$prm['dfi']}', - Other_DnaFragmentasiKesimpulan = '{$prm['kesimpulan']}', - Other_DnaFragmentasiCatatan = '{$prm['catatan']}', - Other_DnaFragmentasiLastUpdated = NOW(), - Other_DnaFragmentasiUserID = {$userid} - WHERE - Other_DnaFragmentasiID = {$prm['xid']}"; - //echo $sql; - $this->db_smartone->query($sql); - } - - - $result = array("total" => 1, "records" => array(), "sql"=> ''); - $this->sys_ok($result); - exit; - } - - -} - +db_smartone = $this->load->database("onedev", true); + $this->load->helper(array('form', 'url')); + } + function getMethodeID($natTestID) { + $sql = "select M_MethodePriorityNat_MethodeID MethodeID, Nat_MethodeName + from + m_methode_priority + join nat_methode on Nat_MethodeID = M_MethodePriorityNat_MethodeID + and Nat_MethodeIsActive = 'Y' + join m_instrumentmethode on M_InstrumentMethodeNat_MethodeID = Nat_MethodeID and M_InstrumentMethodeIsActive = 'Y' + join nat_instrument on M_InstrumentMethodeNat_InstrumentID = Nat_InstrumentID + and Nat_InstrumentIsActive ='Y' + where M_MethodePriorityIsActive = 'Y' + and M_MethodePriorityNat_TestID = $natTestID + and M_MethodePriorityM_DayOfWeekID = dayofweek(now()) + order by M_MethodePriorityNumber desc + limit 0,1 "; + $qry = $this->db->query($sql); + if ($qry) { + $rows = $qry->result_array(); + if (count($rows) > 0 ) return array($rows[0]["MethodeID"],$rows[0]["Nat_MethodeName"]); + } + //2nd + $sql= "select + M_InstrumentMethodeNat_MethodeID MethodeID, Nat_MethodeName + from m_instrumentmethode + join nat_methode on M_InstrumentMethodeNat_MethodeID = Nat_MethodeID + and Nat_MethodeIsActive = 'Y' + join nat_instrument on M_InstrumentMethodeNat_InstrumentID = Nat_InstrumentID + and Nat_InstrumentIsActive ='Y' + where M_InstrumentMethodeNat_TestID = $natTestID + and M_InstrumentMethodeIsActive = 'Y' + order by M_InstrumentMethodePriority desc + limit 0,1"; + $qry = $this->db->query($sql); + if ($qry) { + $rows = $qry->result_array(); + if (count($rows) > 0 ) return array($rows[0]["MethodeID"],$rows[0]["Nat_MethodeName"]); + } + // + $sql = "select Nat_NormalValueNat_MethodeID MethodeID, Nat_MethodeName + from + nat_normalvalue + join nat_methode on Nat_NormalValueNat_MethodeID = Nat_MethodeID + and Nat_MethodeIsActive = 'Y' + where Nat_NormalValueNat_TestID = $natTestID + and Nat_NormalValueIsActive = 'Y' + order by Nat_NormalValueID + limit 0,1"; + $qry = $this->db->query($sql); + if ($qry) { + $rows = $qry->result_array(); + if (count($rows) > 0 ) return array($rows[0]["MethodeID"],$rows[0]["Nat_MethodeName"]); + } + return array(0,""); + } + function get_normal_value($methodeID, $natTestID, $sexID, $ageInDay ) { + $this->load->library('ibl_sampling_normal'); + return $this->ibl_sampling_normal->get_normal_value_id($methodeID, $natTestID, $sexID, $ageInDay); + } + return 0; + } + function fn_fix_normal($order_id) { + $sql = "select + T_OrderDetailID, M_PatientM_SexID, fn_global_age_count_day(M_PatientDOB, date(T_OrderHeaderDate)) Dob , + T_TestNat_TestID + from t_orderheader + join m_patient on T_OrderHeaderID = $order_id and T_OrderHeaderM_PatientID = M_PatientID + join t_orderdetail on T_OrderDetailT_OrderHeaderID = T_OrderHeaderID + and T_OrderDetailIsACtive = 'Y' + and ( T_OrderDetailNat_NormalValueID is null or T_OrderDetailNat_NormalValueID = 0 ) + join t_test on T_OrderDetailT_TestID = T_TestID and T_TestIsResult = 'Y' "; + $qry = $this->db->query($sql); + if(! $qry) { + return; + } + $rows = $qry->result_array(); + if(count($rows) == 0 ) return; + $sql_u = "update t_orderdetail + join nat_normalvalue on T_OrderDetailID = ? and Nat_NormalValueID = ? + set + T_OrderDetailNat_NormalValueID = Nat_NormalValueID, + T_OrderDetailNormalValueNote = Nat_NormalValueNote, + T_OrderDetailNormalValueDescription = Nat_NormalValueDescription, + T_OrderDetailMinValue = Nat_NormalValueMinValue, + T_OrderDetailMaxValue = Nat_NormalValueMaxValue, + T_OrderDetailMinValueInclusive = Nat_NormalValueMinValueInclusive, + T_OrderDetailMaxValueInclusive = Nat_NormalValueMaxValueInclusive, + T_OrderDetailNat_MethodeID = ?, + T_OrderdetailNat_MethodeName =?"; + + foreach($rows as $r) { + $T_OrderDetailID = $r["T_OrderDetailID"]; + $sexID = $r["M_PatientM_SexID"]; + $ageInDay = $r["Dob"]; + $natTestID = $r["T_TestNat_TestID"]; + list($methodeID,$methodeName) = $this->getMethodeID($natTestID); + if ($methodeID == 0 ) continue; + $normalValueID = $this->get_normal_value($methodeID, $natTestID, $sexID, $ageInDay); + if ($normalValueID == 0) return; + $this->db->query($sql_u, array($T_OrderDetailID, $normalValueID, $methodeID, $methodeName)); + } + } + + function update_order_sample($targetID, $sourceID) { + $sql = "update t_ordersample target + join t_ordersample source on + target.T_OrderSampleID = ? + and target.T_OrderSampleWorklistReceive = 'N' + and source.T_OrderSampleID = ? + set + target.T_OrderSampleSampling = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSampling, source.T_OrderSampleSampling), + target.T_OrderSampleSamplingDate = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingDate, source.T_OrderSampleSamplingDate), + target.T_OrderSampleSamplingTime = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingTime, source.T_OrderSampleSamplingTime), + target.T_OrderSampleSamplingUserID = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingUserID, source.T_OrderSampleSamplingUserID), + + target.T_OrderSampleReceive = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceive, source.T_OrderSampleReceive), + target.T_OrderSampleReceiveDate = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveDate, source.T_OrderSampleReceiveDate), + target.T_OrderSampleReceiveTime = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveTime, source.T_OrderSampleReceiveTime), + target.T_OrderSampleReceiveUserID = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveUserID, source.T_OrderSampleReceiveUserID), + + target.T_OrderSampleVerification = if(target.T_OrderSampleVerification='Y',target.T_OrderSampleVerification, source.T_OrderSampleVerification), + target.T_OrderSampleVerificationDate =if(target.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationDate, source.T_OrderSampleVerificationDate), + target.T_OrderSampleVerificationTime =if(source.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationTime, source.T_OrderSampleVerificationTime), + target.T_OrderSampleVerificationUserID =if(source.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationUserID, source.T_OrderSampleVerificationUserID), + + target.T_OrderSampleProcessing = if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessing, source.T_OrderSampleProcessing), + target.T_OrderSampleProcessingDate= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingDate, source.T_OrderSampleProcessingDate), + target.T_OrderSampleProcessingTime= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingTime, source.T_OrderSampleProcessingTime), + target.T_OrderSampleProcessingUserID= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingUserID, source.T_OrderSampleProcessingUserID), + + target.T_OrderSampleReceiveHandling =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandling, source.T_OrderSampleReceiveHandling ), + target.T_OrderSampleReceiveHandlingDate =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingDate, source.T_OrderSampleReceiveHandlingDate), + target.T_OrderSampleReceiveHandlingTime =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingTime, source.T_OrderSampleReceiveHandlingTime), + target.T_OrderSampleReceiveHandlingUserID =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingUserID, source.T_OrderSampleReceiveHandlingUserID), + + target.T_OrderSampleHandling = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandling, source.T_OrderSampleHandling), + target.T_OrderSampleHandlingDate = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingDate, source.T_OrderSampleHandlingDate), + target.T_OrderSampleHandlingTime = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingTime, source.T_OrderSampleHandlingTime), + target.T_OrderSampleHandlingUserID = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingUserID, source.T_OrderSampleHandlingUserID), + + target.T_OrderSampleWorklistReceive = source.T_OrderSampleWorklistReceive, + target.T_OrderSampleWorklistReceiveDatetime = source.T_OrderSampleWorklistReceiveDateTime, + target.T_OrderSampleWorklistReceiveUserID = source.T_OrderSampleWorklistReceiveUserID + "; + $qry = $this->db->query($sql,array($targetID,$sourceID)); + if(! $qry ) { + echo json_encode(array( "status" => "ERR" , "message" => print_r($this->db->error(),true))); + exit; + } + } + function fix_sample_serum($headerID) { + //cari t_ordersample yg belum worklist receive dengan code 017% + $sql = "select T_OrderSampleID + from t_ordersample + join t_sampletype on + T_OrderSampleT_OrderHeaderID = ? + and T_OrderSampleWorklistReceive = 'N' + and T_OrderSampleIsActive = 'Y' + and T_OrderSampleT_SampleTypeID = T_SampletypeID + and T_SampleTypeCode like '017%' + "; + $qry = $this->db->query($sql, array($headerID)); + if(!$qry) { + echo json_encode(array( "status" => "ERR" , "message" => print_r($this->db->error(),true))); + exit; + } + $rows = $qry->result_array(); + if (count($rows) == 0 ) return; + //cari T_OrderSample yang sudah di receive yg terakhir + $sql = "select T_OrderSampleID + from t_ordersample + join t_sampletype on + T_OrderSampleT_OrderHeaderID = ? + and T_OrderSampleWorklistReceive = 'Y' + and T_OrderSampleIsActive = 'Y' + and T_OrderSampleT_SampleTypeID = T_SampletypeID + and T_SampleTypeCode like '017%' + order by T_OrderSampleWorklistReceiveDatetime desc + limit 0,1 + "; + $qry = $this->db->query($sql, array($headerID)); + if(!$qry) { + echo json_encode(array( "status" => "ERR" , "message" => print_r($this->db->error(),true))); + exit; + } + $rcv_rows = $qry->result_array(); + if (count($rcv_rows) == 0 ) return; + + //print_r($rows); + //print_r($rcv_rows); + $rcv_T_OrderSampleID = $rcv_rows[0]["T_OrderSampleID"]; + //ada yg belum di receive + foreach($rows as $r) { + $T_OrderSampleID = $r["T_OrderSampleID"]; + $this->update_order_sample($T_OrderSampleID,$rcv_T_OrderSampleID); + } + } + public function search() + { + $prm = $this->sys_input; + $max_rst = 99; + + $id = $prm["order_id"]; + if ($id > 0 ) { + $this->fix_sample_serum($id); + $this->fn_fix_normal($id); + } + $lang = $this->lang_default_code; + $lang_id = isset($prm['lang_id']) ? $prm['lang_id'] : '0'; + + if ($lang_id != 0) + { + $l = $this->db_smartone->where("Nat_LangID", $lang_id)->get("nat_lang")->row(); + $lang = $l->Nat_LangCode; + } + + //tambahan fajri + $sql = " UPDATE t_orderdetail + JOIN t_test ON T_OrderDetailT_TestID = T_TestID + SET T_OrderDetailT_TestIsResult = T_TestIsResult + WHERE + T_OrderDetailT_OrderHeaderID = {$id} AND + T_OrderDetailT_TestIsResult = '' AND + T_OrderDetailIsActive = 'Y'"; + $this->db_smartone->query($sql); + + $tot_count = 0; + $lq = ""; + $group_id = 0; + if (isset($prm['group_id'])) + $group_id = $prm['group_id']; + + if ($group_id != 0) + { + $sql = "select distinct T_WorklistDetailNat_TestID Nat_TestID + from t_worklistdetailv2 + where T_WorklistDetailT_WorklistID = {$group_id}"; + $qry = $this->db_smartone->query($sql); + $rows = $qry->result_array(); + $nat_test_ids = "0"; + foreach($rows as $r) { + $nat_test_ids .= ", " . $r["Nat_TestID"]; + } + $q_group = " ( $nat_test_ids ) "; + + $sql = " + SELECT a1.*, cOUNT(a2.T_OrderDetailID) level + FROM ( + SELECT IFNULL(y.T_OrderDetailT_TestID, x.T_OrderDetailT_TestID) t_testid, + IFNULL(y.T_OrderDetailT_TestName, y.T_OrderDetailT_TestName) t_testname, + y.T_OrderDetailResult result, y.T_OrderDetailResult result_old, y.T_OrderDetailNote note, y.T_OrderDetailNote note_old, + y.T_OrderDetailID id, + y.T_OrderDetailT_TestIsResult is_result, a.T_TestIsQuantitative is_quantitative, + y.T_OrderDetailResultFlag result_flag, + y.T_OrderDetailNat_NormalValueID normal_id, + y.T_OrderDetailNormalValueNote normal_note, y.T_OrderDetailNat_UnitName unit_name, + y.T_OrderdetailNat_MethodeID methode_id, y.T_OrderdetailNat_MethodeName methode_name, + a.T_TestNat_TestID nattest_id, a.T_TestID tx_id, count(T_ResultInstrumentID) as result_instrument_n, + y.T_OrderDetailVerification, T_OrderSampleReceive sample_receive, + T_OrderSampleProcessing sample_processing, T_OrderSampleWorklistReceive sample_worklist_receive, + IF(T_OrderDetailAddOnPreAnalytic = 'Y', T_OrderDetailAddOnPreAnalytic, PreAnalyticIsOk) pre_analytic, + T_OrderDetailAddOnPreAnalytic, + T_OrderHeaderID order_id, y.T_OrderDetailT_TestSasCode test_sas_code, + tx.T_TestSasCode, + T_OrderDetailAddOnResample `resample`, T_OrderDetailAddOnResampleStatus resample_status, + T_OrderDetailAddOnRef ref, y.T_OrderDetailVerification verification, y.T_OrderDetailValidation validation, + T_OrderPromiseDateTime, Group_ResultName as ResultGroupName + FROM t_orderdetail x + left join t_orderpromise on x.T_OrderDetailT_OrderPromiseID = T_OrderPromiseID + JOIN t_test tx ON x.T_OrderDetailT_TestID = T_TestID + JOIN t_test tcheck on tcheck.T_TestNat_TestID in {$q_group} + and ( tx.T_TestID = tcheck.T_TestID or tx.T_TestSasCode like concat(tcheck.T_TestSasCode,'%')) + LEFT JOIN group_resultdetail ON Group_ResultDetailT_TestID = x.T_OrderDetailT_TestID AND Group_ResultDetailIsActive = 'Y' + LEFT JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND Group_ResultFlagNonLab = 'N' + LEFT JOIN t_orderdetail y ON x.T_OrderDetailT_TestSasCode LIKE CONCAT(y.T_OrderDetailT_TestSasCode, '%') + AND x.T_OrderDetailT_OrderHeaderID = y.T_OrderDetailT_OrderHeaderID + AND y.T_OrderDetailIsActive = 'Y' + LEFT JOIN t_orderdetailaddon ON x.T_OrderDetailID = T_OrderDetailAddOnT_OrderDetailID + JOIN t_orderheader ON y.T_OrderDetailT_OrderHeaderID = T_OrderHeaderID + LEFT JOIN t_test a ON y.T_OrderDetailT_TestID = a.T_TestID + AND a.T_TestIsNonLab = '' + LEFT JOIN (SELECT T_OrderSampleT_SampleTypeID, T_OrderSampleReceive, T_OrderSampleProcessing, T_OrderSampleWorklistReceive + FROM t_ordersample WHERE T_OrderSampleT_OrderHeaderID = {$id} + AND T_OrderSampleIsactive = 'Y' + GROUP BY T_OrderSampleT_SampleTypeID) os ON a.T_TestT_SampleTypeID = os.T_OrderSampleT_SampleTypeID + or os.T_OrderSampleT_SampleTypeID = fn_sampletype_from_local(a.T_TestNat_TestID) + + LEFT JOIN t_resultinstrument ON T_ResultInstrumentT_OrderDetailID = x.T_OrderDetailID + LEFT JOIN pre_analytic ON PreAnalyticNat_TestID = a.T_TestNat_TestID AND PreAnalyticDate = date(now()) and PreAnalyticIsActive = 'Y' + WHERE x.T_OrderDetailT_OrderHeaderID = {$id} + AND x.T_OrderDetailIsActive = 'Y' + GROUP BY y.T_OrderDetailT_TestID + ORDER BY y.T_OrderDetailT_TestSasCode ASC + ) a1 + + LEFT JOIN t_orderdetail a2 ON a2.T_OrderDetailT_OrderHeaderID = a1.order_id + AND a2.T_OrderDetailIsActive = 'Y' + AND a1.test_sas_code LIKE CONCAT(a2.T_OrderDetailT_testSasCode, '%') + GROUP BY a1.t_testid + order by a1.test_sas_code +"; + $query = $this->db_smartone->query($sql); + $lq = $this->db_smartone->last_query(); + } + else + { + $sql = " + SELECT a1.*, cOUNT(a2.T_OrderDetailID) level + FROM ( + SELECT IFNULL(y.T_OrderDetailT_TestID, x.T_OrderDetailT_TestID) t_testid, + IFNULL(y.T_OrderDetailT_TestName, y.T_OrderDetailT_TestName) t_testname, + y.T_OrderDetailResult result, y.T_OrderDetailResult result_old, y.T_OrderDetailNote note, y.T_OrderDetailNote note_old, + y.T_OrderDetailID id, + y.T_OrderDetailT_TestIsResult is_result, a.T_TestIsQuantitative is_quantitative, + y.T_OrderDetailResultFlag result_flag, + y.T_OrderDetailNat_NormalValueID normal_id, + y.T_OrderDetailNormalValueNote normal_note, y.T_OrderDetailNat_UnitName unit_name, + y.T_OrderdetailNat_MethodeID methode_id, y.T_OrderdetailNat_MethodeName methode_name, + a.T_TestNat_TestID nattest_id, a.T_TestID tx_id, count(T_ResultInstrumentID) as result_instrument_n, + y.T_OrderDetailVerification, T_OrderSampleReceive sample_receive, + T_OrderSampleProcessing sample_processing, T_OrderSampleWorklistReceive sample_worklist_receive, + IF(T_OrderDetailAddOnPreAnalytic = 'Y', T_OrderDetailAddOnPreAnalytic, PreAnalyticIsOk) pre_analytic, + T_OrderDetailAddOnPreAnalytic, + T_OrderHeaderID order_id, y.T_OrderDetailT_TestSasCode test_sas_code, + tx.T_TestSasCode, + T_OrderDetailAddOnResample `resample`, T_OrderDetailAddOnResampleStatus resample_status, + T_OrderDetailAddOnRef ref, y.T_OrderDetailVerification verification, y.T_OrderDetailValidation validation, + T_OrderPromiseDateTime , Group_ResultName as ResultGroupName + FROM t_orderdetail x + left join t_orderpromise on x.T_OrderDetailT_OrderPromiseID = T_OrderPromiseID + JOIN t_test tx ON x.T_OrderDetailT_TestID = T_TestID + LEFT JOIN group_resultdetail ON Group_ResultDetailT_TestID = x.T_OrderDetailT_TestID AND Group_ResultDetailIsActive = 'Y' + LEFT JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND Group_ResultFlagNonLab = 'N' + LEFT JOIN t_orderdetail y ON x.T_OrderDetailT_TestSasCode LIKE CONCAT(y.T_OrderDetailT_TestSasCode, '%') + AND x.T_OrderDetailT_OrderHeaderID = y.T_OrderDetailT_OrderHeaderID + AND y.T_OrderDetailIsActive = 'Y' + + LEFT JOIN t_orderdetailaddon ON x.T_OrderDetailID = T_OrderDetailAddOnT_OrderDetailID + + JOIN t_orderheader ON y.T_OrderDetailT_OrderHeaderID = T_OrderHeaderID + LEFT JOIN t_test a ON y.T_OrderDetailT_TestID = a.T_TestID + AND a.T_TestIsNonLab = '' + LEFT JOIN (SELECT T_OrderSampleT_SampleTypeID, T_OrderSampleReceive, T_OrderSampleProcessing, T_OrderSampleWorklistReceive + FROM t_ordersample WHERE T_OrderSampleT_OrderHeaderID = {$id} + AND T_OrderSampleIsactive = 'Y' + GROUP BY T_OrderSampleT_SampleTypeID) os ON a.T_TestT_SampleTypeID = os.T_OrderSampleT_SampleTypeID + or os.T_OrderSampleT_SampleTypeID = fn_sampletype_from_local(a.T_TestNat_TestID) + + LEFT JOIN t_resultinstrument ON T_ResultInstrumentT_OrderDetailID = x.T_OrderDetailID + LEFT JOIN pre_analytic ON PreAnalyticNat_TestID = a.T_TestNat_TestID AND PreAnalyticDate = date(now()) and PreAnalyticIsActive = 'Y' + WHERE x.T_OrderDetailT_OrderHeaderID = {$id} + AND x.T_OrderDetailIsActive = 'Y' + GROUP BY y.T_OrderDetailT_TestID + ORDER BY y.T_OrderDetailT_TestSasCode ASC + ) a1 + + LEFT JOIN t_orderdetail a2 ON a2.T_OrderDetailT_OrderHeaderID = a1.order_id + AND a2.T_OrderDetailIsActive = 'Y' + AND a1.test_sas_code LIKE CONCAT(a2.T_OrderDetailT_testSasCode, '%') + GROUP BY a1.t_testid + order by a1.test_sas_code +"; +//echo $sql; + $query = $this->db_smartone->query($sql); + $lq = $this->db_smartone->last_query(); + } + // file_put_contents("/xtmp/re-query.sql",$lq); + + if ($query) { + $rst = []; + $rows = $query->result_array(); + + foreach($rows as $k => $v) + { + + if ($v['is_result'] == "Y" && $v['is_quantitative'] == "N") + { + $v['template'] = []; + $x = $this->db_smartone->query("CALL sp_master_resulttemplate_get('{$v['t_testid']}')"); + $this->clean_mysqli_connection($this->db_smartone->conn_id); + if ($x) + $v['template'] = $x->result_array(); + } + + // IF Rujukan, by pas Pre Analytik + if ($v['ref'] == 'Y') + $v['pre_analytic'] = 'Y'; + if ($v["id"] == "885455" ) + { + //sipe workaround + //$v["sample_receive"] = "Y"; + $v["sample_worklist_receive"] = "Y"; + } + $rst[] = $v; + } + + $result = array("total" => $tot_count, "records" => $rst, "total_display" => sizeof($rows), "q" => $lq); + $this->sys_ok($result); + } + else { + $this->sys_error_db("RE Px rows", $this->db_smartone); + exit; + } + } + + public function save() + { + $prm = $this->sys_input; + $data = json_decode($prm["data"]); + $lang = $this->lang_default_code; + $lang_id = isset($prm['lang_id']) ? $prm['lang_id'] : '0'; + + if ($lang_id != 0) + { + $l = $this->db_smartone->where("Nat_LangID", $lang_id)->get("nat_lang")->row(); + $lang = $l->Nat_LangCode; + } + + $sql_norm = "select T_OrderDetailMinValue, T_OrderDetailMaxValue, + T_OrderDetailMinValueInclusive, T_OrderDetailMaxValueInclusive, + Nat_TestFlagLow, Nat_TestFlagHigh + from t_orderdetail + join t_test on T_OrderDetailT_TestID = T_TestID + join nat_test on T_TestNat_TestID = Nat_TestID and T_TestIsActive = 'Y' + where T_OrderDetailID = ? "; + + $ids = []; + foreach ($data as $k => $v) + { + if ( $v->resultInstrumentID > 0 ) { + $sql_i = "select T_ResultInstrumentNat_NormalValueID normalValueID + from t_resultinstrument + where T_ResultInstrumentID = ?"; + $qry_i = $this->db_smartone->query($sql_i, array($v->resultInstrumentID)); + if ($qry_i) { + $rows_i = $qry_i->result_array(); + + if (count($rows_i) > 0 ) { + $sql_iu = "update t_orderdetail, nat_normalvalue , nat_methode + set T_OrderDetailMinValue = Nat_NormalValueMinValue, + T_OrderDetailMinValueInclusive = Nat_NormalValueMinValueInclusive, + T_OrderDetailMaxValue = Nat_NormalValueMaxValue , + T_OrderDetailMaxValueInclusive = Nat_NormalValueMaxValueInclusive, + T_OrderDetailNormalValueNote = Nat_NormalValueNote, + T_OrderDetailNormalValueDescription = Nat_NormalValueDescription, + T_OrderDetailNat_NormalValueID = Nat_NormalValueID, + T_OrderDetailNat_MethodeID = Nat_NormalValueNat_MethodeID, + T_OrderDetailNat_MethodeName = Nat_MethodeName + where T_OrderDetailID = ? and Nat_NormalValueID = ? + and Nat_NormalValueNat_MethodeID = Nat_MethodeID + "; + $this->db_smartone->query($sql_iu, array($v->id, $rows_i[0]["normalValueID"])); + //file_put_contents("/xtmp/update-nilai-normal", $this->db_smartone->last_query() . "\n", FILE_APPEND); + } + } + } + $y = $this->db_smartone->query("SELECT fn_process_sample_handling_perfect('{$v->order_id}', '{$v->test_id}') c") + ->row(); + $req_status = $y->c; + $qry_norm = $this->db_smartone->query($sql_norm,$v->id); + $result_flag = ""; + if ($qry_norm) { + $rows_norm = $qry_norm->result_array(); + if (count($rows_norm) > 0 ) { + $r = $rows_norm[0]; + if (is_numeric($v->result)) { + + if ( $r["T_OrderDetailMinValueInclusive"] == "Y" && $v->result < $r["T_OrderDetailMinValue"] ) { + $result_flag = $r["Nat_TestFlagLow"]; + } + if ( $r["T_OrderDetailMinValueInclusive"] == "N" && $v->result <= $r["T_OrderDetailMinValue"] ) { + $result_flag = $r["Nat_TestFlagLow"]; + } + if ( $r["T_OrderDetailMaxValueInclusive"] == "Y" && $v->result > $r["T_OrderDetailMaxValue"] ) { + $result_flag = $r["Nat_TestFlagHigh"]; + } + if ( $r["T_OrderDetailMaxValueInclusive"] == "N" && $v->result >= $r["T_OrderDetailMaxValue"] ) { + $result_flag = $r["Nat_TestFlagHigh"]; + } + } + } + } + if ($lang == $this->lang_default_code) + { + $this->db_smartone->set('T_OrderDetailResult', $v->result) + ->set('T_OrderDetailResultFlag', $result_flag) + ->set('T_OrderDetailNote', $v->note) + ->set('T_OrderDetailReqStatus', $req_status) + ->where('T_OrderDetailID', $v->id) + ->update('t_orderdetail'); + } + else + { + $this->db_smartone->set('T_OrderDetailLangResult', $v->result) + ->set('T_OrderDetailLangNote', $v->note) + ->where('T_OrderDetailLangID', $v->id) + ->update('t_orderdetaillang'); + } + + $ids[] = $v->id; + } + + // LOG Process + $order = $this->db_smartone->select('T_OrderDetailT_OrderHeaderID id, T_OrderHeaderLabNumber lab_number', false) + ->join('t_orderheader', 'T_OrderHeaderID = T_OrderDetailT_OrderHeaderID') + ->where('T_OrderDetailID', $data[0]->id) + ->get('t_orderdetail') + ->row(); + + $dblog = $this->load->database("onelog", true); + $dblog->set('Log_ProcessCode', 'PROCESS.Result.Entry') + ->set('Log_ProcessOrderID', $order->id) + ->set('Log_ProcessOrderNumber', $order->lab_number) + ->set('Log_ProcessJson', json_encode($data)) + ->set('Log_ProcessUserID', $this->sys_user['M_UserID']) + ->insert('log_process'); + // END OF Log Process + //auto calculation + $this->load->library("Resultcalc"); + $rows = $this->resultcalc->auto($order->id); + + try { + foreach($ids as $id ) { + $this->db_smartone->query("call sp_set_normal_value_flag($id)"); + $this->clean_mysqli_connection($this->db_smartone->conn_id); + } + } catch(Exception $e) { + } + + $this->sys_ok($ids); + } + + public function save_template() + { + $prm = $this->sys_input; + + $n = $this->db_smartone->select("COUNT(T_ResultTemplateID) n") + ->where("T_ResultTemplateT_TestID", $prm['test_id']) + ->where("T_ResultTemplateIsActive", "Y") + ->where("T_ResultTemplateValue", $prm['value']) + ->get('t_resulttemplate') + ->row(); + if ($n->n > 0) + { + $this->sys_error_db("Insert Result Template", $this->db_smartone); + return; + } + + $r = $this->db_smartone->set("T_ResultTemplateT_TestID", $prm['test_id']) + ->set("T_ResultTemplateValue", $prm['value']) + ->insert('t_resulttemplate'); + if ($r) + { + $template = []; + $x = $this->db_smartone->query("CALL sp_master_resulttemplate_get('{$prm['test_id']}')"); + $this->clean_mysqli_connection($this->db_smartone->conn_id); + if ($x) + $template = $x->result_array(); + + $this->sys_ok($template); + } + } + + public function export() + { + $prm = $this->sys_input; + + $sql = "CALL sp_process_result_lang(?, ?, ?, ?)"; + $query = $this->db_smartone->query($sql, [$prm['order_id'], $prm['lang_id'], $prm['is_si'], $this->sys_user['M_UserID']]); + if ($query) + { + $r = $query->row(); + if ($r->status == "OK") + { + $this->sys_ok($r->data); + return; + } + + $this->sys_error_db("Message : " . $r->message, $this->db_smartone); + } + else + { + $this->sys_error_db("Lang Result", $this->db_smartone); + return; + } + } + + public function search_group() + { + $prm = $this->sys_input; + $max_rst = 100; + + // QUERY TOTAL + $sql = "select count(*) total + from t_worklist + where T_WorklistIsActive = 'Y' + order by T_WorklistName ASC"; + $query = $this->db_smartone->query($sql); + + if ($query) { + $tot_count = $query->result_array()[0]["total"]; + } + else { + $this->sys_error_db("worklist count", $this->db_smartone); + exit; + } + + $sql = "select T_WorklistID group_id, T_WorklistName group_name + from t_worklist + where T_WorklistIsActive = 'Y' + order by T_WorklistName ASC + limit 0, {$max_rst}"; + $query = $this->db_smartone->query($sql); + + if ($query) { + $rows = $query->result_array(); + foreach ($rows as $k => $v) + $rows[$k]['data'] = json_decode($v['data']); + $result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows), "q" => $this->db_smartone->last_query()); + $this->sys_ok($result); + } + else { + $this->sys_error_db("worklist rows", $this->db_smartone); + exit; + } + } + + public function search_rerun() + { + $prm = $this->sys_input; + $id = $prm["detail_id"]; + + $sql = "CALL sp_process_result_rerun(?)"; + $query = $this->db_smartone->query($sql, [$id]); + + if ($query) + { + $rows = $query->result_array(); + $this->sys_ok(["records"=>$rows]); + } + else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + + + function getdoctorsfna() + { + $prm = $this->sys_input; + // $id = $prm["id"]; + + $sql = " SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY M_DoctorName ASC"; + //echo $sql; + $query = $this->db_smartone->query($sql); + + if ($query) + { + $rows = $query->result_array(); + $this->sys_ok(["records"=>$rows]); + } + else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + function getfnaresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT Other_FNADetailsID as xid, + Other_FNAT_OrderDetailID as orderdetail_id, + Other_FNADetailsCode as code, + Other_FNADetailsLabel as label, + Other_FNADetailsResult as result, + IFNULL(Other_FNAM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_FNAM_DoctorID) OR Other_FNAM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_fna + JOIN other_fnadetails ON Other_FNADetailsOther_FNAID = Other_FNAID AND Other_FNADetailsIsActive = 'Y' + LEFT JOIN m_doctor ON Other_FNAM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_FNAT_OrderDetailID = {$id} AND Other_FNAIsActive = 'Y' + GROUP BY Other_FNADetailsID + ORDER BY Other_FNADetailsCode ASC"; + $query = $this->db_smartone->query($sql); + + if ($query) + { + $rows = $query->result_array(); + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $images = array(); + $sql = "SELECT So_ImageUploadID as xid, + CONCAT('/one-media/one-image-nonlab/',So_ImageUploadNewName) as image_url + FROM t_orderdetail + JOIN so_imageupload ON So_ImageUploadT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND + So_ImageUploadIsActive = 'Y' + WHERE + T_OrderDetailID = {$id} AND + T_OrderDetailIsActive = 'Y' + GROUP BY So_ImageUploadID"; + $images = $this->db_smartone->query($sql)->result_array(); + + $rst = array('doctors'=>$doctors,'results'=>$rows,'images'=>$images); + $this->sys_ok(["records"=>$rst]); + } + else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + function getpatologianatomyresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT Other_PatologiAnatomyID as xid, + Other_PatologiAnatomyT_OrderDetailID as orderdetail_id, + Other_PatologiAnatomyNoSediaan as no_sediaan, + Other_PatologiAnatomyDiagnosaKlinis as diagnosa, + Other_PatologiAnatomyKeteranganKlinis as klinis, + Other_PatologiAnatomyLokasiOrgan as lokasi, + Other_PatologiAnatomyMakroskopik as makroskopik, + Other_PatologiAnatomyMikroskopik as mikroskopik, + Other_PatologiAnatomyKesimpulan as kesimpulan, + IFNULL(Other_PatologiAnatomyM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_PatologiAnatomyM_DoctorID) OR Other_PatologiAnatomyM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_patologi_anatomy + LEFT JOIN m_doctor ON Other_PatologiAnatomyM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_PatologiAnatomyT_OrderDetailID = {$id} AND Other_PatologiAnatomyIsActive = 'Y' + GROUP BY Other_PatologiAnatomyID + ORDER BY Other_PatologiAnatomyID ASC + LIMIT 1"; + $query = $this->db_smartone->query($sql); + + if ($query) + { + $rows = $query->row_array(); + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + + $rst = array('doctors'=>$doctors,'result'=>$rows); + $this->sys_ok(["records"=>$rst]); + } + else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + + function uploadimage(){ + if (! $this->isLogin) { + $this->sys_error("Invalid Token"); + exit; + } + + $userid = $this->sys_user["M_UserID"]; + $data = []; + //print_r($_SERVER); + + $prm = $this->sys_input; + $orderid = $this->input->post('orderid'); + $labnumber = $this->input->post('labnumber'); + $sql = "UPDATE so_imageupload SET + So_ImageUploadIsActive = 'N', + So_ImageUploadUserID = {$userid} + WHERE + So_ImageUploadT_OrderHeaderID = {$orderid}"; + //echo $sql; + $this->db_onedev->query($sql); + //$config['upload_path'] = 'assets/'; + + $path = '/home/one/project/one/one-media/one-image-nonlab/'; + //echo $path; + $config['upload_path'] = $path; + $config['allowed_types'] = 'jpg|jpeg|png|gif'; + + $config['max_size'] = '10000'; + $count = count($_FILES['files']['name']); + //echo $count; + $this->load->library('upload',$config); + + $error = []; + for($i=0;$i<$count;$i++){ + + + if(!empty($_FILES['files']['name'][$i])){ + + + + $_FILES['file']['name'] = $_FILES['files']['name'][$i]; + + $_FILES['file']['type'] = $_FILES['files']['type'][$i]; + + $_FILES['file']['tmp_name'] = $_FILES['files']['tmp_name'][$i]; + + $_FILES['file']['error'] = $_FILES['files']['error'][$i]; + + $_FILES['file']['size'] = $_FILES['files']['size'][$i]; + + + + $namex = $orderid.'-'.$labnumber.'-'.$this->generateRandomString(5); + //echo $namex; + + $config['file_name'] = $namex; + $this->upload->initialize($config); + //echo $config['file_name'] ; + + + + + + if($this->upload->do_upload('file')){ + + $uploadData = $this->upload->data(); + + $filename = $uploadData['file_name']; + //echo $filename; + + + $sql = "INSERT INTO so_imageupload ( + So_ImageUploadT_OrderHeaderID, + So_ImageUploadT_OrderHeaderLabNumber, + So_ImageUploadT_SampleTypeID, + So_ImageUploadOldName, + So_ImageUploadNewName, + So_ImageUploadCreated, + So_ImageUploadUserID + ) + VALUES( + {$orderid}, + '{$labnumber}', + '150', + '{$_FILES['files']['name'][$i]}', + '{$filename}', + NOW(), + {$userid} + + )"; + //echo $sql; + $this->db_onedev->query($sql); + $xlast_id = $this->db_onedev->insert_id(); + $data['totalFiles'][] = array('xid' => $xlast_id ,'image_url' => '/one-media/one-image-nonlab/'.$filename); + + } + else{ + $error = array('error' => $this->upload->display_errors()); + } + + } + + + + } + + $result = array("total" =>count( $data['totalFiles']), "records" => $data['totalFiles'],'errors'=>$error); + $this->sys_ok($result); + } + + + function generateRandomString($length = 10) { + $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; + $charactersLength = strlen($characters); + $randomString = ''; + for ($i = 0; $i < $length; $i++) { + $randomString .= $characters[rand(0, $charactersLength - 1)]; + } + return $randomString; + } + + function getcytologiresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT Other_CytologiDetailsID as xid, + Other_CytologiT_OrderDetailID as orderdetail_id, + Other_CytologiDetailsCode as code, + Other_CytologiDetailsLabel as label, + Other_CytologiDetailsResult as result, + IFNULL(Other_CytologiM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_CytologiM_DoctorID) OR Other_CytologiM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_cytologi + JOIN other_cytologidetails ON Other_CytologiDetailsOther_CytologiID = Other_CytologiID AND Other_CytologiDetailsIsActive = 'Y' + LEFT JOIN m_doctor ON Other_CytologiM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_CytologiT_OrderDetailID = {$id} AND Other_CytologiIsActive = 'Y' + GROUP BY Other_CytologiDetailsID + ORDER BY Other_CytologiDetailsCode ASC"; + //echo $sql; + $query = $this->db_smartone->query($sql); + + if ($query) + { + $rows = $query->result_array(); + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $rst = array('doctors'=>$doctors,'results'=>$rows); + $this->sys_ok(["records"=>$rst]); + } + else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + function getmikroresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT + Other_MikroID as xid, + Other_MikroHasilBiakan as hasil_biakan, + Other_MikroSampleTypeName as sample_name, + Other_MikroT_OrderDetailID as orderdetail_id, + Other_MikroResult as result_value, + '' as result_other, + IFNULL(T_BacteriaID,0) as T_BacteriaID, + IFNULL(T_BacteriaName,'') as T_BacteriaName, + '' as details, + IFNULL(Other_MikroM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_MikroM_DoctorID) OR Other_MikroM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_mikro + LEFT JOIN t_bacteria ON Other_MikroT_BacteriaID = T_BacteriaID + LEFT JOIN m_doctor ON Other_MikroM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_MikroT_OrderDetailID = {$id} AND Other_MikroIsActive = 'Y' + GROUP BY Other_MikroID"; + //echo $sql; + $query = $this->db_smartone->query($sql); + + if ($query) + { + $row = $query->row_array(); + if($row){ + if($row['result_value'] != 'Positif' && $row['result_value'] != 'Negatif'){ + $row['result_other'] = $row['result_value']; + $row['result_value'] = 'other'; + } + $sql = "SELECT '' as xno, + Other_MikroDetailsID as xid, + Other_MikroDetailsValue as value, + IF(Other_MikroDetailsNote = 'R','Y','N') as chx_r, + IF(Other_MikroDetailsNote = 'I','Y','N') as chx_i, + IF(Other_MikroDetailsNote = 'S','Y','N') as chx_s, + Other_MikroDetailsNote as note, + t_antibiotic.* + FROM other_mikrodetails + LEFT JOIN t_antibiotic ON Other_MikroDetailsT_AntibioticID = T_AntibioticID + WHERE + Other_MikroDetailsOther_MikroID = {$row['xid']} AND Other_MikroDetailsIsActive = 'Y' + GROUP BY Other_MikroDetailsID + ORDER BY T_AntibioticName ASC"; + //echo $sql; + $details = $this->db_smartone->query($sql)->result_array(); + if(details){ + foreach($details as $k => $v){ + $details[$k]['xno'] = $k + 1; + } + } + $row['details'] = $details; + } + else{ + $row = array('xid'=>'0','hasil_biakan' => '','result_value'=>'Negatif','sample_name' => '','orderdetail_id'=>$id, 'T_BacteriaID'=>'0','T_BacteriaName'=>'0','details'=>array(),'doctor_id'=>'0','doctor_name'=>'0'); + } + } + else{ + $row = array('xid'=>'0','hasil_biakan' => '','result_value'=>'Negatif','sample_name' => '','orderdetail_id'=>$id, 'T_BacteriaID'=>'0','T_BacteriaName'=>'0','details'=>array(),'doctor_id'=>'0','doctor_name'=>'0'); + } + //print_r($row); + + + + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 7 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $sql = " + SELECT '0' as id, 'Belum memilih bakteria' as name + UNION + SELECT T_BacteriaID as id, T_BacteriaName as name + FROM t_bacteria + WHERE + T_BacteriaIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $bacteries = $this->db_smartone->query($sql)->result_array(); + $rst = array('doctors'=>$doctors,'bacteries'=>$bacteries,'results'=>$row); + $this->sys_ok(["records"=>$rst]); + } + function getantibiotics(){ + $prm = $this->sys_input; + $id = $prm["id"]; + $sql = " SELECT '' as xno, + 0 as xid, + '' as hasil_biakan, + '' as sample_name, + 0 as value, + 'Y' as chx_r, + 'N' as chx_i, + 'N' as chx_s, + 'R' as note, + t_antibiotic.* + FROM t_antibiotic + WHERE + T_AntibioticT_BacteriaID = {$prm['id']} AND T_AntibioticIsActive= 'Y' + ORDER BY T_AntibioticName ASC"; + //echo $sql; + $rows = $this->db_smartone->query($sql)->result_array(); + if(rows){ + foreach($rows as $k => $v){ + $rows[$k]['xno'] = $k + 1; + } + } + + $this->sys_ok(["records"=>$rows]); + } + function getlcprepresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + $sql = " SELECT Other_LcprepDetailsID as xid, + Other_LcprepID as header_id, + Other_LcprepT_orderDetailID as orderdetail_id, + Other_LcprepDetailsCode as code, + Other_LcprepDetailsLabel as label, + Other_LcprepDetailsResult as result, + IFNULL(Other_LcprepM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_LcprepM_DoctorID) OR Other_LcprepM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_lcprep + JOIN other_lcprepdetails ON Other_LcprepDetailsOther_LcprepID = Other_LcprepID AND Other_LcprepDetailsIsActive = 'Y' + LEFT JOIN m_doctor ON Other_LcprepM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_LcprepT_orderDetailID = {$id} AND Other_LcprepIsActive = 'Y' + GROUP BY Other_LcprepDetailsOther_LcprepID, Other_LcprepDetailsCode + ORDER BY Other_LcprepDetailsCode ASC"; + //echo $sql; + $rows = $this->db_smartone->query($sql)->result_array(); + if(!$rows){ + $rows = array( + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'A', + 'label' => 'DESKRIPSI', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ), + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'B', + 'label' => 'KESIMPULAN', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ) + ); + } + + $header_id = $rows[0]['header_id']; + $sql = "SELECT IFNULL(Other_LcprepAdekuasiID,0) as xid, + Lcprep_AdekuasiID as id, + Lcprep_AdekuasiLabel as name, + IF(ISNULL(Other_LcprepAdekuasiID),'N',Other_LcprepAdekuasiChex) as chex + FROM lcprep_adekuasi + LEFT JOIN other_lcprepadekuasi ON Other_LcprepAdekuasiLcprep_AdekuasiID = Lcprep_AdekuasiID AND + Other_LcprepAdekuasiOther_LcprepID = {$header_id} AND + Other_LcprepAdekuasiIsActive = 'Y' + WHERE + Lcprep_AdekuasiIsActive = 'Y' + GROUP BY Lcprep_AdekuasiID + ORDER BY Lcprep_AdekuasiOrder ASC + "; + //echo $sql; + $adeakuasi = $this->db_smartone->query($sql)->result_array(); + foreach($adeakuasi as $kc => $vc){ + $adeakuasi[$kc]['chex'] = $vc['chex'] == 'N'?false:true; + } + + $sql = "SELECT IFNULL(Other_LcprepKategoriUmumID,0) as xid, + Lcprep_KategoriUmumID as id, + Lcprep_KategoriUmumLabel as name, + IF(ISNULL(Other_LcprepKategoriUmumID),'N',Other_LcprepKategoriUmumChex) as chex + FROM lcprep_kategoriumum + LEFT JOIN other_lcprepkategoriumum ON Other_LcprepKategoriUmumLcprep_KategoriUmumID = Lcprep_KategoriUmumID AND + Other_LcprepKategoriUmumOther_LcprepID = {$header_id} AND + Other_LcprepKategoriUmumIsActive = 'Y' + WHERE + Lcprep_KategoriUmumIsActive = 'Y' + GROUP BY Lcprep_KategoriUmumID + "; + //echo $sql; + $kategoriumum = $this->db_smartone->query($sql)->result_array(); + foreach($kategoriumum as $kc => $vc){ + $kategoriumum[$kc]['chex'] = $vc['chex'] == 'N'?false:true; + } + + $sql = " + SELECT Lcprep_InterpretasiGroupID as group_id, + Lcprep_InterpretasiGroupName as group_name, + '' as subgroups + FROM lcprep_interpretasigroup + WHERE + Lcprep_InterpretasiGroupIsActive = 'Y' + "; + //echo $sql; + $interpretasi = $this->db_smartone->query($sql)->result_array(); + foreach($interpretasi as $k => $v){ + $subgroups = array(); + $sql = "SELECT Lcprep_InterpretasiSubgroupID as subgroup_id, + Lcprep_InterpretasiSubgroupName as subgroup_name, + '' as childs + FROM lcprep_interpretasisubgroup + WHERE + Lcprep_InterpretasiSubgroupLcprep_InterpretasiGroupID = {$v['group_id']} AND Lcprep_InterpretasiSubgroupIsActive = 'Y'"; + //echo $sql; + $subgroups = $this->db_smartone->query($sql)->result_array(); + if(count($subgroups) > 0){ + foreach($subgroups as $ki => $vi){ + $childs = array(); + $sql = "SELECT IFNULL(Other_LcprepInterpretasiID,0) as xid, + IFNULL(Other_LcprepInterpretasiChex,'N') as chex, + IFNULL(Other_LcprepInterpretasiValue,'') as value, + Lcprep_InterpretasiID as id, + Lcprep_InterpretasiLcprep_InterpretasiSubgroupID as subgroup_id, + Lcprep_InterpretasiCode as code, + Lcprep_InterpretasiName as name, + Lcprep_InterpretasiParentID as parent_id, + Lcprep_InterpretasiIsParent as is_parent, + Lcprep_InterpretasiHasResult as has_result, + Lcprep_InterpretasiTypeResult as type_result + FROM lcprep_interpretasi + LEFT JOIN other_lcprepinterpretasi ON Other_LcprepInterpretasiOther_LcprepID = {$header_id} AND + Other_LcprepInterpretasiLcprep_InterpretasiID = Lcprep_InterpretasiID AND + Other_LcprepInterpretasiIsActive = 'Y' + WHERE + Lcprep_InterpretasiLcprep_InterpretasiSubgroupID = {$vi['subgroup_id']} AND Lcprep_InterpretasiIsActive = 'Y' + GROUP BY Lcprep_InterpretasiID Order BY Lcprep_InterpretasiCode ASC"; + $childs = $this->db_smartone->query($sql)->result_array(); + if($childs){ + foreach($childs as $kc => $vc){ + $childs[$kc]['chex'] = $vc['chex'] == 'N'?false:true; + } + } + $subgroups[$ki]['childs'] = $childs; + } + } + + $interpretasi[$k]['subgroups'] = $subgroups; + } + + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $rst = array('doctors'=>$doctors,'results'=>$rows,'adekuasi'=>$adeakuasi,'kategoriumum'=>$kategoriumum,'interpretasi'=>$interpretasi); + $this->sys_ok(["records"=>$rst]); + } + + function getpapsmearresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT Other_PapSmearDetailsID as xid, + Other_PapSmearID as header_id, + Other_PapSmearT_OrderDetailID as orderdetail_id, + Other_PapSmearDetailsCode as code, + Other_PapSmearDetailsLabel as label, + Other_PapSmearDetailsResult as result, + IFNULL(Other_PapSmearM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_PapSmearM_DoctorID) OR Other_PapSmearM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_papsmear + JOIN other_papsmeardetails ON Other_PapSmearDetailsOther_PapSmearID = Other_PapSmearID AND Other_PapSmearDetailsIsActive = 'Y' + LEFT JOIN m_doctor ON Other_PapSmearM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_PapSmearT_OrderDetailID = {$id} AND Other_PapSmearIsActive = 'Y' + GROUP BY Other_PapSmearDetailsID + ORDER BY Other_PapSmearDetailsCode ASC"; + //echo $sql; + $rows = $this->db_smartone->query($sql)->result_array(); + if(!$rows){ + $rows = array( + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'A', + 'label' => 'Makroskopik', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ), + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'B', + 'label' => 'Mikroskopik', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ), + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'C', + 'label' => 'Kesimpulan', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ) + ); + } + + $header_id = $rows[0]['header_id']; + $sql = "SELECT Other_PapSmearMaturasiID as xid, + Other_PapSmearMaturasiValue as value + FROM other_papsmearmaturasi + WHERE + Other_PapSmearMaturasiOther_PapSmearID = {$header_id} AND + Other_PapSmearMaturasiIsActive = 'Y' + "; + //echo $sql; + $dt_maturasi = $this->db_smartone->query($sql)->row_array(); + if(!$dt_maturasi){ + $maturasi = array('xid'=>'0','value'=> array('','','')); + } + else{ + $value = explode('/',$dt_maturasi['value']); + $maturasi = array('xid'=>$dt_maturasi['xid'],'value'=> $value); + } + + $sql = "SELECT IFNULL(Other_PapSmearBahanID,0) as xid, + M_PapSmearBahanID as bahan_id, + M_PapSmearBahanName as name, + IF(ISNULL(Other_PapSmearBahanID),'N','Y') as selected + FROM m_papsmearbahan + LEFT JOIN other_papsmearbahan ON Other_PapSmearBahanM_PapSmearBahanID = M_PapSmearBahanID AND + Other_PapSmearBahanOther_PapSmearID = {$header_id} AND + Other_PapSmearBahanIsActive = 'Y' + WHERE + M_PapSmearBahanIsActive = 'Y' + ORDER BY M_PapSmearBahanID ASC + "; + //echo $sql; + $bahans = $this->db_smartone->query($sql)->result_array(); + + $sql = "SELECT IFNULL(Other_PapsmearCategoryID,0) as xid, + M_PapSmearCategoryID as category_id, + M_PapSmearCategoryName as name, + IF(ISNULL(Other_PapsmearCategoryID),'N','Y') as selected + FROM m_papsmearcategory + LEFT JOIN other_papsmearcategory ON Other_PapsmearCategoryM_PapSmearCategoryID = M_PapSmearCategoryID AND + Other_PapsmearCategoryOther_PapSmearID = {$header_id} AND + Other_PapsmearCategoryIsActive = 'Y' + WHERE + M_PapSmearCategoryIsActive = 'Y' + ORDER BY M_PapSmearCategoryID ASC + "; + //echo $sql; + $categories = $this->db_smartone->query($sql)->result_array(); + + $sql = "SELECT IFNULL(Other_PapSmearCheckID,0) as xid, + M_PapSmearCheckID as check_id, + M_PapSmearCheckLabel as name, + IF(ISNULL(Other_PapSmearCheckID),'N','Y') as selected, + Other_PapSmearCheckNote as note + FROM m_papsmearcheck + LEFT JOIN other_papsmearcheck ON Other_PapSmearCheckM_PapSmearCheckID = M_PapSmearCheckID AND + Other_PapSmearCheckOther_PapSmearID = {$header_id} AND + Other_PapSmearCheckIsActive = 'Y' + WHERE + M_PapSmearCheckIsActive = 'Y' + ORDER BY M_PapSmearCheckCode ASC + "; + $checks = $this->db_smartone->query($sql)->result_array(); + + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $rst = array('doctors'=>$doctors,'checks'=>$checks,'bahans'=>$bahans,'categories'=>$categories,'maturasi'=>$maturasi,'results'=>$rows); + $this->sys_ok(["records"=>$rst]); + + } + + function saveresult_lcprep() + { + $prm = $this->sys_input; + $detail_id = $prm['detail_id']; + $doctor_id = $prm['doctor']; + $adekuasi = $prm['adekuasi']; + $kategoriumum = $prm['kategoriumum']; + $interpretasi = $prm['interpretasi']; + $results = $prm['results']; + + $userid = $this->sys_user['M_UserID']; + + $header_id = 0; + $sql = "SELECT * FROM other_lcprep WHERE Other_LcprepT_orderDetailID = {$detail_id} AND Other_LcprepIsActive = 'Y'"; + $dt_header = $this->db_smartone->query($sql)->row_array(); + if($dt_header){ + $header_id = $dt_header['Other_LcprepID']; + } + if($header_id == 0){ + $sql = "INSERT INTO other_lcprep( + Other_LcprepT_orderDetailID, + Other_LcprepM_DoctorID, + Other_LcprepUserID, + Other_LcprepCreated + ) + VALUES( + {$detail_id}, + {$doctor_id}, + {$userid}, + NOW() + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + }else{ + $sql = "UPDATE other_lcprep SET Other_LcprepM_DoctorID = {$doctor_id}, Other_LcprepUserID = {$userid} WHERE Other_LcprepID = {$header_id}"; + $this->db_smartone->query($sql); + } + + if($adekuasi){ + foreach($adekuasi as $k =>$v){ + $selected = $v['chex']?'Y':'N'; + if(intval($v['xid'] == 0)){ + $sql = "UPDATE other_lcprepadekuasi SET Other_LcprepAdekuasiIsActive = 'N' + WHERE + Other_LcprepAdekuasiOther_LcprepID = {$header_id} AND + Other_LcprepAdekuasiIsActive = 'Y' AND + Other_LcprepAdekuasiLcprep_AdekuasiID = {$v['id']}"; + $this->db_smartone->query($sql); + $sql = "INSERT INTO other_lcprepadekuasi ( + Other_LcprepAdekuasiOther_LcprepID, + Other_LcprepAdekuasiLcprep_AdekuasiID, + Other_LcprepAdekuasiChex, + Other_LcprepAdekuasiUserID, + Other_LcprepAdekuasiCreated + ) + VALUES( + {$header_id}, + {$v['id']}, + '{$selected}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + //echo $sql; + } + if(intval($v['xid'] != 0)){ + + $sql = "UPDATE other_lcprepadekuasi SET + Other_LcprepAdekuasiChex = '{$selected}', + Other_LcprepAdekuasiUserID = {$userid} + WHERE + Other_LcprepAdekuasiID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + + //echo $sql; + } + } + + if($kategoriumum){ + foreach($kategoriumum as $k =>$v){ + $selected = $v['chex']?'Y':'N'; + if(intval($v['xid'] == 0)){ + $sql = "UPDATE other_lcprepkategoriumum SET Other_LcprepKategoriUmumIsActive = 'N' + WHERE + Other_LcprepKategoriUmumOther_LcprepID = {$header_id} AND + Other_LcprepKategoriUmumLcprep_KategoriUmumID = {$v['id']} AND + Other_LcprepKategoriUmumIsActive = 'Y' + "; + $this->db_smartone->query($sql); + $sql = "INSERT INTO other_lcprepkategoriumum ( + Other_LcprepKategoriUmumOther_LcprepID, + Other_LcprepKategoriUmumLcprep_KategoriUmumID, + Other_LcprepKategoriUmumChex, + Other_LcprepKategoriUmumUserID, + Other_LcprepKategoriUmumCreated + ) + VALUES( + {$header_id}, + {$v['id']}, + '{$selected}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if(intval($v['xid'] != 0)){ + $sql = "UPDATE other_lcprepkategoriumum SET + Other_LcprepKategoriUmumChex = '{$selected }', + Other_LcprepKategoriUmumUserID = {$userid} + WHERE + Other_LcprepKategoriUmumID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + + //echo $sql; + } + } + + if($results){ + foreach($results as $k =>$v){ + if(intval($v['xid'] == 0)){ + $sql = "UPDATE other_lcprepdetails SET Other_LcprepDetailsIsActive = 'N' + WHERE + Other_LcprepDetailsOther_LcprepID = {$header_id} AND + Other_LcprepDetailsCode = '{$v['code']}' AND + Other_LcprepDetailsIsActive = 'Y'"; + $this->db_smartone->query($sql); + $sql = "INSERT INTO other_lcprepdetails ( + Other_LcprepDetailsOther_LcprepID, + Other_LcprepDetailsCode, + Other_LcprepDetailsLabel, + Other_LcprepDetailsResult, + Other_LcprepDetailsUserID, + Other_LcprepDetailsCreated + ) + VALUES( + {$header_id}, + '{$v['code']}', + '{$v['label']}', + '{$v['result']}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if(intval($v['xid'] != 0)){ + $sql = "UPDATE other_lcprepdetails SET + Other_LcprepDetailsCode = '{$v['code']}', + Other_LcprepDetailsLabel = '{$v['label']}', + Other_LcprepDetailsResult = '{$v['result']}', + Other_LcprepDetailsUserID = {$userid} + WHERE + Other_LcprepDetailsID = {$v['xid']}"; + $this->db_smartone->query($sql); + + } + //echo $sql; + } + } + + if($interpretasi){ + foreach($interpretasi as $k =>$v){ + if(count($v['subgroups']) > 0){ + foreach($v['subgroups'] as $ik => $iv){ + if(count($iv['childs']) > 0){ + foreach($iv['childs'] as $iik => $iiv){ + if(intval($iiv['xid'] == 0)){ + $chex = $iiv['chex'] ? 'Y':'N'; + $sql = "UPDATE other_lcprepinterpretasi SET Other_LcprepInterpretasiIsActive = 'N' + WHERE + Other_LcprepInterpretasiOther_LcprepID = {$header_id} AND + Other_LcprepInterpretasiLcprep_InterpretasiID = '{$iiv['id']}' AND + Other_LcprepInterpretasiIsActive = 'Y'"; + $this->db_smartone->query($sql); + $sql = "INSERT INTO other_lcprepinterpretasi ( + Other_LcprepInterpretasiOther_LcprepID, + Other_LcprepInterpretasiLcprep_InterpretasiID, + Other_LcprepInterpretasiChex, + Other_LcprepInterpretasiValue, + Other_LcprepInterpretasiUserID, + Other_LcprepInterpretasiCreated + ) + VALUES( + {$header_id}, + '{$iiv['id']}', + '{$chex}', + '{$iiv['value']}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + + if(intval($iiv['xid'] != 0)){ + $chex = $iiv['chex'] ? 'Y':'N'; + $sql = "UPDATE other_lcprepinterpretasi SET + Other_LcprepInterpretasiChex = '{$chex}', + Other_LcprepInterpretasiValue = '{$iiv['value']}', + Other_LcprepInterpretasiUserID = {$userid} + WHERE + Other_LcprepInterpretasiID = {$iiv['xid']}"; + $this->db_smartone->query($sql); + //echo $sql; + + } + + } + } + } + } + //echo $sql; + } + } + + + $result = array("total" => 1, "records" => array(), "sql"=> ''); + $this->sys_ok($result); + exit; + } + + function saveresult_papsmear() + { + $prm = $this->sys_input; + $detail_id = $prm['detail_id']; + $doctor_id = $prm['doctor']; + $checks = $prm['checks']; + $maturasi = $prm['maturasi']; + $bahans = $prm['bahans']; + $categories = $prm['categories']; + $results = $prm['results']; + + $userid = $this->sys_user['M_UserID']; + + $header_id = 0; + $sql = "SELECT * FROM other_papsmear WHERE Other_PapSmearT_OrderDetailID = {$detail_id} AND Other_PapSmearIsActive = 'Y'"; + $dt_header = $this->db_smartone->query($sql)->row_array(); + if($dt_header){ + $header_id = $dt_header['Other_PapSmearID']; + } + if($header_id == 0){ + $sql = "INSERT INTO other_papsmear( + Other_PapSmearT_OrderDetailID, + Other_PapSmearM_DoctorID, + Other_PapSmearUserID, + Other_PapSmearCreated + ) + VALUES( + {$detail_id}, + {$doctor_id}, + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } + else{ + $sql = "UPDATE other_papsmear SET Other_PapSmearM_DoctorID = {$doctor_id}, Other_PapSmearUserID = {$userid} WHERE Other_PapSmearID = {$header_id}"; + $this->db_smartone->query($sql); + } + + if($checks){ + foreach($checks as $k =>$v){ + if(intval($v['xid']) == 0 && $v['selected'] === 'Y'){ + $sql = "INSERT INTO other_papsmearcheck ( + Other_PapSmearCheckOther_PapSmearID, + Other_PapSmearCheckM_PapSmearCheckID, + Other_PapSmearCheckNote, + Other_PapSmearCheckUserID, + Other_PapSmearCheckCreated + ) + VALUES( + {$header_id}, + {$v['check_id']}, + '{$v['note']}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if(intval($v['xid']) != 0 && $v['selected'] === 'N'){ + $sql = "UPDATE other_papsmearcheck SET + Other_PapSmearCheckIsActive = 'N', + Other_PapSmearCheckUserID = {$userid} + WHERE + Other_PapSmearCheckID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + if(intval($v['xid']) != 0 && $v['selected'] === 'Y'){ + $sql = "UPDATE other_papsmearcheck SET + Other_PapSmearCheckNote = '{$v['note']}', + Other_PapSmearCheckUserID = {$userid} + WHERE + Other_PapSmearCheckID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + //echo $sql; + } + } + + if($maturasi){ + if(intval($maturasi['xid']) == 0){ + $value = join("/",$maturasi['value']); + $sql = "INSERT INTO other_papsmearmaturasi ( + Other_PapSmearMaturasiOther_PapSmearID, + Other_PapSmearMaturasiValue, + Other_PapSmearMaturasiUserID, + Other_PapSmearMaturasiCreated + ) + VALUE( + {$header_id}, + '{$value}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + //echo $sql; + } + if(intval($maturasi['xid']) != 0){ + $value = join("/",$maturasi['value']); + $sql = "UPDATE other_papsmearmaturasi SET + Other_PapSmearMaturasiValue = '{$value}', + Other_PapSmearMaturasiUserID = {$userid} + WHERE + Other_PapSmearMaturasiID = {$maturasi['xid']}"; + // echo $sql; + $this->db_smartone->query($sql); + } + } + + if($bahans){ + foreach($bahans as $k =>$v){ + if(intval($v['xid']) == 0 && $v['selected'] === 'Y'){ + $sql = "INSERT INTO other_papsmearbahan ( + Other_PapSmearBahanOther_PapSmearID, + Other_PapSmearBahanM_PapSmearBahanID, + Other_PapSmearBahanUserID, + Other_PapSmearBahanCreated + ) + VALUES( + {$header_id}, + {$v['bahan_id']}, + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if(intval($v['xid']) != 0 && $v['selected'] === 'N'){ + $sql = "UPDATE other_papsmearbahan SET + Other_PapSmearBahanIsActive = 'N', + Other_PapsmearCategoryUserID = {$userid} + WHERE + Other_PapSmearBahanID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + if(intval($v['xid']) != 0 && $v['selected'] === 'Y'){ + $sql = "UPDATE other_papsmearbahan SET + Other_PapSmearBahanIsActive = 'Y', + Other_PapsmearCategoryUserID = {$userid} + WHERE + Other_PapSmearBahanID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + //echo $sql; + } + } + + if($categories){ + foreach($categories as $k =>$v){ + if(intval($v['xid']) == 0 && $v['selected'] === 'Y'){ + $sql = "INSERT INTO other_papsmearcategory ( + Other_PapsmearCategoryOther_PapSmearID, + Other_PapsmearCategoryM_PapSmearCategoryID, + Other_PapsmearCategoryUserID, + Other_PapsmearCategoryCreated + ) + VALUES( + {$header_id}, + {$v['category_id']}, + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if(intval($v['xid']) != 0 && $v['selected'] === 'N'){ + $sql = "UPDATE other_papsmearcategory SET + Other_PapsmearCategoryIsActive = 'N', + Other_PapsmearCategoryUserID = {$userid} + WHERE + Other_PapsmearCategoryID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + //echo $sql; + if(intval($v['xid']) != 0 && $v['selected'] === 'Y'){ + $sql = "UPDATE other_papsmearcategory SET + Other_PapsmearCategoryIsActive = 'Y', + Other_PapsmearCategoryUserID = {$userid} + WHERE + Other_PapsmearCategoryID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + } + } + + if($results){ + foreach($results as $k =>$v){ + if(intval($v['xid']) == 0){ + $sql = "INSERT INTO other_papsmeardetails ( + Other_PapSmearDetailsOther_PapSmearID, + Other_PapSmearDetailsCode, + Other_PapSmearDetailsLabel, + Other_PapSmearDetailsResult, + Other_PapSmearDetailsUserID, + Other_PapSmearDetailsCreated + ) + VALUES( + {$header_id}, + '{$v['code']}', + '{$v['label']}', + '{$v['result']}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if(intval($v['xid']) != 0){ + $sql = "UPDATE other_papsmeardetails SET + Other_PapSmearDetailsCode = '{$v['code']}', + Other_PapSmearDetailsLabel = '{$v['label']}', + Other_PapSmearDetailsResult = '{$v['result']}', + Other_PapSmearDetailsUserID = {$userid} + WHERE + Other_PapSmearDetailsID = {$v['xid']}"; + $this->db_smartone->query($sql); + + } + //echo $sql; + } + } + + $result = array("total" => 1, "records" => array(), "sql"=> ''); + $this->sys_ok($result); + exit; + } + + function saveresult_fna() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = $inp['doctor']; + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + if($prm[0]['xid'] == '0'){ + $sql = "INSERT INTO other_fna( + Other_FNAM_DoctorID, + Other_FNAT_OrderDetailID, + Other_FNAUserID, + Other_FNACreated + ) + VALUES( + {$doctor_id}, + {$prm[0]['orderdetail_id']}, + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } + else{ + $sql = "SELECT * FROM other_fna WHERE Other_FNAT_OrderDetailID = {$prm[0]['orderdetail_id']} AND Other_FNAIsActive = 'Y'"; + $data_header = $this->db_smartone->query($sql)->row_array(); + $header_id = $data_header['Other_FNAID']; + $sql = "UPDATE other_fna SET + Other_FNAM_DoctorID = {$doctor_id}, + Other_FNAUserID = {$userid} + WHERE + Other_FNAID = {$header_id}"; + $this->db_smartone->query($sql); + } + foreach($prm as $k => $v){ + if($v['xid'] == '0'){ + $results = str_replace("'", "\\'", $v['result']); + $sql = "INSERT INTO other_fnadetails( + Other_FNADetailsOther_FNAID , + Other_FNADetailsCode, + Other_FNADetailsLabel, + Other_FNADetailsResult, + Other_FNADetailsCreated, + Other_FNADetailsUserID + ) + VALUES( + {$header_id}, + '{$v['code']}', + '{$v['label']}', + '{$results}', + NOW(), + {$userid} + )"; + $query = $this->db_smartone->query($sql); + } + else{ + $results = str_replace("'", "\\'", $v['result']); + $sql = "UPDATE other_fnadetails SET + Other_FNADetailsResult = '{$results}', + Other_FNADetailsUserID = {$userid} + WHERE + Other_FNADetailsID = {$v['xid']}"; + $query = $this->db_smartone->query($sql); + } + } + + $result = array("total" => 1, "records" => array(), "sql"=> ''); + $this->sys_ok($result); + exit; + } + + function saveresult_cytologi() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = $inp['doctor']; + + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + if($prm[0]['xid'] == '0'){ + $sql = "INSERT INTO other_cytologi( + Other_CytologiT_OrderDetailID, + Other_CytologiM_DoctorID, + Other_CytologiUserID, + Other_CytologiCreated + ) + VALUES( + {$prm[0]['orderdetail_id']}, + {$doctor_id}, + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } + else{ + $sql = "SELECT * FROM other_cytologi WHERE Other_CytologiT_OrderDetailID = {$prm[0]['orderdetail_id']} AND Other_CytologiIsActive = 'Y'"; + $data_header = $this->db_smartone->query($sql)->row_array(); + $header_id = $data_header['Other_CytologiID']; + $sql = "UPDATE other_cytologi SET + Other_CytologiM_DoctorID = {$doctor_id}, + Other_CytologiUserID = {$userid} + WHERE + Other_CytologiID = {$header_id}"; + $this->db_smartone->query($sql); + } + foreach($prm as $k => $v){ + if($v['xid'] == '0'){ + $results = str_replace("'", "\\'", $v['result']); + $sql = "INSERT INTO other_cytologidetails( + Other_CytologiDetailsOther_CytologiID , + Other_CytologiDetailsCode, + Other_CytologiDetailsLabel, + Other_CytologiDetailsResult, + Other_CytologiDetailsCreated, + Other_CytologiDetailsUserID + ) + VALUES( + {$header_id}, + '{$v['code']}', + '{$v['label']}', + '{$results}', + NOW(), + {$userid} + )"; + $query = $this->db_smartone->query($sql); + } + else{ + $results = str_replace("'", "\\'", $v['result']); + $sql = "UPDATE other_cytologidetails SET + Other_CytologiDetailsResult = '{$results}', + Other_CytologiDetailsUserID = {$userid} + WHERE + Other_CytologiDetailsID = {$v['xid']}"; + $query = $this->db_smartone->query($sql); + } + } + + $result = array("total" => 1, "records" => array(), "sql"=> ''); + $this->sys_ok($result); + exit; + } + + function saveresult_mikro() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = $inp['doctor']; + $backteria_id = $inp['bacteria']; + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + + if($inp['result_value'] != 'Negatif' && $inp['result_value'] != 'Positif'){ + $prm['result_value'] = $prm['result_other']; + } + else{ + $prm['result_value'] = $inp['result_value']; + } + + if($prm['xid'] == '0'){ + $sql = "INSERT INTO other_mikro( + Other_MikroM_DoctorID, + Other_MikroResult, + Other_MikroT_BacteriaID, + Other_MikroT_OrderDetailID, + Other_MikroHasilBiakan, + Other_MikroSampleTypeName, + Other_MikroUserID, + Other_MikroCreated + ) + VALUES( + {$doctor_id}, + '{$prm['result_value']}', + {$backteria_id}, + {$prm['orderdetail_id']}, + '{$prm['hasil_biakan']}', + '{$prm['sample_name']}', + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } + else{ + $sql = "SELECT * FROM other_mikro WHERE Other_MikroT_OrderDetailID = {$prm['orderdetail_id']} AND Other_MikroIsActive = 'Y'"; + $data_header = $this->db_smartone->query($sql)->row_array(); + $header_id = $data_header['Other_MikroID']; + $sql = "UPDATE other_mikro SET + Other_MikroResult = '{$prm['result_value']}', + Other_MikroM_DoctorID = {$doctor_id}, + Other_MikroT_BacteriaID = {$backteria_id}, + Other_MikroHasilBiakan = '{$prm['hasil_biakan']}', + Other_MikroSampleTypeName = '{$prm['sample_name']}', + Other_MikroUserID = {$userid} + WHERE + Other_MikroID = {$header_id}"; + //echo $sql; + $this->db_smartone->query($sql); + } + + + + $sql = "UPDATE other_mikrodetails SET Other_MikroDetailsIsActive = 'N', Other_MikroDetailsUserID = 0 WHERE Other_MikroDetailsOther_MikroID = {$header_id}"; + $this->db_smartone->query($sql); + + $results = $prm['details']; + if($inp['result_value'] == 'Positif'){ + foreach($results as $k => $v){ + if($v['xid'] == '0'){ + $sql = "INSERT INTO other_mikrodetails( + Other_MikroDetailsOther_MikroID , + Other_MikroDetailsT_AntibioticID, + Other_MikroDetailsValue, + Other_MikroDetailsNote, + Other_MikroDetailsCreated, + Other_MikroDetailsUserID + ) + VALUES( + {$header_id}, + '{$v['T_AntibioticID']}', + '{$v['value']}', + '{$v['note']}', + NOW(), + {$userid} + )"; + $query = $this->db_smartone->query($sql); + } + else{ + $sql = "UPDATE other_mikrodetails SET + Other_MikroDetailsT_AntibioticID = '{$v['T_AntibioticID']}', + Other_MikroDetailsValue = '{$v['value']}', + Other_MikroDetailsNote = '{$v['note']}', + Other_MikroDetailsIsActive = 'Y', + Other_MikroDetailsUserID = {$userid} + WHERE + Other_MikroDetailsID = {$v['xid']}"; + //echo $sql; + $query = $this->db_smartone->query($sql); + } + } + } + + + $result = array("total" => 1, "records" => array(), "sql"=> ''); + $this->sys_ok($result); + exit; + } + + + function get_doctors_preparasi_sperma() + { + $prm = $this->sys_input; + // $id = $prm["id"]; + + $sql = " SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 10 AND + M_DoctorSOIsActive = 'Y' + ORDER BY M_DoctorName ASC"; + //echo $sql; + $query = $this->db_smartone->query($sql); + $rows = $query->result_array(); + $sql = " + SELECT '0' as id, 'Belum memilih metode' as name + UNION + SELECT M_MethodeSpermaID as id, M_MethodeSpermaName as name + FROM m_methodesperma + WHERE + M_MethodeSpermaIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $methodes = $this->db_smartone->query($sql)->result_array(); + + + $this->sys_ok(["records"=>$rows,"methodes"=>$methodes]); + + } + + + function getpreparasispermaresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT other_preparasisperma.*, + Other_PreparasiSpermaID as xid, + Other_PreparasiSpermaT_OrderDetailID as orderdetail_id, + IFNULL(Other_PreparasiSpermaM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_PreparasiSpermaM_DoctorID) OR Other_PreparasiSpermaM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name, + IFNULL(M_MethodeSpermaID,0) as methode_id, + IFNULL(M_MethodeSpermaName,'') as methode_name + FROM other_preparasisperma + LEFT JOIN m_doctor ON Other_PreparasiSpermaM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + LEFT JOIN m_methodesperma ON Other_PreparasiSpermaM_MethodeSpermaID = M_MethodeSpermaID AND + M_MethodeSpermaIsActive = 'Y' + WHERE + Other_PreparasiSpermaT_OrderDetailID = {$id} AND Other_PreparasiSpermaIsActive = 'Y' + GROUP BY Other_PreparasiSpermaID"; + $query = $this->db_smartone->query($sql); + + if ($query) + { + $rows = $query->row_array(); + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 10 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $sql = " + SELECT '0' as id, 'Belum memilih metode' as name + UNION + SELECT M_MethodeSpermaID as id, M_MethodeSpermaName as name + FROM m_methodesperma + WHERE + M_MethodeSpermaIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $methodes = $this->db_smartone->query($sql)->result_array(); + $images = array(); + $sql = "SELECT Other_PreparasiSpermaImgID as xid, + Other_PreparasiSpermaImgType as type, + CONCAT('/one-media/one-image-nonlab/',Other_PreparasiSpermaImgNewName) as image_url + FROM t_orderdetail + JOIN other_preparasisperma_img ON Other_PreparasiSpermaImgT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND + Other_PreparasiSpermaImgIsActive = 'Y' + WHERE + T_OrderDetailID = {$id} AND + T_OrderDetailIsActive = 'Y' + GROUP BY Other_PreparasiSpermaImgID"; + //echo $sql; + $images = $this->db_smartone->query($sql)->result_array(); + + $rst = array('doctors'=>$doctors,'methodes'=>$methodes,'results'=>$rows,'images'=>$images); + $this->sys_ok(["records"=>$rst]); + } + else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + + function uploadimage_preparasi_sperma(){ + if (! $this->isLogin) { + $this->sys_error("Invalid Token"); + exit; + } + + $userid = $this->sys_user["M_UserID"]; + $data = []; + //print_r($_SERVER); + + $prm = $this->sys_input; + $orderid = $this->input->post('orderid'); + $type = $this->input->post('type'); + $labnumber = $this->input->post('labnumber'); + $sql = "UPDATE other_preparasisperma_img SET + Other_PreparasiSpermaImgIsActive = 'N', + Other_PreparasiSpermaImgUserID = {$userid} + WHERE + Other_PreparasiSpermaImgT_OrderHeaderID = {$orderid} AND + Other_PreparasiSpermaImgType = '{$type}'"; + //echo $sql; + $this->db_onedev->query($sql); + //$config['upload_path'] = 'assets/'; + + $path = '/home/one/project/one/one-media/one-image-nonlab/'; + //echo $path; + $config['upload_path'] = $path; + $config['allowed_types'] = 'jpg|jpeg|png|gif'; + + $config['max_size'] = '10000'; + $count = count($_FILES['files']['name']); + //echo $count; + $this->load->library('upload',$config); + + $error = []; + for($i=0;$i<$count;$i++){ + + + if(!empty($_FILES['files']['name'][$i])){ + + + + $_FILES['file']['name'] = $_FILES['files']['name'][$i]; + + $_FILES['file']['type'] = $_FILES['files']['type'][$i]; + + $_FILES['file']['tmp_name'] = $_FILES['files']['tmp_name'][$i]; + + $_FILES['file']['error'] = $_FILES['files']['error'][$i]; + + $_FILES['file']['size'] = $_FILES['files']['size'][$i]; + + + + $namex = $orderid.'-'.$labnumber.'-'.$this->generateRandomString(5); + //echo $namex; + + $config['file_name'] = $namex; + $this->upload->initialize($config); + //echo $config['file_name'] ; + + + + + + if($this->upload->do_upload('file')){ + + $uploadData = $this->upload->data(); + + $filename = $uploadData['file_name']; + //echo $filename; + + + $sql = "INSERT INTO other_preparasisperma_img ( + Other_PreparasiSpermaImgT_OrderHeaderID, + Other_PreparasiSpermaImgType, + Other_PreparasiSpermaImgOldName, + Other_PreparasiSpermaImgNewName, + Other_PreparasiSpermaImgCreated, + Other_PreparasiSpermaImgUserID + ) + VALUES( + {$orderid}, + '{$type}', + '{$_FILES['files']['name'][$i]}', + '{$filename}', + NOW(), + {$userid} + + )"; + //echo $sql; + $this->db_onedev->query($sql); + $xlast_id = $this->db_onedev->insert_id(); + $data['totalFiles'][] = array('xid' => $xlast_id ,'type'=>$type,'image_url' => '/one-media/one-image-nonlab/'.$filename); + + } + else{ + $error = array('error' => $this->upload->display_errors()); + } + + } + + + + } + + $result = array("total" =>count( $data['totalFiles']), "records" => $data['totalFiles'],'errors'=>$error); + $this->sys_ok($result); + } + + + function saveresult_preparasi_sperma() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = $inp['doctor']; + $orderdetail_id = $inp['orderdetailid']; + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + if($prm['xid'] == '0'){ + $sql = "INSERT INTO other_preparasisperma( + Other_PreparasiSpermaM_DoctorID, + Other_PreparasiSpermaT_OrderDetailID, + Other_PreparasiSpermaPreMotilitasA, + Other_PreparasiSpermaPreMotilitasB, + Other_PreparasiSpermaPreMotilitasC, + Other_PreparasiSpermaPreKonsentrasi, + Other_PreparasiSpermaPreKontaminan, + Other_PreparasiSpermaPostMotilitasA, + Other_PreparasiSpermaPostMotilitasB, + Other_PreparasiSpermaPostMotilitasC, + Other_PreparasiSpermaPostKonsentrasi, + Other_PreparasiSpermaPostKontaminan, + Other_PreparasiSpermaPreVolume, + Other_PreparasiSpermaPostVolume, + Other_PreparasiSpermaM_MethodeSpermaID, + Other_PreparasiSpermaNote, + Other_PreparasiSpermaUserID, + Other_PreparasiSpermaCreated + ) + VALUES( + {$doctor_id}, + {$orderdetail_id}, + '{$prm['Other_PreparasiSpermaPreMotilitasA']}', + '{$prm['Other_PreparasiSpermaPreMotilitasB']}', + '{$prm['Other_PreparasiSpermaPreMotilitasC']}', + '{$prm['Other_PreparasiSpermaPreKonsentrasi']}', + '{$prm['Other_PreparasiSpermaPreKontaminan']}', + '{$prm['Other_PreparasiSpermaPostMotilitasA']}', + '{$prm['Other_PreparasiSpermaPostMotilitasB']}', + '{$prm['Other_PreparasiSpermaPostMotilitasC']}', + '{$prm['Other_PreparasiSpermaPostKonsentrasi']}', + '{$prm['Other_PreparasiSpermaPostKontaminan']}', + '{$prm['Other_PreparasiSpermaPreVolume']}', + '{$prm['Other_PreparasiSpermaPostVolume']}', + '{$prm['Other_PreparasiSpermaM_MethodeSpermaID']}', + '{$prm['Other_PreparasiSpermaNote']}', + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } + else{ + $sql = "SELECT * FROM other_preparasisperma WHERE Other_PreparasiSpermaT_OrderDetailID = {$orderdetail_id} AND Other_PreparasiSpermaIsActive = 'Y'"; + $data_header = $this->db_smartone->query($sql)->row_array(); + $header_id = $data_header['Other_PreparasiSpermaID']; + $sql = "UPDATE other_preparasisperma SET + Other_PreparasiSpermaM_DoctorID = {$doctor_id}, + Other_PreparasiSpermaPreMotilitasA = '{$prm['Other_PreparasiSpermaPreMotilitasA']}', + Other_PreparasiSpermaPreMotilitasB = '{$prm['Other_PreparasiSpermaPreMotilitasB']}', + Other_PreparasiSpermaPreMotilitasC = '{$prm['Other_PreparasiSpermaPreMotilitasC']}', + Other_PreparasiSpermaPreKonsentrasi = '{$prm['Other_PreparasiSpermaPreKonsentrasi']}', + Other_PreparasiSpermaPreKontaminan = '{$prm['Other_PreparasiSpermaPreKontaminan']}', + Other_PreparasiSpermaPostMotilitasA = '{$prm['Other_PreparasiSpermaPostMotilitasA']}', + Other_PreparasiSpermaPostMotilitasB = '{$prm['Other_PreparasiSpermaPostMotilitasB']}', + Other_PreparasiSpermaPostMotilitasC = '{$prm['Other_PreparasiSpermaPostMotilitasC']}', + Other_PreparasiSpermaPostKonsentrasi = '{$prm['Other_PreparasiSpermaPostKonsentrasi']}', + Other_PreparasiSpermaPostKontaminan = '{$prm['Other_PreparasiSpermaPostKontaminan']}', + Other_PreparasiSpermaPreVolume = '{$prm['Other_PreparasiSpermaPreVolume']}', + Other_PreparasiSpermaPostVolume = '{$prm['Other_PreparasiSpermaPostVolume']}', + Other_PreparasiSpermaM_MethodeSpermaID = '{$prm['Other_PreparasiSpermaM_MethodeSpermaID']}', + Other_PreparasiSpermaNote = '{$prm['Other_PreparasiSpermaNote']}', + Other_PreparasiSpermaUserID = {$userid} + WHERE + Other_PreparasiSpermaID = {$header_id}"; + $this->db_smartone->query($sql); + } + + + $result = array("total" => 1, "records" => array(), "sql"=> ''); + $this->sys_ok($result); + exit; + } + + function getdnafragmentasiresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT other_dnafragmentasi.*, + Other_DnaFragmentasiID as xid, + Other_DnaFragmentasiT_OrderDetailID as orderdetail_id, + IFNULL(Other_DnaFragmentasiM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_DnaFragmentasiM_DoctorID) OR Other_DnaFragmentasiM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name, + IFNULL(Other_DnaFragmentasiOther_DnaFragmentasiMethodeID,0) as methode_id, + IFNULL(Other_DnaFragmentasiMethodeName,'') as methode_name, + Other_DnaFragmentasiHaloLuas as halo_luas, + Other_DnaFragmentasiHaloSedang as halo_sedang, + Other_DnaFragmentasiHaloSempit as halo_sempit, + Other_DnaFragmentasiTanpaHalo as tanpa_halo, + Other_DnaFragmentasiDFI as dfi, + Other_DnaFragmentasiKesimpulan as kesimpulan, + Other_DnaFragmentasiCatatan as catatan + FROM other_dnafragmentasi + LEFT JOIN m_doctor ON Other_DnaFragmentasiM_DoctorID = M_DoctorID + LEFT JOIN other_dnafragmentasimethode ON Other_DnaFragmentasiOther_DnaFragmentasiMethodeID = Other_DnaFragmentasiMethodeID + WHERE + Other_DnaFragmentasiT_OrderDetailID = {$id} AND Other_DnaFragmentasiIsActive = 'Y' + GROUP BY Other_DnaFragmentasiID + LIMIT 1"; + //echo $sql; + $query = $this->db_smartone->query($sql); + + if ($query) + { + $rows = $query->row_array(); + if(!$rows){ + $rows = array( + 'xid' => 0, + 'orderdetail_id' =>$id, + 'doctor_id' => 0, + 'doctor_name' => '', + 'methode_id' => 0, + 'methode_name' => '', + 'halo_luas' => '', + 'halo_sedang' => '', + 'tanpa_halo' => '', + 'dfi' => '', + 'kesimpulan' => '', + 'catatan' => '' + ); + } + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID + WHERE + M_DoctorSONat_SubGroupID = 4 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + + $sql = " + SELECT '0' as id, 'Belum memilih metode' as name + UNION + SELECT Other_DnaFragmentasiMethodeID as id, Other_DnaFragmentasiMethodeName as name + FROM other_dnafragmentasimethode + WHERE + Other_DnaFragmentasiMethodeIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $methodes = $this->db_smartone->query($sql)->result_array(); + + + $rst = array('doctors'=>$doctors,'methodes'=>$methodes,'results'=>$rows); + $this->sys_ok(["records"=>$rst]); + } + else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + function saveresult_dnafragmentasi() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = $inp['doctor']['id']; + $methode_id = $inp['methode']['id']; + $orderdetail_id = $inp['results']['orderdetail_id']; + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + if(intval($prm['xid']) == 0){ + $sql = "INSERT INTO other_dnafragmentasi( + Other_DnaFragmentasiT_OrderDetailID, + Other_DnaFragmentasiM_DoctorID, + Other_DnaFragmentasiOther_DnaFragmentasiMethodeID, + Other_DnaFragmentasiHaloLuas, + Other_DnaFragmentasiHaloSedang, + Other_DnaFragmentasiHaloSempit, + Other_DnaFragmentasiTanpaHalo, + Other_DnaFragmentasiDFI, + Other_DnaFragmentasiKesimpulan, + Other_DnaFragmentasiCatatan, + Other_DnaFragmentasiUserID, + Other_DnaFragmentasiLastUpdated + ) + VALUES( + {$orderdetail_id}, + {$doctor_id}, + {$methode_id}, + '{$prm['halo_luas']}', + '{$prm['halo_sedang']}', + '{$prm['halo_sempit']}', + '{$prm['tanpa_halo']}', + '{$prm['dfi']}', + '{$prm['kesimpulan']}', + '{$prm['catatan']}', + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } + else{ + $sql = "UPDATE other_dnafragmentasi SET + Other_DnaFragmentasiT_OrderDetailID = {$orderdetail_id}, + Other_DnaFragmentasiM_DoctorID = {$doctor_id}, + Other_DnaFragmentasiOther_DnaFragmentasiMethodeID = '{$methode_id}', + Other_DnaFragmentasiHaloLuas = '{$prm['halo_luas']}', + Other_DnaFragmentasiHaloSedang = '{$prm['halo_sedang']}', + Other_DnaFragmentasiHaloSempit = '{$prm['halo_sempit']}', + Other_DnaFragmentasiTanpaHalo = '{$prm['tanpa_halo']}', + Other_DnaFragmentasiDFI = '{$prm['dfi']}', + Other_DnaFragmentasiKesimpulan = '{$prm['kesimpulan']}', + Other_DnaFragmentasiCatatan = '{$prm['catatan']}', + Other_DnaFragmentasiLastUpdated = NOW(), + Other_DnaFragmentasiUserID = {$userid} + WHERE + Other_DnaFragmentasiID = {$prm['xid']}"; + //echo $sql; + $this->db_smartone->query($sql); + } + + + $result = array("total" => 1, "records" => array(), "sql"=> ''); + $this->sys_ok($result); + exit; + } + + +} + diff --git a/application/controllers/mockup/process/resultverification-v23/Re_px.php b/application/controllers/mockup/process/resultverification-v23/Re_px.php index f9b079b9..d5c1d003 100644 --- a/application/controllers/mockup/process/resultverification-v23/Re_px.php +++ b/application/controllers/mockup/process/resultverification-v23/Re_px.php @@ -1,2512 +1,2509 @@ -db_smartone = $this->load->database("onedev", true); - $this->load->helper(array('form', 'url')); - } - function getMethodeID($natTestID) - { - $sql = "select M_MethodePriorityNat_MethodeID MethodeID, Nat_MethodeName - from - m_methode_priority - join nat_methode on Nat_MethodeID = M_MethodePriorityNat_MethodeID - and Nat_MethodeIsActive = 'Y' - join m_instrumentmethode on M_InstrumentMethodeNat_MethodeID = Nat_MethodeID and M_InstrumentMethodeIsActive = 'Y' - join nat_instrument on M_InstrumentMethodeNat_InstrumentID = Nat_InstrumentID - and Nat_InstrumentIsActive ='Y' - where M_MethodePriorityIsActive = 'Y' - and M_MethodePriorityNat_TestID = $natTestID - and M_MethodePriorityM_DayOfWeekID = dayofweek(now()) - order by M_MethodePriorityNumber desc - limit 0,1 "; - $qry = $this->db->query($sql); - if ($qry) { - $rows = $qry->result_array(); - if (count($rows) > 0) return array($rows[0]["MethodeID"], $rows[0]["Nat_MethodeName"]); - } - //2nd - $sql = "select - M_InstrumentMethodeNat_MethodeID MethodeID, Nat_MethodeName - from m_instrumentmethode - join nat_methode on M_InstrumentMethodeNat_MethodeID = Nat_MethodeID - and Nat_MethodeIsActive = 'Y' - join nat_instrument on M_InstrumentMethodeNat_InstrumentID = Nat_InstrumentID - and Nat_InstrumentIsActive ='Y' - where M_InstrumentMethodeNat_TestID = $natTestID - and M_InstrumentMethodeIsActive = 'Y' - order by M_InstrumentMethodePriority desc - limit 0,1"; - $qry = $this->db->query($sql); - if ($qry) { - $rows = $qry->result_array(); - if (count($rows) > 0) return array($rows[0]["MethodeID"], $rows[0]["Nat_MethodeName"]); - } - // - $sql = "select Nat_NormalValueNat_MethodeID MethodeID, Nat_MethodeName - from - nat_normalvalue - join nat_methode on Nat_NormalValueNat_MethodeID = Nat_MethodeID - and Nat_MethodeIsActive = 'Y' - where Nat_NormalValueNat_TestID = $natTestID - and Nat_NormalValueIsActive = 'Y' - order by Nat_NormalValueID - limit 0,1"; - $qry = $this->db->query($sql); - if ($qry) { - $rows = $qry->result_array(); - if (count($rows) > 0) return array($rows[0]["MethodeID"], $rows[0]["Nat_MethodeName"]); - } - return array(0, ""); - } - function get_normal_value($methodeID, $natTestID, $sexID, $ageInDay) - { - $sql = "select fn_sampling_get_normal($methodeID, $natTestID, $sexID, $ageInDay) as normalValueID"; - $qry = $this->db->query($sql); - if ($qry) { - $rows = $qry->result_array(); - if (count($rows) > 0) return $rows[0]["normalValueID"]; - } - return 0; - } - function fn_fix_normal($order_id) - { - $sql = "select - T_OrderDetailID, M_PatientM_SexID, fn_global_age_count_day(M_PatientDOB, date(T_OrderHeaderDate)) Dob , - T_TestNat_TestID - from t_orderheader - join m_patient on T_OrderHeaderID = $order_id and T_OrderHeaderM_PatientID = M_PatientID - join t_orderdetail on T_OrderDetailT_OrderHeaderID = T_OrderHeaderID - and T_OrderDetailIsACtive = 'Y' - and ( T_OrderDetailNat_NormalValueID is null or T_OrderDetailNat_NormalValueID = 0 ) - join t_test on T_OrderDetailT_TestID = T_TestID and T_TestIsResult = 'Y' "; - $qry = $this->db->query($sql); - if (! $qry) { - return; - } - $rows = $qry->result_array(); - if (count($rows) == 0) return; - $sql_u = "update t_orderdetail - join nat_normalvalue on T_OrderDetailID = ? and Nat_NormalValueID = ? - set - T_OrderDetailNat_NormalValueID = Nat_NormalValueID, - T_OrderDetailNormalValueNote = Nat_NormalValueNote, - T_OrderDetailNormalValueDescription = Nat_NormalValueDescription, - T_OrderDetailMinValue = Nat_NormalValueMinValue, - T_OrderDetailMaxValue = Nat_NormalValueMaxValue, - T_OrderDetailMinValueInclusive = Nat_NormalValueMinValueInclusive, - T_OrderDetailMaxValueInclusive = Nat_NormalValueMaxValueInclusive, - T_OrderDetailNat_MethodeID = ?, - T_OrderdetailNat_MethodeName =?"; - - foreach ($rows as $r) { - $T_OrderDetailID = $r["T_OrderDetailID"]; - $sexID = $r["M_PatientM_SexID"]; - $ageInDay = $r["Dob"]; - $natTestID = $r["T_TestNat_TestID"]; - list($methodeID, $methodeName) = $this->getMethodeID($natTestID); - if ($methodeID == 0) continue; - $normalValueID = $this->get_normal_value($methodeID, $natTestID, $sexID, $ageInDay); - if ($normalValueID == 0) return; - $this->db->query($sql_u, array($T_OrderDetailID, $normalValueID, $methodeID, $methodeName)); - } - } - - function update_order_sample($targetID, $sourceID) - { - $sql = "update t_ordersample target - join t_ordersample source on - target.T_OrderSampleID = ? - and target.T_OrderSampleWorklistReceive = 'N' - and source.T_OrderSampleID = ? - set - target.T_OrderSampleSampling = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSampling, source.T_OrderSampleSampling), - target.T_OrderSampleSamplingDate = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingDate, source.T_OrderSampleSamplingDate), - target.T_OrderSampleSamplingTime = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingTime, source.T_OrderSampleSamplingTime), - target.T_OrderSampleSamplingUserID = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingUserID, source.T_OrderSampleSamplingUserID), - - target.T_OrderSampleReceive = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceive, source.T_OrderSampleReceive), - target.T_OrderSampleReceiveDate = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveDate, source.T_OrderSampleReceiveDate), - target.T_OrderSampleReceiveTime = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveTime, source.T_OrderSampleReceiveTime), - target.T_OrderSampleReceiveUserID = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveUserID, source.T_OrderSampleReceiveUserID), - - target.T_OrderSampleVerification = if(target.T_OrderSampleVerification='Y',target.T_OrderSampleVerification, source.T_OrderSampleVerification), - target.T_OrderSampleVerificationDate =if(target.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationDate, source.T_OrderSampleVerificationDate), - target.T_OrderSampleVerificationTime =if(source.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationTime, source.T_OrderSampleVerificationTime), - target.T_OrderSampleVerificationUserID =if(source.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationUserID, source.T_OrderSampleVerificationUserID), - - target.T_OrderSampleProcessing = if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessing, source.T_OrderSampleProcessing), - target.T_OrderSampleProcessingDate= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingDate, source.T_OrderSampleProcessingDate), - target.T_OrderSampleProcessingTime= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingTime, source.T_OrderSampleProcessingTime), - target.T_OrderSampleProcessingUserID= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingUserID, source.T_OrderSampleProcessingUserID), - - target.T_OrderSampleReceiveHandling =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandling, source.T_OrderSampleReceiveHandling ), - target.T_OrderSampleReceiveHandlingDate =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingDate, source.T_OrderSampleReceiveHandlingDate), - target.T_OrderSampleReceiveHandlingTime =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingTime, source.T_OrderSampleReceiveHandlingTime), - target.T_OrderSampleReceiveHandlingUserID =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingUserID, source.T_OrderSampleReceiveHandlingUserID), - - target.T_OrderSampleHandling = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandling, source.T_OrderSampleHandling), - target.T_OrderSampleHandlingDate = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingDate, source.T_OrderSampleHandlingDate), - target.T_OrderSampleHandlingTime = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingTime, source.T_OrderSampleHandlingTime), - target.T_OrderSampleHandlingUserID = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingUserID, source.T_OrderSampleHandlingUserID), - - target.T_OrderSampleWorklistReceive = source.T_OrderSampleWorklistReceive, - target.T_OrderSampleWorklistReceiveDatetime = source.T_OrderSampleWorklistReceiveDateTime, - target.T_OrderSampleWorklistReceiveUserID = source.T_OrderSampleWorklistReceiveUserID - "; - $qry = $this->db->query($sql, array($targetID, $sourceID)); - if (! $qry) { - echo json_encode(array("status" => "ERR", "message" => print_r($this->db->error(), true))); - exit; - } - } - function fix_sample_serum($headerID) - { - //cari t_ordersample yg belum worklist receive dengan code 017% - $sql = "select T_OrderSampleID - from t_ordersample - join t_sampletype on - T_OrderSampleT_OrderHeaderID = ? - and T_OrderSampleWorklistReceive = 'N' - and T_OrderSampleIsActive = 'Y' - and T_OrderSampleT_SampleTypeID = T_SampletypeID - and T_SampleTypeCode like '017%' - "; - $qry = $this->db->query($sql, array($headerID)); - if (!$qry) { - echo json_encode(array("status" => "ERR", "message" => print_r($this->db->error(), true))); - exit; - } - $rows = $qry->result_array(); - if (count($rows) == 0) return; - //cari T_OrderSample yang sudah di receive yg terakhir - $sql = "select T_OrderSampleID - from t_ordersample - join t_sampletype on - T_OrderSampleT_OrderHeaderID = ? - and T_OrderSampleWorklistReceive = 'Y' - and T_OrderSampleIsActive = 'Y' - and T_OrderSampleT_SampleTypeID = T_SampletypeID - and T_SampleTypeCode like '017%' - order by T_OrderSampleWorklistReceiveDatetime desc - limit 0,1 - "; - $qry = $this->db->query($sql, array($headerID)); - if (!$qry) { - echo json_encode(array("status" => "ERR", "message" => print_r($this->db->error(), true))); - exit; - } - $rcv_rows = $qry->result_array(); - if (count($rcv_rows) == 0) return; - - //print_r($rows); - //print_r($rcv_rows); - $rcv_T_OrderSampleID = $rcv_rows[0]["T_OrderSampleID"]; - //ada yg belum di receive - foreach ($rows as $r) { - $T_OrderSampleID = $r["T_OrderSampleID"]; - $this->update_order_sample($T_OrderSampleID, $rcv_T_OrderSampleID); - } - } - public function search() - { - $prm = $this->sys_input; - $max_rst = 99; - - $id = $prm["order_id"]; - if ($id > 0) { - $this->fix_sample_serum($id); - $this->fn_fix_normal($id); - } - $lang = $this->lang_default_code; - $lang_id = isset($prm['lang_id']) ? $prm['lang_id'] : '0'; - - if ($lang_id != 0) { - $l = $this->db_smartone->where("Nat_LangID", $lang_id)->get("nat_lang")->row(); - $lang = $l->Nat_LangCode; - } - - //tambahan fajri - $sql = " UPDATE t_orderdetail - JOIN t_test ON T_OrderDetailT_TestID = T_TestID - SET T_OrderDetailT_TestIsResult = T_TestIsResult - WHERE - T_OrderDetailT_OrderHeaderID = {$id} AND - T_OrderDetailT_TestIsResult = '' AND - T_OrderDetailIsActive = 'Y'"; - $this->db_smartone->query($sql); - - $tot_count = 0; - $lq = ""; - $group_id = 0; - if (isset($prm['group_id'])) - $group_id = $prm['group_id']; - - if ($group_id != 0) { - $sql = "select distinct T_WorklistDetailNat_TestID Nat_TestID - from t_worklistdetailv2 - where T_WorklistDetailT_WorklistID = {$group_id}"; - $qry = $this->db_smartone->query($sql); - $rows = $qry->result_array(); - $nat_test_ids = "0"; - foreach ($rows as $r) { - $nat_test_ids .= ", " . $r["Nat_TestID"]; - } - $q_group = " ( $nat_test_ids ) "; - - $sql = " - SELECT a1.*, cOUNT(a2.T_OrderDetailID) level - FROM ( - SELECT IFNULL(y.T_OrderDetailT_TestID, x.T_OrderDetailT_TestID) t_testid, - IFNULL(y.T_OrderDetailT_TestName, y.T_OrderDetailT_TestName) t_testname, - y.T_OrderDetailResult result, y.T_OrderDetailResult result_old, y.T_OrderDetailNote note, y.T_OrderDetailNote note_old, - y.T_OrderDetailID id, - y.T_OrderDetailT_TestIsResult is_result, a.T_TestIsQuantitative is_quantitative, - y.T_OrderDetailResultFlag result_flag, - y.T_OrderDetailNat_NormalValueID normal_id, - y.T_OrderDetailNormalValueNote normal_note, y.T_OrderDetailNat_UnitName unit_name, - y.T_OrderdetailNat_MethodeID methode_id, y.T_OrderdetailNat_MethodeName methode_name, - a.T_TestNat_TestID nattest_id, a.T_TestID tx_id, count(T_ResultInstrumentID) as result_instrument_n, - y.T_OrderDetailVerification, T_OrderSampleReceive sample_receive, - T_OrderSampleProcessing sample_processing, T_OrderSampleWorklistReceive sample_worklist_receive, - IF(T_OrderDetailAddOnPreAnalytic = 'Y', T_OrderDetailAddOnPreAnalytic, PreAnalyticIsOk) pre_analytic, - T_OrderDetailAddOnPreAnalytic, - T_OrderHeaderID order_id, y.T_OrderDetailT_TestSasCode test_sas_code, - tx.T_TestSasCode, - T_OrderDetailAddOnResample `resample`, T_OrderDetailAddOnResampleStatus resample_status, - T_OrderDetailAddOnRef ref, y.T_OrderDetailVerification verification, y.T_OrderDetailValidation validation, - T_OrderPromiseDateTime, Group_ResultName as ResultGroupName - FROM t_orderdetail x - left join t_orderpromise on x.T_OrderDetailT_OrderPromiseID = T_OrderPromiseID - JOIN t_test tx ON x.T_OrderDetailT_TestID = T_TestID - JOIN t_test tcheck on tcheck.T_TestNat_TestID in {$q_group} - and ( tx.T_TestID = tcheck.T_TestID or tx.T_TestSasCode like concat(tcheck.T_TestSasCode,'%')) - LEFT JOIN group_resultdetail ON Group_ResultDetailT_TestID = x.T_OrderDetailT_TestID AND Group_ResultDetailIsActive = 'Y' - LEFT JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND Group_ResultFlagNonLab = 'N' - LEFT JOIN t_orderdetail y ON x.T_OrderDetailT_TestSasCode LIKE CONCAT(y.T_OrderDetailT_TestSasCode, '%') - AND x.T_OrderDetailT_OrderHeaderID = y.T_OrderDetailT_OrderHeaderID - AND y.T_OrderDetailIsActive = 'Y' - LEFT JOIN t_orderdetailaddon ON x.T_OrderDetailID = T_OrderDetailAddOnT_OrderDetailID - JOIN t_orderheader ON y.T_OrderDetailT_OrderHeaderID = T_OrderHeaderID - LEFT JOIN t_test a ON y.T_OrderDetailT_TestID = a.T_TestID - AND a.T_TestIsNonLab = '' - LEFT JOIN (SELECT T_OrderSampleT_SampleTypeID, T_OrderSampleReceive, T_OrderSampleProcessing, T_OrderSampleWorklistReceive - FROM t_ordersample WHERE T_OrderSampleT_OrderHeaderID = {$id} - AND T_OrderSampleIsactive = 'Y' - GROUP BY T_OrderSampleT_SampleTypeID) os ON a.T_TestT_SampleTypeID = os.T_OrderSampleT_SampleTypeID - or os.T_OrderSampleT_SampleTypeID = fn_sampletype_from_local(a.T_TestNat_TestID) - - LEFT JOIN t_resultinstrument ON T_ResultInstrumentT_OrderDetailID = x.T_OrderDetailID - LEFT JOIN pre_analytic ON PreAnalyticNat_TestID = a.T_TestNat_TestID AND PreAnalyticDate = date(now()) and PreAnalyticIsActive = 'Y' - WHERE x.T_OrderDetailT_OrderHeaderID = {$id} - AND x.T_OrderDetailIsActive = 'Y' - GROUP BY y.T_OrderDetailT_TestID - ORDER BY y.T_OrderDetailT_TestSasCode ASC - ) a1 - - LEFT JOIN t_orderdetail a2 ON a2.T_OrderDetailT_OrderHeaderID = a1.order_id - AND a2.T_OrderDetailIsActive = 'Y' - AND a1.test_sas_code LIKE CONCAT(a2.T_OrderDetailT_testSasCode, '%') - GROUP BY a1.t_testid - order by a1.test_sas_code -"; - $query = $this->db_smartone->query($sql); - $lq = $this->db_smartone->last_query(); - } else { - $sql = " - SELECT a1.*, cOUNT(a2.T_OrderDetailID) level - FROM ( - SELECT IFNULL(y.T_OrderDetailT_TestID, x.T_OrderDetailT_TestID) t_testid, - IFNULL(y.T_OrderDetailT_TestName, y.T_OrderDetailT_TestName) t_testname, - y.T_OrderDetailResult result, y.T_OrderDetailResult result_old, y.T_OrderDetailNote note, y.T_OrderDetailNote note_old, - y.T_OrderDetailID id, - y.T_OrderDetailT_TestIsResult is_result, a.T_TestIsQuantitative is_quantitative, - y.T_OrderDetailResultFlag result_flag, - y.T_OrderDetailNat_NormalValueID normal_id, - y.T_OrderDetailNormalValueNote normal_note, y.T_OrderDetailNat_UnitName unit_name, - y.T_OrderdetailNat_MethodeID methode_id, y.T_OrderdetailNat_MethodeName methode_name, - a.T_TestNat_TestID nattest_id, a.T_TestID tx_id, count(T_ResultInstrumentID) as result_instrument_n, - y.T_OrderDetailVerification, T_OrderSampleReceive sample_receive, - T_OrderSampleProcessing sample_processing, T_OrderSampleWorklistReceive sample_worklist_receive, - IF(T_OrderDetailAddOnPreAnalytic = 'Y', T_OrderDetailAddOnPreAnalytic, PreAnalyticIsOk) pre_analytic, - T_OrderDetailAddOnPreAnalytic, - T_OrderHeaderID order_id, y.T_OrderDetailT_TestSasCode test_sas_code, - tx.T_TestSasCode, - T_OrderDetailAddOnResample `resample`, T_OrderDetailAddOnResampleStatus resample_status, - T_OrderDetailAddOnRef ref, y.T_OrderDetailVerification verification, y.T_OrderDetailValidation validation, - T_OrderPromiseDateTime , Group_ResultName as ResultGroupName - FROM t_orderdetail x - left join t_orderpromise on x.T_OrderDetailT_OrderPromiseID = T_OrderPromiseID - JOIN t_test tx ON x.T_OrderDetailT_TestID = T_TestID - LEFT JOIN group_resultdetail ON Group_ResultDetailT_TestID = x.T_OrderDetailT_TestID AND Group_ResultDetailIsActive = 'Y' - LEFT JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND Group_ResultFlagNonLab = 'N' - LEFT JOIN t_orderdetail y ON x.T_OrderDetailT_TestSasCode LIKE CONCAT(y.T_OrderDetailT_TestSasCode, '%') - AND x.T_OrderDetailT_OrderHeaderID = y.T_OrderDetailT_OrderHeaderID - AND y.T_OrderDetailIsActive = 'Y' - - LEFT JOIN t_orderdetailaddon ON x.T_OrderDetailID = T_OrderDetailAddOnT_OrderDetailID - - JOIN t_orderheader ON y.T_OrderDetailT_OrderHeaderID = T_OrderHeaderID - LEFT JOIN t_test a ON y.T_OrderDetailT_TestID = a.T_TestID - AND a.T_TestIsNonLab = '' - LEFT JOIN (SELECT T_OrderSampleT_SampleTypeID, T_OrderSampleReceive, T_OrderSampleProcessing, T_OrderSampleWorklistReceive - FROM t_ordersample WHERE T_OrderSampleT_OrderHeaderID = {$id} - AND T_OrderSampleIsactive = 'Y' - GROUP BY T_OrderSampleT_SampleTypeID) os ON a.T_TestT_SampleTypeID = os.T_OrderSampleT_SampleTypeID - or os.T_OrderSampleT_SampleTypeID = fn_sampletype_from_local(a.T_TestNat_TestID) - - LEFT JOIN t_resultinstrument ON T_ResultInstrumentT_OrderDetailID = x.T_OrderDetailID - LEFT JOIN pre_analytic ON PreAnalyticNat_TestID = a.T_TestNat_TestID AND PreAnalyticDate = date(now()) and PreAnalyticIsActive = 'Y' - WHERE x.T_OrderDetailT_OrderHeaderID = {$id} - AND x.T_OrderDetailIsActive = 'Y' - GROUP BY y.T_OrderDetailT_TestID - ORDER BY y.T_OrderDetailT_TestSasCode ASC - ) a1 - - LEFT JOIN t_orderdetail a2 ON a2.T_OrderDetailT_OrderHeaderID = a1.order_id - AND a2.T_OrderDetailIsActive = 'Y' - AND a1.test_sas_code LIKE CONCAT(a2.T_OrderDetailT_testSasCode, '%') - GROUP BY a1.t_testid - order by a1.test_sas_code -"; - //echo $sql; - $query = $this->db_smartone->query($sql); - $lq = $this->db_smartone->last_query(); - } - // file_put_contents("/xtmp/re-query.sql",$lq); - - if ($query) { - $rst = []; - $rows = $query->result_array(); - - foreach ($rows as $k => $v) { - - if ($v['is_result'] == "Y" && $v['is_quantitative'] == "N") { - $v['template'] = []; - $x = $this->db_smartone->query("CALL sp_master_resulttemplate_get('{$v['t_testid']}')"); - $this->clean_mysqli_connection($this->db_smartone->conn_id); - if ($x) - $v['template'] = $x->result_array(); - } - - // IF Rujukan, by pas Pre Analytik - if ($v['ref'] == 'Y') - $v['pre_analytic'] = 'Y'; - if ($v["id"] == "885455") { - //sipe workaround - //$v["sample_receive"] = "Y"; - $v["sample_worklist_receive"] = "Y"; - } - $rst[] = $v; - } - - $result = array("total" => $tot_count, "records" => $rst, "total_display" => sizeof($rows), "q" => $lq); - $this->sys_ok($result); - } else { - $this->sys_error_db("RE Px rows", $this->db_smartone); - exit; - } - } - - public function save() - { - $prm = $this->sys_input; - $data = json_decode($prm["data"]); - $lang = $this->lang_default_code; - $lang_id = isset($prm['lang_id']) ? $prm['lang_id'] : '0'; - - if ($lang_id != 0) { - $l = $this->db_smartone->where("Nat_LangID", $lang_id)->get("nat_lang")->row(); - $lang = $l->Nat_LangCode; - } - - $sql_norm = "select T_OrderDetailMinValue, T_OrderDetailMaxValue, - T_OrderDetailMinValueInclusive, T_OrderDetailMaxValueInclusive, - Nat_TestFlagLow, Nat_TestFlagHigh - from t_orderdetail - join t_test on T_OrderDetailT_TestID = T_TestID - join nat_test on T_TestNat_TestID = Nat_TestID and T_TestIsActive = 'Y' - where T_OrderDetailID = ? "; - - $ids = []; - foreach ($data as $k => $v) { - if ($v->resultInstrumentID > 0) { - $sql_i = "select T_ResultInstrumentNat_NormalValueID normalValueID - from t_resultinstrument - where T_ResultInstrumentID = ?"; - $qry_i = $this->db_smartone->query($sql_i, array($v->resultInstrumentID)); - if ($qry_i) { - $rows_i = $qry_i->result_array(); - - if (count($rows_i) > 0) { - $sql_iu = "update t_orderdetail, nat_normalvalue , nat_methode - set T_OrderDetailMinValue = Nat_NormalValueMinValue, - T_OrderDetailMinValueInclusive = Nat_NormalValueMinValueInclusive, - T_OrderDetailMaxValue = Nat_NormalValueMaxValue , - T_OrderDetailMaxValueInclusive = Nat_NormalValueMaxValueInclusive, - T_OrderDetailNormalValueNote = Nat_NormalValueNote, - T_OrderDetailNormalValueDescription = Nat_NormalValueDescription, - T_OrderDetailNat_NormalValueID = Nat_NormalValueID, - T_OrderDetailNat_MethodeID = Nat_NormalValueNat_MethodeID, - T_OrderDetailNat_MethodeName = Nat_MethodeName - where T_OrderDetailID = ? and Nat_NormalValueID = ? - and Nat_NormalValueNat_MethodeID = Nat_MethodeID - "; - $this->db_smartone->query($sql_iu, array($v->id, $rows_i[0]["normalValueID"])); - //file_put_contents("/xtmp/update-nilai-normal", $this->db_smartone->last_query() . "\n", FILE_APPEND); - } - } - } - $y = $this->db_smartone->query("SELECT fn_process_sample_handling_perfect('{$v->order_id}', '{$v->test_id}') c") - ->row(); - $req_status = $y->c; - $qry_norm = $this->db_smartone->query($sql_norm, $v->id); - $result_flag = ""; - if ($qry_norm) { - $rows_norm = $qry_norm->result_array(); - if (count($rows_norm) > 0) { - $r = $rows_norm[0]; - if (is_numeric($v->result)) { - - if ($r["T_OrderDetailMinValueInclusive"] == "Y" && $v->result < $r["T_OrderDetailMinValue"]) { - $result_flag = $r["Nat_TestFlagLow"]; - } - if ($r["T_OrderDetailMinValueInclusive"] == "N" && $v->result <= $r["T_OrderDetailMinValue"]) { - $result_flag = $r["Nat_TestFlagLow"]; - } - if ($r["T_OrderDetailMaxValueInclusive"] == "Y" && $v->result > $r["T_OrderDetailMaxValue"]) { - $result_flag = $r["Nat_TestFlagHigh"]; - } - if ($r["T_OrderDetailMaxValueInclusive"] == "N" && $v->result >= $r["T_OrderDetailMaxValue"]) { - $result_flag = $r["Nat_TestFlagHigh"]; - } - } - } - } - if ($lang == $this->lang_default_code) { - $this->db_smartone->set('T_OrderDetailResult', $v->result) - ->set('T_OrderDetailResultFlag', $result_flag) - ->set('T_OrderDetailNote', $v->note) - ->set('T_OrderDetailReqStatus', $req_status) - ->where('T_OrderDetailID', $v->id) - ->update('t_orderdetail'); - } else { - $this->db_smartone->set('T_OrderDetailLangResult', $v->result) - ->set('T_OrderDetailLangNote', $v->note) - ->where('T_OrderDetailLangID', $v->id) - ->update('t_orderdetaillang'); - } - - $ids[] = $v->id; - } - - // LOG Process - $order = $this->db_smartone->select('T_OrderDetailT_OrderHeaderID id, T_OrderHeaderLabNumber lab_number', false) - ->join('t_orderheader', 'T_OrderHeaderID = T_OrderDetailT_OrderHeaderID') - ->where('T_OrderDetailID', $data[0]->id) - ->get('t_orderdetail') - ->row(); - - $dblog = $this->load->database("onelog", true); - $dblog->set('Log_ProcessCode', 'PROCESS.Result.Entry') - ->set('Log_ProcessOrderID', $order->id) - ->set('Log_ProcessOrderNumber', $order->lab_number) - ->set('Log_ProcessJson', json_encode($data)) - ->set('Log_ProcessUserID', $this->sys_user['M_UserID']) - ->insert('log_process'); - // END OF Log Process - //auto calculation - $this->load->library("Resultcalc"); - $rows = $this->resultcalc->auto($order->id); - - try { - foreach ($ids as $id) { - $this->db_smartone->query("call sp_set_normal_value_flag($id)"); - $this->clean_mysqli_connection($this->db_smartone->conn_id); - } - } catch (Exception $e) { - } - - $this->sys_ok($ids); - } - - public function save_template() - { - $prm = $this->sys_input; - - $n = $this->db_smartone->select("COUNT(T_ResultTemplateID) n") - ->where("T_ResultTemplateT_TestID", $prm['test_id']) - ->where("T_ResultTemplateIsActive", "Y") - ->where("T_ResultTemplateValue", $prm['value']) - ->get('t_resulttemplate') - ->row(); - if ($n->n > 0) { - $this->sys_error_db("Insert Result Template", $this->db_smartone); - return; - } - - $r = $this->db_smartone->set("T_ResultTemplateT_TestID", $prm['test_id']) - ->set("T_ResultTemplateValue", $prm['value']) - ->insert('t_resulttemplate'); - if ($r) { - $template = []; - $x = $this->db_smartone->query("CALL sp_master_resulttemplate_get('{$prm['test_id']}')"); - $this->clean_mysqli_connection($this->db_smartone->conn_id); - if ($x) - $template = $x->result_array(); - - $this->sys_ok($template); - } - } - - public function export() - { - $prm = $this->sys_input; - - $sql = "CALL sp_process_result_lang(?, ?, ?, ?)"; - $query = $this->db_smartone->query($sql, [$prm['order_id'], $prm['lang_id'], $prm['is_si'], $this->sys_user['M_UserID']]); - if ($query) { - $r = $query->row(); - if ($r->status == "OK") { - $this->sys_ok($r->data); - return; - } - - $this->sys_error_db("Message : " . $r->message, $this->db_smartone); - } else { - $this->sys_error_db("Lang Result", $this->db_smartone); - return; - } - } - - public function search_group() - { - $prm = $this->sys_input; - $max_rst = 100; - - // QUERY TOTAL - $sql = "select count(*) total - from t_worklist - where T_WorklistIsActive = 'Y' - order by T_WorklistName ASC"; - $query = $this->db_smartone->query($sql); - - if ($query) { - $tot_count = $query->result_array()[0]["total"]; - } else { - $this->sys_error_db("worklist count", $this->db_smartone); - exit; - } - - $sql = "select T_WorklistID group_id, T_WorklistName group_name - from t_worklist - where T_WorklistIsActive = 'Y' - order by T_WorklistName ASC - limit 0, {$max_rst}"; - $query = $this->db_smartone->query($sql); - - if ($query) { - $rows = $query->result_array(); - foreach ($rows as $k => $v) - $rows[$k]['data'] = json_decode($v['data']); - $result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows), "q" => $this->db_smartone->last_query()); - $this->sys_ok($result); - } else { - $this->sys_error_db("worklist rows", $this->db_smartone); - exit; - } - } - - public function search_rerun() - { - $prm = $this->sys_input; - $id = $prm["detail_id"]; - - $sql = "CALL sp_process_result_rerun(?)"; - $query = $this->db_smartone->query($sql, [$id]); - - if ($query) { - $rows = $query->result_array(); - $this->sys_ok(["records" => $rows]); - } else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - - - function getdoctorsfna() - { - $prm = $this->sys_input; - // $id = $prm["id"]; - - $sql = " SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY M_DoctorName ASC"; - //echo $sql; - $query = $this->db_smartone->query($sql); - - if ($query) { - $rows = $query->result_array(); - $this->sys_ok(["records" => $rows]); - } else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - function getfnaresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT Other_FNADetailsID as xid, - Other_FNAT_OrderDetailID as orderdetail_id, - Other_FNADetailsCode as code, - Other_FNADetailsLabel as label, - Other_FNADetailsResult as result, - IFNULL(Other_FNAM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_FNAM_DoctorID) OR Other_FNAM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_fna - JOIN other_fnadetails ON Other_FNADetailsOther_FNAID = Other_FNAID AND Other_FNADetailsIsActive = 'Y' - LEFT JOIN m_doctor ON Other_FNAM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_FNAT_OrderDetailID = {$id} AND Other_FNAIsActive = 'Y' - GROUP BY Other_FNADetailsID - ORDER BY Other_FNADetailsCode ASC"; - $query = $this->db_smartone->query($sql); - - if ($query) { - $rows = $query->result_array(); - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $images = array(); - $sql = "SELECT So_ImageUploadID as xid, - CONCAT('/one-media/one-image-nonlab/',So_ImageUploadNewName) as image_url - FROM t_orderdetail - JOIN so_imageupload ON So_ImageUploadT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND - So_ImageUploadIsActive = 'Y' - WHERE - T_OrderDetailID = {$id} AND - T_OrderDetailIsActive = 'Y' - GROUP BY So_ImageUploadID"; - $images = $this->db_smartone->query($sql)->result_array(); - - $rst = array('doctors' => $doctors, 'results' => $rows, 'images' => $images); - $this->sys_ok(["records" => $rst]); - } else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - function getpatologianatomyresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT Other_PatologiAnatomyID as xid, - Other_PatologiAnatomyT_OrderDetailID as orderdetail_id, - Other_PatologiAnatomyNoSediaan as no_sediaan, - Other_PatologiAnatomyDiagnosaKlinis as diagnosa, - Other_PatologiAnatomyKeteranganKlinis as klinis, - Other_PatologiAnatomyLokasiOrgan as lokasi, - Other_PatologiAnatomyMakroskopik as makroskopik, - Other_PatologiAnatomyMikroskopik as mikroskopik, - Other_PatologiAnatomyKesimpulan as kesimpulan, - IFNULL(Other_PatologiAnatomyM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_PatologiAnatomyM_DoctorID) OR Other_PatologiAnatomyM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_patologi_anatomy - LEFT JOIN m_doctor ON Other_PatologiAnatomyM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_PatologiAnatomyT_OrderDetailID = {$id} AND Other_PatologiAnatomyIsActive = 'Y' - GROUP BY Other_PatologiAnatomyID - ORDER BY Other_PatologiAnatomyID ASC - LIMIT 1"; - $query = $this->db_smartone->query($sql); - - if ($query) { - $rows = $query->row_array(); - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - - $sql = "SELECT So_ImageUploadPatologyAnatomyID as xid, - CONCAT('/one-media/one-image-nonlab/',So_ImageUploadPatologyAnatomyNewName) as image_url, - So_ImageUploadPatologyAnatomyType as type - FROM t_orderdetail - JOIN so_imageupload_patology_anatomy ON So_ImageUploadPatologyAnatomyT_OrderHeaderID= T_OrderDetailT_OrderHeaderID AND - So_ImageUploadPatologyAnatomyIsActive= 'Y' - WHERE - T_OrderDetailID = {$id} AND - T_OrderDetailIsActive = 'Y' - GROUP BY So_ImageUploadPatologyAnatomyID"; - $images = $this->db_smartone->query($sql)->result_array(); - $mikro = []; - $makro = []; - - foreach ($images as $key => $value) { - - if ($value['type'] == 'mikro') { - $mikro[] = $value; - } - if ($value['type'] == 'makro') { - $makro[] = $value; - } - } - - $rst = array('doctors' => $doctors, 'result' => $rows, "mikro" => $mikro, "makro" => $makro); - $this->sys_ok(["records" => $rst]); - } else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - - function uploadimage() - { - if (! $this->isLogin) { - $this->sys_error("Invalid Token"); - exit; - } - - $userid = $this->sys_user["M_UserID"]; - $data = []; - //print_r($_SERVER); - - $prm = $this->sys_input; - $orderid = $this->input->post('orderid'); - $labnumber = $this->input->post('labnumber'); - $sql = "UPDATE so_imageupload SET - So_ImageUploadIsActive = 'N', - So_ImageUploadUserID = {$userid} - WHERE - So_ImageUploadT_OrderHeaderID = {$orderid}"; - //echo $sql; - $this->db_onedev->query($sql); - //$config['upload_path'] = 'assets/'; - - $path = '/home/one/project/one/one-media/one-image-nonlab/'; - //echo $path; - $config['upload_path'] = $path; - $config['allowed_types'] = 'jpg|jpeg|png|gif'; - - $config['max_size'] = '10000'; - $count = count($_FILES['files']['name']); - //echo $count; - $this->load->library('upload', $config); - - $error = []; - for ($i = 0; $i < $count; $i++) { - - - if (!empty($_FILES['files']['name'][$i])) { - - - - $_FILES['file']['name'] = $_FILES['files']['name'][$i]; - - $_FILES['file']['type'] = $_FILES['files']['type'][$i]; - - $_FILES['file']['tmp_name'] = $_FILES['files']['tmp_name'][$i]; - - $_FILES['file']['error'] = $_FILES['files']['error'][$i]; - - $_FILES['file']['size'] = $_FILES['files']['size'][$i]; - - - - $namex = $orderid . '-' . $labnumber . '-' . $this->generateRandomString(5); - //echo $namex; - - $config['file_name'] = $namex; - $this->upload->initialize($config); - //echo $config['file_name'] ; - - - - - - if ($this->upload->do_upload('file')) { - - $uploadData = $this->upload->data(); - - $filename = $uploadData['file_name']; - //echo $filename; - - - $sql = "INSERT INTO so_imageupload ( - So_ImageUploadT_OrderHeaderID, - So_ImageUploadT_OrderHeaderLabNumber, - So_ImageUploadT_SampleTypeID, - So_ImageUploadOldName, - So_ImageUploadNewName, - So_ImageUploadCreated, - So_ImageUploadUserID - ) - VALUES( - {$orderid}, - '{$labnumber}', - '150', - '{$_FILES['files']['name'][$i]}', - '{$filename}', - NOW(), - {$userid} - - )"; - //echo $sql; - $this->db_onedev->query($sql); - $xlast_id = $this->db_onedev->insert_id(); - $data['totalFiles'][] = array('xid' => $xlast_id, 'image_url' => '/one-media/one-image-nonlab/' . $filename); - } else { - $error = array('error' => $this->upload->display_errors()); - } - } - } - - $result = array("total" => count($data['totalFiles']), "records" => $data['totalFiles'], 'errors' => $error); - $this->sys_ok($result); - } - - - function generateRandomString($length = 10) - { - $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; - $charactersLength = strlen($characters); - $randomString = ''; - for ($i = 0; $i < $length; $i++) { - $randomString .= $characters[rand(0, $charactersLength - 1)]; - } - return $randomString; - } - - function getcytologiresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT Other_CytologiDetailsID as xid, - Other_CytologiT_OrderDetailID as orderdetail_id, - Other_CytologiDetailsCode as code, - Other_CytologiDetailsLabel as label, - Other_CytologiDetailsResult as result, - IFNULL(Other_CytologiM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_CytologiM_DoctorID) OR Other_CytologiM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_cytologi - JOIN other_cytologidetails ON Other_CytologiDetailsOther_CytologiID = Other_CytologiID AND Other_CytologiDetailsIsActive = 'Y' - LEFT JOIN m_doctor ON Other_CytologiM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_CytologiT_OrderDetailID = {$id} AND Other_CytologiIsActive = 'Y' - GROUP BY Other_CytologiDetailsID - ORDER BY Other_CytologiDetailsCode ASC"; - //echo $sql; - $query = $this->db_smartone->query($sql); - - if ($query) { - $rows = $query->result_array(); - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $rst = array('doctors' => $doctors, 'results' => $rows); - $this->sys_ok(["records" => $rst]); - } else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - function getmikroresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT - Other_MikroID as xid, - Other_MikroHasilBiakan as hasil_biakan, - Other_MikroSampleTypeName as sample_name, - Other_MikroT_OrderDetailID as orderdetail_id, - Other_MikroResult as result_value, - '' as result_other, - IFNULL(T_BacteriaID,0) as T_BacteriaID, - IFNULL(T_BacteriaName,'') as T_BacteriaName, - '' as details, - IFNULL(Other_MikroM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_MikroM_DoctorID) OR Other_MikroM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_mikro - LEFT JOIN t_bacteria ON Other_MikroT_BacteriaID = T_BacteriaID - LEFT JOIN m_doctor ON Other_MikroM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_MikroT_OrderDetailID = {$id} AND Other_MikroIsActive = 'Y' - GROUP BY Other_MikroID"; - //echo $sql; - $query = $this->db_smartone->query($sql); - - if ($query) { - $row = $query->row_array(); - if ($row) { - if ($row['result_value'] != 'Positif' && $row['result_value'] != 'Negatif') { - $row['result_other'] = $row['result_value']; - $row['result_value'] = 'other'; - } - $sql = "SELECT '' as xno, - Other_MikroDetailsID as xid, - Other_MikroDetailsValue as value, - IF(Other_MikroDetailsNote = 'R','Y','N') as chx_r, - IF(Other_MikroDetailsNote = 'I','Y','N') as chx_i, - IF(Other_MikroDetailsNote = 'S','Y','N') as chx_s, - Other_MikroDetailsNote as note, - t_antibiotic.* - FROM other_mikrodetails - LEFT JOIN t_antibiotic ON Other_MikroDetailsT_AntibioticID = T_AntibioticID - WHERE - Other_MikroDetailsOther_MikroID = {$row['xid']} AND Other_MikroDetailsIsActive = 'Y' - GROUP BY Other_MikroDetailsID - ORDER BY T_AntibioticName ASC"; - //echo $sql; - $details = $this->db_smartone->query($sql)->result_array(); - if (details) { - foreach ($details as $k => $v) { - $details[$k]['xno'] = $k + 1; - } - } - $row['details'] = $details; - } else { - $row = array('xid' => '0', 'hasil_biakan' => '', 'result_value' => 'Negatif', 'sample_name' => '', 'orderdetail_id' => $id, 'T_BacteriaID' => '0', 'T_BacteriaName' => '0', 'details' => array(), 'doctor_id' => '0', 'doctor_name' => '0'); - } - } else { - $row = array('xid' => '0', 'hasil_biakan' => '', 'result_value' => 'Negatif', 'sample_name' => '', 'orderdetail_id' => $id, 'T_BacteriaID' => '0', 'T_BacteriaName' => '0', 'details' => array(), 'doctor_id' => '0', 'doctor_name' => '0'); - } - //print_r($row); - - - - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 7 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $sql = " - SELECT '0' as id, 'Belum memilih bakteria' as name - UNION - SELECT T_BacteriaID as id, T_BacteriaName as name - FROM t_bacteria - WHERE - T_BacteriaIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $bacteries = $this->db_smartone->query($sql)->result_array(); - $rst = array('doctors' => $doctors, 'bacteries' => $bacteries, 'results' => $row); - $this->sys_ok(["records" => $rst]); - } - function getantibiotics() - { - $prm = $this->sys_input; - $id = $prm["id"]; - $sql = " SELECT '' as xno, - 0 as xid, - '' as hasil_biakan, - '' as sample_name, - 0 as value, - 'Y' as chx_r, - 'N' as chx_i, - 'N' as chx_s, - 'R' as note, - t_antibiotic.* - FROM t_antibiotic - WHERE - T_AntibioticT_BacteriaID = {$prm['id']} AND T_AntibioticIsActive= 'Y' - ORDER BY T_AntibioticName ASC"; - //echo $sql; - $rows = $this->db_smartone->query($sql)->result_array(); - if (rows) { - foreach ($rows as $k => $v) { - $rows[$k]['xno'] = $k + 1; - } - } - - $this->sys_ok(["records" => $rows]); - } - function getlcprepresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - $sql = " SELECT Other_LcprepDetailsID as xid, - Other_LcprepID as header_id, - Other_LcprepT_orderDetailID as orderdetail_id, - Other_LcprepDetailsCode as code, - Other_LcprepDetailsLabel as label, - Other_LcprepDetailsResult as result, - IFNULL(Other_LcprepM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_LcprepM_DoctorID) OR Other_LcprepM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_lcprep - JOIN other_lcprepdetails ON Other_LcprepDetailsOther_LcprepID = Other_LcprepID AND Other_LcprepDetailsIsActive = 'Y' - LEFT JOIN m_doctor ON Other_LcprepM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_LcprepT_orderDetailID = {$id} AND Other_LcprepIsActive = 'Y' - GROUP BY Other_LcprepDetailsOther_LcprepID, Other_LcprepDetailsCode - ORDER BY Other_LcprepDetailsCode ASC"; - //echo $sql; - $rows = $this->db_smartone->query($sql)->result_array(); - if (!$rows) { - $rows = array( - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'A', - 'label' => 'DESKRIPSI', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ), - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'B', - 'label' => 'KESIMPULAN', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ) - ); - } - - $header_id = $rows[0]['header_id']; - $sql = "SELECT IFNULL(Other_LcprepAdekuasiID,0) as xid, - Lcprep_AdekuasiID as id, - Lcprep_AdekuasiLabel as name, - IF(ISNULL(Other_LcprepAdekuasiID),'N',Other_LcprepAdekuasiChex) as chex - FROM lcprep_adekuasi - LEFT JOIN other_lcprepadekuasi ON Other_LcprepAdekuasiLcprep_AdekuasiID = Lcprep_AdekuasiID AND - Other_LcprepAdekuasiOther_LcprepID = {$header_id} AND - Other_LcprepAdekuasiIsActive = 'Y' - WHERE - Lcprep_AdekuasiIsActive = 'Y' - GROUP BY Lcprep_AdekuasiID - ORDER BY Lcprep_AdekuasiOrder ASC - "; - //echo $sql; - $adeakuasi = $this->db_smartone->query($sql)->result_array(); - foreach ($adeakuasi as $kc => $vc) { - $adeakuasi[$kc]['chex'] = $vc['chex'] == 'N' ? false : true; - } - - $sql = "SELECT IFNULL(Other_LcprepKategoriUmumID,0) as xid, - Lcprep_KategoriUmumID as id, - Lcprep_KategoriUmumLabel as name, - IF(ISNULL(Other_LcprepKategoriUmumID),'N',Other_LcprepKategoriUmumChex) as chex - FROM lcprep_kategoriumum - LEFT JOIN other_lcprepkategoriumum ON Other_LcprepKategoriUmumLcprep_KategoriUmumID = Lcprep_KategoriUmumID AND - Other_LcprepKategoriUmumOther_LcprepID = {$header_id} AND - Other_LcprepKategoriUmumIsActive = 'Y' - WHERE - Lcprep_KategoriUmumIsActive = 'Y' - GROUP BY Lcprep_KategoriUmumID - "; - //echo $sql; - $kategoriumum = $this->db_smartone->query($sql)->result_array(); - foreach ($kategoriumum as $kc => $vc) { - $kategoriumum[$kc]['chex'] = $vc['chex'] == 'N' ? false : true; - } - - $sql = " - SELECT Lcprep_InterpretasiGroupID as group_id, - Lcprep_InterpretasiGroupName as group_name, - '' as subgroups - FROM lcprep_interpretasigroup - WHERE - Lcprep_InterpretasiGroupIsActive = 'Y' - "; - //echo $sql; - $interpretasi = $this->db_smartone->query($sql)->result_array(); - foreach ($interpretasi as $k => $v) { - $subgroups = array(); - $sql = "SELECT Lcprep_InterpretasiSubgroupID as subgroup_id, - Lcprep_InterpretasiSubgroupName as subgroup_name, - '' as childs - FROM lcprep_interpretasisubgroup - WHERE - Lcprep_InterpretasiSubgroupLcprep_InterpretasiGroupID = {$v['group_id']} AND Lcprep_InterpretasiSubgroupIsActive = 'Y'"; - //echo $sql; - $subgroups = $this->db_smartone->query($sql)->result_array(); - if (count($subgroups) > 0) { - foreach ($subgroups as $ki => $vi) { - $childs = array(); - $sql = "SELECT IFNULL(Other_LcprepInterpretasiID,0) as xid, - IFNULL(Other_LcprepInterpretasiChex,'N') as chex, - IFNULL(Other_LcprepInterpretasiValue,'') as value, - Lcprep_InterpretasiID as id, - Lcprep_InterpretasiLcprep_InterpretasiSubgroupID as subgroup_id, - Lcprep_InterpretasiCode as code, - Lcprep_InterpretasiName as name, - Lcprep_InterpretasiParentID as parent_id, - Lcprep_InterpretasiIsParent as is_parent, - Lcprep_InterpretasiHasResult as has_result, - Lcprep_InterpretasiTypeResult as type_result - FROM lcprep_interpretasi - LEFT JOIN other_lcprepinterpretasi ON Other_LcprepInterpretasiOther_LcprepID = {$header_id} AND - Other_LcprepInterpretasiLcprep_InterpretasiID = Lcprep_InterpretasiID AND - Other_LcprepInterpretasiIsActive = 'Y' - WHERE - Lcprep_InterpretasiLcprep_InterpretasiSubgroupID = {$vi['subgroup_id']} AND Lcprep_InterpretasiIsActive = 'Y' - GROUP BY Lcprep_InterpretasiID Order BY Lcprep_InterpretasiCode ASC"; - $childs = $this->db_smartone->query($sql)->result_array(); - if ($childs) { - foreach ($childs as $kc => $vc) { - $childs[$kc]['chex'] = $vc['chex'] == 'N' ? false : true; - } - } - $subgroups[$ki]['childs'] = $childs; - } - } - - $interpretasi[$k]['subgroups'] = $subgroups; - } - - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $rst = array('doctors' => $doctors, 'results' => $rows, 'adekuasi' => $adeakuasi, 'kategoriumum' => $kategoriumum, 'interpretasi' => $interpretasi); - $this->sys_ok(["records" => $rst]); - } - - function getpapsmearresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT Other_PapSmearDetailsID as xid, - Other_PapSmearID as header_id, - Other_PapSmearT_OrderDetailID as orderdetail_id, - Other_PapSmearDetailsCode as code, - Other_PapSmearDetailsLabel as label, - Other_PapSmearDetailsResult as result, - IFNULL(Other_PapSmearM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_PapSmearM_DoctorID) OR Other_PapSmearM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_papsmear - JOIN other_papsmeardetails ON Other_PapSmearDetailsOther_PapSmearID = Other_PapSmearID AND Other_PapSmearDetailsIsActive = 'Y' - LEFT JOIN m_doctor ON Other_PapSmearM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_PapSmearT_OrderDetailID = {$id} AND Other_PapSmearIsActive = 'Y' - GROUP BY Other_PapSmearDetailsID - ORDER BY Other_PapSmearDetailsCode ASC"; - //echo $sql; - $rows = $this->db_smartone->query($sql)->result_array(); - if (!$rows) { - $rows = array( - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'A', - 'label' => 'Makroskopik', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ), - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'B', - 'label' => 'Mikroskopik', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ), - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'C', - 'label' => 'Kesimpulan', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ) - ); - } - - $header_id = $rows[0]['header_id']; - $sql = "SELECT Other_PapSmearMaturasiID as xid, - Other_PapSmearMaturasiValue as value - FROM other_papsmearmaturasi - WHERE - Other_PapSmearMaturasiOther_PapSmearID = {$header_id} AND - Other_PapSmearMaturasiIsActive = 'Y' - "; - //echo $sql; - $dt_maturasi = $this->db_smartone->query($sql)->row_array(); - if (!$dt_maturasi) { - $maturasi = array('xid' => '0', 'value' => array('', '', '')); - } else { - $value = explode('/', $dt_maturasi['value']); - $maturasi = array('xid' => $dt_maturasi['xid'], 'value' => $value); - } - - $sql = "SELECT IFNULL(Other_PapSmearBahanID,0) as xid, - M_PapSmearBahanID as bahan_id, - M_PapSmearBahanName as name, - IF(ISNULL(Other_PapSmearBahanID),'N','Y') as selected - FROM m_papsmearbahan - LEFT JOIN other_papsmearbahan ON Other_PapSmearBahanM_PapSmearBahanID = M_PapSmearBahanID AND - Other_PapSmearBahanOther_PapSmearID = {$header_id} AND - Other_PapSmearBahanIsActive = 'Y' - WHERE - M_PapSmearBahanIsActive = 'Y' - ORDER BY M_PapSmearBahanID ASC - "; - //echo $sql; - $bahans = $this->db_smartone->query($sql)->result_array(); - - $sql = "SELECT IFNULL(Other_PapsmearCategoryID,0) as xid, - M_PapSmearCategoryID as category_id, - M_PapSmearCategoryName as name, - IF(ISNULL(Other_PapsmearCategoryID),'N','Y') as selected - FROM m_papsmearcategory - LEFT JOIN other_papsmearcategory ON Other_PapsmearCategoryM_PapSmearCategoryID = M_PapSmearCategoryID AND - Other_PapsmearCategoryOther_PapSmearID = {$header_id} AND - Other_PapsmearCategoryIsActive = 'Y' - WHERE - M_PapSmearCategoryIsActive = 'Y' - ORDER BY M_PapSmearCategoryID ASC - "; - //echo $sql; - $categories = $this->db_smartone->query($sql)->result_array(); - - $sql = "SELECT IFNULL(Other_PapSmearCheckID,0) as xid, - M_PapSmearCheckID as check_id, - M_PapSmearCheckLabel as name, - IF(ISNULL(Other_PapSmearCheckID),'N','Y') as selected, - Other_PapSmearCheckNote as note - FROM m_papsmearcheck - LEFT JOIN other_papsmearcheck ON Other_PapSmearCheckM_PapSmearCheckID = M_PapSmearCheckID AND - Other_PapSmearCheckOther_PapSmearID = {$header_id} AND - Other_PapSmearCheckIsActive = 'Y' - WHERE - M_PapSmearCheckIsActive = 'Y' - ORDER BY M_PapSmearCheckCode ASC - "; - $checks = $this->db_smartone->query($sql)->result_array(); - - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $rst = array('doctors' => $doctors, 'checks' => $checks, 'bahans' => $bahans, 'categories' => $categories, 'maturasi' => $maturasi, 'results' => $rows); - $this->sys_ok(["records" => $rst]); - } - - function saveresult_lcprep() - { - $prm = $this->sys_input; - $detail_id = $prm['detail_id']; - $doctor_id = $prm['doctor']; - $adekuasi = $prm['adekuasi']; - $kategoriumum = $prm['kategoriumum']; - $interpretasi = $prm['interpretasi']; - $results = $prm['results']; - - $userid = $this->sys_user['M_UserID']; - - $header_id = 0; - $sql = "SELECT * FROM other_lcprep WHERE Other_LcprepT_orderDetailID = {$detail_id} AND Other_LcprepIsActive = 'Y'"; - $dt_header = $this->db_smartone->query($sql)->row_array(); - if ($dt_header) { - $header_id = $dt_header['Other_LcprepID']; - } - if ($header_id == 0) { - $sql = "INSERT INTO other_lcprep( - Other_LcprepT_orderDetailID, - Other_LcprepM_DoctorID, - Other_LcprepUserID, - Other_LcprepCreated - ) - VALUES( - {$detail_id}, - {$doctor_id}, - {$userid}, - NOW() - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } else { - $sql = "UPDATE other_lcprep SET Other_LcprepM_DoctorID = {$doctor_id}, Other_LcprepUserID = {$userid} WHERE Other_LcprepID = {$header_id}"; - $this->db_smartone->query($sql); - } - - if ($adekuasi) { - foreach ($adekuasi as $k => $v) { - $selected = $v['chex'] ? 'Y' : 'N'; - if (intval($v['xid'] == 0)) { - $sql = "UPDATE other_lcprepadekuasi SET Other_LcprepAdekuasiIsActive = 'N' - WHERE - Other_LcprepAdekuasiOther_LcprepID = {$header_id} AND - Other_LcprepAdekuasiIsActive = 'Y' AND - Other_LcprepAdekuasiLcprep_AdekuasiID = {$v['id']}"; - $this->db_smartone->query($sql); - $sql = "INSERT INTO other_lcprepadekuasi ( - Other_LcprepAdekuasiOther_LcprepID, - Other_LcprepAdekuasiLcprep_AdekuasiID, - Other_LcprepAdekuasiChex, - Other_LcprepAdekuasiUserID, - Other_LcprepAdekuasiCreated - ) - VALUES( - {$header_id}, - {$v['id']}, - '{$selected}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - //echo $sql; - } - if (intval($v['xid'] != 0)) { - - $sql = "UPDATE other_lcprepadekuasi SET - Other_LcprepAdekuasiChex = '{$selected}', - Other_LcprepAdekuasiUserID = {$userid} - WHERE - Other_LcprepAdekuasiID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - - //echo $sql; - } - } - - if ($kategoriumum) { - foreach ($kategoriumum as $k => $v) { - $selected = $v['chex'] ? 'Y' : 'N'; - if (intval($v['xid'] == 0)) { - $sql = "UPDATE other_lcprepkategoriumum SET Other_LcprepKategoriUmumIsActive = 'N' - WHERE - Other_LcprepKategoriUmumOther_LcprepID = {$header_id} AND - Other_LcprepKategoriUmumLcprep_KategoriUmumID = {$v['id']} AND - Other_LcprepKategoriUmumIsActive = 'Y' - "; - $this->db_smartone->query($sql); - $sql = "INSERT INTO other_lcprepkategoriumum ( - Other_LcprepKategoriUmumOther_LcprepID, - Other_LcprepKategoriUmumLcprep_KategoriUmumID, - Other_LcprepKategoriUmumChex, - Other_LcprepKategoriUmumUserID, - Other_LcprepKategoriUmumCreated - ) - VALUES( - {$header_id}, - {$v['id']}, - '{$selected}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if (intval($v['xid'] != 0)) { - $sql = "UPDATE other_lcprepkategoriumum SET - Other_LcprepKategoriUmumChex = '{$selected}', - Other_LcprepKategoriUmumUserID = {$userid} - WHERE - Other_LcprepKategoriUmumID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - - //echo $sql; - } - } - - if ($results) { - foreach ($results as $k => $v) { - if (intval($v['xid'] == 0)) { - $sql = "UPDATE other_lcprepdetails SET Other_LcprepDetailsIsActive = 'N' - WHERE - Other_LcprepDetailsOther_LcprepID = {$header_id} AND - Other_LcprepDetailsCode = '{$v['code']}' AND - Other_LcprepDetailsIsActive = 'Y'"; - $this->db_smartone->query($sql); - $sql = "INSERT INTO other_lcprepdetails ( - Other_LcprepDetailsOther_LcprepID, - Other_LcprepDetailsCode, - Other_LcprepDetailsLabel, - Other_LcprepDetailsResult, - Other_LcprepDetailsUserID, - Other_LcprepDetailsCreated - ) - VALUES( - {$header_id}, - '{$v['code']}', - '{$v['label']}', - '{$v['result']}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if (intval($v['xid'] != 0)) { - $sql = "UPDATE other_lcprepdetails SET - Other_LcprepDetailsCode = '{$v['code']}', - Other_LcprepDetailsLabel = '{$v['label']}', - Other_LcprepDetailsResult = '{$v['result']}', - Other_LcprepDetailsUserID = {$userid} - WHERE - Other_LcprepDetailsID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - //echo $sql; - } - } - - if ($interpretasi) { - foreach ($interpretasi as $k => $v) { - if (count($v['subgroups']) > 0) { - foreach ($v['subgroups'] as $ik => $iv) { - if (count($iv['childs']) > 0) { - foreach ($iv['childs'] as $iik => $iiv) { - if (intval($iiv['xid'] == 0)) { - $chex = $iiv['chex'] ? 'Y' : 'N'; - $sql = "UPDATE other_lcprepinterpretasi SET Other_LcprepInterpretasiIsActive = 'N' - WHERE - Other_LcprepInterpretasiOther_LcprepID = {$header_id} AND - Other_LcprepInterpretasiLcprep_InterpretasiID = '{$iiv['id']}' AND - Other_LcprepInterpretasiIsActive = 'Y'"; - $this->db_smartone->query($sql); - $sql = "INSERT INTO other_lcprepinterpretasi ( - Other_LcprepInterpretasiOther_LcprepID, - Other_LcprepInterpretasiLcprep_InterpretasiID, - Other_LcprepInterpretasiChex, - Other_LcprepInterpretasiValue, - Other_LcprepInterpretasiUserID, - Other_LcprepInterpretasiCreated - ) - VALUES( - {$header_id}, - '{$iiv['id']}', - '{$chex}', - '{$iiv['value']}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - - if (intval($iiv['xid'] != 0)) { - $chex = $iiv['chex'] ? 'Y' : 'N'; - $sql = "UPDATE other_lcprepinterpretasi SET - Other_LcprepInterpretasiChex = '{$chex}', - Other_LcprepInterpretasiValue = '{$iiv['value']}', - Other_LcprepInterpretasiUserID = {$userid} - WHERE - Other_LcprepInterpretasiID = {$iiv['xid']}"; - $this->db_smartone->query($sql); - //echo $sql; - - } - } - } - } - } - //echo $sql; - } - } - - - $result = array("total" => 1, "records" => array(), "sql" => ''); - $this->sys_ok($result); - exit; - } - - function saveresult_papsmear() - { - $prm = $this->sys_input; - $detail_id = $prm['detail_id']; - $doctor_id = $prm['doctor']; - $checks = $prm['checks']; - $maturasi = $prm['maturasi']; - $bahans = $prm['bahans']; - $categories = $prm['categories']; - $results = $prm['results']; - - $userid = $this->sys_user['M_UserID']; - - $header_id = 0; - $sql = "SELECT * FROM other_papsmear WHERE Other_PapSmearT_OrderDetailID = {$detail_id} AND Other_PapSmearIsActive = 'Y'"; - $dt_header = $this->db_smartone->query($sql)->row_array(); - if ($dt_header) { - $header_id = $dt_header['Other_PapSmearID']; - } - if ($header_id == 0) { - $sql = "INSERT INTO other_papsmear( - Other_PapSmearT_OrderDetailID, - Other_PapSmearM_DoctorID, - Other_PapSmearUserID, - Other_PapSmearCreated - ) - VALUES( - {$detail_id}, - {$doctor_id}, - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } else { - $sql = "UPDATE other_papsmear SET Other_PapSmearM_DoctorID = {$doctor_id}, Other_PapSmearUserID = {$userid} WHERE Other_PapSmearID = {$header_id}"; - $this->db_smartone->query($sql); - } - - if ($checks) { - foreach ($checks as $k => $v) { - if (intval($v['xid']) == 0 && $v['selected'] === 'Y') { - $sql = "INSERT INTO other_papsmearcheck ( - Other_PapSmearCheckOther_PapSmearID, - Other_PapSmearCheckM_PapSmearCheckID, - Other_PapSmearCheckNote, - Other_PapSmearCheckUserID, - Other_PapSmearCheckCreated - ) - VALUES( - {$header_id}, - {$v['check_id']}, - '{$v['note']}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if (intval($v['xid']) != 0 && $v['selected'] === 'N') { - $sql = "UPDATE other_papsmearcheck SET - Other_PapSmearCheckIsActive = 'N', - Other_PapSmearCheckUserID = {$userid} - WHERE - Other_PapSmearCheckID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - if (intval($v['xid']) != 0 && $v['selected'] === 'Y') { - $sql = "UPDATE other_papsmearcheck SET - Other_PapSmearCheckNote = '{$v['note']}', - Other_PapSmearCheckUserID = {$userid} - WHERE - Other_PapSmearCheckID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - //echo $sql; - } - } - - if ($maturasi) { - if (intval($maturasi['xid']) == 0) { - $value = join("/", $maturasi['value']); - $sql = "INSERT INTO other_papsmearmaturasi ( - Other_PapSmearMaturasiOther_PapSmearID, - Other_PapSmearMaturasiValue, - Other_PapSmearMaturasiUserID, - Other_PapSmearMaturasiCreated - ) - VALUE( - {$header_id}, - '{$value}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - //echo $sql; - } - if (intval($maturasi['xid']) != 0) { - $value = join("/", $maturasi['value']); - $sql = "UPDATE other_papsmearmaturasi SET - Other_PapSmearMaturasiValue = '{$value}', - Other_PapSmearMaturasiUserID = {$userid} - WHERE - Other_PapSmearMaturasiID = {$maturasi['xid']}"; - // echo $sql; - $this->db_smartone->query($sql); - } - } - - if ($bahans) { - foreach ($bahans as $k => $v) { - if (intval($v['xid']) == 0 && $v['selected'] === 'Y') { - $sql = "INSERT INTO other_papsmearbahan ( - Other_PapSmearBahanOther_PapSmearID, - Other_PapSmearBahanM_PapSmearBahanID, - Other_PapSmearBahanUserID, - Other_PapSmearBahanCreated - ) - VALUES( - {$header_id}, - {$v['bahan_id']}, - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if (intval($v['xid']) != 0 && $v['selected'] === 'N') { - $sql = "UPDATE other_papsmearbahan SET - Other_PapSmearBahanIsActive = 'N', - Other_PapsmearCategoryUserID = {$userid} - WHERE - Other_PapSmearBahanID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - if (intval($v['xid']) != 0 && $v['selected'] === 'Y') { - $sql = "UPDATE other_papsmearbahan SET - Other_PapSmearBahanIsActive = 'Y', - Other_PapsmearCategoryUserID = {$userid} - WHERE - Other_PapSmearBahanID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - //echo $sql; - } - } - - if ($categories) { - foreach ($categories as $k => $v) { - if (intval($v['xid']) == 0 && $v['selected'] === 'Y') { - $sql = "INSERT INTO other_papsmearcategory ( - Other_PapsmearCategoryOther_PapSmearID, - Other_PapsmearCategoryM_PapSmearCategoryID, - Other_PapsmearCategoryUserID, - Other_PapsmearCategoryCreated - ) - VALUES( - {$header_id}, - {$v['category_id']}, - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if (intval($v['xid']) != 0 && $v['selected'] === 'N') { - $sql = "UPDATE other_papsmearcategory SET - Other_PapsmearCategoryIsActive = 'N', - Other_PapsmearCategoryUserID = {$userid} - WHERE - Other_PapsmearCategoryID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - //echo $sql; - if (intval($v['xid']) != 0 && $v['selected'] === 'Y') { - $sql = "UPDATE other_papsmearcategory SET - Other_PapsmearCategoryIsActive = 'Y', - Other_PapsmearCategoryUserID = {$userid} - WHERE - Other_PapsmearCategoryID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - } - } - - if ($results) { - foreach ($results as $k => $v) { - if (intval($v['xid']) == 0) { - $sql = "INSERT INTO other_papsmeardetails ( - Other_PapSmearDetailsOther_PapSmearID, - Other_PapSmearDetailsCode, - Other_PapSmearDetailsLabel, - Other_PapSmearDetailsResult, - Other_PapSmearDetailsUserID, - Other_PapSmearDetailsCreated - ) - VALUES( - {$header_id}, - '{$v['code']}', - '{$v['label']}', - '{$v['result']}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if (intval($v['xid']) != 0) { - $sql = "UPDATE other_papsmeardetails SET - Other_PapSmearDetailsCode = '{$v['code']}', - Other_PapSmearDetailsLabel = '{$v['label']}', - Other_PapSmearDetailsResult = '{$v['result']}', - Other_PapSmearDetailsUserID = {$userid} - WHERE - Other_PapSmearDetailsID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - //echo $sql; - } - } - - $result = array("total" => 1, "records" => array(), "sql" => ''); - $this->sys_ok($result); - exit; - } - - function saveresult_fna() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = $inp['doctor']; - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - if ($prm[0]['xid'] == '0') { - $sql = "INSERT INTO other_fna( - Other_FNAM_DoctorID, - Other_FNAT_OrderDetailID, - Other_FNAUserID, - Other_FNACreated - ) - VALUES( - {$doctor_id}, - {$prm[0]['orderdetail_id']}, - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } else { - $sql = "SELECT * FROM other_fna WHERE Other_FNAT_OrderDetailID = {$prm[0]['orderdetail_id']} AND Other_FNAIsActive = 'Y'"; - $data_header = $this->db_smartone->query($sql)->row_array(); - $header_id = $data_header['Other_FNAID']; - $sql = "UPDATE other_fna SET - Other_FNAM_DoctorID = {$doctor_id}, - Other_FNAUserID = {$userid} - WHERE - Other_FNAID = {$header_id}"; - $this->db_smartone->query($sql); - } - foreach ($prm as $k => $v) { - if ($v['xid'] == '0') { - $results = str_replace("'", "\\'", $v['result']); - $sql = "INSERT INTO other_fnadetails( - Other_FNADetailsOther_FNAID , - Other_FNADetailsCode, - Other_FNADetailsLabel, - Other_FNADetailsResult, - Other_FNADetailsCreated, - Other_FNADetailsUserID - ) - VALUES( - {$header_id}, - '{$v['code']}', - '{$v['label']}', - '{$results}', - NOW(), - {$userid} - )"; - $query = $this->db_smartone->query($sql); - } else { - $results = str_replace("'", "\\'", $v['result']); - $sql = "UPDATE other_fnadetails SET - Other_FNADetailsResult = '{$results}', - Other_FNADetailsUserID = {$userid} - WHERE - Other_FNADetailsID = {$v['xid']}"; - $query = $this->db_smartone->query($sql); - } - } - - $result = array("total" => 1, "records" => array(), "sql" => ''); - $this->sys_ok($result); - exit; - } - - function saveresult_cytologi() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = $inp['doctor']; - - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - if ($prm[0]['xid'] == '0') { - $sql = "INSERT INTO other_cytologi( - Other_CytologiT_OrderDetailID, - Other_CytologiM_DoctorID, - Other_CytologiUserID, - Other_CytologiCreated - ) - VALUES( - {$prm[0]['orderdetail_id']}, - {$doctor_id}, - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } else { - $sql = "SELECT * FROM other_cytologi WHERE Other_CytologiT_OrderDetailID = {$prm[0]['orderdetail_id']} AND Other_CytologiIsActive = 'Y'"; - $data_header = $this->db_smartone->query($sql)->row_array(); - $header_id = $data_header['Other_CytologiID']; - $sql = "UPDATE other_cytologi SET - Other_CytologiM_DoctorID = {$doctor_id}, - Other_CytologiUserID = {$userid} - WHERE - Other_CytologiID = {$header_id}"; - $this->db_smartone->query($sql); - } - foreach ($prm as $k => $v) { - if ($v['xid'] == '0') { - $results = str_replace("'", "\\'", $v['result']); - $sql = "INSERT INTO other_cytologidetails( - Other_CytologiDetailsOther_CytologiID , - Other_CytologiDetailsCode, - Other_CytologiDetailsLabel, - Other_CytologiDetailsResult, - Other_CytologiDetailsCreated, - Other_CytologiDetailsUserID - ) - VALUES( - {$header_id}, - '{$v['code']}', - '{$v['label']}', - '{$results}', - NOW(), - {$userid} - )"; - $query = $this->db_smartone->query($sql); - } else { - $results = str_replace("'", "\\'", $v['result']); - $sql = "UPDATE other_cytologidetails SET - Other_CytologiDetailsResult = '{$results}', - Other_CytologiDetailsUserID = {$userid} - WHERE - Other_CytologiDetailsID = {$v['xid']}"; - $query = $this->db_smartone->query($sql); - } - } - - $result = array("total" => 1, "records" => array(), "sql" => ''); - $this->sys_ok($result); - exit; - } - - function saveresult_mikro() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = $inp['doctor']; - $backteria_id = $inp['bacteria']; - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - - if ($inp['result_value'] != 'Negatif' && $inp['result_value'] != 'Positif') { - $prm['result_value'] = $prm['result_other']; - } else { - $prm['result_value'] = $inp['result_value']; - } - - if ($prm['xid'] == '0') { - $sql = "INSERT INTO other_mikro( - Other_MikroM_DoctorID, - Other_MikroResult, - Other_MikroT_BacteriaID, - Other_MikroT_OrderDetailID, - Other_MikroHasilBiakan, - Other_MikroSampleTypeName, - Other_MikroUserID, - Other_MikroCreated - ) - VALUES( - {$doctor_id}, - '{$prm['result_value']}', - {$backteria_id}, - {$prm['orderdetail_id']}, - '{$prm['hasil_biakan']}', - '{$prm['sample_name']}', - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } else { - $sql = "SELECT * FROM other_mikro WHERE Other_MikroT_OrderDetailID = {$prm['orderdetail_id']} AND Other_MikroIsActive = 'Y'"; - $data_header = $this->db_smartone->query($sql)->row_array(); - $header_id = $data_header['Other_MikroID']; - $sql = "UPDATE other_mikro SET - Other_MikroResult = '{$prm['result_value']}', - Other_MikroM_DoctorID = {$doctor_id}, - Other_MikroT_BacteriaID = {$backteria_id}, - Other_MikroHasilBiakan = '{$prm['hasil_biakan']}', - Other_MikroSampleTypeName = '{$prm['sample_name']}', - Other_MikroUserID = {$userid} - WHERE - Other_MikroID = {$header_id}"; - //echo $sql; - $this->db_smartone->query($sql); - } - - - - $sql = "UPDATE other_mikrodetails SET Other_MikroDetailsIsActive = 'N', Other_MikroDetailsUserID = 0 WHERE Other_MikroDetailsOther_MikroID = {$header_id}"; - $this->db_smartone->query($sql); - - $results = $prm['details']; - if ($inp['result_value'] == 'Positif') { - foreach ($results as $k => $v) { - if ($v['xid'] == '0') { - $sql = "INSERT INTO other_mikrodetails( - Other_MikroDetailsOther_MikroID , - Other_MikroDetailsT_AntibioticID, - Other_MikroDetailsValue, - Other_MikroDetailsNote, - Other_MikroDetailsCreated, - Other_MikroDetailsUserID - ) - VALUES( - {$header_id}, - '{$v['T_AntibioticID']}', - '{$v['value']}', - '{$v['note']}', - NOW(), - {$userid} - )"; - $query = $this->db_smartone->query($sql); - } else { - $sql = "UPDATE other_mikrodetails SET - Other_MikroDetailsT_AntibioticID = '{$v['T_AntibioticID']}', - Other_MikroDetailsValue = '{$v['value']}', - Other_MikroDetailsNote = '{$v['note']}', - Other_MikroDetailsIsActive = 'Y', - Other_MikroDetailsUserID = {$userid} - WHERE - Other_MikroDetailsID = {$v['xid']}"; - //echo $sql; - $query = $this->db_smartone->query($sql); - } - } - } - - - $result = array("total" => 1, "records" => array(), "sql" => ''); - $this->sys_ok($result); - exit; - } - - - function get_doctors_preparasi_sperma() - { - $prm = $this->sys_input; - // $id = $prm["id"]; - - $sql = " SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 10 AND - M_DoctorSOIsActive = 'Y' - ORDER BY M_DoctorName ASC"; - //echo $sql; - $query = $this->db_smartone->query($sql); - $rows = $query->result_array(); - $sql = " - SELECT '0' as id, 'Belum memilih metode' as name - UNION - SELECT M_MethodeSpermaID as id, M_MethodeSpermaName as name - FROM m_methodesperma - WHERE - M_MethodeSpermaIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $methodes = $this->db_smartone->query($sql)->result_array(); - - - $this->sys_ok(["records" => $rows, "methodes" => $methodes]); - } - - - function getpreparasispermaresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT other_preparasisperma.*, - Other_PreparasiSpermaID as xid, - Other_PreparasiSpermaT_OrderDetailID as orderdetail_id, - IFNULL(Other_PreparasiSpermaM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_PreparasiSpermaM_DoctorID) OR Other_PreparasiSpermaM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name, - IFNULL(M_MethodeSpermaID,0) as methode_id, - IFNULL(M_MethodeSpermaName,'') as methode_name - FROM other_preparasisperma - LEFT JOIN m_doctor ON Other_PreparasiSpermaM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - LEFT JOIN m_methodesperma ON Other_PreparasiSpermaM_MethodeSpermaID = M_MethodeSpermaID AND - M_MethodeSpermaIsActive = 'Y' - WHERE - Other_PreparasiSpermaT_OrderDetailID = {$id} AND Other_PreparasiSpermaIsActive = 'Y' - GROUP BY Other_PreparasiSpermaID"; - $query = $this->db_smartone->query($sql); - - if ($query) { - $rows = $query->row_array(); - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 10 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $sql = " - SELECT '0' as id, 'Belum memilih metode' as name - UNION - SELECT M_MethodeSpermaID as id, M_MethodeSpermaName as name - FROM m_methodesperma - WHERE - M_MethodeSpermaIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $methodes = $this->db_smartone->query($sql)->result_array(); - $images = array(); - $sql = "SELECT Other_PreparasiSpermaImgID as xid, - Other_PreparasiSpermaImgType as type, - CONCAT('/one-media/one-image-nonlab/',Other_PreparasiSpermaImgNewName) as image_url - FROM t_orderdetail - JOIN other_preparasisperma_img ON Other_PreparasiSpermaImgT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND - Other_PreparasiSpermaImgIsActive = 'Y' - WHERE - T_OrderDetailID = {$id} AND - T_OrderDetailIsActive = 'Y' - GROUP BY Other_PreparasiSpermaImgID"; - //echo $sql; - $images = $this->db_smartone->query($sql)->result_array(); - - $rst = array('doctors' => $doctors, 'methodes' => $methodes, 'results' => $rows, 'images' => $images); - $this->sys_ok(["records" => $rst]); - } else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - - function uploadimage_preparasi_sperma() - { - if (! $this->isLogin) { - $this->sys_error("Invalid Token"); - exit; - } - - $userid = $this->sys_user["M_UserID"]; - $data = []; - //print_r($_SERVER); - - $prm = $this->sys_input; - $orderid = $this->input->post('orderid'); - $type = $this->input->post('type'); - $labnumber = $this->input->post('labnumber'); - $sql = "UPDATE other_preparasisperma_img SET - Other_PreparasiSpermaImgIsActive = 'N', - Other_PreparasiSpermaImgUserID = {$userid} - WHERE - Other_PreparasiSpermaImgT_OrderHeaderID = {$orderid} AND - Other_PreparasiSpermaImgType = '{$type}'"; - //echo $sql; - $this->db_onedev->query($sql); - //$config['upload_path'] = 'assets/'; - - $path = '/home/one/project/one/one-media/one-image-nonlab/'; - //echo $path; - $config['upload_path'] = $path; - $config['allowed_types'] = 'jpg|jpeg|png|gif'; - - $config['max_size'] = '10000'; - $count = count($_FILES['files']['name']); - //echo $count; - $this->load->library('upload', $config); - - $error = []; - for ($i = 0; $i < $count; $i++) { - - - if (!empty($_FILES['files']['name'][$i])) { - - - - $_FILES['file']['name'] = $_FILES['files']['name'][$i]; - - $_FILES['file']['type'] = $_FILES['files']['type'][$i]; - - $_FILES['file']['tmp_name'] = $_FILES['files']['tmp_name'][$i]; - - $_FILES['file']['error'] = $_FILES['files']['error'][$i]; - - $_FILES['file']['size'] = $_FILES['files']['size'][$i]; - - - - $namex = $orderid . '-' . $labnumber . '-' . $this->generateRandomString(5); - //echo $namex; - - $config['file_name'] = $namex; - $this->upload->initialize($config); - //echo $config['file_name'] ; - - - - - - if ($this->upload->do_upload('file')) { - - $uploadData = $this->upload->data(); - - $filename = $uploadData['file_name']; - //echo $filename; - - - $sql = "INSERT INTO other_preparasisperma_img ( - Other_PreparasiSpermaImgT_OrderHeaderID, - Other_PreparasiSpermaImgType, - Other_PreparasiSpermaImgOldName, - Other_PreparasiSpermaImgNewName, - Other_PreparasiSpermaImgCreated, - Other_PreparasiSpermaImgUserID - ) - VALUES( - {$orderid}, - '{$type}', - '{$_FILES['files']['name'][$i]}', - '{$filename}', - NOW(), - {$userid} - - )"; - //echo $sql; - $this->db_onedev->query($sql); - $xlast_id = $this->db_onedev->insert_id(); - $data['totalFiles'][] = array('xid' => $xlast_id, 'type' => $type, 'image_url' => '/one-media/one-image-nonlab/' . $filename); - } else { - $error = array('error' => $this->upload->display_errors()); - } - } - } - - $result = array("total" => count($data['totalFiles']), "records" => $data['totalFiles'], 'errors' => $error); - $this->sys_ok($result); - } - - - function saveresult_preparasi_sperma() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = $inp['doctor']; - $orderdetail_id = $inp['orderdetailid']; - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - if ($prm['xid'] == '0') { - $sql = "INSERT INTO other_preparasisperma( - Other_PreparasiSpermaM_DoctorID, - Other_PreparasiSpermaT_OrderDetailID, - Other_PreparasiSpermaPreMotilitasA, - Other_PreparasiSpermaPreMotilitasB, - Other_PreparasiSpermaPreMotilitasC, - Other_PreparasiSpermaPreKonsentrasi, - Other_PreparasiSpermaPreKontaminan, - Other_PreparasiSpermaPostMotilitasA, - Other_PreparasiSpermaPostMotilitasB, - Other_PreparasiSpermaPostMotilitasC, - Other_PreparasiSpermaPostKonsentrasi, - Other_PreparasiSpermaPostKontaminan, - Other_PreparasiSpermaPreVolume, - Other_PreparasiSpermaPostVolume, - Other_PreparasiSpermaM_MethodeSpermaID, - Other_PreparasiSpermaNote, - Other_PreparasiSpermaUserID, - Other_PreparasiSpermaCreated - ) - VALUES( - {$doctor_id}, - {$orderdetail_id}, - '{$prm['Other_PreparasiSpermaPreMotilitasA']}', - '{$prm['Other_PreparasiSpermaPreMotilitasB']}', - '{$prm['Other_PreparasiSpermaPreMotilitasC']}', - '{$prm['Other_PreparasiSpermaPreKonsentrasi']}', - '{$prm['Other_PreparasiSpermaPreKontaminan']}', - '{$prm['Other_PreparasiSpermaPostMotilitasA']}', - '{$prm['Other_PreparasiSpermaPostMotilitasB']}', - '{$prm['Other_PreparasiSpermaPostMotilitasC']}', - '{$prm['Other_PreparasiSpermaPostKonsentrasi']}', - '{$prm['Other_PreparasiSpermaPostKontaminan']}', - '{$prm['Other_PreparasiSpermaPreVolume']}', - '{$prm['Other_PreparasiSpermaPostVolume']}', - '{$prm['Other_PreparasiSpermaM_MethodeSpermaID']}', - '{$prm['Other_PreparasiSpermaNote']}', - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } else { - $sql = "SELECT * FROM other_preparasisperma WHERE Other_PreparasiSpermaT_OrderDetailID = {$orderdetail_id} AND Other_PreparasiSpermaIsActive = 'Y'"; - $data_header = $this->db_smartone->query($sql)->row_array(); - $header_id = $data_header['Other_PreparasiSpermaID']; - $sql = "UPDATE other_preparasisperma SET - Other_PreparasiSpermaM_DoctorID = {$doctor_id}, - Other_PreparasiSpermaPreMotilitasA = '{$prm['Other_PreparasiSpermaPreMotilitasA']}', - Other_PreparasiSpermaPreMotilitasB = '{$prm['Other_PreparasiSpermaPreMotilitasB']}', - Other_PreparasiSpermaPreMotilitasC = '{$prm['Other_PreparasiSpermaPreMotilitasC']}', - Other_PreparasiSpermaPreKonsentrasi = '{$prm['Other_PreparasiSpermaPreKonsentrasi']}', - Other_PreparasiSpermaPreKontaminan = '{$prm['Other_PreparasiSpermaPreKontaminan']}', - Other_PreparasiSpermaPostMotilitasA = '{$prm['Other_PreparasiSpermaPostMotilitasA']}', - Other_PreparasiSpermaPostMotilitasB = '{$prm['Other_PreparasiSpermaPostMotilitasB']}', - Other_PreparasiSpermaPostMotilitasC = '{$prm['Other_PreparasiSpermaPostMotilitasC']}', - Other_PreparasiSpermaPostKonsentrasi = '{$prm['Other_PreparasiSpermaPostKonsentrasi']}', - Other_PreparasiSpermaPostKontaminan = '{$prm['Other_PreparasiSpermaPostKontaminan']}', - Other_PreparasiSpermaPreVolume = '{$prm['Other_PreparasiSpermaPreVolume']}', - Other_PreparasiSpermaPostVolume = '{$prm['Other_PreparasiSpermaPostVolume']}', - Other_PreparasiSpermaM_MethodeSpermaID = '{$prm['Other_PreparasiSpermaM_MethodeSpermaID']}', - Other_PreparasiSpermaNote = '{$prm['Other_PreparasiSpermaNote']}', - Other_PreparasiSpermaUserID = {$userid} - WHERE - Other_PreparasiSpermaID = {$header_id}"; - $this->db_smartone->query($sql); - } - - - $result = array("total" => 1, "records" => array(), "sql" => ''); - $this->sys_ok($result); - exit; - } - - function getdnafragmentasiresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT other_dnafragmentasi.*, - Other_DnaFragmentasiID as xid, - Other_DnaFragmentasiT_OrderDetailID as orderdetail_id, - IFNULL(Other_DnaFragmentasiM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_DnaFragmentasiM_DoctorID) OR Other_DnaFragmentasiM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name, - IFNULL(Other_DnaFragmentasiOther_DnaFragmentasiMethodeID,0) as methode_id, - IFNULL(Other_DnaFragmentasiMethodeName,'') as methode_name, - Other_DnaFragmentasiHaloLuas as halo_luas, - Other_DnaFragmentasiHaloSedang as halo_sedang, - Other_DnaFragmentasiHaloSempit as halo_sempit, - Other_DnaFragmentasiTanpaHalo as tanpa_halo, - Other_DnaFragmentasiDFI as dfi, - Other_DnaFragmentasiKesimpulan as kesimpulan, - Other_DnaFragmentasiCatatan as catatan - FROM other_dnafragmentasi - LEFT JOIN m_doctor ON Other_DnaFragmentasiM_DoctorID = M_DoctorID - LEFT JOIN other_dnafragmentasimethode ON Other_DnaFragmentasiOther_DnaFragmentasiMethodeID = Other_DnaFragmentasiMethodeID - WHERE - Other_DnaFragmentasiT_OrderDetailID = {$id} AND Other_DnaFragmentasiIsActive = 'Y' - GROUP BY Other_DnaFragmentasiID - LIMIT 1"; - //echo $sql; - $query = $this->db_smartone->query($sql); - - if ($query) { - $rows = $query->row_array(); - if (!$rows) { - $rows = array( - 'xid' => 0, - 'orderdetail_id' => $id, - 'doctor_id' => 0, - 'doctor_name' => '', - 'methode_id' => 0, - 'methode_name' => '', - 'halo_luas' => '', - 'halo_sedang' => '', - 'tanpa_halo' => '', - 'dfi' => '', - 'kesimpulan' => '', - 'catatan' => '' - ); - } - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID - WHERE - M_DoctorSONat_SubGroupID = 4 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - - $sql = " - SELECT '0' as id, 'Belum memilih metode' as name - UNION - SELECT Other_DnaFragmentasiMethodeID as id, Other_DnaFragmentasiMethodeName as name - FROM other_dnafragmentasimethode - WHERE - Other_DnaFragmentasiMethodeIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $methodes = $this->db_smartone->query($sql)->result_array(); - - - $rst = array('doctors' => $doctors, 'methodes' => $methodes, 'results' => $rows); - $this->sys_ok(["records" => $rst]); - } else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - function saveresult_dnafragmentasi() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = $inp['doctor']['id']; - $methode_id = $inp['methode']['id']; - $orderdetail_id = $inp['results']['orderdetail_id']; - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - if (intval($prm['xid']) == 0) { - $sql = "INSERT INTO other_dnafragmentasi( - Other_DnaFragmentasiT_OrderDetailID, - Other_DnaFragmentasiM_DoctorID, - Other_DnaFragmentasiOther_DnaFragmentasiMethodeID, - Other_DnaFragmentasiHaloLuas, - Other_DnaFragmentasiHaloSedang, - Other_DnaFragmentasiHaloSempit, - Other_DnaFragmentasiTanpaHalo, - Other_DnaFragmentasiDFI, - Other_DnaFragmentasiKesimpulan, - Other_DnaFragmentasiCatatan, - Other_DnaFragmentasiUserID, - Other_DnaFragmentasiLastUpdated - ) - VALUES( - {$orderdetail_id}, - {$doctor_id}, - {$methode_id}, - '{$prm['halo_luas']}', - '{$prm['halo_sedang']}', - '{$prm['halo_sempit']}', - '{$prm['tanpa_halo']}', - '{$prm['dfi']}', - '{$prm['kesimpulan']}', - '{$prm['catatan']}', - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } else { - $sql = "UPDATE other_dnafragmentasi SET - Other_DnaFragmentasiT_OrderDetailID = {$orderdetail_id}, - Other_DnaFragmentasiM_DoctorID = {$doctor_id}, - Other_DnaFragmentasiOther_DnaFragmentasiMethodeID = '{$methode_id}', - Other_DnaFragmentasiHaloLuas = '{$prm['halo_luas']}', - Other_DnaFragmentasiHaloSedang = '{$prm['halo_sedang']}', - Other_DnaFragmentasiHaloSempit = '{$prm['halo_sempit']}', - Other_DnaFragmentasiTanpaHalo = '{$prm['tanpa_halo']}', - Other_DnaFragmentasiDFI = '{$prm['dfi']}', - Other_DnaFragmentasiKesimpulan = '{$prm['kesimpulan']}', - Other_DnaFragmentasiCatatan = '{$prm['catatan']}', - Other_DnaFragmentasiLastUpdated = NOW(), - Other_DnaFragmentasiUserID = {$userid} - WHERE - Other_DnaFragmentasiID = {$prm['xid']}"; - //echo $sql; - $this->db_smartone->query($sql); - } - - - $result = array("total" => 1, "records" => array(), "sql" => ''); - $this->sys_ok($result); - exit; - } -} +db_smartone = $this->load->database("onedev", true); + $this->load->helper(array('form', 'url')); + } + function getMethodeID($natTestID) + { + $sql = "select M_MethodePriorityNat_MethodeID MethodeID, Nat_MethodeName + from + m_methode_priority + join nat_methode on Nat_MethodeID = M_MethodePriorityNat_MethodeID + and Nat_MethodeIsActive = 'Y' + join m_instrumentmethode on M_InstrumentMethodeNat_MethodeID = Nat_MethodeID and M_InstrumentMethodeIsActive = 'Y' + join nat_instrument on M_InstrumentMethodeNat_InstrumentID = Nat_InstrumentID + and Nat_InstrumentIsActive ='Y' + where M_MethodePriorityIsActive = 'Y' + and M_MethodePriorityNat_TestID = $natTestID + and M_MethodePriorityM_DayOfWeekID = dayofweek(now()) + order by M_MethodePriorityNumber desc + limit 0,1 "; + $qry = $this->db->query($sql); + if ($qry) { + $rows = $qry->result_array(); + if (count($rows) > 0) return array($rows[0]["MethodeID"], $rows[0]["Nat_MethodeName"]); + } + //2nd + $sql = "select + M_InstrumentMethodeNat_MethodeID MethodeID, Nat_MethodeName + from m_instrumentmethode + join nat_methode on M_InstrumentMethodeNat_MethodeID = Nat_MethodeID + and Nat_MethodeIsActive = 'Y' + join nat_instrument on M_InstrumentMethodeNat_InstrumentID = Nat_InstrumentID + and Nat_InstrumentIsActive ='Y' + where M_InstrumentMethodeNat_TestID = $natTestID + and M_InstrumentMethodeIsActive = 'Y' + order by M_InstrumentMethodePriority desc + limit 0,1"; + $qry = $this->db->query($sql); + if ($qry) { + $rows = $qry->result_array(); + if (count($rows) > 0) return array($rows[0]["MethodeID"], $rows[0]["Nat_MethodeName"]); + } + // + $sql = "select Nat_NormalValueNat_MethodeID MethodeID, Nat_MethodeName + from + nat_normalvalue + join nat_methode on Nat_NormalValueNat_MethodeID = Nat_MethodeID + and Nat_MethodeIsActive = 'Y' + where Nat_NormalValueNat_TestID = $natTestID + and Nat_NormalValueIsActive = 'Y' + order by Nat_NormalValueID + limit 0,1"; + $qry = $this->db->query($sql); + if ($qry) { + $rows = $qry->result_array(); + if (count($rows) > 0) return array($rows[0]["MethodeID"], $rows[0]["Nat_MethodeName"]); + } + return array(0, ""); + } + function get_normal_value($methodeID, $natTestID, $sexID, $ageInDay) + { + $this->load->library('ibl_sampling_normal'); + return $this->ibl_sampling_normal->get_normal_value_id($methodeID, $natTestID, $sexID, $ageInDay); + } + return 0; + } + function fn_fix_normal($order_id) + { + $sql = "select + T_OrderDetailID, M_PatientM_SexID, fn_global_age_count_day(M_PatientDOB, date(T_OrderHeaderDate)) Dob , + T_TestNat_TestID + from t_orderheader + join m_patient on T_OrderHeaderID = $order_id and T_OrderHeaderM_PatientID = M_PatientID + join t_orderdetail on T_OrderDetailT_OrderHeaderID = T_OrderHeaderID + and T_OrderDetailIsACtive = 'Y' + and ( T_OrderDetailNat_NormalValueID is null or T_OrderDetailNat_NormalValueID = 0 ) + join t_test on T_OrderDetailT_TestID = T_TestID and T_TestIsResult = 'Y' "; + $qry = $this->db->query($sql); + if (! $qry) { + return; + } + $rows = $qry->result_array(); + if (count($rows) == 0) return; + $sql_u = "update t_orderdetail + join nat_normalvalue on T_OrderDetailID = ? and Nat_NormalValueID = ? + set + T_OrderDetailNat_NormalValueID = Nat_NormalValueID, + T_OrderDetailNormalValueNote = Nat_NormalValueNote, + T_OrderDetailNormalValueDescription = Nat_NormalValueDescription, + T_OrderDetailMinValue = Nat_NormalValueMinValue, + T_OrderDetailMaxValue = Nat_NormalValueMaxValue, + T_OrderDetailMinValueInclusive = Nat_NormalValueMinValueInclusive, + T_OrderDetailMaxValueInclusive = Nat_NormalValueMaxValueInclusive, + T_OrderDetailNat_MethodeID = ?, + T_OrderdetailNat_MethodeName =?"; + + foreach ($rows as $r) { + $T_OrderDetailID = $r["T_OrderDetailID"]; + $sexID = $r["M_PatientM_SexID"]; + $ageInDay = $r["Dob"]; + $natTestID = $r["T_TestNat_TestID"]; + list($methodeID, $methodeName) = $this->getMethodeID($natTestID); + if ($methodeID == 0) continue; + $normalValueID = $this->get_normal_value($methodeID, $natTestID, $sexID, $ageInDay); + if ($normalValueID == 0) return; + $this->db->query($sql_u, array($T_OrderDetailID, $normalValueID, $methodeID, $methodeName)); + } + } + + function update_order_sample($targetID, $sourceID) + { + $sql = "update t_ordersample target + join t_ordersample source on + target.T_OrderSampleID = ? + and target.T_OrderSampleWorklistReceive = 'N' + and source.T_OrderSampleID = ? + set + target.T_OrderSampleSampling = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSampling, source.T_OrderSampleSampling), + target.T_OrderSampleSamplingDate = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingDate, source.T_OrderSampleSamplingDate), + target.T_OrderSampleSamplingTime = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingTime, source.T_OrderSampleSamplingTime), + target.T_OrderSampleSamplingUserID = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingUserID, source.T_OrderSampleSamplingUserID), + + target.T_OrderSampleReceive = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceive, source.T_OrderSampleReceive), + target.T_OrderSampleReceiveDate = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveDate, source.T_OrderSampleReceiveDate), + target.T_OrderSampleReceiveTime = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveTime, source.T_OrderSampleReceiveTime), + target.T_OrderSampleReceiveUserID = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveUserID, source.T_OrderSampleReceiveUserID), + + target.T_OrderSampleVerification = if(target.T_OrderSampleVerification='Y',target.T_OrderSampleVerification, source.T_OrderSampleVerification), + target.T_OrderSampleVerificationDate =if(target.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationDate, source.T_OrderSampleVerificationDate), + target.T_OrderSampleVerificationTime =if(source.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationTime, source.T_OrderSampleVerificationTime), + target.T_OrderSampleVerificationUserID =if(source.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationUserID, source.T_OrderSampleVerificationUserID), + + target.T_OrderSampleProcessing = if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessing, source.T_OrderSampleProcessing), + target.T_OrderSampleProcessingDate= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingDate, source.T_OrderSampleProcessingDate), + target.T_OrderSampleProcessingTime= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingTime, source.T_OrderSampleProcessingTime), + target.T_OrderSampleProcessingUserID= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingUserID, source.T_OrderSampleProcessingUserID), + + target.T_OrderSampleReceiveHandling =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandling, source.T_OrderSampleReceiveHandling ), + target.T_OrderSampleReceiveHandlingDate =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingDate, source.T_OrderSampleReceiveHandlingDate), + target.T_OrderSampleReceiveHandlingTime =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingTime, source.T_OrderSampleReceiveHandlingTime), + target.T_OrderSampleReceiveHandlingUserID =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingUserID, source.T_OrderSampleReceiveHandlingUserID), + + target.T_OrderSampleHandling = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandling, source.T_OrderSampleHandling), + target.T_OrderSampleHandlingDate = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingDate, source.T_OrderSampleHandlingDate), + target.T_OrderSampleHandlingTime = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingTime, source.T_OrderSampleHandlingTime), + target.T_OrderSampleHandlingUserID = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingUserID, source.T_OrderSampleHandlingUserID), + + target.T_OrderSampleWorklistReceive = source.T_OrderSampleWorklistReceive, + target.T_OrderSampleWorklistReceiveDatetime = source.T_OrderSampleWorklistReceiveDateTime, + target.T_OrderSampleWorklistReceiveUserID = source.T_OrderSampleWorklistReceiveUserID + "; + $qry = $this->db->query($sql, array($targetID, $sourceID)); + if (! $qry) { + echo json_encode(array("status" => "ERR", "message" => print_r($this->db->error(), true))); + exit; + } + } + function fix_sample_serum($headerID) + { + //cari t_ordersample yg belum worklist receive dengan code 017% + $sql = "select T_OrderSampleID + from t_ordersample + join t_sampletype on + T_OrderSampleT_OrderHeaderID = ? + and T_OrderSampleWorklistReceive = 'N' + and T_OrderSampleIsActive = 'Y' + and T_OrderSampleT_SampleTypeID = T_SampletypeID + and T_SampleTypeCode like '017%' + "; + $qry = $this->db->query($sql, array($headerID)); + if (!$qry) { + echo json_encode(array("status" => "ERR", "message" => print_r($this->db->error(), true))); + exit; + } + $rows = $qry->result_array(); + if (count($rows) == 0) return; + //cari T_OrderSample yang sudah di receive yg terakhir + $sql = "select T_OrderSampleID + from t_ordersample + join t_sampletype on + T_OrderSampleT_OrderHeaderID = ? + and T_OrderSampleWorklistReceive = 'Y' + and T_OrderSampleIsActive = 'Y' + and T_OrderSampleT_SampleTypeID = T_SampletypeID + and T_SampleTypeCode like '017%' + order by T_OrderSampleWorklistReceiveDatetime desc + limit 0,1 + "; + $qry = $this->db->query($sql, array($headerID)); + if (!$qry) { + echo json_encode(array("status" => "ERR", "message" => print_r($this->db->error(), true))); + exit; + } + $rcv_rows = $qry->result_array(); + if (count($rcv_rows) == 0) return; + + //print_r($rows); + //print_r($rcv_rows); + $rcv_T_OrderSampleID = $rcv_rows[0]["T_OrderSampleID"]; + //ada yg belum di receive + foreach ($rows as $r) { + $T_OrderSampleID = $r["T_OrderSampleID"]; + $this->update_order_sample($T_OrderSampleID, $rcv_T_OrderSampleID); + } + } + public function search() + { + $prm = $this->sys_input; + $max_rst = 99; + + $id = $prm["order_id"]; + if ($id > 0) { + $this->fix_sample_serum($id); + $this->fn_fix_normal($id); + } + $lang = $this->lang_default_code; + $lang_id = isset($prm['lang_id']) ? $prm['lang_id'] : '0'; + + if ($lang_id != 0) { + $l = $this->db_smartone->where("Nat_LangID", $lang_id)->get("nat_lang")->row(); + $lang = $l->Nat_LangCode; + } + + //tambahan fajri + $sql = " UPDATE t_orderdetail + JOIN t_test ON T_OrderDetailT_TestID = T_TestID + SET T_OrderDetailT_TestIsResult = T_TestIsResult + WHERE + T_OrderDetailT_OrderHeaderID = {$id} AND + T_OrderDetailT_TestIsResult = '' AND + T_OrderDetailIsActive = 'Y'"; + $this->db_smartone->query($sql); + + $tot_count = 0; + $lq = ""; + $group_id = 0; + if (isset($prm['group_id'])) + $group_id = $prm['group_id']; + + if ($group_id != 0) { + $sql = "select distinct T_WorklistDetailNat_TestID Nat_TestID + from t_worklistdetailv2 + where T_WorklistDetailT_WorklistID = {$group_id}"; + $qry = $this->db_smartone->query($sql); + $rows = $qry->result_array(); + $nat_test_ids = "0"; + foreach ($rows as $r) { + $nat_test_ids .= ", " . $r["Nat_TestID"]; + } + $q_group = " ( $nat_test_ids ) "; + + $sql = " + SELECT a1.*, cOUNT(a2.T_OrderDetailID) level + FROM ( + SELECT IFNULL(y.T_OrderDetailT_TestID, x.T_OrderDetailT_TestID) t_testid, + IFNULL(y.T_OrderDetailT_TestName, y.T_OrderDetailT_TestName) t_testname, + y.T_OrderDetailResult result, y.T_OrderDetailResult result_old, y.T_OrderDetailNote note, y.T_OrderDetailNote note_old, + y.T_OrderDetailID id, + y.T_OrderDetailT_TestIsResult is_result, a.T_TestIsQuantitative is_quantitative, + y.T_OrderDetailResultFlag result_flag, + y.T_OrderDetailNat_NormalValueID normal_id, + y.T_OrderDetailNormalValueNote normal_note, y.T_OrderDetailNat_UnitName unit_name, + y.T_OrderdetailNat_MethodeID methode_id, y.T_OrderdetailNat_MethodeName methode_name, + a.T_TestNat_TestID nattest_id, a.T_TestID tx_id, count(T_ResultInstrumentID) as result_instrument_n, + y.T_OrderDetailVerification, T_OrderSampleReceive sample_receive, + T_OrderSampleProcessing sample_processing, T_OrderSampleWorklistReceive sample_worklist_receive, + IF(T_OrderDetailAddOnPreAnalytic = 'Y', T_OrderDetailAddOnPreAnalytic, PreAnalyticIsOk) pre_analytic, + T_OrderDetailAddOnPreAnalytic, + T_OrderHeaderID order_id, y.T_OrderDetailT_TestSasCode test_sas_code, + tx.T_TestSasCode, + T_OrderDetailAddOnResample `resample`, T_OrderDetailAddOnResampleStatus resample_status, + T_OrderDetailAddOnRef ref, y.T_OrderDetailVerification verification, y.T_OrderDetailValidation validation, + T_OrderPromiseDateTime, Group_ResultName as ResultGroupName + FROM t_orderdetail x + left join t_orderpromise on x.T_OrderDetailT_OrderPromiseID = T_OrderPromiseID + JOIN t_test tx ON x.T_OrderDetailT_TestID = T_TestID + JOIN t_test tcheck on tcheck.T_TestNat_TestID in {$q_group} + and ( tx.T_TestID = tcheck.T_TestID or tx.T_TestSasCode like concat(tcheck.T_TestSasCode,'%')) + LEFT JOIN group_resultdetail ON Group_ResultDetailT_TestID = x.T_OrderDetailT_TestID AND Group_ResultDetailIsActive = 'Y' + LEFT JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND Group_ResultFlagNonLab = 'N' + LEFT JOIN t_orderdetail y ON x.T_OrderDetailT_TestSasCode LIKE CONCAT(y.T_OrderDetailT_TestSasCode, '%') + AND x.T_OrderDetailT_OrderHeaderID = y.T_OrderDetailT_OrderHeaderID + AND y.T_OrderDetailIsActive = 'Y' + LEFT JOIN t_orderdetailaddon ON x.T_OrderDetailID = T_OrderDetailAddOnT_OrderDetailID + JOIN t_orderheader ON y.T_OrderDetailT_OrderHeaderID = T_OrderHeaderID + LEFT JOIN t_test a ON y.T_OrderDetailT_TestID = a.T_TestID + AND a.T_TestIsNonLab = '' + LEFT JOIN (SELECT T_OrderSampleT_SampleTypeID, T_OrderSampleReceive, T_OrderSampleProcessing, T_OrderSampleWorklistReceive + FROM t_ordersample WHERE T_OrderSampleT_OrderHeaderID = {$id} + AND T_OrderSampleIsactive = 'Y' + GROUP BY T_OrderSampleT_SampleTypeID) os ON a.T_TestT_SampleTypeID = os.T_OrderSampleT_SampleTypeID + or os.T_OrderSampleT_SampleTypeID = fn_sampletype_from_local(a.T_TestNat_TestID) + + LEFT JOIN t_resultinstrument ON T_ResultInstrumentT_OrderDetailID = x.T_OrderDetailID + LEFT JOIN pre_analytic ON PreAnalyticNat_TestID = a.T_TestNat_TestID AND PreAnalyticDate = date(now()) and PreAnalyticIsActive = 'Y' + WHERE x.T_OrderDetailT_OrderHeaderID = {$id} + AND x.T_OrderDetailIsActive = 'Y' + GROUP BY y.T_OrderDetailT_TestID + ORDER BY y.T_OrderDetailT_TestSasCode ASC + ) a1 + + LEFT JOIN t_orderdetail a2 ON a2.T_OrderDetailT_OrderHeaderID = a1.order_id + AND a2.T_OrderDetailIsActive = 'Y' + AND a1.test_sas_code LIKE CONCAT(a2.T_OrderDetailT_testSasCode, '%') + GROUP BY a1.t_testid + order by a1.test_sas_code +"; + $query = $this->db_smartone->query($sql); + $lq = $this->db_smartone->last_query(); + } else { + $sql = " + SELECT a1.*, cOUNT(a2.T_OrderDetailID) level + FROM ( + SELECT IFNULL(y.T_OrderDetailT_TestID, x.T_OrderDetailT_TestID) t_testid, + IFNULL(y.T_OrderDetailT_TestName, y.T_OrderDetailT_TestName) t_testname, + y.T_OrderDetailResult result, y.T_OrderDetailResult result_old, y.T_OrderDetailNote note, y.T_OrderDetailNote note_old, + y.T_OrderDetailID id, + y.T_OrderDetailT_TestIsResult is_result, a.T_TestIsQuantitative is_quantitative, + y.T_OrderDetailResultFlag result_flag, + y.T_OrderDetailNat_NormalValueID normal_id, + y.T_OrderDetailNormalValueNote normal_note, y.T_OrderDetailNat_UnitName unit_name, + y.T_OrderdetailNat_MethodeID methode_id, y.T_OrderdetailNat_MethodeName methode_name, + a.T_TestNat_TestID nattest_id, a.T_TestID tx_id, count(T_ResultInstrumentID) as result_instrument_n, + y.T_OrderDetailVerification, T_OrderSampleReceive sample_receive, + T_OrderSampleProcessing sample_processing, T_OrderSampleWorklistReceive sample_worklist_receive, + IF(T_OrderDetailAddOnPreAnalytic = 'Y', T_OrderDetailAddOnPreAnalytic, PreAnalyticIsOk) pre_analytic, + T_OrderDetailAddOnPreAnalytic, + T_OrderHeaderID order_id, y.T_OrderDetailT_TestSasCode test_sas_code, + tx.T_TestSasCode, + T_OrderDetailAddOnResample `resample`, T_OrderDetailAddOnResampleStatus resample_status, + T_OrderDetailAddOnRef ref, y.T_OrderDetailVerification verification, y.T_OrderDetailValidation validation, + T_OrderPromiseDateTime , Group_ResultName as ResultGroupName + FROM t_orderdetail x + left join t_orderpromise on x.T_OrderDetailT_OrderPromiseID = T_OrderPromiseID + JOIN t_test tx ON x.T_OrderDetailT_TestID = T_TestID + LEFT JOIN group_resultdetail ON Group_ResultDetailT_TestID = x.T_OrderDetailT_TestID AND Group_ResultDetailIsActive = 'Y' + LEFT JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND Group_ResultFlagNonLab = 'N' + LEFT JOIN t_orderdetail y ON x.T_OrderDetailT_TestSasCode LIKE CONCAT(y.T_OrderDetailT_TestSasCode, '%') + AND x.T_OrderDetailT_OrderHeaderID = y.T_OrderDetailT_OrderHeaderID + AND y.T_OrderDetailIsActive = 'Y' + + LEFT JOIN t_orderdetailaddon ON x.T_OrderDetailID = T_OrderDetailAddOnT_OrderDetailID + + JOIN t_orderheader ON y.T_OrderDetailT_OrderHeaderID = T_OrderHeaderID + LEFT JOIN t_test a ON y.T_OrderDetailT_TestID = a.T_TestID + AND a.T_TestIsNonLab = '' + LEFT JOIN (SELECT T_OrderSampleT_SampleTypeID, T_OrderSampleReceive, T_OrderSampleProcessing, T_OrderSampleWorklistReceive + FROM t_ordersample WHERE T_OrderSampleT_OrderHeaderID = {$id} + AND T_OrderSampleIsactive = 'Y' + GROUP BY T_OrderSampleT_SampleTypeID) os ON a.T_TestT_SampleTypeID = os.T_OrderSampleT_SampleTypeID + or os.T_OrderSampleT_SampleTypeID = fn_sampletype_from_local(a.T_TestNat_TestID) + + LEFT JOIN t_resultinstrument ON T_ResultInstrumentT_OrderDetailID = x.T_OrderDetailID + LEFT JOIN pre_analytic ON PreAnalyticNat_TestID = a.T_TestNat_TestID AND PreAnalyticDate = date(now()) and PreAnalyticIsActive = 'Y' + WHERE x.T_OrderDetailT_OrderHeaderID = {$id} + AND x.T_OrderDetailIsActive = 'Y' + GROUP BY y.T_OrderDetailT_TestID + ORDER BY y.T_OrderDetailT_TestSasCode ASC + ) a1 + + LEFT JOIN t_orderdetail a2 ON a2.T_OrderDetailT_OrderHeaderID = a1.order_id + AND a2.T_OrderDetailIsActive = 'Y' + AND a1.test_sas_code LIKE CONCAT(a2.T_OrderDetailT_testSasCode, '%') + GROUP BY a1.t_testid + order by a1.test_sas_code +"; + //echo $sql; + $query = $this->db_smartone->query($sql); + $lq = $this->db_smartone->last_query(); + } + // file_put_contents("/xtmp/re-query.sql",$lq); + + if ($query) { + $rst = []; + $rows = $query->result_array(); + + foreach ($rows as $k => $v) { + + if ($v['is_result'] == "Y" && $v['is_quantitative'] == "N") { + $v['template'] = []; + $x = $this->db_smartone->query("CALL sp_master_resulttemplate_get('{$v['t_testid']}')"); + $this->clean_mysqli_connection($this->db_smartone->conn_id); + if ($x) + $v['template'] = $x->result_array(); + } + + // IF Rujukan, by pas Pre Analytik + if ($v['ref'] == 'Y') + $v['pre_analytic'] = 'Y'; + if ($v["id"] == "885455") { + //sipe workaround + //$v["sample_receive"] = "Y"; + $v["sample_worklist_receive"] = "Y"; + } + $rst[] = $v; + } + + $result = array("total" => $tot_count, "records" => $rst, "total_display" => sizeof($rows), "q" => $lq); + $this->sys_ok($result); + } else { + $this->sys_error_db("RE Px rows", $this->db_smartone); + exit; + } + } + + public function save() + { + $prm = $this->sys_input; + $data = json_decode($prm["data"]); + $lang = $this->lang_default_code; + $lang_id = isset($prm['lang_id']) ? $prm['lang_id'] : '0'; + + if ($lang_id != 0) { + $l = $this->db_smartone->where("Nat_LangID", $lang_id)->get("nat_lang")->row(); + $lang = $l->Nat_LangCode; + } + + $sql_norm = "select T_OrderDetailMinValue, T_OrderDetailMaxValue, + T_OrderDetailMinValueInclusive, T_OrderDetailMaxValueInclusive, + Nat_TestFlagLow, Nat_TestFlagHigh + from t_orderdetail + join t_test on T_OrderDetailT_TestID = T_TestID + join nat_test on T_TestNat_TestID = Nat_TestID and T_TestIsActive = 'Y' + where T_OrderDetailID = ? "; + + $ids = []; + foreach ($data as $k => $v) { + if ($v->resultInstrumentID > 0) { + $sql_i = "select T_ResultInstrumentNat_NormalValueID normalValueID + from t_resultinstrument + where T_ResultInstrumentID = ?"; + $qry_i = $this->db_smartone->query($sql_i, array($v->resultInstrumentID)); + if ($qry_i) { + $rows_i = $qry_i->result_array(); + + if (count($rows_i) > 0) { + $sql_iu = "update t_orderdetail, nat_normalvalue , nat_methode + set T_OrderDetailMinValue = Nat_NormalValueMinValue, + T_OrderDetailMinValueInclusive = Nat_NormalValueMinValueInclusive, + T_OrderDetailMaxValue = Nat_NormalValueMaxValue , + T_OrderDetailMaxValueInclusive = Nat_NormalValueMaxValueInclusive, + T_OrderDetailNormalValueNote = Nat_NormalValueNote, + T_OrderDetailNormalValueDescription = Nat_NormalValueDescription, + T_OrderDetailNat_NormalValueID = Nat_NormalValueID, + T_OrderDetailNat_MethodeID = Nat_NormalValueNat_MethodeID, + T_OrderDetailNat_MethodeName = Nat_MethodeName + where T_OrderDetailID = ? and Nat_NormalValueID = ? + and Nat_NormalValueNat_MethodeID = Nat_MethodeID + "; + $this->db_smartone->query($sql_iu, array($v->id, $rows_i[0]["normalValueID"])); + //file_put_contents("/xtmp/update-nilai-normal", $this->db_smartone->last_query() . "\n", FILE_APPEND); + } + } + } + $y = $this->db_smartone->query("SELECT fn_process_sample_handling_perfect('{$v->order_id}', '{$v->test_id}') c") + ->row(); + $req_status = $y->c; + $qry_norm = $this->db_smartone->query($sql_norm, $v->id); + $result_flag = ""; + if ($qry_norm) { + $rows_norm = $qry_norm->result_array(); + if (count($rows_norm) > 0) { + $r = $rows_norm[0]; + if (is_numeric($v->result)) { + + if ($r["T_OrderDetailMinValueInclusive"] == "Y" && $v->result < $r["T_OrderDetailMinValue"]) { + $result_flag = $r["Nat_TestFlagLow"]; + } + if ($r["T_OrderDetailMinValueInclusive"] == "N" && $v->result <= $r["T_OrderDetailMinValue"]) { + $result_flag = $r["Nat_TestFlagLow"]; + } + if ($r["T_OrderDetailMaxValueInclusive"] == "Y" && $v->result > $r["T_OrderDetailMaxValue"]) { + $result_flag = $r["Nat_TestFlagHigh"]; + } + if ($r["T_OrderDetailMaxValueInclusive"] == "N" && $v->result >= $r["T_OrderDetailMaxValue"]) { + $result_flag = $r["Nat_TestFlagHigh"]; + } + } + } + } + if ($lang == $this->lang_default_code) { + $this->db_smartone->set('T_OrderDetailResult', $v->result) + ->set('T_OrderDetailResultFlag', $result_flag) + ->set('T_OrderDetailNote', $v->note) + ->set('T_OrderDetailReqStatus', $req_status) + ->where('T_OrderDetailID', $v->id) + ->update('t_orderdetail'); + } else { + $this->db_smartone->set('T_OrderDetailLangResult', $v->result) + ->set('T_OrderDetailLangNote', $v->note) + ->where('T_OrderDetailLangID', $v->id) + ->update('t_orderdetaillang'); + } + + $ids[] = $v->id; + } + + // LOG Process + $order = $this->db_smartone->select('T_OrderDetailT_OrderHeaderID id, T_OrderHeaderLabNumber lab_number', false) + ->join('t_orderheader', 'T_OrderHeaderID = T_OrderDetailT_OrderHeaderID') + ->where('T_OrderDetailID', $data[0]->id) + ->get('t_orderdetail') + ->row(); + + $dblog = $this->load->database("onelog", true); + $dblog->set('Log_ProcessCode', 'PROCESS.Result.Entry') + ->set('Log_ProcessOrderID', $order->id) + ->set('Log_ProcessOrderNumber', $order->lab_number) + ->set('Log_ProcessJson', json_encode($data)) + ->set('Log_ProcessUserID', $this->sys_user['M_UserID']) + ->insert('log_process'); + // END OF Log Process + //auto calculation + $this->load->library("Resultcalc"); + $rows = $this->resultcalc->auto($order->id); + + try { + foreach ($ids as $id) { + $this->db_smartone->query("call sp_set_normal_value_flag($id)"); + $this->clean_mysqli_connection($this->db_smartone->conn_id); + } + } catch (Exception $e) { + } + + $this->sys_ok($ids); + } + + public function save_template() + { + $prm = $this->sys_input; + + $n = $this->db_smartone->select("COUNT(T_ResultTemplateID) n") + ->where("T_ResultTemplateT_TestID", $prm['test_id']) + ->where("T_ResultTemplateIsActive", "Y") + ->where("T_ResultTemplateValue", $prm['value']) + ->get('t_resulttemplate') + ->row(); + if ($n->n > 0) { + $this->sys_error_db("Insert Result Template", $this->db_smartone); + return; + } + + $r = $this->db_smartone->set("T_ResultTemplateT_TestID", $prm['test_id']) + ->set("T_ResultTemplateValue", $prm['value']) + ->insert('t_resulttemplate'); + if ($r) { + $template = []; + $x = $this->db_smartone->query("CALL sp_master_resulttemplate_get('{$prm['test_id']}')"); + $this->clean_mysqli_connection($this->db_smartone->conn_id); + if ($x) + $template = $x->result_array(); + + $this->sys_ok($template); + } + } + + public function export() + { + $prm = $this->sys_input; + + $sql = "CALL sp_process_result_lang(?, ?, ?, ?)"; + $query = $this->db_smartone->query($sql, [$prm['order_id'], $prm['lang_id'], $prm['is_si'], $this->sys_user['M_UserID']]); + if ($query) { + $r = $query->row(); + if ($r->status == "OK") { + $this->sys_ok($r->data); + return; + } + + $this->sys_error_db("Message : " . $r->message, $this->db_smartone); + } else { + $this->sys_error_db("Lang Result", $this->db_smartone); + return; + } + } + + public function search_group() + { + $prm = $this->sys_input; + $max_rst = 100; + + // QUERY TOTAL + $sql = "select count(*) total + from t_worklist + where T_WorklistIsActive = 'Y' + order by T_WorklistName ASC"; + $query = $this->db_smartone->query($sql); + + if ($query) { + $tot_count = $query->result_array()[0]["total"]; + } else { + $this->sys_error_db("worklist count", $this->db_smartone); + exit; + } + + $sql = "select T_WorklistID group_id, T_WorklistName group_name + from t_worklist + where T_WorklistIsActive = 'Y' + order by T_WorklistName ASC + limit 0, {$max_rst}"; + $query = $this->db_smartone->query($sql); + + if ($query) { + $rows = $query->result_array(); + foreach ($rows as $k => $v) + $rows[$k]['data'] = json_decode($v['data']); + $result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows), "q" => $this->db_smartone->last_query()); + $this->sys_ok($result); + } else { + $this->sys_error_db("worklist rows", $this->db_smartone); + exit; + } + } + + public function search_rerun() + { + $prm = $this->sys_input; + $id = $prm["detail_id"]; + + $sql = "CALL sp_process_result_rerun(?)"; + $query = $this->db_smartone->query($sql, [$id]); + + if ($query) { + $rows = $query->result_array(); + $this->sys_ok(["records" => $rows]); + } else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + + + function getdoctorsfna() + { + $prm = $this->sys_input; + // $id = $prm["id"]; + + $sql = " SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY M_DoctorName ASC"; + //echo $sql; + $query = $this->db_smartone->query($sql); + + if ($query) { + $rows = $query->result_array(); + $this->sys_ok(["records" => $rows]); + } else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + function getfnaresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT Other_FNADetailsID as xid, + Other_FNAT_OrderDetailID as orderdetail_id, + Other_FNADetailsCode as code, + Other_FNADetailsLabel as label, + Other_FNADetailsResult as result, + IFNULL(Other_FNAM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_FNAM_DoctorID) OR Other_FNAM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_fna + JOIN other_fnadetails ON Other_FNADetailsOther_FNAID = Other_FNAID AND Other_FNADetailsIsActive = 'Y' + LEFT JOIN m_doctor ON Other_FNAM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_FNAT_OrderDetailID = {$id} AND Other_FNAIsActive = 'Y' + GROUP BY Other_FNADetailsID + ORDER BY Other_FNADetailsCode ASC"; + $query = $this->db_smartone->query($sql); + + if ($query) { + $rows = $query->result_array(); + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $images = array(); + $sql = "SELECT So_ImageUploadID as xid, + CONCAT('/one-media/one-image-nonlab/',So_ImageUploadNewName) as image_url + FROM t_orderdetail + JOIN so_imageupload ON So_ImageUploadT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND + So_ImageUploadIsActive = 'Y' + WHERE + T_OrderDetailID = {$id} AND + T_OrderDetailIsActive = 'Y' + GROUP BY So_ImageUploadID"; + $images = $this->db_smartone->query($sql)->result_array(); + + $rst = array('doctors' => $doctors, 'results' => $rows, 'images' => $images); + $this->sys_ok(["records" => $rst]); + } else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + function getpatologianatomyresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT Other_PatologiAnatomyID as xid, + Other_PatologiAnatomyT_OrderDetailID as orderdetail_id, + Other_PatologiAnatomyNoSediaan as no_sediaan, + Other_PatologiAnatomyDiagnosaKlinis as diagnosa, + Other_PatologiAnatomyKeteranganKlinis as klinis, + Other_PatologiAnatomyLokasiOrgan as lokasi, + Other_PatologiAnatomyMakroskopik as makroskopik, + Other_PatologiAnatomyMikroskopik as mikroskopik, + Other_PatologiAnatomyKesimpulan as kesimpulan, + IFNULL(Other_PatologiAnatomyM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_PatologiAnatomyM_DoctorID) OR Other_PatologiAnatomyM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_patologi_anatomy + LEFT JOIN m_doctor ON Other_PatologiAnatomyM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_PatologiAnatomyT_OrderDetailID = {$id} AND Other_PatologiAnatomyIsActive = 'Y' + GROUP BY Other_PatologiAnatomyID + ORDER BY Other_PatologiAnatomyID ASC + LIMIT 1"; + $query = $this->db_smartone->query($sql); + + if ($query) { + $rows = $query->row_array(); + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + + $sql = "SELECT So_ImageUploadPatologyAnatomyID as xid, + CONCAT('/one-media/one-image-nonlab/',So_ImageUploadPatologyAnatomyNewName) as image_url, + So_ImageUploadPatologyAnatomyType as type + FROM t_orderdetail + JOIN so_imageupload_patology_anatomy ON So_ImageUploadPatologyAnatomyT_OrderHeaderID= T_OrderDetailT_OrderHeaderID AND + So_ImageUploadPatologyAnatomyIsActive= 'Y' + WHERE + T_OrderDetailID = {$id} AND + T_OrderDetailIsActive = 'Y' + GROUP BY So_ImageUploadPatologyAnatomyID"; + $images = $this->db_smartone->query($sql)->result_array(); + $mikro = []; + $makro = []; + + foreach ($images as $key => $value) { + + if ($value['type'] == 'mikro') { + $mikro[] = $value; + } + if ($value['type'] == 'makro') { + $makro[] = $value; + } + } + + $rst = array('doctors' => $doctors, 'result' => $rows, "mikro" => $mikro, "makro" => $makro); + $this->sys_ok(["records" => $rst]); + } else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + + function uploadimage() + { + if (! $this->isLogin) { + $this->sys_error("Invalid Token"); + exit; + } + + $userid = $this->sys_user["M_UserID"]; + $data = []; + //print_r($_SERVER); + + $prm = $this->sys_input; + $orderid = $this->input->post('orderid'); + $labnumber = $this->input->post('labnumber'); + $sql = "UPDATE so_imageupload SET + So_ImageUploadIsActive = 'N', + So_ImageUploadUserID = {$userid} + WHERE + So_ImageUploadT_OrderHeaderID = {$orderid}"; + //echo $sql; + $this->db_onedev->query($sql); + //$config['upload_path'] = 'assets/'; + + $path = '/home/one/project/one/one-media/one-image-nonlab/'; + //echo $path; + $config['upload_path'] = $path; + $config['allowed_types'] = 'jpg|jpeg|png|gif'; + + $config['max_size'] = '10000'; + $count = count($_FILES['files']['name']); + //echo $count; + $this->load->library('upload', $config); + + $error = []; + for ($i = 0; $i < $count; $i++) { + + + if (!empty($_FILES['files']['name'][$i])) { + + + + $_FILES['file']['name'] = $_FILES['files']['name'][$i]; + + $_FILES['file']['type'] = $_FILES['files']['type'][$i]; + + $_FILES['file']['tmp_name'] = $_FILES['files']['tmp_name'][$i]; + + $_FILES['file']['error'] = $_FILES['files']['error'][$i]; + + $_FILES['file']['size'] = $_FILES['files']['size'][$i]; + + + + $namex = $orderid . '-' . $labnumber . '-' . $this->generateRandomString(5); + //echo $namex; + + $config['file_name'] = $namex; + $this->upload->initialize($config); + //echo $config['file_name'] ; + + + + + + if ($this->upload->do_upload('file')) { + + $uploadData = $this->upload->data(); + + $filename = $uploadData['file_name']; + //echo $filename; + + + $sql = "INSERT INTO so_imageupload ( + So_ImageUploadT_OrderHeaderID, + So_ImageUploadT_OrderHeaderLabNumber, + So_ImageUploadT_SampleTypeID, + So_ImageUploadOldName, + So_ImageUploadNewName, + So_ImageUploadCreated, + So_ImageUploadUserID + ) + VALUES( + {$orderid}, + '{$labnumber}', + '150', + '{$_FILES['files']['name'][$i]}', + '{$filename}', + NOW(), + {$userid} + + )"; + //echo $sql; + $this->db_onedev->query($sql); + $xlast_id = $this->db_onedev->insert_id(); + $data['totalFiles'][] = array('xid' => $xlast_id, 'image_url' => '/one-media/one-image-nonlab/' . $filename); + } else { + $error = array('error' => $this->upload->display_errors()); + } + } + } + + $result = array("total" => count($data['totalFiles']), "records" => $data['totalFiles'], 'errors' => $error); + $this->sys_ok($result); + } + + + function generateRandomString($length = 10) + { + $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; + $charactersLength = strlen($characters); + $randomString = ''; + for ($i = 0; $i < $length; $i++) { + $randomString .= $characters[rand(0, $charactersLength - 1)]; + } + return $randomString; + } + + function getcytologiresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT Other_CytologiDetailsID as xid, + Other_CytologiT_OrderDetailID as orderdetail_id, + Other_CytologiDetailsCode as code, + Other_CytologiDetailsLabel as label, + Other_CytologiDetailsResult as result, + IFNULL(Other_CytologiM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_CytologiM_DoctorID) OR Other_CytologiM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_cytologi + JOIN other_cytologidetails ON Other_CytologiDetailsOther_CytologiID = Other_CytologiID AND Other_CytologiDetailsIsActive = 'Y' + LEFT JOIN m_doctor ON Other_CytologiM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_CytologiT_OrderDetailID = {$id} AND Other_CytologiIsActive = 'Y' + GROUP BY Other_CytologiDetailsID + ORDER BY Other_CytologiDetailsCode ASC"; + //echo $sql; + $query = $this->db_smartone->query($sql); + + if ($query) { + $rows = $query->result_array(); + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $rst = array('doctors' => $doctors, 'results' => $rows); + $this->sys_ok(["records" => $rst]); + } else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + function getmikroresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT + Other_MikroID as xid, + Other_MikroHasilBiakan as hasil_biakan, + Other_MikroSampleTypeName as sample_name, + Other_MikroT_OrderDetailID as orderdetail_id, + Other_MikroResult as result_value, + '' as result_other, + IFNULL(T_BacteriaID,0) as T_BacteriaID, + IFNULL(T_BacteriaName,'') as T_BacteriaName, + '' as details, + IFNULL(Other_MikroM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_MikroM_DoctorID) OR Other_MikroM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_mikro + LEFT JOIN t_bacteria ON Other_MikroT_BacteriaID = T_BacteriaID + LEFT JOIN m_doctor ON Other_MikroM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_MikroT_OrderDetailID = {$id} AND Other_MikroIsActive = 'Y' + GROUP BY Other_MikroID"; + //echo $sql; + $query = $this->db_smartone->query($sql); + + if ($query) { + $row = $query->row_array(); + if ($row) { + if ($row['result_value'] != 'Positif' && $row['result_value'] != 'Negatif') { + $row['result_other'] = $row['result_value']; + $row['result_value'] = 'other'; + } + $sql = "SELECT '' as xno, + Other_MikroDetailsID as xid, + Other_MikroDetailsValue as value, + IF(Other_MikroDetailsNote = 'R','Y','N') as chx_r, + IF(Other_MikroDetailsNote = 'I','Y','N') as chx_i, + IF(Other_MikroDetailsNote = 'S','Y','N') as chx_s, + Other_MikroDetailsNote as note, + t_antibiotic.* + FROM other_mikrodetails + LEFT JOIN t_antibiotic ON Other_MikroDetailsT_AntibioticID = T_AntibioticID + WHERE + Other_MikroDetailsOther_MikroID = {$row['xid']} AND Other_MikroDetailsIsActive = 'Y' + GROUP BY Other_MikroDetailsID + ORDER BY T_AntibioticName ASC"; + //echo $sql; + $details = $this->db_smartone->query($sql)->result_array(); + if (details) { + foreach ($details as $k => $v) { + $details[$k]['xno'] = $k + 1; + } + } + $row['details'] = $details; + } else { + $row = array('xid' => '0', 'hasil_biakan' => '', 'result_value' => 'Negatif', 'sample_name' => '', 'orderdetail_id' => $id, 'T_BacteriaID' => '0', 'T_BacteriaName' => '0', 'details' => array(), 'doctor_id' => '0', 'doctor_name' => '0'); + } + } else { + $row = array('xid' => '0', 'hasil_biakan' => '', 'result_value' => 'Negatif', 'sample_name' => '', 'orderdetail_id' => $id, 'T_BacteriaID' => '0', 'T_BacteriaName' => '0', 'details' => array(), 'doctor_id' => '0', 'doctor_name' => '0'); + } + //print_r($row); + + + + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 7 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $sql = " + SELECT '0' as id, 'Belum memilih bakteria' as name + UNION + SELECT T_BacteriaID as id, T_BacteriaName as name + FROM t_bacteria + WHERE + T_BacteriaIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $bacteries = $this->db_smartone->query($sql)->result_array(); + $rst = array('doctors' => $doctors, 'bacteries' => $bacteries, 'results' => $row); + $this->sys_ok(["records" => $rst]); + } + function getantibiotics() + { + $prm = $this->sys_input; + $id = $prm["id"]; + $sql = " SELECT '' as xno, + 0 as xid, + '' as hasil_biakan, + '' as sample_name, + 0 as value, + 'Y' as chx_r, + 'N' as chx_i, + 'N' as chx_s, + 'R' as note, + t_antibiotic.* + FROM t_antibiotic + WHERE + T_AntibioticT_BacteriaID = {$prm['id']} AND T_AntibioticIsActive= 'Y' + ORDER BY T_AntibioticName ASC"; + //echo $sql; + $rows = $this->db_smartone->query($sql)->result_array(); + if (rows) { + foreach ($rows as $k => $v) { + $rows[$k]['xno'] = $k + 1; + } + } + + $this->sys_ok(["records" => $rows]); + } + function getlcprepresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + $sql = " SELECT Other_LcprepDetailsID as xid, + Other_LcprepID as header_id, + Other_LcprepT_orderDetailID as orderdetail_id, + Other_LcprepDetailsCode as code, + Other_LcprepDetailsLabel as label, + Other_LcprepDetailsResult as result, + IFNULL(Other_LcprepM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_LcprepM_DoctorID) OR Other_LcprepM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_lcprep + JOIN other_lcprepdetails ON Other_LcprepDetailsOther_LcprepID = Other_LcprepID AND Other_LcprepDetailsIsActive = 'Y' + LEFT JOIN m_doctor ON Other_LcprepM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_LcprepT_orderDetailID = {$id} AND Other_LcprepIsActive = 'Y' + GROUP BY Other_LcprepDetailsOther_LcprepID, Other_LcprepDetailsCode + ORDER BY Other_LcprepDetailsCode ASC"; + //echo $sql; + $rows = $this->db_smartone->query($sql)->result_array(); + if (!$rows) { + $rows = array( + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'A', + 'label' => 'DESKRIPSI', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ), + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'B', + 'label' => 'KESIMPULAN', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ) + ); + } + + $header_id = $rows[0]['header_id']; + $sql = "SELECT IFNULL(Other_LcprepAdekuasiID,0) as xid, + Lcprep_AdekuasiID as id, + Lcprep_AdekuasiLabel as name, + IF(ISNULL(Other_LcprepAdekuasiID),'N',Other_LcprepAdekuasiChex) as chex + FROM lcprep_adekuasi + LEFT JOIN other_lcprepadekuasi ON Other_LcprepAdekuasiLcprep_AdekuasiID = Lcprep_AdekuasiID AND + Other_LcprepAdekuasiOther_LcprepID = {$header_id} AND + Other_LcprepAdekuasiIsActive = 'Y' + WHERE + Lcprep_AdekuasiIsActive = 'Y' + GROUP BY Lcprep_AdekuasiID + ORDER BY Lcprep_AdekuasiOrder ASC + "; + //echo $sql; + $adeakuasi = $this->db_smartone->query($sql)->result_array(); + foreach ($adeakuasi as $kc => $vc) { + $adeakuasi[$kc]['chex'] = $vc['chex'] == 'N' ? false : true; + } + + $sql = "SELECT IFNULL(Other_LcprepKategoriUmumID,0) as xid, + Lcprep_KategoriUmumID as id, + Lcprep_KategoriUmumLabel as name, + IF(ISNULL(Other_LcprepKategoriUmumID),'N',Other_LcprepKategoriUmumChex) as chex + FROM lcprep_kategoriumum + LEFT JOIN other_lcprepkategoriumum ON Other_LcprepKategoriUmumLcprep_KategoriUmumID = Lcprep_KategoriUmumID AND + Other_LcprepKategoriUmumOther_LcprepID = {$header_id} AND + Other_LcprepKategoriUmumIsActive = 'Y' + WHERE + Lcprep_KategoriUmumIsActive = 'Y' + GROUP BY Lcprep_KategoriUmumID + "; + //echo $sql; + $kategoriumum = $this->db_smartone->query($sql)->result_array(); + foreach ($kategoriumum as $kc => $vc) { + $kategoriumum[$kc]['chex'] = $vc['chex'] == 'N' ? false : true; + } + + $sql = " + SELECT Lcprep_InterpretasiGroupID as group_id, + Lcprep_InterpretasiGroupName as group_name, + '' as subgroups + FROM lcprep_interpretasigroup + WHERE + Lcprep_InterpretasiGroupIsActive = 'Y' + "; + //echo $sql; + $interpretasi = $this->db_smartone->query($sql)->result_array(); + foreach ($interpretasi as $k => $v) { + $subgroups = array(); + $sql = "SELECT Lcprep_InterpretasiSubgroupID as subgroup_id, + Lcprep_InterpretasiSubgroupName as subgroup_name, + '' as childs + FROM lcprep_interpretasisubgroup + WHERE + Lcprep_InterpretasiSubgroupLcprep_InterpretasiGroupID = {$v['group_id']} AND Lcprep_InterpretasiSubgroupIsActive = 'Y'"; + //echo $sql; + $subgroups = $this->db_smartone->query($sql)->result_array(); + if (count($subgroups) > 0) { + foreach ($subgroups as $ki => $vi) { + $childs = array(); + $sql = "SELECT IFNULL(Other_LcprepInterpretasiID,0) as xid, + IFNULL(Other_LcprepInterpretasiChex,'N') as chex, + IFNULL(Other_LcprepInterpretasiValue,'') as value, + Lcprep_InterpretasiID as id, + Lcprep_InterpretasiLcprep_InterpretasiSubgroupID as subgroup_id, + Lcprep_InterpretasiCode as code, + Lcprep_InterpretasiName as name, + Lcprep_InterpretasiParentID as parent_id, + Lcprep_InterpretasiIsParent as is_parent, + Lcprep_InterpretasiHasResult as has_result, + Lcprep_InterpretasiTypeResult as type_result + FROM lcprep_interpretasi + LEFT JOIN other_lcprepinterpretasi ON Other_LcprepInterpretasiOther_LcprepID = {$header_id} AND + Other_LcprepInterpretasiLcprep_InterpretasiID = Lcprep_InterpretasiID AND + Other_LcprepInterpretasiIsActive = 'Y' + WHERE + Lcprep_InterpretasiLcprep_InterpretasiSubgroupID = {$vi['subgroup_id']} AND Lcprep_InterpretasiIsActive = 'Y' + GROUP BY Lcprep_InterpretasiID Order BY Lcprep_InterpretasiCode ASC"; + $childs = $this->db_smartone->query($sql)->result_array(); + if ($childs) { + foreach ($childs as $kc => $vc) { + $childs[$kc]['chex'] = $vc['chex'] == 'N' ? false : true; + } + } + $subgroups[$ki]['childs'] = $childs; + } + } + + $interpretasi[$k]['subgroups'] = $subgroups; + } + + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $rst = array('doctors' => $doctors, 'results' => $rows, 'adekuasi' => $adeakuasi, 'kategoriumum' => $kategoriumum, 'interpretasi' => $interpretasi); + $this->sys_ok(["records" => $rst]); + } + + function getpapsmearresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT Other_PapSmearDetailsID as xid, + Other_PapSmearID as header_id, + Other_PapSmearT_OrderDetailID as orderdetail_id, + Other_PapSmearDetailsCode as code, + Other_PapSmearDetailsLabel as label, + Other_PapSmearDetailsResult as result, + IFNULL(Other_PapSmearM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_PapSmearM_DoctorID) OR Other_PapSmearM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_papsmear + JOIN other_papsmeardetails ON Other_PapSmearDetailsOther_PapSmearID = Other_PapSmearID AND Other_PapSmearDetailsIsActive = 'Y' + LEFT JOIN m_doctor ON Other_PapSmearM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_PapSmearT_OrderDetailID = {$id} AND Other_PapSmearIsActive = 'Y' + GROUP BY Other_PapSmearDetailsID + ORDER BY Other_PapSmearDetailsCode ASC"; + //echo $sql; + $rows = $this->db_smartone->query($sql)->result_array(); + if (!$rows) { + $rows = array( + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'A', + 'label' => 'Makroskopik', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ), + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'B', + 'label' => 'Mikroskopik', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ), + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'C', + 'label' => 'Kesimpulan', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ) + ); + } + + $header_id = $rows[0]['header_id']; + $sql = "SELECT Other_PapSmearMaturasiID as xid, + Other_PapSmearMaturasiValue as value + FROM other_papsmearmaturasi + WHERE + Other_PapSmearMaturasiOther_PapSmearID = {$header_id} AND + Other_PapSmearMaturasiIsActive = 'Y' + "; + //echo $sql; + $dt_maturasi = $this->db_smartone->query($sql)->row_array(); + if (!$dt_maturasi) { + $maturasi = array('xid' => '0', 'value' => array('', '', '')); + } else { + $value = explode('/', $dt_maturasi['value']); + $maturasi = array('xid' => $dt_maturasi['xid'], 'value' => $value); + } + + $sql = "SELECT IFNULL(Other_PapSmearBahanID,0) as xid, + M_PapSmearBahanID as bahan_id, + M_PapSmearBahanName as name, + IF(ISNULL(Other_PapSmearBahanID),'N','Y') as selected + FROM m_papsmearbahan + LEFT JOIN other_papsmearbahan ON Other_PapSmearBahanM_PapSmearBahanID = M_PapSmearBahanID AND + Other_PapSmearBahanOther_PapSmearID = {$header_id} AND + Other_PapSmearBahanIsActive = 'Y' + WHERE + M_PapSmearBahanIsActive = 'Y' + ORDER BY M_PapSmearBahanID ASC + "; + //echo $sql; + $bahans = $this->db_smartone->query($sql)->result_array(); + + $sql = "SELECT IFNULL(Other_PapsmearCategoryID,0) as xid, + M_PapSmearCategoryID as category_id, + M_PapSmearCategoryName as name, + IF(ISNULL(Other_PapsmearCategoryID),'N','Y') as selected + FROM m_papsmearcategory + LEFT JOIN other_papsmearcategory ON Other_PapsmearCategoryM_PapSmearCategoryID = M_PapSmearCategoryID AND + Other_PapsmearCategoryOther_PapSmearID = {$header_id} AND + Other_PapsmearCategoryIsActive = 'Y' + WHERE + M_PapSmearCategoryIsActive = 'Y' + ORDER BY M_PapSmearCategoryID ASC + "; + //echo $sql; + $categories = $this->db_smartone->query($sql)->result_array(); + + $sql = "SELECT IFNULL(Other_PapSmearCheckID,0) as xid, + M_PapSmearCheckID as check_id, + M_PapSmearCheckLabel as name, + IF(ISNULL(Other_PapSmearCheckID),'N','Y') as selected, + Other_PapSmearCheckNote as note + FROM m_papsmearcheck + LEFT JOIN other_papsmearcheck ON Other_PapSmearCheckM_PapSmearCheckID = M_PapSmearCheckID AND + Other_PapSmearCheckOther_PapSmearID = {$header_id} AND + Other_PapSmearCheckIsActive = 'Y' + WHERE + M_PapSmearCheckIsActive = 'Y' + ORDER BY M_PapSmearCheckCode ASC + "; + $checks = $this->db_smartone->query($sql)->result_array(); + + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $rst = array('doctors' => $doctors, 'checks' => $checks, 'bahans' => $bahans, 'categories' => $categories, 'maturasi' => $maturasi, 'results' => $rows); + $this->sys_ok(["records" => $rst]); + } + + function saveresult_lcprep() + { + $prm = $this->sys_input; + $detail_id = $prm['detail_id']; + $doctor_id = $prm['doctor']; + $adekuasi = $prm['adekuasi']; + $kategoriumum = $prm['kategoriumum']; + $interpretasi = $prm['interpretasi']; + $results = $prm['results']; + + $userid = $this->sys_user['M_UserID']; + + $header_id = 0; + $sql = "SELECT * FROM other_lcprep WHERE Other_LcprepT_orderDetailID = {$detail_id} AND Other_LcprepIsActive = 'Y'"; + $dt_header = $this->db_smartone->query($sql)->row_array(); + if ($dt_header) { + $header_id = $dt_header['Other_LcprepID']; + } + if ($header_id == 0) { + $sql = "INSERT INTO other_lcprep( + Other_LcprepT_orderDetailID, + Other_LcprepM_DoctorID, + Other_LcprepUserID, + Other_LcprepCreated + ) + VALUES( + {$detail_id}, + {$doctor_id}, + {$userid}, + NOW() + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } else { + $sql = "UPDATE other_lcprep SET Other_LcprepM_DoctorID = {$doctor_id}, Other_LcprepUserID = {$userid} WHERE Other_LcprepID = {$header_id}"; + $this->db_smartone->query($sql); + } + + if ($adekuasi) { + foreach ($adekuasi as $k => $v) { + $selected = $v['chex'] ? 'Y' : 'N'; + if (intval($v['xid'] == 0)) { + $sql = "UPDATE other_lcprepadekuasi SET Other_LcprepAdekuasiIsActive = 'N' + WHERE + Other_LcprepAdekuasiOther_LcprepID = {$header_id} AND + Other_LcprepAdekuasiIsActive = 'Y' AND + Other_LcprepAdekuasiLcprep_AdekuasiID = {$v['id']}"; + $this->db_smartone->query($sql); + $sql = "INSERT INTO other_lcprepadekuasi ( + Other_LcprepAdekuasiOther_LcprepID, + Other_LcprepAdekuasiLcprep_AdekuasiID, + Other_LcprepAdekuasiChex, + Other_LcprepAdekuasiUserID, + Other_LcprepAdekuasiCreated + ) + VALUES( + {$header_id}, + {$v['id']}, + '{$selected}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + //echo $sql; + } + if (intval($v['xid'] != 0)) { + + $sql = "UPDATE other_lcprepadekuasi SET + Other_LcprepAdekuasiChex = '{$selected}', + Other_LcprepAdekuasiUserID = {$userid} + WHERE + Other_LcprepAdekuasiID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + + //echo $sql; + } + } + + if ($kategoriumum) { + foreach ($kategoriumum as $k => $v) { + $selected = $v['chex'] ? 'Y' : 'N'; + if (intval($v['xid'] == 0)) { + $sql = "UPDATE other_lcprepkategoriumum SET Other_LcprepKategoriUmumIsActive = 'N' + WHERE + Other_LcprepKategoriUmumOther_LcprepID = {$header_id} AND + Other_LcprepKategoriUmumLcprep_KategoriUmumID = {$v['id']} AND + Other_LcprepKategoriUmumIsActive = 'Y' + "; + $this->db_smartone->query($sql); + $sql = "INSERT INTO other_lcprepkategoriumum ( + Other_LcprepKategoriUmumOther_LcprepID, + Other_LcprepKategoriUmumLcprep_KategoriUmumID, + Other_LcprepKategoriUmumChex, + Other_LcprepKategoriUmumUserID, + Other_LcprepKategoriUmumCreated + ) + VALUES( + {$header_id}, + {$v['id']}, + '{$selected}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if (intval($v['xid'] != 0)) { + $sql = "UPDATE other_lcprepkategoriumum SET + Other_LcprepKategoriUmumChex = '{$selected}', + Other_LcprepKategoriUmumUserID = {$userid} + WHERE + Other_LcprepKategoriUmumID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + + //echo $sql; + } + } + + if ($results) { + foreach ($results as $k => $v) { + if (intval($v['xid'] == 0)) { + $sql = "UPDATE other_lcprepdetails SET Other_LcprepDetailsIsActive = 'N' + WHERE + Other_LcprepDetailsOther_LcprepID = {$header_id} AND + Other_LcprepDetailsCode = '{$v['code']}' AND + Other_LcprepDetailsIsActive = 'Y'"; + $this->db_smartone->query($sql); + $sql = "INSERT INTO other_lcprepdetails ( + Other_LcprepDetailsOther_LcprepID, + Other_LcprepDetailsCode, + Other_LcprepDetailsLabel, + Other_LcprepDetailsResult, + Other_LcprepDetailsUserID, + Other_LcprepDetailsCreated + ) + VALUES( + {$header_id}, + '{$v['code']}', + '{$v['label']}', + '{$v['result']}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if (intval($v['xid'] != 0)) { + $sql = "UPDATE other_lcprepdetails SET + Other_LcprepDetailsCode = '{$v['code']}', + Other_LcprepDetailsLabel = '{$v['label']}', + Other_LcprepDetailsResult = '{$v['result']}', + Other_LcprepDetailsUserID = {$userid} + WHERE + Other_LcprepDetailsID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + //echo $sql; + } + } + + if ($interpretasi) { + foreach ($interpretasi as $k => $v) { + if (count($v['subgroups']) > 0) { + foreach ($v['subgroups'] as $ik => $iv) { + if (count($iv['childs']) > 0) { + foreach ($iv['childs'] as $iik => $iiv) { + if (intval($iiv['xid'] == 0)) { + $chex = $iiv['chex'] ? 'Y' : 'N'; + $sql = "UPDATE other_lcprepinterpretasi SET Other_LcprepInterpretasiIsActive = 'N' + WHERE + Other_LcprepInterpretasiOther_LcprepID = {$header_id} AND + Other_LcprepInterpretasiLcprep_InterpretasiID = '{$iiv['id']}' AND + Other_LcprepInterpretasiIsActive = 'Y'"; + $this->db_smartone->query($sql); + $sql = "INSERT INTO other_lcprepinterpretasi ( + Other_LcprepInterpretasiOther_LcprepID, + Other_LcprepInterpretasiLcprep_InterpretasiID, + Other_LcprepInterpretasiChex, + Other_LcprepInterpretasiValue, + Other_LcprepInterpretasiUserID, + Other_LcprepInterpretasiCreated + ) + VALUES( + {$header_id}, + '{$iiv['id']}', + '{$chex}', + '{$iiv['value']}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + + if (intval($iiv['xid'] != 0)) { + $chex = $iiv['chex'] ? 'Y' : 'N'; + $sql = "UPDATE other_lcprepinterpretasi SET + Other_LcprepInterpretasiChex = '{$chex}', + Other_LcprepInterpretasiValue = '{$iiv['value']}', + Other_LcprepInterpretasiUserID = {$userid} + WHERE + Other_LcprepInterpretasiID = {$iiv['xid']}"; + $this->db_smartone->query($sql); + //echo $sql; + + } + } + } + } + } + //echo $sql; + } + } + + + $result = array("total" => 1, "records" => array(), "sql" => ''); + $this->sys_ok($result); + exit; + } + + function saveresult_papsmear() + { + $prm = $this->sys_input; + $detail_id = $prm['detail_id']; + $doctor_id = $prm['doctor']; + $checks = $prm['checks']; + $maturasi = $prm['maturasi']; + $bahans = $prm['bahans']; + $categories = $prm['categories']; + $results = $prm['results']; + + $userid = $this->sys_user['M_UserID']; + + $header_id = 0; + $sql = "SELECT * FROM other_papsmear WHERE Other_PapSmearT_OrderDetailID = {$detail_id} AND Other_PapSmearIsActive = 'Y'"; + $dt_header = $this->db_smartone->query($sql)->row_array(); + if ($dt_header) { + $header_id = $dt_header['Other_PapSmearID']; + } + if ($header_id == 0) { + $sql = "INSERT INTO other_papsmear( + Other_PapSmearT_OrderDetailID, + Other_PapSmearM_DoctorID, + Other_PapSmearUserID, + Other_PapSmearCreated + ) + VALUES( + {$detail_id}, + {$doctor_id}, + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } else { + $sql = "UPDATE other_papsmear SET Other_PapSmearM_DoctorID = {$doctor_id}, Other_PapSmearUserID = {$userid} WHERE Other_PapSmearID = {$header_id}"; + $this->db_smartone->query($sql); + } + + if ($checks) { + foreach ($checks as $k => $v) { + if (intval($v['xid']) == 0 && $v['selected'] === 'Y') { + $sql = "INSERT INTO other_papsmearcheck ( + Other_PapSmearCheckOther_PapSmearID, + Other_PapSmearCheckM_PapSmearCheckID, + Other_PapSmearCheckNote, + Other_PapSmearCheckUserID, + Other_PapSmearCheckCreated + ) + VALUES( + {$header_id}, + {$v['check_id']}, + '{$v['note']}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if (intval($v['xid']) != 0 && $v['selected'] === 'N') { + $sql = "UPDATE other_papsmearcheck SET + Other_PapSmearCheckIsActive = 'N', + Other_PapSmearCheckUserID = {$userid} + WHERE + Other_PapSmearCheckID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + if (intval($v['xid']) != 0 && $v['selected'] === 'Y') { + $sql = "UPDATE other_papsmearcheck SET + Other_PapSmearCheckNote = '{$v['note']}', + Other_PapSmearCheckUserID = {$userid} + WHERE + Other_PapSmearCheckID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + //echo $sql; + } + } + + if ($maturasi) { + if (intval($maturasi['xid']) == 0) { + $value = join("/", $maturasi['value']); + $sql = "INSERT INTO other_papsmearmaturasi ( + Other_PapSmearMaturasiOther_PapSmearID, + Other_PapSmearMaturasiValue, + Other_PapSmearMaturasiUserID, + Other_PapSmearMaturasiCreated + ) + VALUE( + {$header_id}, + '{$value}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + //echo $sql; + } + if (intval($maturasi['xid']) != 0) { + $value = join("/", $maturasi['value']); + $sql = "UPDATE other_papsmearmaturasi SET + Other_PapSmearMaturasiValue = '{$value}', + Other_PapSmearMaturasiUserID = {$userid} + WHERE + Other_PapSmearMaturasiID = {$maturasi['xid']}"; + // echo $sql; + $this->db_smartone->query($sql); + } + } + + if ($bahans) { + foreach ($bahans as $k => $v) { + if (intval($v['xid']) == 0 && $v['selected'] === 'Y') { + $sql = "INSERT INTO other_papsmearbahan ( + Other_PapSmearBahanOther_PapSmearID, + Other_PapSmearBahanM_PapSmearBahanID, + Other_PapSmearBahanUserID, + Other_PapSmearBahanCreated + ) + VALUES( + {$header_id}, + {$v['bahan_id']}, + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if (intval($v['xid']) != 0 && $v['selected'] === 'N') { + $sql = "UPDATE other_papsmearbahan SET + Other_PapSmearBahanIsActive = 'N', + Other_PapsmearCategoryUserID = {$userid} + WHERE + Other_PapSmearBahanID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + if (intval($v['xid']) != 0 && $v['selected'] === 'Y') { + $sql = "UPDATE other_papsmearbahan SET + Other_PapSmearBahanIsActive = 'Y', + Other_PapsmearCategoryUserID = {$userid} + WHERE + Other_PapSmearBahanID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + //echo $sql; + } + } + + if ($categories) { + foreach ($categories as $k => $v) { + if (intval($v['xid']) == 0 && $v['selected'] === 'Y') { + $sql = "INSERT INTO other_papsmearcategory ( + Other_PapsmearCategoryOther_PapSmearID, + Other_PapsmearCategoryM_PapSmearCategoryID, + Other_PapsmearCategoryUserID, + Other_PapsmearCategoryCreated + ) + VALUES( + {$header_id}, + {$v['category_id']}, + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if (intval($v['xid']) != 0 && $v['selected'] === 'N') { + $sql = "UPDATE other_papsmearcategory SET + Other_PapsmearCategoryIsActive = 'N', + Other_PapsmearCategoryUserID = {$userid} + WHERE + Other_PapsmearCategoryID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + //echo $sql; + if (intval($v['xid']) != 0 && $v['selected'] === 'Y') { + $sql = "UPDATE other_papsmearcategory SET + Other_PapsmearCategoryIsActive = 'Y', + Other_PapsmearCategoryUserID = {$userid} + WHERE + Other_PapsmearCategoryID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + } + } + + if ($results) { + foreach ($results as $k => $v) { + if (intval($v['xid']) == 0) { + $sql = "INSERT INTO other_papsmeardetails ( + Other_PapSmearDetailsOther_PapSmearID, + Other_PapSmearDetailsCode, + Other_PapSmearDetailsLabel, + Other_PapSmearDetailsResult, + Other_PapSmearDetailsUserID, + Other_PapSmearDetailsCreated + ) + VALUES( + {$header_id}, + '{$v['code']}', + '{$v['label']}', + '{$v['result']}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if (intval($v['xid']) != 0) { + $sql = "UPDATE other_papsmeardetails SET + Other_PapSmearDetailsCode = '{$v['code']}', + Other_PapSmearDetailsLabel = '{$v['label']}', + Other_PapSmearDetailsResult = '{$v['result']}', + Other_PapSmearDetailsUserID = {$userid} + WHERE + Other_PapSmearDetailsID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + //echo $sql; + } + } + + $result = array("total" => 1, "records" => array(), "sql" => ''); + $this->sys_ok($result); + exit; + } + + function saveresult_fna() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = $inp['doctor']; + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + if ($prm[0]['xid'] == '0') { + $sql = "INSERT INTO other_fna( + Other_FNAM_DoctorID, + Other_FNAT_OrderDetailID, + Other_FNAUserID, + Other_FNACreated + ) + VALUES( + {$doctor_id}, + {$prm[0]['orderdetail_id']}, + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } else { + $sql = "SELECT * FROM other_fna WHERE Other_FNAT_OrderDetailID = {$prm[0]['orderdetail_id']} AND Other_FNAIsActive = 'Y'"; + $data_header = $this->db_smartone->query($sql)->row_array(); + $header_id = $data_header['Other_FNAID']; + $sql = "UPDATE other_fna SET + Other_FNAM_DoctorID = {$doctor_id}, + Other_FNAUserID = {$userid} + WHERE + Other_FNAID = {$header_id}"; + $this->db_smartone->query($sql); + } + foreach ($prm as $k => $v) { + if ($v['xid'] == '0') { + $results = str_replace("'", "\\'", $v['result']); + $sql = "INSERT INTO other_fnadetails( + Other_FNADetailsOther_FNAID , + Other_FNADetailsCode, + Other_FNADetailsLabel, + Other_FNADetailsResult, + Other_FNADetailsCreated, + Other_FNADetailsUserID + ) + VALUES( + {$header_id}, + '{$v['code']}', + '{$v['label']}', + '{$results}', + NOW(), + {$userid} + )"; + $query = $this->db_smartone->query($sql); + } else { + $results = str_replace("'", "\\'", $v['result']); + $sql = "UPDATE other_fnadetails SET + Other_FNADetailsResult = '{$results}', + Other_FNADetailsUserID = {$userid} + WHERE + Other_FNADetailsID = {$v['xid']}"; + $query = $this->db_smartone->query($sql); + } + } + + $result = array("total" => 1, "records" => array(), "sql" => ''); + $this->sys_ok($result); + exit; + } + + function saveresult_cytologi() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = $inp['doctor']; + + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + if ($prm[0]['xid'] == '0') { + $sql = "INSERT INTO other_cytologi( + Other_CytologiT_OrderDetailID, + Other_CytologiM_DoctorID, + Other_CytologiUserID, + Other_CytologiCreated + ) + VALUES( + {$prm[0]['orderdetail_id']}, + {$doctor_id}, + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } else { + $sql = "SELECT * FROM other_cytologi WHERE Other_CytologiT_OrderDetailID = {$prm[0]['orderdetail_id']} AND Other_CytologiIsActive = 'Y'"; + $data_header = $this->db_smartone->query($sql)->row_array(); + $header_id = $data_header['Other_CytologiID']; + $sql = "UPDATE other_cytologi SET + Other_CytologiM_DoctorID = {$doctor_id}, + Other_CytologiUserID = {$userid} + WHERE + Other_CytologiID = {$header_id}"; + $this->db_smartone->query($sql); + } + foreach ($prm as $k => $v) { + if ($v['xid'] == '0') { + $results = str_replace("'", "\\'", $v['result']); + $sql = "INSERT INTO other_cytologidetails( + Other_CytologiDetailsOther_CytologiID , + Other_CytologiDetailsCode, + Other_CytologiDetailsLabel, + Other_CytologiDetailsResult, + Other_CytologiDetailsCreated, + Other_CytologiDetailsUserID + ) + VALUES( + {$header_id}, + '{$v['code']}', + '{$v['label']}', + '{$results}', + NOW(), + {$userid} + )"; + $query = $this->db_smartone->query($sql); + } else { + $results = str_replace("'", "\\'", $v['result']); + $sql = "UPDATE other_cytologidetails SET + Other_CytologiDetailsResult = '{$results}', + Other_CytologiDetailsUserID = {$userid} + WHERE + Other_CytologiDetailsID = {$v['xid']}"; + $query = $this->db_smartone->query($sql); + } + } + + $result = array("total" => 1, "records" => array(), "sql" => ''); + $this->sys_ok($result); + exit; + } + + function saveresult_mikro() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = $inp['doctor']; + $backteria_id = $inp['bacteria']; + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + + if ($inp['result_value'] != 'Negatif' && $inp['result_value'] != 'Positif') { + $prm['result_value'] = $prm['result_other']; + } else { + $prm['result_value'] = $inp['result_value']; + } + + if ($prm['xid'] == '0') { + $sql = "INSERT INTO other_mikro( + Other_MikroM_DoctorID, + Other_MikroResult, + Other_MikroT_BacteriaID, + Other_MikroT_OrderDetailID, + Other_MikroHasilBiakan, + Other_MikroSampleTypeName, + Other_MikroUserID, + Other_MikroCreated + ) + VALUES( + {$doctor_id}, + '{$prm['result_value']}', + {$backteria_id}, + {$prm['orderdetail_id']}, + '{$prm['hasil_biakan']}', + '{$prm['sample_name']}', + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } else { + $sql = "SELECT * FROM other_mikro WHERE Other_MikroT_OrderDetailID = {$prm['orderdetail_id']} AND Other_MikroIsActive = 'Y'"; + $data_header = $this->db_smartone->query($sql)->row_array(); + $header_id = $data_header['Other_MikroID']; + $sql = "UPDATE other_mikro SET + Other_MikroResult = '{$prm['result_value']}', + Other_MikroM_DoctorID = {$doctor_id}, + Other_MikroT_BacteriaID = {$backteria_id}, + Other_MikroHasilBiakan = '{$prm['hasil_biakan']}', + Other_MikroSampleTypeName = '{$prm['sample_name']}', + Other_MikroUserID = {$userid} + WHERE + Other_MikroID = {$header_id}"; + //echo $sql; + $this->db_smartone->query($sql); + } + + + + $sql = "UPDATE other_mikrodetails SET Other_MikroDetailsIsActive = 'N', Other_MikroDetailsUserID = 0 WHERE Other_MikroDetailsOther_MikroID = {$header_id}"; + $this->db_smartone->query($sql); + + $results = $prm['details']; + if ($inp['result_value'] == 'Positif') { + foreach ($results as $k => $v) { + if ($v['xid'] == '0') { + $sql = "INSERT INTO other_mikrodetails( + Other_MikroDetailsOther_MikroID , + Other_MikroDetailsT_AntibioticID, + Other_MikroDetailsValue, + Other_MikroDetailsNote, + Other_MikroDetailsCreated, + Other_MikroDetailsUserID + ) + VALUES( + {$header_id}, + '{$v['T_AntibioticID']}', + '{$v['value']}', + '{$v['note']}', + NOW(), + {$userid} + )"; + $query = $this->db_smartone->query($sql); + } else { + $sql = "UPDATE other_mikrodetails SET + Other_MikroDetailsT_AntibioticID = '{$v['T_AntibioticID']}', + Other_MikroDetailsValue = '{$v['value']}', + Other_MikroDetailsNote = '{$v['note']}', + Other_MikroDetailsIsActive = 'Y', + Other_MikroDetailsUserID = {$userid} + WHERE + Other_MikroDetailsID = {$v['xid']}"; + //echo $sql; + $query = $this->db_smartone->query($sql); + } + } + } + + + $result = array("total" => 1, "records" => array(), "sql" => ''); + $this->sys_ok($result); + exit; + } + + + function get_doctors_preparasi_sperma() + { + $prm = $this->sys_input; + // $id = $prm["id"]; + + $sql = " SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 10 AND + M_DoctorSOIsActive = 'Y' + ORDER BY M_DoctorName ASC"; + //echo $sql; + $query = $this->db_smartone->query($sql); + $rows = $query->result_array(); + $sql = " + SELECT '0' as id, 'Belum memilih metode' as name + UNION + SELECT M_MethodeSpermaID as id, M_MethodeSpermaName as name + FROM m_methodesperma + WHERE + M_MethodeSpermaIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $methodes = $this->db_smartone->query($sql)->result_array(); + + + $this->sys_ok(["records" => $rows, "methodes" => $methodes]); + } + + + function getpreparasispermaresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT other_preparasisperma.*, + Other_PreparasiSpermaID as xid, + Other_PreparasiSpermaT_OrderDetailID as orderdetail_id, + IFNULL(Other_PreparasiSpermaM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_PreparasiSpermaM_DoctorID) OR Other_PreparasiSpermaM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name, + IFNULL(M_MethodeSpermaID,0) as methode_id, + IFNULL(M_MethodeSpermaName,'') as methode_name + FROM other_preparasisperma + LEFT JOIN m_doctor ON Other_PreparasiSpermaM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + LEFT JOIN m_methodesperma ON Other_PreparasiSpermaM_MethodeSpermaID = M_MethodeSpermaID AND + M_MethodeSpermaIsActive = 'Y' + WHERE + Other_PreparasiSpermaT_OrderDetailID = {$id} AND Other_PreparasiSpermaIsActive = 'Y' + GROUP BY Other_PreparasiSpermaID"; + $query = $this->db_smartone->query($sql); + + if ($query) { + $rows = $query->row_array(); + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 10 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $sql = " + SELECT '0' as id, 'Belum memilih metode' as name + UNION + SELECT M_MethodeSpermaID as id, M_MethodeSpermaName as name + FROM m_methodesperma + WHERE + M_MethodeSpermaIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $methodes = $this->db_smartone->query($sql)->result_array(); + $images = array(); + $sql = "SELECT Other_PreparasiSpermaImgID as xid, + Other_PreparasiSpermaImgType as type, + CONCAT('/one-media/one-image-nonlab/',Other_PreparasiSpermaImgNewName) as image_url + FROM t_orderdetail + JOIN other_preparasisperma_img ON Other_PreparasiSpermaImgT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND + Other_PreparasiSpermaImgIsActive = 'Y' + WHERE + T_OrderDetailID = {$id} AND + T_OrderDetailIsActive = 'Y' + GROUP BY Other_PreparasiSpermaImgID"; + //echo $sql; + $images = $this->db_smartone->query($sql)->result_array(); + + $rst = array('doctors' => $doctors, 'methodes' => $methodes, 'results' => $rows, 'images' => $images); + $this->sys_ok(["records" => $rst]); + } else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + + function uploadimage_preparasi_sperma() + { + if (! $this->isLogin) { + $this->sys_error("Invalid Token"); + exit; + } + + $userid = $this->sys_user["M_UserID"]; + $data = []; + //print_r($_SERVER); + + $prm = $this->sys_input; + $orderid = $this->input->post('orderid'); + $type = $this->input->post('type'); + $labnumber = $this->input->post('labnumber'); + $sql = "UPDATE other_preparasisperma_img SET + Other_PreparasiSpermaImgIsActive = 'N', + Other_PreparasiSpermaImgUserID = {$userid} + WHERE + Other_PreparasiSpermaImgT_OrderHeaderID = {$orderid} AND + Other_PreparasiSpermaImgType = '{$type}'"; + //echo $sql; + $this->db_onedev->query($sql); + //$config['upload_path'] = 'assets/'; + + $path = '/home/one/project/one/one-media/one-image-nonlab/'; + //echo $path; + $config['upload_path'] = $path; + $config['allowed_types'] = 'jpg|jpeg|png|gif'; + + $config['max_size'] = '10000'; + $count = count($_FILES['files']['name']); + //echo $count; + $this->load->library('upload', $config); + + $error = []; + for ($i = 0; $i < $count; $i++) { + + + if (!empty($_FILES['files']['name'][$i])) { + + + + $_FILES['file']['name'] = $_FILES['files']['name'][$i]; + + $_FILES['file']['type'] = $_FILES['files']['type'][$i]; + + $_FILES['file']['tmp_name'] = $_FILES['files']['tmp_name'][$i]; + + $_FILES['file']['error'] = $_FILES['files']['error'][$i]; + + $_FILES['file']['size'] = $_FILES['files']['size'][$i]; + + + + $namex = $orderid . '-' . $labnumber . '-' . $this->generateRandomString(5); + //echo $namex; + + $config['file_name'] = $namex; + $this->upload->initialize($config); + //echo $config['file_name'] ; + + + + + + if ($this->upload->do_upload('file')) { + + $uploadData = $this->upload->data(); + + $filename = $uploadData['file_name']; + //echo $filename; + + + $sql = "INSERT INTO other_preparasisperma_img ( + Other_PreparasiSpermaImgT_OrderHeaderID, + Other_PreparasiSpermaImgType, + Other_PreparasiSpermaImgOldName, + Other_PreparasiSpermaImgNewName, + Other_PreparasiSpermaImgCreated, + Other_PreparasiSpermaImgUserID + ) + VALUES( + {$orderid}, + '{$type}', + '{$_FILES['files']['name'][$i]}', + '{$filename}', + NOW(), + {$userid} + + )"; + //echo $sql; + $this->db_onedev->query($sql); + $xlast_id = $this->db_onedev->insert_id(); + $data['totalFiles'][] = array('xid' => $xlast_id, 'type' => $type, 'image_url' => '/one-media/one-image-nonlab/' . $filename); + } else { + $error = array('error' => $this->upload->display_errors()); + } + } + } + + $result = array("total" => count($data['totalFiles']), "records" => $data['totalFiles'], 'errors' => $error); + $this->sys_ok($result); + } + + + function saveresult_preparasi_sperma() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = $inp['doctor']; + $orderdetail_id = $inp['orderdetailid']; + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + if ($prm['xid'] == '0') { + $sql = "INSERT INTO other_preparasisperma( + Other_PreparasiSpermaM_DoctorID, + Other_PreparasiSpermaT_OrderDetailID, + Other_PreparasiSpermaPreMotilitasA, + Other_PreparasiSpermaPreMotilitasB, + Other_PreparasiSpermaPreMotilitasC, + Other_PreparasiSpermaPreKonsentrasi, + Other_PreparasiSpermaPreKontaminan, + Other_PreparasiSpermaPostMotilitasA, + Other_PreparasiSpermaPostMotilitasB, + Other_PreparasiSpermaPostMotilitasC, + Other_PreparasiSpermaPostKonsentrasi, + Other_PreparasiSpermaPostKontaminan, + Other_PreparasiSpermaPreVolume, + Other_PreparasiSpermaPostVolume, + Other_PreparasiSpermaM_MethodeSpermaID, + Other_PreparasiSpermaNote, + Other_PreparasiSpermaUserID, + Other_PreparasiSpermaCreated + ) + VALUES( + {$doctor_id}, + {$orderdetail_id}, + '{$prm['Other_PreparasiSpermaPreMotilitasA']}', + '{$prm['Other_PreparasiSpermaPreMotilitasB']}', + '{$prm['Other_PreparasiSpermaPreMotilitasC']}', + '{$prm['Other_PreparasiSpermaPreKonsentrasi']}', + '{$prm['Other_PreparasiSpermaPreKontaminan']}', + '{$prm['Other_PreparasiSpermaPostMotilitasA']}', + '{$prm['Other_PreparasiSpermaPostMotilitasB']}', + '{$prm['Other_PreparasiSpermaPostMotilitasC']}', + '{$prm['Other_PreparasiSpermaPostKonsentrasi']}', + '{$prm['Other_PreparasiSpermaPostKontaminan']}', + '{$prm['Other_PreparasiSpermaPreVolume']}', + '{$prm['Other_PreparasiSpermaPostVolume']}', + '{$prm['Other_PreparasiSpermaM_MethodeSpermaID']}', + '{$prm['Other_PreparasiSpermaNote']}', + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } else { + $sql = "SELECT * FROM other_preparasisperma WHERE Other_PreparasiSpermaT_OrderDetailID = {$orderdetail_id} AND Other_PreparasiSpermaIsActive = 'Y'"; + $data_header = $this->db_smartone->query($sql)->row_array(); + $header_id = $data_header['Other_PreparasiSpermaID']; + $sql = "UPDATE other_preparasisperma SET + Other_PreparasiSpermaM_DoctorID = {$doctor_id}, + Other_PreparasiSpermaPreMotilitasA = '{$prm['Other_PreparasiSpermaPreMotilitasA']}', + Other_PreparasiSpermaPreMotilitasB = '{$prm['Other_PreparasiSpermaPreMotilitasB']}', + Other_PreparasiSpermaPreMotilitasC = '{$prm['Other_PreparasiSpermaPreMotilitasC']}', + Other_PreparasiSpermaPreKonsentrasi = '{$prm['Other_PreparasiSpermaPreKonsentrasi']}', + Other_PreparasiSpermaPreKontaminan = '{$prm['Other_PreparasiSpermaPreKontaminan']}', + Other_PreparasiSpermaPostMotilitasA = '{$prm['Other_PreparasiSpermaPostMotilitasA']}', + Other_PreparasiSpermaPostMotilitasB = '{$prm['Other_PreparasiSpermaPostMotilitasB']}', + Other_PreparasiSpermaPostMotilitasC = '{$prm['Other_PreparasiSpermaPostMotilitasC']}', + Other_PreparasiSpermaPostKonsentrasi = '{$prm['Other_PreparasiSpermaPostKonsentrasi']}', + Other_PreparasiSpermaPostKontaminan = '{$prm['Other_PreparasiSpermaPostKontaminan']}', + Other_PreparasiSpermaPreVolume = '{$prm['Other_PreparasiSpermaPreVolume']}', + Other_PreparasiSpermaPostVolume = '{$prm['Other_PreparasiSpermaPostVolume']}', + Other_PreparasiSpermaM_MethodeSpermaID = '{$prm['Other_PreparasiSpermaM_MethodeSpermaID']}', + Other_PreparasiSpermaNote = '{$prm['Other_PreparasiSpermaNote']}', + Other_PreparasiSpermaUserID = {$userid} + WHERE + Other_PreparasiSpermaID = {$header_id}"; + $this->db_smartone->query($sql); + } + + + $result = array("total" => 1, "records" => array(), "sql" => ''); + $this->sys_ok($result); + exit; + } + + function getdnafragmentasiresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT other_dnafragmentasi.*, + Other_DnaFragmentasiID as xid, + Other_DnaFragmentasiT_OrderDetailID as orderdetail_id, + IFNULL(Other_DnaFragmentasiM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_DnaFragmentasiM_DoctorID) OR Other_DnaFragmentasiM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name, + IFNULL(Other_DnaFragmentasiOther_DnaFragmentasiMethodeID,0) as methode_id, + IFNULL(Other_DnaFragmentasiMethodeName,'') as methode_name, + Other_DnaFragmentasiHaloLuas as halo_luas, + Other_DnaFragmentasiHaloSedang as halo_sedang, + Other_DnaFragmentasiHaloSempit as halo_sempit, + Other_DnaFragmentasiTanpaHalo as tanpa_halo, + Other_DnaFragmentasiDFI as dfi, + Other_DnaFragmentasiKesimpulan as kesimpulan, + Other_DnaFragmentasiCatatan as catatan + FROM other_dnafragmentasi + LEFT JOIN m_doctor ON Other_DnaFragmentasiM_DoctorID = M_DoctorID + LEFT JOIN other_dnafragmentasimethode ON Other_DnaFragmentasiOther_DnaFragmentasiMethodeID = Other_DnaFragmentasiMethodeID + WHERE + Other_DnaFragmentasiT_OrderDetailID = {$id} AND Other_DnaFragmentasiIsActive = 'Y' + GROUP BY Other_DnaFragmentasiID + LIMIT 1"; + //echo $sql; + $query = $this->db_smartone->query($sql); + + if ($query) { + $rows = $query->row_array(); + if (!$rows) { + $rows = array( + 'xid' => 0, + 'orderdetail_id' => $id, + 'doctor_id' => 0, + 'doctor_name' => '', + 'methode_id' => 0, + 'methode_name' => '', + 'halo_luas' => '', + 'halo_sedang' => '', + 'tanpa_halo' => '', + 'dfi' => '', + 'kesimpulan' => '', + 'catatan' => '' + ); + } + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID + WHERE + M_DoctorSONat_SubGroupID = 4 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + + $sql = " + SELECT '0' as id, 'Belum memilih metode' as name + UNION + SELECT Other_DnaFragmentasiMethodeID as id, Other_DnaFragmentasiMethodeName as name + FROM other_dnafragmentasimethode + WHERE + Other_DnaFragmentasiMethodeIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $methodes = $this->db_smartone->query($sql)->result_array(); + + + $rst = array('doctors' => $doctors, 'methodes' => $methodes, 'results' => $rows); + $this->sys_ok(["records" => $rst]); + } else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + function saveresult_dnafragmentasi() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = $inp['doctor']['id']; + $methode_id = $inp['methode']['id']; + $orderdetail_id = $inp['results']['orderdetail_id']; + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + if (intval($prm['xid']) == 0) { + $sql = "INSERT INTO other_dnafragmentasi( + Other_DnaFragmentasiT_OrderDetailID, + Other_DnaFragmentasiM_DoctorID, + Other_DnaFragmentasiOther_DnaFragmentasiMethodeID, + Other_DnaFragmentasiHaloLuas, + Other_DnaFragmentasiHaloSedang, + Other_DnaFragmentasiHaloSempit, + Other_DnaFragmentasiTanpaHalo, + Other_DnaFragmentasiDFI, + Other_DnaFragmentasiKesimpulan, + Other_DnaFragmentasiCatatan, + Other_DnaFragmentasiUserID, + Other_DnaFragmentasiLastUpdated + ) + VALUES( + {$orderdetail_id}, + {$doctor_id}, + {$methode_id}, + '{$prm['halo_luas']}', + '{$prm['halo_sedang']}', + '{$prm['halo_sempit']}', + '{$prm['tanpa_halo']}', + '{$prm['dfi']}', + '{$prm['kesimpulan']}', + '{$prm['catatan']}', + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } else { + $sql = "UPDATE other_dnafragmentasi SET + Other_DnaFragmentasiT_OrderDetailID = {$orderdetail_id}, + Other_DnaFragmentasiM_DoctorID = {$doctor_id}, + Other_DnaFragmentasiOther_DnaFragmentasiMethodeID = '{$methode_id}', + Other_DnaFragmentasiHaloLuas = '{$prm['halo_luas']}', + Other_DnaFragmentasiHaloSedang = '{$prm['halo_sedang']}', + Other_DnaFragmentasiHaloSempit = '{$prm['halo_sempit']}', + Other_DnaFragmentasiTanpaHalo = '{$prm['tanpa_halo']}', + Other_DnaFragmentasiDFI = '{$prm['dfi']}', + Other_DnaFragmentasiKesimpulan = '{$prm['kesimpulan']}', + Other_DnaFragmentasiCatatan = '{$prm['catatan']}', + Other_DnaFragmentasiLastUpdated = NOW(), + Other_DnaFragmentasiUserID = {$userid} + WHERE + Other_DnaFragmentasiID = {$prm['xid']}"; + //echo $sql; + $this->db_smartone->query($sql); + } + + + $result = array("total" => 1, "records" => array(), "sql" => ''); + $this->sys_ok($result); + exit; + } +} diff --git a/application/controllers/mockup/process/resultverification-westone-030925/Re_px.php b/application/controllers/mockup/process/resultverification-westone-030925/Re_px.php index f9b079b9..d5c1d003 100644 --- a/application/controllers/mockup/process/resultverification-westone-030925/Re_px.php +++ b/application/controllers/mockup/process/resultverification-westone-030925/Re_px.php @@ -1,2512 +1,2509 @@ -db_smartone = $this->load->database("onedev", true); - $this->load->helper(array('form', 'url')); - } - function getMethodeID($natTestID) - { - $sql = "select M_MethodePriorityNat_MethodeID MethodeID, Nat_MethodeName - from - m_methode_priority - join nat_methode on Nat_MethodeID = M_MethodePriorityNat_MethodeID - and Nat_MethodeIsActive = 'Y' - join m_instrumentmethode on M_InstrumentMethodeNat_MethodeID = Nat_MethodeID and M_InstrumentMethodeIsActive = 'Y' - join nat_instrument on M_InstrumentMethodeNat_InstrumentID = Nat_InstrumentID - and Nat_InstrumentIsActive ='Y' - where M_MethodePriorityIsActive = 'Y' - and M_MethodePriorityNat_TestID = $natTestID - and M_MethodePriorityM_DayOfWeekID = dayofweek(now()) - order by M_MethodePriorityNumber desc - limit 0,1 "; - $qry = $this->db->query($sql); - if ($qry) { - $rows = $qry->result_array(); - if (count($rows) > 0) return array($rows[0]["MethodeID"], $rows[0]["Nat_MethodeName"]); - } - //2nd - $sql = "select - M_InstrumentMethodeNat_MethodeID MethodeID, Nat_MethodeName - from m_instrumentmethode - join nat_methode on M_InstrumentMethodeNat_MethodeID = Nat_MethodeID - and Nat_MethodeIsActive = 'Y' - join nat_instrument on M_InstrumentMethodeNat_InstrumentID = Nat_InstrumentID - and Nat_InstrumentIsActive ='Y' - where M_InstrumentMethodeNat_TestID = $natTestID - and M_InstrumentMethodeIsActive = 'Y' - order by M_InstrumentMethodePriority desc - limit 0,1"; - $qry = $this->db->query($sql); - if ($qry) { - $rows = $qry->result_array(); - if (count($rows) > 0) return array($rows[0]["MethodeID"], $rows[0]["Nat_MethodeName"]); - } - // - $sql = "select Nat_NormalValueNat_MethodeID MethodeID, Nat_MethodeName - from - nat_normalvalue - join nat_methode on Nat_NormalValueNat_MethodeID = Nat_MethodeID - and Nat_MethodeIsActive = 'Y' - where Nat_NormalValueNat_TestID = $natTestID - and Nat_NormalValueIsActive = 'Y' - order by Nat_NormalValueID - limit 0,1"; - $qry = $this->db->query($sql); - if ($qry) { - $rows = $qry->result_array(); - if (count($rows) > 0) return array($rows[0]["MethodeID"], $rows[0]["Nat_MethodeName"]); - } - return array(0, ""); - } - function get_normal_value($methodeID, $natTestID, $sexID, $ageInDay) - { - $sql = "select fn_sampling_get_normal($methodeID, $natTestID, $sexID, $ageInDay) as normalValueID"; - $qry = $this->db->query($sql); - if ($qry) { - $rows = $qry->result_array(); - if (count($rows) > 0) return $rows[0]["normalValueID"]; - } - return 0; - } - function fn_fix_normal($order_id) - { - $sql = "select - T_OrderDetailID, M_PatientM_SexID, fn_global_age_count_day(M_PatientDOB, date(T_OrderHeaderDate)) Dob , - T_TestNat_TestID - from t_orderheader - join m_patient on T_OrderHeaderID = $order_id and T_OrderHeaderM_PatientID = M_PatientID - join t_orderdetail on T_OrderDetailT_OrderHeaderID = T_OrderHeaderID - and T_OrderDetailIsACtive = 'Y' - and ( T_OrderDetailNat_NormalValueID is null or T_OrderDetailNat_NormalValueID = 0 ) - join t_test on T_OrderDetailT_TestID = T_TestID and T_TestIsResult = 'Y' "; - $qry = $this->db->query($sql); - if (! $qry) { - return; - } - $rows = $qry->result_array(); - if (count($rows) == 0) return; - $sql_u = "update t_orderdetail - join nat_normalvalue on T_OrderDetailID = ? and Nat_NormalValueID = ? - set - T_OrderDetailNat_NormalValueID = Nat_NormalValueID, - T_OrderDetailNormalValueNote = Nat_NormalValueNote, - T_OrderDetailNormalValueDescription = Nat_NormalValueDescription, - T_OrderDetailMinValue = Nat_NormalValueMinValue, - T_OrderDetailMaxValue = Nat_NormalValueMaxValue, - T_OrderDetailMinValueInclusive = Nat_NormalValueMinValueInclusive, - T_OrderDetailMaxValueInclusive = Nat_NormalValueMaxValueInclusive, - T_OrderDetailNat_MethodeID = ?, - T_OrderdetailNat_MethodeName =?"; - - foreach ($rows as $r) { - $T_OrderDetailID = $r["T_OrderDetailID"]; - $sexID = $r["M_PatientM_SexID"]; - $ageInDay = $r["Dob"]; - $natTestID = $r["T_TestNat_TestID"]; - list($methodeID, $methodeName) = $this->getMethodeID($natTestID); - if ($methodeID == 0) continue; - $normalValueID = $this->get_normal_value($methodeID, $natTestID, $sexID, $ageInDay); - if ($normalValueID == 0) return; - $this->db->query($sql_u, array($T_OrderDetailID, $normalValueID, $methodeID, $methodeName)); - } - } - - function update_order_sample($targetID, $sourceID) - { - $sql = "update t_ordersample target - join t_ordersample source on - target.T_OrderSampleID = ? - and target.T_OrderSampleWorklistReceive = 'N' - and source.T_OrderSampleID = ? - set - target.T_OrderSampleSampling = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSampling, source.T_OrderSampleSampling), - target.T_OrderSampleSamplingDate = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingDate, source.T_OrderSampleSamplingDate), - target.T_OrderSampleSamplingTime = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingTime, source.T_OrderSampleSamplingTime), - target.T_OrderSampleSamplingUserID = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingUserID, source.T_OrderSampleSamplingUserID), - - target.T_OrderSampleReceive = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceive, source.T_OrderSampleReceive), - target.T_OrderSampleReceiveDate = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveDate, source.T_OrderSampleReceiveDate), - target.T_OrderSampleReceiveTime = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveTime, source.T_OrderSampleReceiveTime), - target.T_OrderSampleReceiveUserID = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveUserID, source.T_OrderSampleReceiveUserID), - - target.T_OrderSampleVerification = if(target.T_OrderSampleVerification='Y',target.T_OrderSampleVerification, source.T_OrderSampleVerification), - target.T_OrderSampleVerificationDate =if(target.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationDate, source.T_OrderSampleVerificationDate), - target.T_OrderSampleVerificationTime =if(source.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationTime, source.T_OrderSampleVerificationTime), - target.T_OrderSampleVerificationUserID =if(source.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationUserID, source.T_OrderSampleVerificationUserID), - - target.T_OrderSampleProcessing = if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessing, source.T_OrderSampleProcessing), - target.T_OrderSampleProcessingDate= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingDate, source.T_OrderSampleProcessingDate), - target.T_OrderSampleProcessingTime= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingTime, source.T_OrderSampleProcessingTime), - target.T_OrderSampleProcessingUserID= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingUserID, source.T_OrderSampleProcessingUserID), - - target.T_OrderSampleReceiveHandling =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandling, source.T_OrderSampleReceiveHandling ), - target.T_OrderSampleReceiveHandlingDate =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingDate, source.T_OrderSampleReceiveHandlingDate), - target.T_OrderSampleReceiveHandlingTime =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingTime, source.T_OrderSampleReceiveHandlingTime), - target.T_OrderSampleReceiveHandlingUserID =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingUserID, source.T_OrderSampleReceiveHandlingUserID), - - target.T_OrderSampleHandling = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandling, source.T_OrderSampleHandling), - target.T_OrderSampleHandlingDate = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingDate, source.T_OrderSampleHandlingDate), - target.T_OrderSampleHandlingTime = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingTime, source.T_OrderSampleHandlingTime), - target.T_OrderSampleHandlingUserID = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingUserID, source.T_OrderSampleHandlingUserID), - - target.T_OrderSampleWorklistReceive = source.T_OrderSampleWorklistReceive, - target.T_OrderSampleWorklistReceiveDatetime = source.T_OrderSampleWorklistReceiveDateTime, - target.T_OrderSampleWorklistReceiveUserID = source.T_OrderSampleWorklistReceiveUserID - "; - $qry = $this->db->query($sql, array($targetID, $sourceID)); - if (! $qry) { - echo json_encode(array("status" => "ERR", "message" => print_r($this->db->error(), true))); - exit; - } - } - function fix_sample_serum($headerID) - { - //cari t_ordersample yg belum worklist receive dengan code 017% - $sql = "select T_OrderSampleID - from t_ordersample - join t_sampletype on - T_OrderSampleT_OrderHeaderID = ? - and T_OrderSampleWorklistReceive = 'N' - and T_OrderSampleIsActive = 'Y' - and T_OrderSampleT_SampleTypeID = T_SampletypeID - and T_SampleTypeCode like '017%' - "; - $qry = $this->db->query($sql, array($headerID)); - if (!$qry) { - echo json_encode(array("status" => "ERR", "message" => print_r($this->db->error(), true))); - exit; - } - $rows = $qry->result_array(); - if (count($rows) == 0) return; - //cari T_OrderSample yang sudah di receive yg terakhir - $sql = "select T_OrderSampleID - from t_ordersample - join t_sampletype on - T_OrderSampleT_OrderHeaderID = ? - and T_OrderSampleWorklistReceive = 'Y' - and T_OrderSampleIsActive = 'Y' - and T_OrderSampleT_SampleTypeID = T_SampletypeID - and T_SampleTypeCode like '017%' - order by T_OrderSampleWorklistReceiveDatetime desc - limit 0,1 - "; - $qry = $this->db->query($sql, array($headerID)); - if (!$qry) { - echo json_encode(array("status" => "ERR", "message" => print_r($this->db->error(), true))); - exit; - } - $rcv_rows = $qry->result_array(); - if (count($rcv_rows) == 0) return; - - //print_r($rows); - //print_r($rcv_rows); - $rcv_T_OrderSampleID = $rcv_rows[0]["T_OrderSampleID"]; - //ada yg belum di receive - foreach ($rows as $r) { - $T_OrderSampleID = $r["T_OrderSampleID"]; - $this->update_order_sample($T_OrderSampleID, $rcv_T_OrderSampleID); - } - } - public function search() - { - $prm = $this->sys_input; - $max_rst = 99; - - $id = $prm["order_id"]; - if ($id > 0) { - $this->fix_sample_serum($id); - $this->fn_fix_normal($id); - } - $lang = $this->lang_default_code; - $lang_id = isset($prm['lang_id']) ? $prm['lang_id'] : '0'; - - if ($lang_id != 0) { - $l = $this->db_smartone->where("Nat_LangID", $lang_id)->get("nat_lang")->row(); - $lang = $l->Nat_LangCode; - } - - //tambahan fajri - $sql = " UPDATE t_orderdetail - JOIN t_test ON T_OrderDetailT_TestID = T_TestID - SET T_OrderDetailT_TestIsResult = T_TestIsResult - WHERE - T_OrderDetailT_OrderHeaderID = {$id} AND - T_OrderDetailT_TestIsResult = '' AND - T_OrderDetailIsActive = 'Y'"; - $this->db_smartone->query($sql); - - $tot_count = 0; - $lq = ""; - $group_id = 0; - if (isset($prm['group_id'])) - $group_id = $prm['group_id']; - - if ($group_id != 0) { - $sql = "select distinct T_WorklistDetailNat_TestID Nat_TestID - from t_worklistdetailv2 - where T_WorklistDetailT_WorklistID = {$group_id}"; - $qry = $this->db_smartone->query($sql); - $rows = $qry->result_array(); - $nat_test_ids = "0"; - foreach ($rows as $r) { - $nat_test_ids .= ", " . $r["Nat_TestID"]; - } - $q_group = " ( $nat_test_ids ) "; - - $sql = " - SELECT a1.*, cOUNT(a2.T_OrderDetailID) level - FROM ( - SELECT IFNULL(y.T_OrderDetailT_TestID, x.T_OrderDetailT_TestID) t_testid, - IFNULL(y.T_OrderDetailT_TestName, y.T_OrderDetailT_TestName) t_testname, - y.T_OrderDetailResult result, y.T_OrderDetailResult result_old, y.T_OrderDetailNote note, y.T_OrderDetailNote note_old, - y.T_OrderDetailID id, - y.T_OrderDetailT_TestIsResult is_result, a.T_TestIsQuantitative is_quantitative, - y.T_OrderDetailResultFlag result_flag, - y.T_OrderDetailNat_NormalValueID normal_id, - y.T_OrderDetailNormalValueNote normal_note, y.T_OrderDetailNat_UnitName unit_name, - y.T_OrderdetailNat_MethodeID methode_id, y.T_OrderdetailNat_MethodeName methode_name, - a.T_TestNat_TestID nattest_id, a.T_TestID tx_id, count(T_ResultInstrumentID) as result_instrument_n, - y.T_OrderDetailVerification, T_OrderSampleReceive sample_receive, - T_OrderSampleProcessing sample_processing, T_OrderSampleWorklistReceive sample_worklist_receive, - IF(T_OrderDetailAddOnPreAnalytic = 'Y', T_OrderDetailAddOnPreAnalytic, PreAnalyticIsOk) pre_analytic, - T_OrderDetailAddOnPreAnalytic, - T_OrderHeaderID order_id, y.T_OrderDetailT_TestSasCode test_sas_code, - tx.T_TestSasCode, - T_OrderDetailAddOnResample `resample`, T_OrderDetailAddOnResampleStatus resample_status, - T_OrderDetailAddOnRef ref, y.T_OrderDetailVerification verification, y.T_OrderDetailValidation validation, - T_OrderPromiseDateTime, Group_ResultName as ResultGroupName - FROM t_orderdetail x - left join t_orderpromise on x.T_OrderDetailT_OrderPromiseID = T_OrderPromiseID - JOIN t_test tx ON x.T_OrderDetailT_TestID = T_TestID - JOIN t_test tcheck on tcheck.T_TestNat_TestID in {$q_group} - and ( tx.T_TestID = tcheck.T_TestID or tx.T_TestSasCode like concat(tcheck.T_TestSasCode,'%')) - LEFT JOIN group_resultdetail ON Group_ResultDetailT_TestID = x.T_OrderDetailT_TestID AND Group_ResultDetailIsActive = 'Y' - LEFT JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND Group_ResultFlagNonLab = 'N' - LEFT JOIN t_orderdetail y ON x.T_OrderDetailT_TestSasCode LIKE CONCAT(y.T_OrderDetailT_TestSasCode, '%') - AND x.T_OrderDetailT_OrderHeaderID = y.T_OrderDetailT_OrderHeaderID - AND y.T_OrderDetailIsActive = 'Y' - LEFT JOIN t_orderdetailaddon ON x.T_OrderDetailID = T_OrderDetailAddOnT_OrderDetailID - JOIN t_orderheader ON y.T_OrderDetailT_OrderHeaderID = T_OrderHeaderID - LEFT JOIN t_test a ON y.T_OrderDetailT_TestID = a.T_TestID - AND a.T_TestIsNonLab = '' - LEFT JOIN (SELECT T_OrderSampleT_SampleTypeID, T_OrderSampleReceive, T_OrderSampleProcessing, T_OrderSampleWorklistReceive - FROM t_ordersample WHERE T_OrderSampleT_OrderHeaderID = {$id} - AND T_OrderSampleIsactive = 'Y' - GROUP BY T_OrderSampleT_SampleTypeID) os ON a.T_TestT_SampleTypeID = os.T_OrderSampleT_SampleTypeID - or os.T_OrderSampleT_SampleTypeID = fn_sampletype_from_local(a.T_TestNat_TestID) - - LEFT JOIN t_resultinstrument ON T_ResultInstrumentT_OrderDetailID = x.T_OrderDetailID - LEFT JOIN pre_analytic ON PreAnalyticNat_TestID = a.T_TestNat_TestID AND PreAnalyticDate = date(now()) and PreAnalyticIsActive = 'Y' - WHERE x.T_OrderDetailT_OrderHeaderID = {$id} - AND x.T_OrderDetailIsActive = 'Y' - GROUP BY y.T_OrderDetailT_TestID - ORDER BY y.T_OrderDetailT_TestSasCode ASC - ) a1 - - LEFT JOIN t_orderdetail a2 ON a2.T_OrderDetailT_OrderHeaderID = a1.order_id - AND a2.T_OrderDetailIsActive = 'Y' - AND a1.test_sas_code LIKE CONCAT(a2.T_OrderDetailT_testSasCode, '%') - GROUP BY a1.t_testid - order by a1.test_sas_code -"; - $query = $this->db_smartone->query($sql); - $lq = $this->db_smartone->last_query(); - } else { - $sql = " - SELECT a1.*, cOUNT(a2.T_OrderDetailID) level - FROM ( - SELECT IFNULL(y.T_OrderDetailT_TestID, x.T_OrderDetailT_TestID) t_testid, - IFNULL(y.T_OrderDetailT_TestName, y.T_OrderDetailT_TestName) t_testname, - y.T_OrderDetailResult result, y.T_OrderDetailResult result_old, y.T_OrderDetailNote note, y.T_OrderDetailNote note_old, - y.T_OrderDetailID id, - y.T_OrderDetailT_TestIsResult is_result, a.T_TestIsQuantitative is_quantitative, - y.T_OrderDetailResultFlag result_flag, - y.T_OrderDetailNat_NormalValueID normal_id, - y.T_OrderDetailNormalValueNote normal_note, y.T_OrderDetailNat_UnitName unit_name, - y.T_OrderdetailNat_MethodeID methode_id, y.T_OrderdetailNat_MethodeName methode_name, - a.T_TestNat_TestID nattest_id, a.T_TestID tx_id, count(T_ResultInstrumentID) as result_instrument_n, - y.T_OrderDetailVerification, T_OrderSampleReceive sample_receive, - T_OrderSampleProcessing sample_processing, T_OrderSampleWorklistReceive sample_worklist_receive, - IF(T_OrderDetailAddOnPreAnalytic = 'Y', T_OrderDetailAddOnPreAnalytic, PreAnalyticIsOk) pre_analytic, - T_OrderDetailAddOnPreAnalytic, - T_OrderHeaderID order_id, y.T_OrderDetailT_TestSasCode test_sas_code, - tx.T_TestSasCode, - T_OrderDetailAddOnResample `resample`, T_OrderDetailAddOnResampleStatus resample_status, - T_OrderDetailAddOnRef ref, y.T_OrderDetailVerification verification, y.T_OrderDetailValidation validation, - T_OrderPromiseDateTime , Group_ResultName as ResultGroupName - FROM t_orderdetail x - left join t_orderpromise on x.T_OrderDetailT_OrderPromiseID = T_OrderPromiseID - JOIN t_test tx ON x.T_OrderDetailT_TestID = T_TestID - LEFT JOIN group_resultdetail ON Group_ResultDetailT_TestID = x.T_OrderDetailT_TestID AND Group_ResultDetailIsActive = 'Y' - LEFT JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND Group_ResultFlagNonLab = 'N' - LEFT JOIN t_orderdetail y ON x.T_OrderDetailT_TestSasCode LIKE CONCAT(y.T_OrderDetailT_TestSasCode, '%') - AND x.T_OrderDetailT_OrderHeaderID = y.T_OrderDetailT_OrderHeaderID - AND y.T_OrderDetailIsActive = 'Y' - - LEFT JOIN t_orderdetailaddon ON x.T_OrderDetailID = T_OrderDetailAddOnT_OrderDetailID - - JOIN t_orderheader ON y.T_OrderDetailT_OrderHeaderID = T_OrderHeaderID - LEFT JOIN t_test a ON y.T_OrderDetailT_TestID = a.T_TestID - AND a.T_TestIsNonLab = '' - LEFT JOIN (SELECT T_OrderSampleT_SampleTypeID, T_OrderSampleReceive, T_OrderSampleProcessing, T_OrderSampleWorklistReceive - FROM t_ordersample WHERE T_OrderSampleT_OrderHeaderID = {$id} - AND T_OrderSampleIsactive = 'Y' - GROUP BY T_OrderSampleT_SampleTypeID) os ON a.T_TestT_SampleTypeID = os.T_OrderSampleT_SampleTypeID - or os.T_OrderSampleT_SampleTypeID = fn_sampletype_from_local(a.T_TestNat_TestID) - - LEFT JOIN t_resultinstrument ON T_ResultInstrumentT_OrderDetailID = x.T_OrderDetailID - LEFT JOIN pre_analytic ON PreAnalyticNat_TestID = a.T_TestNat_TestID AND PreAnalyticDate = date(now()) and PreAnalyticIsActive = 'Y' - WHERE x.T_OrderDetailT_OrderHeaderID = {$id} - AND x.T_OrderDetailIsActive = 'Y' - GROUP BY y.T_OrderDetailT_TestID - ORDER BY y.T_OrderDetailT_TestSasCode ASC - ) a1 - - LEFT JOIN t_orderdetail a2 ON a2.T_OrderDetailT_OrderHeaderID = a1.order_id - AND a2.T_OrderDetailIsActive = 'Y' - AND a1.test_sas_code LIKE CONCAT(a2.T_OrderDetailT_testSasCode, '%') - GROUP BY a1.t_testid - order by a1.test_sas_code -"; - //echo $sql; - $query = $this->db_smartone->query($sql); - $lq = $this->db_smartone->last_query(); - } - // file_put_contents("/xtmp/re-query.sql",$lq); - - if ($query) { - $rst = []; - $rows = $query->result_array(); - - foreach ($rows as $k => $v) { - - if ($v['is_result'] == "Y" && $v['is_quantitative'] == "N") { - $v['template'] = []; - $x = $this->db_smartone->query("CALL sp_master_resulttemplate_get('{$v['t_testid']}')"); - $this->clean_mysqli_connection($this->db_smartone->conn_id); - if ($x) - $v['template'] = $x->result_array(); - } - - // IF Rujukan, by pas Pre Analytik - if ($v['ref'] == 'Y') - $v['pre_analytic'] = 'Y'; - if ($v["id"] == "885455") { - //sipe workaround - //$v["sample_receive"] = "Y"; - $v["sample_worklist_receive"] = "Y"; - } - $rst[] = $v; - } - - $result = array("total" => $tot_count, "records" => $rst, "total_display" => sizeof($rows), "q" => $lq); - $this->sys_ok($result); - } else { - $this->sys_error_db("RE Px rows", $this->db_smartone); - exit; - } - } - - public function save() - { - $prm = $this->sys_input; - $data = json_decode($prm["data"]); - $lang = $this->lang_default_code; - $lang_id = isset($prm['lang_id']) ? $prm['lang_id'] : '0'; - - if ($lang_id != 0) { - $l = $this->db_smartone->where("Nat_LangID", $lang_id)->get("nat_lang")->row(); - $lang = $l->Nat_LangCode; - } - - $sql_norm = "select T_OrderDetailMinValue, T_OrderDetailMaxValue, - T_OrderDetailMinValueInclusive, T_OrderDetailMaxValueInclusive, - Nat_TestFlagLow, Nat_TestFlagHigh - from t_orderdetail - join t_test on T_OrderDetailT_TestID = T_TestID - join nat_test on T_TestNat_TestID = Nat_TestID and T_TestIsActive = 'Y' - where T_OrderDetailID = ? "; - - $ids = []; - foreach ($data as $k => $v) { - if ($v->resultInstrumentID > 0) { - $sql_i = "select T_ResultInstrumentNat_NormalValueID normalValueID - from t_resultinstrument - where T_ResultInstrumentID = ?"; - $qry_i = $this->db_smartone->query($sql_i, array($v->resultInstrumentID)); - if ($qry_i) { - $rows_i = $qry_i->result_array(); - - if (count($rows_i) > 0) { - $sql_iu = "update t_orderdetail, nat_normalvalue , nat_methode - set T_OrderDetailMinValue = Nat_NormalValueMinValue, - T_OrderDetailMinValueInclusive = Nat_NormalValueMinValueInclusive, - T_OrderDetailMaxValue = Nat_NormalValueMaxValue , - T_OrderDetailMaxValueInclusive = Nat_NormalValueMaxValueInclusive, - T_OrderDetailNormalValueNote = Nat_NormalValueNote, - T_OrderDetailNormalValueDescription = Nat_NormalValueDescription, - T_OrderDetailNat_NormalValueID = Nat_NormalValueID, - T_OrderDetailNat_MethodeID = Nat_NormalValueNat_MethodeID, - T_OrderDetailNat_MethodeName = Nat_MethodeName - where T_OrderDetailID = ? and Nat_NormalValueID = ? - and Nat_NormalValueNat_MethodeID = Nat_MethodeID - "; - $this->db_smartone->query($sql_iu, array($v->id, $rows_i[0]["normalValueID"])); - //file_put_contents("/xtmp/update-nilai-normal", $this->db_smartone->last_query() . "\n", FILE_APPEND); - } - } - } - $y = $this->db_smartone->query("SELECT fn_process_sample_handling_perfect('{$v->order_id}', '{$v->test_id}') c") - ->row(); - $req_status = $y->c; - $qry_norm = $this->db_smartone->query($sql_norm, $v->id); - $result_flag = ""; - if ($qry_norm) { - $rows_norm = $qry_norm->result_array(); - if (count($rows_norm) > 0) { - $r = $rows_norm[0]; - if (is_numeric($v->result)) { - - if ($r["T_OrderDetailMinValueInclusive"] == "Y" && $v->result < $r["T_OrderDetailMinValue"]) { - $result_flag = $r["Nat_TestFlagLow"]; - } - if ($r["T_OrderDetailMinValueInclusive"] == "N" && $v->result <= $r["T_OrderDetailMinValue"]) { - $result_flag = $r["Nat_TestFlagLow"]; - } - if ($r["T_OrderDetailMaxValueInclusive"] == "Y" && $v->result > $r["T_OrderDetailMaxValue"]) { - $result_flag = $r["Nat_TestFlagHigh"]; - } - if ($r["T_OrderDetailMaxValueInclusive"] == "N" && $v->result >= $r["T_OrderDetailMaxValue"]) { - $result_flag = $r["Nat_TestFlagHigh"]; - } - } - } - } - if ($lang == $this->lang_default_code) { - $this->db_smartone->set('T_OrderDetailResult', $v->result) - ->set('T_OrderDetailResultFlag', $result_flag) - ->set('T_OrderDetailNote', $v->note) - ->set('T_OrderDetailReqStatus', $req_status) - ->where('T_OrderDetailID', $v->id) - ->update('t_orderdetail'); - } else { - $this->db_smartone->set('T_OrderDetailLangResult', $v->result) - ->set('T_OrderDetailLangNote', $v->note) - ->where('T_OrderDetailLangID', $v->id) - ->update('t_orderdetaillang'); - } - - $ids[] = $v->id; - } - - // LOG Process - $order = $this->db_smartone->select('T_OrderDetailT_OrderHeaderID id, T_OrderHeaderLabNumber lab_number', false) - ->join('t_orderheader', 'T_OrderHeaderID = T_OrderDetailT_OrderHeaderID') - ->where('T_OrderDetailID', $data[0]->id) - ->get('t_orderdetail') - ->row(); - - $dblog = $this->load->database("onelog", true); - $dblog->set('Log_ProcessCode', 'PROCESS.Result.Entry') - ->set('Log_ProcessOrderID', $order->id) - ->set('Log_ProcessOrderNumber', $order->lab_number) - ->set('Log_ProcessJson', json_encode($data)) - ->set('Log_ProcessUserID', $this->sys_user['M_UserID']) - ->insert('log_process'); - // END OF Log Process - //auto calculation - $this->load->library("Resultcalc"); - $rows = $this->resultcalc->auto($order->id); - - try { - foreach ($ids as $id) { - $this->db_smartone->query("call sp_set_normal_value_flag($id)"); - $this->clean_mysqli_connection($this->db_smartone->conn_id); - } - } catch (Exception $e) { - } - - $this->sys_ok($ids); - } - - public function save_template() - { - $prm = $this->sys_input; - - $n = $this->db_smartone->select("COUNT(T_ResultTemplateID) n") - ->where("T_ResultTemplateT_TestID", $prm['test_id']) - ->where("T_ResultTemplateIsActive", "Y") - ->where("T_ResultTemplateValue", $prm['value']) - ->get('t_resulttemplate') - ->row(); - if ($n->n > 0) { - $this->sys_error_db("Insert Result Template", $this->db_smartone); - return; - } - - $r = $this->db_smartone->set("T_ResultTemplateT_TestID", $prm['test_id']) - ->set("T_ResultTemplateValue", $prm['value']) - ->insert('t_resulttemplate'); - if ($r) { - $template = []; - $x = $this->db_smartone->query("CALL sp_master_resulttemplate_get('{$prm['test_id']}')"); - $this->clean_mysqli_connection($this->db_smartone->conn_id); - if ($x) - $template = $x->result_array(); - - $this->sys_ok($template); - } - } - - public function export() - { - $prm = $this->sys_input; - - $sql = "CALL sp_process_result_lang(?, ?, ?, ?)"; - $query = $this->db_smartone->query($sql, [$prm['order_id'], $prm['lang_id'], $prm['is_si'], $this->sys_user['M_UserID']]); - if ($query) { - $r = $query->row(); - if ($r->status == "OK") { - $this->sys_ok($r->data); - return; - } - - $this->sys_error_db("Message : " . $r->message, $this->db_smartone); - } else { - $this->sys_error_db("Lang Result", $this->db_smartone); - return; - } - } - - public function search_group() - { - $prm = $this->sys_input; - $max_rst = 100; - - // QUERY TOTAL - $sql = "select count(*) total - from t_worklist - where T_WorklistIsActive = 'Y' - order by T_WorklistName ASC"; - $query = $this->db_smartone->query($sql); - - if ($query) { - $tot_count = $query->result_array()[0]["total"]; - } else { - $this->sys_error_db("worklist count", $this->db_smartone); - exit; - } - - $sql = "select T_WorklistID group_id, T_WorklistName group_name - from t_worklist - where T_WorklistIsActive = 'Y' - order by T_WorklistName ASC - limit 0, {$max_rst}"; - $query = $this->db_smartone->query($sql); - - if ($query) { - $rows = $query->result_array(); - foreach ($rows as $k => $v) - $rows[$k]['data'] = json_decode($v['data']); - $result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows), "q" => $this->db_smartone->last_query()); - $this->sys_ok($result); - } else { - $this->sys_error_db("worklist rows", $this->db_smartone); - exit; - } - } - - public function search_rerun() - { - $prm = $this->sys_input; - $id = $prm["detail_id"]; - - $sql = "CALL sp_process_result_rerun(?)"; - $query = $this->db_smartone->query($sql, [$id]); - - if ($query) { - $rows = $query->result_array(); - $this->sys_ok(["records" => $rows]); - } else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - - - function getdoctorsfna() - { - $prm = $this->sys_input; - // $id = $prm["id"]; - - $sql = " SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY M_DoctorName ASC"; - //echo $sql; - $query = $this->db_smartone->query($sql); - - if ($query) { - $rows = $query->result_array(); - $this->sys_ok(["records" => $rows]); - } else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - function getfnaresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT Other_FNADetailsID as xid, - Other_FNAT_OrderDetailID as orderdetail_id, - Other_FNADetailsCode as code, - Other_FNADetailsLabel as label, - Other_FNADetailsResult as result, - IFNULL(Other_FNAM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_FNAM_DoctorID) OR Other_FNAM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_fna - JOIN other_fnadetails ON Other_FNADetailsOther_FNAID = Other_FNAID AND Other_FNADetailsIsActive = 'Y' - LEFT JOIN m_doctor ON Other_FNAM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_FNAT_OrderDetailID = {$id} AND Other_FNAIsActive = 'Y' - GROUP BY Other_FNADetailsID - ORDER BY Other_FNADetailsCode ASC"; - $query = $this->db_smartone->query($sql); - - if ($query) { - $rows = $query->result_array(); - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $images = array(); - $sql = "SELECT So_ImageUploadID as xid, - CONCAT('/one-media/one-image-nonlab/',So_ImageUploadNewName) as image_url - FROM t_orderdetail - JOIN so_imageupload ON So_ImageUploadT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND - So_ImageUploadIsActive = 'Y' - WHERE - T_OrderDetailID = {$id} AND - T_OrderDetailIsActive = 'Y' - GROUP BY So_ImageUploadID"; - $images = $this->db_smartone->query($sql)->result_array(); - - $rst = array('doctors' => $doctors, 'results' => $rows, 'images' => $images); - $this->sys_ok(["records" => $rst]); - } else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - function getpatologianatomyresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT Other_PatologiAnatomyID as xid, - Other_PatologiAnatomyT_OrderDetailID as orderdetail_id, - Other_PatologiAnatomyNoSediaan as no_sediaan, - Other_PatologiAnatomyDiagnosaKlinis as diagnosa, - Other_PatologiAnatomyKeteranganKlinis as klinis, - Other_PatologiAnatomyLokasiOrgan as lokasi, - Other_PatologiAnatomyMakroskopik as makroskopik, - Other_PatologiAnatomyMikroskopik as mikroskopik, - Other_PatologiAnatomyKesimpulan as kesimpulan, - IFNULL(Other_PatologiAnatomyM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_PatologiAnatomyM_DoctorID) OR Other_PatologiAnatomyM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_patologi_anatomy - LEFT JOIN m_doctor ON Other_PatologiAnatomyM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_PatologiAnatomyT_OrderDetailID = {$id} AND Other_PatologiAnatomyIsActive = 'Y' - GROUP BY Other_PatologiAnatomyID - ORDER BY Other_PatologiAnatomyID ASC - LIMIT 1"; - $query = $this->db_smartone->query($sql); - - if ($query) { - $rows = $query->row_array(); - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - - $sql = "SELECT So_ImageUploadPatologyAnatomyID as xid, - CONCAT('/one-media/one-image-nonlab/',So_ImageUploadPatologyAnatomyNewName) as image_url, - So_ImageUploadPatologyAnatomyType as type - FROM t_orderdetail - JOIN so_imageupload_patology_anatomy ON So_ImageUploadPatologyAnatomyT_OrderHeaderID= T_OrderDetailT_OrderHeaderID AND - So_ImageUploadPatologyAnatomyIsActive= 'Y' - WHERE - T_OrderDetailID = {$id} AND - T_OrderDetailIsActive = 'Y' - GROUP BY So_ImageUploadPatologyAnatomyID"; - $images = $this->db_smartone->query($sql)->result_array(); - $mikro = []; - $makro = []; - - foreach ($images as $key => $value) { - - if ($value['type'] == 'mikro') { - $mikro[] = $value; - } - if ($value['type'] == 'makro') { - $makro[] = $value; - } - } - - $rst = array('doctors' => $doctors, 'result' => $rows, "mikro" => $mikro, "makro" => $makro); - $this->sys_ok(["records" => $rst]); - } else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - - function uploadimage() - { - if (! $this->isLogin) { - $this->sys_error("Invalid Token"); - exit; - } - - $userid = $this->sys_user["M_UserID"]; - $data = []; - //print_r($_SERVER); - - $prm = $this->sys_input; - $orderid = $this->input->post('orderid'); - $labnumber = $this->input->post('labnumber'); - $sql = "UPDATE so_imageupload SET - So_ImageUploadIsActive = 'N', - So_ImageUploadUserID = {$userid} - WHERE - So_ImageUploadT_OrderHeaderID = {$orderid}"; - //echo $sql; - $this->db_onedev->query($sql); - //$config['upload_path'] = 'assets/'; - - $path = '/home/one/project/one/one-media/one-image-nonlab/'; - //echo $path; - $config['upload_path'] = $path; - $config['allowed_types'] = 'jpg|jpeg|png|gif'; - - $config['max_size'] = '10000'; - $count = count($_FILES['files']['name']); - //echo $count; - $this->load->library('upload', $config); - - $error = []; - for ($i = 0; $i < $count; $i++) { - - - if (!empty($_FILES['files']['name'][$i])) { - - - - $_FILES['file']['name'] = $_FILES['files']['name'][$i]; - - $_FILES['file']['type'] = $_FILES['files']['type'][$i]; - - $_FILES['file']['tmp_name'] = $_FILES['files']['tmp_name'][$i]; - - $_FILES['file']['error'] = $_FILES['files']['error'][$i]; - - $_FILES['file']['size'] = $_FILES['files']['size'][$i]; - - - - $namex = $orderid . '-' . $labnumber . '-' . $this->generateRandomString(5); - //echo $namex; - - $config['file_name'] = $namex; - $this->upload->initialize($config); - //echo $config['file_name'] ; - - - - - - if ($this->upload->do_upload('file')) { - - $uploadData = $this->upload->data(); - - $filename = $uploadData['file_name']; - //echo $filename; - - - $sql = "INSERT INTO so_imageupload ( - So_ImageUploadT_OrderHeaderID, - So_ImageUploadT_OrderHeaderLabNumber, - So_ImageUploadT_SampleTypeID, - So_ImageUploadOldName, - So_ImageUploadNewName, - So_ImageUploadCreated, - So_ImageUploadUserID - ) - VALUES( - {$orderid}, - '{$labnumber}', - '150', - '{$_FILES['files']['name'][$i]}', - '{$filename}', - NOW(), - {$userid} - - )"; - //echo $sql; - $this->db_onedev->query($sql); - $xlast_id = $this->db_onedev->insert_id(); - $data['totalFiles'][] = array('xid' => $xlast_id, 'image_url' => '/one-media/one-image-nonlab/' . $filename); - } else { - $error = array('error' => $this->upload->display_errors()); - } - } - } - - $result = array("total" => count($data['totalFiles']), "records" => $data['totalFiles'], 'errors' => $error); - $this->sys_ok($result); - } - - - function generateRandomString($length = 10) - { - $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; - $charactersLength = strlen($characters); - $randomString = ''; - for ($i = 0; $i < $length; $i++) { - $randomString .= $characters[rand(0, $charactersLength - 1)]; - } - return $randomString; - } - - function getcytologiresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT Other_CytologiDetailsID as xid, - Other_CytologiT_OrderDetailID as orderdetail_id, - Other_CytologiDetailsCode as code, - Other_CytologiDetailsLabel as label, - Other_CytologiDetailsResult as result, - IFNULL(Other_CytologiM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_CytologiM_DoctorID) OR Other_CytologiM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_cytologi - JOIN other_cytologidetails ON Other_CytologiDetailsOther_CytologiID = Other_CytologiID AND Other_CytologiDetailsIsActive = 'Y' - LEFT JOIN m_doctor ON Other_CytologiM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_CytologiT_OrderDetailID = {$id} AND Other_CytologiIsActive = 'Y' - GROUP BY Other_CytologiDetailsID - ORDER BY Other_CytologiDetailsCode ASC"; - //echo $sql; - $query = $this->db_smartone->query($sql); - - if ($query) { - $rows = $query->result_array(); - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $rst = array('doctors' => $doctors, 'results' => $rows); - $this->sys_ok(["records" => $rst]); - } else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - function getmikroresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT - Other_MikroID as xid, - Other_MikroHasilBiakan as hasil_biakan, - Other_MikroSampleTypeName as sample_name, - Other_MikroT_OrderDetailID as orderdetail_id, - Other_MikroResult as result_value, - '' as result_other, - IFNULL(T_BacteriaID,0) as T_BacteriaID, - IFNULL(T_BacteriaName,'') as T_BacteriaName, - '' as details, - IFNULL(Other_MikroM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_MikroM_DoctorID) OR Other_MikroM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_mikro - LEFT JOIN t_bacteria ON Other_MikroT_BacteriaID = T_BacteriaID - LEFT JOIN m_doctor ON Other_MikroM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_MikroT_OrderDetailID = {$id} AND Other_MikroIsActive = 'Y' - GROUP BY Other_MikroID"; - //echo $sql; - $query = $this->db_smartone->query($sql); - - if ($query) { - $row = $query->row_array(); - if ($row) { - if ($row['result_value'] != 'Positif' && $row['result_value'] != 'Negatif') { - $row['result_other'] = $row['result_value']; - $row['result_value'] = 'other'; - } - $sql = "SELECT '' as xno, - Other_MikroDetailsID as xid, - Other_MikroDetailsValue as value, - IF(Other_MikroDetailsNote = 'R','Y','N') as chx_r, - IF(Other_MikroDetailsNote = 'I','Y','N') as chx_i, - IF(Other_MikroDetailsNote = 'S','Y','N') as chx_s, - Other_MikroDetailsNote as note, - t_antibiotic.* - FROM other_mikrodetails - LEFT JOIN t_antibiotic ON Other_MikroDetailsT_AntibioticID = T_AntibioticID - WHERE - Other_MikroDetailsOther_MikroID = {$row['xid']} AND Other_MikroDetailsIsActive = 'Y' - GROUP BY Other_MikroDetailsID - ORDER BY T_AntibioticName ASC"; - //echo $sql; - $details = $this->db_smartone->query($sql)->result_array(); - if (details) { - foreach ($details as $k => $v) { - $details[$k]['xno'] = $k + 1; - } - } - $row['details'] = $details; - } else { - $row = array('xid' => '0', 'hasil_biakan' => '', 'result_value' => 'Negatif', 'sample_name' => '', 'orderdetail_id' => $id, 'T_BacteriaID' => '0', 'T_BacteriaName' => '0', 'details' => array(), 'doctor_id' => '0', 'doctor_name' => '0'); - } - } else { - $row = array('xid' => '0', 'hasil_biakan' => '', 'result_value' => 'Negatif', 'sample_name' => '', 'orderdetail_id' => $id, 'T_BacteriaID' => '0', 'T_BacteriaName' => '0', 'details' => array(), 'doctor_id' => '0', 'doctor_name' => '0'); - } - //print_r($row); - - - - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 7 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $sql = " - SELECT '0' as id, 'Belum memilih bakteria' as name - UNION - SELECT T_BacteriaID as id, T_BacteriaName as name - FROM t_bacteria - WHERE - T_BacteriaIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $bacteries = $this->db_smartone->query($sql)->result_array(); - $rst = array('doctors' => $doctors, 'bacteries' => $bacteries, 'results' => $row); - $this->sys_ok(["records" => $rst]); - } - function getantibiotics() - { - $prm = $this->sys_input; - $id = $prm["id"]; - $sql = " SELECT '' as xno, - 0 as xid, - '' as hasil_biakan, - '' as sample_name, - 0 as value, - 'Y' as chx_r, - 'N' as chx_i, - 'N' as chx_s, - 'R' as note, - t_antibiotic.* - FROM t_antibiotic - WHERE - T_AntibioticT_BacteriaID = {$prm['id']} AND T_AntibioticIsActive= 'Y' - ORDER BY T_AntibioticName ASC"; - //echo $sql; - $rows = $this->db_smartone->query($sql)->result_array(); - if (rows) { - foreach ($rows as $k => $v) { - $rows[$k]['xno'] = $k + 1; - } - } - - $this->sys_ok(["records" => $rows]); - } - function getlcprepresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - $sql = " SELECT Other_LcprepDetailsID as xid, - Other_LcprepID as header_id, - Other_LcprepT_orderDetailID as orderdetail_id, - Other_LcprepDetailsCode as code, - Other_LcprepDetailsLabel as label, - Other_LcprepDetailsResult as result, - IFNULL(Other_LcprepM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_LcprepM_DoctorID) OR Other_LcprepM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_lcprep - JOIN other_lcprepdetails ON Other_LcprepDetailsOther_LcprepID = Other_LcprepID AND Other_LcprepDetailsIsActive = 'Y' - LEFT JOIN m_doctor ON Other_LcprepM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_LcprepT_orderDetailID = {$id} AND Other_LcprepIsActive = 'Y' - GROUP BY Other_LcprepDetailsOther_LcprepID, Other_LcprepDetailsCode - ORDER BY Other_LcprepDetailsCode ASC"; - //echo $sql; - $rows = $this->db_smartone->query($sql)->result_array(); - if (!$rows) { - $rows = array( - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'A', - 'label' => 'DESKRIPSI', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ), - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'B', - 'label' => 'KESIMPULAN', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ) - ); - } - - $header_id = $rows[0]['header_id']; - $sql = "SELECT IFNULL(Other_LcprepAdekuasiID,0) as xid, - Lcprep_AdekuasiID as id, - Lcprep_AdekuasiLabel as name, - IF(ISNULL(Other_LcprepAdekuasiID),'N',Other_LcprepAdekuasiChex) as chex - FROM lcprep_adekuasi - LEFT JOIN other_lcprepadekuasi ON Other_LcprepAdekuasiLcprep_AdekuasiID = Lcprep_AdekuasiID AND - Other_LcprepAdekuasiOther_LcprepID = {$header_id} AND - Other_LcprepAdekuasiIsActive = 'Y' - WHERE - Lcprep_AdekuasiIsActive = 'Y' - GROUP BY Lcprep_AdekuasiID - ORDER BY Lcprep_AdekuasiOrder ASC - "; - //echo $sql; - $adeakuasi = $this->db_smartone->query($sql)->result_array(); - foreach ($adeakuasi as $kc => $vc) { - $adeakuasi[$kc]['chex'] = $vc['chex'] == 'N' ? false : true; - } - - $sql = "SELECT IFNULL(Other_LcprepKategoriUmumID,0) as xid, - Lcprep_KategoriUmumID as id, - Lcprep_KategoriUmumLabel as name, - IF(ISNULL(Other_LcprepKategoriUmumID),'N',Other_LcprepKategoriUmumChex) as chex - FROM lcprep_kategoriumum - LEFT JOIN other_lcprepkategoriumum ON Other_LcprepKategoriUmumLcprep_KategoriUmumID = Lcprep_KategoriUmumID AND - Other_LcprepKategoriUmumOther_LcprepID = {$header_id} AND - Other_LcprepKategoriUmumIsActive = 'Y' - WHERE - Lcprep_KategoriUmumIsActive = 'Y' - GROUP BY Lcprep_KategoriUmumID - "; - //echo $sql; - $kategoriumum = $this->db_smartone->query($sql)->result_array(); - foreach ($kategoriumum as $kc => $vc) { - $kategoriumum[$kc]['chex'] = $vc['chex'] == 'N' ? false : true; - } - - $sql = " - SELECT Lcprep_InterpretasiGroupID as group_id, - Lcprep_InterpretasiGroupName as group_name, - '' as subgroups - FROM lcprep_interpretasigroup - WHERE - Lcprep_InterpretasiGroupIsActive = 'Y' - "; - //echo $sql; - $interpretasi = $this->db_smartone->query($sql)->result_array(); - foreach ($interpretasi as $k => $v) { - $subgroups = array(); - $sql = "SELECT Lcprep_InterpretasiSubgroupID as subgroup_id, - Lcprep_InterpretasiSubgroupName as subgroup_name, - '' as childs - FROM lcprep_interpretasisubgroup - WHERE - Lcprep_InterpretasiSubgroupLcprep_InterpretasiGroupID = {$v['group_id']} AND Lcprep_InterpretasiSubgroupIsActive = 'Y'"; - //echo $sql; - $subgroups = $this->db_smartone->query($sql)->result_array(); - if (count($subgroups) > 0) { - foreach ($subgroups as $ki => $vi) { - $childs = array(); - $sql = "SELECT IFNULL(Other_LcprepInterpretasiID,0) as xid, - IFNULL(Other_LcprepInterpretasiChex,'N') as chex, - IFNULL(Other_LcprepInterpretasiValue,'') as value, - Lcprep_InterpretasiID as id, - Lcprep_InterpretasiLcprep_InterpretasiSubgroupID as subgroup_id, - Lcprep_InterpretasiCode as code, - Lcprep_InterpretasiName as name, - Lcprep_InterpretasiParentID as parent_id, - Lcprep_InterpretasiIsParent as is_parent, - Lcprep_InterpretasiHasResult as has_result, - Lcprep_InterpretasiTypeResult as type_result - FROM lcprep_interpretasi - LEFT JOIN other_lcprepinterpretasi ON Other_LcprepInterpretasiOther_LcprepID = {$header_id} AND - Other_LcprepInterpretasiLcprep_InterpretasiID = Lcprep_InterpretasiID AND - Other_LcprepInterpretasiIsActive = 'Y' - WHERE - Lcprep_InterpretasiLcprep_InterpretasiSubgroupID = {$vi['subgroup_id']} AND Lcprep_InterpretasiIsActive = 'Y' - GROUP BY Lcprep_InterpretasiID Order BY Lcprep_InterpretasiCode ASC"; - $childs = $this->db_smartone->query($sql)->result_array(); - if ($childs) { - foreach ($childs as $kc => $vc) { - $childs[$kc]['chex'] = $vc['chex'] == 'N' ? false : true; - } - } - $subgroups[$ki]['childs'] = $childs; - } - } - - $interpretasi[$k]['subgroups'] = $subgroups; - } - - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $rst = array('doctors' => $doctors, 'results' => $rows, 'adekuasi' => $adeakuasi, 'kategoriumum' => $kategoriumum, 'interpretasi' => $interpretasi); - $this->sys_ok(["records" => $rst]); - } - - function getpapsmearresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT Other_PapSmearDetailsID as xid, - Other_PapSmearID as header_id, - Other_PapSmearT_OrderDetailID as orderdetail_id, - Other_PapSmearDetailsCode as code, - Other_PapSmearDetailsLabel as label, - Other_PapSmearDetailsResult as result, - IFNULL(Other_PapSmearM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_PapSmearM_DoctorID) OR Other_PapSmearM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_papsmear - JOIN other_papsmeardetails ON Other_PapSmearDetailsOther_PapSmearID = Other_PapSmearID AND Other_PapSmearDetailsIsActive = 'Y' - LEFT JOIN m_doctor ON Other_PapSmearM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_PapSmearT_OrderDetailID = {$id} AND Other_PapSmearIsActive = 'Y' - GROUP BY Other_PapSmearDetailsID - ORDER BY Other_PapSmearDetailsCode ASC"; - //echo $sql; - $rows = $this->db_smartone->query($sql)->result_array(); - if (!$rows) { - $rows = array( - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'A', - 'label' => 'Makroskopik', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ), - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'B', - 'label' => 'Mikroskopik', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ), - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'C', - 'label' => 'Kesimpulan', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ) - ); - } - - $header_id = $rows[0]['header_id']; - $sql = "SELECT Other_PapSmearMaturasiID as xid, - Other_PapSmearMaturasiValue as value - FROM other_papsmearmaturasi - WHERE - Other_PapSmearMaturasiOther_PapSmearID = {$header_id} AND - Other_PapSmearMaturasiIsActive = 'Y' - "; - //echo $sql; - $dt_maturasi = $this->db_smartone->query($sql)->row_array(); - if (!$dt_maturasi) { - $maturasi = array('xid' => '0', 'value' => array('', '', '')); - } else { - $value = explode('/', $dt_maturasi['value']); - $maturasi = array('xid' => $dt_maturasi['xid'], 'value' => $value); - } - - $sql = "SELECT IFNULL(Other_PapSmearBahanID,0) as xid, - M_PapSmearBahanID as bahan_id, - M_PapSmearBahanName as name, - IF(ISNULL(Other_PapSmearBahanID),'N','Y') as selected - FROM m_papsmearbahan - LEFT JOIN other_papsmearbahan ON Other_PapSmearBahanM_PapSmearBahanID = M_PapSmearBahanID AND - Other_PapSmearBahanOther_PapSmearID = {$header_id} AND - Other_PapSmearBahanIsActive = 'Y' - WHERE - M_PapSmearBahanIsActive = 'Y' - ORDER BY M_PapSmearBahanID ASC - "; - //echo $sql; - $bahans = $this->db_smartone->query($sql)->result_array(); - - $sql = "SELECT IFNULL(Other_PapsmearCategoryID,0) as xid, - M_PapSmearCategoryID as category_id, - M_PapSmearCategoryName as name, - IF(ISNULL(Other_PapsmearCategoryID),'N','Y') as selected - FROM m_papsmearcategory - LEFT JOIN other_papsmearcategory ON Other_PapsmearCategoryM_PapSmearCategoryID = M_PapSmearCategoryID AND - Other_PapsmearCategoryOther_PapSmearID = {$header_id} AND - Other_PapsmearCategoryIsActive = 'Y' - WHERE - M_PapSmearCategoryIsActive = 'Y' - ORDER BY M_PapSmearCategoryID ASC - "; - //echo $sql; - $categories = $this->db_smartone->query($sql)->result_array(); - - $sql = "SELECT IFNULL(Other_PapSmearCheckID,0) as xid, - M_PapSmearCheckID as check_id, - M_PapSmearCheckLabel as name, - IF(ISNULL(Other_PapSmearCheckID),'N','Y') as selected, - Other_PapSmearCheckNote as note - FROM m_papsmearcheck - LEFT JOIN other_papsmearcheck ON Other_PapSmearCheckM_PapSmearCheckID = M_PapSmearCheckID AND - Other_PapSmearCheckOther_PapSmearID = {$header_id} AND - Other_PapSmearCheckIsActive = 'Y' - WHERE - M_PapSmearCheckIsActive = 'Y' - ORDER BY M_PapSmearCheckCode ASC - "; - $checks = $this->db_smartone->query($sql)->result_array(); - - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $rst = array('doctors' => $doctors, 'checks' => $checks, 'bahans' => $bahans, 'categories' => $categories, 'maturasi' => $maturasi, 'results' => $rows); - $this->sys_ok(["records" => $rst]); - } - - function saveresult_lcprep() - { - $prm = $this->sys_input; - $detail_id = $prm['detail_id']; - $doctor_id = $prm['doctor']; - $adekuasi = $prm['adekuasi']; - $kategoriumum = $prm['kategoriumum']; - $interpretasi = $prm['interpretasi']; - $results = $prm['results']; - - $userid = $this->sys_user['M_UserID']; - - $header_id = 0; - $sql = "SELECT * FROM other_lcprep WHERE Other_LcprepT_orderDetailID = {$detail_id} AND Other_LcprepIsActive = 'Y'"; - $dt_header = $this->db_smartone->query($sql)->row_array(); - if ($dt_header) { - $header_id = $dt_header['Other_LcprepID']; - } - if ($header_id == 0) { - $sql = "INSERT INTO other_lcprep( - Other_LcprepT_orderDetailID, - Other_LcprepM_DoctorID, - Other_LcprepUserID, - Other_LcprepCreated - ) - VALUES( - {$detail_id}, - {$doctor_id}, - {$userid}, - NOW() - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } else { - $sql = "UPDATE other_lcprep SET Other_LcprepM_DoctorID = {$doctor_id}, Other_LcprepUserID = {$userid} WHERE Other_LcprepID = {$header_id}"; - $this->db_smartone->query($sql); - } - - if ($adekuasi) { - foreach ($adekuasi as $k => $v) { - $selected = $v['chex'] ? 'Y' : 'N'; - if (intval($v['xid'] == 0)) { - $sql = "UPDATE other_lcprepadekuasi SET Other_LcprepAdekuasiIsActive = 'N' - WHERE - Other_LcprepAdekuasiOther_LcprepID = {$header_id} AND - Other_LcprepAdekuasiIsActive = 'Y' AND - Other_LcprepAdekuasiLcprep_AdekuasiID = {$v['id']}"; - $this->db_smartone->query($sql); - $sql = "INSERT INTO other_lcprepadekuasi ( - Other_LcprepAdekuasiOther_LcprepID, - Other_LcprepAdekuasiLcprep_AdekuasiID, - Other_LcprepAdekuasiChex, - Other_LcprepAdekuasiUserID, - Other_LcprepAdekuasiCreated - ) - VALUES( - {$header_id}, - {$v['id']}, - '{$selected}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - //echo $sql; - } - if (intval($v['xid'] != 0)) { - - $sql = "UPDATE other_lcprepadekuasi SET - Other_LcprepAdekuasiChex = '{$selected}', - Other_LcprepAdekuasiUserID = {$userid} - WHERE - Other_LcprepAdekuasiID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - - //echo $sql; - } - } - - if ($kategoriumum) { - foreach ($kategoriumum as $k => $v) { - $selected = $v['chex'] ? 'Y' : 'N'; - if (intval($v['xid'] == 0)) { - $sql = "UPDATE other_lcprepkategoriumum SET Other_LcprepKategoriUmumIsActive = 'N' - WHERE - Other_LcprepKategoriUmumOther_LcprepID = {$header_id} AND - Other_LcprepKategoriUmumLcprep_KategoriUmumID = {$v['id']} AND - Other_LcprepKategoriUmumIsActive = 'Y' - "; - $this->db_smartone->query($sql); - $sql = "INSERT INTO other_lcprepkategoriumum ( - Other_LcprepKategoriUmumOther_LcprepID, - Other_LcprepKategoriUmumLcprep_KategoriUmumID, - Other_LcprepKategoriUmumChex, - Other_LcprepKategoriUmumUserID, - Other_LcprepKategoriUmumCreated - ) - VALUES( - {$header_id}, - {$v['id']}, - '{$selected}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if (intval($v['xid'] != 0)) { - $sql = "UPDATE other_lcprepkategoriumum SET - Other_LcprepKategoriUmumChex = '{$selected}', - Other_LcprepKategoriUmumUserID = {$userid} - WHERE - Other_LcprepKategoriUmumID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - - //echo $sql; - } - } - - if ($results) { - foreach ($results as $k => $v) { - if (intval($v['xid'] == 0)) { - $sql = "UPDATE other_lcprepdetails SET Other_LcprepDetailsIsActive = 'N' - WHERE - Other_LcprepDetailsOther_LcprepID = {$header_id} AND - Other_LcprepDetailsCode = '{$v['code']}' AND - Other_LcprepDetailsIsActive = 'Y'"; - $this->db_smartone->query($sql); - $sql = "INSERT INTO other_lcprepdetails ( - Other_LcprepDetailsOther_LcprepID, - Other_LcprepDetailsCode, - Other_LcprepDetailsLabel, - Other_LcprepDetailsResult, - Other_LcprepDetailsUserID, - Other_LcprepDetailsCreated - ) - VALUES( - {$header_id}, - '{$v['code']}', - '{$v['label']}', - '{$v['result']}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if (intval($v['xid'] != 0)) { - $sql = "UPDATE other_lcprepdetails SET - Other_LcprepDetailsCode = '{$v['code']}', - Other_LcprepDetailsLabel = '{$v['label']}', - Other_LcprepDetailsResult = '{$v['result']}', - Other_LcprepDetailsUserID = {$userid} - WHERE - Other_LcprepDetailsID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - //echo $sql; - } - } - - if ($interpretasi) { - foreach ($interpretasi as $k => $v) { - if (count($v['subgroups']) > 0) { - foreach ($v['subgroups'] as $ik => $iv) { - if (count($iv['childs']) > 0) { - foreach ($iv['childs'] as $iik => $iiv) { - if (intval($iiv['xid'] == 0)) { - $chex = $iiv['chex'] ? 'Y' : 'N'; - $sql = "UPDATE other_lcprepinterpretasi SET Other_LcprepInterpretasiIsActive = 'N' - WHERE - Other_LcprepInterpretasiOther_LcprepID = {$header_id} AND - Other_LcprepInterpretasiLcprep_InterpretasiID = '{$iiv['id']}' AND - Other_LcprepInterpretasiIsActive = 'Y'"; - $this->db_smartone->query($sql); - $sql = "INSERT INTO other_lcprepinterpretasi ( - Other_LcprepInterpretasiOther_LcprepID, - Other_LcprepInterpretasiLcprep_InterpretasiID, - Other_LcprepInterpretasiChex, - Other_LcprepInterpretasiValue, - Other_LcprepInterpretasiUserID, - Other_LcprepInterpretasiCreated - ) - VALUES( - {$header_id}, - '{$iiv['id']}', - '{$chex}', - '{$iiv['value']}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - - if (intval($iiv['xid'] != 0)) { - $chex = $iiv['chex'] ? 'Y' : 'N'; - $sql = "UPDATE other_lcprepinterpretasi SET - Other_LcprepInterpretasiChex = '{$chex}', - Other_LcprepInterpretasiValue = '{$iiv['value']}', - Other_LcprepInterpretasiUserID = {$userid} - WHERE - Other_LcprepInterpretasiID = {$iiv['xid']}"; - $this->db_smartone->query($sql); - //echo $sql; - - } - } - } - } - } - //echo $sql; - } - } - - - $result = array("total" => 1, "records" => array(), "sql" => ''); - $this->sys_ok($result); - exit; - } - - function saveresult_papsmear() - { - $prm = $this->sys_input; - $detail_id = $prm['detail_id']; - $doctor_id = $prm['doctor']; - $checks = $prm['checks']; - $maturasi = $prm['maturasi']; - $bahans = $prm['bahans']; - $categories = $prm['categories']; - $results = $prm['results']; - - $userid = $this->sys_user['M_UserID']; - - $header_id = 0; - $sql = "SELECT * FROM other_papsmear WHERE Other_PapSmearT_OrderDetailID = {$detail_id} AND Other_PapSmearIsActive = 'Y'"; - $dt_header = $this->db_smartone->query($sql)->row_array(); - if ($dt_header) { - $header_id = $dt_header['Other_PapSmearID']; - } - if ($header_id == 0) { - $sql = "INSERT INTO other_papsmear( - Other_PapSmearT_OrderDetailID, - Other_PapSmearM_DoctorID, - Other_PapSmearUserID, - Other_PapSmearCreated - ) - VALUES( - {$detail_id}, - {$doctor_id}, - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } else { - $sql = "UPDATE other_papsmear SET Other_PapSmearM_DoctorID = {$doctor_id}, Other_PapSmearUserID = {$userid} WHERE Other_PapSmearID = {$header_id}"; - $this->db_smartone->query($sql); - } - - if ($checks) { - foreach ($checks as $k => $v) { - if (intval($v['xid']) == 0 && $v['selected'] === 'Y') { - $sql = "INSERT INTO other_papsmearcheck ( - Other_PapSmearCheckOther_PapSmearID, - Other_PapSmearCheckM_PapSmearCheckID, - Other_PapSmearCheckNote, - Other_PapSmearCheckUserID, - Other_PapSmearCheckCreated - ) - VALUES( - {$header_id}, - {$v['check_id']}, - '{$v['note']}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if (intval($v['xid']) != 0 && $v['selected'] === 'N') { - $sql = "UPDATE other_papsmearcheck SET - Other_PapSmearCheckIsActive = 'N', - Other_PapSmearCheckUserID = {$userid} - WHERE - Other_PapSmearCheckID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - if (intval($v['xid']) != 0 && $v['selected'] === 'Y') { - $sql = "UPDATE other_papsmearcheck SET - Other_PapSmearCheckNote = '{$v['note']}', - Other_PapSmearCheckUserID = {$userid} - WHERE - Other_PapSmearCheckID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - //echo $sql; - } - } - - if ($maturasi) { - if (intval($maturasi['xid']) == 0) { - $value = join("/", $maturasi['value']); - $sql = "INSERT INTO other_papsmearmaturasi ( - Other_PapSmearMaturasiOther_PapSmearID, - Other_PapSmearMaturasiValue, - Other_PapSmearMaturasiUserID, - Other_PapSmearMaturasiCreated - ) - VALUE( - {$header_id}, - '{$value}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - //echo $sql; - } - if (intval($maturasi['xid']) != 0) { - $value = join("/", $maturasi['value']); - $sql = "UPDATE other_papsmearmaturasi SET - Other_PapSmearMaturasiValue = '{$value}', - Other_PapSmearMaturasiUserID = {$userid} - WHERE - Other_PapSmearMaturasiID = {$maturasi['xid']}"; - // echo $sql; - $this->db_smartone->query($sql); - } - } - - if ($bahans) { - foreach ($bahans as $k => $v) { - if (intval($v['xid']) == 0 && $v['selected'] === 'Y') { - $sql = "INSERT INTO other_papsmearbahan ( - Other_PapSmearBahanOther_PapSmearID, - Other_PapSmearBahanM_PapSmearBahanID, - Other_PapSmearBahanUserID, - Other_PapSmearBahanCreated - ) - VALUES( - {$header_id}, - {$v['bahan_id']}, - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if (intval($v['xid']) != 0 && $v['selected'] === 'N') { - $sql = "UPDATE other_papsmearbahan SET - Other_PapSmearBahanIsActive = 'N', - Other_PapsmearCategoryUserID = {$userid} - WHERE - Other_PapSmearBahanID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - if (intval($v['xid']) != 0 && $v['selected'] === 'Y') { - $sql = "UPDATE other_papsmearbahan SET - Other_PapSmearBahanIsActive = 'Y', - Other_PapsmearCategoryUserID = {$userid} - WHERE - Other_PapSmearBahanID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - //echo $sql; - } - } - - if ($categories) { - foreach ($categories as $k => $v) { - if (intval($v['xid']) == 0 && $v['selected'] === 'Y') { - $sql = "INSERT INTO other_papsmearcategory ( - Other_PapsmearCategoryOther_PapSmearID, - Other_PapsmearCategoryM_PapSmearCategoryID, - Other_PapsmearCategoryUserID, - Other_PapsmearCategoryCreated - ) - VALUES( - {$header_id}, - {$v['category_id']}, - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if (intval($v['xid']) != 0 && $v['selected'] === 'N') { - $sql = "UPDATE other_papsmearcategory SET - Other_PapsmearCategoryIsActive = 'N', - Other_PapsmearCategoryUserID = {$userid} - WHERE - Other_PapsmearCategoryID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - //echo $sql; - if (intval($v['xid']) != 0 && $v['selected'] === 'Y') { - $sql = "UPDATE other_papsmearcategory SET - Other_PapsmearCategoryIsActive = 'Y', - Other_PapsmearCategoryUserID = {$userid} - WHERE - Other_PapsmearCategoryID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - } - } - - if ($results) { - foreach ($results as $k => $v) { - if (intval($v['xid']) == 0) { - $sql = "INSERT INTO other_papsmeardetails ( - Other_PapSmearDetailsOther_PapSmearID, - Other_PapSmearDetailsCode, - Other_PapSmearDetailsLabel, - Other_PapSmearDetailsResult, - Other_PapSmearDetailsUserID, - Other_PapSmearDetailsCreated - ) - VALUES( - {$header_id}, - '{$v['code']}', - '{$v['label']}', - '{$v['result']}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if (intval($v['xid']) != 0) { - $sql = "UPDATE other_papsmeardetails SET - Other_PapSmearDetailsCode = '{$v['code']}', - Other_PapSmearDetailsLabel = '{$v['label']}', - Other_PapSmearDetailsResult = '{$v['result']}', - Other_PapSmearDetailsUserID = {$userid} - WHERE - Other_PapSmearDetailsID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - //echo $sql; - } - } - - $result = array("total" => 1, "records" => array(), "sql" => ''); - $this->sys_ok($result); - exit; - } - - function saveresult_fna() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = $inp['doctor']; - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - if ($prm[0]['xid'] == '0') { - $sql = "INSERT INTO other_fna( - Other_FNAM_DoctorID, - Other_FNAT_OrderDetailID, - Other_FNAUserID, - Other_FNACreated - ) - VALUES( - {$doctor_id}, - {$prm[0]['orderdetail_id']}, - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } else { - $sql = "SELECT * FROM other_fna WHERE Other_FNAT_OrderDetailID = {$prm[0]['orderdetail_id']} AND Other_FNAIsActive = 'Y'"; - $data_header = $this->db_smartone->query($sql)->row_array(); - $header_id = $data_header['Other_FNAID']; - $sql = "UPDATE other_fna SET - Other_FNAM_DoctorID = {$doctor_id}, - Other_FNAUserID = {$userid} - WHERE - Other_FNAID = {$header_id}"; - $this->db_smartone->query($sql); - } - foreach ($prm as $k => $v) { - if ($v['xid'] == '0') { - $results = str_replace("'", "\\'", $v['result']); - $sql = "INSERT INTO other_fnadetails( - Other_FNADetailsOther_FNAID , - Other_FNADetailsCode, - Other_FNADetailsLabel, - Other_FNADetailsResult, - Other_FNADetailsCreated, - Other_FNADetailsUserID - ) - VALUES( - {$header_id}, - '{$v['code']}', - '{$v['label']}', - '{$results}', - NOW(), - {$userid} - )"; - $query = $this->db_smartone->query($sql); - } else { - $results = str_replace("'", "\\'", $v['result']); - $sql = "UPDATE other_fnadetails SET - Other_FNADetailsResult = '{$results}', - Other_FNADetailsUserID = {$userid} - WHERE - Other_FNADetailsID = {$v['xid']}"; - $query = $this->db_smartone->query($sql); - } - } - - $result = array("total" => 1, "records" => array(), "sql" => ''); - $this->sys_ok($result); - exit; - } - - function saveresult_cytologi() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = $inp['doctor']; - - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - if ($prm[0]['xid'] == '0') { - $sql = "INSERT INTO other_cytologi( - Other_CytologiT_OrderDetailID, - Other_CytologiM_DoctorID, - Other_CytologiUserID, - Other_CytologiCreated - ) - VALUES( - {$prm[0]['orderdetail_id']}, - {$doctor_id}, - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } else { - $sql = "SELECT * FROM other_cytologi WHERE Other_CytologiT_OrderDetailID = {$prm[0]['orderdetail_id']} AND Other_CytologiIsActive = 'Y'"; - $data_header = $this->db_smartone->query($sql)->row_array(); - $header_id = $data_header['Other_CytologiID']; - $sql = "UPDATE other_cytologi SET - Other_CytologiM_DoctorID = {$doctor_id}, - Other_CytologiUserID = {$userid} - WHERE - Other_CytologiID = {$header_id}"; - $this->db_smartone->query($sql); - } - foreach ($prm as $k => $v) { - if ($v['xid'] == '0') { - $results = str_replace("'", "\\'", $v['result']); - $sql = "INSERT INTO other_cytologidetails( - Other_CytologiDetailsOther_CytologiID , - Other_CytologiDetailsCode, - Other_CytologiDetailsLabel, - Other_CytologiDetailsResult, - Other_CytologiDetailsCreated, - Other_CytologiDetailsUserID - ) - VALUES( - {$header_id}, - '{$v['code']}', - '{$v['label']}', - '{$results}', - NOW(), - {$userid} - )"; - $query = $this->db_smartone->query($sql); - } else { - $results = str_replace("'", "\\'", $v['result']); - $sql = "UPDATE other_cytologidetails SET - Other_CytologiDetailsResult = '{$results}', - Other_CytologiDetailsUserID = {$userid} - WHERE - Other_CytologiDetailsID = {$v['xid']}"; - $query = $this->db_smartone->query($sql); - } - } - - $result = array("total" => 1, "records" => array(), "sql" => ''); - $this->sys_ok($result); - exit; - } - - function saveresult_mikro() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = $inp['doctor']; - $backteria_id = $inp['bacteria']; - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - - if ($inp['result_value'] != 'Negatif' && $inp['result_value'] != 'Positif') { - $prm['result_value'] = $prm['result_other']; - } else { - $prm['result_value'] = $inp['result_value']; - } - - if ($prm['xid'] == '0') { - $sql = "INSERT INTO other_mikro( - Other_MikroM_DoctorID, - Other_MikroResult, - Other_MikroT_BacteriaID, - Other_MikroT_OrderDetailID, - Other_MikroHasilBiakan, - Other_MikroSampleTypeName, - Other_MikroUserID, - Other_MikroCreated - ) - VALUES( - {$doctor_id}, - '{$prm['result_value']}', - {$backteria_id}, - {$prm['orderdetail_id']}, - '{$prm['hasil_biakan']}', - '{$prm['sample_name']}', - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } else { - $sql = "SELECT * FROM other_mikro WHERE Other_MikroT_OrderDetailID = {$prm['orderdetail_id']} AND Other_MikroIsActive = 'Y'"; - $data_header = $this->db_smartone->query($sql)->row_array(); - $header_id = $data_header['Other_MikroID']; - $sql = "UPDATE other_mikro SET - Other_MikroResult = '{$prm['result_value']}', - Other_MikroM_DoctorID = {$doctor_id}, - Other_MikroT_BacteriaID = {$backteria_id}, - Other_MikroHasilBiakan = '{$prm['hasil_biakan']}', - Other_MikroSampleTypeName = '{$prm['sample_name']}', - Other_MikroUserID = {$userid} - WHERE - Other_MikroID = {$header_id}"; - //echo $sql; - $this->db_smartone->query($sql); - } - - - - $sql = "UPDATE other_mikrodetails SET Other_MikroDetailsIsActive = 'N', Other_MikroDetailsUserID = 0 WHERE Other_MikroDetailsOther_MikroID = {$header_id}"; - $this->db_smartone->query($sql); - - $results = $prm['details']; - if ($inp['result_value'] == 'Positif') { - foreach ($results as $k => $v) { - if ($v['xid'] == '0') { - $sql = "INSERT INTO other_mikrodetails( - Other_MikroDetailsOther_MikroID , - Other_MikroDetailsT_AntibioticID, - Other_MikroDetailsValue, - Other_MikroDetailsNote, - Other_MikroDetailsCreated, - Other_MikroDetailsUserID - ) - VALUES( - {$header_id}, - '{$v['T_AntibioticID']}', - '{$v['value']}', - '{$v['note']}', - NOW(), - {$userid} - )"; - $query = $this->db_smartone->query($sql); - } else { - $sql = "UPDATE other_mikrodetails SET - Other_MikroDetailsT_AntibioticID = '{$v['T_AntibioticID']}', - Other_MikroDetailsValue = '{$v['value']}', - Other_MikroDetailsNote = '{$v['note']}', - Other_MikroDetailsIsActive = 'Y', - Other_MikroDetailsUserID = {$userid} - WHERE - Other_MikroDetailsID = {$v['xid']}"; - //echo $sql; - $query = $this->db_smartone->query($sql); - } - } - } - - - $result = array("total" => 1, "records" => array(), "sql" => ''); - $this->sys_ok($result); - exit; - } - - - function get_doctors_preparasi_sperma() - { - $prm = $this->sys_input; - // $id = $prm["id"]; - - $sql = " SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 10 AND - M_DoctorSOIsActive = 'Y' - ORDER BY M_DoctorName ASC"; - //echo $sql; - $query = $this->db_smartone->query($sql); - $rows = $query->result_array(); - $sql = " - SELECT '0' as id, 'Belum memilih metode' as name - UNION - SELECT M_MethodeSpermaID as id, M_MethodeSpermaName as name - FROM m_methodesperma - WHERE - M_MethodeSpermaIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $methodes = $this->db_smartone->query($sql)->result_array(); - - - $this->sys_ok(["records" => $rows, "methodes" => $methodes]); - } - - - function getpreparasispermaresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT other_preparasisperma.*, - Other_PreparasiSpermaID as xid, - Other_PreparasiSpermaT_OrderDetailID as orderdetail_id, - IFNULL(Other_PreparasiSpermaM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_PreparasiSpermaM_DoctorID) OR Other_PreparasiSpermaM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name, - IFNULL(M_MethodeSpermaID,0) as methode_id, - IFNULL(M_MethodeSpermaName,'') as methode_name - FROM other_preparasisperma - LEFT JOIN m_doctor ON Other_PreparasiSpermaM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - LEFT JOIN m_methodesperma ON Other_PreparasiSpermaM_MethodeSpermaID = M_MethodeSpermaID AND - M_MethodeSpermaIsActive = 'Y' - WHERE - Other_PreparasiSpermaT_OrderDetailID = {$id} AND Other_PreparasiSpermaIsActive = 'Y' - GROUP BY Other_PreparasiSpermaID"; - $query = $this->db_smartone->query($sql); - - if ($query) { - $rows = $query->row_array(); - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 10 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $sql = " - SELECT '0' as id, 'Belum memilih metode' as name - UNION - SELECT M_MethodeSpermaID as id, M_MethodeSpermaName as name - FROM m_methodesperma - WHERE - M_MethodeSpermaIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $methodes = $this->db_smartone->query($sql)->result_array(); - $images = array(); - $sql = "SELECT Other_PreparasiSpermaImgID as xid, - Other_PreparasiSpermaImgType as type, - CONCAT('/one-media/one-image-nonlab/',Other_PreparasiSpermaImgNewName) as image_url - FROM t_orderdetail - JOIN other_preparasisperma_img ON Other_PreparasiSpermaImgT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND - Other_PreparasiSpermaImgIsActive = 'Y' - WHERE - T_OrderDetailID = {$id} AND - T_OrderDetailIsActive = 'Y' - GROUP BY Other_PreparasiSpermaImgID"; - //echo $sql; - $images = $this->db_smartone->query($sql)->result_array(); - - $rst = array('doctors' => $doctors, 'methodes' => $methodes, 'results' => $rows, 'images' => $images); - $this->sys_ok(["records" => $rst]); - } else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - - function uploadimage_preparasi_sperma() - { - if (! $this->isLogin) { - $this->sys_error("Invalid Token"); - exit; - } - - $userid = $this->sys_user["M_UserID"]; - $data = []; - //print_r($_SERVER); - - $prm = $this->sys_input; - $orderid = $this->input->post('orderid'); - $type = $this->input->post('type'); - $labnumber = $this->input->post('labnumber'); - $sql = "UPDATE other_preparasisperma_img SET - Other_PreparasiSpermaImgIsActive = 'N', - Other_PreparasiSpermaImgUserID = {$userid} - WHERE - Other_PreparasiSpermaImgT_OrderHeaderID = {$orderid} AND - Other_PreparasiSpermaImgType = '{$type}'"; - //echo $sql; - $this->db_onedev->query($sql); - //$config['upload_path'] = 'assets/'; - - $path = '/home/one/project/one/one-media/one-image-nonlab/'; - //echo $path; - $config['upload_path'] = $path; - $config['allowed_types'] = 'jpg|jpeg|png|gif'; - - $config['max_size'] = '10000'; - $count = count($_FILES['files']['name']); - //echo $count; - $this->load->library('upload', $config); - - $error = []; - for ($i = 0; $i < $count; $i++) { - - - if (!empty($_FILES['files']['name'][$i])) { - - - - $_FILES['file']['name'] = $_FILES['files']['name'][$i]; - - $_FILES['file']['type'] = $_FILES['files']['type'][$i]; - - $_FILES['file']['tmp_name'] = $_FILES['files']['tmp_name'][$i]; - - $_FILES['file']['error'] = $_FILES['files']['error'][$i]; - - $_FILES['file']['size'] = $_FILES['files']['size'][$i]; - - - - $namex = $orderid . '-' . $labnumber . '-' . $this->generateRandomString(5); - //echo $namex; - - $config['file_name'] = $namex; - $this->upload->initialize($config); - //echo $config['file_name'] ; - - - - - - if ($this->upload->do_upload('file')) { - - $uploadData = $this->upload->data(); - - $filename = $uploadData['file_name']; - //echo $filename; - - - $sql = "INSERT INTO other_preparasisperma_img ( - Other_PreparasiSpermaImgT_OrderHeaderID, - Other_PreparasiSpermaImgType, - Other_PreparasiSpermaImgOldName, - Other_PreparasiSpermaImgNewName, - Other_PreparasiSpermaImgCreated, - Other_PreparasiSpermaImgUserID - ) - VALUES( - {$orderid}, - '{$type}', - '{$_FILES['files']['name'][$i]}', - '{$filename}', - NOW(), - {$userid} - - )"; - //echo $sql; - $this->db_onedev->query($sql); - $xlast_id = $this->db_onedev->insert_id(); - $data['totalFiles'][] = array('xid' => $xlast_id, 'type' => $type, 'image_url' => '/one-media/one-image-nonlab/' . $filename); - } else { - $error = array('error' => $this->upload->display_errors()); - } - } - } - - $result = array("total" => count($data['totalFiles']), "records" => $data['totalFiles'], 'errors' => $error); - $this->sys_ok($result); - } - - - function saveresult_preparasi_sperma() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = $inp['doctor']; - $orderdetail_id = $inp['orderdetailid']; - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - if ($prm['xid'] == '0') { - $sql = "INSERT INTO other_preparasisperma( - Other_PreparasiSpermaM_DoctorID, - Other_PreparasiSpermaT_OrderDetailID, - Other_PreparasiSpermaPreMotilitasA, - Other_PreparasiSpermaPreMotilitasB, - Other_PreparasiSpermaPreMotilitasC, - Other_PreparasiSpermaPreKonsentrasi, - Other_PreparasiSpermaPreKontaminan, - Other_PreparasiSpermaPostMotilitasA, - Other_PreparasiSpermaPostMotilitasB, - Other_PreparasiSpermaPostMotilitasC, - Other_PreparasiSpermaPostKonsentrasi, - Other_PreparasiSpermaPostKontaminan, - Other_PreparasiSpermaPreVolume, - Other_PreparasiSpermaPostVolume, - Other_PreparasiSpermaM_MethodeSpermaID, - Other_PreparasiSpermaNote, - Other_PreparasiSpermaUserID, - Other_PreparasiSpermaCreated - ) - VALUES( - {$doctor_id}, - {$orderdetail_id}, - '{$prm['Other_PreparasiSpermaPreMotilitasA']}', - '{$prm['Other_PreparasiSpermaPreMotilitasB']}', - '{$prm['Other_PreparasiSpermaPreMotilitasC']}', - '{$prm['Other_PreparasiSpermaPreKonsentrasi']}', - '{$prm['Other_PreparasiSpermaPreKontaminan']}', - '{$prm['Other_PreparasiSpermaPostMotilitasA']}', - '{$prm['Other_PreparasiSpermaPostMotilitasB']}', - '{$prm['Other_PreparasiSpermaPostMotilitasC']}', - '{$prm['Other_PreparasiSpermaPostKonsentrasi']}', - '{$prm['Other_PreparasiSpermaPostKontaminan']}', - '{$prm['Other_PreparasiSpermaPreVolume']}', - '{$prm['Other_PreparasiSpermaPostVolume']}', - '{$prm['Other_PreparasiSpermaM_MethodeSpermaID']}', - '{$prm['Other_PreparasiSpermaNote']}', - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } else { - $sql = "SELECT * FROM other_preparasisperma WHERE Other_PreparasiSpermaT_OrderDetailID = {$orderdetail_id} AND Other_PreparasiSpermaIsActive = 'Y'"; - $data_header = $this->db_smartone->query($sql)->row_array(); - $header_id = $data_header['Other_PreparasiSpermaID']; - $sql = "UPDATE other_preparasisperma SET - Other_PreparasiSpermaM_DoctorID = {$doctor_id}, - Other_PreparasiSpermaPreMotilitasA = '{$prm['Other_PreparasiSpermaPreMotilitasA']}', - Other_PreparasiSpermaPreMotilitasB = '{$prm['Other_PreparasiSpermaPreMotilitasB']}', - Other_PreparasiSpermaPreMotilitasC = '{$prm['Other_PreparasiSpermaPreMotilitasC']}', - Other_PreparasiSpermaPreKonsentrasi = '{$prm['Other_PreparasiSpermaPreKonsentrasi']}', - Other_PreparasiSpermaPreKontaminan = '{$prm['Other_PreparasiSpermaPreKontaminan']}', - Other_PreparasiSpermaPostMotilitasA = '{$prm['Other_PreparasiSpermaPostMotilitasA']}', - Other_PreparasiSpermaPostMotilitasB = '{$prm['Other_PreparasiSpermaPostMotilitasB']}', - Other_PreparasiSpermaPostMotilitasC = '{$prm['Other_PreparasiSpermaPostMotilitasC']}', - Other_PreparasiSpermaPostKonsentrasi = '{$prm['Other_PreparasiSpermaPostKonsentrasi']}', - Other_PreparasiSpermaPostKontaminan = '{$prm['Other_PreparasiSpermaPostKontaminan']}', - Other_PreparasiSpermaPreVolume = '{$prm['Other_PreparasiSpermaPreVolume']}', - Other_PreparasiSpermaPostVolume = '{$prm['Other_PreparasiSpermaPostVolume']}', - Other_PreparasiSpermaM_MethodeSpermaID = '{$prm['Other_PreparasiSpermaM_MethodeSpermaID']}', - Other_PreparasiSpermaNote = '{$prm['Other_PreparasiSpermaNote']}', - Other_PreparasiSpermaUserID = {$userid} - WHERE - Other_PreparasiSpermaID = {$header_id}"; - $this->db_smartone->query($sql); - } - - - $result = array("total" => 1, "records" => array(), "sql" => ''); - $this->sys_ok($result); - exit; - } - - function getdnafragmentasiresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT other_dnafragmentasi.*, - Other_DnaFragmentasiID as xid, - Other_DnaFragmentasiT_OrderDetailID as orderdetail_id, - IFNULL(Other_DnaFragmentasiM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_DnaFragmentasiM_DoctorID) OR Other_DnaFragmentasiM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name, - IFNULL(Other_DnaFragmentasiOther_DnaFragmentasiMethodeID,0) as methode_id, - IFNULL(Other_DnaFragmentasiMethodeName,'') as methode_name, - Other_DnaFragmentasiHaloLuas as halo_luas, - Other_DnaFragmentasiHaloSedang as halo_sedang, - Other_DnaFragmentasiHaloSempit as halo_sempit, - Other_DnaFragmentasiTanpaHalo as tanpa_halo, - Other_DnaFragmentasiDFI as dfi, - Other_DnaFragmentasiKesimpulan as kesimpulan, - Other_DnaFragmentasiCatatan as catatan - FROM other_dnafragmentasi - LEFT JOIN m_doctor ON Other_DnaFragmentasiM_DoctorID = M_DoctorID - LEFT JOIN other_dnafragmentasimethode ON Other_DnaFragmentasiOther_DnaFragmentasiMethodeID = Other_DnaFragmentasiMethodeID - WHERE - Other_DnaFragmentasiT_OrderDetailID = {$id} AND Other_DnaFragmentasiIsActive = 'Y' - GROUP BY Other_DnaFragmentasiID - LIMIT 1"; - //echo $sql; - $query = $this->db_smartone->query($sql); - - if ($query) { - $rows = $query->row_array(); - if (!$rows) { - $rows = array( - 'xid' => 0, - 'orderdetail_id' => $id, - 'doctor_id' => 0, - 'doctor_name' => '', - 'methode_id' => 0, - 'methode_name' => '', - 'halo_luas' => '', - 'halo_sedang' => '', - 'tanpa_halo' => '', - 'dfi' => '', - 'kesimpulan' => '', - 'catatan' => '' - ); - } - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID - WHERE - M_DoctorSONat_SubGroupID = 4 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - - $sql = " - SELECT '0' as id, 'Belum memilih metode' as name - UNION - SELECT Other_DnaFragmentasiMethodeID as id, Other_DnaFragmentasiMethodeName as name - FROM other_dnafragmentasimethode - WHERE - Other_DnaFragmentasiMethodeIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $methodes = $this->db_smartone->query($sql)->result_array(); - - - $rst = array('doctors' => $doctors, 'methodes' => $methodes, 'results' => $rows); - $this->sys_ok(["records" => $rst]); - } else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - function saveresult_dnafragmentasi() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = $inp['doctor']['id']; - $methode_id = $inp['methode']['id']; - $orderdetail_id = $inp['results']['orderdetail_id']; - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - if (intval($prm['xid']) == 0) { - $sql = "INSERT INTO other_dnafragmentasi( - Other_DnaFragmentasiT_OrderDetailID, - Other_DnaFragmentasiM_DoctorID, - Other_DnaFragmentasiOther_DnaFragmentasiMethodeID, - Other_DnaFragmentasiHaloLuas, - Other_DnaFragmentasiHaloSedang, - Other_DnaFragmentasiHaloSempit, - Other_DnaFragmentasiTanpaHalo, - Other_DnaFragmentasiDFI, - Other_DnaFragmentasiKesimpulan, - Other_DnaFragmentasiCatatan, - Other_DnaFragmentasiUserID, - Other_DnaFragmentasiLastUpdated - ) - VALUES( - {$orderdetail_id}, - {$doctor_id}, - {$methode_id}, - '{$prm['halo_luas']}', - '{$prm['halo_sedang']}', - '{$prm['halo_sempit']}', - '{$prm['tanpa_halo']}', - '{$prm['dfi']}', - '{$prm['kesimpulan']}', - '{$prm['catatan']}', - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } else { - $sql = "UPDATE other_dnafragmentasi SET - Other_DnaFragmentasiT_OrderDetailID = {$orderdetail_id}, - Other_DnaFragmentasiM_DoctorID = {$doctor_id}, - Other_DnaFragmentasiOther_DnaFragmentasiMethodeID = '{$methode_id}', - Other_DnaFragmentasiHaloLuas = '{$prm['halo_luas']}', - Other_DnaFragmentasiHaloSedang = '{$prm['halo_sedang']}', - Other_DnaFragmentasiHaloSempit = '{$prm['halo_sempit']}', - Other_DnaFragmentasiTanpaHalo = '{$prm['tanpa_halo']}', - Other_DnaFragmentasiDFI = '{$prm['dfi']}', - Other_DnaFragmentasiKesimpulan = '{$prm['kesimpulan']}', - Other_DnaFragmentasiCatatan = '{$prm['catatan']}', - Other_DnaFragmentasiLastUpdated = NOW(), - Other_DnaFragmentasiUserID = {$userid} - WHERE - Other_DnaFragmentasiID = {$prm['xid']}"; - //echo $sql; - $this->db_smartone->query($sql); - } - - - $result = array("total" => 1, "records" => array(), "sql" => ''); - $this->sys_ok($result); - exit; - } -} +db_smartone = $this->load->database("onedev", true); + $this->load->helper(array('form', 'url')); + } + function getMethodeID($natTestID) + { + $sql = "select M_MethodePriorityNat_MethodeID MethodeID, Nat_MethodeName + from + m_methode_priority + join nat_methode on Nat_MethodeID = M_MethodePriorityNat_MethodeID + and Nat_MethodeIsActive = 'Y' + join m_instrumentmethode on M_InstrumentMethodeNat_MethodeID = Nat_MethodeID and M_InstrumentMethodeIsActive = 'Y' + join nat_instrument on M_InstrumentMethodeNat_InstrumentID = Nat_InstrumentID + and Nat_InstrumentIsActive ='Y' + where M_MethodePriorityIsActive = 'Y' + and M_MethodePriorityNat_TestID = $natTestID + and M_MethodePriorityM_DayOfWeekID = dayofweek(now()) + order by M_MethodePriorityNumber desc + limit 0,1 "; + $qry = $this->db->query($sql); + if ($qry) { + $rows = $qry->result_array(); + if (count($rows) > 0) return array($rows[0]["MethodeID"], $rows[0]["Nat_MethodeName"]); + } + //2nd + $sql = "select + M_InstrumentMethodeNat_MethodeID MethodeID, Nat_MethodeName + from m_instrumentmethode + join nat_methode on M_InstrumentMethodeNat_MethodeID = Nat_MethodeID + and Nat_MethodeIsActive = 'Y' + join nat_instrument on M_InstrumentMethodeNat_InstrumentID = Nat_InstrumentID + and Nat_InstrumentIsActive ='Y' + where M_InstrumentMethodeNat_TestID = $natTestID + and M_InstrumentMethodeIsActive = 'Y' + order by M_InstrumentMethodePriority desc + limit 0,1"; + $qry = $this->db->query($sql); + if ($qry) { + $rows = $qry->result_array(); + if (count($rows) > 0) return array($rows[0]["MethodeID"], $rows[0]["Nat_MethodeName"]); + } + // + $sql = "select Nat_NormalValueNat_MethodeID MethodeID, Nat_MethodeName + from + nat_normalvalue + join nat_methode on Nat_NormalValueNat_MethodeID = Nat_MethodeID + and Nat_MethodeIsActive = 'Y' + where Nat_NormalValueNat_TestID = $natTestID + and Nat_NormalValueIsActive = 'Y' + order by Nat_NormalValueID + limit 0,1"; + $qry = $this->db->query($sql); + if ($qry) { + $rows = $qry->result_array(); + if (count($rows) > 0) return array($rows[0]["MethodeID"], $rows[0]["Nat_MethodeName"]); + } + return array(0, ""); + } + function get_normal_value($methodeID, $natTestID, $sexID, $ageInDay) + { + $this->load->library('ibl_sampling_normal'); + return $this->ibl_sampling_normal->get_normal_value_id($methodeID, $natTestID, $sexID, $ageInDay); + } + return 0; + } + function fn_fix_normal($order_id) + { + $sql = "select + T_OrderDetailID, M_PatientM_SexID, fn_global_age_count_day(M_PatientDOB, date(T_OrderHeaderDate)) Dob , + T_TestNat_TestID + from t_orderheader + join m_patient on T_OrderHeaderID = $order_id and T_OrderHeaderM_PatientID = M_PatientID + join t_orderdetail on T_OrderDetailT_OrderHeaderID = T_OrderHeaderID + and T_OrderDetailIsACtive = 'Y' + and ( T_OrderDetailNat_NormalValueID is null or T_OrderDetailNat_NormalValueID = 0 ) + join t_test on T_OrderDetailT_TestID = T_TestID and T_TestIsResult = 'Y' "; + $qry = $this->db->query($sql); + if (! $qry) { + return; + } + $rows = $qry->result_array(); + if (count($rows) == 0) return; + $sql_u = "update t_orderdetail + join nat_normalvalue on T_OrderDetailID = ? and Nat_NormalValueID = ? + set + T_OrderDetailNat_NormalValueID = Nat_NormalValueID, + T_OrderDetailNormalValueNote = Nat_NormalValueNote, + T_OrderDetailNormalValueDescription = Nat_NormalValueDescription, + T_OrderDetailMinValue = Nat_NormalValueMinValue, + T_OrderDetailMaxValue = Nat_NormalValueMaxValue, + T_OrderDetailMinValueInclusive = Nat_NormalValueMinValueInclusive, + T_OrderDetailMaxValueInclusive = Nat_NormalValueMaxValueInclusive, + T_OrderDetailNat_MethodeID = ?, + T_OrderdetailNat_MethodeName =?"; + + foreach ($rows as $r) { + $T_OrderDetailID = $r["T_OrderDetailID"]; + $sexID = $r["M_PatientM_SexID"]; + $ageInDay = $r["Dob"]; + $natTestID = $r["T_TestNat_TestID"]; + list($methodeID, $methodeName) = $this->getMethodeID($natTestID); + if ($methodeID == 0) continue; + $normalValueID = $this->get_normal_value($methodeID, $natTestID, $sexID, $ageInDay); + if ($normalValueID == 0) return; + $this->db->query($sql_u, array($T_OrderDetailID, $normalValueID, $methodeID, $methodeName)); + } + } + + function update_order_sample($targetID, $sourceID) + { + $sql = "update t_ordersample target + join t_ordersample source on + target.T_OrderSampleID = ? + and target.T_OrderSampleWorklistReceive = 'N' + and source.T_OrderSampleID = ? + set + target.T_OrderSampleSampling = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSampling, source.T_OrderSampleSampling), + target.T_OrderSampleSamplingDate = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingDate, source.T_OrderSampleSamplingDate), + target.T_OrderSampleSamplingTime = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingTime, source.T_OrderSampleSamplingTime), + target.T_OrderSampleSamplingUserID = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingUserID, source.T_OrderSampleSamplingUserID), + + target.T_OrderSampleReceive = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceive, source.T_OrderSampleReceive), + target.T_OrderSampleReceiveDate = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveDate, source.T_OrderSampleReceiveDate), + target.T_OrderSampleReceiveTime = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveTime, source.T_OrderSampleReceiveTime), + target.T_OrderSampleReceiveUserID = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveUserID, source.T_OrderSampleReceiveUserID), + + target.T_OrderSampleVerification = if(target.T_OrderSampleVerification='Y',target.T_OrderSampleVerification, source.T_OrderSampleVerification), + target.T_OrderSampleVerificationDate =if(target.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationDate, source.T_OrderSampleVerificationDate), + target.T_OrderSampleVerificationTime =if(source.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationTime, source.T_OrderSampleVerificationTime), + target.T_OrderSampleVerificationUserID =if(source.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationUserID, source.T_OrderSampleVerificationUserID), + + target.T_OrderSampleProcessing = if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessing, source.T_OrderSampleProcessing), + target.T_OrderSampleProcessingDate= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingDate, source.T_OrderSampleProcessingDate), + target.T_OrderSampleProcessingTime= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingTime, source.T_OrderSampleProcessingTime), + target.T_OrderSampleProcessingUserID= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingUserID, source.T_OrderSampleProcessingUserID), + + target.T_OrderSampleReceiveHandling =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandling, source.T_OrderSampleReceiveHandling ), + target.T_OrderSampleReceiveHandlingDate =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingDate, source.T_OrderSampleReceiveHandlingDate), + target.T_OrderSampleReceiveHandlingTime =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingTime, source.T_OrderSampleReceiveHandlingTime), + target.T_OrderSampleReceiveHandlingUserID =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingUserID, source.T_OrderSampleReceiveHandlingUserID), + + target.T_OrderSampleHandling = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandling, source.T_OrderSampleHandling), + target.T_OrderSampleHandlingDate = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingDate, source.T_OrderSampleHandlingDate), + target.T_OrderSampleHandlingTime = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingTime, source.T_OrderSampleHandlingTime), + target.T_OrderSampleHandlingUserID = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingUserID, source.T_OrderSampleHandlingUserID), + + target.T_OrderSampleWorklistReceive = source.T_OrderSampleWorklistReceive, + target.T_OrderSampleWorklistReceiveDatetime = source.T_OrderSampleWorklistReceiveDateTime, + target.T_OrderSampleWorklistReceiveUserID = source.T_OrderSampleWorklistReceiveUserID + "; + $qry = $this->db->query($sql, array($targetID, $sourceID)); + if (! $qry) { + echo json_encode(array("status" => "ERR", "message" => print_r($this->db->error(), true))); + exit; + } + } + function fix_sample_serum($headerID) + { + //cari t_ordersample yg belum worklist receive dengan code 017% + $sql = "select T_OrderSampleID + from t_ordersample + join t_sampletype on + T_OrderSampleT_OrderHeaderID = ? + and T_OrderSampleWorklistReceive = 'N' + and T_OrderSampleIsActive = 'Y' + and T_OrderSampleT_SampleTypeID = T_SampletypeID + and T_SampleTypeCode like '017%' + "; + $qry = $this->db->query($sql, array($headerID)); + if (!$qry) { + echo json_encode(array("status" => "ERR", "message" => print_r($this->db->error(), true))); + exit; + } + $rows = $qry->result_array(); + if (count($rows) == 0) return; + //cari T_OrderSample yang sudah di receive yg terakhir + $sql = "select T_OrderSampleID + from t_ordersample + join t_sampletype on + T_OrderSampleT_OrderHeaderID = ? + and T_OrderSampleWorklistReceive = 'Y' + and T_OrderSampleIsActive = 'Y' + and T_OrderSampleT_SampleTypeID = T_SampletypeID + and T_SampleTypeCode like '017%' + order by T_OrderSampleWorklistReceiveDatetime desc + limit 0,1 + "; + $qry = $this->db->query($sql, array($headerID)); + if (!$qry) { + echo json_encode(array("status" => "ERR", "message" => print_r($this->db->error(), true))); + exit; + } + $rcv_rows = $qry->result_array(); + if (count($rcv_rows) == 0) return; + + //print_r($rows); + //print_r($rcv_rows); + $rcv_T_OrderSampleID = $rcv_rows[0]["T_OrderSampleID"]; + //ada yg belum di receive + foreach ($rows as $r) { + $T_OrderSampleID = $r["T_OrderSampleID"]; + $this->update_order_sample($T_OrderSampleID, $rcv_T_OrderSampleID); + } + } + public function search() + { + $prm = $this->sys_input; + $max_rst = 99; + + $id = $prm["order_id"]; + if ($id > 0) { + $this->fix_sample_serum($id); + $this->fn_fix_normal($id); + } + $lang = $this->lang_default_code; + $lang_id = isset($prm['lang_id']) ? $prm['lang_id'] : '0'; + + if ($lang_id != 0) { + $l = $this->db_smartone->where("Nat_LangID", $lang_id)->get("nat_lang")->row(); + $lang = $l->Nat_LangCode; + } + + //tambahan fajri + $sql = " UPDATE t_orderdetail + JOIN t_test ON T_OrderDetailT_TestID = T_TestID + SET T_OrderDetailT_TestIsResult = T_TestIsResult + WHERE + T_OrderDetailT_OrderHeaderID = {$id} AND + T_OrderDetailT_TestIsResult = '' AND + T_OrderDetailIsActive = 'Y'"; + $this->db_smartone->query($sql); + + $tot_count = 0; + $lq = ""; + $group_id = 0; + if (isset($prm['group_id'])) + $group_id = $prm['group_id']; + + if ($group_id != 0) { + $sql = "select distinct T_WorklistDetailNat_TestID Nat_TestID + from t_worklistdetailv2 + where T_WorklistDetailT_WorklistID = {$group_id}"; + $qry = $this->db_smartone->query($sql); + $rows = $qry->result_array(); + $nat_test_ids = "0"; + foreach ($rows as $r) { + $nat_test_ids .= ", " . $r["Nat_TestID"]; + } + $q_group = " ( $nat_test_ids ) "; + + $sql = " + SELECT a1.*, cOUNT(a2.T_OrderDetailID) level + FROM ( + SELECT IFNULL(y.T_OrderDetailT_TestID, x.T_OrderDetailT_TestID) t_testid, + IFNULL(y.T_OrderDetailT_TestName, y.T_OrderDetailT_TestName) t_testname, + y.T_OrderDetailResult result, y.T_OrderDetailResult result_old, y.T_OrderDetailNote note, y.T_OrderDetailNote note_old, + y.T_OrderDetailID id, + y.T_OrderDetailT_TestIsResult is_result, a.T_TestIsQuantitative is_quantitative, + y.T_OrderDetailResultFlag result_flag, + y.T_OrderDetailNat_NormalValueID normal_id, + y.T_OrderDetailNormalValueNote normal_note, y.T_OrderDetailNat_UnitName unit_name, + y.T_OrderdetailNat_MethodeID methode_id, y.T_OrderdetailNat_MethodeName methode_name, + a.T_TestNat_TestID nattest_id, a.T_TestID tx_id, count(T_ResultInstrumentID) as result_instrument_n, + y.T_OrderDetailVerification, T_OrderSampleReceive sample_receive, + T_OrderSampleProcessing sample_processing, T_OrderSampleWorklistReceive sample_worklist_receive, + IF(T_OrderDetailAddOnPreAnalytic = 'Y', T_OrderDetailAddOnPreAnalytic, PreAnalyticIsOk) pre_analytic, + T_OrderDetailAddOnPreAnalytic, + T_OrderHeaderID order_id, y.T_OrderDetailT_TestSasCode test_sas_code, + tx.T_TestSasCode, + T_OrderDetailAddOnResample `resample`, T_OrderDetailAddOnResampleStatus resample_status, + T_OrderDetailAddOnRef ref, y.T_OrderDetailVerification verification, y.T_OrderDetailValidation validation, + T_OrderPromiseDateTime, Group_ResultName as ResultGroupName + FROM t_orderdetail x + left join t_orderpromise on x.T_OrderDetailT_OrderPromiseID = T_OrderPromiseID + JOIN t_test tx ON x.T_OrderDetailT_TestID = T_TestID + JOIN t_test tcheck on tcheck.T_TestNat_TestID in {$q_group} + and ( tx.T_TestID = tcheck.T_TestID or tx.T_TestSasCode like concat(tcheck.T_TestSasCode,'%')) + LEFT JOIN group_resultdetail ON Group_ResultDetailT_TestID = x.T_OrderDetailT_TestID AND Group_ResultDetailIsActive = 'Y' + LEFT JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND Group_ResultFlagNonLab = 'N' + LEFT JOIN t_orderdetail y ON x.T_OrderDetailT_TestSasCode LIKE CONCAT(y.T_OrderDetailT_TestSasCode, '%') + AND x.T_OrderDetailT_OrderHeaderID = y.T_OrderDetailT_OrderHeaderID + AND y.T_OrderDetailIsActive = 'Y' + LEFT JOIN t_orderdetailaddon ON x.T_OrderDetailID = T_OrderDetailAddOnT_OrderDetailID + JOIN t_orderheader ON y.T_OrderDetailT_OrderHeaderID = T_OrderHeaderID + LEFT JOIN t_test a ON y.T_OrderDetailT_TestID = a.T_TestID + AND a.T_TestIsNonLab = '' + LEFT JOIN (SELECT T_OrderSampleT_SampleTypeID, T_OrderSampleReceive, T_OrderSampleProcessing, T_OrderSampleWorklistReceive + FROM t_ordersample WHERE T_OrderSampleT_OrderHeaderID = {$id} + AND T_OrderSampleIsactive = 'Y' + GROUP BY T_OrderSampleT_SampleTypeID) os ON a.T_TestT_SampleTypeID = os.T_OrderSampleT_SampleTypeID + or os.T_OrderSampleT_SampleTypeID = fn_sampletype_from_local(a.T_TestNat_TestID) + + LEFT JOIN t_resultinstrument ON T_ResultInstrumentT_OrderDetailID = x.T_OrderDetailID + LEFT JOIN pre_analytic ON PreAnalyticNat_TestID = a.T_TestNat_TestID AND PreAnalyticDate = date(now()) and PreAnalyticIsActive = 'Y' + WHERE x.T_OrderDetailT_OrderHeaderID = {$id} + AND x.T_OrderDetailIsActive = 'Y' + GROUP BY y.T_OrderDetailT_TestID + ORDER BY y.T_OrderDetailT_TestSasCode ASC + ) a1 + + LEFT JOIN t_orderdetail a2 ON a2.T_OrderDetailT_OrderHeaderID = a1.order_id + AND a2.T_OrderDetailIsActive = 'Y' + AND a1.test_sas_code LIKE CONCAT(a2.T_OrderDetailT_testSasCode, '%') + GROUP BY a1.t_testid + order by a1.test_sas_code +"; + $query = $this->db_smartone->query($sql); + $lq = $this->db_smartone->last_query(); + } else { + $sql = " + SELECT a1.*, cOUNT(a2.T_OrderDetailID) level + FROM ( + SELECT IFNULL(y.T_OrderDetailT_TestID, x.T_OrderDetailT_TestID) t_testid, + IFNULL(y.T_OrderDetailT_TestName, y.T_OrderDetailT_TestName) t_testname, + y.T_OrderDetailResult result, y.T_OrderDetailResult result_old, y.T_OrderDetailNote note, y.T_OrderDetailNote note_old, + y.T_OrderDetailID id, + y.T_OrderDetailT_TestIsResult is_result, a.T_TestIsQuantitative is_quantitative, + y.T_OrderDetailResultFlag result_flag, + y.T_OrderDetailNat_NormalValueID normal_id, + y.T_OrderDetailNormalValueNote normal_note, y.T_OrderDetailNat_UnitName unit_name, + y.T_OrderdetailNat_MethodeID methode_id, y.T_OrderdetailNat_MethodeName methode_name, + a.T_TestNat_TestID nattest_id, a.T_TestID tx_id, count(T_ResultInstrumentID) as result_instrument_n, + y.T_OrderDetailVerification, T_OrderSampleReceive sample_receive, + T_OrderSampleProcessing sample_processing, T_OrderSampleWorklistReceive sample_worklist_receive, + IF(T_OrderDetailAddOnPreAnalytic = 'Y', T_OrderDetailAddOnPreAnalytic, PreAnalyticIsOk) pre_analytic, + T_OrderDetailAddOnPreAnalytic, + T_OrderHeaderID order_id, y.T_OrderDetailT_TestSasCode test_sas_code, + tx.T_TestSasCode, + T_OrderDetailAddOnResample `resample`, T_OrderDetailAddOnResampleStatus resample_status, + T_OrderDetailAddOnRef ref, y.T_OrderDetailVerification verification, y.T_OrderDetailValidation validation, + T_OrderPromiseDateTime , Group_ResultName as ResultGroupName + FROM t_orderdetail x + left join t_orderpromise on x.T_OrderDetailT_OrderPromiseID = T_OrderPromiseID + JOIN t_test tx ON x.T_OrderDetailT_TestID = T_TestID + LEFT JOIN group_resultdetail ON Group_ResultDetailT_TestID = x.T_OrderDetailT_TestID AND Group_ResultDetailIsActive = 'Y' + LEFT JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND Group_ResultFlagNonLab = 'N' + LEFT JOIN t_orderdetail y ON x.T_OrderDetailT_TestSasCode LIKE CONCAT(y.T_OrderDetailT_TestSasCode, '%') + AND x.T_OrderDetailT_OrderHeaderID = y.T_OrderDetailT_OrderHeaderID + AND y.T_OrderDetailIsActive = 'Y' + + LEFT JOIN t_orderdetailaddon ON x.T_OrderDetailID = T_OrderDetailAddOnT_OrderDetailID + + JOIN t_orderheader ON y.T_OrderDetailT_OrderHeaderID = T_OrderHeaderID + LEFT JOIN t_test a ON y.T_OrderDetailT_TestID = a.T_TestID + AND a.T_TestIsNonLab = '' + LEFT JOIN (SELECT T_OrderSampleT_SampleTypeID, T_OrderSampleReceive, T_OrderSampleProcessing, T_OrderSampleWorklistReceive + FROM t_ordersample WHERE T_OrderSampleT_OrderHeaderID = {$id} + AND T_OrderSampleIsactive = 'Y' + GROUP BY T_OrderSampleT_SampleTypeID) os ON a.T_TestT_SampleTypeID = os.T_OrderSampleT_SampleTypeID + or os.T_OrderSampleT_SampleTypeID = fn_sampletype_from_local(a.T_TestNat_TestID) + + LEFT JOIN t_resultinstrument ON T_ResultInstrumentT_OrderDetailID = x.T_OrderDetailID + LEFT JOIN pre_analytic ON PreAnalyticNat_TestID = a.T_TestNat_TestID AND PreAnalyticDate = date(now()) and PreAnalyticIsActive = 'Y' + WHERE x.T_OrderDetailT_OrderHeaderID = {$id} + AND x.T_OrderDetailIsActive = 'Y' + GROUP BY y.T_OrderDetailT_TestID + ORDER BY y.T_OrderDetailT_TestSasCode ASC + ) a1 + + LEFT JOIN t_orderdetail a2 ON a2.T_OrderDetailT_OrderHeaderID = a1.order_id + AND a2.T_OrderDetailIsActive = 'Y' + AND a1.test_sas_code LIKE CONCAT(a2.T_OrderDetailT_testSasCode, '%') + GROUP BY a1.t_testid + order by a1.test_sas_code +"; + //echo $sql; + $query = $this->db_smartone->query($sql); + $lq = $this->db_smartone->last_query(); + } + // file_put_contents("/xtmp/re-query.sql",$lq); + + if ($query) { + $rst = []; + $rows = $query->result_array(); + + foreach ($rows as $k => $v) { + + if ($v['is_result'] == "Y" && $v['is_quantitative'] == "N") { + $v['template'] = []; + $x = $this->db_smartone->query("CALL sp_master_resulttemplate_get('{$v['t_testid']}')"); + $this->clean_mysqli_connection($this->db_smartone->conn_id); + if ($x) + $v['template'] = $x->result_array(); + } + + // IF Rujukan, by pas Pre Analytik + if ($v['ref'] == 'Y') + $v['pre_analytic'] = 'Y'; + if ($v["id"] == "885455") { + //sipe workaround + //$v["sample_receive"] = "Y"; + $v["sample_worklist_receive"] = "Y"; + } + $rst[] = $v; + } + + $result = array("total" => $tot_count, "records" => $rst, "total_display" => sizeof($rows), "q" => $lq); + $this->sys_ok($result); + } else { + $this->sys_error_db("RE Px rows", $this->db_smartone); + exit; + } + } + + public function save() + { + $prm = $this->sys_input; + $data = json_decode($prm["data"]); + $lang = $this->lang_default_code; + $lang_id = isset($prm['lang_id']) ? $prm['lang_id'] : '0'; + + if ($lang_id != 0) { + $l = $this->db_smartone->where("Nat_LangID", $lang_id)->get("nat_lang")->row(); + $lang = $l->Nat_LangCode; + } + + $sql_norm = "select T_OrderDetailMinValue, T_OrderDetailMaxValue, + T_OrderDetailMinValueInclusive, T_OrderDetailMaxValueInclusive, + Nat_TestFlagLow, Nat_TestFlagHigh + from t_orderdetail + join t_test on T_OrderDetailT_TestID = T_TestID + join nat_test on T_TestNat_TestID = Nat_TestID and T_TestIsActive = 'Y' + where T_OrderDetailID = ? "; + + $ids = []; + foreach ($data as $k => $v) { + if ($v->resultInstrumentID > 0) { + $sql_i = "select T_ResultInstrumentNat_NormalValueID normalValueID + from t_resultinstrument + where T_ResultInstrumentID = ?"; + $qry_i = $this->db_smartone->query($sql_i, array($v->resultInstrumentID)); + if ($qry_i) { + $rows_i = $qry_i->result_array(); + + if (count($rows_i) > 0) { + $sql_iu = "update t_orderdetail, nat_normalvalue , nat_methode + set T_OrderDetailMinValue = Nat_NormalValueMinValue, + T_OrderDetailMinValueInclusive = Nat_NormalValueMinValueInclusive, + T_OrderDetailMaxValue = Nat_NormalValueMaxValue , + T_OrderDetailMaxValueInclusive = Nat_NormalValueMaxValueInclusive, + T_OrderDetailNormalValueNote = Nat_NormalValueNote, + T_OrderDetailNormalValueDescription = Nat_NormalValueDescription, + T_OrderDetailNat_NormalValueID = Nat_NormalValueID, + T_OrderDetailNat_MethodeID = Nat_NormalValueNat_MethodeID, + T_OrderDetailNat_MethodeName = Nat_MethodeName + where T_OrderDetailID = ? and Nat_NormalValueID = ? + and Nat_NormalValueNat_MethodeID = Nat_MethodeID + "; + $this->db_smartone->query($sql_iu, array($v->id, $rows_i[0]["normalValueID"])); + //file_put_contents("/xtmp/update-nilai-normal", $this->db_smartone->last_query() . "\n", FILE_APPEND); + } + } + } + $y = $this->db_smartone->query("SELECT fn_process_sample_handling_perfect('{$v->order_id}', '{$v->test_id}') c") + ->row(); + $req_status = $y->c; + $qry_norm = $this->db_smartone->query($sql_norm, $v->id); + $result_flag = ""; + if ($qry_norm) { + $rows_norm = $qry_norm->result_array(); + if (count($rows_norm) > 0) { + $r = $rows_norm[0]; + if (is_numeric($v->result)) { + + if ($r["T_OrderDetailMinValueInclusive"] == "Y" && $v->result < $r["T_OrderDetailMinValue"]) { + $result_flag = $r["Nat_TestFlagLow"]; + } + if ($r["T_OrderDetailMinValueInclusive"] == "N" && $v->result <= $r["T_OrderDetailMinValue"]) { + $result_flag = $r["Nat_TestFlagLow"]; + } + if ($r["T_OrderDetailMaxValueInclusive"] == "Y" && $v->result > $r["T_OrderDetailMaxValue"]) { + $result_flag = $r["Nat_TestFlagHigh"]; + } + if ($r["T_OrderDetailMaxValueInclusive"] == "N" && $v->result >= $r["T_OrderDetailMaxValue"]) { + $result_flag = $r["Nat_TestFlagHigh"]; + } + } + } + } + if ($lang == $this->lang_default_code) { + $this->db_smartone->set('T_OrderDetailResult', $v->result) + ->set('T_OrderDetailResultFlag', $result_flag) + ->set('T_OrderDetailNote', $v->note) + ->set('T_OrderDetailReqStatus', $req_status) + ->where('T_OrderDetailID', $v->id) + ->update('t_orderdetail'); + } else { + $this->db_smartone->set('T_OrderDetailLangResult', $v->result) + ->set('T_OrderDetailLangNote', $v->note) + ->where('T_OrderDetailLangID', $v->id) + ->update('t_orderdetaillang'); + } + + $ids[] = $v->id; + } + + // LOG Process + $order = $this->db_smartone->select('T_OrderDetailT_OrderHeaderID id, T_OrderHeaderLabNumber lab_number', false) + ->join('t_orderheader', 'T_OrderHeaderID = T_OrderDetailT_OrderHeaderID') + ->where('T_OrderDetailID', $data[0]->id) + ->get('t_orderdetail') + ->row(); + + $dblog = $this->load->database("onelog", true); + $dblog->set('Log_ProcessCode', 'PROCESS.Result.Entry') + ->set('Log_ProcessOrderID', $order->id) + ->set('Log_ProcessOrderNumber', $order->lab_number) + ->set('Log_ProcessJson', json_encode($data)) + ->set('Log_ProcessUserID', $this->sys_user['M_UserID']) + ->insert('log_process'); + // END OF Log Process + //auto calculation + $this->load->library("Resultcalc"); + $rows = $this->resultcalc->auto($order->id); + + try { + foreach ($ids as $id) { + $this->db_smartone->query("call sp_set_normal_value_flag($id)"); + $this->clean_mysqli_connection($this->db_smartone->conn_id); + } + } catch (Exception $e) { + } + + $this->sys_ok($ids); + } + + public function save_template() + { + $prm = $this->sys_input; + + $n = $this->db_smartone->select("COUNT(T_ResultTemplateID) n") + ->where("T_ResultTemplateT_TestID", $prm['test_id']) + ->where("T_ResultTemplateIsActive", "Y") + ->where("T_ResultTemplateValue", $prm['value']) + ->get('t_resulttemplate') + ->row(); + if ($n->n > 0) { + $this->sys_error_db("Insert Result Template", $this->db_smartone); + return; + } + + $r = $this->db_smartone->set("T_ResultTemplateT_TestID", $prm['test_id']) + ->set("T_ResultTemplateValue", $prm['value']) + ->insert('t_resulttemplate'); + if ($r) { + $template = []; + $x = $this->db_smartone->query("CALL sp_master_resulttemplate_get('{$prm['test_id']}')"); + $this->clean_mysqli_connection($this->db_smartone->conn_id); + if ($x) + $template = $x->result_array(); + + $this->sys_ok($template); + } + } + + public function export() + { + $prm = $this->sys_input; + + $sql = "CALL sp_process_result_lang(?, ?, ?, ?)"; + $query = $this->db_smartone->query($sql, [$prm['order_id'], $prm['lang_id'], $prm['is_si'], $this->sys_user['M_UserID']]); + if ($query) { + $r = $query->row(); + if ($r->status == "OK") { + $this->sys_ok($r->data); + return; + } + + $this->sys_error_db("Message : " . $r->message, $this->db_smartone); + } else { + $this->sys_error_db("Lang Result", $this->db_smartone); + return; + } + } + + public function search_group() + { + $prm = $this->sys_input; + $max_rst = 100; + + // QUERY TOTAL + $sql = "select count(*) total + from t_worklist + where T_WorklistIsActive = 'Y' + order by T_WorklistName ASC"; + $query = $this->db_smartone->query($sql); + + if ($query) { + $tot_count = $query->result_array()[0]["total"]; + } else { + $this->sys_error_db("worklist count", $this->db_smartone); + exit; + } + + $sql = "select T_WorklistID group_id, T_WorklistName group_name + from t_worklist + where T_WorklistIsActive = 'Y' + order by T_WorklistName ASC + limit 0, {$max_rst}"; + $query = $this->db_smartone->query($sql); + + if ($query) { + $rows = $query->result_array(); + foreach ($rows as $k => $v) + $rows[$k]['data'] = json_decode($v['data']); + $result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows), "q" => $this->db_smartone->last_query()); + $this->sys_ok($result); + } else { + $this->sys_error_db("worklist rows", $this->db_smartone); + exit; + } + } + + public function search_rerun() + { + $prm = $this->sys_input; + $id = $prm["detail_id"]; + + $sql = "CALL sp_process_result_rerun(?)"; + $query = $this->db_smartone->query($sql, [$id]); + + if ($query) { + $rows = $query->result_array(); + $this->sys_ok(["records" => $rows]); + } else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + + + function getdoctorsfna() + { + $prm = $this->sys_input; + // $id = $prm["id"]; + + $sql = " SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY M_DoctorName ASC"; + //echo $sql; + $query = $this->db_smartone->query($sql); + + if ($query) { + $rows = $query->result_array(); + $this->sys_ok(["records" => $rows]); + } else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + function getfnaresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT Other_FNADetailsID as xid, + Other_FNAT_OrderDetailID as orderdetail_id, + Other_FNADetailsCode as code, + Other_FNADetailsLabel as label, + Other_FNADetailsResult as result, + IFNULL(Other_FNAM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_FNAM_DoctorID) OR Other_FNAM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_fna + JOIN other_fnadetails ON Other_FNADetailsOther_FNAID = Other_FNAID AND Other_FNADetailsIsActive = 'Y' + LEFT JOIN m_doctor ON Other_FNAM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_FNAT_OrderDetailID = {$id} AND Other_FNAIsActive = 'Y' + GROUP BY Other_FNADetailsID + ORDER BY Other_FNADetailsCode ASC"; + $query = $this->db_smartone->query($sql); + + if ($query) { + $rows = $query->result_array(); + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $images = array(); + $sql = "SELECT So_ImageUploadID as xid, + CONCAT('/one-media/one-image-nonlab/',So_ImageUploadNewName) as image_url + FROM t_orderdetail + JOIN so_imageupload ON So_ImageUploadT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND + So_ImageUploadIsActive = 'Y' + WHERE + T_OrderDetailID = {$id} AND + T_OrderDetailIsActive = 'Y' + GROUP BY So_ImageUploadID"; + $images = $this->db_smartone->query($sql)->result_array(); + + $rst = array('doctors' => $doctors, 'results' => $rows, 'images' => $images); + $this->sys_ok(["records" => $rst]); + } else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + function getpatologianatomyresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT Other_PatologiAnatomyID as xid, + Other_PatologiAnatomyT_OrderDetailID as orderdetail_id, + Other_PatologiAnatomyNoSediaan as no_sediaan, + Other_PatologiAnatomyDiagnosaKlinis as diagnosa, + Other_PatologiAnatomyKeteranganKlinis as klinis, + Other_PatologiAnatomyLokasiOrgan as lokasi, + Other_PatologiAnatomyMakroskopik as makroskopik, + Other_PatologiAnatomyMikroskopik as mikroskopik, + Other_PatologiAnatomyKesimpulan as kesimpulan, + IFNULL(Other_PatologiAnatomyM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_PatologiAnatomyM_DoctorID) OR Other_PatologiAnatomyM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_patologi_anatomy + LEFT JOIN m_doctor ON Other_PatologiAnatomyM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_PatologiAnatomyT_OrderDetailID = {$id} AND Other_PatologiAnatomyIsActive = 'Y' + GROUP BY Other_PatologiAnatomyID + ORDER BY Other_PatologiAnatomyID ASC + LIMIT 1"; + $query = $this->db_smartone->query($sql); + + if ($query) { + $rows = $query->row_array(); + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + + $sql = "SELECT So_ImageUploadPatologyAnatomyID as xid, + CONCAT('/one-media/one-image-nonlab/',So_ImageUploadPatologyAnatomyNewName) as image_url, + So_ImageUploadPatologyAnatomyType as type + FROM t_orderdetail + JOIN so_imageupload_patology_anatomy ON So_ImageUploadPatologyAnatomyT_OrderHeaderID= T_OrderDetailT_OrderHeaderID AND + So_ImageUploadPatologyAnatomyIsActive= 'Y' + WHERE + T_OrderDetailID = {$id} AND + T_OrderDetailIsActive = 'Y' + GROUP BY So_ImageUploadPatologyAnatomyID"; + $images = $this->db_smartone->query($sql)->result_array(); + $mikro = []; + $makro = []; + + foreach ($images as $key => $value) { + + if ($value['type'] == 'mikro') { + $mikro[] = $value; + } + if ($value['type'] == 'makro') { + $makro[] = $value; + } + } + + $rst = array('doctors' => $doctors, 'result' => $rows, "mikro" => $mikro, "makro" => $makro); + $this->sys_ok(["records" => $rst]); + } else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + + function uploadimage() + { + if (! $this->isLogin) { + $this->sys_error("Invalid Token"); + exit; + } + + $userid = $this->sys_user["M_UserID"]; + $data = []; + //print_r($_SERVER); + + $prm = $this->sys_input; + $orderid = $this->input->post('orderid'); + $labnumber = $this->input->post('labnumber'); + $sql = "UPDATE so_imageupload SET + So_ImageUploadIsActive = 'N', + So_ImageUploadUserID = {$userid} + WHERE + So_ImageUploadT_OrderHeaderID = {$orderid}"; + //echo $sql; + $this->db_onedev->query($sql); + //$config['upload_path'] = 'assets/'; + + $path = '/home/one/project/one/one-media/one-image-nonlab/'; + //echo $path; + $config['upload_path'] = $path; + $config['allowed_types'] = 'jpg|jpeg|png|gif'; + + $config['max_size'] = '10000'; + $count = count($_FILES['files']['name']); + //echo $count; + $this->load->library('upload', $config); + + $error = []; + for ($i = 0; $i < $count; $i++) { + + + if (!empty($_FILES['files']['name'][$i])) { + + + + $_FILES['file']['name'] = $_FILES['files']['name'][$i]; + + $_FILES['file']['type'] = $_FILES['files']['type'][$i]; + + $_FILES['file']['tmp_name'] = $_FILES['files']['tmp_name'][$i]; + + $_FILES['file']['error'] = $_FILES['files']['error'][$i]; + + $_FILES['file']['size'] = $_FILES['files']['size'][$i]; + + + + $namex = $orderid . '-' . $labnumber . '-' . $this->generateRandomString(5); + //echo $namex; + + $config['file_name'] = $namex; + $this->upload->initialize($config); + //echo $config['file_name'] ; + + + + + + if ($this->upload->do_upload('file')) { + + $uploadData = $this->upload->data(); + + $filename = $uploadData['file_name']; + //echo $filename; + + + $sql = "INSERT INTO so_imageupload ( + So_ImageUploadT_OrderHeaderID, + So_ImageUploadT_OrderHeaderLabNumber, + So_ImageUploadT_SampleTypeID, + So_ImageUploadOldName, + So_ImageUploadNewName, + So_ImageUploadCreated, + So_ImageUploadUserID + ) + VALUES( + {$orderid}, + '{$labnumber}', + '150', + '{$_FILES['files']['name'][$i]}', + '{$filename}', + NOW(), + {$userid} + + )"; + //echo $sql; + $this->db_onedev->query($sql); + $xlast_id = $this->db_onedev->insert_id(); + $data['totalFiles'][] = array('xid' => $xlast_id, 'image_url' => '/one-media/one-image-nonlab/' . $filename); + } else { + $error = array('error' => $this->upload->display_errors()); + } + } + } + + $result = array("total" => count($data['totalFiles']), "records" => $data['totalFiles'], 'errors' => $error); + $this->sys_ok($result); + } + + + function generateRandomString($length = 10) + { + $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; + $charactersLength = strlen($characters); + $randomString = ''; + for ($i = 0; $i < $length; $i++) { + $randomString .= $characters[rand(0, $charactersLength - 1)]; + } + return $randomString; + } + + function getcytologiresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT Other_CytologiDetailsID as xid, + Other_CytologiT_OrderDetailID as orderdetail_id, + Other_CytologiDetailsCode as code, + Other_CytologiDetailsLabel as label, + Other_CytologiDetailsResult as result, + IFNULL(Other_CytologiM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_CytologiM_DoctorID) OR Other_CytologiM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_cytologi + JOIN other_cytologidetails ON Other_CytologiDetailsOther_CytologiID = Other_CytologiID AND Other_CytologiDetailsIsActive = 'Y' + LEFT JOIN m_doctor ON Other_CytologiM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_CytologiT_OrderDetailID = {$id} AND Other_CytologiIsActive = 'Y' + GROUP BY Other_CytologiDetailsID + ORDER BY Other_CytologiDetailsCode ASC"; + //echo $sql; + $query = $this->db_smartone->query($sql); + + if ($query) { + $rows = $query->result_array(); + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $rst = array('doctors' => $doctors, 'results' => $rows); + $this->sys_ok(["records" => $rst]); + } else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + function getmikroresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT + Other_MikroID as xid, + Other_MikroHasilBiakan as hasil_biakan, + Other_MikroSampleTypeName as sample_name, + Other_MikroT_OrderDetailID as orderdetail_id, + Other_MikroResult as result_value, + '' as result_other, + IFNULL(T_BacteriaID,0) as T_BacteriaID, + IFNULL(T_BacteriaName,'') as T_BacteriaName, + '' as details, + IFNULL(Other_MikroM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_MikroM_DoctorID) OR Other_MikroM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_mikro + LEFT JOIN t_bacteria ON Other_MikroT_BacteriaID = T_BacteriaID + LEFT JOIN m_doctor ON Other_MikroM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_MikroT_OrderDetailID = {$id} AND Other_MikroIsActive = 'Y' + GROUP BY Other_MikroID"; + //echo $sql; + $query = $this->db_smartone->query($sql); + + if ($query) { + $row = $query->row_array(); + if ($row) { + if ($row['result_value'] != 'Positif' && $row['result_value'] != 'Negatif') { + $row['result_other'] = $row['result_value']; + $row['result_value'] = 'other'; + } + $sql = "SELECT '' as xno, + Other_MikroDetailsID as xid, + Other_MikroDetailsValue as value, + IF(Other_MikroDetailsNote = 'R','Y','N') as chx_r, + IF(Other_MikroDetailsNote = 'I','Y','N') as chx_i, + IF(Other_MikroDetailsNote = 'S','Y','N') as chx_s, + Other_MikroDetailsNote as note, + t_antibiotic.* + FROM other_mikrodetails + LEFT JOIN t_antibiotic ON Other_MikroDetailsT_AntibioticID = T_AntibioticID + WHERE + Other_MikroDetailsOther_MikroID = {$row['xid']} AND Other_MikroDetailsIsActive = 'Y' + GROUP BY Other_MikroDetailsID + ORDER BY T_AntibioticName ASC"; + //echo $sql; + $details = $this->db_smartone->query($sql)->result_array(); + if (details) { + foreach ($details as $k => $v) { + $details[$k]['xno'] = $k + 1; + } + } + $row['details'] = $details; + } else { + $row = array('xid' => '0', 'hasil_biakan' => '', 'result_value' => 'Negatif', 'sample_name' => '', 'orderdetail_id' => $id, 'T_BacteriaID' => '0', 'T_BacteriaName' => '0', 'details' => array(), 'doctor_id' => '0', 'doctor_name' => '0'); + } + } else { + $row = array('xid' => '0', 'hasil_biakan' => '', 'result_value' => 'Negatif', 'sample_name' => '', 'orderdetail_id' => $id, 'T_BacteriaID' => '0', 'T_BacteriaName' => '0', 'details' => array(), 'doctor_id' => '0', 'doctor_name' => '0'); + } + //print_r($row); + + + + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 7 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $sql = " + SELECT '0' as id, 'Belum memilih bakteria' as name + UNION + SELECT T_BacteriaID as id, T_BacteriaName as name + FROM t_bacteria + WHERE + T_BacteriaIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $bacteries = $this->db_smartone->query($sql)->result_array(); + $rst = array('doctors' => $doctors, 'bacteries' => $bacteries, 'results' => $row); + $this->sys_ok(["records" => $rst]); + } + function getantibiotics() + { + $prm = $this->sys_input; + $id = $prm["id"]; + $sql = " SELECT '' as xno, + 0 as xid, + '' as hasil_biakan, + '' as sample_name, + 0 as value, + 'Y' as chx_r, + 'N' as chx_i, + 'N' as chx_s, + 'R' as note, + t_antibiotic.* + FROM t_antibiotic + WHERE + T_AntibioticT_BacteriaID = {$prm['id']} AND T_AntibioticIsActive= 'Y' + ORDER BY T_AntibioticName ASC"; + //echo $sql; + $rows = $this->db_smartone->query($sql)->result_array(); + if (rows) { + foreach ($rows as $k => $v) { + $rows[$k]['xno'] = $k + 1; + } + } + + $this->sys_ok(["records" => $rows]); + } + function getlcprepresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + $sql = " SELECT Other_LcprepDetailsID as xid, + Other_LcprepID as header_id, + Other_LcprepT_orderDetailID as orderdetail_id, + Other_LcprepDetailsCode as code, + Other_LcprepDetailsLabel as label, + Other_LcprepDetailsResult as result, + IFNULL(Other_LcprepM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_LcprepM_DoctorID) OR Other_LcprepM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_lcprep + JOIN other_lcprepdetails ON Other_LcprepDetailsOther_LcprepID = Other_LcprepID AND Other_LcprepDetailsIsActive = 'Y' + LEFT JOIN m_doctor ON Other_LcprepM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_LcprepT_orderDetailID = {$id} AND Other_LcprepIsActive = 'Y' + GROUP BY Other_LcprepDetailsOther_LcprepID, Other_LcprepDetailsCode + ORDER BY Other_LcprepDetailsCode ASC"; + //echo $sql; + $rows = $this->db_smartone->query($sql)->result_array(); + if (!$rows) { + $rows = array( + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'A', + 'label' => 'DESKRIPSI', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ), + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'B', + 'label' => 'KESIMPULAN', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ) + ); + } + + $header_id = $rows[0]['header_id']; + $sql = "SELECT IFNULL(Other_LcprepAdekuasiID,0) as xid, + Lcprep_AdekuasiID as id, + Lcprep_AdekuasiLabel as name, + IF(ISNULL(Other_LcprepAdekuasiID),'N',Other_LcprepAdekuasiChex) as chex + FROM lcprep_adekuasi + LEFT JOIN other_lcprepadekuasi ON Other_LcprepAdekuasiLcprep_AdekuasiID = Lcprep_AdekuasiID AND + Other_LcprepAdekuasiOther_LcprepID = {$header_id} AND + Other_LcprepAdekuasiIsActive = 'Y' + WHERE + Lcprep_AdekuasiIsActive = 'Y' + GROUP BY Lcprep_AdekuasiID + ORDER BY Lcprep_AdekuasiOrder ASC + "; + //echo $sql; + $adeakuasi = $this->db_smartone->query($sql)->result_array(); + foreach ($adeakuasi as $kc => $vc) { + $adeakuasi[$kc]['chex'] = $vc['chex'] == 'N' ? false : true; + } + + $sql = "SELECT IFNULL(Other_LcprepKategoriUmumID,0) as xid, + Lcprep_KategoriUmumID as id, + Lcprep_KategoriUmumLabel as name, + IF(ISNULL(Other_LcprepKategoriUmumID),'N',Other_LcprepKategoriUmumChex) as chex + FROM lcprep_kategoriumum + LEFT JOIN other_lcprepkategoriumum ON Other_LcprepKategoriUmumLcprep_KategoriUmumID = Lcprep_KategoriUmumID AND + Other_LcprepKategoriUmumOther_LcprepID = {$header_id} AND + Other_LcprepKategoriUmumIsActive = 'Y' + WHERE + Lcprep_KategoriUmumIsActive = 'Y' + GROUP BY Lcprep_KategoriUmumID + "; + //echo $sql; + $kategoriumum = $this->db_smartone->query($sql)->result_array(); + foreach ($kategoriumum as $kc => $vc) { + $kategoriumum[$kc]['chex'] = $vc['chex'] == 'N' ? false : true; + } + + $sql = " + SELECT Lcprep_InterpretasiGroupID as group_id, + Lcprep_InterpretasiGroupName as group_name, + '' as subgroups + FROM lcprep_interpretasigroup + WHERE + Lcprep_InterpretasiGroupIsActive = 'Y' + "; + //echo $sql; + $interpretasi = $this->db_smartone->query($sql)->result_array(); + foreach ($interpretasi as $k => $v) { + $subgroups = array(); + $sql = "SELECT Lcprep_InterpretasiSubgroupID as subgroup_id, + Lcprep_InterpretasiSubgroupName as subgroup_name, + '' as childs + FROM lcprep_interpretasisubgroup + WHERE + Lcprep_InterpretasiSubgroupLcprep_InterpretasiGroupID = {$v['group_id']} AND Lcprep_InterpretasiSubgroupIsActive = 'Y'"; + //echo $sql; + $subgroups = $this->db_smartone->query($sql)->result_array(); + if (count($subgroups) > 0) { + foreach ($subgroups as $ki => $vi) { + $childs = array(); + $sql = "SELECT IFNULL(Other_LcprepInterpretasiID,0) as xid, + IFNULL(Other_LcprepInterpretasiChex,'N') as chex, + IFNULL(Other_LcprepInterpretasiValue,'') as value, + Lcprep_InterpretasiID as id, + Lcprep_InterpretasiLcprep_InterpretasiSubgroupID as subgroup_id, + Lcprep_InterpretasiCode as code, + Lcprep_InterpretasiName as name, + Lcprep_InterpretasiParentID as parent_id, + Lcprep_InterpretasiIsParent as is_parent, + Lcprep_InterpretasiHasResult as has_result, + Lcprep_InterpretasiTypeResult as type_result + FROM lcprep_interpretasi + LEFT JOIN other_lcprepinterpretasi ON Other_LcprepInterpretasiOther_LcprepID = {$header_id} AND + Other_LcprepInterpretasiLcprep_InterpretasiID = Lcprep_InterpretasiID AND + Other_LcprepInterpretasiIsActive = 'Y' + WHERE + Lcprep_InterpretasiLcprep_InterpretasiSubgroupID = {$vi['subgroup_id']} AND Lcprep_InterpretasiIsActive = 'Y' + GROUP BY Lcprep_InterpretasiID Order BY Lcprep_InterpretasiCode ASC"; + $childs = $this->db_smartone->query($sql)->result_array(); + if ($childs) { + foreach ($childs as $kc => $vc) { + $childs[$kc]['chex'] = $vc['chex'] == 'N' ? false : true; + } + } + $subgroups[$ki]['childs'] = $childs; + } + } + + $interpretasi[$k]['subgroups'] = $subgroups; + } + + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $rst = array('doctors' => $doctors, 'results' => $rows, 'adekuasi' => $adeakuasi, 'kategoriumum' => $kategoriumum, 'interpretasi' => $interpretasi); + $this->sys_ok(["records" => $rst]); + } + + function getpapsmearresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT Other_PapSmearDetailsID as xid, + Other_PapSmearID as header_id, + Other_PapSmearT_OrderDetailID as orderdetail_id, + Other_PapSmearDetailsCode as code, + Other_PapSmearDetailsLabel as label, + Other_PapSmearDetailsResult as result, + IFNULL(Other_PapSmearM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_PapSmearM_DoctorID) OR Other_PapSmearM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_papsmear + JOIN other_papsmeardetails ON Other_PapSmearDetailsOther_PapSmearID = Other_PapSmearID AND Other_PapSmearDetailsIsActive = 'Y' + LEFT JOIN m_doctor ON Other_PapSmearM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_PapSmearT_OrderDetailID = {$id} AND Other_PapSmearIsActive = 'Y' + GROUP BY Other_PapSmearDetailsID + ORDER BY Other_PapSmearDetailsCode ASC"; + //echo $sql; + $rows = $this->db_smartone->query($sql)->result_array(); + if (!$rows) { + $rows = array( + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'A', + 'label' => 'Makroskopik', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ), + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'B', + 'label' => 'Mikroskopik', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ), + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'C', + 'label' => 'Kesimpulan', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ) + ); + } + + $header_id = $rows[0]['header_id']; + $sql = "SELECT Other_PapSmearMaturasiID as xid, + Other_PapSmearMaturasiValue as value + FROM other_papsmearmaturasi + WHERE + Other_PapSmearMaturasiOther_PapSmearID = {$header_id} AND + Other_PapSmearMaturasiIsActive = 'Y' + "; + //echo $sql; + $dt_maturasi = $this->db_smartone->query($sql)->row_array(); + if (!$dt_maturasi) { + $maturasi = array('xid' => '0', 'value' => array('', '', '')); + } else { + $value = explode('/', $dt_maturasi['value']); + $maturasi = array('xid' => $dt_maturasi['xid'], 'value' => $value); + } + + $sql = "SELECT IFNULL(Other_PapSmearBahanID,0) as xid, + M_PapSmearBahanID as bahan_id, + M_PapSmearBahanName as name, + IF(ISNULL(Other_PapSmearBahanID),'N','Y') as selected + FROM m_papsmearbahan + LEFT JOIN other_papsmearbahan ON Other_PapSmearBahanM_PapSmearBahanID = M_PapSmearBahanID AND + Other_PapSmearBahanOther_PapSmearID = {$header_id} AND + Other_PapSmearBahanIsActive = 'Y' + WHERE + M_PapSmearBahanIsActive = 'Y' + ORDER BY M_PapSmearBahanID ASC + "; + //echo $sql; + $bahans = $this->db_smartone->query($sql)->result_array(); + + $sql = "SELECT IFNULL(Other_PapsmearCategoryID,0) as xid, + M_PapSmearCategoryID as category_id, + M_PapSmearCategoryName as name, + IF(ISNULL(Other_PapsmearCategoryID),'N','Y') as selected + FROM m_papsmearcategory + LEFT JOIN other_papsmearcategory ON Other_PapsmearCategoryM_PapSmearCategoryID = M_PapSmearCategoryID AND + Other_PapsmearCategoryOther_PapSmearID = {$header_id} AND + Other_PapsmearCategoryIsActive = 'Y' + WHERE + M_PapSmearCategoryIsActive = 'Y' + ORDER BY M_PapSmearCategoryID ASC + "; + //echo $sql; + $categories = $this->db_smartone->query($sql)->result_array(); + + $sql = "SELECT IFNULL(Other_PapSmearCheckID,0) as xid, + M_PapSmearCheckID as check_id, + M_PapSmearCheckLabel as name, + IF(ISNULL(Other_PapSmearCheckID),'N','Y') as selected, + Other_PapSmearCheckNote as note + FROM m_papsmearcheck + LEFT JOIN other_papsmearcheck ON Other_PapSmearCheckM_PapSmearCheckID = M_PapSmearCheckID AND + Other_PapSmearCheckOther_PapSmearID = {$header_id} AND + Other_PapSmearCheckIsActive = 'Y' + WHERE + M_PapSmearCheckIsActive = 'Y' + ORDER BY M_PapSmearCheckCode ASC + "; + $checks = $this->db_smartone->query($sql)->result_array(); + + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $rst = array('doctors' => $doctors, 'checks' => $checks, 'bahans' => $bahans, 'categories' => $categories, 'maturasi' => $maturasi, 'results' => $rows); + $this->sys_ok(["records" => $rst]); + } + + function saveresult_lcprep() + { + $prm = $this->sys_input; + $detail_id = $prm['detail_id']; + $doctor_id = $prm['doctor']; + $adekuasi = $prm['adekuasi']; + $kategoriumum = $prm['kategoriumum']; + $interpretasi = $prm['interpretasi']; + $results = $prm['results']; + + $userid = $this->sys_user['M_UserID']; + + $header_id = 0; + $sql = "SELECT * FROM other_lcprep WHERE Other_LcprepT_orderDetailID = {$detail_id} AND Other_LcprepIsActive = 'Y'"; + $dt_header = $this->db_smartone->query($sql)->row_array(); + if ($dt_header) { + $header_id = $dt_header['Other_LcprepID']; + } + if ($header_id == 0) { + $sql = "INSERT INTO other_lcprep( + Other_LcprepT_orderDetailID, + Other_LcprepM_DoctorID, + Other_LcprepUserID, + Other_LcprepCreated + ) + VALUES( + {$detail_id}, + {$doctor_id}, + {$userid}, + NOW() + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } else { + $sql = "UPDATE other_lcprep SET Other_LcprepM_DoctorID = {$doctor_id}, Other_LcprepUserID = {$userid} WHERE Other_LcprepID = {$header_id}"; + $this->db_smartone->query($sql); + } + + if ($adekuasi) { + foreach ($adekuasi as $k => $v) { + $selected = $v['chex'] ? 'Y' : 'N'; + if (intval($v['xid'] == 0)) { + $sql = "UPDATE other_lcprepadekuasi SET Other_LcprepAdekuasiIsActive = 'N' + WHERE + Other_LcprepAdekuasiOther_LcprepID = {$header_id} AND + Other_LcprepAdekuasiIsActive = 'Y' AND + Other_LcprepAdekuasiLcprep_AdekuasiID = {$v['id']}"; + $this->db_smartone->query($sql); + $sql = "INSERT INTO other_lcprepadekuasi ( + Other_LcprepAdekuasiOther_LcprepID, + Other_LcprepAdekuasiLcprep_AdekuasiID, + Other_LcprepAdekuasiChex, + Other_LcprepAdekuasiUserID, + Other_LcprepAdekuasiCreated + ) + VALUES( + {$header_id}, + {$v['id']}, + '{$selected}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + //echo $sql; + } + if (intval($v['xid'] != 0)) { + + $sql = "UPDATE other_lcprepadekuasi SET + Other_LcprepAdekuasiChex = '{$selected}', + Other_LcprepAdekuasiUserID = {$userid} + WHERE + Other_LcprepAdekuasiID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + + //echo $sql; + } + } + + if ($kategoriumum) { + foreach ($kategoriumum as $k => $v) { + $selected = $v['chex'] ? 'Y' : 'N'; + if (intval($v['xid'] == 0)) { + $sql = "UPDATE other_lcprepkategoriumum SET Other_LcprepKategoriUmumIsActive = 'N' + WHERE + Other_LcprepKategoriUmumOther_LcprepID = {$header_id} AND + Other_LcprepKategoriUmumLcprep_KategoriUmumID = {$v['id']} AND + Other_LcprepKategoriUmumIsActive = 'Y' + "; + $this->db_smartone->query($sql); + $sql = "INSERT INTO other_lcprepkategoriumum ( + Other_LcprepKategoriUmumOther_LcprepID, + Other_LcprepKategoriUmumLcprep_KategoriUmumID, + Other_LcprepKategoriUmumChex, + Other_LcprepKategoriUmumUserID, + Other_LcprepKategoriUmumCreated + ) + VALUES( + {$header_id}, + {$v['id']}, + '{$selected}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if (intval($v['xid'] != 0)) { + $sql = "UPDATE other_lcprepkategoriumum SET + Other_LcprepKategoriUmumChex = '{$selected}', + Other_LcprepKategoriUmumUserID = {$userid} + WHERE + Other_LcprepKategoriUmumID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + + //echo $sql; + } + } + + if ($results) { + foreach ($results as $k => $v) { + if (intval($v['xid'] == 0)) { + $sql = "UPDATE other_lcprepdetails SET Other_LcprepDetailsIsActive = 'N' + WHERE + Other_LcprepDetailsOther_LcprepID = {$header_id} AND + Other_LcprepDetailsCode = '{$v['code']}' AND + Other_LcprepDetailsIsActive = 'Y'"; + $this->db_smartone->query($sql); + $sql = "INSERT INTO other_lcprepdetails ( + Other_LcprepDetailsOther_LcprepID, + Other_LcprepDetailsCode, + Other_LcprepDetailsLabel, + Other_LcprepDetailsResult, + Other_LcprepDetailsUserID, + Other_LcprepDetailsCreated + ) + VALUES( + {$header_id}, + '{$v['code']}', + '{$v['label']}', + '{$v['result']}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if (intval($v['xid'] != 0)) { + $sql = "UPDATE other_lcprepdetails SET + Other_LcprepDetailsCode = '{$v['code']}', + Other_LcprepDetailsLabel = '{$v['label']}', + Other_LcprepDetailsResult = '{$v['result']}', + Other_LcprepDetailsUserID = {$userid} + WHERE + Other_LcprepDetailsID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + //echo $sql; + } + } + + if ($interpretasi) { + foreach ($interpretasi as $k => $v) { + if (count($v['subgroups']) > 0) { + foreach ($v['subgroups'] as $ik => $iv) { + if (count($iv['childs']) > 0) { + foreach ($iv['childs'] as $iik => $iiv) { + if (intval($iiv['xid'] == 0)) { + $chex = $iiv['chex'] ? 'Y' : 'N'; + $sql = "UPDATE other_lcprepinterpretasi SET Other_LcprepInterpretasiIsActive = 'N' + WHERE + Other_LcprepInterpretasiOther_LcprepID = {$header_id} AND + Other_LcprepInterpretasiLcprep_InterpretasiID = '{$iiv['id']}' AND + Other_LcprepInterpretasiIsActive = 'Y'"; + $this->db_smartone->query($sql); + $sql = "INSERT INTO other_lcprepinterpretasi ( + Other_LcprepInterpretasiOther_LcprepID, + Other_LcprepInterpretasiLcprep_InterpretasiID, + Other_LcprepInterpretasiChex, + Other_LcprepInterpretasiValue, + Other_LcprepInterpretasiUserID, + Other_LcprepInterpretasiCreated + ) + VALUES( + {$header_id}, + '{$iiv['id']}', + '{$chex}', + '{$iiv['value']}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + + if (intval($iiv['xid'] != 0)) { + $chex = $iiv['chex'] ? 'Y' : 'N'; + $sql = "UPDATE other_lcprepinterpretasi SET + Other_LcprepInterpretasiChex = '{$chex}', + Other_LcprepInterpretasiValue = '{$iiv['value']}', + Other_LcprepInterpretasiUserID = {$userid} + WHERE + Other_LcprepInterpretasiID = {$iiv['xid']}"; + $this->db_smartone->query($sql); + //echo $sql; + + } + } + } + } + } + //echo $sql; + } + } + + + $result = array("total" => 1, "records" => array(), "sql" => ''); + $this->sys_ok($result); + exit; + } + + function saveresult_papsmear() + { + $prm = $this->sys_input; + $detail_id = $prm['detail_id']; + $doctor_id = $prm['doctor']; + $checks = $prm['checks']; + $maturasi = $prm['maturasi']; + $bahans = $prm['bahans']; + $categories = $prm['categories']; + $results = $prm['results']; + + $userid = $this->sys_user['M_UserID']; + + $header_id = 0; + $sql = "SELECT * FROM other_papsmear WHERE Other_PapSmearT_OrderDetailID = {$detail_id} AND Other_PapSmearIsActive = 'Y'"; + $dt_header = $this->db_smartone->query($sql)->row_array(); + if ($dt_header) { + $header_id = $dt_header['Other_PapSmearID']; + } + if ($header_id == 0) { + $sql = "INSERT INTO other_papsmear( + Other_PapSmearT_OrderDetailID, + Other_PapSmearM_DoctorID, + Other_PapSmearUserID, + Other_PapSmearCreated + ) + VALUES( + {$detail_id}, + {$doctor_id}, + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } else { + $sql = "UPDATE other_papsmear SET Other_PapSmearM_DoctorID = {$doctor_id}, Other_PapSmearUserID = {$userid} WHERE Other_PapSmearID = {$header_id}"; + $this->db_smartone->query($sql); + } + + if ($checks) { + foreach ($checks as $k => $v) { + if (intval($v['xid']) == 0 && $v['selected'] === 'Y') { + $sql = "INSERT INTO other_papsmearcheck ( + Other_PapSmearCheckOther_PapSmearID, + Other_PapSmearCheckM_PapSmearCheckID, + Other_PapSmearCheckNote, + Other_PapSmearCheckUserID, + Other_PapSmearCheckCreated + ) + VALUES( + {$header_id}, + {$v['check_id']}, + '{$v['note']}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if (intval($v['xid']) != 0 && $v['selected'] === 'N') { + $sql = "UPDATE other_papsmearcheck SET + Other_PapSmearCheckIsActive = 'N', + Other_PapSmearCheckUserID = {$userid} + WHERE + Other_PapSmearCheckID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + if (intval($v['xid']) != 0 && $v['selected'] === 'Y') { + $sql = "UPDATE other_papsmearcheck SET + Other_PapSmearCheckNote = '{$v['note']}', + Other_PapSmearCheckUserID = {$userid} + WHERE + Other_PapSmearCheckID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + //echo $sql; + } + } + + if ($maturasi) { + if (intval($maturasi['xid']) == 0) { + $value = join("/", $maturasi['value']); + $sql = "INSERT INTO other_papsmearmaturasi ( + Other_PapSmearMaturasiOther_PapSmearID, + Other_PapSmearMaturasiValue, + Other_PapSmearMaturasiUserID, + Other_PapSmearMaturasiCreated + ) + VALUE( + {$header_id}, + '{$value}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + //echo $sql; + } + if (intval($maturasi['xid']) != 0) { + $value = join("/", $maturasi['value']); + $sql = "UPDATE other_papsmearmaturasi SET + Other_PapSmearMaturasiValue = '{$value}', + Other_PapSmearMaturasiUserID = {$userid} + WHERE + Other_PapSmearMaturasiID = {$maturasi['xid']}"; + // echo $sql; + $this->db_smartone->query($sql); + } + } + + if ($bahans) { + foreach ($bahans as $k => $v) { + if (intval($v['xid']) == 0 && $v['selected'] === 'Y') { + $sql = "INSERT INTO other_papsmearbahan ( + Other_PapSmearBahanOther_PapSmearID, + Other_PapSmearBahanM_PapSmearBahanID, + Other_PapSmearBahanUserID, + Other_PapSmearBahanCreated + ) + VALUES( + {$header_id}, + {$v['bahan_id']}, + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if (intval($v['xid']) != 0 && $v['selected'] === 'N') { + $sql = "UPDATE other_papsmearbahan SET + Other_PapSmearBahanIsActive = 'N', + Other_PapsmearCategoryUserID = {$userid} + WHERE + Other_PapSmearBahanID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + if (intval($v['xid']) != 0 && $v['selected'] === 'Y') { + $sql = "UPDATE other_papsmearbahan SET + Other_PapSmearBahanIsActive = 'Y', + Other_PapsmearCategoryUserID = {$userid} + WHERE + Other_PapSmearBahanID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + //echo $sql; + } + } + + if ($categories) { + foreach ($categories as $k => $v) { + if (intval($v['xid']) == 0 && $v['selected'] === 'Y') { + $sql = "INSERT INTO other_papsmearcategory ( + Other_PapsmearCategoryOther_PapSmearID, + Other_PapsmearCategoryM_PapSmearCategoryID, + Other_PapsmearCategoryUserID, + Other_PapsmearCategoryCreated + ) + VALUES( + {$header_id}, + {$v['category_id']}, + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if (intval($v['xid']) != 0 && $v['selected'] === 'N') { + $sql = "UPDATE other_papsmearcategory SET + Other_PapsmearCategoryIsActive = 'N', + Other_PapsmearCategoryUserID = {$userid} + WHERE + Other_PapsmearCategoryID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + //echo $sql; + if (intval($v['xid']) != 0 && $v['selected'] === 'Y') { + $sql = "UPDATE other_papsmearcategory SET + Other_PapsmearCategoryIsActive = 'Y', + Other_PapsmearCategoryUserID = {$userid} + WHERE + Other_PapsmearCategoryID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + } + } + + if ($results) { + foreach ($results as $k => $v) { + if (intval($v['xid']) == 0) { + $sql = "INSERT INTO other_papsmeardetails ( + Other_PapSmearDetailsOther_PapSmearID, + Other_PapSmearDetailsCode, + Other_PapSmearDetailsLabel, + Other_PapSmearDetailsResult, + Other_PapSmearDetailsUserID, + Other_PapSmearDetailsCreated + ) + VALUES( + {$header_id}, + '{$v['code']}', + '{$v['label']}', + '{$v['result']}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if (intval($v['xid']) != 0) { + $sql = "UPDATE other_papsmeardetails SET + Other_PapSmearDetailsCode = '{$v['code']}', + Other_PapSmearDetailsLabel = '{$v['label']}', + Other_PapSmearDetailsResult = '{$v['result']}', + Other_PapSmearDetailsUserID = {$userid} + WHERE + Other_PapSmearDetailsID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + //echo $sql; + } + } + + $result = array("total" => 1, "records" => array(), "sql" => ''); + $this->sys_ok($result); + exit; + } + + function saveresult_fna() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = $inp['doctor']; + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + if ($prm[0]['xid'] == '0') { + $sql = "INSERT INTO other_fna( + Other_FNAM_DoctorID, + Other_FNAT_OrderDetailID, + Other_FNAUserID, + Other_FNACreated + ) + VALUES( + {$doctor_id}, + {$prm[0]['orderdetail_id']}, + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } else { + $sql = "SELECT * FROM other_fna WHERE Other_FNAT_OrderDetailID = {$prm[0]['orderdetail_id']} AND Other_FNAIsActive = 'Y'"; + $data_header = $this->db_smartone->query($sql)->row_array(); + $header_id = $data_header['Other_FNAID']; + $sql = "UPDATE other_fna SET + Other_FNAM_DoctorID = {$doctor_id}, + Other_FNAUserID = {$userid} + WHERE + Other_FNAID = {$header_id}"; + $this->db_smartone->query($sql); + } + foreach ($prm as $k => $v) { + if ($v['xid'] == '0') { + $results = str_replace("'", "\\'", $v['result']); + $sql = "INSERT INTO other_fnadetails( + Other_FNADetailsOther_FNAID , + Other_FNADetailsCode, + Other_FNADetailsLabel, + Other_FNADetailsResult, + Other_FNADetailsCreated, + Other_FNADetailsUserID + ) + VALUES( + {$header_id}, + '{$v['code']}', + '{$v['label']}', + '{$results}', + NOW(), + {$userid} + )"; + $query = $this->db_smartone->query($sql); + } else { + $results = str_replace("'", "\\'", $v['result']); + $sql = "UPDATE other_fnadetails SET + Other_FNADetailsResult = '{$results}', + Other_FNADetailsUserID = {$userid} + WHERE + Other_FNADetailsID = {$v['xid']}"; + $query = $this->db_smartone->query($sql); + } + } + + $result = array("total" => 1, "records" => array(), "sql" => ''); + $this->sys_ok($result); + exit; + } + + function saveresult_cytologi() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = $inp['doctor']; + + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + if ($prm[0]['xid'] == '0') { + $sql = "INSERT INTO other_cytologi( + Other_CytologiT_OrderDetailID, + Other_CytologiM_DoctorID, + Other_CytologiUserID, + Other_CytologiCreated + ) + VALUES( + {$prm[0]['orderdetail_id']}, + {$doctor_id}, + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } else { + $sql = "SELECT * FROM other_cytologi WHERE Other_CytologiT_OrderDetailID = {$prm[0]['orderdetail_id']} AND Other_CytologiIsActive = 'Y'"; + $data_header = $this->db_smartone->query($sql)->row_array(); + $header_id = $data_header['Other_CytologiID']; + $sql = "UPDATE other_cytologi SET + Other_CytologiM_DoctorID = {$doctor_id}, + Other_CytologiUserID = {$userid} + WHERE + Other_CytologiID = {$header_id}"; + $this->db_smartone->query($sql); + } + foreach ($prm as $k => $v) { + if ($v['xid'] == '0') { + $results = str_replace("'", "\\'", $v['result']); + $sql = "INSERT INTO other_cytologidetails( + Other_CytologiDetailsOther_CytologiID , + Other_CytologiDetailsCode, + Other_CytologiDetailsLabel, + Other_CytologiDetailsResult, + Other_CytologiDetailsCreated, + Other_CytologiDetailsUserID + ) + VALUES( + {$header_id}, + '{$v['code']}', + '{$v['label']}', + '{$results}', + NOW(), + {$userid} + )"; + $query = $this->db_smartone->query($sql); + } else { + $results = str_replace("'", "\\'", $v['result']); + $sql = "UPDATE other_cytologidetails SET + Other_CytologiDetailsResult = '{$results}', + Other_CytologiDetailsUserID = {$userid} + WHERE + Other_CytologiDetailsID = {$v['xid']}"; + $query = $this->db_smartone->query($sql); + } + } + + $result = array("total" => 1, "records" => array(), "sql" => ''); + $this->sys_ok($result); + exit; + } + + function saveresult_mikro() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = $inp['doctor']; + $backteria_id = $inp['bacteria']; + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + + if ($inp['result_value'] != 'Negatif' && $inp['result_value'] != 'Positif') { + $prm['result_value'] = $prm['result_other']; + } else { + $prm['result_value'] = $inp['result_value']; + } + + if ($prm['xid'] == '0') { + $sql = "INSERT INTO other_mikro( + Other_MikroM_DoctorID, + Other_MikroResult, + Other_MikroT_BacteriaID, + Other_MikroT_OrderDetailID, + Other_MikroHasilBiakan, + Other_MikroSampleTypeName, + Other_MikroUserID, + Other_MikroCreated + ) + VALUES( + {$doctor_id}, + '{$prm['result_value']}', + {$backteria_id}, + {$prm['orderdetail_id']}, + '{$prm['hasil_biakan']}', + '{$prm['sample_name']}', + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } else { + $sql = "SELECT * FROM other_mikro WHERE Other_MikroT_OrderDetailID = {$prm['orderdetail_id']} AND Other_MikroIsActive = 'Y'"; + $data_header = $this->db_smartone->query($sql)->row_array(); + $header_id = $data_header['Other_MikroID']; + $sql = "UPDATE other_mikro SET + Other_MikroResult = '{$prm['result_value']}', + Other_MikroM_DoctorID = {$doctor_id}, + Other_MikroT_BacteriaID = {$backteria_id}, + Other_MikroHasilBiakan = '{$prm['hasil_biakan']}', + Other_MikroSampleTypeName = '{$prm['sample_name']}', + Other_MikroUserID = {$userid} + WHERE + Other_MikroID = {$header_id}"; + //echo $sql; + $this->db_smartone->query($sql); + } + + + + $sql = "UPDATE other_mikrodetails SET Other_MikroDetailsIsActive = 'N', Other_MikroDetailsUserID = 0 WHERE Other_MikroDetailsOther_MikroID = {$header_id}"; + $this->db_smartone->query($sql); + + $results = $prm['details']; + if ($inp['result_value'] == 'Positif') { + foreach ($results as $k => $v) { + if ($v['xid'] == '0') { + $sql = "INSERT INTO other_mikrodetails( + Other_MikroDetailsOther_MikroID , + Other_MikroDetailsT_AntibioticID, + Other_MikroDetailsValue, + Other_MikroDetailsNote, + Other_MikroDetailsCreated, + Other_MikroDetailsUserID + ) + VALUES( + {$header_id}, + '{$v['T_AntibioticID']}', + '{$v['value']}', + '{$v['note']}', + NOW(), + {$userid} + )"; + $query = $this->db_smartone->query($sql); + } else { + $sql = "UPDATE other_mikrodetails SET + Other_MikroDetailsT_AntibioticID = '{$v['T_AntibioticID']}', + Other_MikroDetailsValue = '{$v['value']}', + Other_MikroDetailsNote = '{$v['note']}', + Other_MikroDetailsIsActive = 'Y', + Other_MikroDetailsUserID = {$userid} + WHERE + Other_MikroDetailsID = {$v['xid']}"; + //echo $sql; + $query = $this->db_smartone->query($sql); + } + } + } + + + $result = array("total" => 1, "records" => array(), "sql" => ''); + $this->sys_ok($result); + exit; + } + + + function get_doctors_preparasi_sperma() + { + $prm = $this->sys_input; + // $id = $prm["id"]; + + $sql = " SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 10 AND + M_DoctorSOIsActive = 'Y' + ORDER BY M_DoctorName ASC"; + //echo $sql; + $query = $this->db_smartone->query($sql); + $rows = $query->result_array(); + $sql = " + SELECT '0' as id, 'Belum memilih metode' as name + UNION + SELECT M_MethodeSpermaID as id, M_MethodeSpermaName as name + FROM m_methodesperma + WHERE + M_MethodeSpermaIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $methodes = $this->db_smartone->query($sql)->result_array(); + + + $this->sys_ok(["records" => $rows, "methodes" => $methodes]); + } + + + function getpreparasispermaresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT other_preparasisperma.*, + Other_PreparasiSpermaID as xid, + Other_PreparasiSpermaT_OrderDetailID as orderdetail_id, + IFNULL(Other_PreparasiSpermaM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_PreparasiSpermaM_DoctorID) OR Other_PreparasiSpermaM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name, + IFNULL(M_MethodeSpermaID,0) as methode_id, + IFNULL(M_MethodeSpermaName,'') as methode_name + FROM other_preparasisperma + LEFT JOIN m_doctor ON Other_PreparasiSpermaM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + LEFT JOIN m_methodesperma ON Other_PreparasiSpermaM_MethodeSpermaID = M_MethodeSpermaID AND + M_MethodeSpermaIsActive = 'Y' + WHERE + Other_PreparasiSpermaT_OrderDetailID = {$id} AND Other_PreparasiSpermaIsActive = 'Y' + GROUP BY Other_PreparasiSpermaID"; + $query = $this->db_smartone->query($sql); + + if ($query) { + $rows = $query->row_array(); + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 10 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $sql = " + SELECT '0' as id, 'Belum memilih metode' as name + UNION + SELECT M_MethodeSpermaID as id, M_MethodeSpermaName as name + FROM m_methodesperma + WHERE + M_MethodeSpermaIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $methodes = $this->db_smartone->query($sql)->result_array(); + $images = array(); + $sql = "SELECT Other_PreparasiSpermaImgID as xid, + Other_PreparasiSpermaImgType as type, + CONCAT('/one-media/one-image-nonlab/',Other_PreparasiSpermaImgNewName) as image_url + FROM t_orderdetail + JOIN other_preparasisperma_img ON Other_PreparasiSpermaImgT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND + Other_PreparasiSpermaImgIsActive = 'Y' + WHERE + T_OrderDetailID = {$id} AND + T_OrderDetailIsActive = 'Y' + GROUP BY Other_PreparasiSpermaImgID"; + //echo $sql; + $images = $this->db_smartone->query($sql)->result_array(); + + $rst = array('doctors' => $doctors, 'methodes' => $methodes, 'results' => $rows, 'images' => $images); + $this->sys_ok(["records" => $rst]); + } else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + + function uploadimage_preparasi_sperma() + { + if (! $this->isLogin) { + $this->sys_error("Invalid Token"); + exit; + } + + $userid = $this->sys_user["M_UserID"]; + $data = []; + //print_r($_SERVER); + + $prm = $this->sys_input; + $orderid = $this->input->post('orderid'); + $type = $this->input->post('type'); + $labnumber = $this->input->post('labnumber'); + $sql = "UPDATE other_preparasisperma_img SET + Other_PreparasiSpermaImgIsActive = 'N', + Other_PreparasiSpermaImgUserID = {$userid} + WHERE + Other_PreparasiSpermaImgT_OrderHeaderID = {$orderid} AND + Other_PreparasiSpermaImgType = '{$type}'"; + //echo $sql; + $this->db_onedev->query($sql); + //$config['upload_path'] = 'assets/'; + + $path = '/home/one/project/one/one-media/one-image-nonlab/'; + //echo $path; + $config['upload_path'] = $path; + $config['allowed_types'] = 'jpg|jpeg|png|gif'; + + $config['max_size'] = '10000'; + $count = count($_FILES['files']['name']); + //echo $count; + $this->load->library('upload', $config); + + $error = []; + for ($i = 0; $i < $count; $i++) { + + + if (!empty($_FILES['files']['name'][$i])) { + + + + $_FILES['file']['name'] = $_FILES['files']['name'][$i]; + + $_FILES['file']['type'] = $_FILES['files']['type'][$i]; + + $_FILES['file']['tmp_name'] = $_FILES['files']['tmp_name'][$i]; + + $_FILES['file']['error'] = $_FILES['files']['error'][$i]; + + $_FILES['file']['size'] = $_FILES['files']['size'][$i]; + + + + $namex = $orderid . '-' . $labnumber . '-' . $this->generateRandomString(5); + //echo $namex; + + $config['file_name'] = $namex; + $this->upload->initialize($config); + //echo $config['file_name'] ; + + + + + + if ($this->upload->do_upload('file')) { + + $uploadData = $this->upload->data(); + + $filename = $uploadData['file_name']; + //echo $filename; + + + $sql = "INSERT INTO other_preparasisperma_img ( + Other_PreparasiSpermaImgT_OrderHeaderID, + Other_PreparasiSpermaImgType, + Other_PreparasiSpermaImgOldName, + Other_PreparasiSpermaImgNewName, + Other_PreparasiSpermaImgCreated, + Other_PreparasiSpermaImgUserID + ) + VALUES( + {$orderid}, + '{$type}', + '{$_FILES['files']['name'][$i]}', + '{$filename}', + NOW(), + {$userid} + + )"; + //echo $sql; + $this->db_onedev->query($sql); + $xlast_id = $this->db_onedev->insert_id(); + $data['totalFiles'][] = array('xid' => $xlast_id, 'type' => $type, 'image_url' => '/one-media/one-image-nonlab/' . $filename); + } else { + $error = array('error' => $this->upload->display_errors()); + } + } + } + + $result = array("total" => count($data['totalFiles']), "records" => $data['totalFiles'], 'errors' => $error); + $this->sys_ok($result); + } + + + function saveresult_preparasi_sperma() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = $inp['doctor']; + $orderdetail_id = $inp['orderdetailid']; + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + if ($prm['xid'] == '0') { + $sql = "INSERT INTO other_preparasisperma( + Other_PreparasiSpermaM_DoctorID, + Other_PreparasiSpermaT_OrderDetailID, + Other_PreparasiSpermaPreMotilitasA, + Other_PreparasiSpermaPreMotilitasB, + Other_PreparasiSpermaPreMotilitasC, + Other_PreparasiSpermaPreKonsentrasi, + Other_PreparasiSpermaPreKontaminan, + Other_PreparasiSpermaPostMotilitasA, + Other_PreparasiSpermaPostMotilitasB, + Other_PreparasiSpermaPostMotilitasC, + Other_PreparasiSpermaPostKonsentrasi, + Other_PreparasiSpermaPostKontaminan, + Other_PreparasiSpermaPreVolume, + Other_PreparasiSpermaPostVolume, + Other_PreparasiSpermaM_MethodeSpermaID, + Other_PreparasiSpermaNote, + Other_PreparasiSpermaUserID, + Other_PreparasiSpermaCreated + ) + VALUES( + {$doctor_id}, + {$orderdetail_id}, + '{$prm['Other_PreparasiSpermaPreMotilitasA']}', + '{$prm['Other_PreparasiSpermaPreMotilitasB']}', + '{$prm['Other_PreparasiSpermaPreMotilitasC']}', + '{$prm['Other_PreparasiSpermaPreKonsentrasi']}', + '{$prm['Other_PreparasiSpermaPreKontaminan']}', + '{$prm['Other_PreparasiSpermaPostMotilitasA']}', + '{$prm['Other_PreparasiSpermaPostMotilitasB']}', + '{$prm['Other_PreparasiSpermaPostMotilitasC']}', + '{$prm['Other_PreparasiSpermaPostKonsentrasi']}', + '{$prm['Other_PreparasiSpermaPostKontaminan']}', + '{$prm['Other_PreparasiSpermaPreVolume']}', + '{$prm['Other_PreparasiSpermaPostVolume']}', + '{$prm['Other_PreparasiSpermaM_MethodeSpermaID']}', + '{$prm['Other_PreparasiSpermaNote']}', + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } else { + $sql = "SELECT * FROM other_preparasisperma WHERE Other_PreparasiSpermaT_OrderDetailID = {$orderdetail_id} AND Other_PreparasiSpermaIsActive = 'Y'"; + $data_header = $this->db_smartone->query($sql)->row_array(); + $header_id = $data_header['Other_PreparasiSpermaID']; + $sql = "UPDATE other_preparasisperma SET + Other_PreparasiSpermaM_DoctorID = {$doctor_id}, + Other_PreparasiSpermaPreMotilitasA = '{$prm['Other_PreparasiSpermaPreMotilitasA']}', + Other_PreparasiSpermaPreMotilitasB = '{$prm['Other_PreparasiSpermaPreMotilitasB']}', + Other_PreparasiSpermaPreMotilitasC = '{$prm['Other_PreparasiSpermaPreMotilitasC']}', + Other_PreparasiSpermaPreKonsentrasi = '{$prm['Other_PreparasiSpermaPreKonsentrasi']}', + Other_PreparasiSpermaPreKontaminan = '{$prm['Other_PreparasiSpermaPreKontaminan']}', + Other_PreparasiSpermaPostMotilitasA = '{$prm['Other_PreparasiSpermaPostMotilitasA']}', + Other_PreparasiSpermaPostMotilitasB = '{$prm['Other_PreparasiSpermaPostMotilitasB']}', + Other_PreparasiSpermaPostMotilitasC = '{$prm['Other_PreparasiSpermaPostMotilitasC']}', + Other_PreparasiSpermaPostKonsentrasi = '{$prm['Other_PreparasiSpermaPostKonsentrasi']}', + Other_PreparasiSpermaPostKontaminan = '{$prm['Other_PreparasiSpermaPostKontaminan']}', + Other_PreparasiSpermaPreVolume = '{$prm['Other_PreparasiSpermaPreVolume']}', + Other_PreparasiSpermaPostVolume = '{$prm['Other_PreparasiSpermaPostVolume']}', + Other_PreparasiSpermaM_MethodeSpermaID = '{$prm['Other_PreparasiSpermaM_MethodeSpermaID']}', + Other_PreparasiSpermaNote = '{$prm['Other_PreparasiSpermaNote']}', + Other_PreparasiSpermaUserID = {$userid} + WHERE + Other_PreparasiSpermaID = {$header_id}"; + $this->db_smartone->query($sql); + } + + + $result = array("total" => 1, "records" => array(), "sql" => ''); + $this->sys_ok($result); + exit; + } + + function getdnafragmentasiresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT other_dnafragmentasi.*, + Other_DnaFragmentasiID as xid, + Other_DnaFragmentasiT_OrderDetailID as orderdetail_id, + IFNULL(Other_DnaFragmentasiM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_DnaFragmentasiM_DoctorID) OR Other_DnaFragmentasiM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name, + IFNULL(Other_DnaFragmentasiOther_DnaFragmentasiMethodeID,0) as methode_id, + IFNULL(Other_DnaFragmentasiMethodeName,'') as methode_name, + Other_DnaFragmentasiHaloLuas as halo_luas, + Other_DnaFragmentasiHaloSedang as halo_sedang, + Other_DnaFragmentasiHaloSempit as halo_sempit, + Other_DnaFragmentasiTanpaHalo as tanpa_halo, + Other_DnaFragmentasiDFI as dfi, + Other_DnaFragmentasiKesimpulan as kesimpulan, + Other_DnaFragmentasiCatatan as catatan + FROM other_dnafragmentasi + LEFT JOIN m_doctor ON Other_DnaFragmentasiM_DoctorID = M_DoctorID + LEFT JOIN other_dnafragmentasimethode ON Other_DnaFragmentasiOther_DnaFragmentasiMethodeID = Other_DnaFragmentasiMethodeID + WHERE + Other_DnaFragmentasiT_OrderDetailID = {$id} AND Other_DnaFragmentasiIsActive = 'Y' + GROUP BY Other_DnaFragmentasiID + LIMIT 1"; + //echo $sql; + $query = $this->db_smartone->query($sql); + + if ($query) { + $rows = $query->row_array(); + if (!$rows) { + $rows = array( + 'xid' => 0, + 'orderdetail_id' => $id, + 'doctor_id' => 0, + 'doctor_name' => '', + 'methode_id' => 0, + 'methode_name' => '', + 'halo_luas' => '', + 'halo_sedang' => '', + 'tanpa_halo' => '', + 'dfi' => '', + 'kesimpulan' => '', + 'catatan' => '' + ); + } + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID + WHERE + M_DoctorSONat_SubGroupID = 4 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + + $sql = " + SELECT '0' as id, 'Belum memilih metode' as name + UNION + SELECT Other_DnaFragmentasiMethodeID as id, Other_DnaFragmentasiMethodeName as name + FROM other_dnafragmentasimethode + WHERE + Other_DnaFragmentasiMethodeIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $methodes = $this->db_smartone->query($sql)->result_array(); + + + $rst = array('doctors' => $doctors, 'methodes' => $methodes, 'results' => $rows); + $this->sys_ok(["records" => $rst]); + } else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + function saveresult_dnafragmentasi() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = $inp['doctor']['id']; + $methode_id = $inp['methode']['id']; + $orderdetail_id = $inp['results']['orderdetail_id']; + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + if (intval($prm['xid']) == 0) { + $sql = "INSERT INTO other_dnafragmentasi( + Other_DnaFragmentasiT_OrderDetailID, + Other_DnaFragmentasiM_DoctorID, + Other_DnaFragmentasiOther_DnaFragmentasiMethodeID, + Other_DnaFragmentasiHaloLuas, + Other_DnaFragmentasiHaloSedang, + Other_DnaFragmentasiHaloSempit, + Other_DnaFragmentasiTanpaHalo, + Other_DnaFragmentasiDFI, + Other_DnaFragmentasiKesimpulan, + Other_DnaFragmentasiCatatan, + Other_DnaFragmentasiUserID, + Other_DnaFragmentasiLastUpdated + ) + VALUES( + {$orderdetail_id}, + {$doctor_id}, + {$methode_id}, + '{$prm['halo_luas']}', + '{$prm['halo_sedang']}', + '{$prm['halo_sempit']}', + '{$prm['tanpa_halo']}', + '{$prm['dfi']}', + '{$prm['kesimpulan']}', + '{$prm['catatan']}', + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } else { + $sql = "UPDATE other_dnafragmentasi SET + Other_DnaFragmentasiT_OrderDetailID = {$orderdetail_id}, + Other_DnaFragmentasiM_DoctorID = {$doctor_id}, + Other_DnaFragmentasiOther_DnaFragmentasiMethodeID = '{$methode_id}', + Other_DnaFragmentasiHaloLuas = '{$prm['halo_luas']}', + Other_DnaFragmentasiHaloSedang = '{$prm['halo_sedang']}', + Other_DnaFragmentasiHaloSempit = '{$prm['halo_sempit']}', + Other_DnaFragmentasiTanpaHalo = '{$prm['tanpa_halo']}', + Other_DnaFragmentasiDFI = '{$prm['dfi']}', + Other_DnaFragmentasiKesimpulan = '{$prm['kesimpulan']}', + Other_DnaFragmentasiCatatan = '{$prm['catatan']}', + Other_DnaFragmentasiLastUpdated = NOW(), + Other_DnaFragmentasiUserID = {$userid} + WHERE + Other_DnaFragmentasiID = {$prm['xid']}"; + //echo $sql; + $this->db_smartone->query($sql); + } + + + $result = array("total" => 1, "records" => array(), "sql" => ''); + $this->sys_ok($result); + exit; + } +} diff --git a/application/controllers/mockup/process/resultverification-westone/Re_px.php b/application/controllers/mockup/process/resultverification-westone/Re_px.php index f9b079b9..d5c1d003 100644 --- a/application/controllers/mockup/process/resultverification-westone/Re_px.php +++ b/application/controllers/mockup/process/resultverification-westone/Re_px.php @@ -1,2512 +1,2509 @@ -db_smartone = $this->load->database("onedev", true); - $this->load->helper(array('form', 'url')); - } - function getMethodeID($natTestID) - { - $sql = "select M_MethodePriorityNat_MethodeID MethodeID, Nat_MethodeName - from - m_methode_priority - join nat_methode on Nat_MethodeID = M_MethodePriorityNat_MethodeID - and Nat_MethodeIsActive = 'Y' - join m_instrumentmethode on M_InstrumentMethodeNat_MethodeID = Nat_MethodeID and M_InstrumentMethodeIsActive = 'Y' - join nat_instrument on M_InstrumentMethodeNat_InstrumentID = Nat_InstrumentID - and Nat_InstrumentIsActive ='Y' - where M_MethodePriorityIsActive = 'Y' - and M_MethodePriorityNat_TestID = $natTestID - and M_MethodePriorityM_DayOfWeekID = dayofweek(now()) - order by M_MethodePriorityNumber desc - limit 0,1 "; - $qry = $this->db->query($sql); - if ($qry) { - $rows = $qry->result_array(); - if (count($rows) > 0) return array($rows[0]["MethodeID"], $rows[0]["Nat_MethodeName"]); - } - //2nd - $sql = "select - M_InstrumentMethodeNat_MethodeID MethodeID, Nat_MethodeName - from m_instrumentmethode - join nat_methode on M_InstrumentMethodeNat_MethodeID = Nat_MethodeID - and Nat_MethodeIsActive = 'Y' - join nat_instrument on M_InstrumentMethodeNat_InstrumentID = Nat_InstrumentID - and Nat_InstrumentIsActive ='Y' - where M_InstrumentMethodeNat_TestID = $natTestID - and M_InstrumentMethodeIsActive = 'Y' - order by M_InstrumentMethodePriority desc - limit 0,1"; - $qry = $this->db->query($sql); - if ($qry) { - $rows = $qry->result_array(); - if (count($rows) > 0) return array($rows[0]["MethodeID"], $rows[0]["Nat_MethodeName"]); - } - // - $sql = "select Nat_NormalValueNat_MethodeID MethodeID, Nat_MethodeName - from - nat_normalvalue - join nat_methode on Nat_NormalValueNat_MethodeID = Nat_MethodeID - and Nat_MethodeIsActive = 'Y' - where Nat_NormalValueNat_TestID = $natTestID - and Nat_NormalValueIsActive = 'Y' - order by Nat_NormalValueID - limit 0,1"; - $qry = $this->db->query($sql); - if ($qry) { - $rows = $qry->result_array(); - if (count($rows) > 0) return array($rows[0]["MethodeID"], $rows[0]["Nat_MethodeName"]); - } - return array(0, ""); - } - function get_normal_value($methodeID, $natTestID, $sexID, $ageInDay) - { - $sql = "select fn_sampling_get_normal($methodeID, $natTestID, $sexID, $ageInDay) as normalValueID"; - $qry = $this->db->query($sql); - if ($qry) { - $rows = $qry->result_array(); - if (count($rows) > 0) return $rows[0]["normalValueID"]; - } - return 0; - } - function fn_fix_normal($order_id) - { - $sql = "select - T_OrderDetailID, M_PatientM_SexID, fn_global_age_count_day(M_PatientDOB, date(T_OrderHeaderDate)) Dob , - T_TestNat_TestID - from t_orderheader - join m_patient on T_OrderHeaderID = $order_id and T_OrderHeaderM_PatientID = M_PatientID - join t_orderdetail on T_OrderDetailT_OrderHeaderID = T_OrderHeaderID - and T_OrderDetailIsACtive = 'Y' - and ( T_OrderDetailNat_NormalValueID is null or T_OrderDetailNat_NormalValueID = 0 ) - join t_test on T_OrderDetailT_TestID = T_TestID and T_TestIsResult = 'Y' "; - $qry = $this->db->query($sql); - if (! $qry) { - return; - } - $rows = $qry->result_array(); - if (count($rows) == 0) return; - $sql_u = "update t_orderdetail - join nat_normalvalue on T_OrderDetailID = ? and Nat_NormalValueID = ? - set - T_OrderDetailNat_NormalValueID = Nat_NormalValueID, - T_OrderDetailNormalValueNote = Nat_NormalValueNote, - T_OrderDetailNormalValueDescription = Nat_NormalValueDescription, - T_OrderDetailMinValue = Nat_NormalValueMinValue, - T_OrderDetailMaxValue = Nat_NormalValueMaxValue, - T_OrderDetailMinValueInclusive = Nat_NormalValueMinValueInclusive, - T_OrderDetailMaxValueInclusive = Nat_NormalValueMaxValueInclusive, - T_OrderDetailNat_MethodeID = ?, - T_OrderdetailNat_MethodeName =?"; - - foreach ($rows as $r) { - $T_OrderDetailID = $r["T_OrderDetailID"]; - $sexID = $r["M_PatientM_SexID"]; - $ageInDay = $r["Dob"]; - $natTestID = $r["T_TestNat_TestID"]; - list($methodeID, $methodeName) = $this->getMethodeID($natTestID); - if ($methodeID == 0) continue; - $normalValueID = $this->get_normal_value($methodeID, $natTestID, $sexID, $ageInDay); - if ($normalValueID == 0) return; - $this->db->query($sql_u, array($T_OrderDetailID, $normalValueID, $methodeID, $methodeName)); - } - } - - function update_order_sample($targetID, $sourceID) - { - $sql = "update t_ordersample target - join t_ordersample source on - target.T_OrderSampleID = ? - and target.T_OrderSampleWorklistReceive = 'N' - and source.T_OrderSampleID = ? - set - target.T_OrderSampleSampling = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSampling, source.T_OrderSampleSampling), - target.T_OrderSampleSamplingDate = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingDate, source.T_OrderSampleSamplingDate), - target.T_OrderSampleSamplingTime = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingTime, source.T_OrderSampleSamplingTime), - target.T_OrderSampleSamplingUserID = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingUserID, source.T_OrderSampleSamplingUserID), - - target.T_OrderSampleReceive = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceive, source.T_OrderSampleReceive), - target.T_OrderSampleReceiveDate = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveDate, source.T_OrderSampleReceiveDate), - target.T_OrderSampleReceiveTime = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveTime, source.T_OrderSampleReceiveTime), - target.T_OrderSampleReceiveUserID = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveUserID, source.T_OrderSampleReceiveUserID), - - target.T_OrderSampleVerification = if(target.T_OrderSampleVerification='Y',target.T_OrderSampleVerification, source.T_OrderSampleVerification), - target.T_OrderSampleVerificationDate =if(target.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationDate, source.T_OrderSampleVerificationDate), - target.T_OrderSampleVerificationTime =if(source.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationTime, source.T_OrderSampleVerificationTime), - target.T_OrderSampleVerificationUserID =if(source.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationUserID, source.T_OrderSampleVerificationUserID), - - target.T_OrderSampleProcessing = if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessing, source.T_OrderSampleProcessing), - target.T_OrderSampleProcessingDate= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingDate, source.T_OrderSampleProcessingDate), - target.T_OrderSampleProcessingTime= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingTime, source.T_OrderSampleProcessingTime), - target.T_OrderSampleProcessingUserID= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingUserID, source.T_OrderSampleProcessingUserID), - - target.T_OrderSampleReceiveHandling =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandling, source.T_OrderSampleReceiveHandling ), - target.T_OrderSampleReceiveHandlingDate =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingDate, source.T_OrderSampleReceiveHandlingDate), - target.T_OrderSampleReceiveHandlingTime =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingTime, source.T_OrderSampleReceiveHandlingTime), - target.T_OrderSampleReceiveHandlingUserID =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingUserID, source.T_OrderSampleReceiveHandlingUserID), - - target.T_OrderSampleHandling = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandling, source.T_OrderSampleHandling), - target.T_OrderSampleHandlingDate = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingDate, source.T_OrderSampleHandlingDate), - target.T_OrderSampleHandlingTime = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingTime, source.T_OrderSampleHandlingTime), - target.T_OrderSampleHandlingUserID = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingUserID, source.T_OrderSampleHandlingUserID), - - target.T_OrderSampleWorklistReceive = source.T_OrderSampleWorklistReceive, - target.T_OrderSampleWorklistReceiveDatetime = source.T_OrderSampleWorklistReceiveDateTime, - target.T_OrderSampleWorklistReceiveUserID = source.T_OrderSampleWorklistReceiveUserID - "; - $qry = $this->db->query($sql, array($targetID, $sourceID)); - if (! $qry) { - echo json_encode(array("status" => "ERR", "message" => print_r($this->db->error(), true))); - exit; - } - } - function fix_sample_serum($headerID) - { - //cari t_ordersample yg belum worklist receive dengan code 017% - $sql = "select T_OrderSampleID - from t_ordersample - join t_sampletype on - T_OrderSampleT_OrderHeaderID = ? - and T_OrderSampleWorklistReceive = 'N' - and T_OrderSampleIsActive = 'Y' - and T_OrderSampleT_SampleTypeID = T_SampletypeID - and T_SampleTypeCode like '017%' - "; - $qry = $this->db->query($sql, array($headerID)); - if (!$qry) { - echo json_encode(array("status" => "ERR", "message" => print_r($this->db->error(), true))); - exit; - } - $rows = $qry->result_array(); - if (count($rows) == 0) return; - //cari T_OrderSample yang sudah di receive yg terakhir - $sql = "select T_OrderSampleID - from t_ordersample - join t_sampletype on - T_OrderSampleT_OrderHeaderID = ? - and T_OrderSampleWorklistReceive = 'Y' - and T_OrderSampleIsActive = 'Y' - and T_OrderSampleT_SampleTypeID = T_SampletypeID - and T_SampleTypeCode like '017%' - order by T_OrderSampleWorklistReceiveDatetime desc - limit 0,1 - "; - $qry = $this->db->query($sql, array($headerID)); - if (!$qry) { - echo json_encode(array("status" => "ERR", "message" => print_r($this->db->error(), true))); - exit; - } - $rcv_rows = $qry->result_array(); - if (count($rcv_rows) == 0) return; - - //print_r($rows); - //print_r($rcv_rows); - $rcv_T_OrderSampleID = $rcv_rows[0]["T_OrderSampleID"]; - //ada yg belum di receive - foreach ($rows as $r) { - $T_OrderSampleID = $r["T_OrderSampleID"]; - $this->update_order_sample($T_OrderSampleID, $rcv_T_OrderSampleID); - } - } - public function search() - { - $prm = $this->sys_input; - $max_rst = 99; - - $id = $prm["order_id"]; - if ($id > 0) { - $this->fix_sample_serum($id); - $this->fn_fix_normal($id); - } - $lang = $this->lang_default_code; - $lang_id = isset($prm['lang_id']) ? $prm['lang_id'] : '0'; - - if ($lang_id != 0) { - $l = $this->db_smartone->where("Nat_LangID", $lang_id)->get("nat_lang")->row(); - $lang = $l->Nat_LangCode; - } - - //tambahan fajri - $sql = " UPDATE t_orderdetail - JOIN t_test ON T_OrderDetailT_TestID = T_TestID - SET T_OrderDetailT_TestIsResult = T_TestIsResult - WHERE - T_OrderDetailT_OrderHeaderID = {$id} AND - T_OrderDetailT_TestIsResult = '' AND - T_OrderDetailIsActive = 'Y'"; - $this->db_smartone->query($sql); - - $tot_count = 0; - $lq = ""; - $group_id = 0; - if (isset($prm['group_id'])) - $group_id = $prm['group_id']; - - if ($group_id != 0) { - $sql = "select distinct T_WorklistDetailNat_TestID Nat_TestID - from t_worklistdetailv2 - where T_WorklistDetailT_WorklistID = {$group_id}"; - $qry = $this->db_smartone->query($sql); - $rows = $qry->result_array(); - $nat_test_ids = "0"; - foreach ($rows as $r) { - $nat_test_ids .= ", " . $r["Nat_TestID"]; - } - $q_group = " ( $nat_test_ids ) "; - - $sql = " - SELECT a1.*, cOUNT(a2.T_OrderDetailID) level - FROM ( - SELECT IFNULL(y.T_OrderDetailT_TestID, x.T_OrderDetailT_TestID) t_testid, - IFNULL(y.T_OrderDetailT_TestName, y.T_OrderDetailT_TestName) t_testname, - y.T_OrderDetailResult result, y.T_OrderDetailResult result_old, y.T_OrderDetailNote note, y.T_OrderDetailNote note_old, - y.T_OrderDetailID id, - y.T_OrderDetailT_TestIsResult is_result, a.T_TestIsQuantitative is_quantitative, - y.T_OrderDetailResultFlag result_flag, - y.T_OrderDetailNat_NormalValueID normal_id, - y.T_OrderDetailNormalValueNote normal_note, y.T_OrderDetailNat_UnitName unit_name, - y.T_OrderdetailNat_MethodeID methode_id, y.T_OrderdetailNat_MethodeName methode_name, - a.T_TestNat_TestID nattest_id, a.T_TestID tx_id, count(T_ResultInstrumentID) as result_instrument_n, - y.T_OrderDetailVerification, T_OrderSampleReceive sample_receive, - T_OrderSampleProcessing sample_processing, T_OrderSampleWorklistReceive sample_worklist_receive, - IF(T_OrderDetailAddOnPreAnalytic = 'Y', T_OrderDetailAddOnPreAnalytic, PreAnalyticIsOk) pre_analytic, - T_OrderDetailAddOnPreAnalytic, - T_OrderHeaderID order_id, y.T_OrderDetailT_TestSasCode test_sas_code, - tx.T_TestSasCode, - T_OrderDetailAddOnResample `resample`, T_OrderDetailAddOnResampleStatus resample_status, - T_OrderDetailAddOnRef ref, y.T_OrderDetailVerification verification, y.T_OrderDetailValidation validation, - T_OrderPromiseDateTime, Group_ResultName as ResultGroupName - FROM t_orderdetail x - left join t_orderpromise on x.T_OrderDetailT_OrderPromiseID = T_OrderPromiseID - JOIN t_test tx ON x.T_OrderDetailT_TestID = T_TestID - JOIN t_test tcheck on tcheck.T_TestNat_TestID in {$q_group} - and ( tx.T_TestID = tcheck.T_TestID or tx.T_TestSasCode like concat(tcheck.T_TestSasCode,'%')) - LEFT JOIN group_resultdetail ON Group_ResultDetailT_TestID = x.T_OrderDetailT_TestID AND Group_ResultDetailIsActive = 'Y' - LEFT JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND Group_ResultFlagNonLab = 'N' - LEFT JOIN t_orderdetail y ON x.T_OrderDetailT_TestSasCode LIKE CONCAT(y.T_OrderDetailT_TestSasCode, '%') - AND x.T_OrderDetailT_OrderHeaderID = y.T_OrderDetailT_OrderHeaderID - AND y.T_OrderDetailIsActive = 'Y' - LEFT JOIN t_orderdetailaddon ON x.T_OrderDetailID = T_OrderDetailAddOnT_OrderDetailID - JOIN t_orderheader ON y.T_OrderDetailT_OrderHeaderID = T_OrderHeaderID - LEFT JOIN t_test a ON y.T_OrderDetailT_TestID = a.T_TestID - AND a.T_TestIsNonLab = '' - LEFT JOIN (SELECT T_OrderSampleT_SampleTypeID, T_OrderSampleReceive, T_OrderSampleProcessing, T_OrderSampleWorklistReceive - FROM t_ordersample WHERE T_OrderSampleT_OrderHeaderID = {$id} - AND T_OrderSampleIsactive = 'Y' - GROUP BY T_OrderSampleT_SampleTypeID) os ON a.T_TestT_SampleTypeID = os.T_OrderSampleT_SampleTypeID - or os.T_OrderSampleT_SampleTypeID = fn_sampletype_from_local(a.T_TestNat_TestID) - - LEFT JOIN t_resultinstrument ON T_ResultInstrumentT_OrderDetailID = x.T_OrderDetailID - LEFT JOIN pre_analytic ON PreAnalyticNat_TestID = a.T_TestNat_TestID AND PreAnalyticDate = date(now()) and PreAnalyticIsActive = 'Y' - WHERE x.T_OrderDetailT_OrderHeaderID = {$id} - AND x.T_OrderDetailIsActive = 'Y' - GROUP BY y.T_OrderDetailT_TestID - ORDER BY y.T_OrderDetailT_TestSasCode ASC - ) a1 - - LEFT JOIN t_orderdetail a2 ON a2.T_OrderDetailT_OrderHeaderID = a1.order_id - AND a2.T_OrderDetailIsActive = 'Y' - AND a1.test_sas_code LIKE CONCAT(a2.T_OrderDetailT_testSasCode, '%') - GROUP BY a1.t_testid - order by a1.test_sas_code -"; - $query = $this->db_smartone->query($sql); - $lq = $this->db_smartone->last_query(); - } else { - $sql = " - SELECT a1.*, cOUNT(a2.T_OrderDetailID) level - FROM ( - SELECT IFNULL(y.T_OrderDetailT_TestID, x.T_OrderDetailT_TestID) t_testid, - IFNULL(y.T_OrderDetailT_TestName, y.T_OrderDetailT_TestName) t_testname, - y.T_OrderDetailResult result, y.T_OrderDetailResult result_old, y.T_OrderDetailNote note, y.T_OrderDetailNote note_old, - y.T_OrderDetailID id, - y.T_OrderDetailT_TestIsResult is_result, a.T_TestIsQuantitative is_quantitative, - y.T_OrderDetailResultFlag result_flag, - y.T_OrderDetailNat_NormalValueID normal_id, - y.T_OrderDetailNormalValueNote normal_note, y.T_OrderDetailNat_UnitName unit_name, - y.T_OrderdetailNat_MethodeID methode_id, y.T_OrderdetailNat_MethodeName methode_name, - a.T_TestNat_TestID nattest_id, a.T_TestID tx_id, count(T_ResultInstrumentID) as result_instrument_n, - y.T_OrderDetailVerification, T_OrderSampleReceive sample_receive, - T_OrderSampleProcessing sample_processing, T_OrderSampleWorklistReceive sample_worklist_receive, - IF(T_OrderDetailAddOnPreAnalytic = 'Y', T_OrderDetailAddOnPreAnalytic, PreAnalyticIsOk) pre_analytic, - T_OrderDetailAddOnPreAnalytic, - T_OrderHeaderID order_id, y.T_OrderDetailT_TestSasCode test_sas_code, - tx.T_TestSasCode, - T_OrderDetailAddOnResample `resample`, T_OrderDetailAddOnResampleStatus resample_status, - T_OrderDetailAddOnRef ref, y.T_OrderDetailVerification verification, y.T_OrderDetailValidation validation, - T_OrderPromiseDateTime , Group_ResultName as ResultGroupName - FROM t_orderdetail x - left join t_orderpromise on x.T_OrderDetailT_OrderPromiseID = T_OrderPromiseID - JOIN t_test tx ON x.T_OrderDetailT_TestID = T_TestID - LEFT JOIN group_resultdetail ON Group_ResultDetailT_TestID = x.T_OrderDetailT_TestID AND Group_ResultDetailIsActive = 'Y' - LEFT JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND Group_ResultFlagNonLab = 'N' - LEFT JOIN t_orderdetail y ON x.T_OrderDetailT_TestSasCode LIKE CONCAT(y.T_OrderDetailT_TestSasCode, '%') - AND x.T_OrderDetailT_OrderHeaderID = y.T_OrderDetailT_OrderHeaderID - AND y.T_OrderDetailIsActive = 'Y' - - LEFT JOIN t_orderdetailaddon ON x.T_OrderDetailID = T_OrderDetailAddOnT_OrderDetailID - - JOIN t_orderheader ON y.T_OrderDetailT_OrderHeaderID = T_OrderHeaderID - LEFT JOIN t_test a ON y.T_OrderDetailT_TestID = a.T_TestID - AND a.T_TestIsNonLab = '' - LEFT JOIN (SELECT T_OrderSampleT_SampleTypeID, T_OrderSampleReceive, T_OrderSampleProcessing, T_OrderSampleWorklistReceive - FROM t_ordersample WHERE T_OrderSampleT_OrderHeaderID = {$id} - AND T_OrderSampleIsactive = 'Y' - GROUP BY T_OrderSampleT_SampleTypeID) os ON a.T_TestT_SampleTypeID = os.T_OrderSampleT_SampleTypeID - or os.T_OrderSampleT_SampleTypeID = fn_sampletype_from_local(a.T_TestNat_TestID) - - LEFT JOIN t_resultinstrument ON T_ResultInstrumentT_OrderDetailID = x.T_OrderDetailID - LEFT JOIN pre_analytic ON PreAnalyticNat_TestID = a.T_TestNat_TestID AND PreAnalyticDate = date(now()) and PreAnalyticIsActive = 'Y' - WHERE x.T_OrderDetailT_OrderHeaderID = {$id} - AND x.T_OrderDetailIsActive = 'Y' - GROUP BY y.T_OrderDetailT_TestID - ORDER BY y.T_OrderDetailT_TestSasCode ASC - ) a1 - - LEFT JOIN t_orderdetail a2 ON a2.T_OrderDetailT_OrderHeaderID = a1.order_id - AND a2.T_OrderDetailIsActive = 'Y' - AND a1.test_sas_code LIKE CONCAT(a2.T_OrderDetailT_testSasCode, '%') - GROUP BY a1.t_testid - order by a1.test_sas_code -"; - //echo $sql; - $query = $this->db_smartone->query($sql); - $lq = $this->db_smartone->last_query(); - } - // file_put_contents("/xtmp/re-query.sql",$lq); - - if ($query) { - $rst = []; - $rows = $query->result_array(); - - foreach ($rows as $k => $v) { - - if ($v['is_result'] == "Y" && $v['is_quantitative'] == "N") { - $v['template'] = []; - $x = $this->db_smartone->query("CALL sp_master_resulttemplate_get('{$v['t_testid']}')"); - $this->clean_mysqli_connection($this->db_smartone->conn_id); - if ($x) - $v['template'] = $x->result_array(); - } - - // IF Rujukan, by pas Pre Analytik - if ($v['ref'] == 'Y') - $v['pre_analytic'] = 'Y'; - if ($v["id"] == "885455") { - //sipe workaround - //$v["sample_receive"] = "Y"; - $v["sample_worklist_receive"] = "Y"; - } - $rst[] = $v; - } - - $result = array("total" => $tot_count, "records" => $rst, "total_display" => sizeof($rows), "q" => $lq); - $this->sys_ok($result); - } else { - $this->sys_error_db("RE Px rows", $this->db_smartone); - exit; - } - } - - public function save() - { - $prm = $this->sys_input; - $data = json_decode($prm["data"]); - $lang = $this->lang_default_code; - $lang_id = isset($prm['lang_id']) ? $prm['lang_id'] : '0'; - - if ($lang_id != 0) { - $l = $this->db_smartone->where("Nat_LangID", $lang_id)->get("nat_lang")->row(); - $lang = $l->Nat_LangCode; - } - - $sql_norm = "select T_OrderDetailMinValue, T_OrderDetailMaxValue, - T_OrderDetailMinValueInclusive, T_OrderDetailMaxValueInclusive, - Nat_TestFlagLow, Nat_TestFlagHigh - from t_orderdetail - join t_test on T_OrderDetailT_TestID = T_TestID - join nat_test on T_TestNat_TestID = Nat_TestID and T_TestIsActive = 'Y' - where T_OrderDetailID = ? "; - - $ids = []; - foreach ($data as $k => $v) { - if ($v->resultInstrumentID > 0) { - $sql_i = "select T_ResultInstrumentNat_NormalValueID normalValueID - from t_resultinstrument - where T_ResultInstrumentID = ?"; - $qry_i = $this->db_smartone->query($sql_i, array($v->resultInstrumentID)); - if ($qry_i) { - $rows_i = $qry_i->result_array(); - - if (count($rows_i) > 0) { - $sql_iu = "update t_orderdetail, nat_normalvalue , nat_methode - set T_OrderDetailMinValue = Nat_NormalValueMinValue, - T_OrderDetailMinValueInclusive = Nat_NormalValueMinValueInclusive, - T_OrderDetailMaxValue = Nat_NormalValueMaxValue , - T_OrderDetailMaxValueInclusive = Nat_NormalValueMaxValueInclusive, - T_OrderDetailNormalValueNote = Nat_NormalValueNote, - T_OrderDetailNormalValueDescription = Nat_NormalValueDescription, - T_OrderDetailNat_NormalValueID = Nat_NormalValueID, - T_OrderDetailNat_MethodeID = Nat_NormalValueNat_MethodeID, - T_OrderDetailNat_MethodeName = Nat_MethodeName - where T_OrderDetailID = ? and Nat_NormalValueID = ? - and Nat_NormalValueNat_MethodeID = Nat_MethodeID - "; - $this->db_smartone->query($sql_iu, array($v->id, $rows_i[0]["normalValueID"])); - //file_put_contents("/xtmp/update-nilai-normal", $this->db_smartone->last_query() . "\n", FILE_APPEND); - } - } - } - $y = $this->db_smartone->query("SELECT fn_process_sample_handling_perfect('{$v->order_id}', '{$v->test_id}') c") - ->row(); - $req_status = $y->c; - $qry_norm = $this->db_smartone->query($sql_norm, $v->id); - $result_flag = ""; - if ($qry_norm) { - $rows_norm = $qry_norm->result_array(); - if (count($rows_norm) > 0) { - $r = $rows_norm[0]; - if (is_numeric($v->result)) { - - if ($r["T_OrderDetailMinValueInclusive"] == "Y" && $v->result < $r["T_OrderDetailMinValue"]) { - $result_flag = $r["Nat_TestFlagLow"]; - } - if ($r["T_OrderDetailMinValueInclusive"] == "N" && $v->result <= $r["T_OrderDetailMinValue"]) { - $result_flag = $r["Nat_TestFlagLow"]; - } - if ($r["T_OrderDetailMaxValueInclusive"] == "Y" && $v->result > $r["T_OrderDetailMaxValue"]) { - $result_flag = $r["Nat_TestFlagHigh"]; - } - if ($r["T_OrderDetailMaxValueInclusive"] == "N" && $v->result >= $r["T_OrderDetailMaxValue"]) { - $result_flag = $r["Nat_TestFlagHigh"]; - } - } - } - } - if ($lang == $this->lang_default_code) { - $this->db_smartone->set('T_OrderDetailResult', $v->result) - ->set('T_OrderDetailResultFlag', $result_flag) - ->set('T_OrderDetailNote', $v->note) - ->set('T_OrderDetailReqStatus', $req_status) - ->where('T_OrderDetailID', $v->id) - ->update('t_orderdetail'); - } else { - $this->db_smartone->set('T_OrderDetailLangResult', $v->result) - ->set('T_OrderDetailLangNote', $v->note) - ->where('T_OrderDetailLangID', $v->id) - ->update('t_orderdetaillang'); - } - - $ids[] = $v->id; - } - - // LOG Process - $order = $this->db_smartone->select('T_OrderDetailT_OrderHeaderID id, T_OrderHeaderLabNumber lab_number', false) - ->join('t_orderheader', 'T_OrderHeaderID = T_OrderDetailT_OrderHeaderID') - ->where('T_OrderDetailID', $data[0]->id) - ->get('t_orderdetail') - ->row(); - - $dblog = $this->load->database("onelog", true); - $dblog->set('Log_ProcessCode', 'PROCESS.Result.Entry') - ->set('Log_ProcessOrderID', $order->id) - ->set('Log_ProcessOrderNumber', $order->lab_number) - ->set('Log_ProcessJson', json_encode($data)) - ->set('Log_ProcessUserID', $this->sys_user['M_UserID']) - ->insert('log_process'); - // END OF Log Process - //auto calculation - $this->load->library("Resultcalc"); - $rows = $this->resultcalc->auto($order->id); - - try { - foreach ($ids as $id) { - $this->db_smartone->query("call sp_set_normal_value_flag($id)"); - $this->clean_mysqli_connection($this->db_smartone->conn_id); - } - } catch (Exception $e) { - } - - $this->sys_ok($ids); - } - - public function save_template() - { - $prm = $this->sys_input; - - $n = $this->db_smartone->select("COUNT(T_ResultTemplateID) n") - ->where("T_ResultTemplateT_TestID", $prm['test_id']) - ->where("T_ResultTemplateIsActive", "Y") - ->where("T_ResultTemplateValue", $prm['value']) - ->get('t_resulttemplate') - ->row(); - if ($n->n > 0) { - $this->sys_error_db("Insert Result Template", $this->db_smartone); - return; - } - - $r = $this->db_smartone->set("T_ResultTemplateT_TestID", $prm['test_id']) - ->set("T_ResultTemplateValue", $prm['value']) - ->insert('t_resulttemplate'); - if ($r) { - $template = []; - $x = $this->db_smartone->query("CALL sp_master_resulttemplate_get('{$prm['test_id']}')"); - $this->clean_mysqli_connection($this->db_smartone->conn_id); - if ($x) - $template = $x->result_array(); - - $this->sys_ok($template); - } - } - - public function export() - { - $prm = $this->sys_input; - - $sql = "CALL sp_process_result_lang(?, ?, ?, ?)"; - $query = $this->db_smartone->query($sql, [$prm['order_id'], $prm['lang_id'], $prm['is_si'], $this->sys_user['M_UserID']]); - if ($query) { - $r = $query->row(); - if ($r->status == "OK") { - $this->sys_ok($r->data); - return; - } - - $this->sys_error_db("Message : " . $r->message, $this->db_smartone); - } else { - $this->sys_error_db("Lang Result", $this->db_smartone); - return; - } - } - - public function search_group() - { - $prm = $this->sys_input; - $max_rst = 100; - - // QUERY TOTAL - $sql = "select count(*) total - from t_worklist - where T_WorklistIsActive = 'Y' - order by T_WorklistName ASC"; - $query = $this->db_smartone->query($sql); - - if ($query) { - $tot_count = $query->result_array()[0]["total"]; - } else { - $this->sys_error_db("worklist count", $this->db_smartone); - exit; - } - - $sql = "select T_WorklistID group_id, T_WorklistName group_name - from t_worklist - where T_WorklistIsActive = 'Y' - order by T_WorklistName ASC - limit 0, {$max_rst}"; - $query = $this->db_smartone->query($sql); - - if ($query) { - $rows = $query->result_array(); - foreach ($rows as $k => $v) - $rows[$k]['data'] = json_decode($v['data']); - $result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows), "q" => $this->db_smartone->last_query()); - $this->sys_ok($result); - } else { - $this->sys_error_db("worklist rows", $this->db_smartone); - exit; - } - } - - public function search_rerun() - { - $prm = $this->sys_input; - $id = $prm["detail_id"]; - - $sql = "CALL sp_process_result_rerun(?)"; - $query = $this->db_smartone->query($sql, [$id]); - - if ($query) { - $rows = $query->result_array(); - $this->sys_ok(["records" => $rows]); - } else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - - - function getdoctorsfna() - { - $prm = $this->sys_input; - // $id = $prm["id"]; - - $sql = " SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY M_DoctorName ASC"; - //echo $sql; - $query = $this->db_smartone->query($sql); - - if ($query) { - $rows = $query->result_array(); - $this->sys_ok(["records" => $rows]); - } else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - function getfnaresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT Other_FNADetailsID as xid, - Other_FNAT_OrderDetailID as orderdetail_id, - Other_FNADetailsCode as code, - Other_FNADetailsLabel as label, - Other_FNADetailsResult as result, - IFNULL(Other_FNAM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_FNAM_DoctorID) OR Other_FNAM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_fna - JOIN other_fnadetails ON Other_FNADetailsOther_FNAID = Other_FNAID AND Other_FNADetailsIsActive = 'Y' - LEFT JOIN m_doctor ON Other_FNAM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_FNAT_OrderDetailID = {$id} AND Other_FNAIsActive = 'Y' - GROUP BY Other_FNADetailsID - ORDER BY Other_FNADetailsCode ASC"; - $query = $this->db_smartone->query($sql); - - if ($query) { - $rows = $query->result_array(); - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $images = array(); - $sql = "SELECT So_ImageUploadID as xid, - CONCAT('/one-media/one-image-nonlab/',So_ImageUploadNewName) as image_url - FROM t_orderdetail - JOIN so_imageupload ON So_ImageUploadT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND - So_ImageUploadIsActive = 'Y' - WHERE - T_OrderDetailID = {$id} AND - T_OrderDetailIsActive = 'Y' - GROUP BY So_ImageUploadID"; - $images = $this->db_smartone->query($sql)->result_array(); - - $rst = array('doctors' => $doctors, 'results' => $rows, 'images' => $images); - $this->sys_ok(["records" => $rst]); - } else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - function getpatologianatomyresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT Other_PatologiAnatomyID as xid, - Other_PatologiAnatomyT_OrderDetailID as orderdetail_id, - Other_PatologiAnatomyNoSediaan as no_sediaan, - Other_PatologiAnatomyDiagnosaKlinis as diagnosa, - Other_PatologiAnatomyKeteranganKlinis as klinis, - Other_PatologiAnatomyLokasiOrgan as lokasi, - Other_PatologiAnatomyMakroskopik as makroskopik, - Other_PatologiAnatomyMikroskopik as mikroskopik, - Other_PatologiAnatomyKesimpulan as kesimpulan, - IFNULL(Other_PatologiAnatomyM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_PatologiAnatomyM_DoctorID) OR Other_PatologiAnatomyM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_patologi_anatomy - LEFT JOIN m_doctor ON Other_PatologiAnatomyM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_PatologiAnatomyT_OrderDetailID = {$id} AND Other_PatologiAnatomyIsActive = 'Y' - GROUP BY Other_PatologiAnatomyID - ORDER BY Other_PatologiAnatomyID ASC - LIMIT 1"; - $query = $this->db_smartone->query($sql); - - if ($query) { - $rows = $query->row_array(); - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - - $sql = "SELECT So_ImageUploadPatologyAnatomyID as xid, - CONCAT('/one-media/one-image-nonlab/',So_ImageUploadPatologyAnatomyNewName) as image_url, - So_ImageUploadPatologyAnatomyType as type - FROM t_orderdetail - JOIN so_imageupload_patology_anatomy ON So_ImageUploadPatologyAnatomyT_OrderHeaderID= T_OrderDetailT_OrderHeaderID AND - So_ImageUploadPatologyAnatomyIsActive= 'Y' - WHERE - T_OrderDetailID = {$id} AND - T_OrderDetailIsActive = 'Y' - GROUP BY So_ImageUploadPatologyAnatomyID"; - $images = $this->db_smartone->query($sql)->result_array(); - $mikro = []; - $makro = []; - - foreach ($images as $key => $value) { - - if ($value['type'] == 'mikro') { - $mikro[] = $value; - } - if ($value['type'] == 'makro') { - $makro[] = $value; - } - } - - $rst = array('doctors' => $doctors, 'result' => $rows, "mikro" => $mikro, "makro" => $makro); - $this->sys_ok(["records" => $rst]); - } else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - - function uploadimage() - { - if (! $this->isLogin) { - $this->sys_error("Invalid Token"); - exit; - } - - $userid = $this->sys_user["M_UserID"]; - $data = []; - //print_r($_SERVER); - - $prm = $this->sys_input; - $orderid = $this->input->post('orderid'); - $labnumber = $this->input->post('labnumber'); - $sql = "UPDATE so_imageupload SET - So_ImageUploadIsActive = 'N', - So_ImageUploadUserID = {$userid} - WHERE - So_ImageUploadT_OrderHeaderID = {$orderid}"; - //echo $sql; - $this->db_onedev->query($sql); - //$config['upload_path'] = 'assets/'; - - $path = '/home/one/project/one/one-media/one-image-nonlab/'; - //echo $path; - $config['upload_path'] = $path; - $config['allowed_types'] = 'jpg|jpeg|png|gif'; - - $config['max_size'] = '10000'; - $count = count($_FILES['files']['name']); - //echo $count; - $this->load->library('upload', $config); - - $error = []; - for ($i = 0; $i < $count; $i++) { - - - if (!empty($_FILES['files']['name'][$i])) { - - - - $_FILES['file']['name'] = $_FILES['files']['name'][$i]; - - $_FILES['file']['type'] = $_FILES['files']['type'][$i]; - - $_FILES['file']['tmp_name'] = $_FILES['files']['tmp_name'][$i]; - - $_FILES['file']['error'] = $_FILES['files']['error'][$i]; - - $_FILES['file']['size'] = $_FILES['files']['size'][$i]; - - - - $namex = $orderid . '-' . $labnumber . '-' . $this->generateRandomString(5); - //echo $namex; - - $config['file_name'] = $namex; - $this->upload->initialize($config); - //echo $config['file_name'] ; - - - - - - if ($this->upload->do_upload('file')) { - - $uploadData = $this->upload->data(); - - $filename = $uploadData['file_name']; - //echo $filename; - - - $sql = "INSERT INTO so_imageupload ( - So_ImageUploadT_OrderHeaderID, - So_ImageUploadT_OrderHeaderLabNumber, - So_ImageUploadT_SampleTypeID, - So_ImageUploadOldName, - So_ImageUploadNewName, - So_ImageUploadCreated, - So_ImageUploadUserID - ) - VALUES( - {$orderid}, - '{$labnumber}', - '150', - '{$_FILES['files']['name'][$i]}', - '{$filename}', - NOW(), - {$userid} - - )"; - //echo $sql; - $this->db_onedev->query($sql); - $xlast_id = $this->db_onedev->insert_id(); - $data['totalFiles'][] = array('xid' => $xlast_id, 'image_url' => '/one-media/one-image-nonlab/' . $filename); - } else { - $error = array('error' => $this->upload->display_errors()); - } - } - } - - $result = array("total" => count($data['totalFiles']), "records" => $data['totalFiles'], 'errors' => $error); - $this->sys_ok($result); - } - - - function generateRandomString($length = 10) - { - $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; - $charactersLength = strlen($characters); - $randomString = ''; - for ($i = 0; $i < $length; $i++) { - $randomString .= $characters[rand(0, $charactersLength - 1)]; - } - return $randomString; - } - - function getcytologiresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT Other_CytologiDetailsID as xid, - Other_CytologiT_OrderDetailID as orderdetail_id, - Other_CytologiDetailsCode as code, - Other_CytologiDetailsLabel as label, - Other_CytologiDetailsResult as result, - IFNULL(Other_CytologiM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_CytologiM_DoctorID) OR Other_CytologiM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_cytologi - JOIN other_cytologidetails ON Other_CytologiDetailsOther_CytologiID = Other_CytologiID AND Other_CytologiDetailsIsActive = 'Y' - LEFT JOIN m_doctor ON Other_CytologiM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_CytologiT_OrderDetailID = {$id} AND Other_CytologiIsActive = 'Y' - GROUP BY Other_CytologiDetailsID - ORDER BY Other_CytologiDetailsCode ASC"; - //echo $sql; - $query = $this->db_smartone->query($sql); - - if ($query) { - $rows = $query->result_array(); - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $rst = array('doctors' => $doctors, 'results' => $rows); - $this->sys_ok(["records" => $rst]); - } else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - function getmikroresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT - Other_MikroID as xid, - Other_MikroHasilBiakan as hasil_biakan, - Other_MikroSampleTypeName as sample_name, - Other_MikroT_OrderDetailID as orderdetail_id, - Other_MikroResult as result_value, - '' as result_other, - IFNULL(T_BacteriaID,0) as T_BacteriaID, - IFNULL(T_BacteriaName,'') as T_BacteriaName, - '' as details, - IFNULL(Other_MikroM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_MikroM_DoctorID) OR Other_MikroM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_mikro - LEFT JOIN t_bacteria ON Other_MikroT_BacteriaID = T_BacteriaID - LEFT JOIN m_doctor ON Other_MikroM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_MikroT_OrderDetailID = {$id} AND Other_MikroIsActive = 'Y' - GROUP BY Other_MikroID"; - //echo $sql; - $query = $this->db_smartone->query($sql); - - if ($query) { - $row = $query->row_array(); - if ($row) { - if ($row['result_value'] != 'Positif' && $row['result_value'] != 'Negatif') { - $row['result_other'] = $row['result_value']; - $row['result_value'] = 'other'; - } - $sql = "SELECT '' as xno, - Other_MikroDetailsID as xid, - Other_MikroDetailsValue as value, - IF(Other_MikroDetailsNote = 'R','Y','N') as chx_r, - IF(Other_MikroDetailsNote = 'I','Y','N') as chx_i, - IF(Other_MikroDetailsNote = 'S','Y','N') as chx_s, - Other_MikroDetailsNote as note, - t_antibiotic.* - FROM other_mikrodetails - LEFT JOIN t_antibiotic ON Other_MikroDetailsT_AntibioticID = T_AntibioticID - WHERE - Other_MikroDetailsOther_MikroID = {$row['xid']} AND Other_MikroDetailsIsActive = 'Y' - GROUP BY Other_MikroDetailsID - ORDER BY T_AntibioticName ASC"; - //echo $sql; - $details = $this->db_smartone->query($sql)->result_array(); - if (details) { - foreach ($details as $k => $v) { - $details[$k]['xno'] = $k + 1; - } - } - $row['details'] = $details; - } else { - $row = array('xid' => '0', 'hasil_biakan' => '', 'result_value' => 'Negatif', 'sample_name' => '', 'orderdetail_id' => $id, 'T_BacteriaID' => '0', 'T_BacteriaName' => '0', 'details' => array(), 'doctor_id' => '0', 'doctor_name' => '0'); - } - } else { - $row = array('xid' => '0', 'hasil_biakan' => '', 'result_value' => 'Negatif', 'sample_name' => '', 'orderdetail_id' => $id, 'T_BacteriaID' => '0', 'T_BacteriaName' => '0', 'details' => array(), 'doctor_id' => '0', 'doctor_name' => '0'); - } - //print_r($row); - - - - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 7 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $sql = " - SELECT '0' as id, 'Belum memilih bakteria' as name - UNION - SELECT T_BacteriaID as id, T_BacteriaName as name - FROM t_bacteria - WHERE - T_BacteriaIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $bacteries = $this->db_smartone->query($sql)->result_array(); - $rst = array('doctors' => $doctors, 'bacteries' => $bacteries, 'results' => $row); - $this->sys_ok(["records" => $rst]); - } - function getantibiotics() - { - $prm = $this->sys_input; - $id = $prm["id"]; - $sql = " SELECT '' as xno, - 0 as xid, - '' as hasil_biakan, - '' as sample_name, - 0 as value, - 'Y' as chx_r, - 'N' as chx_i, - 'N' as chx_s, - 'R' as note, - t_antibiotic.* - FROM t_antibiotic - WHERE - T_AntibioticT_BacteriaID = {$prm['id']} AND T_AntibioticIsActive= 'Y' - ORDER BY T_AntibioticName ASC"; - //echo $sql; - $rows = $this->db_smartone->query($sql)->result_array(); - if (rows) { - foreach ($rows as $k => $v) { - $rows[$k]['xno'] = $k + 1; - } - } - - $this->sys_ok(["records" => $rows]); - } - function getlcprepresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - $sql = " SELECT Other_LcprepDetailsID as xid, - Other_LcprepID as header_id, - Other_LcprepT_orderDetailID as orderdetail_id, - Other_LcprepDetailsCode as code, - Other_LcprepDetailsLabel as label, - Other_LcprepDetailsResult as result, - IFNULL(Other_LcprepM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_LcprepM_DoctorID) OR Other_LcprepM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_lcprep - JOIN other_lcprepdetails ON Other_LcprepDetailsOther_LcprepID = Other_LcprepID AND Other_LcprepDetailsIsActive = 'Y' - LEFT JOIN m_doctor ON Other_LcprepM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_LcprepT_orderDetailID = {$id} AND Other_LcprepIsActive = 'Y' - GROUP BY Other_LcprepDetailsOther_LcprepID, Other_LcprepDetailsCode - ORDER BY Other_LcprepDetailsCode ASC"; - //echo $sql; - $rows = $this->db_smartone->query($sql)->result_array(); - if (!$rows) { - $rows = array( - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'A', - 'label' => 'DESKRIPSI', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ), - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'B', - 'label' => 'KESIMPULAN', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ) - ); - } - - $header_id = $rows[0]['header_id']; - $sql = "SELECT IFNULL(Other_LcprepAdekuasiID,0) as xid, - Lcprep_AdekuasiID as id, - Lcprep_AdekuasiLabel as name, - IF(ISNULL(Other_LcprepAdekuasiID),'N',Other_LcprepAdekuasiChex) as chex - FROM lcprep_adekuasi - LEFT JOIN other_lcprepadekuasi ON Other_LcprepAdekuasiLcprep_AdekuasiID = Lcprep_AdekuasiID AND - Other_LcprepAdekuasiOther_LcprepID = {$header_id} AND - Other_LcprepAdekuasiIsActive = 'Y' - WHERE - Lcprep_AdekuasiIsActive = 'Y' - GROUP BY Lcprep_AdekuasiID - ORDER BY Lcprep_AdekuasiOrder ASC - "; - //echo $sql; - $adeakuasi = $this->db_smartone->query($sql)->result_array(); - foreach ($adeakuasi as $kc => $vc) { - $adeakuasi[$kc]['chex'] = $vc['chex'] == 'N' ? false : true; - } - - $sql = "SELECT IFNULL(Other_LcprepKategoriUmumID,0) as xid, - Lcprep_KategoriUmumID as id, - Lcprep_KategoriUmumLabel as name, - IF(ISNULL(Other_LcprepKategoriUmumID),'N',Other_LcprepKategoriUmumChex) as chex - FROM lcprep_kategoriumum - LEFT JOIN other_lcprepkategoriumum ON Other_LcprepKategoriUmumLcprep_KategoriUmumID = Lcprep_KategoriUmumID AND - Other_LcprepKategoriUmumOther_LcprepID = {$header_id} AND - Other_LcprepKategoriUmumIsActive = 'Y' - WHERE - Lcprep_KategoriUmumIsActive = 'Y' - GROUP BY Lcprep_KategoriUmumID - "; - //echo $sql; - $kategoriumum = $this->db_smartone->query($sql)->result_array(); - foreach ($kategoriumum as $kc => $vc) { - $kategoriumum[$kc]['chex'] = $vc['chex'] == 'N' ? false : true; - } - - $sql = " - SELECT Lcprep_InterpretasiGroupID as group_id, - Lcprep_InterpretasiGroupName as group_name, - '' as subgroups - FROM lcprep_interpretasigroup - WHERE - Lcprep_InterpretasiGroupIsActive = 'Y' - "; - //echo $sql; - $interpretasi = $this->db_smartone->query($sql)->result_array(); - foreach ($interpretasi as $k => $v) { - $subgroups = array(); - $sql = "SELECT Lcprep_InterpretasiSubgroupID as subgroup_id, - Lcprep_InterpretasiSubgroupName as subgroup_name, - '' as childs - FROM lcprep_interpretasisubgroup - WHERE - Lcprep_InterpretasiSubgroupLcprep_InterpretasiGroupID = {$v['group_id']} AND Lcprep_InterpretasiSubgroupIsActive = 'Y'"; - //echo $sql; - $subgroups = $this->db_smartone->query($sql)->result_array(); - if (count($subgroups) > 0) { - foreach ($subgroups as $ki => $vi) { - $childs = array(); - $sql = "SELECT IFNULL(Other_LcprepInterpretasiID,0) as xid, - IFNULL(Other_LcprepInterpretasiChex,'N') as chex, - IFNULL(Other_LcprepInterpretasiValue,'') as value, - Lcprep_InterpretasiID as id, - Lcprep_InterpretasiLcprep_InterpretasiSubgroupID as subgroup_id, - Lcprep_InterpretasiCode as code, - Lcprep_InterpretasiName as name, - Lcprep_InterpretasiParentID as parent_id, - Lcprep_InterpretasiIsParent as is_parent, - Lcprep_InterpretasiHasResult as has_result, - Lcprep_InterpretasiTypeResult as type_result - FROM lcprep_interpretasi - LEFT JOIN other_lcprepinterpretasi ON Other_LcprepInterpretasiOther_LcprepID = {$header_id} AND - Other_LcprepInterpretasiLcprep_InterpretasiID = Lcprep_InterpretasiID AND - Other_LcprepInterpretasiIsActive = 'Y' - WHERE - Lcprep_InterpretasiLcprep_InterpretasiSubgroupID = {$vi['subgroup_id']} AND Lcprep_InterpretasiIsActive = 'Y' - GROUP BY Lcprep_InterpretasiID Order BY Lcprep_InterpretasiCode ASC"; - $childs = $this->db_smartone->query($sql)->result_array(); - if ($childs) { - foreach ($childs as $kc => $vc) { - $childs[$kc]['chex'] = $vc['chex'] == 'N' ? false : true; - } - } - $subgroups[$ki]['childs'] = $childs; - } - } - - $interpretasi[$k]['subgroups'] = $subgroups; - } - - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $rst = array('doctors' => $doctors, 'results' => $rows, 'adekuasi' => $adeakuasi, 'kategoriumum' => $kategoriumum, 'interpretasi' => $interpretasi); - $this->sys_ok(["records" => $rst]); - } - - function getpapsmearresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT Other_PapSmearDetailsID as xid, - Other_PapSmearID as header_id, - Other_PapSmearT_OrderDetailID as orderdetail_id, - Other_PapSmearDetailsCode as code, - Other_PapSmearDetailsLabel as label, - Other_PapSmearDetailsResult as result, - IFNULL(Other_PapSmearM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_PapSmearM_DoctorID) OR Other_PapSmearM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_papsmear - JOIN other_papsmeardetails ON Other_PapSmearDetailsOther_PapSmearID = Other_PapSmearID AND Other_PapSmearDetailsIsActive = 'Y' - LEFT JOIN m_doctor ON Other_PapSmearM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_PapSmearT_OrderDetailID = {$id} AND Other_PapSmearIsActive = 'Y' - GROUP BY Other_PapSmearDetailsID - ORDER BY Other_PapSmearDetailsCode ASC"; - //echo $sql; - $rows = $this->db_smartone->query($sql)->result_array(); - if (!$rows) { - $rows = array( - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'A', - 'label' => 'Makroskopik', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ), - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'B', - 'label' => 'Mikroskopik', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ), - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'C', - 'label' => 'Kesimpulan', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ) - ); - } - - $header_id = $rows[0]['header_id']; - $sql = "SELECT Other_PapSmearMaturasiID as xid, - Other_PapSmearMaturasiValue as value - FROM other_papsmearmaturasi - WHERE - Other_PapSmearMaturasiOther_PapSmearID = {$header_id} AND - Other_PapSmearMaturasiIsActive = 'Y' - "; - //echo $sql; - $dt_maturasi = $this->db_smartone->query($sql)->row_array(); - if (!$dt_maturasi) { - $maturasi = array('xid' => '0', 'value' => array('', '', '')); - } else { - $value = explode('/', $dt_maturasi['value']); - $maturasi = array('xid' => $dt_maturasi['xid'], 'value' => $value); - } - - $sql = "SELECT IFNULL(Other_PapSmearBahanID,0) as xid, - M_PapSmearBahanID as bahan_id, - M_PapSmearBahanName as name, - IF(ISNULL(Other_PapSmearBahanID),'N','Y') as selected - FROM m_papsmearbahan - LEFT JOIN other_papsmearbahan ON Other_PapSmearBahanM_PapSmearBahanID = M_PapSmearBahanID AND - Other_PapSmearBahanOther_PapSmearID = {$header_id} AND - Other_PapSmearBahanIsActive = 'Y' - WHERE - M_PapSmearBahanIsActive = 'Y' - ORDER BY M_PapSmearBahanID ASC - "; - //echo $sql; - $bahans = $this->db_smartone->query($sql)->result_array(); - - $sql = "SELECT IFNULL(Other_PapsmearCategoryID,0) as xid, - M_PapSmearCategoryID as category_id, - M_PapSmearCategoryName as name, - IF(ISNULL(Other_PapsmearCategoryID),'N','Y') as selected - FROM m_papsmearcategory - LEFT JOIN other_papsmearcategory ON Other_PapsmearCategoryM_PapSmearCategoryID = M_PapSmearCategoryID AND - Other_PapsmearCategoryOther_PapSmearID = {$header_id} AND - Other_PapsmearCategoryIsActive = 'Y' - WHERE - M_PapSmearCategoryIsActive = 'Y' - ORDER BY M_PapSmearCategoryID ASC - "; - //echo $sql; - $categories = $this->db_smartone->query($sql)->result_array(); - - $sql = "SELECT IFNULL(Other_PapSmearCheckID,0) as xid, - M_PapSmearCheckID as check_id, - M_PapSmearCheckLabel as name, - IF(ISNULL(Other_PapSmearCheckID),'N','Y') as selected, - Other_PapSmearCheckNote as note - FROM m_papsmearcheck - LEFT JOIN other_papsmearcheck ON Other_PapSmearCheckM_PapSmearCheckID = M_PapSmearCheckID AND - Other_PapSmearCheckOther_PapSmearID = {$header_id} AND - Other_PapSmearCheckIsActive = 'Y' - WHERE - M_PapSmearCheckIsActive = 'Y' - ORDER BY M_PapSmearCheckCode ASC - "; - $checks = $this->db_smartone->query($sql)->result_array(); - - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $rst = array('doctors' => $doctors, 'checks' => $checks, 'bahans' => $bahans, 'categories' => $categories, 'maturasi' => $maturasi, 'results' => $rows); - $this->sys_ok(["records" => $rst]); - } - - function saveresult_lcprep() - { - $prm = $this->sys_input; - $detail_id = $prm['detail_id']; - $doctor_id = $prm['doctor']; - $adekuasi = $prm['adekuasi']; - $kategoriumum = $prm['kategoriumum']; - $interpretasi = $prm['interpretasi']; - $results = $prm['results']; - - $userid = $this->sys_user['M_UserID']; - - $header_id = 0; - $sql = "SELECT * FROM other_lcprep WHERE Other_LcprepT_orderDetailID = {$detail_id} AND Other_LcprepIsActive = 'Y'"; - $dt_header = $this->db_smartone->query($sql)->row_array(); - if ($dt_header) { - $header_id = $dt_header['Other_LcprepID']; - } - if ($header_id == 0) { - $sql = "INSERT INTO other_lcprep( - Other_LcprepT_orderDetailID, - Other_LcprepM_DoctorID, - Other_LcprepUserID, - Other_LcprepCreated - ) - VALUES( - {$detail_id}, - {$doctor_id}, - {$userid}, - NOW() - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } else { - $sql = "UPDATE other_lcprep SET Other_LcprepM_DoctorID = {$doctor_id}, Other_LcprepUserID = {$userid} WHERE Other_LcprepID = {$header_id}"; - $this->db_smartone->query($sql); - } - - if ($adekuasi) { - foreach ($adekuasi as $k => $v) { - $selected = $v['chex'] ? 'Y' : 'N'; - if (intval($v['xid'] == 0)) { - $sql = "UPDATE other_lcprepadekuasi SET Other_LcprepAdekuasiIsActive = 'N' - WHERE - Other_LcprepAdekuasiOther_LcprepID = {$header_id} AND - Other_LcprepAdekuasiIsActive = 'Y' AND - Other_LcprepAdekuasiLcprep_AdekuasiID = {$v['id']}"; - $this->db_smartone->query($sql); - $sql = "INSERT INTO other_lcprepadekuasi ( - Other_LcprepAdekuasiOther_LcprepID, - Other_LcprepAdekuasiLcprep_AdekuasiID, - Other_LcprepAdekuasiChex, - Other_LcprepAdekuasiUserID, - Other_LcprepAdekuasiCreated - ) - VALUES( - {$header_id}, - {$v['id']}, - '{$selected}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - //echo $sql; - } - if (intval($v['xid'] != 0)) { - - $sql = "UPDATE other_lcprepadekuasi SET - Other_LcprepAdekuasiChex = '{$selected}', - Other_LcprepAdekuasiUserID = {$userid} - WHERE - Other_LcprepAdekuasiID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - - //echo $sql; - } - } - - if ($kategoriumum) { - foreach ($kategoriumum as $k => $v) { - $selected = $v['chex'] ? 'Y' : 'N'; - if (intval($v['xid'] == 0)) { - $sql = "UPDATE other_lcprepkategoriumum SET Other_LcprepKategoriUmumIsActive = 'N' - WHERE - Other_LcprepKategoriUmumOther_LcprepID = {$header_id} AND - Other_LcprepKategoriUmumLcprep_KategoriUmumID = {$v['id']} AND - Other_LcprepKategoriUmumIsActive = 'Y' - "; - $this->db_smartone->query($sql); - $sql = "INSERT INTO other_lcprepkategoriumum ( - Other_LcprepKategoriUmumOther_LcprepID, - Other_LcprepKategoriUmumLcprep_KategoriUmumID, - Other_LcprepKategoriUmumChex, - Other_LcprepKategoriUmumUserID, - Other_LcprepKategoriUmumCreated - ) - VALUES( - {$header_id}, - {$v['id']}, - '{$selected}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if (intval($v['xid'] != 0)) { - $sql = "UPDATE other_lcprepkategoriumum SET - Other_LcprepKategoriUmumChex = '{$selected}', - Other_LcprepKategoriUmumUserID = {$userid} - WHERE - Other_LcprepKategoriUmumID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - - //echo $sql; - } - } - - if ($results) { - foreach ($results as $k => $v) { - if (intval($v['xid'] == 0)) { - $sql = "UPDATE other_lcprepdetails SET Other_LcprepDetailsIsActive = 'N' - WHERE - Other_LcprepDetailsOther_LcprepID = {$header_id} AND - Other_LcprepDetailsCode = '{$v['code']}' AND - Other_LcprepDetailsIsActive = 'Y'"; - $this->db_smartone->query($sql); - $sql = "INSERT INTO other_lcprepdetails ( - Other_LcprepDetailsOther_LcprepID, - Other_LcprepDetailsCode, - Other_LcprepDetailsLabel, - Other_LcprepDetailsResult, - Other_LcprepDetailsUserID, - Other_LcprepDetailsCreated - ) - VALUES( - {$header_id}, - '{$v['code']}', - '{$v['label']}', - '{$v['result']}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if (intval($v['xid'] != 0)) { - $sql = "UPDATE other_lcprepdetails SET - Other_LcprepDetailsCode = '{$v['code']}', - Other_LcprepDetailsLabel = '{$v['label']}', - Other_LcprepDetailsResult = '{$v['result']}', - Other_LcprepDetailsUserID = {$userid} - WHERE - Other_LcprepDetailsID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - //echo $sql; - } - } - - if ($interpretasi) { - foreach ($interpretasi as $k => $v) { - if (count($v['subgroups']) > 0) { - foreach ($v['subgroups'] as $ik => $iv) { - if (count($iv['childs']) > 0) { - foreach ($iv['childs'] as $iik => $iiv) { - if (intval($iiv['xid'] == 0)) { - $chex = $iiv['chex'] ? 'Y' : 'N'; - $sql = "UPDATE other_lcprepinterpretasi SET Other_LcprepInterpretasiIsActive = 'N' - WHERE - Other_LcprepInterpretasiOther_LcprepID = {$header_id} AND - Other_LcprepInterpretasiLcprep_InterpretasiID = '{$iiv['id']}' AND - Other_LcprepInterpretasiIsActive = 'Y'"; - $this->db_smartone->query($sql); - $sql = "INSERT INTO other_lcprepinterpretasi ( - Other_LcprepInterpretasiOther_LcprepID, - Other_LcprepInterpretasiLcprep_InterpretasiID, - Other_LcprepInterpretasiChex, - Other_LcprepInterpretasiValue, - Other_LcprepInterpretasiUserID, - Other_LcprepInterpretasiCreated - ) - VALUES( - {$header_id}, - '{$iiv['id']}', - '{$chex}', - '{$iiv['value']}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - - if (intval($iiv['xid'] != 0)) { - $chex = $iiv['chex'] ? 'Y' : 'N'; - $sql = "UPDATE other_lcprepinterpretasi SET - Other_LcprepInterpretasiChex = '{$chex}', - Other_LcprepInterpretasiValue = '{$iiv['value']}', - Other_LcprepInterpretasiUserID = {$userid} - WHERE - Other_LcprepInterpretasiID = {$iiv['xid']}"; - $this->db_smartone->query($sql); - //echo $sql; - - } - } - } - } - } - //echo $sql; - } - } - - - $result = array("total" => 1, "records" => array(), "sql" => ''); - $this->sys_ok($result); - exit; - } - - function saveresult_papsmear() - { - $prm = $this->sys_input; - $detail_id = $prm['detail_id']; - $doctor_id = $prm['doctor']; - $checks = $prm['checks']; - $maturasi = $prm['maturasi']; - $bahans = $prm['bahans']; - $categories = $prm['categories']; - $results = $prm['results']; - - $userid = $this->sys_user['M_UserID']; - - $header_id = 0; - $sql = "SELECT * FROM other_papsmear WHERE Other_PapSmearT_OrderDetailID = {$detail_id} AND Other_PapSmearIsActive = 'Y'"; - $dt_header = $this->db_smartone->query($sql)->row_array(); - if ($dt_header) { - $header_id = $dt_header['Other_PapSmearID']; - } - if ($header_id == 0) { - $sql = "INSERT INTO other_papsmear( - Other_PapSmearT_OrderDetailID, - Other_PapSmearM_DoctorID, - Other_PapSmearUserID, - Other_PapSmearCreated - ) - VALUES( - {$detail_id}, - {$doctor_id}, - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } else { - $sql = "UPDATE other_papsmear SET Other_PapSmearM_DoctorID = {$doctor_id}, Other_PapSmearUserID = {$userid} WHERE Other_PapSmearID = {$header_id}"; - $this->db_smartone->query($sql); - } - - if ($checks) { - foreach ($checks as $k => $v) { - if (intval($v['xid']) == 0 && $v['selected'] === 'Y') { - $sql = "INSERT INTO other_papsmearcheck ( - Other_PapSmearCheckOther_PapSmearID, - Other_PapSmearCheckM_PapSmearCheckID, - Other_PapSmearCheckNote, - Other_PapSmearCheckUserID, - Other_PapSmearCheckCreated - ) - VALUES( - {$header_id}, - {$v['check_id']}, - '{$v['note']}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if (intval($v['xid']) != 0 && $v['selected'] === 'N') { - $sql = "UPDATE other_papsmearcheck SET - Other_PapSmearCheckIsActive = 'N', - Other_PapSmearCheckUserID = {$userid} - WHERE - Other_PapSmearCheckID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - if (intval($v['xid']) != 0 && $v['selected'] === 'Y') { - $sql = "UPDATE other_papsmearcheck SET - Other_PapSmearCheckNote = '{$v['note']}', - Other_PapSmearCheckUserID = {$userid} - WHERE - Other_PapSmearCheckID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - //echo $sql; - } - } - - if ($maturasi) { - if (intval($maturasi['xid']) == 0) { - $value = join("/", $maturasi['value']); - $sql = "INSERT INTO other_papsmearmaturasi ( - Other_PapSmearMaturasiOther_PapSmearID, - Other_PapSmearMaturasiValue, - Other_PapSmearMaturasiUserID, - Other_PapSmearMaturasiCreated - ) - VALUE( - {$header_id}, - '{$value}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - //echo $sql; - } - if (intval($maturasi['xid']) != 0) { - $value = join("/", $maturasi['value']); - $sql = "UPDATE other_papsmearmaturasi SET - Other_PapSmearMaturasiValue = '{$value}', - Other_PapSmearMaturasiUserID = {$userid} - WHERE - Other_PapSmearMaturasiID = {$maturasi['xid']}"; - // echo $sql; - $this->db_smartone->query($sql); - } - } - - if ($bahans) { - foreach ($bahans as $k => $v) { - if (intval($v['xid']) == 0 && $v['selected'] === 'Y') { - $sql = "INSERT INTO other_papsmearbahan ( - Other_PapSmearBahanOther_PapSmearID, - Other_PapSmearBahanM_PapSmearBahanID, - Other_PapSmearBahanUserID, - Other_PapSmearBahanCreated - ) - VALUES( - {$header_id}, - {$v['bahan_id']}, - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if (intval($v['xid']) != 0 && $v['selected'] === 'N') { - $sql = "UPDATE other_papsmearbahan SET - Other_PapSmearBahanIsActive = 'N', - Other_PapsmearCategoryUserID = {$userid} - WHERE - Other_PapSmearBahanID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - if (intval($v['xid']) != 0 && $v['selected'] === 'Y') { - $sql = "UPDATE other_papsmearbahan SET - Other_PapSmearBahanIsActive = 'Y', - Other_PapsmearCategoryUserID = {$userid} - WHERE - Other_PapSmearBahanID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - //echo $sql; - } - } - - if ($categories) { - foreach ($categories as $k => $v) { - if (intval($v['xid']) == 0 && $v['selected'] === 'Y') { - $sql = "INSERT INTO other_papsmearcategory ( - Other_PapsmearCategoryOther_PapSmearID, - Other_PapsmearCategoryM_PapSmearCategoryID, - Other_PapsmearCategoryUserID, - Other_PapsmearCategoryCreated - ) - VALUES( - {$header_id}, - {$v['category_id']}, - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if (intval($v['xid']) != 0 && $v['selected'] === 'N') { - $sql = "UPDATE other_papsmearcategory SET - Other_PapsmearCategoryIsActive = 'N', - Other_PapsmearCategoryUserID = {$userid} - WHERE - Other_PapsmearCategoryID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - //echo $sql; - if (intval($v['xid']) != 0 && $v['selected'] === 'Y') { - $sql = "UPDATE other_papsmearcategory SET - Other_PapsmearCategoryIsActive = 'Y', - Other_PapsmearCategoryUserID = {$userid} - WHERE - Other_PapsmearCategoryID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - } - } - - if ($results) { - foreach ($results as $k => $v) { - if (intval($v['xid']) == 0) { - $sql = "INSERT INTO other_papsmeardetails ( - Other_PapSmearDetailsOther_PapSmearID, - Other_PapSmearDetailsCode, - Other_PapSmearDetailsLabel, - Other_PapSmearDetailsResult, - Other_PapSmearDetailsUserID, - Other_PapSmearDetailsCreated - ) - VALUES( - {$header_id}, - '{$v['code']}', - '{$v['label']}', - '{$v['result']}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if (intval($v['xid']) != 0) { - $sql = "UPDATE other_papsmeardetails SET - Other_PapSmearDetailsCode = '{$v['code']}', - Other_PapSmearDetailsLabel = '{$v['label']}', - Other_PapSmearDetailsResult = '{$v['result']}', - Other_PapSmearDetailsUserID = {$userid} - WHERE - Other_PapSmearDetailsID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - //echo $sql; - } - } - - $result = array("total" => 1, "records" => array(), "sql" => ''); - $this->sys_ok($result); - exit; - } - - function saveresult_fna() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = $inp['doctor']; - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - if ($prm[0]['xid'] == '0') { - $sql = "INSERT INTO other_fna( - Other_FNAM_DoctorID, - Other_FNAT_OrderDetailID, - Other_FNAUserID, - Other_FNACreated - ) - VALUES( - {$doctor_id}, - {$prm[0]['orderdetail_id']}, - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } else { - $sql = "SELECT * FROM other_fna WHERE Other_FNAT_OrderDetailID = {$prm[0]['orderdetail_id']} AND Other_FNAIsActive = 'Y'"; - $data_header = $this->db_smartone->query($sql)->row_array(); - $header_id = $data_header['Other_FNAID']; - $sql = "UPDATE other_fna SET - Other_FNAM_DoctorID = {$doctor_id}, - Other_FNAUserID = {$userid} - WHERE - Other_FNAID = {$header_id}"; - $this->db_smartone->query($sql); - } - foreach ($prm as $k => $v) { - if ($v['xid'] == '0') { - $results = str_replace("'", "\\'", $v['result']); - $sql = "INSERT INTO other_fnadetails( - Other_FNADetailsOther_FNAID , - Other_FNADetailsCode, - Other_FNADetailsLabel, - Other_FNADetailsResult, - Other_FNADetailsCreated, - Other_FNADetailsUserID - ) - VALUES( - {$header_id}, - '{$v['code']}', - '{$v['label']}', - '{$results}', - NOW(), - {$userid} - )"; - $query = $this->db_smartone->query($sql); - } else { - $results = str_replace("'", "\\'", $v['result']); - $sql = "UPDATE other_fnadetails SET - Other_FNADetailsResult = '{$results}', - Other_FNADetailsUserID = {$userid} - WHERE - Other_FNADetailsID = {$v['xid']}"; - $query = $this->db_smartone->query($sql); - } - } - - $result = array("total" => 1, "records" => array(), "sql" => ''); - $this->sys_ok($result); - exit; - } - - function saveresult_cytologi() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = $inp['doctor']; - - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - if ($prm[0]['xid'] == '0') { - $sql = "INSERT INTO other_cytologi( - Other_CytologiT_OrderDetailID, - Other_CytologiM_DoctorID, - Other_CytologiUserID, - Other_CytologiCreated - ) - VALUES( - {$prm[0]['orderdetail_id']}, - {$doctor_id}, - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } else { - $sql = "SELECT * FROM other_cytologi WHERE Other_CytologiT_OrderDetailID = {$prm[0]['orderdetail_id']} AND Other_CytologiIsActive = 'Y'"; - $data_header = $this->db_smartone->query($sql)->row_array(); - $header_id = $data_header['Other_CytologiID']; - $sql = "UPDATE other_cytologi SET - Other_CytologiM_DoctorID = {$doctor_id}, - Other_CytologiUserID = {$userid} - WHERE - Other_CytologiID = {$header_id}"; - $this->db_smartone->query($sql); - } - foreach ($prm as $k => $v) { - if ($v['xid'] == '0') { - $results = str_replace("'", "\\'", $v['result']); - $sql = "INSERT INTO other_cytologidetails( - Other_CytologiDetailsOther_CytologiID , - Other_CytologiDetailsCode, - Other_CytologiDetailsLabel, - Other_CytologiDetailsResult, - Other_CytologiDetailsCreated, - Other_CytologiDetailsUserID - ) - VALUES( - {$header_id}, - '{$v['code']}', - '{$v['label']}', - '{$results}', - NOW(), - {$userid} - )"; - $query = $this->db_smartone->query($sql); - } else { - $results = str_replace("'", "\\'", $v['result']); - $sql = "UPDATE other_cytologidetails SET - Other_CytologiDetailsResult = '{$results}', - Other_CytologiDetailsUserID = {$userid} - WHERE - Other_CytologiDetailsID = {$v['xid']}"; - $query = $this->db_smartone->query($sql); - } - } - - $result = array("total" => 1, "records" => array(), "sql" => ''); - $this->sys_ok($result); - exit; - } - - function saveresult_mikro() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = $inp['doctor']; - $backteria_id = $inp['bacteria']; - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - - if ($inp['result_value'] != 'Negatif' && $inp['result_value'] != 'Positif') { - $prm['result_value'] = $prm['result_other']; - } else { - $prm['result_value'] = $inp['result_value']; - } - - if ($prm['xid'] == '0') { - $sql = "INSERT INTO other_mikro( - Other_MikroM_DoctorID, - Other_MikroResult, - Other_MikroT_BacteriaID, - Other_MikroT_OrderDetailID, - Other_MikroHasilBiakan, - Other_MikroSampleTypeName, - Other_MikroUserID, - Other_MikroCreated - ) - VALUES( - {$doctor_id}, - '{$prm['result_value']}', - {$backteria_id}, - {$prm['orderdetail_id']}, - '{$prm['hasil_biakan']}', - '{$prm['sample_name']}', - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } else { - $sql = "SELECT * FROM other_mikro WHERE Other_MikroT_OrderDetailID = {$prm['orderdetail_id']} AND Other_MikroIsActive = 'Y'"; - $data_header = $this->db_smartone->query($sql)->row_array(); - $header_id = $data_header['Other_MikroID']; - $sql = "UPDATE other_mikro SET - Other_MikroResult = '{$prm['result_value']}', - Other_MikroM_DoctorID = {$doctor_id}, - Other_MikroT_BacteriaID = {$backteria_id}, - Other_MikroHasilBiakan = '{$prm['hasil_biakan']}', - Other_MikroSampleTypeName = '{$prm['sample_name']}', - Other_MikroUserID = {$userid} - WHERE - Other_MikroID = {$header_id}"; - //echo $sql; - $this->db_smartone->query($sql); - } - - - - $sql = "UPDATE other_mikrodetails SET Other_MikroDetailsIsActive = 'N', Other_MikroDetailsUserID = 0 WHERE Other_MikroDetailsOther_MikroID = {$header_id}"; - $this->db_smartone->query($sql); - - $results = $prm['details']; - if ($inp['result_value'] == 'Positif') { - foreach ($results as $k => $v) { - if ($v['xid'] == '0') { - $sql = "INSERT INTO other_mikrodetails( - Other_MikroDetailsOther_MikroID , - Other_MikroDetailsT_AntibioticID, - Other_MikroDetailsValue, - Other_MikroDetailsNote, - Other_MikroDetailsCreated, - Other_MikroDetailsUserID - ) - VALUES( - {$header_id}, - '{$v['T_AntibioticID']}', - '{$v['value']}', - '{$v['note']}', - NOW(), - {$userid} - )"; - $query = $this->db_smartone->query($sql); - } else { - $sql = "UPDATE other_mikrodetails SET - Other_MikroDetailsT_AntibioticID = '{$v['T_AntibioticID']}', - Other_MikroDetailsValue = '{$v['value']}', - Other_MikroDetailsNote = '{$v['note']}', - Other_MikroDetailsIsActive = 'Y', - Other_MikroDetailsUserID = {$userid} - WHERE - Other_MikroDetailsID = {$v['xid']}"; - //echo $sql; - $query = $this->db_smartone->query($sql); - } - } - } - - - $result = array("total" => 1, "records" => array(), "sql" => ''); - $this->sys_ok($result); - exit; - } - - - function get_doctors_preparasi_sperma() - { - $prm = $this->sys_input; - // $id = $prm["id"]; - - $sql = " SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 10 AND - M_DoctorSOIsActive = 'Y' - ORDER BY M_DoctorName ASC"; - //echo $sql; - $query = $this->db_smartone->query($sql); - $rows = $query->result_array(); - $sql = " - SELECT '0' as id, 'Belum memilih metode' as name - UNION - SELECT M_MethodeSpermaID as id, M_MethodeSpermaName as name - FROM m_methodesperma - WHERE - M_MethodeSpermaIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $methodes = $this->db_smartone->query($sql)->result_array(); - - - $this->sys_ok(["records" => $rows, "methodes" => $methodes]); - } - - - function getpreparasispermaresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT other_preparasisperma.*, - Other_PreparasiSpermaID as xid, - Other_PreparasiSpermaT_OrderDetailID as orderdetail_id, - IFNULL(Other_PreparasiSpermaM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_PreparasiSpermaM_DoctorID) OR Other_PreparasiSpermaM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name, - IFNULL(M_MethodeSpermaID,0) as methode_id, - IFNULL(M_MethodeSpermaName,'') as methode_name - FROM other_preparasisperma - LEFT JOIN m_doctor ON Other_PreparasiSpermaM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - LEFT JOIN m_methodesperma ON Other_PreparasiSpermaM_MethodeSpermaID = M_MethodeSpermaID AND - M_MethodeSpermaIsActive = 'Y' - WHERE - Other_PreparasiSpermaT_OrderDetailID = {$id} AND Other_PreparasiSpermaIsActive = 'Y' - GROUP BY Other_PreparasiSpermaID"; - $query = $this->db_smartone->query($sql); - - if ($query) { - $rows = $query->row_array(); - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 10 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $sql = " - SELECT '0' as id, 'Belum memilih metode' as name - UNION - SELECT M_MethodeSpermaID as id, M_MethodeSpermaName as name - FROM m_methodesperma - WHERE - M_MethodeSpermaIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $methodes = $this->db_smartone->query($sql)->result_array(); - $images = array(); - $sql = "SELECT Other_PreparasiSpermaImgID as xid, - Other_PreparasiSpermaImgType as type, - CONCAT('/one-media/one-image-nonlab/',Other_PreparasiSpermaImgNewName) as image_url - FROM t_orderdetail - JOIN other_preparasisperma_img ON Other_PreparasiSpermaImgT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND - Other_PreparasiSpermaImgIsActive = 'Y' - WHERE - T_OrderDetailID = {$id} AND - T_OrderDetailIsActive = 'Y' - GROUP BY Other_PreparasiSpermaImgID"; - //echo $sql; - $images = $this->db_smartone->query($sql)->result_array(); - - $rst = array('doctors' => $doctors, 'methodes' => $methodes, 'results' => $rows, 'images' => $images); - $this->sys_ok(["records" => $rst]); - } else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - - function uploadimage_preparasi_sperma() - { - if (! $this->isLogin) { - $this->sys_error("Invalid Token"); - exit; - } - - $userid = $this->sys_user["M_UserID"]; - $data = []; - //print_r($_SERVER); - - $prm = $this->sys_input; - $orderid = $this->input->post('orderid'); - $type = $this->input->post('type'); - $labnumber = $this->input->post('labnumber'); - $sql = "UPDATE other_preparasisperma_img SET - Other_PreparasiSpermaImgIsActive = 'N', - Other_PreparasiSpermaImgUserID = {$userid} - WHERE - Other_PreparasiSpermaImgT_OrderHeaderID = {$orderid} AND - Other_PreparasiSpermaImgType = '{$type}'"; - //echo $sql; - $this->db_onedev->query($sql); - //$config['upload_path'] = 'assets/'; - - $path = '/home/one/project/one/one-media/one-image-nonlab/'; - //echo $path; - $config['upload_path'] = $path; - $config['allowed_types'] = 'jpg|jpeg|png|gif'; - - $config['max_size'] = '10000'; - $count = count($_FILES['files']['name']); - //echo $count; - $this->load->library('upload', $config); - - $error = []; - for ($i = 0; $i < $count; $i++) { - - - if (!empty($_FILES['files']['name'][$i])) { - - - - $_FILES['file']['name'] = $_FILES['files']['name'][$i]; - - $_FILES['file']['type'] = $_FILES['files']['type'][$i]; - - $_FILES['file']['tmp_name'] = $_FILES['files']['tmp_name'][$i]; - - $_FILES['file']['error'] = $_FILES['files']['error'][$i]; - - $_FILES['file']['size'] = $_FILES['files']['size'][$i]; - - - - $namex = $orderid . '-' . $labnumber . '-' . $this->generateRandomString(5); - //echo $namex; - - $config['file_name'] = $namex; - $this->upload->initialize($config); - //echo $config['file_name'] ; - - - - - - if ($this->upload->do_upload('file')) { - - $uploadData = $this->upload->data(); - - $filename = $uploadData['file_name']; - //echo $filename; - - - $sql = "INSERT INTO other_preparasisperma_img ( - Other_PreparasiSpermaImgT_OrderHeaderID, - Other_PreparasiSpermaImgType, - Other_PreparasiSpermaImgOldName, - Other_PreparasiSpermaImgNewName, - Other_PreparasiSpermaImgCreated, - Other_PreparasiSpermaImgUserID - ) - VALUES( - {$orderid}, - '{$type}', - '{$_FILES['files']['name'][$i]}', - '{$filename}', - NOW(), - {$userid} - - )"; - //echo $sql; - $this->db_onedev->query($sql); - $xlast_id = $this->db_onedev->insert_id(); - $data['totalFiles'][] = array('xid' => $xlast_id, 'type' => $type, 'image_url' => '/one-media/one-image-nonlab/' . $filename); - } else { - $error = array('error' => $this->upload->display_errors()); - } - } - } - - $result = array("total" => count($data['totalFiles']), "records" => $data['totalFiles'], 'errors' => $error); - $this->sys_ok($result); - } - - - function saveresult_preparasi_sperma() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = $inp['doctor']; - $orderdetail_id = $inp['orderdetailid']; - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - if ($prm['xid'] == '0') { - $sql = "INSERT INTO other_preparasisperma( - Other_PreparasiSpermaM_DoctorID, - Other_PreparasiSpermaT_OrderDetailID, - Other_PreparasiSpermaPreMotilitasA, - Other_PreparasiSpermaPreMotilitasB, - Other_PreparasiSpermaPreMotilitasC, - Other_PreparasiSpermaPreKonsentrasi, - Other_PreparasiSpermaPreKontaminan, - Other_PreparasiSpermaPostMotilitasA, - Other_PreparasiSpermaPostMotilitasB, - Other_PreparasiSpermaPostMotilitasC, - Other_PreparasiSpermaPostKonsentrasi, - Other_PreparasiSpermaPostKontaminan, - Other_PreparasiSpermaPreVolume, - Other_PreparasiSpermaPostVolume, - Other_PreparasiSpermaM_MethodeSpermaID, - Other_PreparasiSpermaNote, - Other_PreparasiSpermaUserID, - Other_PreparasiSpermaCreated - ) - VALUES( - {$doctor_id}, - {$orderdetail_id}, - '{$prm['Other_PreparasiSpermaPreMotilitasA']}', - '{$prm['Other_PreparasiSpermaPreMotilitasB']}', - '{$prm['Other_PreparasiSpermaPreMotilitasC']}', - '{$prm['Other_PreparasiSpermaPreKonsentrasi']}', - '{$prm['Other_PreparasiSpermaPreKontaminan']}', - '{$prm['Other_PreparasiSpermaPostMotilitasA']}', - '{$prm['Other_PreparasiSpermaPostMotilitasB']}', - '{$prm['Other_PreparasiSpermaPostMotilitasC']}', - '{$prm['Other_PreparasiSpermaPostKonsentrasi']}', - '{$prm['Other_PreparasiSpermaPostKontaminan']}', - '{$prm['Other_PreparasiSpermaPreVolume']}', - '{$prm['Other_PreparasiSpermaPostVolume']}', - '{$prm['Other_PreparasiSpermaM_MethodeSpermaID']}', - '{$prm['Other_PreparasiSpermaNote']}', - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } else { - $sql = "SELECT * FROM other_preparasisperma WHERE Other_PreparasiSpermaT_OrderDetailID = {$orderdetail_id} AND Other_PreparasiSpermaIsActive = 'Y'"; - $data_header = $this->db_smartone->query($sql)->row_array(); - $header_id = $data_header['Other_PreparasiSpermaID']; - $sql = "UPDATE other_preparasisperma SET - Other_PreparasiSpermaM_DoctorID = {$doctor_id}, - Other_PreparasiSpermaPreMotilitasA = '{$prm['Other_PreparasiSpermaPreMotilitasA']}', - Other_PreparasiSpermaPreMotilitasB = '{$prm['Other_PreparasiSpermaPreMotilitasB']}', - Other_PreparasiSpermaPreMotilitasC = '{$prm['Other_PreparasiSpermaPreMotilitasC']}', - Other_PreparasiSpermaPreKonsentrasi = '{$prm['Other_PreparasiSpermaPreKonsentrasi']}', - Other_PreparasiSpermaPreKontaminan = '{$prm['Other_PreparasiSpermaPreKontaminan']}', - Other_PreparasiSpermaPostMotilitasA = '{$prm['Other_PreparasiSpermaPostMotilitasA']}', - Other_PreparasiSpermaPostMotilitasB = '{$prm['Other_PreparasiSpermaPostMotilitasB']}', - Other_PreparasiSpermaPostMotilitasC = '{$prm['Other_PreparasiSpermaPostMotilitasC']}', - Other_PreparasiSpermaPostKonsentrasi = '{$prm['Other_PreparasiSpermaPostKonsentrasi']}', - Other_PreparasiSpermaPostKontaminan = '{$prm['Other_PreparasiSpermaPostKontaminan']}', - Other_PreparasiSpermaPreVolume = '{$prm['Other_PreparasiSpermaPreVolume']}', - Other_PreparasiSpermaPostVolume = '{$prm['Other_PreparasiSpermaPostVolume']}', - Other_PreparasiSpermaM_MethodeSpermaID = '{$prm['Other_PreparasiSpermaM_MethodeSpermaID']}', - Other_PreparasiSpermaNote = '{$prm['Other_PreparasiSpermaNote']}', - Other_PreparasiSpermaUserID = {$userid} - WHERE - Other_PreparasiSpermaID = {$header_id}"; - $this->db_smartone->query($sql); - } - - - $result = array("total" => 1, "records" => array(), "sql" => ''); - $this->sys_ok($result); - exit; - } - - function getdnafragmentasiresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT other_dnafragmentasi.*, - Other_DnaFragmentasiID as xid, - Other_DnaFragmentasiT_OrderDetailID as orderdetail_id, - IFNULL(Other_DnaFragmentasiM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_DnaFragmentasiM_DoctorID) OR Other_DnaFragmentasiM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name, - IFNULL(Other_DnaFragmentasiOther_DnaFragmentasiMethodeID,0) as methode_id, - IFNULL(Other_DnaFragmentasiMethodeName,'') as methode_name, - Other_DnaFragmentasiHaloLuas as halo_luas, - Other_DnaFragmentasiHaloSedang as halo_sedang, - Other_DnaFragmentasiHaloSempit as halo_sempit, - Other_DnaFragmentasiTanpaHalo as tanpa_halo, - Other_DnaFragmentasiDFI as dfi, - Other_DnaFragmentasiKesimpulan as kesimpulan, - Other_DnaFragmentasiCatatan as catatan - FROM other_dnafragmentasi - LEFT JOIN m_doctor ON Other_DnaFragmentasiM_DoctorID = M_DoctorID - LEFT JOIN other_dnafragmentasimethode ON Other_DnaFragmentasiOther_DnaFragmentasiMethodeID = Other_DnaFragmentasiMethodeID - WHERE - Other_DnaFragmentasiT_OrderDetailID = {$id} AND Other_DnaFragmentasiIsActive = 'Y' - GROUP BY Other_DnaFragmentasiID - LIMIT 1"; - //echo $sql; - $query = $this->db_smartone->query($sql); - - if ($query) { - $rows = $query->row_array(); - if (!$rows) { - $rows = array( - 'xid' => 0, - 'orderdetail_id' => $id, - 'doctor_id' => 0, - 'doctor_name' => '', - 'methode_id' => 0, - 'methode_name' => '', - 'halo_luas' => '', - 'halo_sedang' => '', - 'tanpa_halo' => '', - 'dfi' => '', - 'kesimpulan' => '', - 'catatan' => '' - ); - } - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID - WHERE - M_DoctorSONat_SubGroupID = 4 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - - $sql = " - SELECT '0' as id, 'Belum memilih metode' as name - UNION - SELECT Other_DnaFragmentasiMethodeID as id, Other_DnaFragmentasiMethodeName as name - FROM other_dnafragmentasimethode - WHERE - Other_DnaFragmentasiMethodeIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $methodes = $this->db_smartone->query($sql)->result_array(); - - - $rst = array('doctors' => $doctors, 'methodes' => $methodes, 'results' => $rows); - $this->sys_ok(["records" => $rst]); - } else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - function saveresult_dnafragmentasi() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = $inp['doctor']['id']; - $methode_id = $inp['methode']['id']; - $orderdetail_id = $inp['results']['orderdetail_id']; - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - if (intval($prm['xid']) == 0) { - $sql = "INSERT INTO other_dnafragmentasi( - Other_DnaFragmentasiT_OrderDetailID, - Other_DnaFragmentasiM_DoctorID, - Other_DnaFragmentasiOther_DnaFragmentasiMethodeID, - Other_DnaFragmentasiHaloLuas, - Other_DnaFragmentasiHaloSedang, - Other_DnaFragmentasiHaloSempit, - Other_DnaFragmentasiTanpaHalo, - Other_DnaFragmentasiDFI, - Other_DnaFragmentasiKesimpulan, - Other_DnaFragmentasiCatatan, - Other_DnaFragmentasiUserID, - Other_DnaFragmentasiLastUpdated - ) - VALUES( - {$orderdetail_id}, - {$doctor_id}, - {$methode_id}, - '{$prm['halo_luas']}', - '{$prm['halo_sedang']}', - '{$prm['halo_sempit']}', - '{$prm['tanpa_halo']}', - '{$prm['dfi']}', - '{$prm['kesimpulan']}', - '{$prm['catatan']}', - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } else { - $sql = "UPDATE other_dnafragmentasi SET - Other_DnaFragmentasiT_OrderDetailID = {$orderdetail_id}, - Other_DnaFragmentasiM_DoctorID = {$doctor_id}, - Other_DnaFragmentasiOther_DnaFragmentasiMethodeID = '{$methode_id}', - Other_DnaFragmentasiHaloLuas = '{$prm['halo_luas']}', - Other_DnaFragmentasiHaloSedang = '{$prm['halo_sedang']}', - Other_DnaFragmentasiHaloSempit = '{$prm['halo_sempit']}', - Other_DnaFragmentasiTanpaHalo = '{$prm['tanpa_halo']}', - Other_DnaFragmentasiDFI = '{$prm['dfi']}', - Other_DnaFragmentasiKesimpulan = '{$prm['kesimpulan']}', - Other_DnaFragmentasiCatatan = '{$prm['catatan']}', - Other_DnaFragmentasiLastUpdated = NOW(), - Other_DnaFragmentasiUserID = {$userid} - WHERE - Other_DnaFragmentasiID = {$prm['xid']}"; - //echo $sql; - $this->db_smartone->query($sql); - } - - - $result = array("total" => 1, "records" => array(), "sql" => ''); - $this->sys_ok($result); - exit; - } -} +db_smartone = $this->load->database("onedev", true); + $this->load->helper(array('form', 'url')); + } + function getMethodeID($natTestID) + { + $sql = "select M_MethodePriorityNat_MethodeID MethodeID, Nat_MethodeName + from + m_methode_priority + join nat_methode on Nat_MethodeID = M_MethodePriorityNat_MethodeID + and Nat_MethodeIsActive = 'Y' + join m_instrumentmethode on M_InstrumentMethodeNat_MethodeID = Nat_MethodeID and M_InstrumentMethodeIsActive = 'Y' + join nat_instrument on M_InstrumentMethodeNat_InstrumentID = Nat_InstrumentID + and Nat_InstrumentIsActive ='Y' + where M_MethodePriorityIsActive = 'Y' + and M_MethodePriorityNat_TestID = $natTestID + and M_MethodePriorityM_DayOfWeekID = dayofweek(now()) + order by M_MethodePriorityNumber desc + limit 0,1 "; + $qry = $this->db->query($sql); + if ($qry) { + $rows = $qry->result_array(); + if (count($rows) > 0) return array($rows[0]["MethodeID"], $rows[0]["Nat_MethodeName"]); + } + //2nd + $sql = "select + M_InstrumentMethodeNat_MethodeID MethodeID, Nat_MethodeName + from m_instrumentmethode + join nat_methode on M_InstrumentMethodeNat_MethodeID = Nat_MethodeID + and Nat_MethodeIsActive = 'Y' + join nat_instrument on M_InstrumentMethodeNat_InstrumentID = Nat_InstrumentID + and Nat_InstrumentIsActive ='Y' + where M_InstrumentMethodeNat_TestID = $natTestID + and M_InstrumentMethodeIsActive = 'Y' + order by M_InstrumentMethodePriority desc + limit 0,1"; + $qry = $this->db->query($sql); + if ($qry) { + $rows = $qry->result_array(); + if (count($rows) > 0) return array($rows[0]["MethodeID"], $rows[0]["Nat_MethodeName"]); + } + // + $sql = "select Nat_NormalValueNat_MethodeID MethodeID, Nat_MethodeName + from + nat_normalvalue + join nat_methode on Nat_NormalValueNat_MethodeID = Nat_MethodeID + and Nat_MethodeIsActive = 'Y' + where Nat_NormalValueNat_TestID = $natTestID + and Nat_NormalValueIsActive = 'Y' + order by Nat_NormalValueID + limit 0,1"; + $qry = $this->db->query($sql); + if ($qry) { + $rows = $qry->result_array(); + if (count($rows) > 0) return array($rows[0]["MethodeID"], $rows[0]["Nat_MethodeName"]); + } + return array(0, ""); + } + function get_normal_value($methodeID, $natTestID, $sexID, $ageInDay) + { + $this->load->library('ibl_sampling_normal'); + return $this->ibl_sampling_normal->get_normal_value_id($methodeID, $natTestID, $sexID, $ageInDay); + } + return 0; + } + function fn_fix_normal($order_id) + { + $sql = "select + T_OrderDetailID, M_PatientM_SexID, fn_global_age_count_day(M_PatientDOB, date(T_OrderHeaderDate)) Dob , + T_TestNat_TestID + from t_orderheader + join m_patient on T_OrderHeaderID = $order_id and T_OrderHeaderM_PatientID = M_PatientID + join t_orderdetail on T_OrderDetailT_OrderHeaderID = T_OrderHeaderID + and T_OrderDetailIsACtive = 'Y' + and ( T_OrderDetailNat_NormalValueID is null or T_OrderDetailNat_NormalValueID = 0 ) + join t_test on T_OrderDetailT_TestID = T_TestID and T_TestIsResult = 'Y' "; + $qry = $this->db->query($sql); + if (! $qry) { + return; + } + $rows = $qry->result_array(); + if (count($rows) == 0) return; + $sql_u = "update t_orderdetail + join nat_normalvalue on T_OrderDetailID = ? and Nat_NormalValueID = ? + set + T_OrderDetailNat_NormalValueID = Nat_NormalValueID, + T_OrderDetailNormalValueNote = Nat_NormalValueNote, + T_OrderDetailNormalValueDescription = Nat_NormalValueDescription, + T_OrderDetailMinValue = Nat_NormalValueMinValue, + T_OrderDetailMaxValue = Nat_NormalValueMaxValue, + T_OrderDetailMinValueInclusive = Nat_NormalValueMinValueInclusive, + T_OrderDetailMaxValueInclusive = Nat_NormalValueMaxValueInclusive, + T_OrderDetailNat_MethodeID = ?, + T_OrderdetailNat_MethodeName =?"; + + foreach ($rows as $r) { + $T_OrderDetailID = $r["T_OrderDetailID"]; + $sexID = $r["M_PatientM_SexID"]; + $ageInDay = $r["Dob"]; + $natTestID = $r["T_TestNat_TestID"]; + list($methodeID, $methodeName) = $this->getMethodeID($natTestID); + if ($methodeID == 0) continue; + $normalValueID = $this->get_normal_value($methodeID, $natTestID, $sexID, $ageInDay); + if ($normalValueID == 0) return; + $this->db->query($sql_u, array($T_OrderDetailID, $normalValueID, $methodeID, $methodeName)); + } + } + + function update_order_sample($targetID, $sourceID) + { + $sql = "update t_ordersample target + join t_ordersample source on + target.T_OrderSampleID = ? + and target.T_OrderSampleWorklistReceive = 'N' + and source.T_OrderSampleID = ? + set + target.T_OrderSampleSampling = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSampling, source.T_OrderSampleSampling), + target.T_OrderSampleSamplingDate = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingDate, source.T_OrderSampleSamplingDate), + target.T_OrderSampleSamplingTime = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingTime, source.T_OrderSampleSamplingTime), + target.T_OrderSampleSamplingUserID = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingUserID, source.T_OrderSampleSamplingUserID), + + target.T_OrderSampleReceive = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceive, source.T_OrderSampleReceive), + target.T_OrderSampleReceiveDate = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveDate, source.T_OrderSampleReceiveDate), + target.T_OrderSampleReceiveTime = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveTime, source.T_OrderSampleReceiveTime), + target.T_OrderSampleReceiveUserID = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveUserID, source.T_OrderSampleReceiveUserID), + + target.T_OrderSampleVerification = if(target.T_OrderSampleVerification='Y',target.T_OrderSampleVerification, source.T_OrderSampleVerification), + target.T_OrderSampleVerificationDate =if(target.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationDate, source.T_OrderSampleVerificationDate), + target.T_OrderSampleVerificationTime =if(source.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationTime, source.T_OrderSampleVerificationTime), + target.T_OrderSampleVerificationUserID =if(source.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationUserID, source.T_OrderSampleVerificationUserID), + + target.T_OrderSampleProcessing = if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessing, source.T_OrderSampleProcessing), + target.T_OrderSampleProcessingDate= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingDate, source.T_OrderSampleProcessingDate), + target.T_OrderSampleProcessingTime= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingTime, source.T_OrderSampleProcessingTime), + target.T_OrderSampleProcessingUserID= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingUserID, source.T_OrderSampleProcessingUserID), + + target.T_OrderSampleReceiveHandling =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandling, source.T_OrderSampleReceiveHandling ), + target.T_OrderSampleReceiveHandlingDate =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingDate, source.T_OrderSampleReceiveHandlingDate), + target.T_OrderSampleReceiveHandlingTime =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingTime, source.T_OrderSampleReceiveHandlingTime), + target.T_OrderSampleReceiveHandlingUserID =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingUserID, source.T_OrderSampleReceiveHandlingUserID), + + target.T_OrderSampleHandling = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandling, source.T_OrderSampleHandling), + target.T_OrderSampleHandlingDate = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingDate, source.T_OrderSampleHandlingDate), + target.T_OrderSampleHandlingTime = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingTime, source.T_OrderSampleHandlingTime), + target.T_OrderSampleHandlingUserID = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingUserID, source.T_OrderSampleHandlingUserID), + + target.T_OrderSampleWorklistReceive = source.T_OrderSampleWorklistReceive, + target.T_OrderSampleWorklistReceiveDatetime = source.T_OrderSampleWorklistReceiveDateTime, + target.T_OrderSampleWorklistReceiveUserID = source.T_OrderSampleWorklistReceiveUserID + "; + $qry = $this->db->query($sql, array($targetID, $sourceID)); + if (! $qry) { + echo json_encode(array("status" => "ERR", "message" => print_r($this->db->error(), true))); + exit; + } + } + function fix_sample_serum($headerID) + { + //cari t_ordersample yg belum worklist receive dengan code 017% + $sql = "select T_OrderSampleID + from t_ordersample + join t_sampletype on + T_OrderSampleT_OrderHeaderID = ? + and T_OrderSampleWorklistReceive = 'N' + and T_OrderSampleIsActive = 'Y' + and T_OrderSampleT_SampleTypeID = T_SampletypeID + and T_SampleTypeCode like '017%' + "; + $qry = $this->db->query($sql, array($headerID)); + if (!$qry) { + echo json_encode(array("status" => "ERR", "message" => print_r($this->db->error(), true))); + exit; + } + $rows = $qry->result_array(); + if (count($rows) == 0) return; + //cari T_OrderSample yang sudah di receive yg terakhir + $sql = "select T_OrderSampleID + from t_ordersample + join t_sampletype on + T_OrderSampleT_OrderHeaderID = ? + and T_OrderSampleWorklistReceive = 'Y' + and T_OrderSampleIsActive = 'Y' + and T_OrderSampleT_SampleTypeID = T_SampletypeID + and T_SampleTypeCode like '017%' + order by T_OrderSampleWorklistReceiveDatetime desc + limit 0,1 + "; + $qry = $this->db->query($sql, array($headerID)); + if (!$qry) { + echo json_encode(array("status" => "ERR", "message" => print_r($this->db->error(), true))); + exit; + } + $rcv_rows = $qry->result_array(); + if (count($rcv_rows) == 0) return; + + //print_r($rows); + //print_r($rcv_rows); + $rcv_T_OrderSampleID = $rcv_rows[0]["T_OrderSampleID"]; + //ada yg belum di receive + foreach ($rows as $r) { + $T_OrderSampleID = $r["T_OrderSampleID"]; + $this->update_order_sample($T_OrderSampleID, $rcv_T_OrderSampleID); + } + } + public function search() + { + $prm = $this->sys_input; + $max_rst = 99; + + $id = $prm["order_id"]; + if ($id > 0) { + $this->fix_sample_serum($id); + $this->fn_fix_normal($id); + } + $lang = $this->lang_default_code; + $lang_id = isset($prm['lang_id']) ? $prm['lang_id'] : '0'; + + if ($lang_id != 0) { + $l = $this->db_smartone->where("Nat_LangID", $lang_id)->get("nat_lang")->row(); + $lang = $l->Nat_LangCode; + } + + //tambahan fajri + $sql = " UPDATE t_orderdetail + JOIN t_test ON T_OrderDetailT_TestID = T_TestID + SET T_OrderDetailT_TestIsResult = T_TestIsResult + WHERE + T_OrderDetailT_OrderHeaderID = {$id} AND + T_OrderDetailT_TestIsResult = '' AND + T_OrderDetailIsActive = 'Y'"; + $this->db_smartone->query($sql); + + $tot_count = 0; + $lq = ""; + $group_id = 0; + if (isset($prm['group_id'])) + $group_id = $prm['group_id']; + + if ($group_id != 0) { + $sql = "select distinct T_WorklistDetailNat_TestID Nat_TestID + from t_worklistdetailv2 + where T_WorklistDetailT_WorklistID = {$group_id}"; + $qry = $this->db_smartone->query($sql); + $rows = $qry->result_array(); + $nat_test_ids = "0"; + foreach ($rows as $r) { + $nat_test_ids .= ", " . $r["Nat_TestID"]; + } + $q_group = " ( $nat_test_ids ) "; + + $sql = " + SELECT a1.*, cOUNT(a2.T_OrderDetailID) level + FROM ( + SELECT IFNULL(y.T_OrderDetailT_TestID, x.T_OrderDetailT_TestID) t_testid, + IFNULL(y.T_OrderDetailT_TestName, y.T_OrderDetailT_TestName) t_testname, + y.T_OrderDetailResult result, y.T_OrderDetailResult result_old, y.T_OrderDetailNote note, y.T_OrderDetailNote note_old, + y.T_OrderDetailID id, + y.T_OrderDetailT_TestIsResult is_result, a.T_TestIsQuantitative is_quantitative, + y.T_OrderDetailResultFlag result_flag, + y.T_OrderDetailNat_NormalValueID normal_id, + y.T_OrderDetailNormalValueNote normal_note, y.T_OrderDetailNat_UnitName unit_name, + y.T_OrderdetailNat_MethodeID methode_id, y.T_OrderdetailNat_MethodeName methode_name, + a.T_TestNat_TestID nattest_id, a.T_TestID tx_id, count(T_ResultInstrumentID) as result_instrument_n, + y.T_OrderDetailVerification, T_OrderSampleReceive sample_receive, + T_OrderSampleProcessing sample_processing, T_OrderSampleWorklistReceive sample_worklist_receive, + IF(T_OrderDetailAddOnPreAnalytic = 'Y', T_OrderDetailAddOnPreAnalytic, PreAnalyticIsOk) pre_analytic, + T_OrderDetailAddOnPreAnalytic, + T_OrderHeaderID order_id, y.T_OrderDetailT_TestSasCode test_sas_code, + tx.T_TestSasCode, + T_OrderDetailAddOnResample `resample`, T_OrderDetailAddOnResampleStatus resample_status, + T_OrderDetailAddOnRef ref, y.T_OrderDetailVerification verification, y.T_OrderDetailValidation validation, + T_OrderPromiseDateTime, Group_ResultName as ResultGroupName + FROM t_orderdetail x + left join t_orderpromise on x.T_OrderDetailT_OrderPromiseID = T_OrderPromiseID + JOIN t_test tx ON x.T_OrderDetailT_TestID = T_TestID + JOIN t_test tcheck on tcheck.T_TestNat_TestID in {$q_group} + and ( tx.T_TestID = tcheck.T_TestID or tx.T_TestSasCode like concat(tcheck.T_TestSasCode,'%')) + LEFT JOIN group_resultdetail ON Group_ResultDetailT_TestID = x.T_OrderDetailT_TestID AND Group_ResultDetailIsActive = 'Y' + LEFT JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND Group_ResultFlagNonLab = 'N' + LEFT JOIN t_orderdetail y ON x.T_OrderDetailT_TestSasCode LIKE CONCAT(y.T_OrderDetailT_TestSasCode, '%') + AND x.T_OrderDetailT_OrderHeaderID = y.T_OrderDetailT_OrderHeaderID + AND y.T_OrderDetailIsActive = 'Y' + LEFT JOIN t_orderdetailaddon ON x.T_OrderDetailID = T_OrderDetailAddOnT_OrderDetailID + JOIN t_orderheader ON y.T_OrderDetailT_OrderHeaderID = T_OrderHeaderID + LEFT JOIN t_test a ON y.T_OrderDetailT_TestID = a.T_TestID + AND a.T_TestIsNonLab = '' + LEFT JOIN (SELECT T_OrderSampleT_SampleTypeID, T_OrderSampleReceive, T_OrderSampleProcessing, T_OrderSampleWorklistReceive + FROM t_ordersample WHERE T_OrderSampleT_OrderHeaderID = {$id} + AND T_OrderSampleIsactive = 'Y' + GROUP BY T_OrderSampleT_SampleTypeID) os ON a.T_TestT_SampleTypeID = os.T_OrderSampleT_SampleTypeID + or os.T_OrderSampleT_SampleTypeID = fn_sampletype_from_local(a.T_TestNat_TestID) + + LEFT JOIN t_resultinstrument ON T_ResultInstrumentT_OrderDetailID = x.T_OrderDetailID + LEFT JOIN pre_analytic ON PreAnalyticNat_TestID = a.T_TestNat_TestID AND PreAnalyticDate = date(now()) and PreAnalyticIsActive = 'Y' + WHERE x.T_OrderDetailT_OrderHeaderID = {$id} + AND x.T_OrderDetailIsActive = 'Y' + GROUP BY y.T_OrderDetailT_TestID + ORDER BY y.T_OrderDetailT_TestSasCode ASC + ) a1 + + LEFT JOIN t_orderdetail a2 ON a2.T_OrderDetailT_OrderHeaderID = a1.order_id + AND a2.T_OrderDetailIsActive = 'Y' + AND a1.test_sas_code LIKE CONCAT(a2.T_OrderDetailT_testSasCode, '%') + GROUP BY a1.t_testid + order by a1.test_sas_code +"; + $query = $this->db_smartone->query($sql); + $lq = $this->db_smartone->last_query(); + } else { + $sql = " + SELECT a1.*, cOUNT(a2.T_OrderDetailID) level + FROM ( + SELECT IFNULL(y.T_OrderDetailT_TestID, x.T_OrderDetailT_TestID) t_testid, + IFNULL(y.T_OrderDetailT_TestName, y.T_OrderDetailT_TestName) t_testname, + y.T_OrderDetailResult result, y.T_OrderDetailResult result_old, y.T_OrderDetailNote note, y.T_OrderDetailNote note_old, + y.T_OrderDetailID id, + y.T_OrderDetailT_TestIsResult is_result, a.T_TestIsQuantitative is_quantitative, + y.T_OrderDetailResultFlag result_flag, + y.T_OrderDetailNat_NormalValueID normal_id, + y.T_OrderDetailNormalValueNote normal_note, y.T_OrderDetailNat_UnitName unit_name, + y.T_OrderdetailNat_MethodeID methode_id, y.T_OrderdetailNat_MethodeName methode_name, + a.T_TestNat_TestID nattest_id, a.T_TestID tx_id, count(T_ResultInstrumentID) as result_instrument_n, + y.T_OrderDetailVerification, T_OrderSampleReceive sample_receive, + T_OrderSampleProcessing sample_processing, T_OrderSampleWorklistReceive sample_worklist_receive, + IF(T_OrderDetailAddOnPreAnalytic = 'Y', T_OrderDetailAddOnPreAnalytic, PreAnalyticIsOk) pre_analytic, + T_OrderDetailAddOnPreAnalytic, + T_OrderHeaderID order_id, y.T_OrderDetailT_TestSasCode test_sas_code, + tx.T_TestSasCode, + T_OrderDetailAddOnResample `resample`, T_OrderDetailAddOnResampleStatus resample_status, + T_OrderDetailAddOnRef ref, y.T_OrderDetailVerification verification, y.T_OrderDetailValidation validation, + T_OrderPromiseDateTime , Group_ResultName as ResultGroupName + FROM t_orderdetail x + left join t_orderpromise on x.T_OrderDetailT_OrderPromiseID = T_OrderPromiseID + JOIN t_test tx ON x.T_OrderDetailT_TestID = T_TestID + LEFT JOIN group_resultdetail ON Group_ResultDetailT_TestID = x.T_OrderDetailT_TestID AND Group_ResultDetailIsActive = 'Y' + LEFT JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND Group_ResultFlagNonLab = 'N' + LEFT JOIN t_orderdetail y ON x.T_OrderDetailT_TestSasCode LIKE CONCAT(y.T_OrderDetailT_TestSasCode, '%') + AND x.T_OrderDetailT_OrderHeaderID = y.T_OrderDetailT_OrderHeaderID + AND y.T_OrderDetailIsActive = 'Y' + + LEFT JOIN t_orderdetailaddon ON x.T_OrderDetailID = T_OrderDetailAddOnT_OrderDetailID + + JOIN t_orderheader ON y.T_OrderDetailT_OrderHeaderID = T_OrderHeaderID + LEFT JOIN t_test a ON y.T_OrderDetailT_TestID = a.T_TestID + AND a.T_TestIsNonLab = '' + LEFT JOIN (SELECT T_OrderSampleT_SampleTypeID, T_OrderSampleReceive, T_OrderSampleProcessing, T_OrderSampleWorklistReceive + FROM t_ordersample WHERE T_OrderSampleT_OrderHeaderID = {$id} + AND T_OrderSampleIsactive = 'Y' + GROUP BY T_OrderSampleT_SampleTypeID) os ON a.T_TestT_SampleTypeID = os.T_OrderSampleT_SampleTypeID + or os.T_OrderSampleT_SampleTypeID = fn_sampletype_from_local(a.T_TestNat_TestID) + + LEFT JOIN t_resultinstrument ON T_ResultInstrumentT_OrderDetailID = x.T_OrderDetailID + LEFT JOIN pre_analytic ON PreAnalyticNat_TestID = a.T_TestNat_TestID AND PreAnalyticDate = date(now()) and PreAnalyticIsActive = 'Y' + WHERE x.T_OrderDetailT_OrderHeaderID = {$id} + AND x.T_OrderDetailIsActive = 'Y' + GROUP BY y.T_OrderDetailT_TestID + ORDER BY y.T_OrderDetailT_TestSasCode ASC + ) a1 + + LEFT JOIN t_orderdetail a2 ON a2.T_OrderDetailT_OrderHeaderID = a1.order_id + AND a2.T_OrderDetailIsActive = 'Y' + AND a1.test_sas_code LIKE CONCAT(a2.T_OrderDetailT_testSasCode, '%') + GROUP BY a1.t_testid + order by a1.test_sas_code +"; + //echo $sql; + $query = $this->db_smartone->query($sql); + $lq = $this->db_smartone->last_query(); + } + // file_put_contents("/xtmp/re-query.sql",$lq); + + if ($query) { + $rst = []; + $rows = $query->result_array(); + + foreach ($rows as $k => $v) { + + if ($v['is_result'] == "Y" && $v['is_quantitative'] == "N") { + $v['template'] = []; + $x = $this->db_smartone->query("CALL sp_master_resulttemplate_get('{$v['t_testid']}')"); + $this->clean_mysqli_connection($this->db_smartone->conn_id); + if ($x) + $v['template'] = $x->result_array(); + } + + // IF Rujukan, by pas Pre Analytik + if ($v['ref'] == 'Y') + $v['pre_analytic'] = 'Y'; + if ($v["id"] == "885455") { + //sipe workaround + //$v["sample_receive"] = "Y"; + $v["sample_worklist_receive"] = "Y"; + } + $rst[] = $v; + } + + $result = array("total" => $tot_count, "records" => $rst, "total_display" => sizeof($rows), "q" => $lq); + $this->sys_ok($result); + } else { + $this->sys_error_db("RE Px rows", $this->db_smartone); + exit; + } + } + + public function save() + { + $prm = $this->sys_input; + $data = json_decode($prm["data"]); + $lang = $this->lang_default_code; + $lang_id = isset($prm['lang_id']) ? $prm['lang_id'] : '0'; + + if ($lang_id != 0) { + $l = $this->db_smartone->where("Nat_LangID", $lang_id)->get("nat_lang")->row(); + $lang = $l->Nat_LangCode; + } + + $sql_norm = "select T_OrderDetailMinValue, T_OrderDetailMaxValue, + T_OrderDetailMinValueInclusive, T_OrderDetailMaxValueInclusive, + Nat_TestFlagLow, Nat_TestFlagHigh + from t_orderdetail + join t_test on T_OrderDetailT_TestID = T_TestID + join nat_test on T_TestNat_TestID = Nat_TestID and T_TestIsActive = 'Y' + where T_OrderDetailID = ? "; + + $ids = []; + foreach ($data as $k => $v) { + if ($v->resultInstrumentID > 0) { + $sql_i = "select T_ResultInstrumentNat_NormalValueID normalValueID + from t_resultinstrument + where T_ResultInstrumentID = ?"; + $qry_i = $this->db_smartone->query($sql_i, array($v->resultInstrumentID)); + if ($qry_i) { + $rows_i = $qry_i->result_array(); + + if (count($rows_i) > 0) { + $sql_iu = "update t_orderdetail, nat_normalvalue , nat_methode + set T_OrderDetailMinValue = Nat_NormalValueMinValue, + T_OrderDetailMinValueInclusive = Nat_NormalValueMinValueInclusive, + T_OrderDetailMaxValue = Nat_NormalValueMaxValue , + T_OrderDetailMaxValueInclusive = Nat_NormalValueMaxValueInclusive, + T_OrderDetailNormalValueNote = Nat_NormalValueNote, + T_OrderDetailNormalValueDescription = Nat_NormalValueDescription, + T_OrderDetailNat_NormalValueID = Nat_NormalValueID, + T_OrderDetailNat_MethodeID = Nat_NormalValueNat_MethodeID, + T_OrderDetailNat_MethodeName = Nat_MethodeName + where T_OrderDetailID = ? and Nat_NormalValueID = ? + and Nat_NormalValueNat_MethodeID = Nat_MethodeID + "; + $this->db_smartone->query($sql_iu, array($v->id, $rows_i[0]["normalValueID"])); + //file_put_contents("/xtmp/update-nilai-normal", $this->db_smartone->last_query() . "\n", FILE_APPEND); + } + } + } + $y = $this->db_smartone->query("SELECT fn_process_sample_handling_perfect('{$v->order_id}', '{$v->test_id}') c") + ->row(); + $req_status = $y->c; + $qry_norm = $this->db_smartone->query($sql_norm, $v->id); + $result_flag = ""; + if ($qry_norm) { + $rows_norm = $qry_norm->result_array(); + if (count($rows_norm) > 0) { + $r = $rows_norm[0]; + if (is_numeric($v->result)) { + + if ($r["T_OrderDetailMinValueInclusive"] == "Y" && $v->result < $r["T_OrderDetailMinValue"]) { + $result_flag = $r["Nat_TestFlagLow"]; + } + if ($r["T_OrderDetailMinValueInclusive"] == "N" && $v->result <= $r["T_OrderDetailMinValue"]) { + $result_flag = $r["Nat_TestFlagLow"]; + } + if ($r["T_OrderDetailMaxValueInclusive"] == "Y" && $v->result > $r["T_OrderDetailMaxValue"]) { + $result_flag = $r["Nat_TestFlagHigh"]; + } + if ($r["T_OrderDetailMaxValueInclusive"] == "N" && $v->result >= $r["T_OrderDetailMaxValue"]) { + $result_flag = $r["Nat_TestFlagHigh"]; + } + } + } + } + if ($lang == $this->lang_default_code) { + $this->db_smartone->set('T_OrderDetailResult', $v->result) + ->set('T_OrderDetailResultFlag', $result_flag) + ->set('T_OrderDetailNote', $v->note) + ->set('T_OrderDetailReqStatus', $req_status) + ->where('T_OrderDetailID', $v->id) + ->update('t_orderdetail'); + } else { + $this->db_smartone->set('T_OrderDetailLangResult', $v->result) + ->set('T_OrderDetailLangNote', $v->note) + ->where('T_OrderDetailLangID', $v->id) + ->update('t_orderdetaillang'); + } + + $ids[] = $v->id; + } + + // LOG Process + $order = $this->db_smartone->select('T_OrderDetailT_OrderHeaderID id, T_OrderHeaderLabNumber lab_number', false) + ->join('t_orderheader', 'T_OrderHeaderID = T_OrderDetailT_OrderHeaderID') + ->where('T_OrderDetailID', $data[0]->id) + ->get('t_orderdetail') + ->row(); + + $dblog = $this->load->database("onelog", true); + $dblog->set('Log_ProcessCode', 'PROCESS.Result.Entry') + ->set('Log_ProcessOrderID', $order->id) + ->set('Log_ProcessOrderNumber', $order->lab_number) + ->set('Log_ProcessJson', json_encode($data)) + ->set('Log_ProcessUserID', $this->sys_user['M_UserID']) + ->insert('log_process'); + // END OF Log Process + //auto calculation + $this->load->library("Resultcalc"); + $rows = $this->resultcalc->auto($order->id); + + try { + foreach ($ids as $id) { + $this->db_smartone->query("call sp_set_normal_value_flag($id)"); + $this->clean_mysqli_connection($this->db_smartone->conn_id); + } + } catch (Exception $e) { + } + + $this->sys_ok($ids); + } + + public function save_template() + { + $prm = $this->sys_input; + + $n = $this->db_smartone->select("COUNT(T_ResultTemplateID) n") + ->where("T_ResultTemplateT_TestID", $prm['test_id']) + ->where("T_ResultTemplateIsActive", "Y") + ->where("T_ResultTemplateValue", $prm['value']) + ->get('t_resulttemplate') + ->row(); + if ($n->n > 0) { + $this->sys_error_db("Insert Result Template", $this->db_smartone); + return; + } + + $r = $this->db_smartone->set("T_ResultTemplateT_TestID", $prm['test_id']) + ->set("T_ResultTemplateValue", $prm['value']) + ->insert('t_resulttemplate'); + if ($r) { + $template = []; + $x = $this->db_smartone->query("CALL sp_master_resulttemplate_get('{$prm['test_id']}')"); + $this->clean_mysqli_connection($this->db_smartone->conn_id); + if ($x) + $template = $x->result_array(); + + $this->sys_ok($template); + } + } + + public function export() + { + $prm = $this->sys_input; + + $sql = "CALL sp_process_result_lang(?, ?, ?, ?)"; + $query = $this->db_smartone->query($sql, [$prm['order_id'], $prm['lang_id'], $prm['is_si'], $this->sys_user['M_UserID']]); + if ($query) { + $r = $query->row(); + if ($r->status == "OK") { + $this->sys_ok($r->data); + return; + } + + $this->sys_error_db("Message : " . $r->message, $this->db_smartone); + } else { + $this->sys_error_db("Lang Result", $this->db_smartone); + return; + } + } + + public function search_group() + { + $prm = $this->sys_input; + $max_rst = 100; + + // QUERY TOTAL + $sql = "select count(*) total + from t_worklist + where T_WorklistIsActive = 'Y' + order by T_WorklistName ASC"; + $query = $this->db_smartone->query($sql); + + if ($query) { + $tot_count = $query->result_array()[0]["total"]; + } else { + $this->sys_error_db("worklist count", $this->db_smartone); + exit; + } + + $sql = "select T_WorklistID group_id, T_WorklistName group_name + from t_worklist + where T_WorklistIsActive = 'Y' + order by T_WorklistName ASC + limit 0, {$max_rst}"; + $query = $this->db_smartone->query($sql); + + if ($query) { + $rows = $query->result_array(); + foreach ($rows as $k => $v) + $rows[$k]['data'] = json_decode($v['data']); + $result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows), "q" => $this->db_smartone->last_query()); + $this->sys_ok($result); + } else { + $this->sys_error_db("worklist rows", $this->db_smartone); + exit; + } + } + + public function search_rerun() + { + $prm = $this->sys_input; + $id = $prm["detail_id"]; + + $sql = "CALL sp_process_result_rerun(?)"; + $query = $this->db_smartone->query($sql, [$id]); + + if ($query) { + $rows = $query->result_array(); + $this->sys_ok(["records" => $rows]); + } else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + + + function getdoctorsfna() + { + $prm = $this->sys_input; + // $id = $prm["id"]; + + $sql = " SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY M_DoctorName ASC"; + //echo $sql; + $query = $this->db_smartone->query($sql); + + if ($query) { + $rows = $query->result_array(); + $this->sys_ok(["records" => $rows]); + } else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + function getfnaresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT Other_FNADetailsID as xid, + Other_FNAT_OrderDetailID as orderdetail_id, + Other_FNADetailsCode as code, + Other_FNADetailsLabel as label, + Other_FNADetailsResult as result, + IFNULL(Other_FNAM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_FNAM_DoctorID) OR Other_FNAM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_fna + JOIN other_fnadetails ON Other_FNADetailsOther_FNAID = Other_FNAID AND Other_FNADetailsIsActive = 'Y' + LEFT JOIN m_doctor ON Other_FNAM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_FNAT_OrderDetailID = {$id} AND Other_FNAIsActive = 'Y' + GROUP BY Other_FNADetailsID + ORDER BY Other_FNADetailsCode ASC"; + $query = $this->db_smartone->query($sql); + + if ($query) { + $rows = $query->result_array(); + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $images = array(); + $sql = "SELECT So_ImageUploadID as xid, + CONCAT('/one-media/one-image-nonlab/',So_ImageUploadNewName) as image_url + FROM t_orderdetail + JOIN so_imageupload ON So_ImageUploadT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND + So_ImageUploadIsActive = 'Y' + WHERE + T_OrderDetailID = {$id} AND + T_OrderDetailIsActive = 'Y' + GROUP BY So_ImageUploadID"; + $images = $this->db_smartone->query($sql)->result_array(); + + $rst = array('doctors' => $doctors, 'results' => $rows, 'images' => $images); + $this->sys_ok(["records" => $rst]); + } else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + function getpatologianatomyresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT Other_PatologiAnatomyID as xid, + Other_PatologiAnatomyT_OrderDetailID as orderdetail_id, + Other_PatologiAnatomyNoSediaan as no_sediaan, + Other_PatologiAnatomyDiagnosaKlinis as diagnosa, + Other_PatologiAnatomyKeteranganKlinis as klinis, + Other_PatologiAnatomyLokasiOrgan as lokasi, + Other_PatologiAnatomyMakroskopik as makroskopik, + Other_PatologiAnatomyMikroskopik as mikroskopik, + Other_PatologiAnatomyKesimpulan as kesimpulan, + IFNULL(Other_PatologiAnatomyM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_PatologiAnatomyM_DoctorID) OR Other_PatologiAnatomyM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_patologi_anatomy + LEFT JOIN m_doctor ON Other_PatologiAnatomyM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_PatologiAnatomyT_OrderDetailID = {$id} AND Other_PatologiAnatomyIsActive = 'Y' + GROUP BY Other_PatologiAnatomyID + ORDER BY Other_PatologiAnatomyID ASC + LIMIT 1"; + $query = $this->db_smartone->query($sql); + + if ($query) { + $rows = $query->row_array(); + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + + $sql = "SELECT So_ImageUploadPatologyAnatomyID as xid, + CONCAT('/one-media/one-image-nonlab/',So_ImageUploadPatologyAnatomyNewName) as image_url, + So_ImageUploadPatologyAnatomyType as type + FROM t_orderdetail + JOIN so_imageupload_patology_anatomy ON So_ImageUploadPatologyAnatomyT_OrderHeaderID= T_OrderDetailT_OrderHeaderID AND + So_ImageUploadPatologyAnatomyIsActive= 'Y' + WHERE + T_OrderDetailID = {$id} AND + T_OrderDetailIsActive = 'Y' + GROUP BY So_ImageUploadPatologyAnatomyID"; + $images = $this->db_smartone->query($sql)->result_array(); + $mikro = []; + $makro = []; + + foreach ($images as $key => $value) { + + if ($value['type'] == 'mikro') { + $mikro[] = $value; + } + if ($value['type'] == 'makro') { + $makro[] = $value; + } + } + + $rst = array('doctors' => $doctors, 'result' => $rows, "mikro" => $mikro, "makro" => $makro); + $this->sys_ok(["records" => $rst]); + } else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + + function uploadimage() + { + if (! $this->isLogin) { + $this->sys_error("Invalid Token"); + exit; + } + + $userid = $this->sys_user["M_UserID"]; + $data = []; + //print_r($_SERVER); + + $prm = $this->sys_input; + $orderid = $this->input->post('orderid'); + $labnumber = $this->input->post('labnumber'); + $sql = "UPDATE so_imageupload SET + So_ImageUploadIsActive = 'N', + So_ImageUploadUserID = {$userid} + WHERE + So_ImageUploadT_OrderHeaderID = {$orderid}"; + //echo $sql; + $this->db_onedev->query($sql); + //$config['upload_path'] = 'assets/'; + + $path = '/home/one/project/one/one-media/one-image-nonlab/'; + //echo $path; + $config['upload_path'] = $path; + $config['allowed_types'] = 'jpg|jpeg|png|gif'; + + $config['max_size'] = '10000'; + $count = count($_FILES['files']['name']); + //echo $count; + $this->load->library('upload', $config); + + $error = []; + for ($i = 0; $i < $count; $i++) { + + + if (!empty($_FILES['files']['name'][$i])) { + + + + $_FILES['file']['name'] = $_FILES['files']['name'][$i]; + + $_FILES['file']['type'] = $_FILES['files']['type'][$i]; + + $_FILES['file']['tmp_name'] = $_FILES['files']['tmp_name'][$i]; + + $_FILES['file']['error'] = $_FILES['files']['error'][$i]; + + $_FILES['file']['size'] = $_FILES['files']['size'][$i]; + + + + $namex = $orderid . '-' . $labnumber . '-' . $this->generateRandomString(5); + //echo $namex; + + $config['file_name'] = $namex; + $this->upload->initialize($config); + //echo $config['file_name'] ; + + + + + + if ($this->upload->do_upload('file')) { + + $uploadData = $this->upload->data(); + + $filename = $uploadData['file_name']; + //echo $filename; + + + $sql = "INSERT INTO so_imageupload ( + So_ImageUploadT_OrderHeaderID, + So_ImageUploadT_OrderHeaderLabNumber, + So_ImageUploadT_SampleTypeID, + So_ImageUploadOldName, + So_ImageUploadNewName, + So_ImageUploadCreated, + So_ImageUploadUserID + ) + VALUES( + {$orderid}, + '{$labnumber}', + '150', + '{$_FILES['files']['name'][$i]}', + '{$filename}', + NOW(), + {$userid} + + )"; + //echo $sql; + $this->db_onedev->query($sql); + $xlast_id = $this->db_onedev->insert_id(); + $data['totalFiles'][] = array('xid' => $xlast_id, 'image_url' => '/one-media/one-image-nonlab/' . $filename); + } else { + $error = array('error' => $this->upload->display_errors()); + } + } + } + + $result = array("total" => count($data['totalFiles']), "records" => $data['totalFiles'], 'errors' => $error); + $this->sys_ok($result); + } + + + function generateRandomString($length = 10) + { + $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; + $charactersLength = strlen($characters); + $randomString = ''; + for ($i = 0; $i < $length; $i++) { + $randomString .= $characters[rand(0, $charactersLength - 1)]; + } + return $randomString; + } + + function getcytologiresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT Other_CytologiDetailsID as xid, + Other_CytologiT_OrderDetailID as orderdetail_id, + Other_CytologiDetailsCode as code, + Other_CytologiDetailsLabel as label, + Other_CytologiDetailsResult as result, + IFNULL(Other_CytologiM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_CytologiM_DoctorID) OR Other_CytologiM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_cytologi + JOIN other_cytologidetails ON Other_CytologiDetailsOther_CytologiID = Other_CytologiID AND Other_CytologiDetailsIsActive = 'Y' + LEFT JOIN m_doctor ON Other_CytologiM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_CytologiT_OrderDetailID = {$id} AND Other_CytologiIsActive = 'Y' + GROUP BY Other_CytologiDetailsID + ORDER BY Other_CytologiDetailsCode ASC"; + //echo $sql; + $query = $this->db_smartone->query($sql); + + if ($query) { + $rows = $query->result_array(); + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $rst = array('doctors' => $doctors, 'results' => $rows); + $this->sys_ok(["records" => $rst]); + } else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + function getmikroresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT + Other_MikroID as xid, + Other_MikroHasilBiakan as hasil_biakan, + Other_MikroSampleTypeName as sample_name, + Other_MikroT_OrderDetailID as orderdetail_id, + Other_MikroResult as result_value, + '' as result_other, + IFNULL(T_BacteriaID,0) as T_BacteriaID, + IFNULL(T_BacteriaName,'') as T_BacteriaName, + '' as details, + IFNULL(Other_MikroM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_MikroM_DoctorID) OR Other_MikroM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_mikro + LEFT JOIN t_bacteria ON Other_MikroT_BacteriaID = T_BacteriaID + LEFT JOIN m_doctor ON Other_MikroM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_MikroT_OrderDetailID = {$id} AND Other_MikroIsActive = 'Y' + GROUP BY Other_MikroID"; + //echo $sql; + $query = $this->db_smartone->query($sql); + + if ($query) { + $row = $query->row_array(); + if ($row) { + if ($row['result_value'] != 'Positif' && $row['result_value'] != 'Negatif') { + $row['result_other'] = $row['result_value']; + $row['result_value'] = 'other'; + } + $sql = "SELECT '' as xno, + Other_MikroDetailsID as xid, + Other_MikroDetailsValue as value, + IF(Other_MikroDetailsNote = 'R','Y','N') as chx_r, + IF(Other_MikroDetailsNote = 'I','Y','N') as chx_i, + IF(Other_MikroDetailsNote = 'S','Y','N') as chx_s, + Other_MikroDetailsNote as note, + t_antibiotic.* + FROM other_mikrodetails + LEFT JOIN t_antibiotic ON Other_MikroDetailsT_AntibioticID = T_AntibioticID + WHERE + Other_MikroDetailsOther_MikroID = {$row['xid']} AND Other_MikroDetailsIsActive = 'Y' + GROUP BY Other_MikroDetailsID + ORDER BY T_AntibioticName ASC"; + //echo $sql; + $details = $this->db_smartone->query($sql)->result_array(); + if (details) { + foreach ($details as $k => $v) { + $details[$k]['xno'] = $k + 1; + } + } + $row['details'] = $details; + } else { + $row = array('xid' => '0', 'hasil_biakan' => '', 'result_value' => 'Negatif', 'sample_name' => '', 'orderdetail_id' => $id, 'T_BacteriaID' => '0', 'T_BacteriaName' => '0', 'details' => array(), 'doctor_id' => '0', 'doctor_name' => '0'); + } + } else { + $row = array('xid' => '0', 'hasil_biakan' => '', 'result_value' => 'Negatif', 'sample_name' => '', 'orderdetail_id' => $id, 'T_BacteriaID' => '0', 'T_BacteriaName' => '0', 'details' => array(), 'doctor_id' => '0', 'doctor_name' => '0'); + } + //print_r($row); + + + + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 7 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $sql = " + SELECT '0' as id, 'Belum memilih bakteria' as name + UNION + SELECT T_BacteriaID as id, T_BacteriaName as name + FROM t_bacteria + WHERE + T_BacteriaIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $bacteries = $this->db_smartone->query($sql)->result_array(); + $rst = array('doctors' => $doctors, 'bacteries' => $bacteries, 'results' => $row); + $this->sys_ok(["records" => $rst]); + } + function getantibiotics() + { + $prm = $this->sys_input; + $id = $prm["id"]; + $sql = " SELECT '' as xno, + 0 as xid, + '' as hasil_biakan, + '' as sample_name, + 0 as value, + 'Y' as chx_r, + 'N' as chx_i, + 'N' as chx_s, + 'R' as note, + t_antibiotic.* + FROM t_antibiotic + WHERE + T_AntibioticT_BacteriaID = {$prm['id']} AND T_AntibioticIsActive= 'Y' + ORDER BY T_AntibioticName ASC"; + //echo $sql; + $rows = $this->db_smartone->query($sql)->result_array(); + if (rows) { + foreach ($rows as $k => $v) { + $rows[$k]['xno'] = $k + 1; + } + } + + $this->sys_ok(["records" => $rows]); + } + function getlcprepresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + $sql = " SELECT Other_LcprepDetailsID as xid, + Other_LcprepID as header_id, + Other_LcprepT_orderDetailID as orderdetail_id, + Other_LcprepDetailsCode as code, + Other_LcprepDetailsLabel as label, + Other_LcprepDetailsResult as result, + IFNULL(Other_LcprepM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_LcprepM_DoctorID) OR Other_LcprepM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_lcprep + JOIN other_lcprepdetails ON Other_LcprepDetailsOther_LcprepID = Other_LcprepID AND Other_LcprepDetailsIsActive = 'Y' + LEFT JOIN m_doctor ON Other_LcprepM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_LcprepT_orderDetailID = {$id} AND Other_LcprepIsActive = 'Y' + GROUP BY Other_LcprepDetailsOther_LcprepID, Other_LcprepDetailsCode + ORDER BY Other_LcprepDetailsCode ASC"; + //echo $sql; + $rows = $this->db_smartone->query($sql)->result_array(); + if (!$rows) { + $rows = array( + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'A', + 'label' => 'DESKRIPSI', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ), + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'B', + 'label' => 'KESIMPULAN', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ) + ); + } + + $header_id = $rows[0]['header_id']; + $sql = "SELECT IFNULL(Other_LcprepAdekuasiID,0) as xid, + Lcprep_AdekuasiID as id, + Lcprep_AdekuasiLabel as name, + IF(ISNULL(Other_LcprepAdekuasiID),'N',Other_LcprepAdekuasiChex) as chex + FROM lcprep_adekuasi + LEFT JOIN other_lcprepadekuasi ON Other_LcprepAdekuasiLcprep_AdekuasiID = Lcprep_AdekuasiID AND + Other_LcprepAdekuasiOther_LcprepID = {$header_id} AND + Other_LcprepAdekuasiIsActive = 'Y' + WHERE + Lcprep_AdekuasiIsActive = 'Y' + GROUP BY Lcprep_AdekuasiID + ORDER BY Lcprep_AdekuasiOrder ASC + "; + //echo $sql; + $adeakuasi = $this->db_smartone->query($sql)->result_array(); + foreach ($adeakuasi as $kc => $vc) { + $adeakuasi[$kc]['chex'] = $vc['chex'] == 'N' ? false : true; + } + + $sql = "SELECT IFNULL(Other_LcprepKategoriUmumID,0) as xid, + Lcprep_KategoriUmumID as id, + Lcprep_KategoriUmumLabel as name, + IF(ISNULL(Other_LcprepKategoriUmumID),'N',Other_LcprepKategoriUmumChex) as chex + FROM lcprep_kategoriumum + LEFT JOIN other_lcprepkategoriumum ON Other_LcprepKategoriUmumLcprep_KategoriUmumID = Lcprep_KategoriUmumID AND + Other_LcprepKategoriUmumOther_LcprepID = {$header_id} AND + Other_LcprepKategoriUmumIsActive = 'Y' + WHERE + Lcprep_KategoriUmumIsActive = 'Y' + GROUP BY Lcprep_KategoriUmumID + "; + //echo $sql; + $kategoriumum = $this->db_smartone->query($sql)->result_array(); + foreach ($kategoriumum as $kc => $vc) { + $kategoriumum[$kc]['chex'] = $vc['chex'] == 'N' ? false : true; + } + + $sql = " + SELECT Lcprep_InterpretasiGroupID as group_id, + Lcprep_InterpretasiGroupName as group_name, + '' as subgroups + FROM lcprep_interpretasigroup + WHERE + Lcprep_InterpretasiGroupIsActive = 'Y' + "; + //echo $sql; + $interpretasi = $this->db_smartone->query($sql)->result_array(); + foreach ($interpretasi as $k => $v) { + $subgroups = array(); + $sql = "SELECT Lcprep_InterpretasiSubgroupID as subgroup_id, + Lcprep_InterpretasiSubgroupName as subgroup_name, + '' as childs + FROM lcprep_interpretasisubgroup + WHERE + Lcprep_InterpretasiSubgroupLcprep_InterpretasiGroupID = {$v['group_id']} AND Lcprep_InterpretasiSubgroupIsActive = 'Y'"; + //echo $sql; + $subgroups = $this->db_smartone->query($sql)->result_array(); + if (count($subgroups) > 0) { + foreach ($subgroups as $ki => $vi) { + $childs = array(); + $sql = "SELECT IFNULL(Other_LcprepInterpretasiID,0) as xid, + IFNULL(Other_LcprepInterpretasiChex,'N') as chex, + IFNULL(Other_LcprepInterpretasiValue,'') as value, + Lcprep_InterpretasiID as id, + Lcprep_InterpretasiLcprep_InterpretasiSubgroupID as subgroup_id, + Lcprep_InterpretasiCode as code, + Lcprep_InterpretasiName as name, + Lcprep_InterpretasiParentID as parent_id, + Lcprep_InterpretasiIsParent as is_parent, + Lcprep_InterpretasiHasResult as has_result, + Lcprep_InterpretasiTypeResult as type_result + FROM lcprep_interpretasi + LEFT JOIN other_lcprepinterpretasi ON Other_LcprepInterpretasiOther_LcprepID = {$header_id} AND + Other_LcprepInterpretasiLcprep_InterpretasiID = Lcprep_InterpretasiID AND + Other_LcprepInterpretasiIsActive = 'Y' + WHERE + Lcprep_InterpretasiLcprep_InterpretasiSubgroupID = {$vi['subgroup_id']} AND Lcprep_InterpretasiIsActive = 'Y' + GROUP BY Lcprep_InterpretasiID Order BY Lcprep_InterpretasiCode ASC"; + $childs = $this->db_smartone->query($sql)->result_array(); + if ($childs) { + foreach ($childs as $kc => $vc) { + $childs[$kc]['chex'] = $vc['chex'] == 'N' ? false : true; + } + } + $subgroups[$ki]['childs'] = $childs; + } + } + + $interpretasi[$k]['subgroups'] = $subgroups; + } + + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $rst = array('doctors' => $doctors, 'results' => $rows, 'adekuasi' => $adeakuasi, 'kategoriumum' => $kategoriumum, 'interpretasi' => $interpretasi); + $this->sys_ok(["records" => $rst]); + } + + function getpapsmearresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT Other_PapSmearDetailsID as xid, + Other_PapSmearID as header_id, + Other_PapSmearT_OrderDetailID as orderdetail_id, + Other_PapSmearDetailsCode as code, + Other_PapSmearDetailsLabel as label, + Other_PapSmearDetailsResult as result, + IFNULL(Other_PapSmearM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_PapSmearM_DoctorID) OR Other_PapSmearM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_papsmear + JOIN other_papsmeardetails ON Other_PapSmearDetailsOther_PapSmearID = Other_PapSmearID AND Other_PapSmearDetailsIsActive = 'Y' + LEFT JOIN m_doctor ON Other_PapSmearM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_PapSmearT_OrderDetailID = {$id} AND Other_PapSmearIsActive = 'Y' + GROUP BY Other_PapSmearDetailsID + ORDER BY Other_PapSmearDetailsCode ASC"; + //echo $sql; + $rows = $this->db_smartone->query($sql)->result_array(); + if (!$rows) { + $rows = array( + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'A', + 'label' => 'Makroskopik', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ), + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'B', + 'label' => 'Mikroskopik', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ), + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'C', + 'label' => 'Kesimpulan', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ) + ); + } + + $header_id = $rows[0]['header_id']; + $sql = "SELECT Other_PapSmearMaturasiID as xid, + Other_PapSmearMaturasiValue as value + FROM other_papsmearmaturasi + WHERE + Other_PapSmearMaturasiOther_PapSmearID = {$header_id} AND + Other_PapSmearMaturasiIsActive = 'Y' + "; + //echo $sql; + $dt_maturasi = $this->db_smartone->query($sql)->row_array(); + if (!$dt_maturasi) { + $maturasi = array('xid' => '0', 'value' => array('', '', '')); + } else { + $value = explode('/', $dt_maturasi['value']); + $maturasi = array('xid' => $dt_maturasi['xid'], 'value' => $value); + } + + $sql = "SELECT IFNULL(Other_PapSmearBahanID,0) as xid, + M_PapSmearBahanID as bahan_id, + M_PapSmearBahanName as name, + IF(ISNULL(Other_PapSmearBahanID),'N','Y') as selected + FROM m_papsmearbahan + LEFT JOIN other_papsmearbahan ON Other_PapSmearBahanM_PapSmearBahanID = M_PapSmearBahanID AND + Other_PapSmearBahanOther_PapSmearID = {$header_id} AND + Other_PapSmearBahanIsActive = 'Y' + WHERE + M_PapSmearBahanIsActive = 'Y' + ORDER BY M_PapSmearBahanID ASC + "; + //echo $sql; + $bahans = $this->db_smartone->query($sql)->result_array(); + + $sql = "SELECT IFNULL(Other_PapsmearCategoryID,0) as xid, + M_PapSmearCategoryID as category_id, + M_PapSmearCategoryName as name, + IF(ISNULL(Other_PapsmearCategoryID),'N','Y') as selected + FROM m_papsmearcategory + LEFT JOIN other_papsmearcategory ON Other_PapsmearCategoryM_PapSmearCategoryID = M_PapSmearCategoryID AND + Other_PapsmearCategoryOther_PapSmearID = {$header_id} AND + Other_PapsmearCategoryIsActive = 'Y' + WHERE + M_PapSmearCategoryIsActive = 'Y' + ORDER BY M_PapSmearCategoryID ASC + "; + //echo $sql; + $categories = $this->db_smartone->query($sql)->result_array(); + + $sql = "SELECT IFNULL(Other_PapSmearCheckID,0) as xid, + M_PapSmearCheckID as check_id, + M_PapSmearCheckLabel as name, + IF(ISNULL(Other_PapSmearCheckID),'N','Y') as selected, + Other_PapSmearCheckNote as note + FROM m_papsmearcheck + LEFT JOIN other_papsmearcheck ON Other_PapSmearCheckM_PapSmearCheckID = M_PapSmearCheckID AND + Other_PapSmearCheckOther_PapSmearID = {$header_id} AND + Other_PapSmearCheckIsActive = 'Y' + WHERE + M_PapSmearCheckIsActive = 'Y' + ORDER BY M_PapSmearCheckCode ASC + "; + $checks = $this->db_smartone->query($sql)->result_array(); + + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $rst = array('doctors' => $doctors, 'checks' => $checks, 'bahans' => $bahans, 'categories' => $categories, 'maturasi' => $maturasi, 'results' => $rows); + $this->sys_ok(["records" => $rst]); + } + + function saveresult_lcprep() + { + $prm = $this->sys_input; + $detail_id = $prm['detail_id']; + $doctor_id = $prm['doctor']; + $adekuasi = $prm['adekuasi']; + $kategoriumum = $prm['kategoriumum']; + $interpretasi = $prm['interpretasi']; + $results = $prm['results']; + + $userid = $this->sys_user['M_UserID']; + + $header_id = 0; + $sql = "SELECT * FROM other_lcprep WHERE Other_LcprepT_orderDetailID = {$detail_id} AND Other_LcprepIsActive = 'Y'"; + $dt_header = $this->db_smartone->query($sql)->row_array(); + if ($dt_header) { + $header_id = $dt_header['Other_LcprepID']; + } + if ($header_id == 0) { + $sql = "INSERT INTO other_lcprep( + Other_LcprepT_orderDetailID, + Other_LcprepM_DoctorID, + Other_LcprepUserID, + Other_LcprepCreated + ) + VALUES( + {$detail_id}, + {$doctor_id}, + {$userid}, + NOW() + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } else { + $sql = "UPDATE other_lcprep SET Other_LcprepM_DoctorID = {$doctor_id}, Other_LcprepUserID = {$userid} WHERE Other_LcprepID = {$header_id}"; + $this->db_smartone->query($sql); + } + + if ($adekuasi) { + foreach ($adekuasi as $k => $v) { + $selected = $v['chex'] ? 'Y' : 'N'; + if (intval($v['xid'] == 0)) { + $sql = "UPDATE other_lcprepadekuasi SET Other_LcprepAdekuasiIsActive = 'N' + WHERE + Other_LcprepAdekuasiOther_LcprepID = {$header_id} AND + Other_LcprepAdekuasiIsActive = 'Y' AND + Other_LcprepAdekuasiLcprep_AdekuasiID = {$v['id']}"; + $this->db_smartone->query($sql); + $sql = "INSERT INTO other_lcprepadekuasi ( + Other_LcprepAdekuasiOther_LcprepID, + Other_LcprepAdekuasiLcprep_AdekuasiID, + Other_LcprepAdekuasiChex, + Other_LcprepAdekuasiUserID, + Other_LcprepAdekuasiCreated + ) + VALUES( + {$header_id}, + {$v['id']}, + '{$selected}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + //echo $sql; + } + if (intval($v['xid'] != 0)) { + + $sql = "UPDATE other_lcprepadekuasi SET + Other_LcprepAdekuasiChex = '{$selected}', + Other_LcprepAdekuasiUserID = {$userid} + WHERE + Other_LcprepAdekuasiID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + + //echo $sql; + } + } + + if ($kategoriumum) { + foreach ($kategoriumum as $k => $v) { + $selected = $v['chex'] ? 'Y' : 'N'; + if (intval($v['xid'] == 0)) { + $sql = "UPDATE other_lcprepkategoriumum SET Other_LcprepKategoriUmumIsActive = 'N' + WHERE + Other_LcprepKategoriUmumOther_LcprepID = {$header_id} AND + Other_LcprepKategoriUmumLcprep_KategoriUmumID = {$v['id']} AND + Other_LcprepKategoriUmumIsActive = 'Y' + "; + $this->db_smartone->query($sql); + $sql = "INSERT INTO other_lcprepkategoriumum ( + Other_LcprepKategoriUmumOther_LcprepID, + Other_LcprepKategoriUmumLcprep_KategoriUmumID, + Other_LcprepKategoriUmumChex, + Other_LcprepKategoriUmumUserID, + Other_LcprepKategoriUmumCreated + ) + VALUES( + {$header_id}, + {$v['id']}, + '{$selected}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if (intval($v['xid'] != 0)) { + $sql = "UPDATE other_lcprepkategoriumum SET + Other_LcprepKategoriUmumChex = '{$selected}', + Other_LcprepKategoriUmumUserID = {$userid} + WHERE + Other_LcprepKategoriUmumID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + + //echo $sql; + } + } + + if ($results) { + foreach ($results as $k => $v) { + if (intval($v['xid'] == 0)) { + $sql = "UPDATE other_lcprepdetails SET Other_LcprepDetailsIsActive = 'N' + WHERE + Other_LcprepDetailsOther_LcprepID = {$header_id} AND + Other_LcprepDetailsCode = '{$v['code']}' AND + Other_LcprepDetailsIsActive = 'Y'"; + $this->db_smartone->query($sql); + $sql = "INSERT INTO other_lcprepdetails ( + Other_LcprepDetailsOther_LcprepID, + Other_LcprepDetailsCode, + Other_LcprepDetailsLabel, + Other_LcprepDetailsResult, + Other_LcprepDetailsUserID, + Other_LcprepDetailsCreated + ) + VALUES( + {$header_id}, + '{$v['code']}', + '{$v['label']}', + '{$v['result']}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if (intval($v['xid'] != 0)) { + $sql = "UPDATE other_lcprepdetails SET + Other_LcprepDetailsCode = '{$v['code']}', + Other_LcprepDetailsLabel = '{$v['label']}', + Other_LcprepDetailsResult = '{$v['result']}', + Other_LcprepDetailsUserID = {$userid} + WHERE + Other_LcprepDetailsID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + //echo $sql; + } + } + + if ($interpretasi) { + foreach ($interpretasi as $k => $v) { + if (count($v['subgroups']) > 0) { + foreach ($v['subgroups'] as $ik => $iv) { + if (count($iv['childs']) > 0) { + foreach ($iv['childs'] as $iik => $iiv) { + if (intval($iiv['xid'] == 0)) { + $chex = $iiv['chex'] ? 'Y' : 'N'; + $sql = "UPDATE other_lcprepinterpretasi SET Other_LcprepInterpretasiIsActive = 'N' + WHERE + Other_LcprepInterpretasiOther_LcprepID = {$header_id} AND + Other_LcprepInterpretasiLcprep_InterpretasiID = '{$iiv['id']}' AND + Other_LcprepInterpretasiIsActive = 'Y'"; + $this->db_smartone->query($sql); + $sql = "INSERT INTO other_lcprepinterpretasi ( + Other_LcprepInterpretasiOther_LcprepID, + Other_LcprepInterpretasiLcprep_InterpretasiID, + Other_LcprepInterpretasiChex, + Other_LcprepInterpretasiValue, + Other_LcprepInterpretasiUserID, + Other_LcprepInterpretasiCreated + ) + VALUES( + {$header_id}, + '{$iiv['id']}', + '{$chex}', + '{$iiv['value']}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + + if (intval($iiv['xid'] != 0)) { + $chex = $iiv['chex'] ? 'Y' : 'N'; + $sql = "UPDATE other_lcprepinterpretasi SET + Other_LcprepInterpretasiChex = '{$chex}', + Other_LcprepInterpretasiValue = '{$iiv['value']}', + Other_LcprepInterpretasiUserID = {$userid} + WHERE + Other_LcprepInterpretasiID = {$iiv['xid']}"; + $this->db_smartone->query($sql); + //echo $sql; + + } + } + } + } + } + //echo $sql; + } + } + + + $result = array("total" => 1, "records" => array(), "sql" => ''); + $this->sys_ok($result); + exit; + } + + function saveresult_papsmear() + { + $prm = $this->sys_input; + $detail_id = $prm['detail_id']; + $doctor_id = $prm['doctor']; + $checks = $prm['checks']; + $maturasi = $prm['maturasi']; + $bahans = $prm['bahans']; + $categories = $prm['categories']; + $results = $prm['results']; + + $userid = $this->sys_user['M_UserID']; + + $header_id = 0; + $sql = "SELECT * FROM other_papsmear WHERE Other_PapSmearT_OrderDetailID = {$detail_id} AND Other_PapSmearIsActive = 'Y'"; + $dt_header = $this->db_smartone->query($sql)->row_array(); + if ($dt_header) { + $header_id = $dt_header['Other_PapSmearID']; + } + if ($header_id == 0) { + $sql = "INSERT INTO other_papsmear( + Other_PapSmearT_OrderDetailID, + Other_PapSmearM_DoctorID, + Other_PapSmearUserID, + Other_PapSmearCreated + ) + VALUES( + {$detail_id}, + {$doctor_id}, + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } else { + $sql = "UPDATE other_papsmear SET Other_PapSmearM_DoctorID = {$doctor_id}, Other_PapSmearUserID = {$userid} WHERE Other_PapSmearID = {$header_id}"; + $this->db_smartone->query($sql); + } + + if ($checks) { + foreach ($checks as $k => $v) { + if (intval($v['xid']) == 0 && $v['selected'] === 'Y') { + $sql = "INSERT INTO other_papsmearcheck ( + Other_PapSmearCheckOther_PapSmearID, + Other_PapSmearCheckM_PapSmearCheckID, + Other_PapSmearCheckNote, + Other_PapSmearCheckUserID, + Other_PapSmearCheckCreated + ) + VALUES( + {$header_id}, + {$v['check_id']}, + '{$v['note']}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if (intval($v['xid']) != 0 && $v['selected'] === 'N') { + $sql = "UPDATE other_papsmearcheck SET + Other_PapSmearCheckIsActive = 'N', + Other_PapSmearCheckUserID = {$userid} + WHERE + Other_PapSmearCheckID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + if (intval($v['xid']) != 0 && $v['selected'] === 'Y') { + $sql = "UPDATE other_papsmearcheck SET + Other_PapSmearCheckNote = '{$v['note']}', + Other_PapSmearCheckUserID = {$userid} + WHERE + Other_PapSmearCheckID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + //echo $sql; + } + } + + if ($maturasi) { + if (intval($maturasi['xid']) == 0) { + $value = join("/", $maturasi['value']); + $sql = "INSERT INTO other_papsmearmaturasi ( + Other_PapSmearMaturasiOther_PapSmearID, + Other_PapSmearMaturasiValue, + Other_PapSmearMaturasiUserID, + Other_PapSmearMaturasiCreated + ) + VALUE( + {$header_id}, + '{$value}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + //echo $sql; + } + if (intval($maturasi['xid']) != 0) { + $value = join("/", $maturasi['value']); + $sql = "UPDATE other_papsmearmaturasi SET + Other_PapSmearMaturasiValue = '{$value}', + Other_PapSmearMaturasiUserID = {$userid} + WHERE + Other_PapSmearMaturasiID = {$maturasi['xid']}"; + // echo $sql; + $this->db_smartone->query($sql); + } + } + + if ($bahans) { + foreach ($bahans as $k => $v) { + if (intval($v['xid']) == 0 && $v['selected'] === 'Y') { + $sql = "INSERT INTO other_papsmearbahan ( + Other_PapSmearBahanOther_PapSmearID, + Other_PapSmearBahanM_PapSmearBahanID, + Other_PapSmearBahanUserID, + Other_PapSmearBahanCreated + ) + VALUES( + {$header_id}, + {$v['bahan_id']}, + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if (intval($v['xid']) != 0 && $v['selected'] === 'N') { + $sql = "UPDATE other_papsmearbahan SET + Other_PapSmearBahanIsActive = 'N', + Other_PapsmearCategoryUserID = {$userid} + WHERE + Other_PapSmearBahanID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + if (intval($v['xid']) != 0 && $v['selected'] === 'Y') { + $sql = "UPDATE other_papsmearbahan SET + Other_PapSmearBahanIsActive = 'Y', + Other_PapsmearCategoryUserID = {$userid} + WHERE + Other_PapSmearBahanID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + //echo $sql; + } + } + + if ($categories) { + foreach ($categories as $k => $v) { + if (intval($v['xid']) == 0 && $v['selected'] === 'Y') { + $sql = "INSERT INTO other_papsmearcategory ( + Other_PapsmearCategoryOther_PapSmearID, + Other_PapsmearCategoryM_PapSmearCategoryID, + Other_PapsmearCategoryUserID, + Other_PapsmearCategoryCreated + ) + VALUES( + {$header_id}, + {$v['category_id']}, + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if (intval($v['xid']) != 0 && $v['selected'] === 'N') { + $sql = "UPDATE other_papsmearcategory SET + Other_PapsmearCategoryIsActive = 'N', + Other_PapsmearCategoryUserID = {$userid} + WHERE + Other_PapsmearCategoryID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + //echo $sql; + if (intval($v['xid']) != 0 && $v['selected'] === 'Y') { + $sql = "UPDATE other_papsmearcategory SET + Other_PapsmearCategoryIsActive = 'Y', + Other_PapsmearCategoryUserID = {$userid} + WHERE + Other_PapsmearCategoryID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + } + } + + if ($results) { + foreach ($results as $k => $v) { + if (intval($v['xid']) == 0) { + $sql = "INSERT INTO other_papsmeardetails ( + Other_PapSmearDetailsOther_PapSmearID, + Other_PapSmearDetailsCode, + Other_PapSmearDetailsLabel, + Other_PapSmearDetailsResult, + Other_PapSmearDetailsUserID, + Other_PapSmearDetailsCreated + ) + VALUES( + {$header_id}, + '{$v['code']}', + '{$v['label']}', + '{$v['result']}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if (intval($v['xid']) != 0) { + $sql = "UPDATE other_papsmeardetails SET + Other_PapSmearDetailsCode = '{$v['code']}', + Other_PapSmearDetailsLabel = '{$v['label']}', + Other_PapSmearDetailsResult = '{$v['result']}', + Other_PapSmearDetailsUserID = {$userid} + WHERE + Other_PapSmearDetailsID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + //echo $sql; + } + } + + $result = array("total" => 1, "records" => array(), "sql" => ''); + $this->sys_ok($result); + exit; + } + + function saveresult_fna() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = $inp['doctor']; + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + if ($prm[0]['xid'] == '0') { + $sql = "INSERT INTO other_fna( + Other_FNAM_DoctorID, + Other_FNAT_OrderDetailID, + Other_FNAUserID, + Other_FNACreated + ) + VALUES( + {$doctor_id}, + {$prm[0]['orderdetail_id']}, + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } else { + $sql = "SELECT * FROM other_fna WHERE Other_FNAT_OrderDetailID = {$prm[0]['orderdetail_id']} AND Other_FNAIsActive = 'Y'"; + $data_header = $this->db_smartone->query($sql)->row_array(); + $header_id = $data_header['Other_FNAID']; + $sql = "UPDATE other_fna SET + Other_FNAM_DoctorID = {$doctor_id}, + Other_FNAUserID = {$userid} + WHERE + Other_FNAID = {$header_id}"; + $this->db_smartone->query($sql); + } + foreach ($prm as $k => $v) { + if ($v['xid'] == '0') { + $results = str_replace("'", "\\'", $v['result']); + $sql = "INSERT INTO other_fnadetails( + Other_FNADetailsOther_FNAID , + Other_FNADetailsCode, + Other_FNADetailsLabel, + Other_FNADetailsResult, + Other_FNADetailsCreated, + Other_FNADetailsUserID + ) + VALUES( + {$header_id}, + '{$v['code']}', + '{$v['label']}', + '{$results}', + NOW(), + {$userid} + )"; + $query = $this->db_smartone->query($sql); + } else { + $results = str_replace("'", "\\'", $v['result']); + $sql = "UPDATE other_fnadetails SET + Other_FNADetailsResult = '{$results}', + Other_FNADetailsUserID = {$userid} + WHERE + Other_FNADetailsID = {$v['xid']}"; + $query = $this->db_smartone->query($sql); + } + } + + $result = array("total" => 1, "records" => array(), "sql" => ''); + $this->sys_ok($result); + exit; + } + + function saveresult_cytologi() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = $inp['doctor']; + + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + if ($prm[0]['xid'] == '0') { + $sql = "INSERT INTO other_cytologi( + Other_CytologiT_OrderDetailID, + Other_CytologiM_DoctorID, + Other_CytologiUserID, + Other_CytologiCreated + ) + VALUES( + {$prm[0]['orderdetail_id']}, + {$doctor_id}, + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } else { + $sql = "SELECT * FROM other_cytologi WHERE Other_CytologiT_OrderDetailID = {$prm[0]['orderdetail_id']} AND Other_CytologiIsActive = 'Y'"; + $data_header = $this->db_smartone->query($sql)->row_array(); + $header_id = $data_header['Other_CytologiID']; + $sql = "UPDATE other_cytologi SET + Other_CytologiM_DoctorID = {$doctor_id}, + Other_CytologiUserID = {$userid} + WHERE + Other_CytologiID = {$header_id}"; + $this->db_smartone->query($sql); + } + foreach ($prm as $k => $v) { + if ($v['xid'] == '0') { + $results = str_replace("'", "\\'", $v['result']); + $sql = "INSERT INTO other_cytologidetails( + Other_CytologiDetailsOther_CytologiID , + Other_CytologiDetailsCode, + Other_CytologiDetailsLabel, + Other_CytologiDetailsResult, + Other_CytologiDetailsCreated, + Other_CytologiDetailsUserID + ) + VALUES( + {$header_id}, + '{$v['code']}', + '{$v['label']}', + '{$results}', + NOW(), + {$userid} + )"; + $query = $this->db_smartone->query($sql); + } else { + $results = str_replace("'", "\\'", $v['result']); + $sql = "UPDATE other_cytologidetails SET + Other_CytologiDetailsResult = '{$results}', + Other_CytologiDetailsUserID = {$userid} + WHERE + Other_CytologiDetailsID = {$v['xid']}"; + $query = $this->db_smartone->query($sql); + } + } + + $result = array("total" => 1, "records" => array(), "sql" => ''); + $this->sys_ok($result); + exit; + } + + function saveresult_mikro() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = $inp['doctor']; + $backteria_id = $inp['bacteria']; + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + + if ($inp['result_value'] != 'Negatif' && $inp['result_value'] != 'Positif') { + $prm['result_value'] = $prm['result_other']; + } else { + $prm['result_value'] = $inp['result_value']; + } + + if ($prm['xid'] == '0') { + $sql = "INSERT INTO other_mikro( + Other_MikroM_DoctorID, + Other_MikroResult, + Other_MikroT_BacteriaID, + Other_MikroT_OrderDetailID, + Other_MikroHasilBiakan, + Other_MikroSampleTypeName, + Other_MikroUserID, + Other_MikroCreated + ) + VALUES( + {$doctor_id}, + '{$prm['result_value']}', + {$backteria_id}, + {$prm['orderdetail_id']}, + '{$prm['hasil_biakan']}', + '{$prm['sample_name']}', + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } else { + $sql = "SELECT * FROM other_mikro WHERE Other_MikroT_OrderDetailID = {$prm['orderdetail_id']} AND Other_MikroIsActive = 'Y'"; + $data_header = $this->db_smartone->query($sql)->row_array(); + $header_id = $data_header['Other_MikroID']; + $sql = "UPDATE other_mikro SET + Other_MikroResult = '{$prm['result_value']}', + Other_MikroM_DoctorID = {$doctor_id}, + Other_MikroT_BacteriaID = {$backteria_id}, + Other_MikroHasilBiakan = '{$prm['hasil_biakan']}', + Other_MikroSampleTypeName = '{$prm['sample_name']}', + Other_MikroUserID = {$userid} + WHERE + Other_MikroID = {$header_id}"; + //echo $sql; + $this->db_smartone->query($sql); + } + + + + $sql = "UPDATE other_mikrodetails SET Other_MikroDetailsIsActive = 'N', Other_MikroDetailsUserID = 0 WHERE Other_MikroDetailsOther_MikroID = {$header_id}"; + $this->db_smartone->query($sql); + + $results = $prm['details']; + if ($inp['result_value'] == 'Positif') { + foreach ($results as $k => $v) { + if ($v['xid'] == '0') { + $sql = "INSERT INTO other_mikrodetails( + Other_MikroDetailsOther_MikroID , + Other_MikroDetailsT_AntibioticID, + Other_MikroDetailsValue, + Other_MikroDetailsNote, + Other_MikroDetailsCreated, + Other_MikroDetailsUserID + ) + VALUES( + {$header_id}, + '{$v['T_AntibioticID']}', + '{$v['value']}', + '{$v['note']}', + NOW(), + {$userid} + )"; + $query = $this->db_smartone->query($sql); + } else { + $sql = "UPDATE other_mikrodetails SET + Other_MikroDetailsT_AntibioticID = '{$v['T_AntibioticID']}', + Other_MikroDetailsValue = '{$v['value']}', + Other_MikroDetailsNote = '{$v['note']}', + Other_MikroDetailsIsActive = 'Y', + Other_MikroDetailsUserID = {$userid} + WHERE + Other_MikroDetailsID = {$v['xid']}"; + //echo $sql; + $query = $this->db_smartone->query($sql); + } + } + } + + + $result = array("total" => 1, "records" => array(), "sql" => ''); + $this->sys_ok($result); + exit; + } + + + function get_doctors_preparasi_sperma() + { + $prm = $this->sys_input; + // $id = $prm["id"]; + + $sql = " SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 10 AND + M_DoctorSOIsActive = 'Y' + ORDER BY M_DoctorName ASC"; + //echo $sql; + $query = $this->db_smartone->query($sql); + $rows = $query->result_array(); + $sql = " + SELECT '0' as id, 'Belum memilih metode' as name + UNION + SELECT M_MethodeSpermaID as id, M_MethodeSpermaName as name + FROM m_methodesperma + WHERE + M_MethodeSpermaIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $methodes = $this->db_smartone->query($sql)->result_array(); + + + $this->sys_ok(["records" => $rows, "methodes" => $methodes]); + } + + + function getpreparasispermaresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT other_preparasisperma.*, + Other_PreparasiSpermaID as xid, + Other_PreparasiSpermaT_OrderDetailID as orderdetail_id, + IFNULL(Other_PreparasiSpermaM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_PreparasiSpermaM_DoctorID) OR Other_PreparasiSpermaM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name, + IFNULL(M_MethodeSpermaID,0) as methode_id, + IFNULL(M_MethodeSpermaName,'') as methode_name + FROM other_preparasisperma + LEFT JOIN m_doctor ON Other_PreparasiSpermaM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + LEFT JOIN m_methodesperma ON Other_PreparasiSpermaM_MethodeSpermaID = M_MethodeSpermaID AND + M_MethodeSpermaIsActive = 'Y' + WHERE + Other_PreparasiSpermaT_OrderDetailID = {$id} AND Other_PreparasiSpermaIsActive = 'Y' + GROUP BY Other_PreparasiSpermaID"; + $query = $this->db_smartone->query($sql); + + if ($query) { + $rows = $query->row_array(); + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 10 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $sql = " + SELECT '0' as id, 'Belum memilih metode' as name + UNION + SELECT M_MethodeSpermaID as id, M_MethodeSpermaName as name + FROM m_methodesperma + WHERE + M_MethodeSpermaIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $methodes = $this->db_smartone->query($sql)->result_array(); + $images = array(); + $sql = "SELECT Other_PreparasiSpermaImgID as xid, + Other_PreparasiSpermaImgType as type, + CONCAT('/one-media/one-image-nonlab/',Other_PreparasiSpermaImgNewName) as image_url + FROM t_orderdetail + JOIN other_preparasisperma_img ON Other_PreparasiSpermaImgT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND + Other_PreparasiSpermaImgIsActive = 'Y' + WHERE + T_OrderDetailID = {$id} AND + T_OrderDetailIsActive = 'Y' + GROUP BY Other_PreparasiSpermaImgID"; + //echo $sql; + $images = $this->db_smartone->query($sql)->result_array(); + + $rst = array('doctors' => $doctors, 'methodes' => $methodes, 'results' => $rows, 'images' => $images); + $this->sys_ok(["records" => $rst]); + } else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + + function uploadimage_preparasi_sperma() + { + if (! $this->isLogin) { + $this->sys_error("Invalid Token"); + exit; + } + + $userid = $this->sys_user["M_UserID"]; + $data = []; + //print_r($_SERVER); + + $prm = $this->sys_input; + $orderid = $this->input->post('orderid'); + $type = $this->input->post('type'); + $labnumber = $this->input->post('labnumber'); + $sql = "UPDATE other_preparasisperma_img SET + Other_PreparasiSpermaImgIsActive = 'N', + Other_PreparasiSpermaImgUserID = {$userid} + WHERE + Other_PreparasiSpermaImgT_OrderHeaderID = {$orderid} AND + Other_PreparasiSpermaImgType = '{$type}'"; + //echo $sql; + $this->db_onedev->query($sql); + //$config['upload_path'] = 'assets/'; + + $path = '/home/one/project/one/one-media/one-image-nonlab/'; + //echo $path; + $config['upload_path'] = $path; + $config['allowed_types'] = 'jpg|jpeg|png|gif'; + + $config['max_size'] = '10000'; + $count = count($_FILES['files']['name']); + //echo $count; + $this->load->library('upload', $config); + + $error = []; + for ($i = 0; $i < $count; $i++) { + + + if (!empty($_FILES['files']['name'][$i])) { + + + + $_FILES['file']['name'] = $_FILES['files']['name'][$i]; + + $_FILES['file']['type'] = $_FILES['files']['type'][$i]; + + $_FILES['file']['tmp_name'] = $_FILES['files']['tmp_name'][$i]; + + $_FILES['file']['error'] = $_FILES['files']['error'][$i]; + + $_FILES['file']['size'] = $_FILES['files']['size'][$i]; + + + + $namex = $orderid . '-' . $labnumber . '-' . $this->generateRandomString(5); + //echo $namex; + + $config['file_name'] = $namex; + $this->upload->initialize($config); + //echo $config['file_name'] ; + + + + + + if ($this->upload->do_upload('file')) { + + $uploadData = $this->upload->data(); + + $filename = $uploadData['file_name']; + //echo $filename; + + + $sql = "INSERT INTO other_preparasisperma_img ( + Other_PreparasiSpermaImgT_OrderHeaderID, + Other_PreparasiSpermaImgType, + Other_PreparasiSpermaImgOldName, + Other_PreparasiSpermaImgNewName, + Other_PreparasiSpermaImgCreated, + Other_PreparasiSpermaImgUserID + ) + VALUES( + {$orderid}, + '{$type}', + '{$_FILES['files']['name'][$i]}', + '{$filename}', + NOW(), + {$userid} + + )"; + //echo $sql; + $this->db_onedev->query($sql); + $xlast_id = $this->db_onedev->insert_id(); + $data['totalFiles'][] = array('xid' => $xlast_id, 'type' => $type, 'image_url' => '/one-media/one-image-nonlab/' . $filename); + } else { + $error = array('error' => $this->upload->display_errors()); + } + } + } + + $result = array("total" => count($data['totalFiles']), "records" => $data['totalFiles'], 'errors' => $error); + $this->sys_ok($result); + } + + + function saveresult_preparasi_sperma() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = $inp['doctor']; + $orderdetail_id = $inp['orderdetailid']; + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + if ($prm['xid'] == '0') { + $sql = "INSERT INTO other_preparasisperma( + Other_PreparasiSpermaM_DoctorID, + Other_PreparasiSpermaT_OrderDetailID, + Other_PreparasiSpermaPreMotilitasA, + Other_PreparasiSpermaPreMotilitasB, + Other_PreparasiSpermaPreMotilitasC, + Other_PreparasiSpermaPreKonsentrasi, + Other_PreparasiSpermaPreKontaminan, + Other_PreparasiSpermaPostMotilitasA, + Other_PreparasiSpermaPostMotilitasB, + Other_PreparasiSpermaPostMotilitasC, + Other_PreparasiSpermaPostKonsentrasi, + Other_PreparasiSpermaPostKontaminan, + Other_PreparasiSpermaPreVolume, + Other_PreparasiSpermaPostVolume, + Other_PreparasiSpermaM_MethodeSpermaID, + Other_PreparasiSpermaNote, + Other_PreparasiSpermaUserID, + Other_PreparasiSpermaCreated + ) + VALUES( + {$doctor_id}, + {$orderdetail_id}, + '{$prm['Other_PreparasiSpermaPreMotilitasA']}', + '{$prm['Other_PreparasiSpermaPreMotilitasB']}', + '{$prm['Other_PreparasiSpermaPreMotilitasC']}', + '{$prm['Other_PreparasiSpermaPreKonsentrasi']}', + '{$prm['Other_PreparasiSpermaPreKontaminan']}', + '{$prm['Other_PreparasiSpermaPostMotilitasA']}', + '{$prm['Other_PreparasiSpermaPostMotilitasB']}', + '{$prm['Other_PreparasiSpermaPostMotilitasC']}', + '{$prm['Other_PreparasiSpermaPostKonsentrasi']}', + '{$prm['Other_PreparasiSpermaPostKontaminan']}', + '{$prm['Other_PreparasiSpermaPreVolume']}', + '{$prm['Other_PreparasiSpermaPostVolume']}', + '{$prm['Other_PreparasiSpermaM_MethodeSpermaID']}', + '{$prm['Other_PreparasiSpermaNote']}', + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } else { + $sql = "SELECT * FROM other_preparasisperma WHERE Other_PreparasiSpermaT_OrderDetailID = {$orderdetail_id} AND Other_PreparasiSpermaIsActive = 'Y'"; + $data_header = $this->db_smartone->query($sql)->row_array(); + $header_id = $data_header['Other_PreparasiSpermaID']; + $sql = "UPDATE other_preparasisperma SET + Other_PreparasiSpermaM_DoctorID = {$doctor_id}, + Other_PreparasiSpermaPreMotilitasA = '{$prm['Other_PreparasiSpermaPreMotilitasA']}', + Other_PreparasiSpermaPreMotilitasB = '{$prm['Other_PreparasiSpermaPreMotilitasB']}', + Other_PreparasiSpermaPreMotilitasC = '{$prm['Other_PreparasiSpermaPreMotilitasC']}', + Other_PreparasiSpermaPreKonsentrasi = '{$prm['Other_PreparasiSpermaPreKonsentrasi']}', + Other_PreparasiSpermaPreKontaminan = '{$prm['Other_PreparasiSpermaPreKontaminan']}', + Other_PreparasiSpermaPostMotilitasA = '{$prm['Other_PreparasiSpermaPostMotilitasA']}', + Other_PreparasiSpermaPostMotilitasB = '{$prm['Other_PreparasiSpermaPostMotilitasB']}', + Other_PreparasiSpermaPostMotilitasC = '{$prm['Other_PreparasiSpermaPostMotilitasC']}', + Other_PreparasiSpermaPostKonsentrasi = '{$prm['Other_PreparasiSpermaPostKonsentrasi']}', + Other_PreparasiSpermaPostKontaminan = '{$prm['Other_PreparasiSpermaPostKontaminan']}', + Other_PreparasiSpermaPreVolume = '{$prm['Other_PreparasiSpermaPreVolume']}', + Other_PreparasiSpermaPostVolume = '{$prm['Other_PreparasiSpermaPostVolume']}', + Other_PreparasiSpermaM_MethodeSpermaID = '{$prm['Other_PreparasiSpermaM_MethodeSpermaID']}', + Other_PreparasiSpermaNote = '{$prm['Other_PreparasiSpermaNote']}', + Other_PreparasiSpermaUserID = {$userid} + WHERE + Other_PreparasiSpermaID = {$header_id}"; + $this->db_smartone->query($sql); + } + + + $result = array("total" => 1, "records" => array(), "sql" => ''); + $this->sys_ok($result); + exit; + } + + function getdnafragmentasiresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT other_dnafragmentasi.*, + Other_DnaFragmentasiID as xid, + Other_DnaFragmentasiT_OrderDetailID as orderdetail_id, + IFNULL(Other_DnaFragmentasiM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_DnaFragmentasiM_DoctorID) OR Other_DnaFragmentasiM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name, + IFNULL(Other_DnaFragmentasiOther_DnaFragmentasiMethodeID,0) as methode_id, + IFNULL(Other_DnaFragmentasiMethodeName,'') as methode_name, + Other_DnaFragmentasiHaloLuas as halo_luas, + Other_DnaFragmentasiHaloSedang as halo_sedang, + Other_DnaFragmentasiHaloSempit as halo_sempit, + Other_DnaFragmentasiTanpaHalo as tanpa_halo, + Other_DnaFragmentasiDFI as dfi, + Other_DnaFragmentasiKesimpulan as kesimpulan, + Other_DnaFragmentasiCatatan as catatan + FROM other_dnafragmentasi + LEFT JOIN m_doctor ON Other_DnaFragmentasiM_DoctorID = M_DoctorID + LEFT JOIN other_dnafragmentasimethode ON Other_DnaFragmentasiOther_DnaFragmentasiMethodeID = Other_DnaFragmentasiMethodeID + WHERE + Other_DnaFragmentasiT_OrderDetailID = {$id} AND Other_DnaFragmentasiIsActive = 'Y' + GROUP BY Other_DnaFragmentasiID + LIMIT 1"; + //echo $sql; + $query = $this->db_smartone->query($sql); + + if ($query) { + $rows = $query->row_array(); + if (!$rows) { + $rows = array( + 'xid' => 0, + 'orderdetail_id' => $id, + 'doctor_id' => 0, + 'doctor_name' => '', + 'methode_id' => 0, + 'methode_name' => '', + 'halo_luas' => '', + 'halo_sedang' => '', + 'tanpa_halo' => '', + 'dfi' => '', + 'kesimpulan' => '', + 'catatan' => '' + ); + } + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID + WHERE + M_DoctorSONat_SubGroupID = 4 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + + $sql = " + SELECT '0' as id, 'Belum memilih metode' as name + UNION + SELECT Other_DnaFragmentasiMethodeID as id, Other_DnaFragmentasiMethodeName as name + FROM other_dnafragmentasimethode + WHERE + Other_DnaFragmentasiMethodeIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $methodes = $this->db_smartone->query($sql)->result_array(); + + + $rst = array('doctors' => $doctors, 'methodes' => $methodes, 'results' => $rows); + $this->sys_ok(["records" => $rst]); + } else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + function saveresult_dnafragmentasi() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = $inp['doctor']['id']; + $methode_id = $inp['methode']['id']; + $orderdetail_id = $inp['results']['orderdetail_id']; + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + if (intval($prm['xid']) == 0) { + $sql = "INSERT INTO other_dnafragmentasi( + Other_DnaFragmentasiT_OrderDetailID, + Other_DnaFragmentasiM_DoctorID, + Other_DnaFragmentasiOther_DnaFragmentasiMethodeID, + Other_DnaFragmentasiHaloLuas, + Other_DnaFragmentasiHaloSedang, + Other_DnaFragmentasiHaloSempit, + Other_DnaFragmentasiTanpaHalo, + Other_DnaFragmentasiDFI, + Other_DnaFragmentasiKesimpulan, + Other_DnaFragmentasiCatatan, + Other_DnaFragmentasiUserID, + Other_DnaFragmentasiLastUpdated + ) + VALUES( + {$orderdetail_id}, + {$doctor_id}, + {$methode_id}, + '{$prm['halo_luas']}', + '{$prm['halo_sedang']}', + '{$prm['halo_sempit']}', + '{$prm['tanpa_halo']}', + '{$prm['dfi']}', + '{$prm['kesimpulan']}', + '{$prm['catatan']}', + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } else { + $sql = "UPDATE other_dnafragmentasi SET + Other_DnaFragmentasiT_OrderDetailID = {$orderdetail_id}, + Other_DnaFragmentasiM_DoctorID = {$doctor_id}, + Other_DnaFragmentasiOther_DnaFragmentasiMethodeID = '{$methode_id}', + Other_DnaFragmentasiHaloLuas = '{$prm['halo_luas']}', + Other_DnaFragmentasiHaloSedang = '{$prm['halo_sedang']}', + Other_DnaFragmentasiHaloSempit = '{$prm['halo_sempit']}', + Other_DnaFragmentasiTanpaHalo = '{$prm['tanpa_halo']}', + Other_DnaFragmentasiDFI = '{$prm['dfi']}', + Other_DnaFragmentasiKesimpulan = '{$prm['kesimpulan']}', + Other_DnaFragmentasiCatatan = '{$prm['catatan']}', + Other_DnaFragmentasiLastUpdated = NOW(), + Other_DnaFragmentasiUserID = {$userid} + WHERE + Other_DnaFragmentasiID = {$prm['xid']}"; + //echo $sql; + $this->db_smartone->query($sql); + } + + + $result = array("total" => 1, "records" => array(), "sql" => ''); + $this->sys_ok($result); + exit; + } +} diff --git a/application/controllers/mockup/process/westone_resultvalidation-030925/Re_px.php b/application/controllers/mockup/process/westone_resultvalidation-030925/Re_px.php index 8e1cbe21..dca767be 100644 --- a/application/controllers/mockup/process/westone_resultvalidation-030925/Re_px.php +++ b/application/controllers/mockup/process/westone_resultvalidation-030925/Re_px.php @@ -1,2513 +1,2510 @@ -db_smartone = $this->load->database("onedev", true); - $this->load->helper(array('form', 'url')); - } - function getMethodeID($natTestID) - { - $sql = "select M_MethodePriorityNat_MethodeID MethodeID, Nat_MethodeName - from - m_methode_priority - join nat_methode on Nat_MethodeID = M_MethodePriorityNat_MethodeID - and Nat_MethodeIsActive = 'Y' - join m_instrumentmethode on M_InstrumentMethodeNat_MethodeID = Nat_MethodeID and M_InstrumentMethodeIsActive = 'Y' - join nat_instrument on M_InstrumentMethodeNat_InstrumentID = Nat_InstrumentID - and Nat_InstrumentIsActive ='Y' - where M_MethodePriorityIsActive = 'Y' - and M_MethodePriorityNat_TestID = $natTestID - and M_MethodePriorityM_DayOfWeekID = dayofweek(now()) - order by M_MethodePriorityNumber desc - limit 0,1 "; - $qry = $this->db->query($sql); - if ($qry) { - $rows = $qry->result_array(); - if (count($rows) > 0) return array($rows[0]["MethodeID"], $rows[0]["Nat_MethodeName"]); - } - //2nd - $sql = "select - M_InstrumentMethodeNat_MethodeID MethodeID, Nat_MethodeName - from m_instrumentmethode - join nat_methode on M_InstrumentMethodeNat_MethodeID = Nat_MethodeID - and Nat_MethodeIsActive = 'Y' - join nat_instrument on M_InstrumentMethodeNat_InstrumentID = Nat_InstrumentID - and Nat_InstrumentIsActive ='Y' - where M_InstrumentMethodeNat_TestID = $natTestID - and M_InstrumentMethodeIsActive = 'Y' - order by M_InstrumentMethodePriority desc - limit 0,1"; - $qry = $this->db->query($sql); - if ($qry) { - $rows = $qry->result_array(); - if (count($rows) > 0) return array($rows[0]["MethodeID"], $rows[0]["Nat_MethodeName"]); - } - // - $sql = "select Nat_NormalValueNat_MethodeID MethodeID, Nat_MethodeName - from - nat_normalvalue - join nat_methode on Nat_NormalValueNat_MethodeID = Nat_MethodeID - and Nat_MethodeIsActive = 'Y' - where Nat_NormalValueNat_TestID = $natTestID - and Nat_NormalValueIsActive = 'Y' - order by Nat_NormalValueID - limit 0,1"; - $qry = $this->db->query($sql); - if ($qry) { - $rows = $qry->result_array(); - if (count($rows) > 0) return array($rows[0]["MethodeID"], $rows[0]["Nat_MethodeName"]); - } - return array(0, ""); - } - function get_normal_value($methodeID, $natTestID, $sexID, $ageInDay) - { - $sql = "select fn_sampling_get_normal($methodeID, $natTestID, $sexID, $ageInDay) as normalValueID"; - $qry = $this->db->query($sql); - if ($qry) { - $rows = $qry->result_array(); - if (count($rows) > 0) return $rows[0]["normalValueID"]; - } - return 0; - } - function fn_fix_normal($order_id) - { - $sql = "select - T_OrderDetailID, M_PatientM_SexID, fn_global_age_count_day(M_PatientDOB, date(T_OrderHeaderDate)) Dob , - T_TestNat_TestID - from t_orderheader - join m_patient on T_OrderHeaderID = $order_id and T_OrderHeaderM_PatientID = M_PatientID - join t_orderdetail on T_OrderDetailT_OrderHeaderID = T_OrderHeaderID - and T_OrderDetailIsACtive = 'Y' - and ( T_OrderDetailNat_NormalValueID is null or T_OrderDetailNat_NormalValueID = 0 ) - join t_test on T_OrderDetailT_TestID = T_TestID and T_TestIsResult = 'Y' "; - $qry = $this->db->query($sql); - if (! $qry) { - return; - } - $rows = $qry->result_array(); - if (count($rows) == 0) return; - $sql_u = "update t_orderdetail - join nat_normalvalue on T_OrderDetailID = ? and Nat_NormalValueID = ? - set - T_OrderDetailNat_NormalValueID = Nat_NormalValueID, - T_OrderDetailNormalValueNote = Nat_NormalValueNote, - T_OrderDetailNormalValueDescription = Nat_NormalValueDescription, - T_OrderDetailMinValue = Nat_NormalValueMinValue, - T_OrderDetailMaxValue = Nat_NormalValueMaxValue, - T_OrderDetailMinValueInclusive = Nat_NormalValueMinValueInclusive, - T_OrderDetailMaxValueInclusive = Nat_NormalValueMaxValueInclusive, - T_OrderDetailNat_MethodeID = ?, - T_OrderdetailNat_MethodeName =?"; - - foreach ($rows as $r) { - $T_OrderDetailID = $r["T_OrderDetailID"]; - $sexID = $r["M_PatientM_SexID"]; - $ageInDay = $r["Dob"]; - $natTestID = $r["T_TestNat_TestID"]; - list($methodeID, $methodeName) = $this->getMethodeID($natTestID); - if ($methodeID == 0) continue; - $normalValueID = $this->get_normal_value($methodeID, $natTestID, $sexID, $ageInDay); - if ($normalValueID == 0) return; - $this->db->query($sql_u, array($T_OrderDetailID, $normalValueID, $methodeID, $methodeName)); - } - } - function update_order_sample($targetID, $sourceID) - { - $sql = "update t_ordersample target - join t_ordersample source on - target.T_OrderSampleID = ? - and target.T_OrderSampleWorklistReceive = 'N' - and source.T_OrderSampleID = ? - set - target.T_OrderSampleSampling = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSampling, source.T_OrderSampleSampling), - target.T_OrderSampleSamplingDate = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingDate, source.T_OrderSampleSamplingDate), - target.T_OrderSampleSamplingTime = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingTime, source.T_OrderSampleSamplingTime), - target.T_OrderSampleSamplingUserID = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingUserID, source.T_OrderSampleSamplingUserID), - - target.T_OrderSampleReceive = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceive, source.T_OrderSampleReceive), - target.T_OrderSampleReceiveDate = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveDate, source.T_OrderSampleReceiveDate), - target.T_OrderSampleReceiveTime = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveTime, source.T_OrderSampleReceiveTime), - target.T_OrderSampleReceiveUserID = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveUserID, source.T_OrderSampleReceiveUserID), - - target.T_OrderSampleVerification = if(target.T_OrderSampleVerification='Y',target.T_OrderSampleVerification, source.T_OrderSampleVerification), - target.T_OrderSampleVerificationDate =if(target.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationDate, source.T_OrderSampleVerificationDate), - target.T_OrderSampleVerificationTime =if(source.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationTime, source.T_OrderSampleVerificationTime), - target.T_OrderSampleVerificationUserID =if(source.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationUserID, source.T_OrderSampleVerificationUserID), - - target.T_OrderSampleProcessing = if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessing, source.T_OrderSampleProcessing), - target.T_OrderSampleProcessingDate= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingDate, source.T_OrderSampleProcessingDate), - target.T_OrderSampleProcessingTime= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingTime, source.T_OrderSampleProcessingTime), - target.T_OrderSampleProcessingUserID= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingUserID, source.T_OrderSampleProcessingUserID), - - target.T_OrderSampleReceiveHandling =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandling, source.T_OrderSampleReceiveHandling ), - target.T_OrderSampleReceiveHandlingDate =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingDate, source.T_OrderSampleReceiveHandlingDate), - target.T_OrderSampleReceiveHandlingTime =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingTime, source.T_OrderSampleReceiveHandlingTime), - target.T_OrderSampleReceiveHandlingUserID =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingUserID, source.T_OrderSampleReceiveHandlingUserID), - - target.T_OrderSampleHandling = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandling, source.T_OrderSampleHandling), - target.T_OrderSampleHandlingDate = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingDate, source.T_OrderSampleHandlingDate), - target.T_OrderSampleHandlingTime = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingTime, source.T_OrderSampleHandlingTime), - target.T_OrderSampleHandlingUserID = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingUserID, source.T_OrderSampleHandlingUserID), - - target.T_OrderSampleWorklistReceive = source.T_OrderSampleWorklistReceive, - target.T_OrderSampleWorklistReceiveDatetime = source.T_OrderSampleWorklistReceiveDateTime, - target.T_OrderSampleWorklistReceiveUserID = source.T_OrderSampleWorklistReceiveUserID - "; - $qry = $this->db->query($sql, array($targetID, $sourceID)); - if (! $qry) { - echo json_encode(array("status" => "ERR", "message" => print_r($this->db->error(), true))); - exit; - } - } - function fix_sample_serum($headerID) - { - //cari t_ordersample yg belum worklist receive dengan code 017% - $sql = "select T_OrderSampleID - from t_ordersample - join t_sampletype on - T_OrderSampleT_OrderHeaderID = ? - and T_OrderSampleWorklistReceive = 'N' - and T_OrderSampleIsActive = 'Y' - and T_OrderSampleT_SampleTypeID = T_SampletypeID - and T_SampleTypeCode like '017%' - "; - $qry = $this->db->query($sql, array($headerID)); - if (!$qry) { - echo json_encode(array("status" => "ERR", "message" => print_r($this->db->error(), true))); - exit; - } - $rows = $qry->result_array(); - if (count($rows) == 0) return; - //cari T_OrderSample yang sudah di receive yg terakhir - $sql = "select T_OrderSampleID - from t_ordersample - join t_sampletype on - T_OrderSampleT_OrderHeaderID = ? - and T_OrderSampleWorklistReceive = 'Y' - and T_OrderSampleIsActive = 'Y' - and T_OrderSampleT_SampleTypeID = T_SampletypeID - and T_SampleTypeCode like '017%' - order by T_OrderSampleWorklistReceiveDatetime desc - limit 0,1 - "; - $qry = $this->db->query($sql, array($headerID)); - if (!$qry) { - echo json_encode(array("status" => "ERR", "message" => print_r($this->db->error(), true))); - exit; - } - $rcv_rows = $qry->result_array(); - if (count($rcv_rows) == 0) return; - - //print_r($rows); - //print_r($rcv_rows); - $rcv_T_OrderSampleID = $rcv_rows[0]["T_OrderSampleID"]; - //ada yg belum di receive - foreach ($rows as $r) { - $T_OrderSampleID = $r["T_OrderSampleID"]; - $this->update_order_sample($T_OrderSampleID, $rcv_T_OrderSampleID); - } - } - public function search() - { - $prm = $this->sys_input; - $max_rst = 99; - - $id = $prm["order_id"]; - if ($id > 0) { - $this->fix_sample_serum($id); - $this->fn_fix_normal($id); - } - $lang = $this->lang_default_code; - $lang_id = isset($prm['lang_id']) ? $prm['lang_id'] : '0'; - - if ($lang_id != 0) { - $l = $this->db_smartone->where("Nat_LangID", $lang_id)->get("nat_lang")->row(); - $lang = $l->Nat_LangCode; - } - - //tambahan fajri - $sql = " UPDATE t_orderdetail - JOIN t_test ON T_OrderDetailT_TestID = T_TestID - SET T_OrderDetailT_TestIsResult = T_TestIsResult - WHERE - T_OrderDetailT_OrderHeaderID = {$id} AND - T_OrderDetailT_TestIsResult = '' AND - T_OrderDetailIsActive = 'Y'"; - $this->db_smartone->query($sql); - - $tot_count = 0; - $lq = ""; - $group_id = 0; - if (isset($prm['group_id'])) - $group_id = $prm['group_id']; - - if ($group_id != 0) { - $sql = "select distinct T_WorklistDetailNat_TestID Nat_TestID - from t_worklistdetailv2 - where T_WorklistDetailT_WorklistID = {$group_id}"; - $qry = $this->db_smartone->query($sql); - $rows = $qry->result_array(); - $nat_test_ids = "0"; - foreach ($rows as $r) { - $nat_test_ids .= ", " . $r["Nat_TestID"]; - } - $q_group = " ( $nat_test_ids ) "; - - $sql = " - SELECT a1.*, cOUNT(a2.T_OrderDetailID) level - FROM ( - SELECT IFNULL(y.T_OrderDetailT_TestID, x.T_OrderDetailT_TestID) t_testid, - IFNULL(y.T_OrderDetailT_TestName, y.T_OrderDetailT_TestName) t_testname, - y.T_OrderDetailResult result, y.T_OrderDetailResult result_old, y.T_OrderDetailNote note, y.T_OrderDetailNote note_old, - y.T_OrderDetailID id, - y.T_OrderDetailT_TestIsResult is_result, a.T_TestIsQuantitative is_quantitative, - y.T_OrderDetailResultFlag result_flag, - y.T_OrderDetailNat_NormalValueID normal_id, - y.T_OrderDetailNormalValueNote normal_note, y.T_OrderDetailNat_UnitName unit_name, - y.T_OrderdetailNat_MethodeID methode_id, y.T_OrderdetailNat_MethodeName methode_name, - a.T_TestNat_TestID nattest_id, a.T_TestID tx_id, count(T_ResultInstrumentID) as result_instrument_n, - y.T_OrderDetailVerification, T_OrderSampleReceive sample_receive, - T_OrderSampleProcessing sample_processing, T_OrderSampleWorklistReceive sample_worklist_receive, - IF(T_OrderDetailAddOnPreAnalytic = 'Y', T_OrderDetailAddOnPreAnalytic, PreAnalyticIsOk) pre_analytic, - T_OrderDetailAddOnPreAnalytic, - T_OrderHeaderID order_id, y.T_OrderDetailT_TestSasCode test_sas_code, - tx.T_TestSasCode, - T_OrderDetailAddOnResample `resample`, T_OrderDetailAddOnResampleStatus resample_status, - T_OrderDetailAddOnRef ref, y.T_OrderDetailVerification verification, y.T_OrderDetailValidation validation, - T_OrderPromiseDateTime, Group_ResultName as ResultGroupName - FROM t_orderdetail x - left join t_orderpromise on x.T_OrderDetailT_OrderPromiseID = T_OrderPromiseID - JOIN t_test tx ON x.T_OrderDetailT_TestID = T_TestID - JOIN t_test tcheck on tcheck.T_TestNat_TestID in {$q_group} - and ( tx.T_TestID = tcheck.T_TestID or tx.T_TestSasCode like concat(tcheck.T_TestSasCode,'%')) - LEFT JOIN group_resultdetail ON Group_ResultDetailT_TestID = x.T_OrderDetailT_TestID AND Group_ResultDetailIsActive = 'Y' - LEFT JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND Group_ResultFlagNonLab = 'N' - LEFT JOIN t_orderdetail y ON x.T_OrderDetailT_TestSasCode LIKE CONCAT(y.T_OrderDetailT_TestSasCode, '%') - AND x.T_OrderDetailT_OrderHeaderID = y.T_OrderDetailT_OrderHeaderID - AND y.T_OrderDetailIsActive = 'Y' - LEFT JOIN t_orderdetailaddon ON x.T_OrderDetailID = T_OrderDetailAddOnT_OrderDetailID - JOIN t_orderheader ON y.T_OrderDetailT_OrderHeaderID = T_OrderHeaderID - LEFT JOIN t_test a ON y.T_OrderDetailT_TestID = a.T_TestID - AND a.T_TestIsNonLab = '' - LEFT JOIN (SELECT T_OrderSampleT_SampleTypeID, T_OrderSampleReceive, T_OrderSampleProcessing, T_OrderSampleWorklistReceive - FROM t_ordersample WHERE T_OrderSampleT_OrderHeaderID = {$id} - AND T_OrderSampleIsactive = 'Y' - GROUP BY T_OrderSampleT_SampleTypeID) os ON a.T_TestT_SampleTypeID = os.T_OrderSampleT_SampleTypeID - or os.T_OrderSampleT_SampleTypeID = fn_sampletype_from_local(a.T_TestNat_TestID) - - LEFT JOIN t_resultinstrument ON T_ResultInstrumentT_OrderDetailID = x.T_OrderDetailID - LEFT JOIN pre_analytic ON PreAnalyticNat_TestID = a.T_TestNat_TestID AND PreAnalyticDate = date(now()) and PreAnalyticIsActive = 'Y' - WHERE x.T_OrderDetailT_OrderHeaderID = {$id} - AND x.T_OrderDetailIsActive = 'Y' - GROUP BY y.T_OrderDetailT_TestID - ORDER BY y.T_OrderDetailT_TestSasCode ASC - ) a1 - - LEFT JOIN t_orderdetail a2 ON a2.T_OrderDetailT_OrderHeaderID = a1.order_id - AND a2.T_OrderDetailIsActive = 'Y' - AND a1.test_sas_code LIKE CONCAT(a2.T_OrderDetailT_testSasCode, '%') - GROUP BY a1.t_testid - order by a1.test_sas_code -"; - $query = $this->db_smartone->query($sql); - $lq = $this->db_smartone->last_query(); - } else { - $sql = " - SELECT a1.*, cOUNT(a2.T_OrderDetailID) level - FROM ( - SELECT IFNULL(y.T_OrderDetailT_TestID, x.T_OrderDetailT_TestID) t_testid, - IFNULL(y.T_OrderDetailT_TestName, y.T_OrderDetailT_TestName) t_testname, - y.T_OrderDetailResult result, y.T_OrderDetailResult result_old, y.T_OrderDetailNote note, y.T_OrderDetailNote note_old, - y.T_OrderDetailID id, - y.T_OrderDetailT_TestIsResult is_result, a.T_TestIsQuantitative is_quantitative, - y.T_OrderDetailResultFlag result_flag, - y.T_OrderDetailNat_NormalValueID normal_id, - y.T_OrderDetailNormalValueNote normal_note, y.T_OrderDetailNat_UnitName unit_name, - y.T_OrderdetailNat_MethodeID methode_id, y.T_OrderdetailNat_MethodeName methode_name, - a.T_TestNat_TestID nattest_id, a.T_TestID tx_id, count(T_ResultInstrumentID) as result_instrument_n, - y.T_OrderDetailVerification, T_OrderSampleReceive sample_receive, - T_OrderSampleProcessing sample_processing, T_OrderSampleWorklistReceive sample_worklist_receive, - IF(T_OrderDetailAddOnPreAnalytic = 'Y', T_OrderDetailAddOnPreAnalytic, PreAnalyticIsOk) pre_analytic, - T_OrderDetailAddOnPreAnalytic, - T_OrderHeaderID order_id, y.T_OrderDetailT_TestSasCode test_sas_code, - tx.T_TestSasCode, - T_OrderDetailAddOnResample `resample`, T_OrderDetailAddOnResampleStatus resample_status, - T_OrderDetailAddOnRef ref, y.T_OrderDetailVerification verification, y.T_OrderDetailValidation validation, - T_OrderPromiseDateTime , Group_ResultName as ResultGroupName - FROM t_orderdetail x - left join t_orderpromise on x.T_OrderDetailT_OrderPromiseID = T_OrderPromiseID - JOIN t_test tx ON x.T_OrderDetailT_TestID = T_TestID - LEFT JOIN group_resultdetail ON Group_ResultDetailT_TestID = x.T_OrderDetailT_TestID AND Group_ResultDetailIsActive = 'Y' - LEFT JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND Group_ResultFlagNonLab = 'N' - LEFT JOIN t_orderdetail y ON x.T_OrderDetailT_TestSasCode LIKE CONCAT(y.T_OrderDetailT_TestSasCode, '%') - AND x.T_OrderDetailT_OrderHeaderID = y.T_OrderDetailT_OrderHeaderID - AND y.T_OrderDetailIsActive = 'Y' - - LEFT JOIN t_orderdetailaddon ON x.T_OrderDetailID = T_OrderDetailAddOnT_OrderDetailID - - JOIN t_orderheader ON y.T_OrderDetailT_OrderHeaderID = T_OrderHeaderID - LEFT JOIN t_test a ON y.T_OrderDetailT_TestID = a.T_TestID - AND a.T_TestIsNonLab = '' - LEFT JOIN (SELECT T_OrderSampleT_SampleTypeID, T_OrderSampleReceive, T_OrderSampleProcessing, T_OrderSampleWorklistReceive - FROM t_ordersample WHERE T_OrderSampleT_OrderHeaderID = {$id} - AND T_OrderSampleIsactive = 'Y' - GROUP BY T_OrderSampleT_SampleTypeID) os ON a.T_TestT_SampleTypeID = os.T_OrderSampleT_SampleTypeID - or os.T_OrderSampleT_SampleTypeID = fn_sampletype_from_local(a.T_TestNat_TestID) - - LEFT JOIN t_resultinstrument ON T_ResultInstrumentT_OrderDetailID = x.T_OrderDetailID - LEFT JOIN pre_analytic ON PreAnalyticNat_TestID = a.T_TestNat_TestID AND PreAnalyticDate = date(now()) and PreAnalyticIsActive = 'Y' - WHERE x.T_OrderDetailT_OrderHeaderID = {$id} - AND x.T_OrderDetailIsActive = 'Y' - GROUP BY y.T_OrderDetailT_TestID - ORDER BY y.T_OrderDetailT_TestSasCode ASC - ) a1 - - LEFT JOIN t_orderdetail a2 ON a2.T_OrderDetailT_OrderHeaderID = a1.order_id - AND a2.T_OrderDetailIsActive = 'Y' - AND a1.test_sas_code LIKE CONCAT(a2.T_OrderDetailT_testSasCode, '%') - GROUP BY a1.t_testid - order by a1.test_sas_code -"; - //echo $sql; - $query = $this->db_smartone->query($sql); - $lq = $this->db_smartone->last_query(); - } - // file_put_contents("/xtmp/re-query.sql",$lq); - - if ($query) { - $rst = []; - $rows = $query->result_array(); - - foreach ($rows as $k => $v) { - - if ($v['is_result'] == "Y" && $v['is_quantitative'] == "N") { - $v['template'] = []; - $x = $this->db_smartone->query("CALL sp_master_resulttemplate_get('{$v['t_testid']}')"); - $this->clean_mysqli_connection($this->db_smartone->conn_id); - if ($x) - $v['template'] = $x->result_array(); - } - - // IF Rujukan, by pas Pre Analytik - if ($v['ref'] == 'Y') - $v['pre_analytic'] = 'Y'; - if ($v["id"] == "885455") { - //sipe workaround - //$v["sample_receive"] = "Y"; - $v["sample_worklist_receive"] = "Y"; - } - $rst[] = $v; - } - - $result = array("total" => $tot_count, "records" => $rst, "total_display" => sizeof($rows), "q" => $lq); - $this->sys_ok($result); - } else { - $this->sys_error_db("RE Px rows", $this->db_smartone); - exit; - } - } - - public function save() - { - $prm = $this->sys_input; - $data = json_decode($prm["data"]); - $lang = $this->lang_default_code; - $lang_id = isset($prm['lang_id']) ? $prm['lang_id'] : '0'; - - if ($lang_id != 0) { - $l = $this->db_smartone->where("Nat_LangID", $lang_id)->get("nat_lang")->row(); - $lang = $l->Nat_LangCode; - } - - $sql_norm = "select T_OrderDetailMinValue, T_OrderDetailMaxValue, - T_OrderDetailMinValueInclusive, T_OrderDetailMaxValueInclusive, - Nat_TestFlagLow, Nat_TestFlagHigh - from t_orderdetail - join t_test on T_OrderDetailT_TestID = T_TestID - join nat_test on T_TestNat_TestID = Nat_TestID and T_TestIsActive = 'Y' - where T_OrderDetailID = ? "; - - $ids = []; - foreach ($data as $k => $v) { - if ($v->resultInstrumentID > 0) { - $sql_i = "select T_ResultInstrumentNat_NormalValueID normalValueID - from t_resultinstrument - where T_ResultInstrumentID = ?"; - $qry_i = $this->db_smartone->query($sql_i, array($v->resultInstrumentID)); - if ($qry_i) { - $rows_i = $qry_i->result_array(); - - if (count($rows_i) > 0) { - $sql_iu = "update t_orderdetail, nat_normalvalue , nat_methode - set T_OrderDetailMinValue = Nat_NormalValueMinValue, - T_OrderDetailMinValueInclusive = Nat_NormalValueMinValueInclusive, - T_OrderDetailMaxValue = Nat_NormalValueMaxValue , - T_OrderDetailMaxValueInclusive = Nat_NormalValueMaxValueInclusive, - T_OrderDetailNormalValueNote = Nat_NormalValueNote, - T_OrderDetailNormalValueDescription = Nat_NormalValueDescription, - T_OrderDetailNat_NormalValueID = Nat_NormalValueID, - T_OrderDetailNat_MethodeID = Nat_NormalValueNat_MethodeID, - T_OrderDetailNat_MethodeName = Nat_MethodeName - where T_OrderDetailID = ? and Nat_NormalValueID = ? - and Nat_NormalValueNat_MethodeID = Nat_MethodeID - "; - $this->db_smartone->query($sql_iu, array($v->id, $rows_i[0]["normalValueID"])); - //file_put_contents("/xtmp/update-nilai-normal", $this->db_smartone->last_query() . "\n", FILE_APPEND); - } - } - } - $y = $this->db_smartone->query("SELECT fn_process_sample_handling_perfect('{$v->order_id}', '{$v->test_id}') c") - ->row(); - $req_status = $y->c; - $qry_norm = $this->db_smartone->query($sql_norm, $v->id); - $result_flag = ""; - if ($qry_norm) { - $rows_norm = $qry_norm->result_array(); - if (count($rows_norm) > 0) { - $r = $rows_norm[0]; - if (is_numeric($v->result)) { - - if ($r["T_OrderDetailMinValueInclusive"] == "Y" && $v->result < $r["T_OrderDetailMinValue"]) { - $result_flag = $r["Nat_TestFlagLow"]; - } - if ($r["T_OrderDetailMinValueInclusive"] == "N" && $v->result <= $r["T_OrderDetailMinValue"]) { - $result_flag = $r["Nat_TestFlagLow"]; - } - if ($r["T_OrderDetailMaxValueInclusive"] == "Y" && $v->result > $r["T_OrderDetailMaxValue"]) { - $result_flag = $r["Nat_TestFlagHigh"]; - } - if ($r["T_OrderDetailMaxValueInclusive"] == "N" && $v->result >= $r["T_OrderDetailMaxValue"]) { - $result_flag = $r["Nat_TestFlagHigh"]; - } - } - } - } - if ($lang == $this->lang_default_code) { - $this->db_smartone->set('T_OrderDetailResult', $v->result) - ->set('T_OrderDetailResultFlag', $result_flag) - ->set('T_OrderDetailNote', $v->note) - ->set('T_OrderDetailReqStatus', $req_status) - ->where('T_OrderDetailID', $v->id) - ->update('t_orderdetail'); - } else { - $this->db_smartone->set('T_OrderDetailLangResult', $v->result) - ->set('T_OrderDetailLangNote', $v->note) - ->where('T_OrderDetailLangID', $v->id) - ->update('t_orderdetaillang'); - } - - $ids[] = $v->id; - } - - // LOG Process - $order = $this->db_smartone->select('T_OrderDetailT_OrderHeaderID id, T_OrderHeaderLabNumber lab_number', false) - ->join('t_orderheader', 'T_OrderHeaderID = T_OrderDetailT_OrderHeaderID') - ->where('T_OrderDetailID', $data[0]->id) - ->get('t_orderdetail') - ->row(); - - $dblog = $this->load->database("onelog", true); - $dblog->set('Log_ProcessCode', 'PROCESS.Result.Entry') - ->set('Log_ProcessOrderID', $order->id) - ->set('Log_ProcessOrderNumber', $order->lab_number) - ->set('Log_ProcessJson', json_encode($data)) - ->set('Log_ProcessUserID', $this->sys_user['M_UserID']) - ->insert('log_process'); - // END OF Log Process - //auto calculation - $this->load->library("Resultcalc"); - $rows = $this->resultcalc->auto($order->id); - - try { - foreach ($ids as $id) { - $this->db_smartone->query("call sp_set_normal_value_flag($id)"); - $this->clean_mysqli_connection($this->db_smartone->conn_id); - } - } catch (Exception $e) { - } - - $this->sys_ok($ids); - } - - public function save_template() - { - $prm = $this->sys_input; - - $n = $this->db_smartone->select("COUNT(T_ResultTemplateID) n") - ->where("T_ResultTemplateT_TestID", $prm['test_id']) - ->where("T_ResultTemplateIsActive", "Y") - ->where("T_ResultTemplateValue", $prm['value']) - ->get('t_resulttemplate') - ->row(); - if ($n->n > 0) { - $this->sys_error_db("Insert Result Template", $this->db_smartone); - return; - } - - $r = $this->db_smartone->set("T_ResultTemplateT_TestID", $prm['test_id']) - ->set("T_ResultTemplateValue", $prm['value']) - ->insert('t_resulttemplate'); - if ($r) { - $template = []; - $x = $this->db_smartone->query("CALL sp_master_resulttemplate_get('{$prm['test_id']}')"); - $this->clean_mysqli_connection($this->db_smartone->conn_id); - if ($x) - $template = $x->result_array(); - - $this->sys_ok($template); - } - } - - public function export() - { - $prm = $this->sys_input; - - $sql = "CALL sp_process_result_lang(?, ?, ?, ?)"; - $query = $this->db_smartone->query($sql, [$prm['order_id'], $prm['lang_id'], $prm['is_si'], $this->sys_user['M_UserID']]); - if ($query) { - $r = $query->row(); - if ($r->status == "OK") { - $this->sys_ok($r->data); - return; - } - - $this->sys_error_db("Message : " . $r->message, $this->db_smartone); - } else { - $this->sys_error_db("Lang Result", $this->db_smartone); - return; - } - } - - public function search_group() - { - $prm = $this->sys_input; - $max_rst = 100; - - // QUERY TOTAL - $sql = "select count(*) total - from t_worklist - where T_WorklistIsActive = 'Y' - order by T_WorklistName ASC"; - $query = $this->db_smartone->query($sql); - - if ($query) { - $tot_count = $query->result_array()[0]["total"]; - } else { - $this->sys_error_db("worklist count", $this->db_smartone); - exit; - } - - $sql = "select T_WorklistID group_id, T_WorklistName group_name - from t_worklist - where T_WorklistIsActive = 'Y' - order by T_WorklistName ASC - limit 0, {$max_rst}"; - $query = $this->db_smartone->query($sql); - - if ($query) { - $rows = $query->result_array(); - foreach ($rows as $k => $v) - $rows[$k]['data'] = json_decode($v['data']); - $result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows), "q" => $this->db_smartone->last_query()); - $this->sys_ok($result); - } else { - $this->sys_error_db("worklist rows", $this->db_smartone); - exit; - } - } - - public function search_rerun() - { - $prm = $this->sys_input; - $id = $prm["detail_id"]; - - $sql = "CALL sp_process_result_rerun(?)"; - $query = $this->db_smartone->query($sql, [$id]); - - if ($query) { - $rows = $query->result_array(); - $this->sys_ok(["records" => $rows]); - } else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - - - function getdoctorsfna() - { - $prm = $this->sys_input; - // $id = $prm["id"]; - - $sql = " SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY M_DoctorName ASC"; - //echo $sql; - $query = $this->db_smartone->query($sql); - - if ($query) { - $rows = $query->result_array(); - $this->sys_ok(["records" => $rows]); - } else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - function getfnaresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT Other_FNADetailsID as xid, - Other_FNAT_OrderDetailID as orderdetail_id, - Other_FNADetailsCode as code, - Other_FNADetailsLabel as label, - Other_FNADetailsResult as result, - IFNULL(Other_FNAM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_FNAM_DoctorID) OR Other_FNAM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_fna - JOIN other_fnadetails ON Other_FNADetailsOther_FNAID = Other_FNAID AND Other_FNADetailsIsActive = 'Y' - LEFT JOIN m_doctor ON Other_FNAM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_FNAT_OrderDetailID = {$id} AND Other_FNAIsActive = 'Y' - GROUP BY Other_FNADetailsID - ORDER BY Other_FNADetailsCode ASC"; - $query = $this->db_smartone->query($sql); - - if ($query) { - $rows = $query->result_array(); - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $images = array(); - $sql = "SELECT So_ImageUploadID as xid, - CONCAT('/one-media/one-image-nonlab/',So_ImageUploadNewName) as image_url - FROM t_orderdetail - JOIN so_imageupload ON So_ImageUploadT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND - So_ImageUploadIsActive = 'Y' - WHERE - T_OrderDetailID = {$id} AND - T_OrderDetailIsActive = 'Y' - GROUP BY So_ImageUploadID"; - $images = $this->db_smartone->query($sql)->result_array(); - - $rst = array('doctors' => $doctors, 'results' => $rows, 'images' => $images); - $this->sys_ok(["records" => $rst]); - } else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - - function uploadimage() - { - if (! $this->isLogin) { - $this->sys_error("Invalid Token"); - exit; - } - - $userid = $this->sys_user["M_UserID"]; - $data = []; - //print_r($_SERVER); - - $prm = $this->sys_input; - $orderid = $this->input->post('orderid'); - $labnumber = $this->input->post('labnumber'); - $sql = "UPDATE so_imageupload SET - So_ImageUploadIsActive = 'N', - So_ImageUploadUserID = {$userid} - WHERE - So_ImageUploadT_OrderHeaderID = {$orderid}"; - //echo $sql; - $this->db_onedev->query($sql); - //$config['upload_path'] = 'assets/'; - - $path = '/home/one/project/one/one-media/one-image-nonlab/'; - //echo $path; - $config['upload_path'] = $path; - $config['allowed_types'] = 'jpg|jpeg|png|gif'; - - $config['max_size'] = '10000'; - $count = count($_FILES['files']['name']); - //echo $count; - $this->load->library('upload', $config); - - $error = []; - for ($i = 0; $i < $count; $i++) { - - - if (!empty($_FILES['files']['name'][$i])) { - - - - $_FILES['file']['name'] = $_FILES['files']['name'][$i]; - - $_FILES['file']['type'] = $_FILES['files']['type'][$i]; - - $_FILES['file']['tmp_name'] = $_FILES['files']['tmp_name'][$i]; - - $_FILES['file']['error'] = $_FILES['files']['error'][$i]; - - $_FILES['file']['size'] = $_FILES['files']['size'][$i]; - - - - $namex = $orderid . '-' . $labnumber . '-' . $this->generateRandomString(5); - //echo $namex; - - $config['file_name'] = $namex; - $this->upload->initialize($config); - //echo $config['file_name'] ; - - - - - - if ($this->upload->do_upload('file')) { - - $uploadData = $this->upload->data(); - - $filename = $uploadData['file_name']; - //echo $filename; - - - $sql = "INSERT INTO so_imageupload ( - So_ImageUploadT_OrderHeaderID, - So_ImageUploadT_OrderHeaderLabNumber, - So_ImageUploadT_SampleTypeID, - So_ImageUploadOldName, - So_ImageUploadNewName, - So_ImageUploadCreated, - So_ImageUploadUserID - ) - VALUES( - {$orderid}, - '{$labnumber}', - '150', - '{$_FILES['files']['name'][$i]}', - '{$filename}', - NOW(), - {$userid} - - )"; - //echo $sql; - $this->db_onedev->query($sql); - $xlast_id = $this->db_onedev->insert_id(); - $data['totalFiles'][] = array('xid' => $xlast_id, 'image_url' => '/one-media/one-image-nonlab/' . $filename); - } else { - $error = array('error' => $this->upload->display_errors()); - } - } - } - - $result = array("total" => count($data['totalFiles']), "records" => $data['totalFiles'], 'errors' => $error); - $this->sys_ok($result); - } - - - function getpatologianatomyresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT Other_PatologiAnatomyID as xid, - Other_PatologiAnatomyT_OrderDetailID as orderdetail_id, - Other_PatologiAnatomyNoSediaan as no_sediaan, - Other_PatologiAnatomyDiagnosaKlinis as diagnosa, - Other_PatologiAnatomyKeteranganKlinis as klinis, - Other_PatologiAnatomyLokasiOrgan as lokasi, - Other_PatologiAnatomyMakroskopik as makroskopik, - Other_PatologiAnatomyMikroskopik as mikroskopik, - Other_PatologiAnatomyKesimpulan as kesimpulan, - IFNULL(Other_PatologiAnatomyM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_PatologiAnatomyM_DoctorID) OR Other_PatologiAnatomyM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_patologi_anatomy - LEFT JOIN m_doctor ON Other_PatologiAnatomyM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_PatologiAnatomyT_OrderDetailID = {$id} AND Other_PatologiAnatomyIsActive = 'Y' - GROUP BY Other_PatologiAnatomyID - ORDER BY Other_PatologiAnatomyID ASC - LIMIT 1"; - $query = $this->db_smartone->query($sql); - - if ($query) { - $rows = $query->row_array(); - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - - $sql = "SELECT So_ImageUploadPatologyAnatomyID as xid, - CONCAT('/one-media/one-image-nonlab/',So_ImageUploadPatologyAnatomyNewName) as image_url, - So_ImageUploadPatologyAnatomyType as type - FROM t_orderdetail - JOIN so_imageupload_patology_anatomy ON So_ImageUploadPatologyAnatomyT_OrderHeaderID= T_OrderDetailT_OrderHeaderID AND - So_ImageUploadPatologyAnatomyIsActive= 'Y' - WHERE - T_OrderDetailID = {$id} AND - T_OrderDetailIsActive = 'Y' - GROUP BY So_ImageUploadPatologyAnatomyID"; - $images = $this->db_smartone->query($sql)->result_array(); - $mikro = []; - $makro = []; - - foreach ($images as $key => $value) { - - if ($value['type'] == 'mikro') { - $mikro[] = $value; - } - if ($value['type'] == 'makro') { - $makro[] = $value; - } - } - - $rst = array('doctors' => $doctors, 'result' => $rows, 'mikro' => $mikro, 'makro' => $makro); - $this->sys_ok(["records" => $rst]); - } else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - - - function generateRandomString($length = 10) - { - $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; - $charactersLength = strlen($characters); - $randomString = ''; - for ($i = 0; $i < $length; $i++) { - $randomString .= $characters[rand(0, $charactersLength - 1)]; - } - return $randomString; - } - - function getcytologiresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT Other_CytologiDetailsID as xid, - Other_CytologiT_OrderDetailID as orderdetail_id, - Other_CytologiDetailsCode as code, - Other_CytologiDetailsLabel as label, - Other_CytologiDetailsResult as result, - IFNULL(Other_CytologiM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_CytologiM_DoctorID) OR Other_CytologiM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_cytologi - JOIN other_cytologidetails ON Other_CytologiDetailsOther_CytologiID = Other_CytologiID AND Other_CytologiDetailsIsActive = 'Y' - LEFT JOIN m_doctor ON Other_CytologiM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_CytologiT_OrderDetailID = {$id} AND Other_CytologiIsActive = 'Y' - GROUP BY Other_CytologiDetailsID - ORDER BY Other_CytologiDetailsCode ASC"; - //echo $sql; - $query = $this->db_smartone->query($sql); - - if ($query) { - $rows = $query->result_array(); - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $rst = array('doctors' => $doctors, 'results' => $rows); - $this->sys_ok(["records" => $rst]); - } else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - function getmikroresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT - Other_MikroID as xid, - Other_MikroHasilBiakan as hasil_biakan, - Other_MikroSampleTypeName as sample_name, - Other_MikroT_OrderDetailID as orderdetail_id, - Other_MikroResult as result_value, - '' as result_other, - IFNULL(T_BacteriaID,0) as T_BacteriaID, - IFNULL(T_BacteriaName,'') as T_BacteriaName, - '' as details, - IFNULL(Other_MikroM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_MikroM_DoctorID) OR Other_MikroM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_mikro - LEFT JOIN t_bacteria ON Other_MikroT_BacteriaID = T_BacteriaID - LEFT JOIN m_doctor ON Other_MikroM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_MikroT_OrderDetailID = {$id} AND Other_MikroIsActive = 'Y' - GROUP BY Other_MikroID"; - //echo $sql; - $query = $this->db_smartone->query($sql); - - if ($query) { - $row = $query->row_array(); - if ($row) { - if ($row['result_value'] != 'Positif' && $row['result_value'] != 'Negatif') { - $row['result_other'] = $row['result_value']; - $row['result_value'] = 'other'; - } - $sql = "SELECT '' as xno, - Other_MikroDetailsID as xid, - Other_MikroDetailsValue as value, - IF(Other_MikroDetailsNote = 'R','Y','N') as chx_r, - IF(Other_MikroDetailsNote = 'I','Y','N') as chx_i, - IF(Other_MikroDetailsNote = 'S','Y','N') as chx_s, - Other_MikroDetailsNote as note, - t_antibiotic.* - FROM other_mikrodetails - LEFT JOIN t_antibiotic ON Other_MikroDetailsT_AntibioticID = T_AntibioticID - WHERE - Other_MikroDetailsOther_MikroID = {$row['xid']} AND Other_MikroDetailsIsActive = 'Y' - GROUP BY Other_MikroDetailsID - ORDER BY T_AntibioticName ASC"; - //echo $sql; - $details = $this->db_smartone->query($sql)->result_array(); - if (details) { - foreach ($details as $k => $v) { - $details[$k]['xno'] = $k + 1; - } - } - $row['details'] = $details; - } else { - $row = array('xid' => '0', 'hasil_biakan' => '', 'result_value' => 'Negatif', 'sample_name' => '', 'orderdetail_id' => $id, 'T_BacteriaID' => '0', 'T_BacteriaName' => '0', 'details' => array(), 'doctor_id' => '0', 'doctor_name' => '0'); - } - } else { - $row = array('xid' => '0', 'hasil_biakan' => '', 'result_value' => 'Negatif', 'sample_name' => '', 'orderdetail_id' => $id, 'T_BacteriaID' => '0', 'T_BacteriaName' => '0', 'details' => array(), 'doctor_id' => '0', 'doctor_name' => '0'); - } - //print_r($row); - - - - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 7 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $sql = " - SELECT '0' as id, 'Belum memilih bakteria' as name - UNION - SELECT T_BacteriaID as id, T_BacteriaName as name - FROM t_bacteria - WHERE - T_BacteriaIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $bacteries = $this->db_smartone->query($sql)->result_array(); - $rst = array('doctors' => $doctors, 'bacteries' => $bacteries, 'results' => $row); - $this->sys_ok(["records" => $rst]); - } - function getantibiotics() - { - $prm = $this->sys_input; - $id = $prm["id"]; - $sql = " SELECT '' as xno, - 0 as xid, - '' as hasil_biakan, - '' as sample_name, - 0 as value, - 'Y' as chx_r, - 'N' as chx_i, - 'N' as chx_s, - 'R' as note, - t_antibiotic.* - FROM t_antibiotic - WHERE - T_AntibioticT_BacteriaID = {$prm['id']} AND T_AntibioticIsActive= 'Y' - ORDER BY T_AntibioticName ASC"; - //echo $sql; - $rows = $this->db_smartone->query($sql)->result_array(); - if (rows) { - foreach ($rows as $k => $v) { - $rows[$k]['xno'] = $k + 1; - } - } - - $this->sys_ok(["records" => $rows]); - } - function getlcprepresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - $sql = " SELECT Other_LcprepDetailsID as xid, - Other_LcprepID as header_id, - Other_LcprepT_orderDetailID as orderdetail_id, - Other_LcprepDetailsCode as code, - Other_LcprepDetailsLabel as label, - Other_LcprepDetailsResult as result, - IFNULL(Other_LcprepM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_LcprepM_DoctorID) OR Other_LcprepM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_lcprep - JOIN other_lcprepdetails ON Other_LcprepDetailsOther_LcprepID = Other_LcprepID AND Other_LcprepDetailsIsActive = 'Y' - LEFT JOIN m_doctor ON Other_LcprepM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_LcprepT_orderDetailID = {$id} AND Other_LcprepIsActive = 'Y' - GROUP BY Other_LcprepDetailsOther_LcprepID, Other_LcprepDetailsCode - ORDER BY Other_LcprepDetailsCode ASC"; - //echo $sql; - $rows = $this->db_smartone->query($sql)->result_array(); - if (!$rows) { - $rows = array( - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'A', - 'label' => 'DESKRIPSI', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ), - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'B', - 'label' => 'KESIMPULAN', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ) - ); - } - - $header_id = $rows[0]['header_id']; - $sql = "SELECT IFNULL(Other_LcprepAdekuasiID,0) as xid, - Lcprep_AdekuasiID as id, - Lcprep_AdekuasiLabel as name, - IF(ISNULL(Other_LcprepAdekuasiID),'N',Other_LcprepAdekuasiChex) as chex - FROM lcprep_adekuasi - LEFT JOIN other_lcprepadekuasi ON Other_LcprepAdekuasiLcprep_AdekuasiID = Lcprep_AdekuasiID AND - Other_LcprepAdekuasiOther_LcprepID = {$header_id} AND - Other_LcprepAdekuasiIsActive = 'Y' - WHERE - Lcprep_AdekuasiIsActive = 'Y' - GROUP BY Lcprep_AdekuasiID - ORDER BY Lcprep_AdekuasiOrder ASC - "; - //echo $sql; - $adeakuasi = $this->db_smartone->query($sql)->result_array(); - foreach ($adeakuasi as $kc => $vc) { - $adeakuasi[$kc]['chex'] = $vc['chex'] == 'N' ? false : true; - } - - $sql = "SELECT IFNULL(Other_LcprepKategoriUmumID,0) as xid, - Lcprep_KategoriUmumID as id, - Lcprep_KategoriUmumLabel as name, - IF(ISNULL(Other_LcprepKategoriUmumID),'N',Other_LcprepKategoriUmumChex) as chex - FROM lcprep_kategoriumum - LEFT JOIN other_lcprepkategoriumum ON Other_LcprepKategoriUmumLcprep_KategoriUmumID = Lcprep_KategoriUmumID AND - Other_LcprepKategoriUmumOther_LcprepID = {$header_id} AND - Other_LcprepKategoriUmumIsActive = 'Y' - WHERE - Lcprep_KategoriUmumIsActive = 'Y' - GROUP BY Lcprep_KategoriUmumID - "; - //echo $sql; - $kategoriumum = $this->db_smartone->query($sql)->result_array(); - foreach ($kategoriumum as $kc => $vc) { - $kategoriumum[$kc]['chex'] = $vc['chex'] == 'N' ? false : true; - } - - $sql = " - SELECT Lcprep_InterpretasiGroupID as group_id, - Lcprep_InterpretasiGroupName as group_name, - '' as subgroups - FROM lcprep_interpretasigroup - WHERE - Lcprep_InterpretasiGroupIsActive = 'Y' - "; - //echo $sql; - $interpretasi = $this->db_smartone->query($sql)->result_array(); - foreach ($interpretasi as $k => $v) { - $subgroups = array(); - $sql = "SELECT Lcprep_InterpretasiSubgroupID as subgroup_id, - Lcprep_InterpretasiSubgroupName as subgroup_name, - '' as childs - FROM lcprep_interpretasisubgroup - WHERE - Lcprep_InterpretasiSubgroupLcprep_InterpretasiGroupID = {$v['group_id']} AND Lcprep_InterpretasiSubgroupIsActive = 'Y'"; - //echo $sql; - $subgroups = $this->db_smartone->query($sql)->result_array(); - if (count($subgroups) > 0) { - foreach ($subgroups as $ki => $vi) { - $childs = array(); - $sql = "SELECT IFNULL(Other_LcprepInterpretasiID,0) as xid, - IFNULL(Other_LcprepInterpretasiChex,'N') as chex, - IFNULL(Other_LcprepInterpretasiValue,'') as value, - Lcprep_InterpretasiID as id, - Lcprep_InterpretasiLcprep_InterpretasiSubgroupID as subgroup_id, - Lcprep_InterpretasiCode as code, - Lcprep_InterpretasiName as name, - Lcprep_InterpretasiParentID as parent_id, - Lcprep_InterpretasiIsParent as is_parent, - Lcprep_InterpretasiHasResult as has_result, - Lcprep_InterpretasiTypeResult as type_result - FROM lcprep_interpretasi - LEFT JOIN other_lcprepinterpretasi ON Other_LcprepInterpretasiOther_LcprepID = {$header_id} AND - Other_LcprepInterpretasiLcprep_InterpretasiID = Lcprep_InterpretasiID AND - Other_LcprepInterpretasiIsActive = 'Y' - WHERE - Lcprep_InterpretasiLcprep_InterpretasiSubgroupID = {$vi['subgroup_id']} AND Lcprep_InterpretasiIsActive = 'Y' - GROUP BY Lcprep_InterpretasiID Order BY Lcprep_InterpretasiCode ASC"; - $childs = $this->db_smartone->query($sql)->result_array(); - if ($childs) { - foreach ($childs as $kc => $vc) { - $childs[$kc]['chex'] = $vc['chex'] == 'N' ? false : true; - } - } - $subgroups[$ki]['childs'] = $childs; - } - } - - $interpretasi[$k]['subgroups'] = $subgroups; - } - - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $rst = array('doctors' => $doctors, 'results' => $rows, 'adekuasi' => $adeakuasi, 'kategoriumum' => $kategoriumum, 'interpretasi' => $interpretasi); - $this->sys_ok(["records" => $rst]); - } - - function getpapsmearresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT Other_PapSmearDetailsID as xid, - Other_PapSmearID as header_id, - Other_PapSmearT_OrderDetailID as orderdetail_id, - Other_PapSmearDetailsCode as code, - Other_PapSmearDetailsLabel as label, - Other_PapSmearDetailsResult as result, - IFNULL(Other_PapSmearM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_PapSmearM_DoctorID) OR Other_PapSmearM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_papsmear - JOIN other_papsmeardetails ON Other_PapSmearDetailsOther_PapSmearID = Other_PapSmearID AND Other_PapSmearDetailsIsActive = 'Y' - LEFT JOIN m_doctor ON Other_PapSmearM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_PapSmearT_OrderDetailID = {$id} AND Other_PapSmearIsActive = 'Y' - GROUP BY Other_PapSmearDetailsID - ORDER BY Other_PapSmearDetailsCode ASC"; - //echo $sql; - $rows = $this->db_smartone->query($sql)->result_array(); - if (!$rows) { - $rows = array( - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'A', - 'label' => 'Makroskopik', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ), - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'B', - 'label' => 'Mikroskopik', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ), - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'C', - 'label' => 'Kesimpulan', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ) - ); - } - - $header_id = $rows[0]['header_id']; - $sql = "SELECT Other_PapSmearMaturasiID as xid, - Other_PapSmearMaturasiValue as value - FROM other_papsmearmaturasi - WHERE - Other_PapSmearMaturasiOther_PapSmearID = {$header_id} AND - Other_PapSmearMaturasiIsActive = 'Y' - "; - //echo $sql; - $dt_maturasi = $this->db_smartone->query($sql)->row_array(); - if (!$dt_maturasi) { - $maturasi = array('xid' => '0', 'value' => array('', '', '')); - } else { - $value = explode('/', $dt_maturasi['value']); - $maturasi = array('xid' => $dt_maturasi['xid'], 'value' => $value); - } - - $sql = "SELECT IFNULL(Other_PapSmearBahanID,0) as xid, - M_PapSmearBahanID as bahan_id, - M_PapSmearBahanName as name, - IF(ISNULL(Other_PapSmearBahanID),'N','Y') as selected - FROM m_papsmearbahan - LEFT JOIN other_papsmearbahan ON Other_PapSmearBahanM_PapSmearBahanID = M_PapSmearBahanID AND - Other_PapSmearBahanOther_PapSmearID = {$header_id} AND - Other_PapSmearBahanIsActive = 'Y' - WHERE - M_PapSmearBahanIsActive = 'Y' - ORDER BY M_PapSmearBahanID ASC - "; - //echo $sql; - $bahans = $this->db_smartone->query($sql)->result_array(); - - $sql = "SELECT IFNULL(Other_PapsmearCategoryID,0) as xid, - M_PapSmearCategoryID as category_id, - M_PapSmearCategoryName as name, - IF(ISNULL(Other_PapsmearCategoryID),'N','Y') as selected - FROM m_papsmearcategory - LEFT JOIN other_papsmearcategory ON Other_PapsmearCategoryM_PapSmearCategoryID = M_PapSmearCategoryID AND - Other_PapsmearCategoryOther_PapSmearID = {$header_id} AND - Other_PapsmearCategoryIsActive = 'Y' - WHERE - M_PapSmearCategoryIsActive = 'Y' - ORDER BY M_PapSmearCategoryID ASC - "; - //echo $sql; - $categories = $this->db_smartone->query($sql)->result_array(); - - $sql = "SELECT IFNULL(Other_PapSmearCheckID,0) as xid, - M_PapSmearCheckID as check_id, - M_PapSmearCheckLabel as name, - IF(ISNULL(Other_PapSmearCheckID),'N','Y') as selected, - Other_PapSmearCheckNote as note - FROM m_papsmearcheck - LEFT JOIN other_papsmearcheck ON Other_PapSmearCheckM_PapSmearCheckID = M_PapSmearCheckID AND - Other_PapSmearCheckOther_PapSmearID = {$header_id} AND - Other_PapSmearCheckIsActive = 'Y' - WHERE - M_PapSmearCheckIsActive = 'Y' - ORDER BY M_PapSmearCheckCode ASC - "; - $checks = $this->db_smartone->query($sql)->result_array(); - - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $rst = array('doctors' => $doctors, 'checks' => $checks, 'bahans' => $bahans, 'categories' => $categories, 'maturasi' => $maturasi, 'results' => $rows); - $this->sys_ok(["records" => $rst]); - } - - function saveresult_lcprep() - { - $prm = $this->sys_input; - $detail_id = $prm['detail_id']; - $doctor_id = $prm['doctor']; - $adekuasi = $prm['adekuasi']; - $kategoriumum = $prm['kategoriumum']; - $interpretasi = $prm['interpretasi']; - $results = $prm['results']; - - $userid = $this->sys_user['M_UserID']; - - $header_id = 0; - $sql = "SELECT * FROM other_lcprep WHERE Other_LcprepT_orderDetailID = {$detail_id} AND Other_LcprepIsActive = 'Y'"; - $dt_header = $this->db_smartone->query($sql)->row_array(); - if ($dt_header) { - $header_id = $dt_header['Other_LcprepID']; - } - if ($header_id == 0) { - $sql = "INSERT INTO other_lcprep( - Other_LcprepT_orderDetailID, - Other_LcprepM_DoctorID, - Other_LcprepUserID, - Other_LcprepCreated - ) - VALUES( - {$detail_id}, - {$doctor_id}, - {$userid}, - NOW() - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } else { - $sql = "UPDATE other_lcprep SET Other_LcprepM_DoctorID = {$doctor_id}, Other_LcprepUserID = {$userid} WHERE Other_LcprepID = {$header_id}"; - $this->db_smartone->query($sql); - } - - if ($adekuasi) { - foreach ($adekuasi as $k => $v) { - $selected = $v['chex'] ? 'Y' : 'N'; - if (intval($v['xid'] == 0)) { - $sql = "UPDATE other_lcprepadekuasi SET Other_LcprepAdekuasiIsActive = 'N' - WHERE - Other_LcprepAdekuasiOther_LcprepID = {$header_id} AND - Other_LcprepAdekuasiIsActive = 'Y' AND - Other_LcprepAdekuasiLcprep_AdekuasiID = {$v['id']}"; - $this->db_smartone->query($sql); - $sql = "INSERT INTO other_lcprepadekuasi ( - Other_LcprepAdekuasiOther_LcprepID, - Other_LcprepAdekuasiLcprep_AdekuasiID, - Other_LcprepAdekuasiChex, - Other_LcprepAdekuasiUserID, - Other_LcprepAdekuasiCreated - ) - VALUES( - {$header_id}, - {$v['id']}, - '{$selected}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - //echo $sql; - } - if (intval($v['xid'] != 0)) { - - $sql = "UPDATE other_lcprepadekuasi SET - Other_LcprepAdekuasiChex = '{$selected}', - Other_LcprepAdekuasiUserID = {$userid} - WHERE - Other_LcprepAdekuasiID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - - //echo $sql; - } - } - - if ($kategoriumum) { - foreach ($kategoriumum as $k => $v) { - $selected = $v['chex'] ? 'Y' : 'N'; - if (intval($v['xid'] == 0)) { - $sql = "UPDATE other_lcprepkategoriumum SET Other_LcprepKategoriUmumIsActive = 'N' - WHERE - Other_LcprepKategoriUmumOther_LcprepID = {$header_id} AND - Other_LcprepKategoriUmumLcprep_KategoriUmumID = {$v['id']} AND - Other_LcprepKategoriUmumIsActive = 'Y' - "; - $this->db_smartone->query($sql); - $sql = "INSERT INTO other_lcprepkategoriumum ( - Other_LcprepKategoriUmumOther_LcprepID, - Other_LcprepKategoriUmumLcprep_KategoriUmumID, - Other_LcprepKategoriUmumChex, - Other_LcprepKategoriUmumUserID, - Other_LcprepKategoriUmumCreated - ) - VALUES( - {$header_id}, - {$v['id']}, - '{$selected}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if (intval($v['xid'] != 0)) { - $sql = "UPDATE other_lcprepkategoriumum SET - Other_LcprepKategoriUmumChex = '{$selected}', - Other_LcprepKategoriUmumUserID = {$userid} - WHERE - Other_LcprepKategoriUmumID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - - //echo $sql; - } - } - - if ($results) { - foreach ($results as $k => $v) { - if (intval($v['xid'] == 0)) { - $sql = "UPDATE other_lcprepdetails SET Other_LcprepDetailsIsActive = 'N' - WHERE - Other_LcprepDetailsOther_LcprepID = {$header_id} AND - Other_LcprepDetailsCode = '{$v['code']}' AND - Other_LcprepDetailsIsActive = 'Y'"; - $this->db_smartone->query($sql); - $sql = "INSERT INTO other_lcprepdetails ( - Other_LcprepDetailsOther_LcprepID, - Other_LcprepDetailsCode, - Other_LcprepDetailsLabel, - Other_LcprepDetailsResult, - Other_LcprepDetailsUserID, - Other_LcprepDetailsCreated - ) - VALUES( - {$header_id}, - '{$v['code']}', - '{$v['label']}', - '{$v['result']}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if (intval($v['xid'] != 0)) { - $sql = "UPDATE other_lcprepdetails SET - Other_LcprepDetailsCode = '{$v['code']}', - Other_LcprepDetailsLabel = '{$v['label']}', - Other_LcprepDetailsResult = '{$v['result']}', - Other_LcprepDetailsUserID = {$userid} - WHERE - Other_LcprepDetailsID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - //echo $sql; - } - } - - if ($interpretasi) { - foreach ($interpretasi as $k => $v) { - if (count($v['subgroups']) > 0) { - foreach ($v['subgroups'] as $ik => $iv) { - if (count($iv['childs']) > 0) { - foreach ($iv['childs'] as $iik => $iiv) { - if (intval($iiv['xid'] == 0)) { - $chex = $iiv['chex'] ? 'Y' : 'N'; - $sql = "UPDATE other_lcprepinterpretasi SET Other_LcprepInterpretasiIsActive = 'N' - WHERE - Other_LcprepInterpretasiOther_LcprepID = {$header_id} AND - Other_LcprepInterpretasiLcprep_InterpretasiID = '{$iiv['id']}' AND - Other_LcprepInterpretasiIsActive = 'Y'"; - $this->db_smartone->query($sql); - $sql = "INSERT INTO other_lcprepinterpretasi ( - Other_LcprepInterpretasiOther_LcprepID, - Other_LcprepInterpretasiLcprep_InterpretasiID, - Other_LcprepInterpretasiChex, - Other_LcprepInterpretasiValue, - Other_LcprepInterpretasiUserID, - Other_LcprepInterpretasiCreated - ) - VALUES( - {$header_id}, - '{$iiv['id']}', - '{$chex}', - '{$iiv['value']}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - - if (intval($iiv['xid'] != 0)) { - $chex = $iiv['chex'] ? 'Y' : 'N'; - $sql = "UPDATE other_lcprepinterpretasi SET - Other_LcprepInterpretasiChex = '{$chex}', - Other_LcprepInterpretasiValue = '{$iiv['value']}', - Other_LcprepInterpretasiUserID = {$userid} - WHERE - Other_LcprepInterpretasiID = {$iiv['xid']}"; - $this->db_smartone->query($sql); - //echo $sql; - - } - } - } - } - } - //echo $sql; - } - } - - - $result = array("total" => 1, "records" => array(), "sql" => ''); - $this->sys_ok($result); - exit; - } - - function saveresult_papsmear() - { - $prm = $this->sys_input; - $detail_id = $prm['detail_id']; - $doctor_id = $prm['doctor']; - $checks = $prm['checks']; - $maturasi = $prm['maturasi']; - $bahans = $prm['bahans']; - $categories = $prm['categories']; - $results = $prm['results']; - - $userid = $this->sys_user['M_UserID']; - - $header_id = 0; - $sql = "SELECT * FROM other_papsmear WHERE Other_PapSmearT_OrderDetailID = {$detail_id} AND Other_PapSmearIsActive = 'Y'"; - $dt_header = $this->db_smartone->query($sql)->row_array(); - if ($dt_header) { - $header_id = $dt_header['Other_PapSmearID']; - } - if ($header_id == 0) { - $sql = "INSERT INTO other_papsmear( - Other_PapSmearT_OrderDetailID, - Other_PapSmearM_DoctorID, - Other_PapSmearUserID, - Other_PapSmearCreated - ) - VALUES( - {$detail_id}, - {$doctor_id}, - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } else { - $sql = "UPDATE other_papsmear SET Other_PapSmearM_DoctorID = {$doctor_id}, Other_PapSmearUserID = {$userid} WHERE Other_PapSmearID = {$header_id}"; - $this->db_smartone->query($sql); - } - - if ($checks) { - foreach ($checks as $k => $v) { - if (intval($v['xid']) == 0 && $v['selected'] === 'Y') { - $sql = "INSERT INTO other_papsmearcheck ( - Other_PapSmearCheckOther_PapSmearID, - Other_PapSmearCheckM_PapSmearCheckID, - Other_PapSmearCheckNote, - Other_PapSmearCheckUserID, - Other_PapSmearCheckCreated - ) - VALUES( - {$header_id}, - {$v['check_id']}, - '{$v['note']}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if (intval($v['xid']) != 0 && $v['selected'] === 'N') { - $sql = "UPDATE other_papsmearcheck SET - Other_PapSmearCheckIsActive = 'N', - Other_PapSmearCheckUserID = {$userid} - WHERE - Other_PapSmearCheckID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - if (intval($v['xid']) != 0 && $v['selected'] === 'Y') { - $sql = "UPDATE other_papsmearcheck SET - Other_PapSmearCheckNote = '{$v['note']}', - Other_PapSmearCheckUserID = {$userid} - WHERE - Other_PapSmearCheckID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - //echo $sql; - } - } - - if ($maturasi) { - if (intval($maturasi['xid']) == 0) { - $value = join("/", $maturasi['value']); - $sql = "INSERT INTO other_papsmearmaturasi ( - Other_PapSmearMaturasiOther_PapSmearID, - Other_PapSmearMaturasiValue, - Other_PapSmearMaturasiUserID, - Other_PapSmearMaturasiCreated - ) - VALUE( - {$header_id}, - '{$value}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - //echo $sql; - } - if (intval($maturasi['xid']) != 0) { - $value = join("/", $maturasi['value']); - $sql = "UPDATE other_papsmearmaturasi SET - Other_PapSmearMaturasiValue = '{$value}', - Other_PapSmearMaturasiUserID = {$userid} - WHERE - Other_PapSmearMaturasiID = {$maturasi['xid']}"; - // echo $sql; - $this->db_smartone->query($sql); - } - } - - if ($bahans) { - foreach ($bahans as $k => $v) { - if (intval($v['xid']) == 0 && $v['selected'] === 'Y') { - $sql = "INSERT INTO other_papsmearbahan ( - Other_PapSmearBahanOther_PapSmearID, - Other_PapSmearBahanM_PapSmearBahanID, - Other_PapSmearBahanUserID, - Other_PapSmearBahanCreated - ) - VALUES( - {$header_id}, - {$v['bahan_id']}, - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if (intval($v['xid']) != 0 && $v['selected'] === 'N') { - $sql = "UPDATE other_papsmearbahan SET - Other_PapSmearBahanIsActive = 'N', - Other_PapsmearCategoryUserID = {$userid} - WHERE - Other_PapSmearBahanID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - if (intval($v['xid']) != 0 && $v['selected'] === 'Y') { - $sql = "UPDATE other_papsmearbahan SET - Other_PapSmearBahanIsActive = 'Y', - Other_PapsmearCategoryUserID = {$userid} - WHERE - Other_PapSmearBahanID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - //echo $sql; - } - } - - if ($categories) { - foreach ($categories as $k => $v) { - if (intval($v['xid']) == 0 && $v['selected'] === 'Y') { - $sql = "INSERT INTO other_papsmearcategory ( - Other_PapsmearCategoryOther_PapSmearID, - Other_PapsmearCategoryM_PapSmearCategoryID, - Other_PapsmearCategoryUserID, - Other_PapsmearCategoryCreated - ) - VALUES( - {$header_id}, - {$v['category_id']}, - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if (intval($v['xid']) != 0 && $v['selected'] === 'N') { - $sql = "UPDATE other_papsmearcategory SET - Other_PapsmearCategoryIsActive = 'N', - Other_PapsmearCategoryUserID = {$userid} - WHERE - Other_PapsmearCategoryID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - //echo $sql; - if (intval($v['xid']) != 0 && $v['selected'] === 'Y') { - $sql = "UPDATE other_papsmearcategory SET - Other_PapsmearCategoryIsActive = 'Y', - Other_PapsmearCategoryUserID = {$userid} - WHERE - Other_PapsmearCategoryID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - } - } - - if ($results) { - foreach ($results as $k => $v) { - if (intval($v['xid']) == 0) { - $sql = "INSERT INTO other_papsmeardetails ( - Other_PapSmearDetailsOther_PapSmearID, - Other_PapSmearDetailsCode, - Other_PapSmearDetailsLabel, - Other_PapSmearDetailsResult, - Other_PapSmearDetailsUserID, - Other_PapSmearDetailsCreated - ) - VALUES( - {$header_id}, - '{$v['code']}', - '{$v['label']}', - '{$v['result']}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if (intval($v['xid']) != 0) { - $sql = "UPDATE other_papsmeardetails SET - Other_PapSmearDetailsCode = '{$v['code']}', - Other_PapSmearDetailsLabel = '{$v['label']}', - Other_PapSmearDetailsResult = '{$v['result']}', - Other_PapSmearDetailsUserID = {$userid} - WHERE - Other_PapSmearDetailsID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - //echo $sql; - } - } - - $result = array("total" => 1, "records" => array(), "sql" => ''); - $this->sys_ok($result); - exit; - } - - function saveresult_fna() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = $inp['doctor']; - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - if ($prm[0]['xid'] == '0') { - $sql = "INSERT INTO other_fna( - Other_FNAM_DoctorID, - Other_FNAT_OrderDetailID, - Other_FNAUserID, - Other_FNACreated - ) - VALUES( - {$doctor_id}, - {$prm[0]['orderdetail_id']}, - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } else { - $sql = "SELECT * FROM other_fna WHERE Other_FNAT_OrderDetailID = {$prm[0]['orderdetail_id']} AND Other_FNAIsActive = 'Y'"; - $data_header = $this->db_smartone->query($sql)->row_array(); - $header_id = $data_header['Other_FNAID']; - $sql = "UPDATE other_fna SET - Other_FNAM_DoctorID = {$doctor_id}, - Other_FNAUserID = {$userid} - WHERE - Other_FNAID = {$header_id}"; - $this->db_smartone->query($sql); - } - foreach ($prm as $k => $v) { - if ($v['xid'] == '0') { - $results = str_replace("'", "\\'", $v['result']); - $sql = "INSERT INTO other_fnadetails( - Other_FNADetailsOther_FNAID , - Other_FNADetailsCode, - Other_FNADetailsLabel, - Other_FNADetailsResult, - Other_FNADetailsCreated, - Other_FNADetailsUserID - ) - VALUES( - {$header_id}, - '{$v['code']}', - '{$v['label']}', - '{$results}', - NOW(), - {$userid} - )"; - $query = $this->db_smartone->query($sql); - } else { - $results = str_replace("'", "\\'", $v['result']); - $sql = "UPDATE other_fnadetails SET - Other_FNADetailsResult = '{$results}', - Other_FNADetailsUserID = {$userid} - WHERE - Other_FNADetailsID = {$v['xid']}"; - $query = $this->db_smartone->query($sql); - } - } - - $result = array("total" => 1, "records" => array(), "sql" => ''); - $this->sys_ok($result); - exit; - } - - function saveresult_cytologi() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = $inp['doctor']; - - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - if ($prm[0]['xid'] == '0') { - $sql = "INSERT INTO other_cytologi( - Other_CytologiT_OrderDetailID, - Other_CytologiM_DoctorID, - Other_CytologiUserID, - Other_CytologiCreated - ) - VALUES( - {$prm[0]['orderdetail_id']}, - {$doctor_id}, - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } else { - $sql = "SELECT * FROM other_cytologi WHERE Other_CytologiT_OrderDetailID = {$prm[0]['orderdetail_id']} AND Other_CytologiIsActive = 'Y'"; - $data_header = $this->db_smartone->query($sql)->row_array(); - $header_id = $data_header['Other_CytologiID']; - $sql = "UPDATE other_cytologi SET - Other_CytologiM_DoctorID = {$doctor_id}, - Other_CytologiUserID = {$userid} - WHERE - Other_CytologiID = {$header_id}"; - $this->db_smartone->query($sql); - } - foreach ($prm as $k => $v) { - if ($v['xid'] == '0') { - $results = str_replace("'", "\\'", $v['result']); - $sql = "INSERT INTO other_cytologidetails( - Other_CytologiDetailsOther_CytologiID , - Other_CytologiDetailsCode, - Other_CytologiDetailsLabel, - Other_CytologiDetailsResult, - Other_CytologiDetailsCreated, - Other_CytologiDetailsUserID - ) - VALUES( - {$header_id}, - '{$v['code']}', - '{$v['label']}', - '{$results}', - NOW(), - {$userid} - )"; - $query = $this->db_smartone->query($sql); - } else { - $results = str_replace("'", "\\'", $v['result']); - $sql = "UPDATE other_cytologidetails SET - Other_CytologiDetailsResult = '{$results}', - Other_CytologiDetailsUserID = {$userid} - WHERE - Other_CytologiDetailsID = {$v['xid']}"; - $query = $this->db_smartone->query($sql); - } - } - - $result = array("total" => 1, "records" => array(), "sql" => ''); - $this->sys_ok($result); - exit; - } - - function saveresult_mikro() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = $inp['doctor']; - $backteria_id = $inp['bacteria']; - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - - if ($inp['result_value'] != 'Negatif' && $inp['result_value'] != 'Positif') { - $prm['result_value'] = $prm['result_other']; - } else { - $prm['result_value'] = $inp['result_value']; - } - - if ($prm['xid'] == '0') { - $sql = "INSERT INTO other_mikro( - Other_MikroM_DoctorID, - Other_MikroResult, - Other_MikroT_BacteriaID, - Other_MikroT_OrderDetailID, - Other_MikroHasilBiakan, - Other_MikroSampleTypeName, - Other_MikroUserID, - Other_MikroCreated - ) - VALUES( - {$doctor_id}, - '{$prm['result_value']}', - {$backteria_id}, - {$prm['orderdetail_id']}, - '{$prm['hasil_biakan']}', - '{$prm['sample_name']}', - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } else { - $sql = "SELECT * FROM other_mikro WHERE Other_MikroT_OrderDetailID = {$prm['orderdetail_id']} AND Other_MikroIsActive = 'Y'"; - $data_header = $this->db_smartone->query($sql)->row_array(); - $header_id = $data_header['Other_MikroID']; - $sql = "UPDATE other_mikro SET - Other_MikroResult = '{$prm['result_value']}', - Other_MikroM_DoctorID = {$doctor_id}, - Other_MikroT_BacteriaID = {$backteria_id}, - Other_MikroHasilBiakan = '{$prm['hasil_biakan']}', - Other_MikroSampleTypeName = '{$prm['sample_name']}', - Other_MikroUserID = {$userid} - WHERE - Other_MikroID = {$header_id}"; - //echo $sql; - $this->db_smartone->query($sql); - } - - - - $sql = "UPDATE other_mikrodetails SET Other_MikroDetailsIsActive = 'N', Other_MikroDetailsUserID = 0 WHERE Other_MikroDetailsOther_MikroID = {$header_id}"; - $this->db_smartone->query($sql); - - $results = $prm['details']; - if ($inp['result_value'] == 'Positif') { - foreach ($results as $k => $v) { - if ($v['xid'] == '0') { - $sql = "INSERT INTO other_mikrodetails( - Other_MikroDetailsOther_MikroID , - Other_MikroDetailsT_AntibioticID, - Other_MikroDetailsValue, - Other_MikroDetailsNote, - Other_MikroDetailsCreated, - Other_MikroDetailsUserID - ) - VALUES( - {$header_id}, - '{$v['T_AntibioticID']}', - '{$v['value']}', - '{$v['note']}', - NOW(), - {$userid} - )"; - $query = $this->db_smartone->query($sql); - } else { - $sql = "UPDATE other_mikrodetails SET - Other_MikroDetailsT_AntibioticID = '{$v['T_AntibioticID']}', - Other_MikroDetailsValue = '{$v['value']}', - Other_MikroDetailsNote = '{$v['note']}', - Other_MikroDetailsIsActive = 'Y', - Other_MikroDetailsUserID = {$userid} - WHERE - Other_MikroDetailsID = {$v['xid']}"; - //echo $sql; - $query = $this->db_smartone->query($sql); - } - } - } - - - $result = array("total" => 1, "records" => array(), "sql" => ''); - $this->sys_ok($result); - exit; - } - - - function get_doctors_preparasi_sperma() - { - $prm = $this->sys_input; - // $id = $prm["id"]; - - $sql = " SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 10 AND - M_DoctorSOIsActive = 'Y' - ORDER BY M_DoctorName ASC"; - //echo $sql; - $query = $this->db_smartone->query($sql); - $rows = $query->result_array(); - $sql = " - SELECT '0' as id, 'Belum memilih metode' as name - UNION - SELECT M_MethodeSpermaID as id, M_MethodeSpermaName as name - FROM m_methodesperma - WHERE - M_MethodeSpermaIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $methodes = $this->db_smartone->query($sql)->result_array(); - - - $this->sys_ok(["records" => $rows, "methodes" => $methodes]); - } - - - function getpreparasispermaresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT other_preparasisperma.*, - Other_PreparasiSpermaID as xid, - Other_PreparasiSpermaT_OrderDetailID as orderdetail_id, - IFNULL(Other_PreparasiSpermaM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_PreparasiSpermaM_DoctorID) OR Other_PreparasiSpermaM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name, - IFNULL(M_MethodeSpermaID,0) as methode_id, - IFNULL(M_MethodeSpermaName,'') as methode_name - FROM other_preparasisperma - LEFT JOIN m_doctor ON Other_PreparasiSpermaM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - LEFT JOIN m_methodesperma ON Other_PreparasiSpermaM_MethodeSpermaID = M_MethodeSpermaID AND - M_MethodeSpermaIsActive = 'Y' - WHERE - Other_PreparasiSpermaT_OrderDetailID = {$id} AND Other_PreparasiSpermaIsActive = 'Y' - GROUP BY Other_PreparasiSpermaID"; - $query = $this->db_smartone->query($sql); - - if ($query) { - $rows = $query->row_array(); - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 10 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $sql = " - SELECT '0' as id, 'Belum memilih metode' as name - UNION - SELECT M_MethodeSpermaID as id, M_MethodeSpermaName as name - FROM m_methodesperma - WHERE - M_MethodeSpermaIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $methodes = $this->db_smartone->query($sql)->result_array(); - $images = array(); - $sql = "SELECT Other_PreparasiSpermaImgID as xid, - Other_PreparasiSpermaImgType as type, - CONCAT('/one-media/one-image-nonlab/',Other_PreparasiSpermaImgNewName) as image_url - FROM t_orderdetail - JOIN other_preparasisperma_img ON Other_PreparasiSpermaImgT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND - Other_PreparasiSpermaImgIsActive = 'Y' - WHERE - T_OrderDetailID = {$id} AND - T_OrderDetailIsActive = 'Y' - GROUP BY Other_PreparasiSpermaImgID"; - //echo $sql; - $images = $this->db_smartone->query($sql)->result_array(); - - $rst = array('doctors' => $doctors, 'methodes' => $methodes, 'results' => $rows, 'images' => $images); - $this->sys_ok(["records" => $rst]); - } else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - - function uploadimage_preparasi_sperma() - { - if (! $this->isLogin) { - $this->sys_error("Invalid Token"); - exit; - } - - $userid = $this->sys_user["M_UserID"]; - $data = []; - //print_r($_SERVER); - - $prm = $this->sys_input; - $orderid = $this->input->post('orderid'); - $type = $this->input->post('type'); - $labnumber = $this->input->post('labnumber'); - $sql = "UPDATE other_preparasisperma_img SET - Other_PreparasiSpermaImgIsActive = 'N', - Other_PreparasiSpermaImgUserID = {$userid} - WHERE - Other_PreparasiSpermaImgT_OrderHeaderID = {$orderid} AND - Other_PreparasiSpermaImgType = '{$type}'"; - //echo $sql; - $this->db_onedev->query($sql); - //$config['upload_path'] = 'assets/'; - - $path = '/home/one/project/one/one-media/one-image-nonlab/'; - //echo $path; - $config['upload_path'] = $path; - $config['allowed_types'] = 'jpg|jpeg|png|gif'; - - $config['max_size'] = '10000'; - $count = count($_FILES['files']['name']); - //echo $count; - $this->load->library('upload', $config); - - $error = []; - for ($i = 0; $i < $count; $i++) { - - - if (!empty($_FILES['files']['name'][$i])) { - - - - $_FILES['file']['name'] = $_FILES['files']['name'][$i]; - - $_FILES['file']['type'] = $_FILES['files']['type'][$i]; - - $_FILES['file']['tmp_name'] = $_FILES['files']['tmp_name'][$i]; - - $_FILES['file']['error'] = $_FILES['files']['error'][$i]; - - $_FILES['file']['size'] = $_FILES['files']['size'][$i]; - - - - $namex = $orderid . '-' . $labnumber . '-' . $this->generateRandomString(5); - //echo $namex; - - $config['file_name'] = $namex; - $this->upload->initialize($config); - //echo $config['file_name'] ; - - - - - - if ($this->upload->do_upload('file')) { - - $uploadData = $this->upload->data(); - - $filename = $uploadData['file_name']; - //echo $filename; - - - $sql = "INSERT INTO other_preparasisperma_img ( - Other_PreparasiSpermaImgT_OrderHeaderID, - Other_PreparasiSpermaImgType, - Other_PreparasiSpermaImgOldName, - Other_PreparasiSpermaImgNewName, - Other_PreparasiSpermaImgCreated, - Other_PreparasiSpermaImgUserID - ) - VALUES( - {$orderid}, - '{$type}', - '{$_FILES['files']['name'][$i]}', - '{$filename}', - NOW(), - {$userid} - - )"; - //echo $sql; - $this->db_onedev->query($sql); - $xlast_id = $this->db_onedev->insert_id(); - $data['totalFiles'][] = array('xid' => $xlast_id, 'type' => $type, 'image_url' => '/one-media/one-image-nonlab/' . $filename); - } else { - $error = array('error' => $this->upload->display_errors()); - } - } - } - - $result = array("total" => count($data['totalFiles']), "records" => $data['totalFiles'], 'errors' => $error); - $this->sys_ok($result); - } - - - function saveresult_preparasi_sperma() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = $inp['doctor']; - $orderdetail_id = $inp['orderdetailid']; - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - if ($prm['xid'] == '0') { - $sql = "INSERT INTO other_preparasisperma( - Other_PreparasiSpermaM_DoctorID, - Other_PreparasiSpermaT_OrderDetailID, - Other_PreparasiSpermaPreMotilitasA, - Other_PreparasiSpermaPreMotilitasB, - Other_PreparasiSpermaPreMotilitasC, - Other_PreparasiSpermaPreKonsentrasi, - Other_PreparasiSpermaPreKontaminan, - Other_PreparasiSpermaPostMotilitasA, - Other_PreparasiSpermaPostMotilitasB, - Other_PreparasiSpermaPostMotilitasC, - Other_PreparasiSpermaPostKonsentrasi, - Other_PreparasiSpermaPostKontaminan, - Other_PreparasiSpermaPreVolume, - Other_PreparasiSpermaPostVolume, - Other_PreparasiSpermaM_MethodeSpermaID, - Other_PreparasiSpermaNote, - Other_PreparasiSpermaUserID, - Other_PreparasiSpermaCreated - ) - VALUES( - {$doctor_id}, - {$orderdetail_id}, - '{$prm['Other_PreparasiSpermaPreMotilitasA']}', - '{$prm['Other_PreparasiSpermaPreMotilitasB']}', - '{$prm['Other_PreparasiSpermaPreMotilitasC']}', - '{$prm['Other_PreparasiSpermaPreKonsentrasi']}', - '{$prm['Other_PreparasiSpermaPreKontaminan']}', - '{$prm['Other_PreparasiSpermaPostMotilitasA']}', - '{$prm['Other_PreparasiSpermaPostMotilitasB']}', - '{$prm['Other_PreparasiSpermaPostMotilitasC']}', - '{$prm['Other_PreparasiSpermaPostKonsentrasi']}', - '{$prm['Other_PreparasiSpermaPostKontaminan']}', - '{$prm['Other_PreparasiSpermaPreVolume']}', - '{$prm['Other_PreparasiSpermaPostVolume']}', - '{$prm['Other_PreparasiSpermaM_MethodeSpermaID']}', - '{$prm['Other_PreparasiSpermaNote']}', - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } else { - $sql = "SELECT * FROM other_preparasisperma WHERE Other_PreparasiSpermaT_OrderDetailID = {$orderdetail_id} AND Other_PreparasiSpermaIsActive = 'Y'"; - $data_header = $this->db_smartone->query($sql)->row_array(); - $header_id = $data_header['Other_PreparasiSpermaID']; - $sql = "UPDATE other_preparasisperma SET - Other_PreparasiSpermaM_DoctorID = {$doctor_id}, - Other_PreparasiSpermaPreMotilitasA = '{$prm['Other_PreparasiSpermaPreMotilitasA']}', - Other_PreparasiSpermaPreMotilitasB = '{$prm['Other_PreparasiSpermaPreMotilitasB']}', - Other_PreparasiSpermaPreMotilitasC = '{$prm['Other_PreparasiSpermaPreMotilitasC']}', - Other_PreparasiSpermaPreKonsentrasi = '{$prm['Other_PreparasiSpermaPreKonsentrasi']}', - Other_PreparasiSpermaPreKontaminan = '{$prm['Other_PreparasiSpermaPreKontaminan']}', - Other_PreparasiSpermaPostMotilitasA = '{$prm['Other_PreparasiSpermaPostMotilitasA']}', - Other_PreparasiSpermaPostMotilitasB = '{$prm['Other_PreparasiSpermaPostMotilitasB']}', - Other_PreparasiSpermaPostMotilitasC = '{$prm['Other_PreparasiSpermaPostMotilitasC']}', - Other_PreparasiSpermaPostKonsentrasi = '{$prm['Other_PreparasiSpermaPostKonsentrasi']}', - Other_PreparasiSpermaPostKontaminan = '{$prm['Other_PreparasiSpermaPostKontaminan']}', - Other_PreparasiSpermaPreVolume = '{$prm['Other_PreparasiSpermaPreVolume']}', - Other_PreparasiSpermaPostVolume = '{$prm['Other_PreparasiSpermaPostVolume']}', - Other_PreparasiSpermaM_MethodeSpermaID = '{$prm['Other_PreparasiSpermaM_MethodeSpermaID']}', - Other_PreparasiSpermaNote = '{$prm['Other_PreparasiSpermaNote']}', - Other_PreparasiSpermaUserID = {$userid} - WHERE - Other_PreparasiSpermaID = {$header_id}"; - $this->db_smartone->query($sql); - } - - - $result = array("total" => 1, "records" => array(), "sql" => ''); - $this->sys_ok($result); - exit; - } - - function getdnafragmentasiresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT other_dnafragmentasi.*, - Other_DnaFragmentasiID as xid, - Other_DnaFragmentasiT_OrderDetailID as orderdetail_id, - IFNULL(Other_DnaFragmentasiM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_DnaFragmentasiM_DoctorID) OR Other_DnaFragmentasiM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name, - IFNULL(Other_DnaFragmentasiOther_DnaFragmentasiMethodeID,0) as methode_id, - IFNULL(Other_DnaFragmentasiMethodeName,'') as methode_name, - Other_DnaFragmentasiHaloLuas as halo_luas, - Other_DnaFragmentasiHaloSedang as halo_sedang, - Other_DnaFragmentasiHaloSempit as halo_sempit, - Other_DnaFragmentasiTanpaHalo as tanpa_halo, - Other_DnaFragmentasiDFI as dfi, - Other_DnaFragmentasiKesimpulan as kesimpulan, - Other_DnaFragmentasiCatatan as catatan - FROM other_dnafragmentasi - LEFT JOIN m_doctor ON Other_DnaFragmentasiM_DoctorID = M_DoctorID - LEFT JOIN other_dnafragmentasimethode ON Other_DnaFragmentasiOther_DnaFragmentasiMethodeID = Other_DnaFragmentasiMethodeID - WHERE - Other_DnaFragmentasiT_OrderDetailID = {$id} AND Other_DnaFragmentasiIsActive = 'Y' - GROUP BY Other_DnaFragmentasiID - LIMIT 1"; - //echo $sql; - $query = $this->db_smartone->query($sql); - - if ($query) { - $rows = $query->row_array(); - if (!$rows) { - $rows = array( - 'xid' => 0, - 'orderdetail_id' => $id, - 'doctor_id' => 0, - 'doctor_name' => '', - 'methode_id' => 0, - 'methode_name' => '', - 'halo_luas' => '', - 'halo_sedang' => '', - 'tanpa_halo' => '', - 'dfi' => '', - 'kesimpulan' => '', - 'catatan' => '' - ); - } - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID - WHERE - M_DoctorSONat_SubGroupID = 4 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - - $sql = " - SELECT '0' as id, 'Belum memilih metode' as name - UNION - SELECT Other_DnaFragmentasiMethodeID as id, Other_DnaFragmentasiMethodeName as name - FROM other_dnafragmentasimethode - WHERE - Other_DnaFragmentasiMethodeIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $methodes = $this->db_smartone->query($sql)->result_array(); - - - $rst = array('doctors' => $doctors, 'methodes' => $methodes, 'results' => $rows); - $this->sys_ok(["records" => $rst]); - } else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - function saveresult_dnafragmentasi() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = $inp['doctor']['id']; - $methode_id = $inp['methode']['id']; - $orderdetail_id = $inp['results']['orderdetail_id']; - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - if (intval($prm['xid']) == 0) { - $sql = "INSERT INTO other_dnafragmentasi( - Other_DnaFragmentasiT_OrderDetailID, - Other_DnaFragmentasiM_DoctorID, - Other_DnaFragmentasiOther_DnaFragmentasiMethodeID, - Other_DnaFragmentasiHaloLuas, - Other_DnaFragmentasiHaloSedang, - Other_DnaFragmentasiHaloSempit, - Other_DnaFragmentasiTanpaHalo, - Other_DnaFragmentasiDFI, - Other_DnaFragmentasiKesimpulan, - Other_DnaFragmentasiCatatan, - Other_DnaFragmentasiUserID, - Other_DnaFragmentasiLastUpdated - ) - VALUES( - {$orderdetail_id}, - {$doctor_id}, - {$methode_id}, - '{$prm['halo_luas']}', - '{$prm['halo_sedang']}', - '{$prm['halo_sempit']}', - '{$prm['tanpa_halo']}', - '{$prm['dfi']}', - '{$prm['kesimpulan']}', - '{$prm['catatan']}', - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } else { - $sql = "UPDATE other_dnafragmentasi SET - Other_DnaFragmentasiT_OrderDetailID = {$orderdetail_id}, - Other_DnaFragmentasiM_DoctorID = {$doctor_id}, - Other_DnaFragmentasiOther_DnaFragmentasiMethodeID = '{$methode_id}', - Other_DnaFragmentasiHaloLuas = '{$prm['halo_luas']}', - Other_DnaFragmentasiHaloSedang = '{$prm['halo_sedang']}', - Other_DnaFragmentasiHaloSempit = '{$prm['halo_sempit']}', - Other_DnaFragmentasiTanpaHalo = '{$prm['tanpa_halo']}', - Other_DnaFragmentasiDFI = '{$prm['dfi']}', - Other_DnaFragmentasiKesimpulan = '{$prm['kesimpulan']}', - Other_DnaFragmentasiCatatan = '{$prm['catatan']}', - Other_DnaFragmentasiLastUpdated = NOW(), - Other_DnaFragmentasiUserID = {$userid} - WHERE - Other_DnaFragmentasiID = {$prm['xid']}"; - //echo $sql; - $this->db_smartone->query($sql); - } - - - $result = array("total" => 1, "records" => array(), "sql" => ''); - $this->sys_ok($result); - exit; - } -} +db_smartone = $this->load->database("onedev", true); + $this->load->helper(array('form', 'url')); + } + function getMethodeID($natTestID) + { + $sql = "select M_MethodePriorityNat_MethodeID MethodeID, Nat_MethodeName + from + m_methode_priority + join nat_methode on Nat_MethodeID = M_MethodePriorityNat_MethodeID + and Nat_MethodeIsActive = 'Y' + join m_instrumentmethode on M_InstrumentMethodeNat_MethodeID = Nat_MethodeID and M_InstrumentMethodeIsActive = 'Y' + join nat_instrument on M_InstrumentMethodeNat_InstrumentID = Nat_InstrumentID + and Nat_InstrumentIsActive ='Y' + where M_MethodePriorityIsActive = 'Y' + and M_MethodePriorityNat_TestID = $natTestID + and M_MethodePriorityM_DayOfWeekID = dayofweek(now()) + order by M_MethodePriorityNumber desc + limit 0,1 "; + $qry = $this->db->query($sql); + if ($qry) { + $rows = $qry->result_array(); + if (count($rows) > 0) return array($rows[0]["MethodeID"], $rows[0]["Nat_MethodeName"]); + } + //2nd + $sql = "select + M_InstrumentMethodeNat_MethodeID MethodeID, Nat_MethodeName + from m_instrumentmethode + join nat_methode on M_InstrumentMethodeNat_MethodeID = Nat_MethodeID + and Nat_MethodeIsActive = 'Y' + join nat_instrument on M_InstrumentMethodeNat_InstrumentID = Nat_InstrumentID + and Nat_InstrumentIsActive ='Y' + where M_InstrumentMethodeNat_TestID = $natTestID + and M_InstrumentMethodeIsActive = 'Y' + order by M_InstrumentMethodePriority desc + limit 0,1"; + $qry = $this->db->query($sql); + if ($qry) { + $rows = $qry->result_array(); + if (count($rows) > 0) return array($rows[0]["MethodeID"], $rows[0]["Nat_MethodeName"]); + } + // + $sql = "select Nat_NormalValueNat_MethodeID MethodeID, Nat_MethodeName + from + nat_normalvalue + join nat_methode on Nat_NormalValueNat_MethodeID = Nat_MethodeID + and Nat_MethodeIsActive = 'Y' + where Nat_NormalValueNat_TestID = $natTestID + and Nat_NormalValueIsActive = 'Y' + order by Nat_NormalValueID + limit 0,1"; + $qry = $this->db->query($sql); + if ($qry) { + $rows = $qry->result_array(); + if (count($rows) > 0) return array($rows[0]["MethodeID"], $rows[0]["Nat_MethodeName"]); + } + return array(0, ""); + } + function get_normal_value($methodeID, $natTestID, $sexID, $ageInDay) + { + $this->load->library('ibl_sampling_normal'); + return $this->ibl_sampling_normal->get_normal_value_id($methodeID, $natTestID, $sexID, $ageInDay); + } + return 0; + } + function fn_fix_normal($order_id) + { + $sql = "select + T_OrderDetailID, M_PatientM_SexID, fn_global_age_count_day(M_PatientDOB, date(T_OrderHeaderDate)) Dob , + T_TestNat_TestID + from t_orderheader + join m_patient on T_OrderHeaderID = $order_id and T_OrderHeaderM_PatientID = M_PatientID + join t_orderdetail on T_OrderDetailT_OrderHeaderID = T_OrderHeaderID + and T_OrderDetailIsACtive = 'Y' + and ( T_OrderDetailNat_NormalValueID is null or T_OrderDetailNat_NormalValueID = 0 ) + join t_test on T_OrderDetailT_TestID = T_TestID and T_TestIsResult = 'Y' "; + $qry = $this->db->query($sql); + if (! $qry) { + return; + } + $rows = $qry->result_array(); + if (count($rows) == 0) return; + $sql_u = "update t_orderdetail + join nat_normalvalue on T_OrderDetailID = ? and Nat_NormalValueID = ? + set + T_OrderDetailNat_NormalValueID = Nat_NormalValueID, + T_OrderDetailNormalValueNote = Nat_NormalValueNote, + T_OrderDetailNormalValueDescription = Nat_NormalValueDescription, + T_OrderDetailMinValue = Nat_NormalValueMinValue, + T_OrderDetailMaxValue = Nat_NormalValueMaxValue, + T_OrderDetailMinValueInclusive = Nat_NormalValueMinValueInclusive, + T_OrderDetailMaxValueInclusive = Nat_NormalValueMaxValueInclusive, + T_OrderDetailNat_MethodeID = ?, + T_OrderdetailNat_MethodeName =?"; + + foreach ($rows as $r) { + $T_OrderDetailID = $r["T_OrderDetailID"]; + $sexID = $r["M_PatientM_SexID"]; + $ageInDay = $r["Dob"]; + $natTestID = $r["T_TestNat_TestID"]; + list($methodeID, $methodeName) = $this->getMethodeID($natTestID); + if ($methodeID == 0) continue; + $normalValueID = $this->get_normal_value($methodeID, $natTestID, $sexID, $ageInDay); + if ($normalValueID == 0) return; + $this->db->query($sql_u, array($T_OrderDetailID, $normalValueID, $methodeID, $methodeName)); + } + } + function update_order_sample($targetID, $sourceID) + { + $sql = "update t_ordersample target + join t_ordersample source on + target.T_OrderSampleID = ? + and target.T_OrderSampleWorklistReceive = 'N' + and source.T_OrderSampleID = ? + set + target.T_OrderSampleSampling = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSampling, source.T_OrderSampleSampling), + target.T_OrderSampleSamplingDate = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingDate, source.T_OrderSampleSamplingDate), + target.T_OrderSampleSamplingTime = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingTime, source.T_OrderSampleSamplingTime), + target.T_OrderSampleSamplingUserID = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingUserID, source.T_OrderSampleSamplingUserID), + + target.T_OrderSampleReceive = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceive, source.T_OrderSampleReceive), + target.T_OrderSampleReceiveDate = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveDate, source.T_OrderSampleReceiveDate), + target.T_OrderSampleReceiveTime = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveTime, source.T_OrderSampleReceiveTime), + target.T_OrderSampleReceiveUserID = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveUserID, source.T_OrderSampleReceiveUserID), + + target.T_OrderSampleVerification = if(target.T_OrderSampleVerification='Y',target.T_OrderSampleVerification, source.T_OrderSampleVerification), + target.T_OrderSampleVerificationDate =if(target.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationDate, source.T_OrderSampleVerificationDate), + target.T_OrderSampleVerificationTime =if(source.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationTime, source.T_OrderSampleVerificationTime), + target.T_OrderSampleVerificationUserID =if(source.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationUserID, source.T_OrderSampleVerificationUserID), + + target.T_OrderSampleProcessing = if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessing, source.T_OrderSampleProcessing), + target.T_OrderSampleProcessingDate= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingDate, source.T_OrderSampleProcessingDate), + target.T_OrderSampleProcessingTime= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingTime, source.T_OrderSampleProcessingTime), + target.T_OrderSampleProcessingUserID= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingUserID, source.T_OrderSampleProcessingUserID), + + target.T_OrderSampleReceiveHandling =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandling, source.T_OrderSampleReceiveHandling ), + target.T_OrderSampleReceiveHandlingDate =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingDate, source.T_OrderSampleReceiveHandlingDate), + target.T_OrderSampleReceiveHandlingTime =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingTime, source.T_OrderSampleReceiveHandlingTime), + target.T_OrderSampleReceiveHandlingUserID =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingUserID, source.T_OrderSampleReceiveHandlingUserID), + + target.T_OrderSampleHandling = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandling, source.T_OrderSampleHandling), + target.T_OrderSampleHandlingDate = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingDate, source.T_OrderSampleHandlingDate), + target.T_OrderSampleHandlingTime = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingTime, source.T_OrderSampleHandlingTime), + target.T_OrderSampleHandlingUserID = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingUserID, source.T_OrderSampleHandlingUserID), + + target.T_OrderSampleWorklistReceive = source.T_OrderSampleWorklistReceive, + target.T_OrderSampleWorklistReceiveDatetime = source.T_OrderSampleWorklistReceiveDateTime, + target.T_OrderSampleWorklistReceiveUserID = source.T_OrderSampleWorklistReceiveUserID + "; + $qry = $this->db->query($sql, array($targetID, $sourceID)); + if (! $qry) { + echo json_encode(array("status" => "ERR", "message" => print_r($this->db->error(), true))); + exit; + } + } + function fix_sample_serum($headerID) + { + //cari t_ordersample yg belum worklist receive dengan code 017% + $sql = "select T_OrderSampleID + from t_ordersample + join t_sampletype on + T_OrderSampleT_OrderHeaderID = ? + and T_OrderSampleWorklistReceive = 'N' + and T_OrderSampleIsActive = 'Y' + and T_OrderSampleT_SampleTypeID = T_SampletypeID + and T_SampleTypeCode like '017%' + "; + $qry = $this->db->query($sql, array($headerID)); + if (!$qry) { + echo json_encode(array("status" => "ERR", "message" => print_r($this->db->error(), true))); + exit; + } + $rows = $qry->result_array(); + if (count($rows) == 0) return; + //cari T_OrderSample yang sudah di receive yg terakhir + $sql = "select T_OrderSampleID + from t_ordersample + join t_sampletype on + T_OrderSampleT_OrderHeaderID = ? + and T_OrderSampleWorklistReceive = 'Y' + and T_OrderSampleIsActive = 'Y' + and T_OrderSampleT_SampleTypeID = T_SampletypeID + and T_SampleTypeCode like '017%' + order by T_OrderSampleWorklistReceiveDatetime desc + limit 0,1 + "; + $qry = $this->db->query($sql, array($headerID)); + if (!$qry) { + echo json_encode(array("status" => "ERR", "message" => print_r($this->db->error(), true))); + exit; + } + $rcv_rows = $qry->result_array(); + if (count($rcv_rows) == 0) return; + + //print_r($rows); + //print_r($rcv_rows); + $rcv_T_OrderSampleID = $rcv_rows[0]["T_OrderSampleID"]; + //ada yg belum di receive + foreach ($rows as $r) { + $T_OrderSampleID = $r["T_OrderSampleID"]; + $this->update_order_sample($T_OrderSampleID, $rcv_T_OrderSampleID); + } + } + public function search() + { + $prm = $this->sys_input; + $max_rst = 99; + + $id = $prm["order_id"]; + if ($id > 0) { + $this->fix_sample_serum($id); + $this->fn_fix_normal($id); + } + $lang = $this->lang_default_code; + $lang_id = isset($prm['lang_id']) ? $prm['lang_id'] : '0'; + + if ($lang_id != 0) { + $l = $this->db_smartone->where("Nat_LangID", $lang_id)->get("nat_lang")->row(); + $lang = $l->Nat_LangCode; + } + + //tambahan fajri + $sql = " UPDATE t_orderdetail + JOIN t_test ON T_OrderDetailT_TestID = T_TestID + SET T_OrderDetailT_TestIsResult = T_TestIsResult + WHERE + T_OrderDetailT_OrderHeaderID = {$id} AND + T_OrderDetailT_TestIsResult = '' AND + T_OrderDetailIsActive = 'Y'"; + $this->db_smartone->query($sql); + + $tot_count = 0; + $lq = ""; + $group_id = 0; + if (isset($prm['group_id'])) + $group_id = $prm['group_id']; + + if ($group_id != 0) { + $sql = "select distinct T_WorklistDetailNat_TestID Nat_TestID + from t_worklistdetailv2 + where T_WorklistDetailT_WorklistID = {$group_id}"; + $qry = $this->db_smartone->query($sql); + $rows = $qry->result_array(); + $nat_test_ids = "0"; + foreach ($rows as $r) { + $nat_test_ids .= ", " . $r["Nat_TestID"]; + } + $q_group = " ( $nat_test_ids ) "; + + $sql = " + SELECT a1.*, cOUNT(a2.T_OrderDetailID) level + FROM ( + SELECT IFNULL(y.T_OrderDetailT_TestID, x.T_OrderDetailT_TestID) t_testid, + IFNULL(y.T_OrderDetailT_TestName, y.T_OrderDetailT_TestName) t_testname, + y.T_OrderDetailResult result, y.T_OrderDetailResult result_old, y.T_OrderDetailNote note, y.T_OrderDetailNote note_old, + y.T_OrderDetailID id, + y.T_OrderDetailT_TestIsResult is_result, a.T_TestIsQuantitative is_quantitative, + y.T_OrderDetailResultFlag result_flag, + y.T_OrderDetailNat_NormalValueID normal_id, + y.T_OrderDetailNormalValueNote normal_note, y.T_OrderDetailNat_UnitName unit_name, + y.T_OrderdetailNat_MethodeID methode_id, y.T_OrderdetailNat_MethodeName methode_name, + a.T_TestNat_TestID nattest_id, a.T_TestID tx_id, count(T_ResultInstrumentID) as result_instrument_n, + y.T_OrderDetailVerification, T_OrderSampleReceive sample_receive, + T_OrderSampleProcessing sample_processing, T_OrderSampleWorklistReceive sample_worklist_receive, + IF(T_OrderDetailAddOnPreAnalytic = 'Y', T_OrderDetailAddOnPreAnalytic, PreAnalyticIsOk) pre_analytic, + T_OrderDetailAddOnPreAnalytic, + T_OrderHeaderID order_id, y.T_OrderDetailT_TestSasCode test_sas_code, + tx.T_TestSasCode, + T_OrderDetailAddOnResample `resample`, T_OrderDetailAddOnResampleStatus resample_status, + T_OrderDetailAddOnRef ref, y.T_OrderDetailVerification verification, y.T_OrderDetailValidation validation, + T_OrderPromiseDateTime, Group_ResultName as ResultGroupName + FROM t_orderdetail x + left join t_orderpromise on x.T_OrderDetailT_OrderPromiseID = T_OrderPromiseID + JOIN t_test tx ON x.T_OrderDetailT_TestID = T_TestID + JOIN t_test tcheck on tcheck.T_TestNat_TestID in {$q_group} + and ( tx.T_TestID = tcheck.T_TestID or tx.T_TestSasCode like concat(tcheck.T_TestSasCode,'%')) + LEFT JOIN group_resultdetail ON Group_ResultDetailT_TestID = x.T_OrderDetailT_TestID AND Group_ResultDetailIsActive = 'Y' + LEFT JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND Group_ResultFlagNonLab = 'N' + LEFT JOIN t_orderdetail y ON x.T_OrderDetailT_TestSasCode LIKE CONCAT(y.T_OrderDetailT_TestSasCode, '%') + AND x.T_OrderDetailT_OrderHeaderID = y.T_OrderDetailT_OrderHeaderID + AND y.T_OrderDetailIsActive = 'Y' + LEFT JOIN t_orderdetailaddon ON x.T_OrderDetailID = T_OrderDetailAddOnT_OrderDetailID + JOIN t_orderheader ON y.T_OrderDetailT_OrderHeaderID = T_OrderHeaderID + LEFT JOIN t_test a ON y.T_OrderDetailT_TestID = a.T_TestID + AND a.T_TestIsNonLab = '' + LEFT JOIN (SELECT T_OrderSampleT_SampleTypeID, T_OrderSampleReceive, T_OrderSampleProcessing, T_OrderSampleWorklistReceive + FROM t_ordersample WHERE T_OrderSampleT_OrderHeaderID = {$id} + AND T_OrderSampleIsactive = 'Y' + GROUP BY T_OrderSampleT_SampleTypeID) os ON a.T_TestT_SampleTypeID = os.T_OrderSampleT_SampleTypeID + or os.T_OrderSampleT_SampleTypeID = fn_sampletype_from_local(a.T_TestNat_TestID) + + LEFT JOIN t_resultinstrument ON T_ResultInstrumentT_OrderDetailID = x.T_OrderDetailID + LEFT JOIN pre_analytic ON PreAnalyticNat_TestID = a.T_TestNat_TestID AND PreAnalyticDate = date(now()) and PreAnalyticIsActive = 'Y' + WHERE x.T_OrderDetailT_OrderHeaderID = {$id} + AND x.T_OrderDetailIsActive = 'Y' + GROUP BY y.T_OrderDetailT_TestID + ORDER BY y.T_OrderDetailT_TestSasCode ASC + ) a1 + + LEFT JOIN t_orderdetail a2 ON a2.T_OrderDetailT_OrderHeaderID = a1.order_id + AND a2.T_OrderDetailIsActive = 'Y' + AND a1.test_sas_code LIKE CONCAT(a2.T_OrderDetailT_testSasCode, '%') + GROUP BY a1.t_testid + order by a1.test_sas_code +"; + $query = $this->db_smartone->query($sql); + $lq = $this->db_smartone->last_query(); + } else { + $sql = " + SELECT a1.*, cOUNT(a2.T_OrderDetailID) level + FROM ( + SELECT IFNULL(y.T_OrderDetailT_TestID, x.T_OrderDetailT_TestID) t_testid, + IFNULL(y.T_OrderDetailT_TestName, y.T_OrderDetailT_TestName) t_testname, + y.T_OrderDetailResult result, y.T_OrderDetailResult result_old, y.T_OrderDetailNote note, y.T_OrderDetailNote note_old, + y.T_OrderDetailID id, + y.T_OrderDetailT_TestIsResult is_result, a.T_TestIsQuantitative is_quantitative, + y.T_OrderDetailResultFlag result_flag, + y.T_OrderDetailNat_NormalValueID normal_id, + y.T_OrderDetailNormalValueNote normal_note, y.T_OrderDetailNat_UnitName unit_name, + y.T_OrderdetailNat_MethodeID methode_id, y.T_OrderdetailNat_MethodeName methode_name, + a.T_TestNat_TestID nattest_id, a.T_TestID tx_id, count(T_ResultInstrumentID) as result_instrument_n, + y.T_OrderDetailVerification, T_OrderSampleReceive sample_receive, + T_OrderSampleProcessing sample_processing, T_OrderSampleWorklistReceive sample_worklist_receive, + IF(T_OrderDetailAddOnPreAnalytic = 'Y', T_OrderDetailAddOnPreAnalytic, PreAnalyticIsOk) pre_analytic, + T_OrderDetailAddOnPreAnalytic, + T_OrderHeaderID order_id, y.T_OrderDetailT_TestSasCode test_sas_code, + tx.T_TestSasCode, + T_OrderDetailAddOnResample `resample`, T_OrderDetailAddOnResampleStatus resample_status, + T_OrderDetailAddOnRef ref, y.T_OrderDetailVerification verification, y.T_OrderDetailValidation validation, + T_OrderPromiseDateTime , Group_ResultName as ResultGroupName + FROM t_orderdetail x + left join t_orderpromise on x.T_OrderDetailT_OrderPromiseID = T_OrderPromiseID + JOIN t_test tx ON x.T_OrderDetailT_TestID = T_TestID + LEFT JOIN group_resultdetail ON Group_ResultDetailT_TestID = x.T_OrderDetailT_TestID AND Group_ResultDetailIsActive = 'Y' + LEFT JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND Group_ResultFlagNonLab = 'N' + LEFT JOIN t_orderdetail y ON x.T_OrderDetailT_TestSasCode LIKE CONCAT(y.T_OrderDetailT_TestSasCode, '%') + AND x.T_OrderDetailT_OrderHeaderID = y.T_OrderDetailT_OrderHeaderID + AND y.T_OrderDetailIsActive = 'Y' + + LEFT JOIN t_orderdetailaddon ON x.T_OrderDetailID = T_OrderDetailAddOnT_OrderDetailID + + JOIN t_orderheader ON y.T_OrderDetailT_OrderHeaderID = T_OrderHeaderID + LEFT JOIN t_test a ON y.T_OrderDetailT_TestID = a.T_TestID + AND a.T_TestIsNonLab = '' + LEFT JOIN (SELECT T_OrderSampleT_SampleTypeID, T_OrderSampleReceive, T_OrderSampleProcessing, T_OrderSampleWorklistReceive + FROM t_ordersample WHERE T_OrderSampleT_OrderHeaderID = {$id} + AND T_OrderSampleIsactive = 'Y' + GROUP BY T_OrderSampleT_SampleTypeID) os ON a.T_TestT_SampleTypeID = os.T_OrderSampleT_SampleTypeID + or os.T_OrderSampleT_SampleTypeID = fn_sampletype_from_local(a.T_TestNat_TestID) + + LEFT JOIN t_resultinstrument ON T_ResultInstrumentT_OrderDetailID = x.T_OrderDetailID + LEFT JOIN pre_analytic ON PreAnalyticNat_TestID = a.T_TestNat_TestID AND PreAnalyticDate = date(now()) and PreAnalyticIsActive = 'Y' + WHERE x.T_OrderDetailT_OrderHeaderID = {$id} + AND x.T_OrderDetailIsActive = 'Y' + GROUP BY y.T_OrderDetailT_TestID + ORDER BY y.T_OrderDetailT_TestSasCode ASC + ) a1 + + LEFT JOIN t_orderdetail a2 ON a2.T_OrderDetailT_OrderHeaderID = a1.order_id + AND a2.T_OrderDetailIsActive = 'Y' + AND a1.test_sas_code LIKE CONCAT(a2.T_OrderDetailT_testSasCode, '%') + GROUP BY a1.t_testid + order by a1.test_sas_code +"; + //echo $sql; + $query = $this->db_smartone->query($sql); + $lq = $this->db_smartone->last_query(); + } + // file_put_contents("/xtmp/re-query.sql",$lq); + + if ($query) { + $rst = []; + $rows = $query->result_array(); + + foreach ($rows as $k => $v) { + + if ($v['is_result'] == "Y" && $v['is_quantitative'] == "N") { + $v['template'] = []; + $x = $this->db_smartone->query("CALL sp_master_resulttemplate_get('{$v['t_testid']}')"); + $this->clean_mysqli_connection($this->db_smartone->conn_id); + if ($x) + $v['template'] = $x->result_array(); + } + + // IF Rujukan, by pas Pre Analytik + if ($v['ref'] == 'Y') + $v['pre_analytic'] = 'Y'; + if ($v["id"] == "885455") { + //sipe workaround + //$v["sample_receive"] = "Y"; + $v["sample_worklist_receive"] = "Y"; + } + $rst[] = $v; + } + + $result = array("total" => $tot_count, "records" => $rst, "total_display" => sizeof($rows), "q" => $lq); + $this->sys_ok($result); + } else { + $this->sys_error_db("RE Px rows", $this->db_smartone); + exit; + } + } + + public function save() + { + $prm = $this->sys_input; + $data = json_decode($prm["data"]); + $lang = $this->lang_default_code; + $lang_id = isset($prm['lang_id']) ? $prm['lang_id'] : '0'; + + if ($lang_id != 0) { + $l = $this->db_smartone->where("Nat_LangID", $lang_id)->get("nat_lang")->row(); + $lang = $l->Nat_LangCode; + } + + $sql_norm = "select T_OrderDetailMinValue, T_OrderDetailMaxValue, + T_OrderDetailMinValueInclusive, T_OrderDetailMaxValueInclusive, + Nat_TestFlagLow, Nat_TestFlagHigh + from t_orderdetail + join t_test on T_OrderDetailT_TestID = T_TestID + join nat_test on T_TestNat_TestID = Nat_TestID and T_TestIsActive = 'Y' + where T_OrderDetailID = ? "; + + $ids = []; + foreach ($data as $k => $v) { + if ($v->resultInstrumentID > 0) { + $sql_i = "select T_ResultInstrumentNat_NormalValueID normalValueID + from t_resultinstrument + where T_ResultInstrumentID = ?"; + $qry_i = $this->db_smartone->query($sql_i, array($v->resultInstrumentID)); + if ($qry_i) { + $rows_i = $qry_i->result_array(); + + if (count($rows_i) > 0) { + $sql_iu = "update t_orderdetail, nat_normalvalue , nat_methode + set T_OrderDetailMinValue = Nat_NormalValueMinValue, + T_OrderDetailMinValueInclusive = Nat_NormalValueMinValueInclusive, + T_OrderDetailMaxValue = Nat_NormalValueMaxValue , + T_OrderDetailMaxValueInclusive = Nat_NormalValueMaxValueInclusive, + T_OrderDetailNormalValueNote = Nat_NormalValueNote, + T_OrderDetailNormalValueDescription = Nat_NormalValueDescription, + T_OrderDetailNat_NormalValueID = Nat_NormalValueID, + T_OrderDetailNat_MethodeID = Nat_NormalValueNat_MethodeID, + T_OrderDetailNat_MethodeName = Nat_MethodeName + where T_OrderDetailID = ? and Nat_NormalValueID = ? + and Nat_NormalValueNat_MethodeID = Nat_MethodeID + "; + $this->db_smartone->query($sql_iu, array($v->id, $rows_i[0]["normalValueID"])); + //file_put_contents("/xtmp/update-nilai-normal", $this->db_smartone->last_query() . "\n", FILE_APPEND); + } + } + } + $y = $this->db_smartone->query("SELECT fn_process_sample_handling_perfect('{$v->order_id}', '{$v->test_id}') c") + ->row(); + $req_status = $y->c; + $qry_norm = $this->db_smartone->query($sql_norm, $v->id); + $result_flag = ""; + if ($qry_norm) { + $rows_norm = $qry_norm->result_array(); + if (count($rows_norm) > 0) { + $r = $rows_norm[0]; + if (is_numeric($v->result)) { + + if ($r["T_OrderDetailMinValueInclusive"] == "Y" && $v->result < $r["T_OrderDetailMinValue"]) { + $result_flag = $r["Nat_TestFlagLow"]; + } + if ($r["T_OrderDetailMinValueInclusive"] == "N" && $v->result <= $r["T_OrderDetailMinValue"]) { + $result_flag = $r["Nat_TestFlagLow"]; + } + if ($r["T_OrderDetailMaxValueInclusive"] == "Y" && $v->result > $r["T_OrderDetailMaxValue"]) { + $result_flag = $r["Nat_TestFlagHigh"]; + } + if ($r["T_OrderDetailMaxValueInclusive"] == "N" && $v->result >= $r["T_OrderDetailMaxValue"]) { + $result_flag = $r["Nat_TestFlagHigh"]; + } + } + } + } + if ($lang == $this->lang_default_code) { + $this->db_smartone->set('T_OrderDetailResult', $v->result) + ->set('T_OrderDetailResultFlag', $result_flag) + ->set('T_OrderDetailNote', $v->note) + ->set('T_OrderDetailReqStatus', $req_status) + ->where('T_OrderDetailID', $v->id) + ->update('t_orderdetail'); + } else { + $this->db_smartone->set('T_OrderDetailLangResult', $v->result) + ->set('T_OrderDetailLangNote', $v->note) + ->where('T_OrderDetailLangID', $v->id) + ->update('t_orderdetaillang'); + } + + $ids[] = $v->id; + } + + // LOG Process + $order = $this->db_smartone->select('T_OrderDetailT_OrderHeaderID id, T_OrderHeaderLabNumber lab_number', false) + ->join('t_orderheader', 'T_OrderHeaderID = T_OrderDetailT_OrderHeaderID') + ->where('T_OrderDetailID', $data[0]->id) + ->get('t_orderdetail') + ->row(); + + $dblog = $this->load->database("onelog", true); + $dblog->set('Log_ProcessCode', 'PROCESS.Result.Entry') + ->set('Log_ProcessOrderID', $order->id) + ->set('Log_ProcessOrderNumber', $order->lab_number) + ->set('Log_ProcessJson', json_encode($data)) + ->set('Log_ProcessUserID', $this->sys_user['M_UserID']) + ->insert('log_process'); + // END OF Log Process + //auto calculation + $this->load->library("Resultcalc"); + $rows = $this->resultcalc->auto($order->id); + + try { + foreach ($ids as $id) { + $this->db_smartone->query("call sp_set_normal_value_flag($id)"); + $this->clean_mysqli_connection($this->db_smartone->conn_id); + } + } catch (Exception $e) { + } + + $this->sys_ok($ids); + } + + public function save_template() + { + $prm = $this->sys_input; + + $n = $this->db_smartone->select("COUNT(T_ResultTemplateID) n") + ->where("T_ResultTemplateT_TestID", $prm['test_id']) + ->where("T_ResultTemplateIsActive", "Y") + ->where("T_ResultTemplateValue", $prm['value']) + ->get('t_resulttemplate') + ->row(); + if ($n->n > 0) { + $this->sys_error_db("Insert Result Template", $this->db_smartone); + return; + } + + $r = $this->db_smartone->set("T_ResultTemplateT_TestID", $prm['test_id']) + ->set("T_ResultTemplateValue", $prm['value']) + ->insert('t_resulttemplate'); + if ($r) { + $template = []; + $x = $this->db_smartone->query("CALL sp_master_resulttemplate_get('{$prm['test_id']}')"); + $this->clean_mysqli_connection($this->db_smartone->conn_id); + if ($x) + $template = $x->result_array(); + + $this->sys_ok($template); + } + } + + public function export() + { + $prm = $this->sys_input; + + $sql = "CALL sp_process_result_lang(?, ?, ?, ?)"; + $query = $this->db_smartone->query($sql, [$prm['order_id'], $prm['lang_id'], $prm['is_si'], $this->sys_user['M_UserID']]); + if ($query) { + $r = $query->row(); + if ($r->status == "OK") { + $this->sys_ok($r->data); + return; + } + + $this->sys_error_db("Message : " . $r->message, $this->db_smartone); + } else { + $this->sys_error_db("Lang Result", $this->db_smartone); + return; + } + } + + public function search_group() + { + $prm = $this->sys_input; + $max_rst = 100; + + // QUERY TOTAL + $sql = "select count(*) total + from t_worklist + where T_WorklistIsActive = 'Y' + order by T_WorklistName ASC"; + $query = $this->db_smartone->query($sql); + + if ($query) { + $tot_count = $query->result_array()[0]["total"]; + } else { + $this->sys_error_db("worklist count", $this->db_smartone); + exit; + } + + $sql = "select T_WorklistID group_id, T_WorklistName group_name + from t_worklist + where T_WorklistIsActive = 'Y' + order by T_WorklistName ASC + limit 0, {$max_rst}"; + $query = $this->db_smartone->query($sql); + + if ($query) { + $rows = $query->result_array(); + foreach ($rows as $k => $v) + $rows[$k]['data'] = json_decode($v['data']); + $result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows), "q" => $this->db_smartone->last_query()); + $this->sys_ok($result); + } else { + $this->sys_error_db("worklist rows", $this->db_smartone); + exit; + } + } + + public function search_rerun() + { + $prm = $this->sys_input; + $id = $prm["detail_id"]; + + $sql = "CALL sp_process_result_rerun(?)"; + $query = $this->db_smartone->query($sql, [$id]); + + if ($query) { + $rows = $query->result_array(); + $this->sys_ok(["records" => $rows]); + } else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + + + function getdoctorsfna() + { + $prm = $this->sys_input; + // $id = $prm["id"]; + + $sql = " SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY M_DoctorName ASC"; + //echo $sql; + $query = $this->db_smartone->query($sql); + + if ($query) { + $rows = $query->result_array(); + $this->sys_ok(["records" => $rows]); + } else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + function getfnaresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT Other_FNADetailsID as xid, + Other_FNAT_OrderDetailID as orderdetail_id, + Other_FNADetailsCode as code, + Other_FNADetailsLabel as label, + Other_FNADetailsResult as result, + IFNULL(Other_FNAM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_FNAM_DoctorID) OR Other_FNAM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_fna + JOIN other_fnadetails ON Other_FNADetailsOther_FNAID = Other_FNAID AND Other_FNADetailsIsActive = 'Y' + LEFT JOIN m_doctor ON Other_FNAM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_FNAT_OrderDetailID = {$id} AND Other_FNAIsActive = 'Y' + GROUP BY Other_FNADetailsID + ORDER BY Other_FNADetailsCode ASC"; + $query = $this->db_smartone->query($sql); + + if ($query) { + $rows = $query->result_array(); + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $images = array(); + $sql = "SELECT So_ImageUploadID as xid, + CONCAT('/one-media/one-image-nonlab/',So_ImageUploadNewName) as image_url + FROM t_orderdetail + JOIN so_imageupload ON So_ImageUploadT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND + So_ImageUploadIsActive = 'Y' + WHERE + T_OrderDetailID = {$id} AND + T_OrderDetailIsActive = 'Y' + GROUP BY So_ImageUploadID"; + $images = $this->db_smartone->query($sql)->result_array(); + + $rst = array('doctors' => $doctors, 'results' => $rows, 'images' => $images); + $this->sys_ok(["records" => $rst]); + } else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + + function uploadimage() + { + if (! $this->isLogin) { + $this->sys_error("Invalid Token"); + exit; + } + + $userid = $this->sys_user["M_UserID"]; + $data = []; + //print_r($_SERVER); + + $prm = $this->sys_input; + $orderid = $this->input->post('orderid'); + $labnumber = $this->input->post('labnumber'); + $sql = "UPDATE so_imageupload SET + So_ImageUploadIsActive = 'N', + So_ImageUploadUserID = {$userid} + WHERE + So_ImageUploadT_OrderHeaderID = {$orderid}"; + //echo $sql; + $this->db_onedev->query($sql); + //$config['upload_path'] = 'assets/'; + + $path = '/home/one/project/one/one-media/one-image-nonlab/'; + //echo $path; + $config['upload_path'] = $path; + $config['allowed_types'] = 'jpg|jpeg|png|gif'; + + $config['max_size'] = '10000'; + $count = count($_FILES['files']['name']); + //echo $count; + $this->load->library('upload', $config); + + $error = []; + for ($i = 0; $i < $count; $i++) { + + + if (!empty($_FILES['files']['name'][$i])) { + + + + $_FILES['file']['name'] = $_FILES['files']['name'][$i]; + + $_FILES['file']['type'] = $_FILES['files']['type'][$i]; + + $_FILES['file']['tmp_name'] = $_FILES['files']['tmp_name'][$i]; + + $_FILES['file']['error'] = $_FILES['files']['error'][$i]; + + $_FILES['file']['size'] = $_FILES['files']['size'][$i]; + + + + $namex = $orderid . '-' . $labnumber . '-' . $this->generateRandomString(5); + //echo $namex; + + $config['file_name'] = $namex; + $this->upload->initialize($config); + //echo $config['file_name'] ; + + + + + + if ($this->upload->do_upload('file')) { + + $uploadData = $this->upload->data(); + + $filename = $uploadData['file_name']; + //echo $filename; + + + $sql = "INSERT INTO so_imageupload ( + So_ImageUploadT_OrderHeaderID, + So_ImageUploadT_OrderHeaderLabNumber, + So_ImageUploadT_SampleTypeID, + So_ImageUploadOldName, + So_ImageUploadNewName, + So_ImageUploadCreated, + So_ImageUploadUserID + ) + VALUES( + {$orderid}, + '{$labnumber}', + '150', + '{$_FILES['files']['name'][$i]}', + '{$filename}', + NOW(), + {$userid} + + )"; + //echo $sql; + $this->db_onedev->query($sql); + $xlast_id = $this->db_onedev->insert_id(); + $data['totalFiles'][] = array('xid' => $xlast_id, 'image_url' => '/one-media/one-image-nonlab/' . $filename); + } else { + $error = array('error' => $this->upload->display_errors()); + } + } + } + + $result = array("total" => count($data['totalFiles']), "records" => $data['totalFiles'], 'errors' => $error); + $this->sys_ok($result); + } + + + function getpatologianatomyresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT Other_PatologiAnatomyID as xid, + Other_PatologiAnatomyT_OrderDetailID as orderdetail_id, + Other_PatologiAnatomyNoSediaan as no_sediaan, + Other_PatologiAnatomyDiagnosaKlinis as diagnosa, + Other_PatologiAnatomyKeteranganKlinis as klinis, + Other_PatologiAnatomyLokasiOrgan as lokasi, + Other_PatologiAnatomyMakroskopik as makroskopik, + Other_PatologiAnatomyMikroskopik as mikroskopik, + Other_PatologiAnatomyKesimpulan as kesimpulan, + IFNULL(Other_PatologiAnatomyM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_PatologiAnatomyM_DoctorID) OR Other_PatologiAnatomyM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_patologi_anatomy + LEFT JOIN m_doctor ON Other_PatologiAnatomyM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_PatologiAnatomyT_OrderDetailID = {$id} AND Other_PatologiAnatomyIsActive = 'Y' + GROUP BY Other_PatologiAnatomyID + ORDER BY Other_PatologiAnatomyID ASC + LIMIT 1"; + $query = $this->db_smartone->query($sql); + + if ($query) { + $rows = $query->row_array(); + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + + $sql = "SELECT So_ImageUploadPatologyAnatomyID as xid, + CONCAT('/one-media/one-image-nonlab/',So_ImageUploadPatologyAnatomyNewName) as image_url, + So_ImageUploadPatologyAnatomyType as type + FROM t_orderdetail + JOIN so_imageupload_patology_anatomy ON So_ImageUploadPatologyAnatomyT_OrderHeaderID= T_OrderDetailT_OrderHeaderID AND + So_ImageUploadPatologyAnatomyIsActive= 'Y' + WHERE + T_OrderDetailID = {$id} AND + T_OrderDetailIsActive = 'Y' + GROUP BY So_ImageUploadPatologyAnatomyID"; + $images = $this->db_smartone->query($sql)->result_array(); + $mikro = []; + $makro = []; + + foreach ($images as $key => $value) { + + if ($value['type'] == 'mikro') { + $mikro[] = $value; + } + if ($value['type'] == 'makro') { + $makro[] = $value; + } + } + + $rst = array('doctors' => $doctors, 'result' => $rows, 'mikro' => $mikro, 'makro' => $makro); + $this->sys_ok(["records" => $rst]); + } else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + + + function generateRandomString($length = 10) + { + $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; + $charactersLength = strlen($characters); + $randomString = ''; + for ($i = 0; $i < $length; $i++) { + $randomString .= $characters[rand(0, $charactersLength - 1)]; + } + return $randomString; + } + + function getcytologiresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT Other_CytologiDetailsID as xid, + Other_CytologiT_OrderDetailID as orderdetail_id, + Other_CytologiDetailsCode as code, + Other_CytologiDetailsLabel as label, + Other_CytologiDetailsResult as result, + IFNULL(Other_CytologiM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_CytologiM_DoctorID) OR Other_CytologiM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_cytologi + JOIN other_cytologidetails ON Other_CytologiDetailsOther_CytologiID = Other_CytologiID AND Other_CytologiDetailsIsActive = 'Y' + LEFT JOIN m_doctor ON Other_CytologiM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_CytologiT_OrderDetailID = {$id} AND Other_CytologiIsActive = 'Y' + GROUP BY Other_CytologiDetailsID + ORDER BY Other_CytologiDetailsCode ASC"; + //echo $sql; + $query = $this->db_smartone->query($sql); + + if ($query) { + $rows = $query->result_array(); + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $rst = array('doctors' => $doctors, 'results' => $rows); + $this->sys_ok(["records" => $rst]); + } else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + function getmikroresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT + Other_MikroID as xid, + Other_MikroHasilBiakan as hasil_biakan, + Other_MikroSampleTypeName as sample_name, + Other_MikroT_OrderDetailID as orderdetail_id, + Other_MikroResult as result_value, + '' as result_other, + IFNULL(T_BacteriaID,0) as T_BacteriaID, + IFNULL(T_BacteriaName,'') as T_BacteriaName, + '' as details, + IFNULL(Other_MikroM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_MikroM_DoctorID) OR Other_MikroM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_mikro + LEFT JOIN t_bacteria ON Other_MikroT_BacteriaID = T_BacteriaID + LEFT JOIN m_doctor ON Other_MikroM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_MikroT_OrderDetailID = {$id} AND Other_MikroIsActive = 'Y' + GROUP BY Other_MikroID"; + //echo $sql; + $query = $this->db_smartone->query($sql); + + if ($query) { + $row = $query->row_array(); + if ($row) { + if ($row['result_value'] != 'Positif' && $row['result_value'] != 'Negatif') { + $row['result_other'] = $row['result_value']; + $row['result_value'] = 'other'; + } + $sql = "SELECT '' as xno, + Other_MikroDetailsID as xid, + Other_MikroDetailsValue as value, + IF(Other_MikroDetailsNote = 'R','Y','N') as chx_r, + IF(Other_MikroDetailsNote = 'I','Y','N') as chx_i, + IF(Other_MikroDetailsNote = 'S','Y','N') as chx_s, + Other_MikroDetailsNote as note, + t_antibiotic.* + FROM other_mikrodetails + LEFT JOIN t_antibiotic ON Other_MikroDetailsT_AntibioticID = T_AntibioticID + WHERE + Other_MikroDetailsOther_MikroID = {$row['xid']} AND Other_MikroDetailsIsActive = 'Y' + GROUP BY Other_MikroDetailsID + ORDER BY T_AntibioticName ASC"; + //echo $sql; + $details = $this->db_smartone->query($sql)->result_array(); + if (details) { + foreach ($details as $k => $v) { + $details[$k]['xno'] = $k + 1; + } + } + $row['details'] = $details; + } else { + $row = array('xid' => '0', 'hasil_biakan' => '', 'result_value' => 'Negatif', 'sample_name' => '', 'orderdetail_id' => $id, 'T_BacteriaID' => '0', 'T_BacteriaName' => '0', 'details' => array(), 'doctor_id' => '0', 'doctor_name' => '0'); + } + } else { + $row = array('xid' => '0', 'hasil_biakan' => '', 'result_value' => 'Negatif', 'sample_name' => '', 'orderdetail_id' => $id, 'T_BacteriaID' => '0', 'T_BacteriaName' => '0', 'details' => array(), 'doctor_id' => '0', 'doctor_name' => '0'); + } + //print_r($row); + + + + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 7 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $sql = " + SELECT '0' as id, 'Belum memilih bakteria' as name + UNION + SELECT T_BacteriaID as id, T_BacteriaName as name + FROM t_bacteria + WHERE + T_BacteriaIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $bacteries = $this->db_smartone->query($sql)->result_array(); + $rst = array('doctors' => $doctors, 'bacteries' => $bacteries, 'results' => $row); + $this->sys_ok(["records" => $rst]); + } + function getantibiotics() + { + $prm = $this->sys_input; + $id = $prm["id"]; + $sql = " SELECT '' as xno, + 0 as xid, + '' as hasil_biakan, + '' as sample_name, + 0 as value, + 'Y' as chx_r, + 'N' as chx_i, + 'N' as chx_s, + 'R' as note, + t_antibiotic.* + FROM t_antibiotic + WHERE + T_AntibioticT_BacteriaID = {$prm['id']} AND T_AntibioticIsActive= 'Y' + ORDER BY T_AntibioticName ASC"; + //echo $sql; + $rows = $this->db_smartone->query($sql)->result_array(); + if (rows) { + foreach ($rows as $k => $v) { + $rows[$k]['xno'] = $k + 1; + } + } + + $this->sys_ok(["records" => $rows]); + } + function getlcprepresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + $sql = " SELECT Other_LcprepDetailsID as xid, + Other_LcprepID as header_id, + Other_LcprepT_orderDetailID as orderdetail_id, + Other_LcprepDetailsCode as code, + Other_LcprepDetailsLabel as label, + Other_LcprepDetailsResult as result, + IFNULL(Other_LcprepM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_LcprepM_DoctorID) OR Other_LcprepM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_lcprep + JOIN other_lcprepdetails ON Other_LcprepDetailsOther_LcprepID = Other_LcprepID AND Other_LcprepDetailsIsActive = 'Y' + LEFT JOIN m_doctor ON Other_LcprepM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_LcprepT_orderDetailID = {$id} AND Other_LcprepIsActive = 'Y' + GROUP BY Other_LcprepDetailsOther_LcprepID, Other_LcprepDetailsCode + ORDER BY Other_LcprepDetailsCode ASC"; + //echo $sql; + $rows = $this->db_smartone->query($sql)->result_array(); + if (!$rows) { + $rows = array( + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'A', + 'label' => 'DESKRIPSI', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ), + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'B', + 'label' => 'KESIMPULAN', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ) + ); + } + + $header_id = $rows[0]['header_id']; + $sql = "SELECT IFNULL(Other_LcprepAdekuasiID,0) as xid, + Lcprep_AdekuasiID as id, + Lcprep_AdekuasiLabel as name, + IF(ISNULL(Other_LcprepAdekuasiID),'N',Other_LcprepAdekuasiChex) as chex + FROM lcprep_adekuasi + LEFT JOIN other_lcprepadekuasi ON Other_LcprepAdekuasiLcprep_AdekuasiID = Lcprep_AdekuasiID AND + Other_LcprepAdekuasiOther_LcprepID = {$header_id} AND + Other_LcprepAdekuasiIsActive = 'Y' + WHERE + Lcprep_AdekuasiIsActive = 'Y' + GROUP BY Lcprep_AdekuasiID + ORDER BY Lcprep_AdekuasiOrder ASC + "; + //echo $sql; + $adeakuasi = $this->db_smartone->query($sql)->result_array(); + foreach ($adeakuasi as $kc => $vc) { + $adeakuasi[$kc]['chex'] = $vc['chex'] == 'N' ? false : true; + } + + $sql = "SELECT IFNULL(Other_LcprepKategoriUmumID,0) as xid, + Lcprep_KategoriUmumID as id, + Lcprep_KategoriUmumLabel as name, + IF(ISNULL(Other_LcprepKategoriUmumID),'N',Other_LcprepKategoriUmumChex) as chex + FROM lcprep_kategoriumum + LEFT JOIN other_lcprepkategoriumum ON Other_LcprepKategoriUmumLcprep_KategoriUmumID = Lcprep_KategoriUmumID AND + Other_LcprepKategoriUmumOther_LcprepID = {$header_id} AND + Other_LcprepKategoriUmumIsActive = 'Y' + WHERE + Lcprep_KategoriUmumIsActive = 'Y' + GROUP BY Lcprep_KategoriUmumID + "; + //echo $sql; + $kategoriumum = $this->db_smartone->query($sql)->result_array(); + foreach ($kategoriumum as $kc => $vc) { + $kategoriumum[$kc]['chex'] = $vc['chex'] == 'N' ? false : true; + } + + $sql = " + SELECT Lcprep_InterpretasiGroupID as group_id, + Lcprep_InterpretasiGroupName as group_name, + '' as subgroups + FROM lcprep_interpretasigroup + WHERE + Lcprep_InterpretasiGroupIsActive = 'Y' + "; + //echo $sql; + $interpretasi = $this->db_smartone->query($sql)->result_array(); + foreach ($interpretasi as $k => $v) { + $subgroups = array(); + $sql = "SELECT Lcprep_InterpretasiSubgroupID as subgroup_id, + Lcprep_InterpretasiSubgroupName as subgroup_name, + '' as childs + FROM lcprep_interpretasisubgroup + WHERE + Lcprep_InterpretasiSubgroupLcprep_InterpretasiGroupID = {$v['group_id']} AND Lcprep_InterpretasiSubgroupIsActive = 'Y'"; + //echo $sql; + $subgroups = $this->db_smartone->query($sql)->result_array(); + if (count($subgroups) > 0) { + foreach ($subgroups as $ki => $vi) { + $childs = array(); + $sql = "SELECT IFNULL(Other_LcprepInterpretasiID,0) as xid, + IFNULL(Other_LcprepInterpretasiChex,'N') as chex, + IFNULL(Other_LcprepInterpretasiValue,'') as value, + Lcprep_InterpretasiID as id, + Lcprep_InterpretasiLcprep_InterpretasiSubgroupID as subgroup_id, + Lcprep_InterpretasiCode as code, + Lcprep_InterpretasiName as name, + Lcprep_InterpretasiParentID as parent_id, + Lcprep_InterpretasiIsParent as is_parent, + Lcprep_InterpretasiHasResult as has_result, + Lcprep_InterpretasiTypeResult as type_result + FROM lcprep_interpretasi + LEFT JOIN other_lcprepinterpretasi ON Other_LcprepInterpretasiOther_LcprepID = {$header_id} AND + Other_LcprepInterpretasiLcprep_InterpretasiID = Lcprep_InterpretasiID AND + Other_LcprepInterpretasiIsActive = 'Y' + WHERE + Lcprep_InterpretasiLcprep_InterpretasiSubgroupID = {$vi['subgroup_id']} AND Lcprep_InterpretasiIsActive = 'Y' + GROUP BY Lcprep_InterpretasiID Order BY Lcprep_InterpretasiCode ASC"; + $childs = $this->db_smartone->query($sql)->result_array(); + if ($childs) { + foreach ($childs as $kc => $vc) { + $childs[$kc]['chex'] = $vc['chex'] == 'N' ? false : true; + } + } + $subgroups[$ki]['childs'] = $childs; + } + } + + $interpretasi[$k]['subgroups'] = $subgroups; + } + + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $rst = array('doctors' => $doctors, 'results' => $rows, 'adekuasi' => $adeakuasi, 'kategoriumum' => $kategoriumum, 'interpretasi' => $interpretasi); + $this->sys_ok(["records" => $rst]); + } + + function getpapsmearresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT Other_PapSmearDetailsID as xid, + Other_PapSmearID as header_id, + Other_PapSmearT_OrderDetailID as orderdetail_id, + Other_PapSmearDetailsCode as code, + Other_PapSmearDetailsLabel as label, + Other_PapSmearDetailsResult as result, + IFNULL(Other_PapSmearM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_PapSmearM_DoctorID) OR Other_PapSmearM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_papsmear + JOIN other_papsmeardetails ON Other_PapSmearDetailsOther_PapSmearID = Other_PapSmearID AND Other_PapSmearDetailsIsActive = 'Y' + LEFT JOIN m_doctor ON Other_PapSmearM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_PapSmearT_OrderDetailID = {$id} AND Other_PapSmearIsActive = 'Y' + GROUP BY Other_PapSmearDetailsID + ORDER BY Other_PapSmearDetailsCode ASC"; + //echo $sql; + $rows = $this->db_smartone->query($sql)->result_array(); + if (!$rows) { + $rows = array( + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'A', + 'label' => 'Makroskopik', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ), + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'B', + 'label' => 'Mikroskopik', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ), + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'C', + 'label' => 'Kesimpulan', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ) + ); + } + + $header_id = $rows[0]['header_id']; + $sql = "SELECT Other_PapSmearMaturasiID as xid, + Other_PapSmearMaturasiValue as value + FROM other_papsmearmaturasi + WHERE + Other_PapSmearMaturasiOther_PapSmearID = {$header_id} AND + Other_PapSmearMaturasiIsActive = 'Y' + "; + //echo $sql; + $dt_maturasi = $this->db_smartone->query($sql)->row_array(); + if (!$dt_maturasi) { + $maturasi = array('xid' => '0', 'value' => array('', '', '')); + } else { + $value = explode('/', $dt_maturasi['value']); + $maturasi = array('xid' => $dt_maturasi['xid'], 'value' => $value); + } + + $sql = "SELECT IFNULL(Other_PapSmearBahanID,0) as xid, + M_PapSmearBahanID as bahan_id, + M_PapSmearBahanName as name, + IF(ISNULL(Other_PapSmearBahanID),'N','Y') as selected + FROM m_papsmearbahan + LEFT JOIN other_papsmearbahan ON Other_PapSmearBahanM_PapSmearBahanID = M_PapSmearBahanID AND + Other_PapSmearBahanOther_PapSmearID = {$header_id} AND + Other_PapSmearBahanIsActive = 'Y' + WHERE + M_PapSmearBahanIsActive = 'Y' + ORDER BY M_PapSmearBahanID ASC + "; + //echo $sql; + $bahans = $this->db_smartone->query($sql)->result_array(); + + $sql = "SELECT IFNULL(Other_PapsmearCategoryID,0) as xid, + M_PapSmearCategoryID as category_id, + M_PapSmearCategoryName as name, + IF(ISNULL(Other_PapsmearCategoryID),'N','Y') as selected + FROM m_papsmearcategory + LEFT JOIN other_papsmearcategory ON Other_PapsmearCategoryM_PapSmearCategoryID = M_PapSmearCategoryID AND + Other_PapsmearCategoryOther_PapSmearID = {$header_id} AND + Other_PapsmearCategoryIsActive = 'Y' + WHERE + M_PapSmearCategoryIsActive = 'Y' + ORDER BY M_PapSmearCategoryID ASC + "; + //echo $sql; + $categories = $this->db_smartone->query($sql)->result_array(); + + $sql = "SELECT IFNULL(Other_PapSmearCheckID,0) as xid, + M_PapSmearCheckID as check_id, + M_PapSmearCheckLabel as name, + IF(ISNULL(Other_PapSmearCheckID),'N','Y') as selected, + Other_PapSmearCheckNote as note + FROM m_papsmearcheck + LEFT JOIN other_papsmearcheck ON Other_PapSmearCheckM_PapSmearCheckID = M_PapSmearCheckID AND + Other_PapSmearCheckOther_PapSmearID = {$header_id} AND + Other_PapSmearCheckIsActive = 'Y' + WHERE + M_PapSmearCheckIsActive = 'Y' + ORDER BY M_PapSmearCheckCode ASC + "; + $checks = $this->db_smartone->query($sql)->result_array(); + + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $rst = array('doctors' => $doctors, 'checks' => $checks, 'bahans' => $bahans, 'categories' => $categories, 'maturasi' => $maturasi, 'results' => $rows); + $this->sys_ok(["records" => $rst]); + } + + function saveresult_lcprep() + { + $prm = $this->sys_input; + $detail_id = $prm['detail_id']; + $doctor_id = $prm['doctor']; + $adekuasi = $prm['adekuasi']; + $kategoriumum = $prm['kategoriumum']; + $interpretasi = $prm['interpretasi']; + $results = $prm['results']; + + $userid = $this->sys_user['M_UserID']; + + $header_id = 0; + $sql = "SELECT * FROM other_lcprep WHERE Other_LcprepT_orderDetailID = {$detail_id} AND Other_LcprepIsActive = 'Y'"; + $dt_header = $this->db_smartone->query($sql)->row_array(); + if ($dt_header) { + $header_id = $dt_header['Other_LcprepID']; + } + if ($header_id == 0) { + $sql = "INSERT INTO other_lcprep( + Other_LcprepT_orderDetailID, + Other_LcprepM_DoctorID, + Other_LcprepUserID, + Other_LcprepCreated + ) + VALUES( + {$detail_id}, + {$doctor_id}, + {$userid}, + NOW() + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } else { + $sql = "UPDATE other_lcprep SET Other_LcprepM_DoctorID = {$doctor_id}, Other_LcprepUserID = {$userid} WHERE Other_LcprepID = {$header_id}"; + $this->db_smartone->query($sql); + } + + if ($adekuasi) { + foreach ($adekuasi as $k => $v) { + $selected = $v['chex'] ? 'Y' : 'N'; + if (intval($v['xid'] == 0)) { + $sql = "UPDATE other_lcprepadekuasi SET Other_LcprepAdekuasiIsActive = 'N' + WHERE + Other_LcprepAdekuasiOther_LcprepID = {$header_id} AND + Other_LcprepAdekuasiIsActive = 'Y' AND + Other_LcprepAdekuasiLcprep_AdekuasiID = {$v['id']}"; + $this->db_smartone->query($sql); + $sql = "INSERT INTO other_lcprepadekuasi ( + Other_LcprepAdekuasiOther_LcprepID, + Other_LcprepAdekuasiLcprep_AdekuasiID, + Other_LcprepAdekuasiChex, + Other_LcprepAdekuasiUserID, + Other_LcprepAdekuasiCreated + ) + VALUES( + {$header_id}, + {$v['id']}, + '{$selected}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + //echo $sql; + } + if (intval($v['xid'] != 0)) { + + $sql = "UPDATE other_lcprepadekuasi SET + Other_LcprepAdekuasiChex = '{$selected}', + Other_LcprepAdekuasiUserID = {$userid} + WHERE + Other_LcprepAdekuasiID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + + //echo $sql; + } + } + + if ($kategoriumum) { + foreach ($kategoriumum as $k => $v) { + $selected = $v['chex'] ? 'Y' : 'N'; + if (intval($v['xid'] == 0)) { + $sql = "UPDATE other_lcprepkategoriumum SET Other_LcprepKategoriUmumIsActive = 'N' + WHERE + Other_LcprepKategoriUmumOther_LcprepID = {$header_id} AND + Other_LcprepKategoriUmumLcprep_KategoriUmumID = {$v['id']} AND + Other_LcprepKategoriUmumIsActive = 'Y' + "; + $this->db_smartone->query($sql); + $sql = "INSERT INTO other_lcprepkategoriumum ( + Other_LcprepKategoriUmumOther_LcprepID, + Other_LcprepKategoriUmumLcprep_KategoriUmumID, + Other_LcprepKategoriUmumChex, + Other_LcprepKategoriUmumUserID, + Other_LcprepKategoriUmumCreated + ) + VALUES( + {$header_id}, + {$v['id']}, + '{$selected}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if (intval($v['xid'] != 0)) { + $sql = "UPDATE other_lcprepkategoriumum SET + Other_LcprepKategoriUmumChex = '{$selected}', + Other_LcprepKategoriUmumUserID = {$userid} + WHERE + Other_LcprepKategoriUmumID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + + //echo $sql; + } + } + + if ($results) { + foreach ($results as $k => $v) { + if (intval($v['xid'] == 0)) { + $sql = "UPDATE other_lcprepdetails SET Other_LcprepDetailsIsActive = 'N' + WHERE + Other_LcprepDetailsOther_LcprepID = {$header_id} AND + Other_LcprepDetailsCode = '{$v['code']}' AND + Other_LcprepDetailsIsActive = 'Y'"; + $this->db_smartone->query($sql); + $sql = "INSERT INTO other_lcprepdetails ( + Other_LcprepDetailsOther_LcprepID, + Other_LcprepDetailsCode, + Other_LcprepDetailsLabel, + Other_LcprepDetailsResult, + Other_LcprepDetailsUserID, + Other_LcprepDetailsCreated + ) + VALUES( + {$header_id}, + '{$v['code']}', + '{$v['label']}', + '{$v['result']}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if (intval($v['xid'] != 0)) { + $sql = "UPDATE other_lcprepdetails SET + Other_LcprepDetailsCode = '{$v['code']}', + Other_LcprepDetailsLabel = '{$v['label']}', + Other_LcprepDetailsResult = '{$v['result']}', + Other_LcprepDetailsUserID = {$userid} + WHERE + Other_LcprepDetailsID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + //echo $sql; + } + } + + if ($interpretasi) { + foreach ($interpretasi as $k => $v) { + if (count($v['subgroups']) > 0) { + foreach ($v['subgroups'] as $ik => $iv) { + if (count($iv['childs']) > 0) { + foreach ($iv['childs'] as $iik => $iiv) { + if (intval($iiv['xid'] == 0)) { + $chex = $iiv['chex'] ? 'Y' : 'N'; + $sql = "UPDATE other_lcprepinterpretasi SET Other_LcprepInterpretasiIsActive = 'N' + WHERE + Other_LcprepInterpretasiOther_LcprepID = {$header_id} AND + Other_LcprepInterpretasiLcprep_InterpretasiID = '{$iiv['id']}' AND + Other_LcprepInterpretasiIsActive = 'Y'"; + $this->db_smartone->query($sql); + $sql = "INSERT INTO other_lcprepinterpretasi ( + Other_LcprepInterpretasiOther_LcprepID, + Other_LcprepInterpretasiLcprep_InterpretasiID, + Other_LcprepInterpretasiChex, + Other_LcprepInterpretasiValue, + Other_LcprepInterpretasiUserID, + Other_LcprepInterpretasiCreated + ) + VALUES( + {$header_id}, + '{$iiv['id']}', + '{$chex}', + '{$iiv['value']}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + + if (intval($iiv['xid'] != 0)) { + $chex = $iiv['chex'] ? 'Y' : 'N'; + $sql = "UPDATE other_lcprepinterpretasi SET + Other_LcprepInterpretasiChex = '{$chex}', + Other_LcprepInterpretasiValue = '{$iiv['value']}', + Other_LcprepInterpretasiUserID = {$userid} + WHERE + Other_LcprepInterpretasiID = {$iiv['xid']}"; + $this->db_smartone->query($sql); + //echo $sql; + + } + } + } + } + } + //echo $sql; + } + } + + + $result = array("total" => 1, "records" => array(), "sql" => ''); + $this->sys_ok($result); + exit; + } + + function saveresult_papsmear() + { + $prm = $this->sys_input; + $detail_id = $prm['detail_id']; + $doctor_id = $prm['doctor']; + $checks = $prm['checks']; + $maturasi = $prm['maturasi']; + $bahans = $prm['bahans']; + $categories = $prm['categories']; + $results = $prm['results']; + + $userid = $this->sys_user['M_UserID']; + + $header_id = 0; + $sql = "SELECT * FROM other_papsmear WHERE Other_PapSmearT_OrderDetailID = {$detail_id} AND Other_PapSmearIsActive = 'Y'"; + $dt_header = $this->db_smartone->query($sql)->row_array(); + if ($dt_header) { + $header_id = $dt_header['Other_PapSmearID']; + } + if ($header_id == 0) { + $sql = "INSERT INTO other_papsmear( + Other_PapSmearT_OrderDetailID, + Other_PapSmearM_DoctorID, + Other_PapSmearUserID, + Other_PapSmearCreated + ) + VALUES( + {$detail_id}, + {$doctor_id}, + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } else { + $sql = "UPDATE other_papsmear SET Other_PapSmearM_DoctorID = {$doctor_id}, Other_PapSmearUserID = {$userid} WHERE Other_PapSmearID = {$header_id}"; + $this->db_smartone->query($sql); + } + + if ($checks) { + foreach ($checks as $k => $v) { + if (intval($v['xid']) == 0 && $v['selected'] === 'Y') { + $sql = "INSERT INTO other_papsmearcheck ( + Other_PapSmearCheckOther_PapSmearID, + Other_PapSmearCheckM_PapSmearCheckID, + Other_PapSmearCheckNote, + Other_PapSmearCheckUserID, + Other_PapSmearCheckCreated + ) + VALUES( + {$header_id}, + {$v['check_id']}, + '{$v['note']}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if (intval($v['xid']) != 0 && $v['selected'] === 'N') { + $sql = "UPDATE other_papsmearcheck SET + Other_PapSmearCheckIsActive = 'N', + Other_PapSmearCheckUserID = {$userid} + WHERE + Other_PapSmearCheckID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + if (intval($v['xid']) != 0 && $v['selected'] === 'Y') { + $sql = "UPDATE other_papsmearcheck SET + Other_PapSmearCheckNote = '{$v['note']}', + Other_PapSmearCheckUserID = {$userid} + WHERE + Other_PapSmearCheckID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + //echo $sql; + } + } + + if ($maturasi) { + if (intval($maturasi['xid']) == 0) { + $value = join("/", $maturasi['value']); + $sql = "INSERT INTO other_papsmearmaturasi ( + Other_PapSmearMaturasiOther_PapSmearID, + Other_PapSmearMaturasiValue, + Other_PapSmearMaturasiUserID, + Other_PapSmearMaturasiCreated + ) + VALUE( + {$header_id}, + '{$value}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + //echo $sql; + } + if (intval($maturasi['xid']) != 0) { + $value = join("/", $maturasi['value']); + $sql = "UPDATE other_papsmearmaturasi SET + Other_PapSmearMaturasiValue = '{$value}', + Other_PapSmearMaturasiUserID = {$userid} + WHERE + Other_PapSmearMaturasiID = {$maturasi['xid']}"; + // echo $sql; + $this->db_smartone->query($sql); + } + } + + if ($bahans) { + foreach ($bahans as $k => $v) { + if (intval($v['xid']) == 0 && $v['selected'] === 'Y') { + $sql = "INSERT INTO other_papsmearbahan ( + Other_PapSmearBahanOther_PapSmearID, + Other_PapSmearBahanM_PapSmearBahanID, + Other_PapSmearBahanUserID, + Other_PapSmearBahanCreated + ) + VALUES( + {$header_id}, + {$v['bahan_id']}, + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if (intval($v['xid']) != 0 && $v['selected'] === 'N') { + $sql = "UPDATE other_papsmearbahan SET + Other_PapSmearBahanIsActive = 'N', + Other_PapsmearCategoryUserID = {$userid} + WHERE + Other_PapSmearBahanID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + if (intval($v['xid']) != 0 && $v['selected'] === 'Y') { + $sql = "UPDATE other_papsmearbahan SET + Other_PapSmearBahanIsActive = 'Y', + Other_PapsmearCategoryUserID = {$userid} + WHERE + Other_PapSmearBahanID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + //echo $sql; + } + } + + if ($categories) { + foreach ($categories as $k => $v) { + if (intval($v['xid']) == 0 && $v['selected'] === 'Y') { + $sql = "INSERT INTO other_papsmearcategory ( + Other_PapsmearCategoryOther_PapSmearID, + Other_PapsmearCategoryM_PapSmearCategoryID, + Other_PapsmearCategoryUserID, + Other_PapsmearCategoryCreated + ) + VALUES( + {$header_id}, + {$v['category_id']}, + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if (intval($v['xid']) != 0 && $v['selected'] === 'N') { + $sql = "UPDATE other_papsmearcategory SET + Other_PapsmearCategoryIsActive = 'N', + Other_PapsmearCategoryUserID = {$userid} + WHERE + Other_PapsmearCategoryID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + //echo $sql; + if (intval($v['xid']) != 0 && $v['selected'] === 'Y') { + $sql = "UPDATE other_papsmearcategory SET + Other_PapsmearCategoryIsActive = 'Y', + Other_PapsmearCategoryUserID = {$userid} + WHERE + Other_PapsmearCategoryID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + } + } + + if ($results) { + foreach ($results as $k => $v) { + if (intval($v['xid']) == 0) { + $sql = "INSERT INTO other_papsmeardetails ( + Other_PapSmearDetailsOther_PapSmearID, + Other_PapSmearDetailsCode, + Other_PapSmearDetailsLabel, + Other_PapSmearDetailsResult, + Other_PapSmearDetailsUserID, + Other_PapSmearDetailsCreated + ) + VALUES( + {$header_id}, + '{$v['code']}', + '{$v['label']}', + '{$v['result']}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if (intval($v['xid']) != 0) { + $sql = "UPDATE other_papsmeardetails SET + Other_PapSmearDetailsCode = '{$v['code']}', + Other_PapSmearDetailsLabel = '{$v['label']}', + Other_PapSmearDetailsResult = '{$v['result']}', + Other_PapSmearDetailsUserID = {$userid} + WHERE + Other_PapSmearDetailsID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + //echo $sql; + } + } + + $result = array("total" => 1, "records" => array(), "sql" => ''); + $this->sys_ok($result); + exit; + } + + function saveresult_fna() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = $inp['doctor']; + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + if ($prm[0]['xid'] == '0') { + $sql = "INSERT INTO other_fna( + Other_FNAM_DoctorID, + Other_FNAT_OrderDetailID, + Other_FNAUserID, + Other_FNACreated + ) + VALUES( + {$doctor_id}, + {$prm[0]['orderdetail_id']}, + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } else { + $sql = "SELECT * FROM other_fna WHERE Other_FNAT_OrderDetailID = {$prm[0]['orderdetail_id']} AND Other_FNAIsActive = 'Y'"; + $data_header = $this->db_smartone->query($sql)->row_array(); + $header_id = $data_header['Other_FNAID']; + $sql = "UPDATE other_fna SET + Other_FNAM_DoctorID = {$doctor_id}, + Other_FNAUserID = {$userid} + WHERE + Other_FNAID = {$header_id}"; + $this->db_smartone->query($sql); + } + foreach ($prm as $k => $v) { + if ($v['xid'] == '0') { + $results = str_replace("'", "\\'", $v['result']); + $sql = "INSERT INTO other_fnadetails( + Other_FNADetailsOther_FNAID , + Other_FNADetailsCode, + Other_FNADetailsLabel, + Other_FNADetailsResult, + Other_FNADetailsCreated, + Other_FNADetailsUserID + ) + VALUES( + {$header_id}, + '{$v['code']}', + '{$v['label']}', + '{$results}', + NOW(), + {$userid} + )"; + $query = $this->db_smartone->query($sql); + } else { + $results = str_replace("'", "\\'", $v['result']); + $sql = "UPDATE other_fnadetails SET + Other_FNADetailsResult = '{$results}', + Other_FNADetailsUserID = {$userid} + WHERE + Other_FNADetailsID = {$v['xid']}"; + $query = $this->db_smartone->query($sql); + } + } + + $result = array("total" => 1, "records" => array(), "sql" => ''); + $this->sys_ok($result); + exit; + } + + function saveresult_cytologi() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = $inp['doctor']; + + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + if ($prm[0]['xid'] == '0') { + $sql = "INSERT INTO other_cytologi( + Other_CytologiT_OrderDetailID, + Other_CytologiM_DoctorID, + Other_CytologiUserID, + Other_CytologiCreated + ) + VALUES( + {$prm[0]['orderdetail_id']}, + {$doctor_id}, + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } else { + $sql = "SELECT * FROM other_cytologi WHERE Other_CytologiT_OrderDetailID = {$prm[0]['orderdetail_id']} AND Other_CytologiIsActive = 'Y'"; + $data_header = $this->db_smartone->query($sql)->row_array(); + $header_id = $data_header['Other_CytologiID']; + $sql = "UPDATE other_cytologi SET + Other_CytologiM_DoctorID = {$doctor_id}, + Other_CytologiUserID = {$userid} + WHERE + Other_CytologiID = {$header_id}"; + $this->db_smartone->query($sql); + } + foreach ($prm as $k => $v) { + if ($v['xid'] == '0') { + $results = str_replace("'", "\\'", $v['result']); + $sql = "INSERT INTO other_cytologidetails( + Other_CytologiDetailsOther_CytologiID , + Other_CytologiDetailsCode, + Other_CytologiDetailsLabel, + Other_CytologiDetailsResult, + Other_CytologiDetailsCreated, + Other_CytologiDetailsUserID + ) + VALUES( + {$header_id}, + '{$v['code']}', + '{$v['label']}', + '{$results}', + NOW(), + {$userid} + )"; + $query = $this->db_smartone->query($sql); + } else { + $results = str_replace("'", "\\'", $v['result']); + $sql = "UPDATE other_cytologidetails SET + Other_CytologiDetailsResult = '{$results}', + Other_CytologiDetailsUserID = {$userid} + WHERE + Other_CytologiDetailsID = {$v['xid']}"; + $query = $this->db_smartone->query($sql); + } + } + + $result = array("total" => 1, "records" => array(), "sql" => ''); + $this->sys_ok($result); + exit; + } + + function saveresult_mikro() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = $inp['doctor']; + $backteria_id = $inp['bacteria']; + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + + if ($inp['result_value'] != 'Negatif' && $inp['result_value'] != 'Positif') { + $prm['result_value'] = $prm['result_other']; + } else { + $prm['result_value'] = $inp['result_value']; + } + + if ($prm['xid'] == '0') { + $sql = "INSERT INTO other_mikro( + Other_MikroM_DoctorID, + Other_MikroResult, + Other_MikroT_BacteriaID, + Other_MikroT_OrderDetailID, + Other_MikroHasilBiakan, + Other_MikroSampleTypeName, + Other_MikroUserID, + Other_MikroCreated + ) + VALUES( + {$doctor_id}, + '{$prm['result_value']}', + {$backteria_id}, + {$prm['orderdetail_id']}, + '{$prm['hasil_biakan']}', + '{$prm['sample_name']}', + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } else { + $sql = "SELECT * FROM other_mikro WHERE Other_MikroT_OrderDetailID = {$prm['orderdetail_id']} AND Other_MikroIsActive = 'Y'"; + $data_header = $this->db_smartone->query($sql)->row_array(); + $header_id = $data_header['Other_MikroID']; + $sql = "UPDATE other_mikro SET + Other_MikroResult = '{$prm['result_value']}', + Other_MikroM_DoctorID = {$doctor_id}, + Other_MikroT_BacteriaID = {$backteria_id}, + Other_MikroHasilBiakan = '{$prm['hasil_biakan']}', + Other_MikroSampleTypeName = '{$prm['sample_name']}', + Other_MikroUserID = {$userid} + WHERE + Other_MikroID = {$header_id}"; + //echo $sql; + $this->db_smartone->query($sql); + } + + + + $sql = "UPDATE other_mikrodetails SET Other_MikroDetailsIsActive = 'N', Other_MikroDetailsUserID = 0 WHERE Other_MikroDetailsOther_MikroID = {$header_id}"; + $this->db_smartone->query($sql); + + $results = $prm['details']; + if ($inp['result_value'] == 'Positif') { + foreach ($results as $k => $v) { + if ($v['xid'] == '0') { + $sql = "INSERT INTO other_mikrodetails( + Other_MikroDetailsOther_MikroID , + Other_MikroDetailsT_AntibioticID, + Other_MikroDetailsValue, + Other_MikroDetailsNote, + Other_MikroDetailsCreated, + Other_MikroDetailsUserID + ) + VALUES( + {$header_id}, + '{$v['T_AntibioticID']}', + '{$v['value']}', + '{$v['note']}', + NOW(), + {$userid} + )"; + $query = $this->db_smartone->query($sql); + } else { + $sql = "UPDATE other_mikrodetails SET + Other_MikroDetailsT_AntibioticID = '{$v['T_AntibioticID']}', + Other_MikroDetailsValue = '{$v['value']}', + Other_MikroDetailsNote = '{$v['note']}', + Other_MikroDetailsIsActive = 'Y', + Other_MikroDetailsUserID = {$userid} + WHERE + Other_MikroDetailsID = {$v['xid']}"; + //echo $sql; + $query = $this->db_smartone->query($sql); + } + } + } + + + $result = array("total" => 1, "records" => array(), "sql" => ''); + $this->sys_ok($result); + exit; + } + + + function get_doctors_preparasi_sperma() + { + $prm = $this->sys_input; + // $id = $prm["id"]; + + $sql = " SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 10 AND + M_DoctorSOIsActive = 'Y' + ORDER BY M_DoctorName ASC"; + //echo $sql; + $query = $this->db_smartone->query($sql); + $rows = $query->result_array(); + $sql = " + SELECT '0' as id, 'Belum memilih metode' as name + UNION + SELECT M_MethodeSpermaID as id, M_MethodeSpermaName as name + FROM m_methodesperma + WHERE + M_MethodeSpermaIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $methodes = $this->db_smartone->query($sql)->result_array(); + + + $this->sys_ok(["records" => $rows, "methodes" => $methodes]); + } + + + function getpreparasispermaresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT other_preparasisperma.*, + Other_PreparasiSpermaID as xid, + Other_PreparasiSpermaT_OrderDetailID as orderdetail_id, + IFNULL(Other_PreparasiSpermaM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_PreparasiSpermaM_DoctorID) OR Other_PreparasiSpermaM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name, + IFNULL(M_MethodeSpermaID,0) as methode_id, + IFNULL(M_MethodeSpermaName,'') as methode_name + FROM other_preparasisperma + LEFT JOIN m_doctor ON Other_PreparasiSpermaM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + LEFT JOIN m_methodesperma ON Other_PreparasiSpermaM_MethodeSpermaID = M_MethodeSpermaID AND + M_MethodeSpermaIsActive = 'Y' + WHERE + Other_PreparasiSpermaT_OrderDetailID = {$id} AND Other_PreparasiSpermaIsActive = 'Y' + GROUP BY Other_PreparasiSpermaID"; + $query = $this->db_smartone->query($sql); + + if ($query) { + $rows = $query->row_array(); + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 10 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $sql = " + SELECT '0' as id, 'Belum memilih metode' as name + UNION + SELECT M_MethodeSpermaID as id, M_MethodeSpermaName as name + FROM m_methodesperma + WHERE + M_MethodeSpermaIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $methodes = $this->db_smartone->query($sql)->result_array(); + $images = array(); + $sql = "SELECT Other_PreparasiSpermaImgID as xid, + Other_PreparasiSpermaImgType as type, + CONCAT('/one-media/one-image-nonlab/',Other_PreparasiSpermaImgNewName) as image_url + FROM t_orderdetail + JOIN other_preparasisperma_img ON Other_PreparasiSpermaImgT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND + Other_PreparasiSpermaImgIsActive = 'Y' + WHERE + T_OrderDetailID = {$id} AND + T_OrderDetailIsActive = 'Y' + GROUP BY Other_PreparasiSpermaImgID"; + //echo $sql; + $images = $this->db_smartone->query($sql)->result_array(); + + $rst = array('doctors' => $doctors, 'methodes' => $methodes, 'results' => $rows, 'images' => $images); + $this->sys_ok(["records" => $rst]); + } else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + + function uploadimage_preparasi_sperma() + { + if (! $this->isLogin) { + $this->sys_error("Invalid Token"); + exit; + } + + $userid = $this->sys_user["M_UserID"]; + $data = []; + //print_r($_SERVER); + + $prm = $this->sys_input; + $orderid = $this->input->post('orderid'); + $type = $this->input->post('type'); + $labnumber = $this->input->post('labnumber'); + $sql = "UPDATE other_preparasisperma_img SET + Other_PreparasiSpermaImgIsActive = 'N', + Other_PreparasiSpermaImgUserID = {$userid} + WHERE + Other_PreparasiSpermaImgT_OrderHeaderID = {$orderid} AND + Other_PreparasiSpermaImgType = '{$type}'"; + //echo $sql; + $this->db_onedev->query($sql); + //$config['upload_path'] = 'assets/'; + + $path = '/home/one/project/one/one-media/one-image-nonlab/'; + //echo $path; + $config['upload_path'] = $path; + $config['allowed_types'] = 'jpg|jpeg|png|gif'; + + $config['max_size'] = '10000'; + $count = count($_FILES['files']['name']); + //echo $count; + $this->load->library('upload', $config); + + $error = []; + for ($i = 0; $i < $count; $i++) { + + + if (!empty($_FILES['files']['name'][$i])) { + + + + $_FILES['file']['name'] = $_FILES['files']['name'][$i]; + + $_FILES['file']['type'] = $_FILES['files']['type'][$i]; + + $_FILES['file']['tmp_name'] = $_FILES['files']['tmp_name'][$i]; + + $_FILES['file']['error'] = $_FILES['files']['error'][$i]; + + $_FILES['file']['size'] = $_FILES['files']['size'][$i]; + + + + $namex = $orderid . '-' . $labnumber . '-' . $this->generateRandomString(5); + //echo $namex; + + $config['file_name'] = $namex; + $this->upload->initialize($config); + //echo $config['file_name'] ; + + + + + + if ($this->upload->do_upload('file')) { + + $uploadData = $this->upload->data(); + + $filename = $uploadData['file_name']; + //echo $filename; + + + $sql = "INSERT INTO other_preparasisperma_img ( + Other_PreparasiSpermaImgT_OrderHeaderID, + Other_PreparasiSpermaImgType, + Other_PreparasiSpermaImgOldName, + Other_PreparasiSpermaImgNewName, + Other_PreparasiSpermaImgCreated, + Other_PreparasiSpermaImgUserID + ) + VALUES( + {$orderid}, + '{$type}', + '{$_FILES['files']['name'][$i]}', + '{$filename}', + NOW(), + {$userid} + + )"; + //echo $sql; + $this->db_onedev->query($sql); + $xlast_id = $this->db_onedev->insert_id(); + $data['totalFiles'][] = array('xid' => $xlast_id, 'type' => $type, 'image_url' => '/one-media/one-image-nonlab/' . $filename); + } else { + $error = array('error' => $this->upload->display_errors()); + } + } + } + + $result = array("total" => count($data['totalFiles']), "records" => $data['totalFiles'], 'errors' => $error); + $this->sys_ok($result); + } + + + function saveresult_preparasi_sperma() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = $inp['doctor']; + $orderdetail_id = $inp['orderdetailid']; + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + if ($prm['xid'] == '0') { + $sql = "INSERT INTO other_preparasisperma( + Other_PreparasiSpermaM_DoctorID, + Other_PreparasiSpermaT_OrderDetailID, + Other_PreparasiSpermaPreMotilitasA, + Other_PreparasiSpermaPreMotilitasB, + Other_PreparasiSpermaPreMotilitasC, + Other_PreparasiSpermaPreKonsentrasi, + Other_PreparasiSpermaPreKontaminan, + Other_PreparasiSpermaPostMotilitasA, + Other_PreparasiSpermaPostMotilitasB, + Other_PreparasiSpermaPostMotilitasC, + Other_PreparasiSpermaPostKonsentrasi, + Other_PreparasiSpermaPostKontaminan, + Other_PreparasiSpermaPreVolume, + Other_PreparasiSpermaPostVolume, + Other_PreparasiSpermaM_MethodeSpermaID, + Other_PreparasiSpermaNote, + Other_PreparasiSpermaUserID, + Other_PreparasiSpermaCreated + ) + VALUES( + {$doctor_id}, + {$orderdetail_id}, + '{$prm['Other_PreparasiSpermaPreMotilitasA']}', + '{$prm['Other_PreparasiSpermaPreMotilitasB']}', + '{$prm['Other_PreparasiSpermaPreMotilitasC']}', + '{$prm['Other_PreparasiSpermaPreKonsentrasi']}', + '{$prm['Other_PreparasiSpermaPreKontaminan']}', + '{$prm['Other_PreparasiSpermaPostMotilitasA']}', + '{$prm['Other_PreparasiSpermaPostMotilitasB']}', + '{$prm['Other_PreparasiSpermaPostMotilitasC']}', + '{$prm['Other_PreparasiSpermaPostKonsentrasi']}', + '{$prm['Other_PreparasiSpermaPostKontaminan']}', + '{$prm['Other_PreparasiSpermaPreVolume']}', + '{$prm['Other_PreparasiSpermaPostVolume']}', + '{$prm['Other_PreparasiSpermaM_MethodeSpermaID']}', + '{$prm['Other_PreparasiSpermaNote']}', + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } else { + $sql = "SELECT * FROM other_preparasisperma WHERE Other_PreparasiSpermaT_OrderDetailID = {$orderdetail_id} AND Other_PreparasiSpermaIsActive = 'Y'"; + $data_header = $this->db_smartone->query($sql)->row_array(); + $header_id = $data_header['Other_PreparasiSpermaID']; + $sql = "UPDATE other_preparasisperma SET + Other_PreparasiSpermaM_DoctorID = {$doctor_id}, + Other_PreparasiSpermaPreMotilitasA = '{$prm['Other_PreparasiSpermaPreMotilitasA']}', + Other_PreparasiSpermaPreMotilitasB = '{$prm['Other_PreparasiSpermaPreMotilitasB']}', + Other_PreparasiSpermaPreMotilitasC = '{$prm['Other_PreparasiSpermaPreMotilitasC']}', + Other_PreparasiSpermaPreKonsentrasi = '{$prm['Other_PreparasiSpermaPreKonsentrasi']}', + Other_PreparasiSpermaPreKontaminan = '{$prm['Other_PreparasiSpermaPreKontaminan']}', + Other_PreparasiSpermaPostMotilitasA = '{$prm['Other_PreparasiSpermaPostMotilitasA']}', + Other_PreparasiSpermaPostMotilitasB = '{$prm['Other_PreparasiSpermaPostMotilitasB']}', + Other_PreparasiSpermaPostMotilitasC = '{$prm['Other_PreparasiSpermaPostMotilitasC']}', + Other_PreparasiSpermaPostKonsentrasi = '{$prm['Other_PreparasiSpermaPostKonsentrasi']}', + Other_PreparasiSpermaPostKontaminan = '{$prm['Other_PreparasiSpermaPostKontaminan']}', + Other_PreparasiSpermaPreVolume = '{$prm['Other_PreparasiSpermaPreVolume']}', + Other_PreparasiSpermaPostVolume = '{$prm['Other_PreparasiSpermaPostVolume']}', + Other_PreparasiSpermaM_MethodeSpermaID = '{$prm['Other_PreparasiSpermaM_MethodeSpermaID']}', + Other_PreparasiSpermaNote = '{$prm['Other_PreparasiSpermaNote']}', + Other_PreparasiSpermaUserID = {$userid} + WHERE + Other_PreparasiSpermaID = {$header_id}"; + $this->db_smartone->query($sql); + } + + + $result = array("total" => 1, "records" => array(), "sql" => ''); + $this->sys_ok($result); + exit; + } + + function getdnafragmentasiresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT other_dnafragmentasi.*, + Other_DnaFragmentasiID as xid, + Other_DnaFragmentasiT_OrderDetailID as orderdetail_id, + IFNULL(Other_DnaFragmentasiM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_DnaFragmentasiM_DoctorID) OR Other_DnaFragmentasiM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name, + IFNULL(Other_DnaFragmentasiOther_DnaFragmentasiMethodeID,0) as methode_id, + IFNULL(Other_DnaFragmentasiMethodeName,'') as methode_name, + Other_DnaFragmentasiHaloLuas as halo_luas, + Other_DnaFragmentasiHaloSedang as halo_sedang, + Other_DnaFragmentasiHaloSempit as halo_sempit, + Other_DnaFragmentasiTanpaHalo as tanpa_halo, + Other_DnaFragmentasiDFI as dfi, + Other_DnaFragmentasiKesimpulan as kesimpulan, + Other_DnaFragmentasiCatatan as catatan + FROM other_dnafragmentasi + LEFT JOIN m_doctor ON Other_DnaFragmentasiM_DoctorID = M_DoctorID + LEFT JOIN other_dnafragmentasimethode ON Other_DnaFragmentasiOther_DnaFragmentasiMethodeID = Other_DnaFragmentasiMethodeID + WHERE + Other_DnaFragmentasiT_OrderDetailID = {$id} AND Other_DnaFragmentasiIsActive = 'Y' + GROUP BY Other_DnaFragmentasiID + LIMIT 1"; + //echo $sql; + $query = $this->db_smartone->query($sql); + + if ($query) { + $rows = $query->row_array(); + if (!$rows) { + $rows = array( + 'xid' => 0, + 'orderdetail_id' => $id, + 'doctor_id' => 0, + 'doctor_name' => '', + 'methode_id' => 0, + 'methode_name' => '', + 'halo_luas' => '', + 'halo_sedang' => '', + 'tanpa_halo' => '', + 'dfi' => '', + 'kesimpulan' => '', + 'catatan' => '' + ); + } + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID + WHERE + M_DoctorSONat_SubGroupID = 4 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + + $sql = " + SELECT '0' as id, 'Belum memilih metode' as name + UNION + SELECT Other_DnaFragmentasiMethodeID as id, Other_DnaFragmentasiMethodeName as name + FROM other_dnafragmentasimethode + WHERE + Other_DnaFragmentasiMethodeIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $methodes = $this->db_smartone->query($sql)->result_array(); + + + $rst = array('doctors' => $doctors, 'methodes' => $methodes, 'results' => $rows); + $this->sys_ok(["records" => $rst]); + } else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + function saveresult_dnafragmentasi() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = $inp['doctor']['id']; + $methode_id = $inp['methode']['id']; + $orderdetail_id = $inp['results']['orderdetail_id']; + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + if (intval($prm['xid']) == 0) { + $sql = "INSERT INTO other_dnafragmentasi( + Other_DnaFragmentasiT_OrderDetailID, + Other_DnaFragmentasiM_DoctorID, + Other_DnaFragmentasiOther_DnaFragmentasiMethodeID, + Other_DnaFragmentasiHaloLuas, + Other_DnaFragmentasiHaloSedang, + Other_DnaFragmentasiHaloSempit, + Other_DnaFragmentasiTanpaHalo, + Other_DnaFragmentasiDFI, + Other_DnaFragmentasiKesimpulan, + Other_DnaFragmentasiCatatan, + Other_DnaFragmentasiUserID, + Other_DnaFragmentasiLastUpdated + ) + VALUES( + {$orderdetail_id}, + {$doctor_id}, + {$methode_id}, + '{$prm['halo_luas']}', + '{$prm['halo_sedang']}', + '{$prm['halo_sempit']}', + '{$prm['tanpa_halo']}', + '{$prm['dfi']}', + '{$prm['kesimpulan']}', + '{$prm['catatan']}', + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } else { + $sql = "UPDATE other_dnafragmentasi SET + Other_DnaFragmentasiT_OrderDetailID = {$orderdetail_id}, + Other_DnaFragmentasiM_DoctorID = {$doctor_id}, + Other_DnaFragmentasiOther_DnaFragmentasiMethodeID = '{$methode_id}', + Other_DnaFragmentasiHaloLuas = '{$prm['halo_luas']}', + Other_DnaFragmentasiHaloSedang = '{$prm['halo_sedang']}', + Other_DnaFragmentasiHaloSempit = '{$prm['halo_sempit']}', + Other_DnaFragmentasiTanpaHalo = '{$prm['tanpa_halo']}', + Other_DnaFragmentasiDFI = '{$prm['dfi']}', + Other_DnaFragmentasiKesimpulan = '{$prm['kesimpulan']}', + Other_DnaFragmentasiCatatan = '{$prm['catatan']}', + Other_DnaFragmentasiLastUpdated = NOW(), + Other_DnaFragmentasiUserID = {$userid} + WHERE + Other_DnaFragmentasiID = {$prm['xid']}"; + //echo $sql; + $this->db_smartone->query($sql); + } + + + $result = array("total" => 1, "records" => array(), "sql" => ''); + $this->sys_ok($result); + exit; + } +} diff --git a/application/controllers/mockup/process/westone_resultvalidation-ibl/Re_px.php b/application/controllers/mockup/process/westone_resultvalidation-ibl/Re_px.php index 8e1cbe21..dca767be 100644 --- a/application/controllers/mockup/process/westone_resultvalidation-ibl/Re_px.php +++ b/application/controllers/mockup/process/westone_resultvalidation-ibl/Re_px.php @@ -1,2513 +1,2510 @@ -db_smartone = $this->load->database("onedev", true); - $this->load->helper(array('form', 'url')); - } - function getMethodeID($natTestID) - { - $sql = "select M_MethodePriorityNat_MethodeID MethodeID, Nat_MethodeName - from - m_methode_priority - join nat_methode on Nat_MethodeID = M_MethodePriorityNat_MethodeID - and Nat_MethodeIsActive = 'Y' - join m_instrumentmethode on M_InstrumentMethodeNat_MethodeID = Nat_MethodeID and M_InstrumentMethodeIsActive = 'Y' - join nat_instrument on M_InstrumentMethodeNat_InstrumentID = Nat_InstrumentID - and Nat_InstrumentIsActive ='Y' - where M_MethodePriorityIsActive = 'Y' - and M_MethodePriorityNat_TestID = $natTestID - and M_MethodePriorityM_DayOfWeekID = dayofweek(now()) - order by M_MethodePriorityNumber desc - limit 0,1 "; - $qry = $this->db->query($sql); - if ($qry) { - $rows = $qry->result_array(); - if (count($rows) > 0) return array($rows[0]["MethodeID"], $rows[0]["Nat_MethodeName"]); - } - //2nd - $sql = "select - M_InstrumentMethodeNat_MethodeID MethodeID, Nat_MethodeName - from m_instrumentmethode - join nat_methode on M_InstrumentMethodeNat_MethodeID = Nat_MethodeID - and Nat_MethodeIsActive = 'Y' - join nat_instrument on M_InstrumentMethodeNat_InstrumentID = Nat_InstrumentID - and Nat_InstrumentIsActive ='Y' - where M_InstrumentMethodeNat_TestID = $natTestID - and M_InstrumentMethodeIsActive = 'Y' - order by M_InstrumentMethodePriority desc - limit 0,1"; - $qry = $this->db->query($sql); - if ($qry) { - $rows = $qry->result_array(); - if (count($rows) > 0) return array($rows[0]["MethodeID"], $rows[0]["Nat_MethodeName"]); - } - // - $sql = "select Nat_NormalValueNat_MethodeID MethodeID, Nat_MethodeName - from - nat_normalvalue - join nat_methode on Nat_NormalValueNat_MethodeID = Nat_MethodeID - and Nat_MethodeIsActive = 'Y' - where Nat_NormalValueNat_TestID = $natTestID - and Nat_NormalValueIsActive = 'Y' - order by Nat_NormalValueID - limit 0,1"; - $qry = $this->db->query($sql); - if ($qry) { - $rows = $qry->result_array(); - if (count($rows) > 0) return array($rows[0]["MethodeID"], $rows[0]["Nat_MethodeName"]); - } - return array(0, ""); - } - function get_normal_value($methodeID, $natTestID, $sexID, $ageInDay) - { - $sql = "select fn_sampling_get_normal($methodeID, $natTestID, $sexID, $ageInDay) as normalValueID"; - $qry = $this->db->query($sql); - if ($qry) { - $rows = $qry->result_array(); - if (count($rows) > 0) return $rows[0]["normalValueID"]; - } - return 0; - } - function fn_fix_normal($order_id) - { - $sql = "select - T_OrderDetailID, M_PatientM_SexID, fn_global_age_count_day(M_PatientDOB, date(T_OrderHeaderDate)) Dob , - T_TestNat_TestID - from t_orderheader - join m_patient on T_OrderHeaderID = $order_id and T_OrderHeaderM_PatientID = M_PatientID - join t_orderdetail on T_OrderDetailT_OrderHeaderID = T_OrderHeaderID - and T_OrderDetailIsACtive = 'Y' - and ( T_OrderDetailNat_NormalValueID is null or T_OrderDetailNat_NormalValueID = 0 ) - join t_test on T_OrderDetailT_TestID = T_TestID and T_TestIsResult = 'Y' "; - $qry = $this->db->query($sql); - if (! $qry) { - return; - } - $rows = $qry->result_array(); - if (count($rows) == 0) return; - $sql_u = "update t_orderdetail - join nat_normalvalue on T_OrderDetailID = ? and Nat_NormalValueID = ? - set - T_OrderDetailNat_NormalValueID = Nat_NormalValueID, - T_OrderDetailNormalValueNote = Nat_NormalValueNote, - T_OrderDetailNormalValueDescription = Nat_NormalValueDescription, - T_OrderDetailMinValue = Nat_NormalValueMinValue, - T_OrderDetailMaxValue = Nat_NormalValueMaxValue, - T_OrderDetailMinValueInclusive = Nat_NormalValueMinValueInclusive, - T_OrderDetailMaxValueInclusive = Nat_NormalValueMaxValueInclusive, - T_OrderDetailNat_MethodeID = ?, - T_OrderdetailNat_MethodeName =?"; - - foreach ($rows as $r) { - $T_OrderDetailID = $r["T_OrderDetailID"]; - $sexID = $r["M_PatientM_SexID"]; - $ageInDay = $r["Dob"]; - $natTestID = $r["T_TestNat_TestID"]; - list($methodeID, $methodeName) = $this->getMethodeID($natTestID); - if ($methodeID == 0) continue; - $normalValueID = $this->get_normal_value($methodeID, $natTestID, $sexID, $ageInDay); - if ($normalValueID == 0) return; - $this->db->query($sql_u, array($T_OrderDetailID, $normalValueID, $methodeID, $methodeName)); - } - } - function update_order_sample($targetID, $sourceID) - { - $sql = "update t_ordersample target - join t_ordersample source on - target.T_OrderSampleID = ? - and target.T_OrderSampleWorklistReceive = 'N' - and source.T_OrderSampleID = ? - set - target.T_OrderSampleSampling = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSampling, source.T_OrderSampleSampling), - target.T_OrderSampleSamplingDate = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingDate, source.T_OrderSampleSamplingDate), - target.T_OrderSampleSamplingTime = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingTime, source.T_OrderSampleSamplingTime), - target.T_OrderSampleSamplingUserID = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingUserID, source.T_OrderSampleSamplingUserID), - - target.T_OrderSampleReceive = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceive, source.T_OrderSampleReceive), - target.T_OrderSampleReceiveDate = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveDate, source.T_OrderSampleReceiveDate), - target.T_OrderSampleReceiveTime = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveTime, source.T_OrderSampleReceiveTime), - target.T_OrderSampleReceiveUserID = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveUserID, source.T_OrderSampleReceiveUserID), - - target.T_OrderSampleVerification = if(target.T_OrderSampleVerification='Y',target.T_OrderSampleVerification, source.T_OrderSampleVerification), - target.T_OrderSampleVerificationDate =if(target.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationDate, source.T_OrderSampleVerificationDate), - target.T_OrderSampleVerificationTime =if(source.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationTime, source.T_OrderSampleVerificationTime), - target.T_OrderSampleVerificationUserID =if(source.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationUserID, source.T_OrderSampleVerificationUserID), - - target.T_OrderSampleProcessing = if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessing, source.T_OrderSampleProcessing), - target.T_OrderSampleProcessingDate= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingDate, source.T_OrderSampleProcessingDate), - target.T_OrderSampleProcessingTime= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingTime, source.T_OrderSampleProcessingTime), - target.T_OrderSampleProcessingUserID= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingUserID, source.T_OrderSampleProcessingUserID), - - target.T_OrderSampleReceiveHandling =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandling, source.T_OrderSampleReceiveHandling ), - target.T_OrderSampleReceiveHandlingDate =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingDate, source.T_OrderSampleReceiveHandlingDate), - target.T_OrderSampleReceiveHandlingTime =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingTime, source.T_OrderSampleReceiveHandlingTime), - target.T_OrderSampleReceiveHandlingUserID =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingUserID, source.T_OrderSampleReceiveHandlingUserID), - - target.T_OrderSampleHandling = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandling, source.T_OrderSampleHandling), - target.T_OrderSampleHandlingDate = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingDate, source.T_OrderSampleHandlingDate), - target.T_OrderSampleHandlingTime = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingTime, source.T_OrderSampleHandlingTime), - target.T_OrderSampleHandlingUserID = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingUserID, source.T_OrderSampleHandlingUserID), - - target.T_OrderSampleWorklistReceive = source.T_OrderSampleWorklistReceive, - target.T_OrderSampleWorklistReceiveDatetime = source.T_OrderSampleWorklistReceiveDateTime, - target.T_OrderSampleWorklistReceiveUserID = source.T_OrderSampleWorklistReceiveUserID - "; - $qry = $this->db->query($sql, array($targetID, $sourceID)); - if (! $qry) { - echo json_encode(array("status" => "ERR", "message" => print_r($this->db->error(), true))); - exit; - } - } - function fix_sample_serum($headerID) - { - //cari t_ordersample yg belum worklist receive dengan code 017% - $sql = "select T_OrderSampleID - from t_ordersample - join t_sampletype on - T_OrderSampleT_OrderHeaderID = ? - and T_OrderSampleWorklistReceive = 'N' - and T_OrderSampleIsActive = 'Y' - and T_OrderSampleT_SampleTypeID = T_SampletypeID - and T_SampleTypeCode like '017%' - "; - $qry = $this->db->query($sql, array($headerID)); - if (!$qry) { - echo json_encode(array("status" => "ERR", "message" => print_r($this->db->error(), true))); - exit; - } - $rows = $qry->result_array(); - if (count($rows) == 0) return; - //cari T_OrderSample yang sudah di receive yg terakhir - $sql = "select T_OrderSampleID - from t_ordersample - join t_sampletype on - T_OrderSampleT_OrderHeaderID = ? - and T_OrderSampleWorklistReceive = 'Y' - and T_OrderSampleIsActive = 'Y' - and T_OrderSampleT_SampleTypeID = T_SampletypeID - and T_SampleTypeCode like '017%' - order by T_OrderSampleWorklistReceiveDatetime desc - limit 0,1 - "; - $qry = $this->db->query($sql, array($headerID)); - if (!$qry) { - echo json_encode(array("status" => "ERR", "message" => print_r($this->db->error(), true))); - exit; - } - $rcv_rows = $qry->result_array(); - if (count($rcv_rows) == 0) return; - - //print_r($rows); - //print_r($rcv_rows); - $rcv_T_OrderSampleID = $rcv_rows[0]["T_OrderSampleID"]; - //ada yg belum di receive - foreach ($rows as $r) { - $T_OrderSampleID = $r["T_OrderSampleID"]; - $this->update_order_sample($T_OrderSampleID, $rcv_T_OrderSampleID); - } - } - public function search() - { - $prm = $this->sys_input; - $max_rst = 99; - - $id = $prm["order_id"]; - if ($id > 0) { - $this->fix_sample_serum($id); - $this->fn_fix_normal($id); - } - $lang = $this->lang_default_code; - $lang_id = isset($prm['lang_id']) ? $prm['lang_id'] : '0'; - - if ($lang_id != 0) { - $l = $this->db_smartone->where("Nat_LangID", $lang_id)->get("nat_lang")->row(); - $lang = $l->Nat_LangCode; - } - - //tambahan fajri - $sql = " UPDATE t_orderdetail - JOIN t_test ON T_OrderDetailT_TestID = T_TestID - SET T_OrderDetailT_TestIsResult = T_TestIsResult - WHERE - T_OrderDetailT_OrderHeaderID = {$id} AND - T_OrderDetailT_TestIsResult = '' AND - T_OrderDetailIsActive = 'Y'"; - $this->db_smartone->query($sql); - - $tot_count = 0; - $lq = ""; - $group_id = 0; - if (isset($prm['group_id'])) - $group_id = $prm['group_id']; - - if ($group_id != 0) { - $sql = "select distinct T_WorklistDetailNat_TestID Nat_TestID - from t_worklistdetailv2 - where T_WorklistDetailT_WorklistID = {$group_id}"; - $qry = $this->db_smartone->query($sql); - $rows = $qry->result_array(); - $nat_test_ids = "0"; - foreach ($rows as $r) { - $nat_test_ids .= ", " . $r["Nat_TestID"]; - } - $q_group = " ( $nat_test_ids ) "; - - $sql = " - SELECT a1.*, cOUNT(a2.T_OrderDetailID) level - FROM ( - SELECT IFNULL(y.T_OrderDetailT_TestID, x.T_OrderDetailT_TestID) t_testid, - IFNULL(y.T_OrderDetailT_TestName, y.T_OrderDetailT_TestName) t_testname, - y.T_OrderDetailResult result, y.T_OrderDetailResult result_old, y.T_OrderDetailNote note, y.T_OrderDetailNote note_old, - y.T_OrderDetailID id, - y.T_OrderDetailT_TestIsResult is_result, a.T_TestIsQuantitative is_quantitative, - y.T_OrderDetailResultFlag result_flag, - y.T_OrderDetailNat_NormalValueID normal_id, - y.T_OrderDetailNormalValueNote normal_note, y.T_OrderDetailNat_UnitName unit_name, - y.T_OrderdetailNat_MethodeID methode_id, y.T_OrderdetailNat_MethodeName methode_name, - a.T_TestNat_TestID nattest_id, a.T_TestID tx_id, count(T_ResultInstrumentID) as result_instrument_n, - y.T_OrderDetailVerification, T_OrderSampleReceive sample_receive, - T_OrderSampleProcessing sample_processing, T_OrderSampleWorklistReceive sample_worklist_receive, - IF(T_OrderDetailAddOnPreAnalytic = 'Y', T_OrderDetailAddOnPreAnalytic, PreAnalyticIsOk) pre_analytic, - T_OrderDetailAddOnPreAnalytic, - T_OrderHeaderID order_id, y.T_OrderDetailT_TestSasCode test_sas_code, - tx.T_TestSasCode, - T_OrderDetailAddOnResample `resample`, T_OrderDetailAddOnResampleStatus resample_status, - T_OrderDetailAddOnRef ref, y.T_OrderDetailVerification verification, y.T_OrderDetailValidation validation, - T_OrderPromiseDateTime, Group_ResultName as ResultGroupName - FROM t_orderdetail x - left join t_orderpromise on x.T_OrderDetailT_OrderPromiseID = T_OrderPromiseID - JOIN t_test tx ON x.T_OrderDetailT_TestID = T_TestID - JOIN t_test tcheck on tcheck.T_TestNat_TestID in {$q_group} - and ( tx.T_TestID = tcheck.T_TestID or tx.T_TestSasCode like concat(tcheck.T_TestSasCode,'%')) - LEFT JOIN group_resultdetail ON Group_ResultDetailT_TestID = x.T_OrderDetailT_TestID AND Group_ResultDetailIsActive = 'Y' - LEFT JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND Group_ResultFlagNonLab = 'N' - LEFT JOIN t_orderdetail y ON x.T_OrderDetailT_TestSasCode LIKE CONCAT(y.T_OrderDetailT_TestSasCode, '%') - AND x.T_OrderDetailT_OrderHeaderID = y.T_OrderDetailT_OrderHeaderID - AND y.T_OrderDetailIsActive = 'Y' - LEFT JOIN t_orderdetailaddon ON x.T_OrderDetailID = T_OrderDetailAddOnT_OrderDetailID - JOIN t_orderheader ON y.T_OrderDetailT_OrderHeaderID = T_OrderHeaderID - LEFT JOIN t_test a ON y.T_OrderDetailT_TestID = a.T_TestID - AND a.T_TestIsNonLab = '' - LEFT JOIN (SELECT T_OrderSampleT_SampleTypeID, T_OrderSampleReceive, T_OrderSampleProcessing, T_OrderSampleWorklistReceive - FROM t_ordersample WHERE T_OrderSampleT_OrderHeaderID = {$id} - AND T_OrderSampleIsactive = 'Y' - GROUP BY T_OrderSampleT_SampleTypeID) os ON a.T_TestT_SampleTypeID = os.T_OrderSampleT_SampleTypeID - or os.T_OrderSampleT_SampleTypeID = fn_sampletype_from_local(a.T_TestNat_TestID) - - LEFT JOIN t_resultinstrument ON T_ResultInstrumentT_OrderDetailID = x.T_OrderDetailID - LEFT JOIN pre_analytic ON PreAnalyticNat_TestID = a.T_TestNat_TestID AND PreAnalyticDate = date(now()) and PreAnalyticIsActive = 'Y' - WHERE x.T_OrderDetailT_OrderHeaderID = {$id} - AND x.T_OrderDetailIsActive = 'Y' - GROUP BY y.T_OrderDetailT_TestID - ORDER BY y.T_OrderDetailT_TestSasCode ASC - ) a1 - - LEFT JOIN t_orderdetail a2 ON a2.T_OrderDetailT_OrderHeaderID = a1.order_id - AND a2.T_OrderDetailIsActive = 'Y' - AND a1.test_sas_code LIKE CONCAT(a2.T_OrderDetailT_testSasCode, '%') - GROUP BY a1.t_testid - order by a1.test_sas_code -"; - $query = $this->db_smartone->query($sql); - $lq = $this->db_smartone->last_query(); - } else { - $sql = " - SELECT a1.*, cOUNT(a2.T_OrderDetailID) level - FROM ( - SELECT IFNULL(y.T_OrderDetailT_TestID, x.T_OrderDetailT_TestID) t_testid, - IFNULL(y.T_OrderDetailT_TestName, y.T_OrderDetailT_TestName) t_testname, - y.T_OrderDetailResult result, y.T_OrderDetailResult result_old, y.T_OrderDetailNote note, y.T_OrderDetailNote note_old, - y.T_OrderDetailID id, - y.T_OrderDetailT_TestIsResult is_result, a.T_TestIsQuantitative is_quantitative, - y.T_OrderDetailResultFlag result_flag, - y.T_OrderDetailNat_NormalValueID normal_id, - y.T_OrderDetailNormalValueNote normal_note, y.T_OrderDetailNat_UnitName unit_name, - y.T_OrderdetailNat_MethodeID methode_id, y.T_OrderdetailNat_MethodeName methode_name, - a.T_TestNat_TestID nattest_id, a.T_TestID tx_id, count(T_ResultInstrumentID) as result_instrument_n, - y.T_OrderDetailVerification, T_OrderSampleReceive sample_receive, - T_OrderSampleProcessing sample_processing, T_OrderSampleWorklistReceive sample_worklist_receive, - IF(T_OrderDetailAddOnPreAnalytic = 'Y', T_OrderDetailAddOnPreAnalytic, PreAnalyticIsOk) pre_analytic, - T_OrderDetailAddOnPreAnalytic, - T_OrderHeaderID order_id, y.T_OrderDetailT_TestSasCode test_sas_code, - tx.T_TestSasCode, - T_OrderDetailAddOnResample `resample`, T_OrderDetailAddOnResampleStatus resample_status, - T_OrderDetailAddOnRef ref, y.T_OrderDetailVerification verification, y.T_OrderDetailValidation validation, - T_OrderPromiseDateTime , Group_ResultName as ResultGroupName - FROM t_orderdetail x - left join t_orderpromise on x.T_OrderDetailT_OrderPromiseID = T_OrderPromiseID - JOIN t_test tx ON x.T_OrderDetailT_TestID = T_TestID - LEFT JOIN group_resultdetail ON Group_ResultDetailT_TestID = x.T_OrderDetailT_TestID AND Group_ResultDetailIsActive = 'Y' - LEFT JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND Group_ResultFlagNonLab = 'N' - LEFT JOIN t_orderdetail y ON x.T_OrderDetailT_TestSasCode LIKE CONCAT(y.T_OrderDetailT_TestSasCode, '%') - AND x.T_OrderDetailT_OrderHeaderID = y.T_OrderDetailT_OrderHeaderID - AND y.T_OrderDetailIsActive = 'Y' - - LEFT JOIN t_orderdetailaddon ON x.T_OrderDetailID = T_OrderDetailAddOnT_OrderDetailID - - JOIN t_orderheader ON y.T_OrderDetailT_OrderHeaderID = T_OrderHeaderID - LEFT JOIN t_test a ON y.T_OrderDetailT_TestID = a.T_TestID - AND a.T_TestIsNonLab = '' - LEFT JOIN (SELECT T_OrderSampleT_SampleTypeID, T_OrderSampleReceive, T_OrderSampleProcessing, T_OrderSampleWorklistReceive - FROM t_ordersample WHERE T_OrderSampleT_OrderHeaderID = {$id} - AND T_OrderSampleIsactive = 'Y' - GROUP BY T_OrderSampleT_SampleTypeID) os ON a.T_TestT_SampleTypeID = os.T_OrderSampleT_SampleTypeID - or os.T_OrderSampleT_SampleTypeID = fn_sampletype_from_local(a.T_TestNat_TestID) - - LEFT JOIN t_resultinstrument ON T_ResultInstrumentT_OrderDetailID = x.T_OrderDetailID - LEFT JOIN pre_analytic ON PreAnalyticNat_TestID = a.T_TestNat_TestID AND PreAnalyticDate = date(now()) and PreAnalyticIsActive = 'Y' - WHERE x.T_OrderDetailT_OrderHeaderID = {$id} - AND x.T_OrderDetailIsActive = 'Y' - GROUP BY y.T_OrderDetailT_TestID - ORDER BY y.T_OrderDetailT_TestSasCode ASC - ) a1 - - LEFT JOIN t_orderdetail a2 ON a2.T_OrderDetailT_OrderHeaderID = a1.order_id - AND a2.T_OrderDetailIsActive = 'Y' - AND a1.test_sas_code LIKE CONCAT(a2.T_OrderDetailT_testSasCode, '%') - GROUP BY a1.t_testid - order by a1.test_sas_code -"; - //echo $sql; - $query = $this->db_smartone->query($sql); - $lq = $this->db_smartone->last_query(); - } - // file_put_contents("/xtmp/re-query.sql",$lq); - - if ($query) { - $rst = []; - $rows = $query->result_array(); - - foreach ($rows as $k => $v) { - - if ($v['is_result'] == "Y" && $v['is_quantitative'] == "N") { - $v['template'] = []; - $x = $this->db_smartone->query("CALL sp_master_resulttemplate_get('{$v['t_testid']}')"); - $this->clean_mysqli_connection($this->db_smartone->conn_id); - if ($x) - $v['template'] = $x->result_array(); - } - - // IF Rujukan, by pas Pre Analytik - if ($v['ref'] == 'Y') - $v['pre_analytic'] = 'Y'; - if ($v["id"] == "885455") { - //sipe workaround - //$v["sample_receive"] = "Y"; - $v["sample_worklist_receive"] = "Y"; - } - $rst[] = $v; - } - - $result = array("total" => $tot_count, "records" => $rst, "total_display" => sizeof($rows), "q" => $lq); - $this->sys_ok($result); - } else { - $this->sys_error_db("RE Px rows", $this->db_smartone); - exit; - } - } - - public function save() - { - $prm = $this->sys_input; - $data = json_decode($prm["data"]); - $lang = $this->lang_default_code; - $lang_id = isset($prm['lang_id']) ? $prm['lang_id'] : '0'; - - if ($lang_id != 0) { - $l = $this->db_smartone->where("Nat_LangID", $lang_id)->get("nat_lang")->row(); - $lang = $l->Nat_LangCode; - } - - $sql_norm = "select T_OrderDetailMinValue, T_OrderDetailMaxValue, - T_OrderDetailMinValueInclusive, T_OrderDetailMaxValueInclusive, - Nat_TestFlagLow, Nat_TestFlagHigh - from t_orderdetail - join t_test on T_OrderDetailT_TestID = T_TestID - join nat_test on T_TestNat_TestID = Nat_TestID and T_TestIsActive = 'Y' - where T_OrderDetailID = ? "; - - $ids = []; - foreach ($data as $k => $v) { - if ($v->resultInstrumentID > 0) { - $sql_i = "select T_ResultInstrumentNat_NormalValueID normalValueID - from t_resultinstrument - where T_ResultInstrumentID = ?"; - $qry_i = $this->db_smartone->query($sql_i, array($v->resultInstrumentID)); - if ($qry_i) { - $rows_i = $qry_i->result_array(); - - if (count($rows_i) > 0) { - $sql_iu = "update t_orderdetail, nat_normalvalue , nat_methode - set T_OrderDetailMinValue = Nat_NormalValueMinValue, - T_OrderDetailMinValueInclusive = Nat_NormalValueMinValueInclusive, - T_OrderDetailMaxValue = Nat_NormalValueMaxValue , - T_OrderDetailMaxValueInclusive = Nat_NormalValueMaxValueInclusive, - T_OrderDetailNormalValueNote = Nat_NormalValueNote, - T_OrderDetailNormalValueDescription = Nat_NormalValueDescription, - T_OrderDetailNat_NormalValueID = Nat_NormalValueID, - T_OrderDetailNat_MethodeID = Nat_NormalValueNat_MethodeID, - T_OrderDetailNat_MethodeName = Nat_MethodeName - where T_OrderDetailID = ? and Nat_NormalValueID = ? - and Nat_NormalValueNat_MethodeID = Nat_MethodeID - "; - $this->db_smartone->query($sql_iu, array($v->id, $rows_i[0]["normalValueID"])); - //file_put_contents("/xtmp/update-nilai-normal", $this->db_smartone->last_query() . "\n", FILE_APPEND); - } - } - } - $y = $this->db_smartone->query("SELECT fn_process_sample_handling_perfect('{$v->order_id}', '{$v->test_id}') c") - ->row(); - $req_status = $y->c; - $qry_norm = $this->db_smartone->query($sql_norm, $v->id); - $result_flag = ""; - if ($qry_norm) { - $rows_norm = $qry_norm->result_array(); - if (count($rows_norm) > 0) { - $r = $rows_norm[0]; - if (is_numeric($v->result)) { - - if ($r["T_OrderDetailMinValueInclusive"] == "Y" && $v->result < $r["T_OrderDetailMinValue"]) { - $result_flag = $r["Nat_TestFlagLow"]; - } - if ($r["T_OrderDetailMinValueInclusive"] == "N" && $v->result <= $r["T_OrderDetailMinValue"]) { - $result_flag = $r["Nat_TestFlagLow"]; - } - if ($r["T_OrderDetailMaxValueInclusive"] == "Y" && $v->result > $r["T_OrderDetailMaxValue"]) { - $result_flag = $r["Nat_TestFlagHigh"]; - } - if ($r["T_OrderDetailMaxValueInclusive"] == "N" && $v->result >= $r["T_OrderDetailMaxValue"]) { - $result_flag = $r["Nat_TestFlagHigh"]; - } - } - } - } - if ($lang == $this->lang_default_code) { - $this->db_smartone->set('T_OrderDetailResult', $v->result) - ->set('T_OrderDetailResultFlag', $result_flag) - ->set('T_OrderDetailNote', $v->note) - ->set('T_OrderDetailReqStatus', $req_status) - ->where('T_OrderDetailID', $v->id) - ->update('t_orderdetail'); - } else { - $this->db_smartone->set('T_OrderDetailLangResult', $v->result) - ->set('T_OrderDetailLangNote', $v->note) - ->where('T_OrderDetailLangID', $v->id) - ->update('t_orderdetaillang'); - } - - $ids[] = $v->id; - } - - // LOG Process - $order = $this->db_smartone->select('T_OrderDetailT_OrderHeaderID id, T_OrderHeaderLabNumber lab_number', false) - ->join('t_orderheader', 'T_OrderHeaderID = T_OrderDetailT_OrderHeaderID') - ->where('T_OrderDetailID', $data[0]->id) - ->get('t_orderdetail') - ->row(); - - $dblog = $this->load->database("onelog", true); - $dblog->set('Log_ProcessCode', 'PROCESS.Result.Entry') - ->set('Log_ProcessOrderID', $order->id) - ->set('Log_ProcessOrderNumber', $order->lab_number) - ->set('Log_ProcessJson', json_encode($data)) - ->set('Log_ProcessUserID', $this->sys_user['M_UserID']) - ->insert('log_process'); - // END OF Log Process - //auto calculation - $this->load->library("Resultcalc"); - $rows = $this->resultcalc->auto($order->id); - - try { - foreach ($ids as $id) { - $this->db_smartone->query("call sp_set_normal_value_flag($id)"); - $this->clean_mysqli_connection($this->db_smartone->conn_id); - } - } catch (Exception $e) { - } - - $this->sys_ok($ids); - } - - public function save_template() - { - $prm = $this->sys_input; - - $n = $this->db_smartone->select("COUNT(T_ResultTemplateID) n") - ->where("T_ResultTemplateT_TestID", $prm['test_id']) - ->where("T_ResultTemplateIsActive", "Y") - ->where("T_ResultTemplateValue", $prm['value']) - ->get('t_resulttemplate') - ->row(); - if ($n->n > 0) { - $this->sys_error_db("Insert Result Template", $this->db_smartone); - return; - } - - $r = $this->db_smartone->set("T_ResultTemplateT_TestID", $prm['test_id']) - ->set("T_ResultTemplateValue", $prm['value']) - ->insert('t_resulttemplate'); - if ($r) { - $template = []; - $x = $this->db_smartone->query("CALL sp_master_resulttemplate_get('{$prm['test_id']}')"); - $this->clean_mysqli_connection($this->db_smartone->conn_id); - if ($x) - $template = $x->result_array(); - - $this->sys_ok($template); - } - } - - public function export() - { - $prm = $this->sys_input; - - $sql = "CALL sp_process_result_lang(?, ?, ?, ?)"; - $query = $this->db_smartone->query($sql, [$prm['order_id'], $prm['lang_id'], $prm['is_si'], $this->sys_user['M_UserID']]); - if ($query) { - $r = $query->row(); - if ($r->status == "OK") { - $this->sys_ok($r->data); - return; - } - - $this->sys_error_db("Message : " . $r->message, $this->db_smartone); - } else { - $this->sys_error_db("Lang Result", $this->db_smartone); - return; - } - } - - public function search_group() - { - $prm = $this->sys_input; - $max_rst = 100; - - // QUERY TOTAL - $sql = "select count(*) total - from t_worklist - where T_WorklistIsActive = 'Y' - order by T_WorklistName ASC"; - $query = $this->db_smartone->query($sql); - - if ($query) { - $tot_count = $query->result_array()[0]["total"]; - } else { - $this->sys_error_db("worklist count", $this->db_smartone); - exit; - } - - $sql = "select T_WorklistID group_id, T_WorklistName group_name - from t_worklist - where T_WorklistIsActive = 'Y' - order by T_WorklistName ASC - limit 0, {$max_rst}"; - $query = $this->db_smartone->query($sql); - - if ($query) { - $rows = $query->result_array(); - foreach ($rows as $k => $v) - $rows[$k]['data'] = json_decode($v['data']); - $result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows), "q" => $this->db_smartone->last_query()); - $this->sys_ok($result); - } else { - $this->sys_error_db("worklist rows", $this->db_smartone); - exit; - } - } - - public function search_rerun() - { - $prm = $this->sys_input; - $id = $prm["detail_id"]; - - $sql = "CALL sp_process_result_rerun(?)"; - $query = $this->db_smartone->query($sql, [$id]); - - if ($query) { - $rows = $query->result_array(); - $this->sys_ok(["records" => $rows]); - } else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - - - function getdoctorsfna() - { - $prm = $this->sys_input; - // $id = $prm["id"]; - - $sql = " SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY M_DoctorName ASC"; - //echo $sql; - $query = $this->db_smartone->query($sql); - - if ($query) { - $rows = $query->result_array(); - $this->sys_ok(["records" => $rows]); - } else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - function getfnaresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT Other_FNADetailsID as xid, - Other_FNAT_OrderDetailID as orderdetail_id, - Other_FNADetailsCode as code, - Other_FNADetailsLabel as label, - Other_FNADetailsResult as result, - IFNULL(Other_FNAM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_FNAM_DoctorID) OR Other_FNAM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_fna - JOIN other_fnadetails ON Other_FNADetailsOther_FNAID = Other_FNAID AND Other_FNADetailsIsActive = 'Y' - LEFT JOIN m_doctor ON Other_FNAM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_FNAT_OrderDetailID = {$id} AND Other_FNAIsActive = 'Y' - GROUP BY Other_FNADetailsID - ORDER BY Other_FNADetailsCode ASC"; - $query = $this->db_smartone->query($sql); - - if ($query) { - $rows = $query->result_array(); - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $images = array(); - $sql = "SELECT So_ImageUploadID as xid, - CONCAT('/one-media/one-image-nonlab/',So_ImageUploadNewName) as image_url - FROM t_orderdetail - JOIN so_imageupload ON So_ImageUploadT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND - So_ImageUploadIsActive = 'Y' - WHERE - T_OrderDetailID = {$id} AND - T_OrderDetailIsActive = 'Y' - GROUP BY So_ImageUploadID"; - $images = $this->db_smartone->query($sql)->result_array(); - - $rst = array('doctors' => $doctors, 'results' => $rows, 'images' => $images); - $this->sys_ok(["records" => $rst]); - } else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - - function uploadimage() - { - if (! $this->isLogin) { - $this->sys_error("Invalid Token"); - exit; - } - - $userid = $this->sys_user["M_UserID"]; - $data = []; - //print_r($_SERVER); - - $prm = $this->sys_input; - $orderid = $this->input->post('orderid'); - $labnumber = $this->input->post('labnumber'); - $sql = "UPDATE so_imageupload SET - So_ImageUploadIsActive = 'N', - So_ImageUploadUserID = {$userid} - WHERE - So_ImageUploadT_OrderHeaderID = {$orderid}"; - //echo $sql; - $this->db_onedev->query($sql); - //$config['upload_path'] = 'assets/'; - - $path = '/home/one/project/one/one-media/one-image-nonlab/'; - //echo $path; - $config['upload_path'] = $path; - $config['allowed_types'] = 'jpg|jpeg|png|gif'; - - $config['max_size'] = '10000'; - $count = count($_FILES['files']['name']); - //echo $count; - $this->load->library('upload', $config); - - $error = []; - for ($i = 0; $i < $count; $i++) { - - - if (!empty($_FILES['files']['name'][$i])) { - - - - $_FILES['file']['name'] = $_FILES['files']['name'][$i]; - - $_FILES['file']['type'] = $_FILES['files']['type'][$i]; - - $_FILES['file']['tmp_name'] = $_FILES['files']['tmp_name'][$i]; - - $_FILES['file']['error'] = $_FILES['files']['error'][$i]; - - $_FILES['file']['size'] = $_FILES['files']['size'][$i]; - - - - $namex = $orderid . '-' . $labnumber . '-' . $this->generateRandomString(5); - //echo $namex; - - $config['file_name'] = $namex; - $this->upload->initialize($config); - //echo $config['file_name'] ; - - - - - - if ($this->upload->do_upload('file')) { - - $uploadData = $this->upload->data(); - - $filename = $uploadData['file_name']; - //echo $filename; - - - $sql = "INSERT INTO so_imageupload ( - So_ImageUploadT_OrderHeaderID, - So_ImageUploadT_OrderHeaderLabNumber, - So_ImageUploadT_SampleTypeID, - So_ImageUploadOldName, - So_ImageUploadNewName, - So_ImageUploadCreated, - So_ImageUploadUserID - ) - VALUES( - {$orderid}, - '{$labnumber}', - '150', - '{$_FILES['files']['name'][$i]}', - '{$filename}', - NOW(), - {$userid} - - )"; - //echo $sql; - $this->db_onedev->query($sql); - $xlast_id = $this->db_onedev->insert_id(); - $data['totalFiles'][] = array('xid' => $xlast_id, 'image_url' => '/one-media/one-image-nonlab/' . $filename); - } else { - $error = array('error' => $this->upload->display_errors()); - } - } - } - - $result = array("total" => count($data['totalFiles']), "records" => $data['totalFiles'], 'errors' => $error); - $this->sys_ok($result); - } - - - function getpatologianatomyresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT Other_PatologiAnatomyID as xid, - Other_PatologiAnatomyT_OrderDetailID as orderdetail_id, - Other_PatologiAnatomyNoSediaan as no_sediaan, - Other_PatologiAnatomyDiagnosaKlinis as diagnosa, - Other_PatologiAnatomyKeteranganKlinis as klinis, - Other_PatologiAnatomyLokasiOrgan as lokasi, - Other_PatologiAnatomyMakroskopik as makroskopik, - Other_PatologiAnatomyMikroskopik as mikroskopik, - Other_PatologiAnatomyKesimpulan as kesimpulan, - IFNULL(Other_PatologiAnatomyM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_PatologiAnatomyM_DoctorID) OR Other_PatologiAnatomyM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_patologi_anatomy - LEFT JOIN m_doctor ON Other_PatologiAnatomyM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_PatologiAnatomyT_OrderDetailID = {$id} AND Other_PatologiAnatomyIsActive = 'Y' - GROUP BY Other_PatologiAnatomyID - ORDER BY Other_PatologiAnatomyID ASC - LIMIT 1"; - $query = $this->db_smartone->query($sql); - - if ($query) { - $rows = $query->row_array(); - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - - $sql = "SELECT So_ImageUploadPatologyAnatomyID as xid, - CONCAT('/one-media/one-image-nonlab/',So_ImageUploadPatologyAnatomyNewName) as image_url, - So_ImageUploadPatologyAnatomyType as type - FROM t_orderdetail - JOIN so_imageupload_patology_anatomy ON So_ImageUploadPatologyAnatomyT_OrderHeaderID= T_OrderDetailT_OrderHeaderID AND - So_ImageUploadPatologyAnatomyIsActive= 'Y' - WHERE - T_OrderDetailID = {$id} AND - T_OrderDetailIsActive = 'Y' - GROUP BY So_ImageUploadPatologyAnatomyID"; - $images = $this->db_smartone->query($sql)->result_array(); - $mikro = []; - $makro = []; - - foreach ($images as $key => $value) { - - if ($value['type'] == 'mikro') { - $mikro[] = $value; - } - if ($value['type'] == 'makro') { - $makro[] = $value; - } - } - - $rst = array('doctors' => $doctors, 'result' => $rows, 'mikro' => $mikro, 'makro' => $makro); - $this->sys_ok(["records" => $rst]); - } else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - - - function generateRandomString($length = 10) - { - $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; - $charactersLength = strlen($characters); - $randomString = ''; - for ($i = 0; $i < $length; $i++) { - $randomString .= $characters[rand(0, $charactersLength - 1)]; - } - return $randomString; - } - - function getcytologiresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT Other_CytologiDetailsID as xid, - Other_CytologiT_OrderDetailID as orderdetail_id, - Other_CytologiDetailsCode as code, - Other_CytologiDetailsLabel as label, - Other_CytologiDetailsResult as result, - IFNULL(Other_CytologiM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_CytologiM_DoctorID) OR Other_CytologiM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_cytologi - JOIN other_cytologidetails ON Other_CytologiDetailsOther_CytologiID = Other_CytologiID AND Other_CytologiDetailsIsActive = 'Y' - LEFT JOIN m_doctor ON Other_CytologiM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_CytologiT_OrderDetailID = {$id} AND Other_CytologiIsActive = 'Y' - GROUP BY Other_CytologiDetailsID - ORDER BY Other_CytologiDetailsCode ASC"; - //echo $sql; - $query = $this->db_smartone->query($sql); - - if ($query) { - $rows = $query->result_array(); - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $rst = array('doctors' => $doctors, 'results' => $rows); - $this->sys_ok(["records" => $rst]); - } else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - function getmikroresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT - Other_MikroID as xid, - Other_MikroHasilBiakan as hasil_biakan, - Other_MikroSampleTypeName as sample_name, - Other_MikroT_OrderDetailID as orderdetail_id, - Other_MikroResult as result_value, - '' as result_other, - IFNULL(T_BacteriaID,0) as T_BacteriaID, - IFNULL(T_BacteriaName,'') as T_BacteriaName, - '' as details, - IFNULL(Other_MikroM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_MikroM_DoctorID) OR Other_MikroM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_mikro - LEFT JOIN t_bacteria ON Other_MikroT_BacteriaID = T_BacteriaID - LEFT JOIN m_doctor ON Other_MikroM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_MikroT_OrderDetailID = {$id} AND Other_MikroIsActive = 'Y' - GROUP BY Other_MikroID"; - //echo $sql; - $query = $this->db_smartone->query($sql); - - if ($query) { - $row = $query->row_array(); - if ($row) { - if ($row['result_value'] != 'Positif' && $row['result_value'] != 'Negatif') { - $row['result_other'] = $row['result_value']; - $row['result_value'] = 'other'; - } - $sql = "SELECT '' as xno, - Other_MikroDetailsID as xid, - Other_MikroDetailsValue as value, - IF(Other_MikroDetailsNote = 'R','Y','N') as chx_r, - IF(Other_MikroDetailsNote = 'I','Y','N') as chx_i, - IF(Other_MikroDetailsNote = 'S','Y','N') as chx_s, - Other_MikroDetailsNote as note, - t_antibiotic.* - FROM other_mikrodetails - LEFT JOIN t_antibiotic ON Other_MikroDetailsT_AntibioticID = T_AntibioticID - WHERE - Other_MikroDetailsOther_MikroID = {$row['xid']} AND Other_MikroDetailsIsActive = 'Y' - GROUP BY Other_MikroDetailsID - ORDER BY T_AntibioticName ASC"; - //echo $sql; - $details = $this->db_smartone->query($sql)->result_array(); - if (details) { - foreach ($details as $k => $v) { - $details[$k]['xno'] = $k + 1; - } - } - $row['details'] = $details; - } else { - $row = array('xid' => '0', 'hasil_biakan' => '', 'result_value' => 'Negatif', 'sample_name' => '', 'orderdetail_id' => $id, 'T_BacteriaID' => '0', 'T_BacteriaName' => '0', 'details' => array(), 'doctor_id' => '0', 'doctor_name' => '0'); - } - } else { - $row = array('xid' => '0', 'hasil_biakan' => '', 'result_value' => 'Negatif', 'sample_name' => '', 'orderdetail_id' => $id, 'T_BacteriaID' => '0', 'T_BacteriaName' => '0', 'details' => array(), 'doctor_id' => '0', 'doctor_name' => '0'); - } - //print_r($row); - - - - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 7 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $sql = " - SELECT '0' as id, 'Belum memilih bakteria' as name - UNION - SELECT T_BacteriaID as id, T_BacteriaName as name - FROM t_bacteria - WHERE - T_BacteriaIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $bacteries = $this->db_smartone->query($sql)->result_array(); - $rst = array('doctors' => $doctors, 'bacteries' => $bacteries, 'results' => $row); - $this->sys_ok(["records" => $rst]); - } - function getantibiotics() - { - $prm = $this->sys_input; - $id = $prm["id"]; - $sql = " SELECT '' as xno, - 0 as xid, - '' as hasil_biakan, - '' as sample_name, - 0 as value, - 'Y' as chx_r, - 'N' as chx_i, - 'N' as chx_s, - 'R' as note, - t_antibiotic.* - FROM t_antibiotic - WHERE - T_AntibioticT_BacteriaID = {$prm['id']} AND T_AntibioticIsActive= 'Y' - ORDER BY T_AntibioticName ASC"; - //echo $sql; - $rows = $this->db_smartone->query($sql)->result_array(); - if (rows) { - foreach ($rows as $k => $v) { - $rows[$k]['xno'] = $k + 1; - } - } - - $this->sys_ok(["records" => $rows]); - } - function getlcprepresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - $sql = " SELECT Other_LcprepDetailsID as xid, - Other_LcprepID as header_id, - Other_LcprepT_orderDetailID as orderdetail_id, - Other_LcprepDetailsCode as code, - Other_LcprepDetailsLabel as label, - Other_LcprepDetailsResult as result, - IFNULL(Other_LcprepM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_LcprepM_DoctorID) OR Other_LcprepM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_lcprep - JOIN other_lcprepdetails ON Other_LcprepDetailsOther_LcprepID = Other_LcprepID AND Other_LcprepDetailsIsActive = 'Y' - LEFT JOIN m_doctor ON Other_LcprepM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_LcprepT_orderDetailID = {$id} AND Other_LcprepIsActive = 'Y' - GROUP BY Other_LcprepDetailsOther_LcprepID, Other_LcprepDetailsCode - ORDER BY Other_LcprepDetailsCode ASC"; - //echo $sql; - $rows = $this->db_smartone->query($sql)->result_array(); - if (!$rows) { - $rows = array( - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'A', - 'label' => 'DESKRIPSI', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ), - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'B', - 'label' => 'KESIMPULAN', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ) - ); - } - - $header_id = $rows[0]['header_id']; - $sql = "SELECT IFNULL(Other_LcprepAdekuasiID,0) as xid, - Lcprep_AdekuasiID as id, - Lcprep_AdekuasiLabel as name, - IF(ISNULL(Other_LcprepAdekuasiID),'N',Other_LcprepAdekuasiChex) as chex - FROM lcprep_adekuasi - LEFT JOIN other_lcprepadekuasi ON Other_LcprepAdekuasiLcprep_AdekuasiID = Lcprep_AdekuasiID AND - Other_LcprepAdekuasiOther_LcprepID = {$header_id} AND - Other_LcprepAdekuasiIsActive = 'Y' - WHERE - Lcprep_AdekuasiIsActive = 'Y' - GROUP BY Lcprep_AdekuasiID - ORDER BY Lcprep_AdekuasiOrder ASC - "; - //echo $sql; - $adeakuasi = $this->db_smartone->query($sql)->result_array(); - foreach ($adeakuasi as $kc => $vc) { - $adeakuasi[$kc]['chex'] = $vc['chex'] == 'N' ? false : true; - } - - $sql = "SELECT IFNULL(Other_LcprepKategoriUmumID,0) as xid, - Lcprep_KategoriUmumID as id, - Lcprep_KategoriUmumLabel as name, - IF(ISNULL(Other_LcprepKategoriUmumID),'N',Other_LcprepKategoriUmumChex) as chex - FROM lcprep_kategoriumum - LEFT JOIN other_lcprepkategoriumum ON Other_LcprepKategoriUmumLcprep_KategoriUmumID = Lcprep_KategoriUmumID AND - Other_LcprepKategoriUmumOther_LcprepID = {$header_id} AND - Other_LcprepKategoriUmumIsActive = 'Y' - WHERE - Lcprep_KategoriUmumIsActive = 'Y' - GROUP BY Lcprep_KategoriUmumID - "; - //echo $sql; - $kategoriumum = $this->db_smartone->query($sql)->result_array(); - foreach ($kategoriumum as $kc => $vc) { - $kategoriumum[$kc]['chex'] = $vc['chex'] == 'N' ? false : true; - } - - $sql = " - SELECT Lcprep_InterpretasiGroupID as group_id, - Lcprep_InterpretasiGroupName as group_name, - '' as subgroups - FROM lcprep_interpretasigroup - WHERE - Lcprep_InterpretasiGroupIsActive = 'Y' - "; - //echo $sql; - $interpretasi = $this->db_smartone->query($sql)->result_array(); - foreach ($interpretasi as $k => $v) { - $subgroups = array(); - $sql = "SELECT Lcprep_InterpretasiSubgroupID as subgroup_id, - Lcprep_InterpretasiSubgroupName as subgroup_name, - '' as childs - FROM lcprep_interpretasisubgroup - WHERE - Lcprep_InterpretasiSubgroupLcprep_InterpretasiGroupID = {$v['group_id']} AND Lcprep_InterpretasiSubgroupIsActive = 'Y'"; - //echo $sql; - $subgroups = $this->db_smartone->query($sql)->result_array(); - if (count($subgroups) > 0) { - foreach ($subgroups as $ki => $vi) { - $childs = array(); - $sql = "SELECT IFNULL(Other_LcprepInterpretasiID,0) as xid, - IFNULL(Other_LcprepInterpretasiChex,'N') as chex, - IFNULL(Other_LcprepInterpretasiValue,'') as value, - Lcprep_InterpretasiID as id, - Lcprep_InterpretasiLcprep_InterpretasiSubgroupID as subgroup_id, - Lcprep_InterpretasiCode as code, - Lcprep_InterpretasiName as name, - Lcprep_InterpretasiParentID as parent_id, - Lcprep_InterpretasiIsParent as is_parent, - Lcprep_InterpretasiHasResult as has_result, - Lcprep_InterpretasiTypeResult as type_result - FROM lcprep_interpretasi - LEFT JOIN other_lcprepinterpretasi ON Other_LcprepInterpretasiOther_LcprepID = {$header_id} AND - Other_LcprepInterpretasiLcprep_InterpretasiID = Lcprep_InterpretasiID AND - Other_LcprepInterpretasiIsActive = 'Y' - WHERE - Lcprep_InterpretasiLcprep_InterpretasiSubgroupID = {$vi['subgroup_id']} AND Lcprep_InterpretasiIsActive = 'Y' - GROUP BY Lcprep_InterpretasiID Order BY Lcprep_InterpretasiCode ASC"; - $childs = $this->db_smartone->query($sql)->result_array(); - if ($childs) { - foreach ($childs as $kc => $vc) { - $childs[$kc]['chex'] = $vc['chex'] == 'N' ? false : true; - } - } - $subgroups[$ki]['childs'] = $childs; - } - } - - $interpretasi[$k]['subgroups'] = $subgroups; - } - - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $rst = array('doctors' => $doctors, 'results' => $rows, 'adekuasi' => $adeakuasi, 'kategoriumum' => $kategoriumum, 'interpretasi' => $interpretasi); - $this->sys_ok(["records" => $rst]); - } - - function getpapsmearresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT Other_PapSmearDetailsID as xid, - Other_PapSmearID as header_id, - Other_PapSmearT_OrderDetailID as orderdetail_id, - Other_PapSmearDetailsCode as code, - Other_PapSmearDetailsLabel as label, - Other_PapSmearDetailsResult as result, - IFNULL(Other_PapSmearM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_PapSmearM_DoctorID) OR Other_PapSmearM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_papsmear - JOIN other_papsmeardetails ON Other_PapSmearDetailsOther_PapSmearID = Other_PapSmearID AND Other_PapSmearDetailsIsActive = 'Y' - LEFT JOIN m_doctor ON Other_PapSmearM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_PapSmearT_OrderDetailID = {$id} AND Other_PapSmearIsActive = 'Y' - GROUP BY Other_PapSmearDetailsID - ORDER BY Other_PapSmearDetailsCode ASC"; - //echo $sql; - $rows = $this->db_smartone->query($sql)->result_array(); - if (!$rows) { - $rows = array( - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'A', - 'label' => 'Makroskopik', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ), - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'B', - 'label' => 'Mikroskopik', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ), - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'C', - 'label' => 'Kesimpulan', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ) - ); - } - - $header_id = $rows[0]['header_id']; - $sql = "SELECT Other_PapSmearMaturasiID as xid, - Other_PapSmearMaturasiValue as value - FROM other_papsmearmaturasi - WHERE - Other_PapSmearMaturasiOther_PapSmearID = {$header_id} AND - Other_PapSmearMaturasiIsActive = 'Y' - "; - //echo $sql; - $dt_maturasi = $this->db_smartone->query($sql)->row_array(); - if (!$dt_maturasi) { - $maturasi = array('xid' => '0', 'value' => array('', '', '')); - } else { - $value = explode('/', $dt_maturasi['value']); - $maturasi = array('xid' => $dt_maturasi['xid'], 'value' => $value); - } - - $sql = "SELECT IFNULL(Other_PapSmearBahanID,0) as xid, - M_PapSmearBahanID as bahan_id, - M_PapSmearBahanName as name, - IF(ISNULL(Other_PapSmearBahanID),'N','Y') as selected - FROM m_papsmearbahan - LEFT JOIN other_papsmearbahan ON Other_PapSmearBahanM_PapSmearBahanID = M_PapSmearBahanID AND - Other_PapSmearBahanOther_PapSmearID = {$header_id} AND - Other_PapSmearBahanIsActive = 'Y' - WHERE - M_PapSmearBahanIsActive = 'Y' - ORDER BY M_PapSmearBahanID ASC - "; - //echo $sql; - $bahans = $this->db_smartone->query($sql)->result_array(); - - $sql = "SELECT IFNULL(Other_PapsmearCategoryID,0) as xid, - M_PapSmearCategoryID as category_id, - M_PapSmearCategoryName as name, - IF(ISNULL(Other_PapsmearCategoryID),'N','Y') as selected - FROM m_papsmearcategory - LEFT JOIN other_papsmearcategory ON Other_PapsmearCategoryM_PapSmearCategoryID = M_PapSmearCategoryID AND - Other_PapsmearCategoryOther_PapSmearID = {$header_id} AND - Other_PapsmearCategoryIsActive = 'Y' - WHERE - M_PapSmearCategoryIsActive = 'Y' - ORDER BY M_PapSmearCategoryID ASC - "; - //echo $sql; - $categories = $this->db_smartone->query($sql)->result_array(); - - $sql = "SELECT IFNULL(Other_PapSmearCheckID,0) as xid, - M_PapSmearCheckID as check_id, - M_PapSmearCheckLabel as name, - IF(ISNULL(Other_PapSmearCheckID),'N','Y') as selected, - Other_PapSmearCheckNote as note - FROM m_papsmearcheck - LEFT JOIN other_papsmearcheck ON Other_PapSmearCheckM_PapSmearCheckID = M_PapSmearCheckID AND - Other_PapSmearCheckOther_PapSmearID = {$header_id} AND - Other_PapSmearCheckIsActive = 'Y' - WHERE - M_PapSmearCheckIsActive = 'Y' - ORDER BY M_PapSmearCheckCode ASC - "; - $checks = $this->db_smartone->query($sql)->result_array(); - - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $rst = array('doctors' => $doctors, 'checks' => $checks, 'bahans' => $bahans, 'categories' => $categories, 'maturasi' => $maturasi, 'results' => $rows); - $this->sys_ok(["records" => $rst]); - } - - function saveresult_lcprep() - { - $prm = $this->sys_input; - $detail_id = $prm['detail_id']; - $doctor_id = $prm['doctor']; - $adekuasi = $prm['adekuasi']; - $kategoriumum = $prm['kategoriumum']; - $interpretasi = $prm['interpretasi']; - $results = $prm['results']; - - $userid = $this->sys_user['M_UserID']; - - $header_id = 0; - $sql = "SELECT * FROM other_lcprep WHERE Other_LcprepT_orderDetailID = {$detail_id} AND Other_LcprepIsActive = 'Y'"; - $dt_header = $this->db_smartone->query($sql)->row_array(); - if ($dt_header) { - $header_id = $dt_header['Other_LcprepID']; - } - if ($header_id == 0) { - $sql = "INSERT INTO other_lcprep( - Other_LcprepT_orderDetailID, - Other_LcprepM_DoctorID, - Other_LcprepUserID, - Other_LcprepCreated - ) - VALUES( - {$detail_id}, - {$doctor_id}, - {$userid}, - NOW() - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } else { - $sql = "UPDATE other_lcprep SET Other_LcprepM_DoctorID = {$doctor_id}, Other_LcprepUserID = {$userid} WHERE Other_LcprepID = {$header_id}"; - $this->db_smartone->query($sql); - } - - if ($adekuasi) { - foreach ($adekuasi as $k => $v) { - $selected = $v['chex'] ? 'Y' : 'N'; - if (intval($v['xid'] == 0)) { - $sql = "UPDATE other_lcprepadekuasi SET Other_LcprepAdekuasiIsActive = 'N' - WHERE - Other_LcprepAdekuasiOther_LcprepID = {$header_id} AND - Other_LcprepAdekuasiIsActive = 'Y' AND - Other_LcprepAdekuasiLcprep_AdekuasiID = {$v['id']}"; - $this->db_smartone->query($sql); - $sql = "INSERT INTO other_lcprepadekuasi ( - Other_LcprepAdekuasiOther_LcprepID, - Other_LcprepAdekuasiLcprep_AdekuasiID, - Other_LcprepAdekuasiChex, - Other_LcprepAdekuasiUserID, - Other_LcprepAdekuasiCreated - ) - VALUES( - {$header_id}, - {$v['id']}, - '{$selected}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - //echo $sql; - } - if (intval($v['xid'] != 0)) { - - $sql = "UPDATE other_lcprepadekuasi SET - Other_LcprepAdekuasiChex = '{$selected}', - Other_LcprepAdekuasiUserID = {$userid} - WHERE - Other_LcprepAdekuasiID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - - //echo $sql; - } - } - - if ($kategoriumum) { - foreach ($kategoriumum as $k => $v) { - $selected = $v['chex'] ? 'Y' : 'N'; - if (intval($v['xid'] == 0)) { - $sql = "UPDATE other_lcprepkategoriumum SET Other_LcprepKategoriUmumIsActive = 'N' - WHERE - Other_LcprepKategoriUmumOther_LcprepID = {$header_id} AND - Other_LcprepKategoriUmumLcprep_KategoriUmumID = {$v['id']} AND - Other_LcprepKategoriUmumIsActive = 'Y' - "; - $this->db_smartone->query($sql); - $sql = "INSERT INTO other_lcprepkategoriumum ( - Other_LcprepKategoriUmumOther_LcprepID, - Other_LcprepKategoriUmumLcprep_KategoriUmumID, - Other_LcprepKategoriUmumChex, - Other_LcprepKategoriUmumUserID, - Other_LcprepKategoriUmumCreated - ) - VALUES( - {$header_id}, - {$v['id']}, - '{$selected}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if (intval($v['xid'] != 0)) { - $sql = "UPDATE other_lcprepkategoriumum SET - Other_LcprepKategoriUmumChex = '{$selected}', - Other_LcprepKategoriUmumUserID = {$userid} - WHERE - Other_LcprepKategoriUmumID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - - //echo $sql; - } - } - - if ($results) { - foreach ($results as $k => $v) { - if (intval($v['xid'] == 0)) { - $sql = "UPDATE other_lcprepdetails SET Other_LcprepDetailsIsActive = 'N' - WHERE - Other_LcprepDetailsOther_LcprepID = {$header_id} AND - Other_LcprepDetailsCode = '{$v['code']}' AND - Other_LcprepDetailsIsActive = 'Y'"; - $this->db_smartone->query($sql); - $sql = "INSERT INTO other_lcprepdetails ( - Other_LcprepDetailsOther_LcprepID, - Other_LcprepDetailsCode, - Other_LcprepDetailsLabel, - Other_LcprepDetailsResult, - Other_LcprepDetailsUserID, - Other_LcprepDetailsCreated - ) - VALUES( - {$header_id}, - '{$v['code']}', - '{$v['label']}', - '{$v['result']}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if (intval($v['xid'] != 0)) { - $sql = "UPDATE other_lcprepdetails SET - Other_LcprepDetailsCode = '{$v['code']}', - Other_LcprepDetailsLabel = '{$v['label']}', - Other_LcprepDetailsResult = '{$v['result']}', - Other_LcprepDetailsUserID = {$userid} - WHERE - Other_LcprepDetailsID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - //echo $sql; - } - } - - if ($interpretasi) { - foreach ($interpretasi as $k => $v) { - if (count($v['subgroups']) > 0) { - foreach ($v['subgroups'] as $ik => $iv) { - if (count($iv['childs']) > 0) { - foreach ($iv['childs'] as $iik => $iiv) { - if (intval($iiv['xid'] == 0)) { - $chex = $iiv['chex'] ? 'Y' : 'N'; - $sql = "UPDATE other_lcprepinterpretasi SET Other_LcprepInterpretasiIsActive = 'N' - WHERE - Other_LcprepInterpretasiOther_LcprepID = {$header_id} AND - Other_LcprepInterpretasiLcprep_InterpretasiID = '{$iiv['id']}' AND - Other_LcprepInterpretasiIsActive = 'Y'"; - $this->db_smartone->query($sql); - $sql = "INSERT INTO other_lcprepinterpretasi ( - Other_LcprepInterpretasiOther_LcprepID, - Other_LcprepInterpretasiLcprep_InterpretasiID, - Other_LcprepInterpretasiChex, - Other_LcprepInterpretasiValue, - Other_LcprepInterpretasiUserID, - Other_LcprepInterpretasiCreated - ) - VALUES( - {$header_id}, - '{$iiv['id']}', - '{$chex}', - '{$iiv['value']}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - - if (intval($iiv['xid'] != 0)) { - $chex = $iiv['chex'] ? 'Y' : 'N'; - $sql = "UPDATE other_lcprepinterpretasi SET - Other_LcprepInterpretasiChex = '{$chex}', - Other_LcprepInterpretasiValue = '{$iiv['value']}', - Other_LcprepInterpretasiUserID = {$userid} - WHERE - Other_LcprepInterpretasiID = {$iiv['xid']}"; - $this->db_smartone->query($sql); - //echo $sql; - - } - } - } - } - } - //echo $sql; - } - } - - - $result = array("total" => 1, "records" => array(), "sql" => ''); - $this->sys_ok($result); - exit; - } - - function saveresult_papsmear() - { - $prm = $this->sys_input; - $detail_id = $prm['detail_id']; - $doctor_id = $prm['doctor']; - $checks = $prm['checks']; - $maturasi = $prm['maturasi']; - $bahans = $prm['bahans']; - $categories = $prm['categories']; - $results = $prm['results']; - - $userid = $this->sys_user['M_UserID']; - - $header_id = 0; - $sql = "SELECT * FROM other_papsmear WHERE Other_PapSmearT_OrderDetailID = {$detail_id} AND Other_PapSmearIsActive = 'Y'"; - $dt_header = $this->db_smartone->query($sql)->row_array(); - if ($dt_header) { - $header_id = $dt_header['Other_PapSmearID']; - } - if ($header_id == 0) { - $sql = "INSERT INTO other_papsmear( - Other_PapSmearT_OrderDetailID, - Other_PapSmearM_DoctorID, - Other_PapSmearUserID, - Other_PapSmearCreated - ) - VALUES( - {$detail_id}, - {$doctor_id}, - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } else { - $sql = "UPDATE other_papsmear SET Other_PapSmearM_DoctorID = {$doctor_id}, Other_PapSmearUserID = {$userid} WHERE Other_PapSmearID = {$header_id}"; - $this->db_smartone->query($sql); - } - - if ($checks) { - foreach ($checks as $k => $v) { - if (intval($v['xid']) == 0 && $v['selected'] === 'Y') { - $sql = "INSERT INTO other_papsmearcheck ( - Other_PapSmearCheckOther_PapSmearID, - Other_PapSmearCheckM_PapSmearCheckID, - Other_PapSmearCheckNote, - Other_PapSmearCheckUserID, - Other_PapSmearCheckCreated - ) - VALUES( - {$header_id}, - {$v['check_id']}, - '{$v['note']}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if (intval($v['xid']) != 0 && $v['selected'] === 'N') { - $sql = "UPDATE other_papsmearcheck SET - Other_PapSmearCheckIsActive = 'N', - Other_PapSmearCheckUserID = {$userid} - WHERE - Other_PapSmearCheckID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - if (intval($v['xid']) != 0 && $v['selected'] === 'Y') { - $sql = "UPDATE other_papsmearcheck SET - Other_PapSmearCheckNote = '{$v['note']}', - Other_PapSmearCheckUserID = {$userid} - WHERE - Other_PapSmearCheckID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - //echo $sql; - } - } - - if ($maturasi) { - if (intval($maturasi['xid']) == 0) { - $value = join("/", $maturasi['value']); - $sql = "INSERT INTO other_papsmearmaturasi ( - Other_PapSmearMaturasiOther_PapSmearID, - Other_PapSmearMaturasiValue, - Other_PapSmearMaturasiUserID, - Other_PapSmearMaturasiCreated - ) - VALUE( - {$header_id}, - '{$value}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - //echo $sql; - } - if (intval($maturasi['xid']) != 0) { - $value = join("/", $maturasi['value']); - $sql = "UPDATE other_papsmearmaturasi SET - Other_PapSmearMaturasiValue = '{$value}', - Other_PapSmearMaturasiUserID = {$userid} - WHERE - Other_PapSmearMaturasiID = {$maturasi['xid']}"; - // echo $sql; - $this->db_smartone->query($sql); - } - } - - if ($bahans) { - foreach ($bahans as $k => $v) { - if (intval($v['xid']) == 0 && $v['selected'] === 'Y') { - $sql = "INSERT INTO other_papsmearbahan ( - Other_PapSmearBahanOther_PapSmearID, - Other_PapSmearBahanM_PapSmearBahanID, - Other_PapSmearBahanUserID, - Other_PapSmearBahanCreated - ) - VALUES( - {$header_id}, - {$v['bahan_id']}, - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if (intval($v['xid']) != 0 && $v['selected'] === 'N') { - $sql = "UPDATE other_papsmearbahan SET - Other_PapSmearBahanIsActive = 'N', - Other_PapsmearCategoryUserID = {$userid} - WHERE - Other_PapSmearBahanID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - if (intval($v['xid']) != 0 && $v['selected'] === 'Y') { - $sql = "UPDATE other_papsmearbahan SET - Other_PapSmearBahanIsActive = 'Y', - Other_PapsmearCategoryUserID = {$userid} - WHERE - Other_PapSmearBahanID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - //echo $sql; - } - } - - if ($categories) { - foreach ($categories as $k => $v) { - if (intval($v['xid']) == 0 && $v['selected'] === 'Y') { - $sql = "INSERT INTO other_papsmearcategory ( - Other_PapsmearCategoryOther_PapSmearID, - Other_PapsmearCategoryM_PapSmearCategoryID, - Other_PapsmearCategoryUserID, - Other_PapsmearCategoryCreated - ) - VALUES( - {$header_id}, - {$v['category_id']}, - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if (intval($v['xid']) != 0 && $v['selected'] === 'N') { - $sql = "UPDATE other_papsmearcategory SET - Other_PapsmearCategoryIsActive = 'N', - Other_PapsmearCategoryUserID = {$userid} - WHERE - Other_PapsmearCategoryID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - //echo $sql; - if (intval($v['xid']) != 0 && $v['selected'] === 'Y') { - $sql = "UPDATE other_papsmearcategory SET - Other_PapsmearCategoryIsActive = 'Y', - Other_PapsmearCategoryUserID = {$userid} - WHERE - Other_PapsmearCategoryID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - } - } - - if ($results) { - foreach ($results as $k => $v) { - if (intval($v['xid']) == 0) { - $sql = "INSERT INTO other_papsmeardetails ( - Other_PapSmearDetailsOther_PapSmearID, - Other_PapSmearDetailsCode, - Other_PapSmearDetailsLabel, - Other_PapSmearDetailsResult, - Other_PapSmearDetailsUserID, - Other_PapSmearDetailsCreated - ) - VALUES( - {$header_id}, - '{$v['code']}', - '{$v['label']}', - '{$v['result']}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if (intval($v['xid']) != 0) { - $sql = "UPDATE other_papsmeardetails SET - Other_PapSmearDetailsCode = '{$v['code']}', - Other_PapSmearDetailsLabel = '{$v['label']}', - Other_PapSmearDetailsResult = '{$v['result']}', - Other_PapSmearDetailsUserID = {$userid} - WHERE - Other_PapSmearDetailsID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - //echo $sql; - } - } - - $result = array("total" => 1, "records" => array(), "sql" => ''); - $this->sys_ok($result); - exit; - } - - function saveresult_fna() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = $inp['doctor']; - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - if ($prm[0]['xid'] == '0') { - $sql = "INSERT INTO other_fna( - Other_FNAM_DoctorID, - Other_FNAT_OrderDetailID, - Other_FNAUserID, - Other_FNACreated - ) - VALUES( - {$doctor_id}, - {$prm[0]['orderdetail_id']}, - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } else { - $sql = "SELECT * FROM other_fna WHERE Other_FNAT_OrderDetailID = {$prm[0]['orderdetail_id']} AND Other_FNAIsActive = 'Y'"; - $data_header = $this->db_smartone->query($sql)->row_array(); - $header_id = $data_header['Other_FNAID']; - $sql = "UPDATE other_fna SET - Other_FNAM_DoctorID = {$doctor_id}, - Other_FNAUserID = {$userid} - WHERE - Other_FNAID = {$header_id}"; - $this->db_smartone->query($sql); - } - foreach ($prm as $k => $v) { - if ($v['xid'] == '0') { - $results = str_replace("'", "\\'", $v['result']); - $sql = "INSERT INTO other_fnadetails( - Other_FNADetailsOther_FNAID , - Other_FNADetailsCode, - Other_FNADetailsLabel, - Other_FNADetailsResult, - Other_FNADetailsCreated, - Other_FNADetailsUserID - ) - VALUES( - {$header_id}, - '{$v['code']}', - '{$v['label']}', - '{$results}', - NOW(), - {$userid} - )"; - $query = $this->db_smartone->query($sql); - } else { - $results = str_replace("'", "\\'", $v['result']); - $sql = "UPDATE other_fnadetails SET - Other_FNADetailsResult = '{$results}', - Other_FNADetailsUserID = {$userid} - WHERE - Other_FNADetailsID = {$v['xid']}"; - $query = $this->db_smartone->query($sql); - } - } - - $result = array("total" => 1, "records" => array(), "sql" => ''); - $this->sys_ok($result); - exit; - } - - function saveresult_cytologi() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = $inp['doctor']; - - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - if ($prm[0]['xid'] == '0') { - $sql = "INSERT INTO other_cytologi( - Other_CytologiT_OrderDetailID, - Other_CytologiM_DoctorID, - Other_CytologiUserID, - Other_CytologiCreated - ) - VALUES( - {$prm[0]['orderdetail_id']}, - {$doctor_id}, - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } else { - $sql = "SELECT * FROM other_cytologi WHERE Other_CytologiT_OrderDetailID = {$prm[0]['orderdetail_id']} AND Other_CytologiIsActive = 'Y'"; - $data_header = $this->db_smartone->query($sql)->row_array(); - $header_id = $data_header['Other_CytologiID']; - $sql = "UPDATE other_cytologi SET - Other_CytologiM_DoctorID = {$doctor_id}, - Other_CytologiUserID = {$userid} - WHERE - Other_CytologiID = {$header_id}"; - $this->db_smartone->query($sql); - } - foreach ($prm as $k => $v) { - if ($v['xid'] == '0') { - $results = str_replace("'", "\\'", $v['result']); - $sql = "INSERT INTO other_cytologidetails( - Other_CytologiDetailsOther_CytologiID , - Other_CytologiDetailsCode, - Other_CytologiDetailsLabel, - Other_CytologiDetailsResult, - Other_CytologiDetailsCreated, - Other_CytologiDetailsUserID - ) - VALUES( - {$header_id}, - '{$v['code']}', - '{$v['label']}', - '{$results}', - NOW(), - {$userid} - )"; - $query = $this->db_smartone->query($sql); - } else { - $results = str_replace("'", "\\'", $v['result']); - $sql = "UPDATE other_cytologidetails SET - Other_CytologiDetailsResult = '{$results}', - Other_CytologiDetailsUserID = {$userid} - WHERE - Other_CytologiDetailsID = {$v['xid']}"; - $query = $this->db_smartone->query($sql); - } - } - - $result = array("total" => 1, "records" => array(), "sql" => ''); - $this->sys_ok($result); - exit; - } - - function saveresult_mikro() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = $inp['doctor']; - $backteria_id = $inp['bacteria']; - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - - if ($inp['result_value'] != 'Negatif' && $inp['result_value'] != 'Positif') { - $prm['result_value'] = $prm['result_other']; - } else { - $prm['result_value'] = $inp['result_value']; - } - - if ($prm['xid'] == '0') { - $sql = "INSERT INTO other_mikro( - Other_MikroM_DoctorID, - Other_MikroResult, - Other_MikroT_BacteriaID, - Other_MikroT_OrderDetailID, - Other_MikroHasilBiakan, - Other_MikroSampleTypeName, - Other_MikroUserID, - Other_MikroCreated - ) - VALUES( - {$doctor_id}, - '{$prm['result_value']}', - {$backteria_id}, - {$prm['orderdetail_id']}, - '{$prm['hasil_biakan']}', - '{$prm['sample_name']}', - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } else { - $sql = "SELECT * FROM other_mikro WHERE Other_MikroT_OrderDetailID = {$prm['orderdetail_id']} AND Other_MikroIsActive = 'Y'"; - $data_header = $this->db_smartone->query($sql)->row_array(); - $header_id = $data_header['Other_MikroID']; - $sql = "UPDATE other_mikro SET - Other_MikroResult = '{$prm['result_value']}', - Other_MikroM_DoctorID = {$doctor_id}, - Other_MikroT_BacteriaID = {$backteria_id}, - Other_MikroHasilBiakan = '{$prm['hasil_biakan']}', - Other_MikroSampleTypeName = '{$prm['sample_name']}', - Other_MikroUserID = {$userid} - WHERE - Other_MikroID = {$header_id}"; - //echo $sql; - $this->db_smartone->query($sql); - } - - - - $sql = "UPDATE other_mikrodetails SET Other_MikroDetailsIsActive = 'N', Other_MikroDetailsUserID = 0 WHERE Other_MikroDetailsOther_MikroID = {$header_id}"; - $this->db_smartone->query($sql); - - $results = $prm['details']; - if ($inp['result_value'] == 'Positif') { - foreach ($results as $k => $v) { - if ($v['xid'] == '0') { - $sql = "INSERT INTO other_mikrodetails( - Other_MikroDetailsOther_MikroID , - Other_MikroDetailsT_AntibioticID, - Other_MikroDetailsValue, - Other_MikroDetailsNote, - Other_MikroDetailsCreated, - Other_MikroDetailsUserID - ) - VALUES( - {$header_id}, - '{$v['T_AntibioticID']}', - '{$v['value']}', - '{$v['note']}', - NOW(), - {$userid} - )"; - $query = $this->db_smartone->query($sql); - } else { - $sql = "UPDATE other_mikrodetails SET - Other_MikroDetailsT_AntibioticID = '{$v['T_AntibioticID']}', - Other_MikroDetailsValue = '{$v['value']}', - Other_MikroDetailsNote = '{$v['note']}', - Other_MikroDetailsIsActive = 'Y', - Other_MikroDetailsUserID = {$userid} - WHERE - Other_MikroDetailsID = {$v['xid']}"; - //echo $sql; - $query = $this->db_smartone->query($sql); - } - } - } - - - $result = array("total" => 1, "records" => array(), "sql" => ''); - $this->sys_ok($result); - exit; - } - - - function get_doctors_preparasi_sperma() - { - $prm = $this->sys_input; - // $id = $prm["id"]; - - $sql = " SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 10 AND - M_DoctorSOIsActive = 'Y' - ORDER BY M_DoctorName ASC"; - //echo $sql; - $query = $this->db_smartone->query($sql); - $rows = $query->result_array(); - $sql = " - SELECT '0' as id, 'Belum memilih metode' as name - UNION - SELECT M_MethodeSpermaID as id, M_MethodeSpermaName as name - FROM m_methodesperma - WHERE - M_MethodeSpermaIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $methodes = $this->db_smartone->query($sql)->result_array(); - - - $this->sys_ok(["records" => $rows, "methodes" => $methodes]); - } - - - function getpreparasispermaresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT other_preparasisperma.*, - Other_PreparasiSpermaID as xid, - Other_PreparasiSpermaT_OrderDetailID as orderdetail_id, - IFNULL(Other_PreparasiSpermaM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_PreparasiSpermaM_DoctorID) OR Other_PreparasiSpermaM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name, - IFNULL(M_MethodeSpermaID,0) as methode_id, - IFNULL(M_MethodeSpermaName,'') as methode_name - FROM other_preparasisperma - LEFT JOIN m_doctor ON Other_PreparasiSpermaM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - LEFT JOIN m_methodesperma ON Other_PreparasiSpermaM_MethodeSpermaID = M_MethodeSpermaID AND - M_MethodeSpermaIsActive = 'Y' - WHERE - Other_PreparasiSpermaT_OrderDetailID = {$id} AND Other_PreparasiSpermaIsActive = 'Y' - GROUP BY Other_PreparasiSpermaID"; - $query = $this->db_smartone->query($sql); - - if ($query) { - $rows = $query->row_array(); - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 10 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $sql = " - SELECT '0' as id, 'Belum memilih metode' as name - UNION - SELECT M_MethodeSpermaID as id, M_MethodeSpermaName as name - FROM m_methodesperma - WHERE - M_MethodeSpermaIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $methodes = $this->db_smartone->query($sql)->result_array(); - $images = array(); - $sql = "SELECT Other_PreparasiSpermaImgID as xid, - Other_PreparasiSpermaImgType as type, - CONCAT('/one-media/one-image-nonlab/',Other_PreparasiSpermaImgNewName) as image_url - FROM t_orderdetail - JOIN other_preparasisperma_img ON Other_PreparasiSpermaImgT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND - Other_PreparasiSpermaImgIsActive = 'Y' - WHERE - T_OrderDetailID = {$id} AND - T_OrderDetailIsActive = 'Y' - GROUP BY Other_PreparasiSpermaImgID"; - //echo $sql; - $images = $this->db_smartone->query($sql)->result_array(); - - $rst = array('doctors' => $doctors, 'methodes' => $methodes, 'results' => $rows, 'images' => $images); - $this->sys_ok(["records" => $rst]); - } else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - - function uploadimage_preparasi_sperma() - { - if (! $this->isLogin) { - $this->sys_error("Invalid Token"); - exit; - } - - $userid = $this->sys_user["M_UserID"]; - $data = []; - //print_r($_SERVER); - - $prm = $this->sys_input; - $orderid = $this->input->post('orderid'); - $type = $this->input->post('type'); - $labnumber = $this->input->post('labnumber'); - $sql = "UPDATE other_preparasisperma_img SET - Other_PreparasiSpermaImgIsActive = 'N', - Other_PreparasiSpermaImgUserID = {$userid} - WHERE - Other_PreparasiSpermaImgT_OrderHeaderID = {$orderid} AND - Other_PreparasiSpermaImgType = '{$type}'"; - //echo $sql; - $this->db_onedev->query($sql); - //$config['upload_path'] = 'assets/'; - - $path = '/home/one/project/one/one-media/one-image-nonlab/'; - //echo $path; - $config['upload_path'] = $path; - $config['allowed_types'] = 'jpg|jpeg|png|gif'; - - $config['max_size'] = '10000'; - $count = count($_FILES['files']['name']); - //echo $count; - $this->load->library('upload', $config); - - $error = []; - for ($i = 0; $i < $count; $i++) { - - - if (!empty($_FILES['files']['name'][$i])) { - - - - $_FILES['file']['name'] = $_FILES['files']['name'][$i]; - - $_FILES['file']['type'] = $_FILES['files']['type'][$i]; - - $_FILES['file']['tmp_name'] = $_FILES['files']['tmp_name'][$i]; - - $_FILES['file']['error'] = $_FILES['files']['error'][$i]; - - $_FILES['file']['size'] = $_FILES['files']['size'][$i]; - - - - $namex = $orderid . '-' . $labnumber . '-' . $this->generateRandomString(5); - //echo $namex; - - $config['file_name'] = $namex; - $this->upload->initialize($config); - //echo $config['file_name'] ; - - - - - - if ($this->upload->do_upload('file')) { - - $uploadData = $this->upload->data(); - - $filename = $uploadData['file_name']; - //echo $filename; - - - $sql = "INSERT INTO other_preparasisperma_img ( - Other_PreparasiSpermaImgT_OrderHeaderID, - Other_PreparasiSpermaImgType, - Other_PreparasiSpermaImgOldName, - Other_PreparasiSpermaImgNewName, - Other_PreparasiSpermaImgCreated, - Other_PreparasiSpermaImgUserID - ) - VALUES( - {$orderid}, - '{$type}', - '{$_FILES['files']['name'][$i]}', - '{$filename}', - NOW(), - {$userid} - - )"; - //echo $sql; - $this->db_onedev->query($sql); - $xlast_id = $this->db_onedev->insert_id(); - $data['totalFiles'][] = array('xid' => $xlast_id, 'type' => $type, 'image_url' => '/one-media/one-image-nonlab/' . $filename); - } else { - $error = array('error' => $this->upload->display_errors()); - } - } - } - - $result = array("total" => count($data['totalFiles']), "records" => $data['totalFiles'], 'errors' => $error); - $this->sys_ok($result); - } - - - function saveresult_preparasi_sperma() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = $inp['doctor']; - $orderdetail_id = $inp['orderdetailid']; - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - if ($prm['xid'] == '0') { - $sql = "INSERT INTO other_preparasisperma( - Other_PreparasiSpermaM_DoctorID, - Other_PreparasiSpermaT_OrderDetailID, - Other_PreparasiSpermaPreMotilitasA, - Other_PreparasiSpermaPreMotilitasB, - Other_PreparasiSpermaPreMotilitasC, - Other_PreparasiSpermaPreKonsentrasi, - Other_PreparasiSpermaPreKontaminan, - Other_PreparasiSpermaPostMotilitasA, - Other_PreparasiSpermaPostMotilitasB, - Other_PreparasiSpermaPostMotilitasC, - Other_PreparasiSpermaPostKonsentrasi, - Other_PreparasiSpermaPostKontaminan, - Other_PreparasiSpermaPreVolume, - Other_PreparasiSpermaPostVolume, - Other_PreparasiSpermaM_MethodeSpermaID, - Other_PreparasiSpermaNote, - Other_PreparasiSpermaUserID, - Other_PreparasiSpermaCreated - ) - VALUES( - {$doctor_id}, - {$orderdetail_id}, - '{$prm['Other_PreparasiSpermaPreMotilitasA']}', - '{$prm['Other_PreparasiSpermaPreMotilitasB']}', - '{$prm['Other_PreparasiSpermaPreMotilitasC']}', - '{$prm['Other_PreparasiSpermaPreKonsentrasi']}', - '{$prm['Other_PreparasiSpermaPreKontaminan']}', - '{$prm['Other_PreparasiSpermaPostMotilitasA']}', - '{$prm['Other_PreparasiSpermaPostMotilitasB']}', - '{$prm['Other_PreparasiSpermaPostMotilitasC']}', - '{$prm['Other_PreparasiSpermaPostKonsentrasi']}', - '{$prm['Other_PreparasiSpermaPostKontaminan']}', - '{$prm['Other_PreparasiSpermaPreVolume']}', - '{$prm['Other_PreparasiSpermaPostVolume']}', - '{$prm['Other_PreparasiSpermaM_MethodeSpermaID']}', - '{$prm['Other_PreparasiSpermaNote']}', - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } else { - $sql = "SELECT * FROM other_preparasisperma WHERE Other_PreparasiSpermaT_OrderDetailID = {$orderdetail_id} AND Other_PreparasiSpermaIsActive = 'Y'"; - $data_header = $this->db_smartone->query($sql)->row_array(); - $header_id = $data_header['Other_PreparasiSpermaID']; - $sql = "UPDATE other_preparasisperma SET - Other_PreparasiSpermaM_DoctorID = {$doctor_id}, - Other_PreparasiSpermaPreMotilitasA = '{$prm['Other_PreparasiSpermaPreMotilitasA']}', - Other_PreparasiSpermaPreMotilitasB = '{$prm['Other_PreparasiSpermaPreMotilitasB']}', - Other_PreparasiSpermaPreMotilitasC = '{$prm['Other_PreparasiSpermaPreMotilitasC']}', - Other_PreparasiSpermaPreKonsentrasi = '{$prm['Other_PreparasiSpermaPreKonsentrasi']}', - Other_PreparasiSpermaPreKontaminan = '{$prm['Other_PreparasiSpermaPreKontaminan']}', - Other_PreparasiSpermaPostMotilitasA = '{$prm['Other_PreparasiSpermaPostMotilitasA']}', - Other_PreparasiSpermaPostMotilitasB = '{$prm['Other_PreparasiSpermaPostMotilitasB']}', - Other_PreparasiSpermaPostMotilitasC = '{$prm['Other_PreparasiSpermaPostMotilitasC']}', - Other_PreparasiSpermaPostKonsentrasi = '{$prm['Other_PreparasiSpermaPostKonsentrasi']}', - Other_PreparasiSpermaPostKontaminan = '{$prm['Other_PreparasiSpermaPostKontaminan']}', - Other_PreparasiSpermaPreVolume = '{$prm['Other_PreparasiSpermaPreVolume']}', - Other_PreparasiSpermaPostVolume = '{$prm['Other_PreparasiSpermaPostVolume']}', - Other_PreparasiSpermaM_MethodeSpermaID = '{$prm['Other_PreparasiSpermaM_MethodeSpermaID']}', - Other_PreparasiSpermaNote = '{$prm['Other_PreparasiSpermaNote']}', - Other_PreparasiSpermaUserID = {$userid} - WHERE - Other_PreparasiSpermaID = {$header_id}"; - $this->db_smartone->query($sql); - } - - - $result = array("total" => 1, "records" => array(), "sql" => ''); - $this->sys_ok($result); - exit; - } - - function getdnafragmentasiresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT other_dnafragmentasi.*, - Other_DnaFragmentasiID as xid, - Other_DnaFragmentasiT_OrderDetailID as orderdetail_id, - IFNULL(Other_DnaFragmentasiM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_DnaFragmentasiM_DoctorID) OR Other_DnaFragmentasiM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name, - IFNULL(Other_DnaFragmentasiOther_DnaFragmentasiMethodeID,0) as methode_id, - IFNULL(Other_DnaFragmentasiMethodeName,'') as methode_name, - Other_DnaFragmentasiHaloLuas as halo_luas, - Other_DnaFragmentasiHaloSedang as halo_sedang, - Other_DnaFragmentasiHaloSempit as halo_sempit, - Other_DnaFragmentasiTanpaHalo as tanpa_halo, - Other_DnaFragmentasiDFI as dfi, - Other_DnaFragmentasiKesimpulan as kesimpulan, - Other_DnaFragmentasiCatatan as catatan - FROM other_dnafragmentasi - LEFT JOIN m_doctor ON Other_DnaFragmentasiM_DoctorID = M_DoctorID - LEFT JOIN other_dnafragmentasimethode ON Other_DnaFragmentasiOther_DnaFragmentasiMethodeID = Other_DnaFragmentasiMethodeID - WHERE - Other_DnaFragmentasiT_OrderDetailID = {$id} AND Other_DnaFragmentasiIsActive = 'Y' - GROUP BY Other_DnaFragmentasiID - LIMIT 1"; - //echo $sql; - $query = $this->db_smartone->query($sql); - - if ($query) { - $rows = $query->row_array(); - if (!$rows) { - $rows = array( - 'xid' => 0, - 'orderdetail_id' => $id, - 'doctor_id' => 0, - 'doctor_name' => '', - 'methode_id' => 0, - 'methode_name' => '', - 'halo_luas' => '', - 'halo_sedang' => '', - 'tanpa_halo' => '', - 'dfi' => '', - 'kesimpulan' => '', - 'catatan' => '' - ); - } - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID - WHERE - M_DoctorSONat_SubGroupID = 4 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - - $sql = " - SELECT '0' as id, 'Belum memilih metode' as name - UNION - SELECT Other_DnaFragmentasiMethodeID as id, Other_DnaFragmentasiMethodeName as name - FROM other_dnafragmentasimethode - WHERE - Other_DnaFragmentasiMethodeIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $methodes = $this->db_smartone->query($sql)->result_array(); - - - $rst = array('doctors' => $doctors, 'methodes' => $methodes, 'results' => $rows); - $this->sys_ok(["records" => $rst]); - } else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - function saveresult_dnafragmentasi() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = $inp['doctor']['id']; - $methode_id = $inp['methode']['id']; - $orderdetail_id = $inp['results']['orderdetail_id']; - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - if (intval($prm['xid']) == 0) { - $sql = "INSERT INTO other_dnafragmentasi( - Other_DnaFragmentasiT_OrderDetailID, - Other_DnaFragmentasiM_DoctorID, - Other_DnaFragmentasiOther_DnaFragmentasiMethodeID, - Other_DnaFragmentasiHaloLuas, - Other_DnaFragmentasiHaloSedang, - Other_DnaFragmentasiHaloSempit, - Other_DnaFragmentasiTanpaHalo, - Other_DnaFragmentasiDFI, - Other_DnaFragmentasiKesimpulan, - Other_DnaFragmentasiCatatan, - Other_DnaFragmentasiUserID, - Other_DnaFragmentasiLastUpdated - ) - VALUES( - {$orderdetail_id}, - {$doctor_id}, - {$methode_id}, - '{$prm['halo_luas']}', - '{$prm['halo_sedang']}', - '{$prm['halo_sempit']}', - '{$prm['tanpa_halo']}', - '{$prm['dfi']}', - '{$prm['kesimpulan']}', - '{$prm['catatan']}', - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } else { - $sql = "UPDATE other_dnafragmentasi SET - Other_DnaFragmentasiT_OrderDetailID = {$orderdetail_id}, - Other_DnaFragmentasiM_DoctorID = {$doctor_id}, - Other_DnaFragmentasiOther_DnaFragmentasiMethodeID = '{$methode_id}', - Other_DnaFragmentasiHaloLuas = '{$prm['halo_luas']}', - Other_DnaFragmentasiHaloSedang = '{$prm['halo_sedang']}', - Other_DnaFragmentasiHaloSempit = '{$prm['halo_sempit']}', - Other_DnaFragmentasiTanpaHalo = '{$prm['tanpa_halo']}', - Other_DnaFragmentasiDFI = '{$prm['dfi']}', - Other_DnaFragmentasiKesimpulan = '{$prm['kesimpulan']}', - Other_DnaFragmentasiCatatan = '{$prm['catatan']}', - Other_DnaFragmentasiLastUpdated = NOW(), - Other_DnaFragmentasiUserID = {$userid} - WHERE - Other_DnaFragmentasiID = {$prm['xid']}"; - //echo $sql; - $this->db_smartone->query($sql); - } - - - $result = array("total" => 1, "records" => array(), "sql" => ''); - $this->sys_ok($result); - exit; - } -} +db_smartone = $this->load->database("onedev", true); + $this->load->helper(array('form', 'url')); + } + function getMethodeID($natTestID) + { + $sql = "select M_MethodePriorityNat_MethodeID MethodeID, Nat_MethodeName + from + m_methode_priority + join nat_methode on Nat_MethodeID = M_MethodePriorityNat_MethodeID + and Nat_MethodeIsActive = 'Y' + join m_instrumentmethode on M_InstrumentMethodeNat_MethodeID = Nat_MethodeID and M_InstrumentMethodeIsActive = 'Y' + join nat_instrument on M_InstrumentMethodeNat_InstrumentID = Nat_InstrumentID + and Nat_InstrumentIsActive ='Y' + where M_MethodePriorityIsActive = 'Y' + and M_MethodePriorityNat_TestID = $natTestID + and M_MethodePriorityM_DayOfWeekID = dayofweek(now()) + order by M_MethodePriorityNumber desc + limit 0,1 "; + $qry = $this->db->query($sql); + if ($qry) { + $rows = $qry->result_array(); + if (count($rows) > 0) return array($rows[0]["MethodeID"], $rows[0]["Nat_MethodeName"]); + } + //2nd + $sql = "select + M_InstrumentMethodeNat_MethodeID MethodeID, Nat_MethodeName + from m_instrumentmethode + join nat_methode on M_InstrumentMethodeNat_MethodeID = Nat_MethodeID + and Nat_MethodeIsActive = 'Y' + join nat_instrument on M_InstrumentMethodeNat_InstrumentID = Nat_InstrumentID + and Nat_InstrumentIsActive ='Y' + where M_InstrumentMethodeNat_TestID = $natTestID + and M_InstrumentMethodeIsActive = 'Y' + order by M_InstrumentMethodePriority desc + limit 0,1"; + $qry = $this->db->query($sql); + if ($qry) { + $rows = $qry->result_array(); + if (count($rows) > 0) return array($rows[0]["MethodeID"], $rows[0]["Nat_MethodeName"]); + } + // + $sql = "select Nat_NormalValueNat_MethodeID MethodeID, Nat_MethodeName + from + nat_normalvalue + join nat_methode on Nat_NormalValueNat_MethodeID = Nat_MethodeID + and Nat_MethodeIsActive = 'Y' + where Nat_NormalValueNat_TestID = $natTestID + and Nat_NormalValueIsActive = 'Y' + order by Nat_NormalValueID + limit 0,1"; + $qry = $this->db->query($sql); + if ($qry) { + $rows = $qry->result_array(); + if (count($rows) > 0) return array($rows[0]["MethodeID"], $rows[0]["Nat_MethodeName"]); + } + return array(0, ""); + } + function get_normal_value($methodeID, $natTestID, $sexID, $ageInDay) + { + $this->load->library('ibl_sampling_normal'); + return $this->ibl_sampling_normal->get_normal_value_id($methodeID, $natTestID, $sexID, $ageInDay); + } + return 0; + } + function fn_fix_normal($order_id) + { + $sql = "select + T_OrderDetailID, M_PatientM_SexID, fn_global_age_count_day(M_PatientDOB, date(T_OrderHeaderDate)) Dob , + T_TestNat_TestID + from t_orderheader + join m_patient on T_OrderHeaderID = $order_id and T_OrderHeaderM_PatientID = M_PatientID + join t_orderdetail on T_OrderDetailT_OrderHeaderID = T_OrderHeaderID + and T_OrderDetailIsACtive = 'Y' + and ( T_OrderDetailNat_NormalValueID is null or T_OrderDetailNat_NormalValueID = 0 ) + join t_test on T_OrderDetailT_TestID = T_TestID and T_TestIsResult = 'Y' "; + $qry = $this->db->query($sql); + if (! $qry) { + return; + } + $rows = $qry->result_array(); + if (count($rows) == 0) return; + $sql_u = "update t_orderdetail + join nat_normalvalue on T_OrderDetailID = ? and Nat_NormalValueID = ? + set + T_OrderDetailNat_NormalValueID = Nat_NormalValueID, + T_OrderDetailNormalValueNote = Nat_NormalValueNote, + T_OrderDetailNormalValueDescription = Nat_NormalValueDescription, + T_OrderDetailMinValue = Nat_NormalValueMinValue, + T_OrderDetailMaxValue = Nat_NormalValueMaxValue, + T_OrderDetailMinValueInclusive = Nat_NormalValueMinValueInclusive, + T_OrderDetailMaxValueInclusive = Nat_NormalValueMaxValueInclusive, + T_OrderDetailNat_MethodeID = ?, + T_OrderdetailNat_MethodeName =?"; + + foreach ($rows as $r) { + $T_OrderDetailID = $r["T_OrderDetailID"]; + $sexID = $r["M_PatientM_SexID"]; + $ageInDay = $r["Dob"]; + $natTestID = $r["T_TestNat_TestID"]; + list($methodeID, $methodeName) = $this->getMethodeID($natTestID); + if ($methodeID == 0) continue; + $normalValueID = $this->get_normal_value($methodeID, $natTestID, $sexID, $ageInDay); + if ($normalValueID == 0) return; + $this->db->query($sql_u, array($T_OrderDetailID, $normalValueID, $methodeID, $methodeName)); + } + } + function update_order_sample($targetID, $sourceID) + { + $sql = "update t_ordersample target + join t_ordersample source on + target.T_OrderSampleID = ? + and target.T_OrderSampleWorklistReceive = 'N' + and source.T_OrderSampleID = ? + set + target.T_OrderSampleSampling = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSampling, source.T_OrderSampleSampling), + target.T_OrderSampleSamplingDate = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingDate, source.T_OrderSampleSamplingDate), + target.T_OrderSampleSamplingTime = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingTime, source.T_OrderSampleSamplingTime), + target.T_OrderSampleSamplingUserID = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingUserID, source.T_OrderSampleSamplingUserID), + + target.T_OrderSampleReceive = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceive, source.T_OrderSampleReceive), + target.T_OrderSampleReceiveDate = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveDate, source.T_OrderSampleReceiveDate), + target.T_OrderSampleReceiveTime = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveTime, source.T_OrderSampleReceiveTime), + target.T_OrderSampleReceiveUserID = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveUserID, source.T_OrderSampleReceiveUserID), + + target.T_OrderSampleVerification = if(target.T_OrderSampleVerification='Y',target.T_OrderSampleVerification, source.T_OrderSampleVerification), + target.T_OrderSampleVerificationDate =if(target.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationDate, source.T_OrderSampleVerificationDate), + target.T_OrderSampleVerificationTime =if(source.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationTime, source.T_OrderSampleVerificationTime), + target.T_OrderSampleVerificationUserID =if(source.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationUserID, source.T_OrderSampleVerificationUserID), + + target.T_OrderSampleProcessing = if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessing, source.T_OrderSampleProcessing), + target.T_OrderSampleProcessingDate= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingDate, source.T_OrderSampleProcessingDate), + target.T_OrderSampleProcessingTime= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingTime, source.T_OrderSampleProcessingTime), + target.T_OrderSampleProcessingUserID= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingUserID, source.T_OrderSampleProcessingUserID), + + target.T_OrderSampleReceiveHandling =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandling, source.T_OrderSampleReceiveHandling ), + target.T_OrderSampleReceiveHandlingDate =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingDate, source.T_OrderSampleReceiveHandlingDate), + target.T_OrderSampleReceiveHandlingTime =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingTime, source.T_OrderSampleReceiveHandlingTime), + target.T_OrderSampleReceiveHandlingUserID =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingUserID, source.T_OrderSampleReceiveHandlingUserID), + + target.T_OrderSampleHandling = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandling, source.T_OrderSampleHandling), + target.T_OrderSampleHandlingDate = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingDate, source.T_OrderSampleHandlingDate), + target.T_OrderSampleHandlingTime = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingTime, source.T_OrderSampleHandlingTime), + target.T_OrderSampleHandlingUserID = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingUserID, source.T_OrderSampleHandlingUserID), + + target.T_OrderSampleWorklistReceive = source.T_OrderSampleWorklistReceive, + target.T_OrderSampleWorklistReceiveDatetime = source.T_OrderSampleWorklistReceiveDateTime, + target.T_OrderSampleWorklistReceiveUserID = source.T_OrderSampleWorklistReceiveUserID + "; + $qry = $this->db->query($sql, array($targetID, $sourceID)); + if (! $qry) { + echo json_encode(array("status" => "ERR", "message" => print_r($this->db->error(), true))); + exit; + } + } + function fix_sample_serum($headerID) + { + //cari t_ordersample yg belum worklist receive dengan code 017% + $sql = "select T_OrderSampleID + from t_ordersample + join t_sampletype on + T_OrderSampleT_OrderHeaderID = ? + and T_OrderSampleWorklistReceive = 'N' + and T_OrderSampleIsActive = 'Y' + and T_OrderSampleT_SampleTypeID = T_SampletypeID + and T_SampleTypeCode like '017%' + "; + $qry = $this->db->query($sql, array($headerID)); + if (!$qry) { + echo json_encode(array("status" => "ERR", "message" => print_r($this->db->error(), true))); + exit; + } + $rows = $qry->result_array(); + if (count($rows) == 0) return; + //cari T_OrderSample yang sudah di receive yg terakhir + $sql = "select T_OrderSampleID + from t_ordersample + join t_sampletype on + T_OrderSampleT_OrderHeaderID = ? + and T_OrderSampleWorklistReceive = 'Y' + and T_OrderSampleIsActive = 'Y' + and T_OrderSampleT_SampleTypeID = T_SampletypeID + and T_SampleTypeCode like '017%' + order by T_OrderSampleWorklistReceiveDatetime desc + limit 0,1 + "; + $qry = $this->db->query($sql, array($headerID)); + if (!$qry) { + echo json_encode(array("status" => "ERR", "message" => print_r($this->db->error(), true))); + exit; + } + $rcv_rows = $qry->result_array(); + if (count($rcv_rows) == 0) return; + + //print_r($rows); + //print_r($rcv_rows); + $rcv_T_OrderSampleID = $rcv_rows[0]["T_OrderSampleID"]; + //ada yg belum di receive + foreach ($rows as $r) { + $T_OrderSampleID = $r["T_OrderSampleID"]; + $this->update_order_sample($T_OrderSampleID, $rcv_T_OrderSampleID); + } + } + public function search() + { + $prm = $this->sys_input; + $max_rst = 99; + + $id = $prm["order_id"]; + if ($id > 0) { + $this->fix_sample_serum($id); + $this->fn_fix_normal($id); + } + $lang = $this->lang_default_code; + $lang_id = isset($prm['lang_id']) ? $prm['lang_id'] : '0'; + + if ($lang_id != 0) { + $l = $this->db_smartone->where("Nat_LangID", $lang_id)->get("nat_lang")->row(); + $lang = $l->Nat_LangCode; + } + + //tambahan fajri + $sql = " UPDATE t_orderdetail + JOIN t_test ON T_OrderDetailT_TestID = T_TestID + SET T_OrderDetailT_TestIsResult = T_TestIsResult + WHERE + T_OrderDetailT_OrderHeaderID = {$id} AND + T_OrderDetailT_TestIsResult = '' AND + T_OrderDetailIsActive = 'Y'"; + $this->db_smartone->query($sql); + + $tot_count = 0; + $lq = ""; + $group_id = 0; + if (isset($prm['group_id'])) + $group_id = $prm['group_id']; + + if ($group_id != 0) { + $sql = "select distinct T_WorklistDetailNat_TestID Nat_TestID + from t_worklistdetailv2 + where T_WorklistDetailT_WorklistID = {$group_id}"; + $qry = $this->db_smartone->query($sql); + $rows = $qry->result_array(); + $nat_test_ids = "0"; + foreach ($rows as $r) { + $nat_test_ids .= ", " . $r["Nat_TestID"]; + } + $q_group = " ( $nat_test_ids ) "; + + $sql = " + SELECT a1.*, cOUNT(a2.T_OrderDetailID) level + FROM ( + SELECT IFNULL(y.T_OrderDetailT_TestID, x.T_OrderDetailT_TestID) t_testid, + IFNULL(y.T_OrderDetailT_TestName, y.T_OrderDetailT_TestName) t_testname, + y.T_OrderDetailResult result, y.T_OrderDetailResult result_old, y.T_OrderDetailNote note, y.T_OrderDetailNote note_old, + y.T_OrderDetailID id, + y.T_OrderDetailT_TestIsResult is_result, a.T_TestIsQuantitative is_quantitative, + y.T_OrderDetailResultFlag result_flag, + y.T_OrderDetailNat_NormalValueID normal_id, + y.T_OrderDetailNormalValueNote normal_note, y.T_OrderDetailNat_UnitName unit_name, + y.T_OrderdetailNat_MethodeID methode_id, y.T_OrderdetailNat_MethodeName methode_name, + a.T_TestNat_TestID nattest_id, a.T_TestID tx_id, count(T_ResultInstrumentID) as result_instrument_n, + y.T_OrderDetailVerification, T_OrderSampleReceive sample_receive, + T_OrderSampleProcessing sample_processing, T_OrderSampleWorklistReceive sample_worklist_receive, + IF(T_OrderDetailAddOnPreAnalytic = 'Y', T_OrderDetailAddOnPreAnalytic, PreAnalyticIsOk) pre_analytic, + T_OrderDetailAddOnPreAnalytic, + T_OrderHeaderID order_id, y.T_OrderDetailT_TestSasCode test_sas_code, + tx.T_TestSasCode, + T_OrderDetailAddOnResample `resample`, T_OrderDetailAddOnResampleStatus resample_status, + T_OrderDetailAddOnRef ref, y.T_OrderDetailVerification verification, y.T_OrderDetailValidation validation, + T_OrderPromiseDateTime, Group_ResultName as ResultGroupName + FROM t_orderdetail x + left join t_orderpromise on x.T_OrderDetailT_OrderPromiseID = T_OrderPromiseID + JOIN t_test tx ON x.T_OrderDetailT_TestID = T_TestID + JOIN t_test tcheck on tcheck.T_TestNat_TestID in {$q_group} + and ( tx.T_TestID = tcheck.T_TestID or tx.T_TestSasCode like concat(tcheck.T_TestSasCode,'%')) + LEFT JOIN group_resultdetail ON Group_ResultDetailT_TestID = x.T_OrderDetailT_TestID AND Group_ResultDetailIsActive = 'Y' + LEFT JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND Group_ResultFlagNonLab = 'N' + LEFT JOIN t_orderdetail y ON x.T_OrderDetailT_TestSasCode LIKE CONCAT(y.T_OrderDetailT_TestSasCode, '%') + AND x.T_OrderDetailT_OrderHeaderID = y.T_OrderDetailT_OrderHeaderID + AND y.T_OrderDetailIsActive = 'Y' + LEFT JOIN t_orderdetailaddon ON x.T_OrderDetailID = T_OrderDetailAddOnT_OrderDetailID + JOIN t_orderheader ON y.T_OrderDetailT_OrderHeaderID = T_OrderHeaderID + LEFT JOIN t_test a ON y.T_OrderDetailT_TestID = a.T_TestID + AND a.T_TestIsNonLab = '' + LEFT JOIN (SELECT T_OrderSampleT_SampleTypeID, T_OrderSampleReceive, T_OrderSampleProcessing, T_OrderSampleWorklistReceive + FROM t_ordersample WHERE T_OrderSampleT_OrderHeaderID = {$id} + AND T_OrderSampleIsactive = 'Y' + GROUP BY T_OrderSampleT_SampleTypeID) os ON a.T_TestT_SampleTypeID = os.T_OrderSampleT_SampleTypeID + or os.T_OrderSampleT_SampleTypeID = fn_sampletype_from_local(a.T_TestNat_TestID) + + LEFT JOIN t_resultinstrument ON T_ResultInstrumentT_OrderDetailID = x.T_OrderDetailID + LEFT JOIN pre_analytic ON PreAnalyticNat_TestID = a.T_TestNat_TestID AND PreAnalyticDate = date(now()) and PreAnalyticIsActive = 'Y' + WHERE x.T_OrderDetailT_OrderHeaderID = {$id} + AND x.T_OrderDetailIsActive = 'Y' + GROUP BY y.T_OrderDetailT_TestID + ORDER BY y.T_OrderDetailT_TestSasCode ASC + ) a1 + + LEFT JOIN t_orderdetail a2 ON a2.T_OrderDetailT_OrderHeaderID = a1.order_id + AND a2.T_OrderDetailIsActive = 'Y' + AND a1.test_sas_code LIKE CONCAT(a2.T_OrderDetailT_testSasCode, '%') + GROUP BY a1.t_testid + order by a1.test_sas_code +"; + $query = $this->db_smartone->query($sql); + $lq = $this->db_smartone->last_query(); + } else { + $sql = " + SELECT a1.*, cOUNT(a2.T_OrderDetailID) level + FROM ( + SELECT IFNULL(y.T_OrderDetailT_TestID, x.T_OrderDetailT_TestID) t_testid, + IFNULL(y.T_OrderDetailT_TestName, y.T_OrderDetailT_TestName) t_testname, + y.T_OrderDetailResult result, y.T_OrderDetailResult result_old, y.T_OrderDetailNote note, y.T_OrderDetailNote note_old, + y.T_OrderDetailID id, + y.T_OrderDetailT_TestIsResult is_result, a.T_TestIsQuantitative is_quantitative, + y.T_OrderDetailResultFlag result_flag, + y.T_OrderDetailNat_NormalValueID normal_id, + y.T_OrderDetailNormalValueNote normal_note, y.T_OrderDetailNat_UnitName unit_name, + y.T_OrderdetailNat_MethodeID methode_id, y.T_OrderdetailNat_MethodeName methode_name, + a.T_TestNat_TestID nattest_id, a.T_TestID tx_id, count(T_ResultInstrumentID) as result_instrument_n, + y.T_OrderDetailVerification, T_OrderSampleReceive sample_receive, + T_OrderSampleProcessing sample_processing, T_OrderSampleWorklistReceive sample_worklist_receive, + IF(T_OrderDetailAddOnPreAnalytic = 'Y', T_OrderDetailAddOnPreAnalytic, PreAnalyticIsOk) pre_analytic, + T_OrderDetailAddOnPreAnalytic, + T_OrderHeaderID order_id, y.T_OrderDetailT_TestSasCode test_sas_code, + tx.T_TestSasCode, + T_OrderDetailAddOnResample `resample`, T_OrderDetailAddOnResampleStatus resample_status, + T_OrderDetailAddOnRef ref, y.T_OrderDetailVerification verification, y.T_OrderDetailValidation validation, + T_OrderPromiseDateTime , Group_ResultName as ResultGroupName + FROM t_orderdetail x + left join t_orderpromise on x.T_OrderDetailT_OrderPromiseID = T_OrderPromiseID + JOIN t_test tx ON x.T_OrderDetailT_TestID = T_TestID + LEFT JOIN group_resultdetail ON Group_ResultDetailT_TestID = x.T_OrderDetailT_TestID AND Group_ResultDetailIsActive = 'Y' + LEFT JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND Group_ResultFlagNonLab = 'N' + LEFT JOIN t_orderdetail y ON x.T_OrderDetailT_TestSasCode LIKE CONCAT(y.T_OrderDetailT_TestSasCode, '%') + AND x.T_OrderDetailT_OrderHeaderID = y.T_OrderDetailT_OrderHeaderID + AND y.T_OrderDetailIsActive = 'Y' + + LEFT JOIN t_orderdetailaddon ON x.T_OrderDetailID = T_OrderDetailAddOnT_OrderDetailID + + JOIN t_orderheader ON y.T_OrderDetailT_OrderHeaderID = T_OrderHeaderID + LEFT JOIN t_test a ON y.T_OrderDetailT_TestID = a.T_TestID + AND a.T_TestIsNonLab = '' + LEFT JOIN (SELECT T_OrderSampleT_SampleTypeID, T_OrderSampleReceive, T_OrderSampleProcessing, T_OrderSampleWorklistReceive + FROM t_ordersample WHERE T_OrderSampleT_OrderHeaderID = {$id} + AND T_OrderSampleIsactive = 'Y' + GROUP BY T_OrderSampleT_SampleTypeID) os ON a.T_TestT_SampleTypeID = os.T_OrderSampleT_SampleTypeID + or os.T_OrderSampleT_SampleTypeID = fn_sampletype_from_local(a.T_TestNat_TestID) + + LEFT JOIN t_resultinstrument ON T_ResultInstrumentT_OrderDetailID = x.T_OrderDetailID + LEFT JOIN pre_analytic ON PreAnalyticNat_TestID = a.T_TestNat_TestID AND PreAnalyticDate = date(now()) and PreAnalyticIsActive = 'Y' + WHERE x.T_OrderDetailT_OrderHeaderID = {$id} + AND x.T_OrderDetailIsActive = 'Y' + GROUP BY y.T_OrderDetailT_TestID + ORDER BY y.T_OrderDetailT_TestSasCode ASC + ) a1 + + LEFT JOIN t_orderdetail a2 ON a2.T_OrderDetailT_OrderHeaderID = a1.order_id + AND a2.T_OrderDetailIsActive = 'Y' + AND a1.test_sas_code LIKE CONCAT(a2.T_OrderDetailT_testSasCode, '%') + GROUP BY a1.t_testid + order by a1.test_sas_code +"; + //echo $sql; + $query = $this->db_smartone->query($sql); + $lq = $this->db_smartone->last_query(); + } + // file_put_contents("/xtmp/re-query.sql",$lq); + + if ($query) { + $rst = []; + $rows = $query->result_array(); + + foreach ($rows as $k => $v) { + + if ($v['is_result'] == "Y" && $v['is_quantitative'] == "N") { + $v['template'] = []; + $x = $this->db_smartone->query("CALL sp_master_resulttemplate_get('{$v['t_testid']}')"); + $this->clean_mysqli_connection($this->db_smartone->conn_id); + if ($x) + $v['template'] = $x->result_array(); + } + + // IF Rujukan, by pas Pre Analytik + if ($v['ref'] == 'Y') + $v['pre_analytic'] = 'Y'; + if ($v["id"] == "885455") { + //sipe workaround + //$v["sample_receive"] = "Y"; + $v["sample_worklist_receive"] = "Y"; + } + $rst[] = $v; + } + + $result = array("total" => $tot_count, "records" => $rst, "total_display" => sizeof($rows), "q" => $lq); + $this->sys_ok($result); + } else { + $this->sys_error_db("RE Px rows", $this->db_smartone); + exit; + } + } + + public function save() + { + $prm = $this->sys_input; + $data = json_decode($prm["data"]); + $lang = $this->lang_default_code; + $lang_id = isset($prm['lang_id']) ? $prm['lang_id'] : '0'; + + if ($lang_id != 0) { + $l = $this->db_smartone->where("Nat_LangID", $lang_id)->get("nat_lang")->row(); + $lang = $l->Nat_LangCode; + } + + $sql_norm = "select T_OrderDetailMinValue, T_OrderDetailMaxValue, + T_OrderDetailMinValueInclusive, T_OrderDetailMaxValueInclusive, + Nat_TestFlagLow, Nat_TestFlagHigh + from t_orderdetail + join t_test on T_OrderDetailT_TestID = T_TestID + join nat_test on T_TestNat_TestID = Nat_TestID and T_TestIsActive = 'Y' + where T_OrderDetailID = ? "; + + $ids = []; + foreach ($data as $k => $v) { + if ($v->resultInstrumentID > 0) { + $sql_i = "select T_ResultInstrumentNat_NormalValueID normalValueID + from t_resultinstrument + where T_ResultInstrumentID = ?"; + $qry_i = $this->db_smartone->query($sql_i, array($v->resultInstrumentID)); + if ($qry_i) { + $rows_i = $qry_i->result_array(); + + if (count($rows_i) > 0) { + $sql_iu = "update t_orderdetail, nat_normalvalue , nat_methode + set T_OrderDetailMinValue = Nat_NormalValueMinValue, + T_OrderDetailMinValueInclusive = Nat_NormalValueMinValueInclusive, + T_OrderDetailMaxValue = Nat_NormalValueMaxValue , + T_OrderDetailMaxValueInclusive = Nat_NormalValueMaxValueInclusive, + T_OrderDetailNormalValueNote = Nat_NormalValueNote, + T_OrderDetailNormalValueDescription = Nat_NormalValueDescription, + T_OrderDetailNat_NormalValueID = Nat_NormalValueID, + T_OrderDetailNat_MethodeID = Nat_NormalValueNat_MethodeID, + T_OrderDetailNat_MethodeName = Nat_MethodeName + where T_OrderDetailID = ? and Nat_NormalValueID = ? + and Nat_NormalValueNat_MethodeID = Nat_MethodeID + "; + $this->db_smartone->query($sql_iu, array($v->id, $rows_i[0]["normalValueID"])); + //file_put_contents("/xtmp/update-nilai-normal", $this->db_smartone->last_query() . "\n", FILE_APPEND); + } + } + } + $y = $this->db_smartone->query("SELECT fn_process_sample_handling_perfect('{$v->order_id}', '{$v->test_id}') c") + ->row(); + $req_status = $y->c; + $qry_norm = $this->db_smartone->query($sql_norm, $v->id); + $result_flag = ""; + if ($qry_norm) { + $rows_norm = $qry_norm->result_array(); + if (count($rows_norm) > 0) { + $r = $rows_norm[0]; + if (is_numeric($v->result)) { + + if ($r["T_OrderDetailMinValueInclusive"] == "Y" && $v->result < $r["T_OrderDetailMinValue"]) { + $result_flag = $r["Nat_TestFlagLow"]; + } + if ($r["T_OrderDetailMinValueInclusive"] == "N" && $v->result <= $r["T_OrderDetailMinValue"]) { + $result_flag = $r["Nat_TestFlagLow"]; + } + if ($r["T_OrderDetailMaxValueInclusive"] == "Y" && $v->result > $r["T_OrderDetailMaxValue"]) { + $result_flag = $r["Nat_TestFlagHigh"]; + } + if ($r["T_OrderDetailMaxValueInclusive"] == "N" && $v->result >= $r["T_OrderDetailMaxValue"]) { + $result_flag = $r["Nat_TestFlagHigh"]; + } + } + } + } + if ($lang == $this->lang_default_code) { + $this->db_smartone->set('T_OrderDetailResult', $v->result) + ->set('T_OrderDetailResultFlag', $result_flag) + ->set('T_OrderDetailNote', $v->note) + ->set('T_OrderDetailReqStatus', $req_status) + ->where('T_OrderDetailID', $v->id) + ->update('t_orderdetail'); + } else { + $this->db_smartone->set('T_OrderDetailLangResult', $v->result) + ->set('T_OrderDetailLangNote', $v->note) + ->where('T_OrderDetailLangID', $v->id) + ->update('t_orderdetaillang'); + } + + $ids[] = $v->id; + } + + // LOG Process + $order = $this->db_smartone->select('T_OrderDetailT_OrderHeaderID id, T_OrderHeaderLabNumber lab_number', false) + ->join('t_orderheader', 'T_OrderHeaderID = T_OrderDetailT_OrderHeaderID') + ->where('T_OrderDetailID', $data[0]->id) + ->get('t_orderdetail') + ->row(); + + $dblog = $this->load->database("onelog", true); + $dblog->set('Log_ProcessCode', 'PROCESS.Result.Entry') + ->set('Log_ProcessOrderID', $order->id) + ->set('Log_ProcessOrderNumber', $order->lab_number) + ->set('Log_ProcessJson', json_encode($data)) + ->set('Log_ProcessUserID', $this->sys_user['M_UserID']) + ->insert('log_process'); + // END OF Log Process + //auto calculation + $this->load->library("Resultcalc"); + $rows = $this->resultcalc->auto($order->id); + + try { + foreach ($ids as $id) { + $this->db_smartone->query("call sp_set_normal_value_flag($id)"); + $this->clean_mysqli_connection($this->db_smartone->conn_id); + } + } catch (Exception $e) { + } + + $this->sys_ok($ids); + } + + public function save_template() + { + $prm = $this->sys_input; + + $n = $this->db_smartone->select("COUNT(T_ResultTemplateID) n") + ->where("T_ResultTemplateT_TestID", $prm['test_id']) + ->where("T_ResultTemplateIsActive", "Y") + ->where("T_ResultTemplateValue", $prm['value']) + ->get('t_resulttemplate') + ->row(); + if ($n->n > 0) { + $this->sys_error_db("Insert Result Template", $this->db_smartone); + return; + } + + $r = $this->db_smartone->set("T_ResultTemplateT_TestID", $prm['test_id']) + ->set("T_ResultTemplateValue", $prm['value']) + ->insert('t_resulttemplate'); + if ($r) { + $template = []; + $x = $this->db_smartone->query("CALL sp_master_resulttemplate_get('{$prm['test_id']}')"); + $this->clean_mysqli_connection($this->db_smartone->conn_id); + if ($x) + $template = $x->result_array(); + + $this->sys_ok($template); + } + } + + public function export() + { + $prm = $this->sys_input; + + $sql = "CALL sp_process_result_lang(?, ?, ?, ?)"; + $query = $this->db_smartone->query($sql, [$prm['order_id'], $prm['lang_id'], $prm['is_si'], $this->sys_user['M_UserID']]); + if ($query) { + $r = $query->row(); + if ($r->status == "OK") { + $this->sys_ok($r->data); + return; + } + + $this->sys_error_db("Message : " . $r->message, $this->db_smartone); + } else { + $this->sys_error_db("Lang Result", $this->db_smartone); + return; + } + } + + public function search_group() + { + $prm = $this->sys_input; + $max_rst = 100; + + // QUERY TOTAL + $sql = "select count(*) total + from t_worklist + where T_WorklistIsActive = 'Y' + order by T_WorklistName ASC"; + $query = $this->db_smartone->query($sql); + + if ($query) { + $tot_count = $query->result_array()[0]["total"]; + } else { + $this->sys_error_db("worklist count", $this->db_smartone); + exit; + } + + $sql = "select T_WorklistID group_id, T_WorklistName group_name + from t_worklist + where T_WorklistIsActive = 'Y' + order by T_WorklistName ASC + limit 0, {$max_rst}"; + $query = $this->db_smartone->query($sql); + + if ($query) { + $rows = $query->result_array(); + foreach ($rows as $k => $v) + $rows[$k]['data'] = json_decode($v['data']); + $result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows), "q" => $this->db_smartone->last_query()); + $this->sys_ok($result); + } else { + $this->sys_error_db("worklist rows", $this->db_smartone); + exit; + } + } + + public function search_rerun() + { + $prm = $this->sys_input; + $id = $prm["detail_id"]; + + $sql = "CALL sp_process_result_rerun(?)"; + $query = $this->db_smartone->query($sql, [$id]); + + if ($query) { + $rows = $query->result_array(); + $this->sys_ok(["records" => $rows]); + } else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + + + function getdoctorsfna() + { + $prm = $this->sys_input; + // $id = $prm["id"]; + + $sql = " SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY M_DoctorName ASC"; + //echo $sql; + $query = $this->db_smartone->query($sql); + + if ($query) { + $rows = $query->result_array(); + $this->sys_ok(["records" => $rows]); + } else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + function getfnaresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT Other_FNADetailsID as xid, + Other_FNAT_OrderDetailID as orderdetail_id, + Other_FNADetailsCode as code, + Other_FNADetailsLabel as label, + Other_FNADetailsResult as result, + IFNULL(Other_FNAM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_FNAM_DoctorID) OR Other_FNAM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_fna + JOIN other_fnadetails ON Other_FNADetailsOther_FNAID = Other_FNAID AND Other_FNADetailsIsActive = 'Y' + LEFT JOIN m_doctor ON Other_FNAM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_FNAT_OrderDetailID = {$id} AND Other_FNAIsActive = 'Y' + GROUP BY Other_FNADetailsID + ORDER BY Other_FNADetailsCode ASC"; + $query = $this->db_smartone->query($sql); + + if ($query) { + $rows = $query->result_array(); + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $images = array(); + $sql = "SELECT So_ImageUploadID as xid, + CONCAT('/one-media/one-image-nonlab/',So_ImageUploadNewName) as image_url + FROM t_orderdetail + JOIN so_imageupload ON So_ImageUploadT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND + So_ImageUploadIsActive = 'Y' + WHERE + T_OrderDetailID = {$id} AND + T_OrderDetailIsActive = 'Y' + GROUP BY So_ImageUploadID"; + $images = $this->db_smartone->query($sql)->result_array(); + + $rst = array('doctors' => $doctors, 'results' => $rows, 'images' => $images); + $this->sys_ok(["records" => $rst]); + } else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + + function uploadimage() + { + if (! $this->isLogin) { + $this->sys_error("Invalid Token"); + exit; + } + + $userid = $this->sys_user["M_UserID"]; + $data = []; + //print_r($_SERVER); + + $prm = $this->sys_input; + $orderid = $this->input->post('orderid'); + $labnumber = $this->input->post('labnumber'); + $sql = "UPDATE so_imageupload SET + So_ImageUploadIsActive = 'N', + So_ImageUploadUserID = {$userid} + WHERE + So_ImageUploadT_OrderHeaderID = {$orderid}"; + //echo $sql; + $this->db_onedev->query($sql); + //$config['upload_path'] = 'assets/'; + + $path = '/home/one/project/one/one-media/one-image-nonlab/'; + //echo $path; + $config['upload_path'] = $path; + $config['allowed_types'] = 'jpg|jpeg|png|gif'; + + $config['max_size'] = '10000'; + $count = count($_FILES['files']['name']); + //echo $count; + $this->load->library('upload', $config); + + $error = []; + for ($i = 0; $i < $count; $i++) { + + + if (!empty($_FILES['files']['name'][$i])) { + + + + $_FILES['file']['name'] = $_FILES['files']['name'][$i]; + + $_FILES['file']['type'] = $_FILES['files']['type'][$i]; + + $_FILES['file']['tmp_name'] = $_FILES['files']['tmp_name'][$i]; + + $_FILES['file']['error'] = $_FILES['files']['error'][$i]; + + $_FILES['file']['size'] = $_FILES['files']['size'][$i]; + + + + $namex = $orderid . '-' . $labnumber . '-' . $this->generateRandomString(5); + //echo $namex; + + $config['file_name'] = $namex; + $this->upload->initialize($config); + //echo $config['file_name'] ; + + + + + + if ($this->upload->do_upload('file')) { + + $uploadData = $this->upload->data(); + + $filename = $uploadData['file_name']; + //echo $filename; + + + $sql = "INSERT INTO so_imageupload ( + So_ImageUploadT_OrderHeaderID, + So_ImageUploadT_OrderHeaderLabNumber, + So_ImageUploadT_SampleTypeID, + So_ImageUploadOldName, + So_ImageUploadNewName, + So_ImageUploadCreated, + So_ImageUploadUserID + ) + VALUES( + {$orderid}, + '{$labnumber}', + '150', + '{$_FILES['files']['name'][$i]}', + '{$filename}', + NOW(), + {$userid} + + )"; + //echo $sql; + $this->db_onedev->query($sql); + $xlast_id = $this->db_onedev->insert_id(); + $data['totalFiles'][] = array('xid' => $xlast_id, 'image_url' => '/one-media/one-image-nonlab/' . $filename); + } else { + $error = array('error' => $this->upload->display_errors()); + } + } + } + + $result = array("total" => count($data['totalFiles']), "records" => $data['totalFiles'], 'errors' => $error); + $this->sys_ok($result); + } + + + function getpatologianatomyresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT Other_PatologiAnatomyID as xid, + Other_PatologiAnatomyT_OrderDetailID as orderdetail_id, + Other_PatologiAnatomyNoSediaan as no_sediaan, + Other_PatologiAnatomyDiagnosaKlinis as diagnosa, + Other_PatologiAnatomyKeteranganKlinis as klinis, + Other_PatologiAnatomyLokasiOrgan as lokasi, + Other_PatologiAnatomyMakroskopik as makroskopik, + Other_PatologiAnatomyMikroskopik as mikroskopik, + Other_PatologiAnatomyKesimpulan as kesimpulan, + IFNULL(Other_PatologiAnatomyM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_PatologiAnatomyM_DoctorID) OR Other_PatologiAnatomyM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_patologi_anatomy + LEFT JOIN m_doctor ON Other_PatologiAnatomyM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_PatologiAnatomyT_OrderDetailID = {$id} AND Other_PatologiAnatomyIsActive = 'Y' + GROUP BY Other_PatologiAnatomyID + ORDER BY Other_PatologiAnatomyID ASC + LIMIT 1"; + $query = $this->db_smartone->query($sql); + + if ($query) { + $rows = $query->row_array(); + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + + $sql = "SELECT So_ImageUploadPatologyAnatomyID as xid, + CONCAT('/one-media/one-image-nonlab/',So_ImageUploadPatologyAnatomyNewName) as image_url, + So_ImageUploadPatologyAnatomyType as type + FROM t_orderdetail + JOIN so_imageupload_patology_anatomy ON So_ImageUploadPatologyAnatomyT_OrderHeaderID= T_OrderDetailT_OrderHeaderID AND + So_ImageUploadPatologyAnatomyIsActive= 'Y' + WHERE + T_OrderDetailID = {$id} AND + T_OrderDetailIsActive = 'Y' + GROUP BY So_ImageUploadPatologyAnatomyID"; + $images = $this->db_smartone->query($sql)->result_array(); + $mikro = []; + $makro = []; + + foreach ($images as $key => $value) { + + if ($value['type'] == 'mikro') { + $mikro[] = $value; + } + if ($value['type'] == 'makro') { + $makro[] = $value; + } + } + + $rst = array('doctors' => $doctors, 'result' => $rows, 'mikro' => $mikro, 'makro' => $makro); + $this->sys_ok(["records" => $rst]); + } else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + + + function generateRandomString($length = 10) + { + $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; + $charactersLength = strlen($characters); + $randomString = ''; + for ($i = 0; $i < $length; $i++) { + $randomString .= $characters[rand(0, $charactersLength - 1)]; + } + return $randomString; + } + + function getcytologiresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT Other_CytologiDetailsID as xid, + Other_CytologiT_OrderDetailID as orderdetail_id, + Other_CytologiDetailsCode as code, + Other_CytologiDetailsLabel as label, + Other_CytologiDetailsResult as result, + IFNULL(Other_CytologiM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_CytologiM_DoctorID) OR Other_CytologiM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_cytologi + JOIN other_cytologidetails ON Other_CytologiDetailsOther_CytologiID = Other_CytologiID AND Other_CytologiDetailsIsActive = 'Y' + LEFT JOIN m_doctor ON Other_CytologiM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_CytologiT_OrderDetailID = {$id} AND Other_CytologiIsActive = 'Y' + GROUP BY Other_CytologiDetailsID + ORDER BY Other_CytologiDetailsCode ASC"; + //echo $sql; + $query = $this->db_smartone->query($sql); + + if ($query) { + $rows = $query->result_array(); + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $rst = array('doctors' => $doctors, 'results' => $rows); + $this->sys_ok(["records" => $rst]); + } else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + function getmikroresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT + Other_MikroID as xid, + Other_MikroHasilBiakan as hasil_biakan, + Other_MikroSampleTypeName as sample_name, + Other_MikroT_OrderDetailID as orderdetail_id, + Other_MikroResult as result_value, + '' as result_other, + IFNULL(T_BacteriaID,0) as T_BacteriaID, + IFNULL(T_BacteriaName,'') as T_BacteriaName, + '' as details, + IFNULL(Other_MikroM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_MikroM_DoctorID) OR Other_MikroM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_mikro + LEFT JOIN t_bacteria ON Other_MikroT_BacteriaID = T_BacteriaID + LEFT JOIN m_doctor ON Other_MikroM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_MikroT_OrderDetailID = {$id} AND Other_MikroIsActive = 'Y' + GROUP BY Other_MikroID"; + //echo $sql; + $query = $this->db_smartone->query($sql); + + if ($query) { + $row = $query->row_array(); + if ($row) { + if ($row['result_value'] != 'Positif' && $row['result_value'] != 'Negatif') { + $row['result_other'] = $row['result_value']; + $row['result_value'] = 'other'; + } + $sql = "SELECT '' as xno, + Other_MikroDetailsID as xid, + Other_MikroDetailsValue as value, + IF(Other_MikroDetailsNote = 'R','Y','N') as chx_r, + IF(Other_MikroDetailsNote = 'I','Y','N') as chx_i, + IF(Other_MikroDetailsNote = 'S','Y','N') as chx_s, + Other_MikroDetailsNote as note, + t_antibiotic.* + FROM other_mikrodetails + LEFT JOIN t_antibiotic ON Other_MikroDetailsT_AntibioticID = T_AntibioticID + WHERE + Other_MikroDetailsOther_MikroID = {$row['xid']} AND Other_MikroDetailsIsActive = 'Y' + GROUP BY Other_MikroDetailsID + ORDER BY T_AntibioticName ASC"; + //echo $sql; + $details = $this->db_smartone->query($sql)->result_array(); + if (details) { + foreach ($details as $k => $v) { + $details[$k]['xno'] = $k + 1; + } + } + $row['details'] = $details; + } else { + $row = array('xid' => '0', 'hasil_biakan' => '', 'result_value' => 'Negatif', 'sample_name' => '', 'orderdetail_id' => $id, 'T_BacteriaID' => '0', 'T_BacteriaName' => '0', 'details' => array(), 'doctor_id' => '0', 'doctor_name' => '0'); + } + } else { + $row = array('xid' => '0', 'hasil_biakan' => '', 'result_value' => 'Negatif', 'sample_name' => '', 'orderdetail_id' => $id, 'T_BacteriaID' => '0', 'T_BacteriaName' => '0', 'details' => array(), 'doctor_id' => '0', 'doctor_name' => '0'); + } + //print_r($row); + + + + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 7 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $sql = " + SELECT '0' as id, 'Belum memilih bakteria' as name + UNION + SELECT T_BacteriaID as id, T_BacteriaName as name + FROM t_bacteria + WHERE + T_BacteriaIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $bacteries = $this->db_smartone->query($sql)->result_array(); + $rst = array('doctors' => $doctors, 'bacteries' => $bacteries, 'results' => $row); + $this->sys_ok(["records" => $rst]); + } + function getantibiotics() + { + $prm = $this->sys_input; + $id = $prm["id"]; + $sql = " SELECT '' as xno, + 0 as xid, + '' as hasil_biakan, + '' as sample_name, + 0 as value, + 'Y' as chx_r, + 'N' as chx_i, + 'N' as chx_s, + 'R' as note, + t_antibiotic.* + FROM t_antibiotic + WHERE + T_AntibioticT_BacteriaID = {$prm['id']} AND T_AntibioticIsActive= 'Y' + ORDER BY T_AntibioticName ASC"; + //echo $sql; + $rows = $this->db_smartone->query($sql)->result_array(); + if (rows) { + foreach ($rows as $k => $v) { + $rows[$k]['xno'] = $k + 1; + } + } + + $this->sys_ok(["records" => $rows]); + } + function getlcprepresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + $sql = " SELECT Other_LcprepDetailsID as xid, + Other_LcprepID as header_id, + Other_LcprepT_orderDetailID as orderdetail_id, + Other_LcprepDetailsCode as code, + Other_LcprepDetailsLabel as label, + Other_LcprepDetailsResult as result, + IFNULL(Other_LcprepM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_LcprepM_DoctorID) OR Other_LcprepM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_lcprep + JOIN other_lcprepdetails ON Other_LcprepDetailsOther_LcprepID = Other_LcprepID AND Other_LcprepDetailsIsActive = 'Y' + LEFT JOIN m_doctor ON Other_LcprepM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_LcprepT_orderDetailID = {$id} AND Other_LcprepIsActive = 'Y' + GROUP BY Other_LcprepDetailsOther_LcprepID, Other_LcprepDetailsCode + ORDER BY Other_LcprepDetailsCode ASC"; + //echo $sql; + $rows = $this->db_smartone->query($sql)->result_array(); + if (!$rows) { + $rows = array( + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'A', + 'label' => 'DESKRIPSI', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ), + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'B', + 'label' => 'KESIMPULAN', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ) + ); + } + + $header_id = $rows[0]['header_id']; + $sql = "SELECT IFNULL(Other_LcprepAdekuasiID,0) as xid, + Lcprep_AdekuasiID as id, + Lcprep_AdekuasiLabel as name, + IF(ISNULL(Other_LcprepAdekuasiID),'N',Other_LcprepAdekuasiChex) as chex + FROM lcprep_adekuasi + LEFT JOIN other_lcprepadekuasi ON Other_LcprepAdekuasiLcprep_AdekuasiID = Lcprep_AdekuasiID AND + Other_LcprepAdekuasiOther_LcprepID = {$header_id} AND + Other_LcprepAdekuasiIsActive = 'Y' + WHERE + Lcprep_AdekuasiIsActive = 'Y' + GROUP BY Lcprep_AdekuasiID + ORDER BY Lcprep_AdekuasiOrder ASC + "; + //echo $sql; + $adeakuasi = $this->db_smartone->query($sql)->result_array(); + foreach ($adeakuasi as $kc => $vc) { + $adeakuasi[$kc]['chex'] = $vc['chex'] == 'N' ? false : true; + } + + $sql = "SELECT IFNULL(Other_LcprepKategoriUmumID,0) as xid, + Lcprep_KategoriUmumID as id, + Lcprep_KategoriUmumLabel as name, + IF(ISNULL(Other_LcprepKategoriUmumID),'N',Other_LcprepKategoriUmumChex) as chex + FROM lcprep_kategoriumum + LEFT JOIN other_lcprepkategoriumum ON Other_LcprepKategoriUmumLcprep_KategoriUmumID = Lcprep_KategoriUmumID AND + Other_LcprepKategoriUmumOther_LcprepID = {$header_id} AND + Other_LcprepKategoriUmumIsActive = 'Y' + WHERE + Lcprep_KategoriUmumIsActive = 'Y' + GROUP BY Lcprep_KategoriUmumID + "; + //echo $sql; + $kategoriumum = $this->db_smartone->query($sql)->result_array(); + foreach ($kategoriumum as $kc => $vc) { + $kategoriumum[$kc]['chex'] = $vc['chex'] == 'N' ? false : true; + } + + $sql = " + SELECT Lcprep_InterpretasiGroupID as group_id, + Lcprep_InterpretasiGroupName as group_name, + '' as subgroups + FROM lcprep_interpretasigroup + WHERE + Lcprep_InterpretasiGroupIsActive = 'Y' + "; + //echo $sql; + $interpretasi = $this->db_smartone->query($sql)->result_array(); + foreach ($interpretasi as $k => $v) { + $subgroups = array(); + $sql = "SELECT Lcprep_InterpretasiSubgroupID as subgroup_id, + Lcprep_InterpretasiSubgroupName as subgroup_name, + '' as childs + FROM lcprep_interpretasisubgroup + WHERE + Lcprep_InterpretasiSubgroupLcprep_InterpretasiGroupID = {$v['group_id']} AND Lcprep_InterpretasiSubgroupIsActive = 'Y'"; + //echo $sql; + $subgroups = $this->db_smartone->query($sql)->result_array(); + if (count($subgroups) > 0) { + foreach ($subgroups as $ki => $vi) { + $childs = array(); + $sql = "SELECT IFNULL(Other_LcprepInterpretasiID,0) as xid, + IFNULL(Other_LcprepInterpretasiChex,'N') as chex, + IFNULL(Other_LcprepInterpretasiValue,'') as value, + Lcprep_InterpretasiID as id, + Lcprep_InterpretasiLcprep_InterpretasiSubgroupID as subgroup_id, + Lcprep_InterpretasiCode as code, + Lcprep_InterpretasiName as name, + Lcprep_InterpretasiParentID as parent_id, + Lcprep_InterpretasiIsParent as is_parent, + Lcprep_InterpretasiHasResult as has_result, + Lcprep_InterpretasiTypeResult as type_result + FROM lcprep_interpretasi + LEFT JOIN other_lcprepinterpretasi ON Other_LcprepInterpretasiOther_LcprepID = {$header_id} AND + Other_LcprepInterpretasiLcprep_InterpretasiID = Lcprep_InterpretasiID AND + Other_LcprepInterpretasiIsActive = 'Y' + WHERE + Lcprep_InterpretasiLcprep_InterpretasiSubgroupID = {$vi['subgroup_id']} AND Lcprep_InterpretasiIsActive = 'Y' + GROUP BY Lcprep_InterpretasiID Order BY Lcprep_InterpretasiCode ASC"; + $childs = $this->db_smartone->query($sql)->result_array(); + if ($childs) { + foreach ($childs as $kc => $vc) { + $childs[$kc]['chex'] = $vc['chex'] == 'N' ? false : true; + } + } + $subgroups[$ki]['childs'] = $childs; + } + } + + $interpretasi[$k]['subgroups'] = $subgroups; + } + + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $rst = array('doctors' => $doctors, 'results' => $rows, 'adekuasi' => $adeakuasi, 'kategoriumum' => $kategoriumum, 'interpretasi' => $interpretasi); + $this->sys_ok(["records" => $rst]); + } + + function getpapsmearresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT Other_PapSmearDetailsID as xid, + Other_PapSmearID as header_id, + Other_PapSmearT_OrderDetailID as orderdetail_id, + Other_PapSmearDetailsCode as code, + Other_PapSmearDetailsLabel as label, + Other_PapSmearDetailsResult as result, + IFNULL(Other_PapSmearM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_PapSmearM_DoctorID) OR Other_PapSmearM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_papsmear + JOIN other_papsmeardetails ON Other_PapSmearDetailsOther_PapSmearID = Other_PapSmearID AND Other_PapSmearDetailsIsActive = 'Y' + LEFT JOIN m_doctor ON Other_PapSmearM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_PapSmearT_OrderDetailID = {$id} AND Other_PapSmearIsActive = 'Y' + GROUP BY Other_PapSmearDetailsID + ORDER BY Other_PapSmearDetailsCode ASC"; + //echo $sql; + $rows = $this->db_smartone->query($sql)->result_array(); + if (!$rows) { + $rows = array( + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'A', + 'label' => 'Makroskopik', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ), + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'B', + 'label' => 'Mikroskopik', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ), + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'C', + 'label' => 'Kesimpulan', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ) + ); + } + + $header_id = $rows[0]['header_id']; + $sql = "SELECT Other_PapSmearMaturasiID as xid, + Other_PapSmearMaturasiValue as value + FROM other_papsmearmaturasi + WHERE + Other_PapSmearMaturasiOther_PapSmearID = {$header_id} AND + Other_PapSmearMaturasiIsActive = 'Y' + "; + //echo $sql; + $dt_maturasi = $this->db_smartone->query($sql)->row_array(); + if (!$dt_maturasi) { + $maturasi = array('xid' => '0', 'value' => array('', '', '')); + } else { + $value = explode('/', $dt_maturasi['value']); + $maturasi = array('xid' => $dt_maturasi['xid'], 'value' => $value); + } + + $sql = "SELECT IFNULL(Other_PapSmearBahanID,0) as xid, + M_PapSmearBahanID as bahan_id, + M_PapSmearBahanName as name, + IF(ISNULL(Other_PapSmearBahanID),'N','Y') as selected + FROM m_papsmearbahan + LEFT JOIN other_papsmearbahan ON Other_PapSmearBahanM_PapSmearBahanID = M_PapSmearBahanID AND + Other_PapSmearBahanOther_PapSmearID = {$header_id} AND + Other_PapSmearBahanIsActive = 'Y' + WHERE + M_PapSmearBahanIsActive = 'Y' + ORDER BY M_PapSmearBahanID ASC + "; + //echo $sql; + $bahans = $this->db_smartone->query($sql)->result_array(); + + $sql = "SELECT IFNULL(Other_PapsmearCategoryID,0) as xid, + M_PapSmearCategoryID as category_id, + M_PapSmearCategoryName as name, + IF(ISNULL(Other_PapsmearCategoryID),'N','Y') as selected + FROM m_papsmearcategory + LEFT JOIN other_papsmearcategory ON Other_PapsmearCategoryM_PapSmearCategoryID = M_PapSmearCategoryID AND + Other_PapsmearCategoryOther_PapSmearID = {$header_id} AND + Other_PapsmearCategoryIsActive = 'Y' + WHERE + M_PapSmearCategoryIsActive = 'Y' + ORDER BY M_PapSmearCategoryID ASC + "; + //echo $sql; + $categories = $this->db_smartone->query($sql)->result_array(); + + $sql = "SELECT IFNULL(Other_PapSmearCheckID,0) as xid, + M_PapSmearCheckID as check_id, + M_PapSmearCheckLabel as name, + IF(ISNULL(Other_PapSmearCheckID),'N','Y') as selected, + Other_PapSmearCheckNote as note + FROM m_papsmearcheck + LEFT JOIN other_papsmearcheck ON Other_PapSmearCheckM_PapSmearCheckID = M_PapSmearCheckID AND + Other_PapSmearCheckOther_PapSmearID = {$header_id} AND + Other_PapSmearCheckIsActive = 'Y' + WHERE + M_PapSmearCheckIsActive = 'Y' + ORDER BY M_PapSmearCheckCode ASC + "; + $checks = $this->db_smartone->query($sql)->result_array(); + + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $rst = array('doctors' => $doctors, 'checks' => $checks, 'bahans' => $bahans, 'categories' => $categories, 'maturasi' => $maturasi, 'results' => $rows); + $this->sys_ok(["records" => $rst]); + } + + function saveresult_lcprep() + { + $prm = $this->sys_input; + $detail_id = $prm['detail_id']; + $doctor_id = $prm['doctor']; + $adekuasi = $prm['adekuasi']; + $kategoriumum = $prm['kategoriumum']; + $interpretasi = $prm['interpretasi']; + $results = $prm['results']; + + $userid = $this->sys_user['M_UserID']; + + $header_id = 0; + $sql = "SELECT * FROM other_lcprep WHERE Other_LcprepT_orderDetailID = {$detail_id} AND Other_LcprepIsActive = 'Y'"; + $dt_header = $this->db_smartone->query($sql)->row_array(); + if ($dt_header) { + $header_id = $dt_header['Other_LcprepID']; + } + if ($header_id == 0) { + $sql = "INSERT INTO other_lcprep( + Other_LcprepT_orderDetailID, + Other_LcprepM_DoctorID, + Other_LcprepUserID, + Other_LcprepCreated + ) + VALUES( + {$detail_id}, + {$doctor_id}, + {$userid}, + NOW() + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } else { + $sql = "UPDATE other_lcprep SET Other_LcprepM_DoctorID = {$doctor_id}, Other_LcprepUserID = {$userid} WHERE Other_LcprepID = {$header_id}"; + $this->db_smartone->query($sql); + } + + if ($adekuasi) { + foreach ($adekuasi as $k => $v) { + $selected = $v['chex'] ? 'Y' : 'N'; + if (intval($v['xid'] == 0)) { + $sql = "UPDATE other_lcprepadekuasi SET Other_LcprepAdekuasiIsActive = 'N' + WHERE + Other_LcprepAdekuasiOther_LcprepID = {$header_id} AND + Other_LcprepAdekuasiIsActive = 'Y' AND + Other_LcprepAdekuasiLcprep_AdekuasiID = {$v['id']}"; + $this->db_smartone->query($sql); + $sql = "INSERT INTO other_lcprepadekuasi ( + Other_LcprepAdekuasiOther_LcprepID, + Other_LcprepAdekuasiLcprep_AdekuasiID, + Other_LcprepAdekuasiChex, + Other_LcprepAdekuasiUserID, + Other_LcprepAdekuasiCreated + ) + VALUES( + {$header_id}, + {$v['id']}, + '{$selected}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + //echo $sql; + } + if (intval($v['xid'] != 0)) { + + $sql = "UPDATE other_lcprepadekuasi SET + Other_LcprepAdekuasiChex = '{$selected}', + Other_LcprepAdekuasiUserID = {$userid} + WHERE + Other_LcprepAdekuasiID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + + //echo $sql; + } + } + + if ($kategoriumum) { + foreach ($kategoriumum as $k => $v) { + $selected = $v['chex'] ? 'Y' : 'N'; + if (intval($v['xid'] == 0)) { + $sql = "UPDATE other_lcprepkategoriumum SET Other_LcprepKategoriUmumIsActive = 'N' + WHERE + Other_LcprepKategoriUmumOther_LcprepID = {$header_id} AND + Other_LcprepKategoriUmumLcprep_KategoriUmumID = {$v['id']} AND + Other_LcprepKategoriUmumIsActive = 'Y' + "; + $this->db_smartone->query($sql); + $sql = "INSERT INTO other_lcprepkategoriumum ( + Other_LcprepKategoriUmumOther_LcprepID, + Other_LcprepKategoriUmumLcprep_KategoriUmumID, + Other_LcprepKategoriUmumChex, + Other_LcprepKategoriUmumUserID, + Other_LcprepKategoriUmumCreated + ) + VALUES( + {$header_id}, + {$v['id']}, + '{$selected}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if (intval($v['xid'] != 0)) { + $sql = "UPDATE other_lcprepkategoriumum SET + Other_LcprepKategoriUmumChex = '{$selected}', + Other_LcprepKategoriUmumUserID = {$userid} + WHERE + Other_LcprepKategoriUmumID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + + //echo $sql; + } + } + + if ($results) { + foreach ($results as $k => $v) { + if (intval($v['xid'] == 0)) { + $sql = "UPDATE other_lcprepdetails SET Other_LcprepDetailsIsActive = 'N' + WHERE + Other_LcprepDetailsOther_LcprepID = {$header_id} AND + Other_LcprepDetailsCode = '{$v['code']}' AND + Other_LcprepDetailsIsActive = 'Y'"; + $this->db_smartone->query($sql); + $sql = "INSERT INTO other_lcprepdetails ( + Other_LcprepDetailsOther_LcprepID, + Other_LcprepDetailsCode, + Other_LcprepDetailsLabel, + Other_LcprepDetailsResult, + Other_LcprepDetailsUserID, + Other_LcprepDetailsCreated + ) + VALUES( + {$header_id}, + '{$v['code']}', + '{$v['label']}', + '{$v['result']}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if (intval($v['xid'] != 0)) { + $sql = "UPDATE other_lcprepdetails SET + Other_LcprepDetailsCode = '{$v['code']}', + Other_LcprepDetailsLabel = '{$v['label']}', + Other_LcprepDetailsResult = '{$v['result']}', + Other_LcprepDetailsUserID = {$userid} + WHERE + Other_LcprepDetailsID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + //echo $sql; + } + } + + if ($interpretasi) { + foreach ($interpretasi as $k => $v) { + if (count($v['subgroups']) > 0) { + foreach ($v['subgroups'] as $ik => $iv) { + if (count($iv['childs']) > 0) { + foreach ($iv['childs'] as $iik => $iiv) { + if (intval($iiv['xid'] == 0)) { + $chex = $iiv['chex'] ? 'Y' : 'N'; + $sql = "UPDATE other_lcprepinterpretasi SET Other_LcprepInterpretasiIsActive = 'N' + WHERE + Other_LcprepInterpretasiOther_LcprepID = {$header_id} AND + Other_LcprepInterpretasiLcprep_InterpretasiID = '{$iiv['id']}' AND + Other_LcprepInterpretasiIsActive = 'Y'"; + $this->db_smartone->query($sql); + $sql = "INSERT INTO other_lcprepinterpretasi ( + Other_LcprepInterpretasiOther_LcprepID, + Other_LcprepInterpretasiLcprep_InterpretasiID, + Other_LcprepInterpretasiChex, + Other_LcprepInterpretasiValue, + Other_LcprepInterpretasiUserID, + Other_LcprepInterpretasiCreated + ) + VALUES( + {$header_id}, + '{$iiv['id']}', + '{$chex}', + '{$iiv['value']}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + + if (intval($iiv['xid'] != 0)) { + $chex = $iiv['chex'] ? 'Y' : 'N'; + $sql = "UPDATE other_lcprepinterpretasi SET + Other_LcprepInterpretasiChex = '{$chex}', + Other_LcprepInterpretasiValue = '{$iiv['value']}', + Other_LcprepInterpretasiUserID = {$userid} + WHERE + Other_LcprepInterpretasiID = {$iiv['xid']}"; + $this->db_smartone->query($sql); + //echo $sql; + + } + } + } + } + } + //echo $sql; + } + } + + + $result = array("total" => 1, "records" => array(), "sql" => ''); + $this->sys_ok($result); + exit; + } + + function saveresult_papsmear() + { + $prm = $this->sys_input; + $detail_id = $prm['detail_id']; + $doctor_id = $prm['doctor']; + $checks = $prm['checks']; + $maturasi = $prm['maturasi']; + $bahans = $prm['bahans']; + $categories = $prm['categories']; + $results = $prm['results']; + + $userid = $this->sys_user['M_UserID']; + + $header_id = 0; + $sql = "SELECT * FROM other_papsmear WHERE Other_PapSmearT_OrderDetailID = {$detail_id} AND Other_PapSmearIsActive = 'Y'"; + $dt_header = $this->db_smartone->query($sql)->row_array(); + if ($dt_header) { + $header_id = $dt_header['Other_PapSmearID']; + } + if ($header_id == 0) { + $sql = "INSERT INTO other_papsmear( + Other_PapSmearT_OrderDetailID, + Other_PapSmearM_DoctorID, + Other_PapSmearUserID, + Other_PapSmearCreated + ) + VALUES( + {$detail_id}, + {$doctor_id}, + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } else { + $sql = "UPDATE other_papsmear SET Other_PapSmearM_DoctorID = {$doctor_id}, Other_PapSmearUserID = {$userid} WHERE Other_PapSmearID = {$header_id}"; + $this->db_smartone->query($sql); + } + + if ($checks) { + foreach ($checks as $k => $v) { + if (intval($v['xid']) == 0 && $v['selected'] === 'Y') { + $sql = "INSERT INTO other_papsmearcheck ( + Other_PapSmearCheckOther_PapSmearID, + Other_PapSmearCheckM_PapSmearCheckID, + Other_PapSmearCheckNote, + Other_PapSmearCheckUserID, + Other_PapSmearCheckCreated + ) + VALUES( + {$header_id}, + {$v['check_id']}, + '{$v['note']}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if (intval($v['xid']) != 0 && $v['selected'] === 'N') { + $sql = "UPDATE other_papsmearcheck SET + Other_PapSmearCheckIsActive = 'N', + Other_PapSmearCheckUserID = {$userid} + WHERE + Other_PapSmearCheckID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + if (intval($v['xid']) != 0 && $v['selected'] === 'Y') { + $sql = "UPDATE other_papsmearcheck SET + Other_PapSmearCheckNote = '{$v['note']}', + Other_PapSmearCheckUserID = {$userid} + WHERE + Other_PapSmearCheckID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + //echo $sql; + } + } + + if ($maturasi) { + if (intval($maturasi['xid']) == 0) { + $value = join("/", $maturasi['value']); + $sql = "INSERT INTO other_papsmearmaturasi ( + Other_PapSmearMaturasiOther_PapSmearID, + Other_PapSmearMaturasiValue, + Other_PapSmearMaturasiUserID, + Other_PapSmearMaturasiCreated + ) + VALUE( + {$header_id}, + '{$value}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + //echo $sql; + } + if (intval($maturasi['xid']) != 0) { + $value = join("/", $maturasi['value']); + $sql = "UPDATE other_papsmearmaturasi SET + Other_PapSmearMaturasiValue = '{$value}', + Other_PapSmearMaturasiUserID = {$userid} + WHERE + Other_PapSmearMaturasiID = {$maturasi['xid']}"; + // echo $sql; + $this->db_smartone->query($sql); + } + } + + if ($bahans) { + foreach ($bahans as $k => $v) { + if (intval($v['xid']) == 0 && $v['selected'] === 'Y') { + $sql = "INSERT INTO other_papsmearbahan ( + Other_PapSmearBahanOther_PapSmearID, + Other_PapSmearBahanM_PapSmearBahanID, + Other_PapSmearBahanUserID, + Other_PapSmearBahanCreated + ) + VALUES( + {$header_id}, + {$v['bahan_id']}, + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if (intval($v['xid']) != 0 && $v['selected'] === 'N') { + $sql = "UPDATE other_papsmearbahan SET + Other_PapSmearBahanIsActive = 'N', + Other_PapsmearCategoryUserID = {$userid} + WHERE + Other_PapSmearBahanID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + if (intval($v['xid']) != 0 && $v['selected'] === 'Y') { + $sql = "UPDATE other_papsmearbahan SET + Other_PapSmearBahanIsActive = 'Y', + Other_PapsmearCategoryUserID = {$userid} + WHERE + Other_PapSmearBahanID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + //echo $sql; + } + } + + if ($categories) { + foreach ($categories as $k => $v) { + if (intval($v['xid']) == 0 && $v['selected'] === 'Y') { + $sql = "INSERT INTO other_papsmearcategory ( + Other_PapsmearCategoryOther_PapSmearID, + Other_PapsmearCategoryM_PapSmearCategoryID, + Other_PapsmearCategoryUserID, + Other_PapsmearCategoryCreated + ) + VALUES( + {$header_id}, + {$v['category_id']}, + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if (intval($v['xid']) != 0 && $v['selected'] === 'N') { + $sql = "UPDATE other_papsmearcategory SET + Other_PapsmearCategoryIsActive = 'N', + Other_PapsmearCategoryUserID = {$userid} + WHERE + Other_PapsmearCategoryID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + //echo $sql; + if (intval($v['xid']) != 0 && $v['selected'] === 'Y') { + $sql = "UPDATE other_papsmearcategory SET + Other_PapsmearCategoryIsActive = 'Y', + Other_PapsmearCategoryUserID = {$userid} + WHERE + Other_PapsmearCategoryID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + } + } + + if ($results) { + foreach ($results as $k => $v) { + if (intval($v['xid']) == 0) { + $sql = "INSERT INTO other_papsmeardetails ( + Other_PapSmearDetailsOther_PapSmearID, + Other_PapSmearDetailsCode, + Other_PapSmearDetailsLabel, + Other_PapSmearDetailsResult, + Other_PapSmearDetailsUserID, + Other_PapSmearDetailsCreated + ) + VALUES( + {$header_id}, + '{$v['code']}', + '{$v['label']}', + '{$v['result']}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if (intval($v['xid']) != 0) { + $sql = "UPDATE other_papsmeardetails SET + Other_PapSmearDetailsCode = '{$v['code']}', + Other_PapSmearDetailsLabel = '{$v['label']}', + Other_PapSmearDetailsResult = '{$v['result']}', + Other_PapSmearDetailsUserID = {$userid} + WHERE + Other_PapSmearDetailsID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + //echo $sql; + } + } + + $result = array("total" => 1, "records" => array(), "sql" => ''); + $this->sys_ok($result); + exit; + } + + function saveresult_fna() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = $inp['doctor']; + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + if ($prm[0]['xid'] == '0') { + $sql = "INSERT INTO other_fna( + Other_FNAM_DoctorID, + Other_FNAT_OrderDetailID, + Other_FNAUserID, + Other_FNACreated + ) + VALUES( + {$doctor_id}, + {$prm[0]['orderdetail_id']}, + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } else { + $sql = "SELECT * FROM other_fna WHERE Other_FNAT_OrderDetailID = {$prm[0]['orderdetail_id']} AND Other_FNAIsActive = 'Y'"; + $data_header = $this->db_smartone->query($sql)->row_array(); + $header_id = $data_header['Other_FNAID']; + $sql = "UPDATE other_fna SET + Other_FNAM_DoctorID = {$doctor_id}, + Other_FNAUserID = {$userid} + WHERE + Other_FNAID = {$header_id}"; + $this->db_smartone->query($sql); + } + foreach ($prm as $k => $v) { + if ($v['xid'] == '0') { + $results = str_replace("'", "\\'", $v['result']); + $sql = "INSERT INTO other_fnadetails( + Other_FNADetailsOther_FNAID , + Other_FNADetailsCode, + Other_FNADetailsLabel, + Other_FNADetailsResult, + Other_FNADetailsCreated, + Other_FNADetailsUserID + ) + VALUES( + {$header_id}, + '{$v['code']}', + '{$v['label']}', + '{$results}', + NOW(), + {$userid} + )"; + $query = $this->db_smartone->query($sql); + } else { + $results = str_replace("'", "\\'", $v['result']); + $sql = "UPDATE other_fnadetails SET + Other_FNADetailsResult = '{$results}', + Other_FNADetailsUserID = {$userid} + WHERE + Other_FNADetailsID = {$v['xid']}"; + $query = $this->db_smartone->query($sql); + } + } + + $result = array("total" => 1, "records" => array(), "sql" => ''); + $this->sys_ok($result); + exit; + } + + function saveresult_cytologi() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = $inp['doctor']; + + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + if ($prm[0]['xid'] == '0') { + $sql = "INSERT INTO other_cytologi( + Other_CytologiT_OrderDetailID, + Other_CytologiM_DoctorID, + Other_CytologiUserID, + Other_CytologiCreated + ) + VALUES( + {$prm[0]['orderdetail_id']}, + {$doctor_id}, + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } else { + $sql = "SELECT * FROM other_cytologi WHERE Other_CytologiT_OrderDetailID = {$prm[0]['orderdetail_id']} AND Other_CytologiIsActive = 'Y'"; + $data_header = $this->db_smartone->query($sql)->row_array(); + $header_id = $data_header['Other_CytologiID']; + $sql = "UPDATE other_cytologi SET + Other_CytologiM_DoctorID = {$doctor_id}, + Other_CytologiUserID = {$userid} + WHERE + Other_CytologiID = {$header_id}"; + $this->db_smartone->query($sql); + } + foreach ($prm as $k => $v) { + if ($v['xid'] == '0') { + $results = str_replace("'", "\\'", $v['result']); + $sql = "INSERT INTO other_cytologidetails( + Other_CytologiDetailsOther_CytologiID , + Other_CytologiDetailsCode, + Other_CytologiDetailsLabel, + Other_CytologiDetailsResult, + Other_CytologiDetailsCreated, + Other_CytologiDetailsUserID + ) + VALUES( + {$header_id}, + '{$v['code']}', + '{$v['label']}', + '{$results}', + NOW(), + {$userid} + )"; + $query = $this->db_smartone->query($sql); + } else { + $results = str_replace("'", "\\'", $v['result']); + $sql = "UPDATE other_cytologidetails SET + Other_CytologiDetailsResult = '{$results}', + Other_CytologiDetailsUserID = {$userid} + WHERE + Other_CytologiDetailsID = {$v['xid']}"; + $query = $this->db_smartone->query($sql); + } + } + + $result = array("total" => 1, "records" => array(), "sql" => ''); + $this->sys_ok($result); + exit; + } + + function saveresult_mikro() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = $inp['doctor']; + $backteria_id = $inp['bacteria']; + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + + if ($inp['result_value'] != 'Negatif' && $inp['result_value'] != 'Positif') { + $prm['result_value'] = $prm['result_other']; + } else { + $prm['result_value'] = $inp['result_value']; + } + + if ($prm['xid'] == '0') { + $sql = "INSERT INTO other_mikro( + Other_MikroM_DoctorID, + Other_MikroResult, + Other_MikroT_BacteriaID, + Other_MikroT_OrderDetailID, + Other_MikroHasilBiakan, + Other_MikroSampleTypeName, + Other_MikroUserID, + Other_MikroCreated + ) + VALUES( + {$doctor_id}, + '{$prm['result_value']}', + {$backteria_id}, + {$prm['orderdetail_id']}, + '{$prm['hasil_biakan']}', + '{$prm['sample_name']}', + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } else { + $sql = "SELECT * FROM other_mikro WHERE Other_MikroT_OrderDetailID = {$prm['orderdetail_id']} AND Other_MikroIsActive = 'Y'"; + $data_header = $this->db_smartone->query($sql)->row_array(); + $header_id = $data_header['Other_MikroID']; + $sql = "UPDATE other_mikro SET + Other_MikroResult = '{$prm['result_value']}', + Other_MikroM_DoctorID = {$doctor_id}, + Other_MikroT_BacteriaID = {$backteria_id}, + Other_MikroHasilBiakan = '{$prm['hasil_biakan']}', + Other_MikroSampleTypeName = '{$prm['sample_name']}', + Other_MikroUserID = {$userid} + WHERE + Other_MikroID = {$header_id}"; + //echo $sql; + $this->db_smartone->query($sql); + } + + + + $sql = "UPDATE other_mikrodetails SET Other_MikroDetailsIsActive = 'N', Other_MikroDetailsUserID = 0 WHERE Other_MikroDetailsOther_MikroID = {$header_id}"; + $this->db_smartone->query($sql); + + $results = $prm['details']; + if ($inp['result_value'] == 'Positif') { + foreach ($results as $k => $v) { + if ($v['xid'] == '0') { + $sql = "INSERT INTO other_mikrodetails( + Other_MikroDetailsOther_MikroID , + Other_MikroDetailsT_AntibioticID, + Other_MikroDetailsValue, + Other_MikroDetailsNote, + Other_MikroDetailsCreated, + Other_MikroDetailsUserID + ) + VALUES( + {$header_id}, + '{$v['T_AntibioticID']}', + '{$v['value']}', + '{$v['note']}', + NOW(), + {$userid} + )"; + $query = $this->db_smartone->query($sql); + } else { + $sql = "UPDATE other_mikrodetails SET + Other_MikroDetailsT_AntibioticID = '{$v['T_AntibioticID']}', + Other_MikroDetailsValue = '{$v['value']}', + Other_MikroDetailsNote = '{$v['note']}', + Other_MikroDetailsIsActive = 'Y', + Other_MikroDetailsUserID = {$userid} + WHERE + Other_MikroDetailsID = {$v['xid']}"; + //echo $sql; + $query = $this->db_smartone->query($sql); + } + } + } + + + $result = array("total" => 1, "records" => array(), "sql" => ''); + $this->sys_ok($result); + exit; + } + + + function get_doctors_preparasi_sperma() + { + $prm = $this->sys_input; + // $id = $prm["id"]; + + $sql = " SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 10 AND + M_DoctorSOIsActive = 'Y' + ORDER BY M_DoctorName ASC"; + //echo $sql; + $query = $this->db_smartone->query($sql); + $rows = $query->result_array(); + $sql = " + SELECT '0' as id, 'Belum memilih metode' as name + UNION + SELECT M_MethodeSpermaID as id, M_MethodeSpermaName as name + FROM m_methodesperma + WHERE + M_MethodeSpermaIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $methodes = $this->db_smartone->query($sql)->result_array(); + + + $this->sys_ok(["records" => $rows, "methodes" => $methodes]); + } + + + function getpreparasispermaresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT other_preparasisperma.*, + Other_PreparasiSpermaID as xid, + Other_PreparasiSpermaT_OrderDetailID as orderdetail_id, + IFNULL(Other_PreparasiSpermaM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_PreparasiSpermaM_DoctorID) OR Other_PreparasiSpermaM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name, + IFNULL(M_MethodeSpermaID,0) as methode_id, + IFNULL(M_MethodeSpermaName,'') as methode_name + FROM other_preparasisperma + LEFT JOIN m_doctor ON Other_PreparasiSpermaM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + LEFT JOIN m_methodesperma ON Other_PreparasiSpermaM_MethodeSpermaID = M_MethodeSpermaID AND + M_MethodeSpermaIsActive = 'Y' + WHERE + Other_PreparasiSpermaT_OrderDetailID = {$id} AND Other_PreparasiSpermaIsActive = 'Y' + GROUP BY Other_PreparasiSpermaID"; + $query = $this->db_smartone->query($sql); + + if ($query) { + $rows = $query->row_array(); + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 10 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $sql = " + SELECT '0' as id, 'Belum memilih metode' as name + UNION + SELECT M_MethodeSpermaID as id, M_MethodeSpermaName as name + FROM m_methodesperma + WHERE + M_MethodeSpermaIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $methodes = $this->db_smartone->query($sql)->result_array(); + $images = array(); + $sql = "SELECT Other_PreparasiSpermaImgID as xid, + Other_PreparasiSpermaImgType as type, + CONCAT('/one-media/one-image-nonlab/',Other_PreparasiSpermaImgNewName) as image_url + FROM t_orderdetail + JOIN other_preparasisperma_img ON Other_PreparasiSpermaImgT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND + Other_PreparasiSpermaImgIsActive = 'Y' + WHERE + T_OrderDetailID = {$id} AND + T_OrderDetailIsActive = 'Y' + GROUP BY Other_PreparasiSpermaImgID"; + //echo $sql; + $images = $this->db_smartone->query($sql)->result_array(); + + $rst = array('doctors' => $doctors, 'methodes' => $methodes, 'results' => $rows, 'images' => $images); + $this->sys_ok(["records" => $rst]); + } else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + + function uploadimage_preparasi_sperma() + { + if (! $this->isLogin) { + $this->sys_error("Invalid Token"); + exit; + } + + $userid = $this->sys_user["M_UserID"]; + $data = []; + //print_r($_SERVER); + + $prm = $this->sys_input; + $orderid = $this->input->post('orderid'); + $type = $this->input->post('type'); + $labnumber = $this->input->post('labnumber'); + $sql = "UPDATE other_preparasisperma_img SET + Other_PreparasiSpermaImgIsActive = 'N', + Other_PreparasiSpermaImgUserID = {$userid} + WHERE + Other_PreparasiSpermaImgT_OrderHeaderID = {$orderid} AND + Other_PreparasiSpermaImgType = '{$type}'"; + //echo $sql; + $this->db_onedev->query($sql); + //$config['upload_path'] = 'assets/'; + + $path = '/home/one/project/one/one-media/one-image-nonlab/'; + //echo $path; + $config['upload_path'] = $path; + $config['allowed_types'] = 'jpg|jpeg|png|gif'; + + $config['max_size'] = '10000'; + $count = count($_FILES['files']['name']); + //echo $count; + $this->load->library('upload', $config); + + $error = []; + for ($i = 0; $i < $count; $i++) { + + + if (!empty($_FILES['files']['name'][$i])) { + + + + $_FILES['file']['name'] = $_FILES['files']['name'][$i]; + + $_FILES['file']['type'] = $_FILES['files']['type'][$i]; + + $_FILES['file']['tmp_name'] = $_FILES['files']['tmp_name'][$i]; + + $_FILES['file']['error'] = $_FILES['files']['error'][$i]; + + $_FILES['file']['size'] = $_FILES['files']['size'][$i]; + + + + $namex = $orderid . '-' . $labnumber . '-' . $this->generateRandomString(5); + //echo $namex; + + $config['file_name'] = $namex; + $this->upload->initialize($config); + //echo $config['file_name'] ; + + + + + + if ($this->upload->do_upload('file')) { + + $uploadData = $this->upload->data(); + + $filename = $uploadData['file_name']; + //echo $filename; + + + $sql = "INSERT INTO other_preparasisperma_img ( + Other_PreparasiSpermaImgT_OrderHeaderID, + Other_PreparasiSpermaImgType, + Other_PreparasiSpermaImgOldName, + Other_PreparasiSpermaImgNewName, + Other_PreparasiSpermaImgCreated, + Other_PreparasiSpermaImgUserID + ) + VALUES( + {$orderid}, + '{$type}', + '{$_FILES['files']['name'][$i]}', + '{$filename}', + NOW(), + {$userid} + + )"; + //echo $sql; + $this->db_onedev->query($sql); + $xlast_id = $this->db_onedev->insert_id(); + $data['totalFiles'][] = array('xid' => $xlast_id, 'type' => $type, 'image_url' => '/one-media/one-image-nonlab/' . $filename); + } else { + $error = array('error' => $this->upload->display_errors()); + } + } + } + + $result = array("total" => count($data['totalFiles']), "records" => $data['totalFiles'], 'errors' => $error); + $this->sys_ok($result); + } + + + function saveresult_preparasi_sperma() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = $inp['doctor']; + $orderdetail_id = $inp['orderdetailid']; + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + if ($prm['xid'] == '0') { + $sql = "INSERT INTO other_preparasisperma( + Other_PreparasiSpermaM_DoctorID, + Other_PreparasiSpermaT_OrderDetailID, + Other_PreparasiSpermaPreMotilitasA, + Other_PreparasiSpermaPreMotilitasB, + Other_PreparasiSpermaPreMotilitasC, + Other_PreparasiSpermaPreKonsentrasi, + Other_PreparasiSpermaPreKontaminan, + Other_PreparasiSpermaPostMotilitasA, + Other_PreparasiSpermaPostMotilitasB, + Other_PreparasiSpermaPostMotilitasC, + Other_PreparasiSpermaPostKonsentrasi, + Other_PreparasiSpermaPostKontaminan, + Other_PreparasiSpermaPreVolume, + Other_PreparasiSpermaPostVolume, + Other_PreparasiSpermaM_MethodeSpermaID, + Other_PreparasiSpermaNote, + Other_PreparasiSpermaUserID, + Other_PreparasiSpermaCreated + ) + VALUES( + {$doctor_id}, + {$orderdetail_id}, + '{$prm['Other_PreparasiSpermaPreMotilitasA']}', + '{$prm['Other_PreparasiSpermaPreMotilitasB']}', + '{$prm['Other_PreparasiSpermaPreMotilitasC']}', + '{$prm['Other_PreparasiSpermaPreKonsentrasi']}', + '{$prm['Other_PreparasiSpermaPreKontaminan']}', + '{$prm['Other_PreparasiSpermaPostMotilitasA']}', + '{$prm['Other_PreparasiSpermaPostMotilitasB']}', + '{$prm['Other_PreparasiSpermaPostMotilitasC']}', + '{$prm['Other_PreparasiSpermaPostKonsentrasi']}', + '{$prm['Other_PreparasiSpermaPostKontaminan']}', + '{$prm['Other_PreparasiSpermaPreVolume']}', + '{$prm['Other_PreparasiSpermaPostVolume']}', + '{$prm['Other_PreparasiSpermaM_MethodeSpermaID']}', + '{$prm['Other_PreparasiSpermaNote']}', + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } else { + $sql = "SELECT * FROM other_preparasisperma WHERE Other_PreparasiSpermaT_OrderDetailID = {$orderdetail_id} AND Other_PreparasiSpermaIsActive = 'Y'"; + $data_header = $this->db_smartone->query($sql)->row_array(); + $header_id = $data_header['Other_PreparasiSpermaID']; + $sql = "UPDATE other_preparasisperma SET + Other_PreparasiSpermaM_DoctorID = {$doctor_id}, + Other_PreparasiSpermaPreMotilitasA = '{$prm['Other_PreparasiSpermaPreMotilitasA']}', + Other_PreparasiSpermaPreMotilitasB = '{$prm['Other_PreparasiSpermaPreMotilitasB']}', + Other_PreparasiSpermaPreMotilitasC = '{$prm['Other_PreparasiSpermaPreMotilitasC']}', + Other_PreparasiSpermaPreKonsentrasi = '{$prm['Other_PreparasiSpermaPreKonsentrasi']}', + Other_PreparasiSpermaPreKontaminan = '{$prm['Other_PreparasiSpermaPreKontaminan']}', + Other_PreparasiSpermaPostMotilitasA = '{$prm['Other_PreparasiSpermaPostMotilitasA']}', + Other_PreparasiSpermaPostMotilitasB = '{$prm['Other_PreparasiSpermaPostMotilitasB']}', + Other_PreparasiSpermaPostMotilitasC = '{$prm['Other_PreparasiSpermaPostMotilitasC']}', + Other_PreparasiSpermaPostKonsentrasi = '{$prm['Other_PreparasiSpermaPostKonsentrasi']}', + Other_PreparasiSpermaPostKontaminan = '{$prm['Other_PreparasiSpermaPostKontaminan']}', + Other_PreparasiSpermaPreVolume = '{$prm['Other_PreparasiSpermaPreVolume']}', + Other_PreparasiSpermaPostVolume = '{$prm['Other_PreparasiSpermaPostVolume']}', + Other_PreparasiSpermaM_MethodeSpermaID = '{$prm['Other_PreparasiSpermaM_MethodeSpermaID']}', + Other_PreparasiSpermaNote = '{$prm['Other_PreparasiSpermaNote']}', + Other_PreparasiSpermaUserID = {$userid} + WHERE + Other_PreparasiSpermaID = {$header_id}"; + $this->db_smartone->query($sql); + } + + + $result = array("total" => 1, "records" => array(), "sql" => ''); + $this->sys_ok($result); + exit; + } + + function getdnafragmentasiresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT other_dnafragmentasi.*, + Other_DnaFragmentasiID as xid, + Other_DnaFragmentasiT_OrderDetailID as orderdetail_id, + IFNULL(Other_DnaFragmentasiM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_DnaFragmentasiM_DoctorID) OR Other_DnaFragmentasiM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name, + IFNULL(Other_DnaFragmentasiOther_DnaFragmentasiMethodeID,0) as methode_id, + IFNULL(Other_DnaFragmentasiMethodeName,'') as methode_name, + Other_DnaFragmentasiHaloLuas as halo_luas, + Other_DnaFragmentasiHaloSedang as halo_sedang, + Other_DnaFragmentasiHaloSempit as halo_sempit, + Other_DnaFragmentasiTanpaHalo as tanpa_halo, + Other_DnaFragmentasiDFI as dfi, + Other_DnaFragmentasiKesimpulan as kesimpulan, + Other_DnaFragmentasiCatatan as catatan + FROM other_dnafragmentasi + LEFT JOIN m_doctor ON Other_DnaFragmentasiM_DoctorID = M_DoctorID + LEFT JOIN other_dnafragmentasimethode ON Other_DnaFragmentasiOther_DnaFragmentasiMethodeID = Other_DnaFragmentasiMethodeID + WHERE + Other_DnaFragmentasiT_OrderDetailID = {$id} AND Other_DnaFragmentasiIsActive = 'Y' + GROUP BY Other_DnaFragmentasiID + LIMIT 1"; + //echo $sql; + $query = $this->db_smartone->query($sql); + + if ($query) { + $rows = $query->row_array(); + if (!$rows) { + $rows = array( + 'xid' => 0, + 'orderdetail_id' => $id, + 'doctor_id' => 0, + 'doctor_name' => '', + 'methode_id' => 0, + 'methode_name' => '', + 'halo_luas' => '', + 'halo_sedang' => '', + 'tanpa_halo' => '', + 'dfi' => '', + 'kesimpulan' => '', + 'catatan' => '' + ); + } + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID + WHERE + M_DoctorSONat_SubGroupID = 4 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + + $sql = " + SELECT '0' as id, 'Belum memilih metode' as name + UNION + SELECT Other_DnaFragmentasiMethodeID as id, Other_DnaFragmentasiMethodeName as name + FROM other_dnafragmentasimethode + WHERE + Other_DnaFragmentasiMethodeIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $methodes = $this->db_smartone->query($sql)->result_array(); + + + $rst = array('doctors' => $doctors, 'methodes' => $methodes, 'results' => $rows); + $this->sys_ok(["records" => $rst]); + } else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + function saveresult_dnafragmentasi() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = $inp['doctor']['id']; + $methode_id = $inp['methode']['id']; + $orderdetail_id = $inp['results']['orderdetail_id']; + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + if (intval($prm['xid']) == 0) { + $sql = "INSERT INTO other_dnafragmentasi( + Other_DnaFragmentasiT_OrderDetailID, + Other_DnaFragmentasiM_DoctorID, + Other_DnaFragmentasiOther_DnaFragmentasiMethodeID, + Other_DnaFragmentasiHaloLuas, + Other_DnaFragmentasiHaloSedang, + Other_DnaFragmentasiHaloSempit, + Other_DnaFragmentasiTanpaHalo, + Other_DnaFragmentasiDFI, + Other_DnaFragmentasiKesimpulan, + Other_DnaFragmentasiCatatan, + Other_DnaFragmentasiUserID, + Other_DnaFragmentasiLastUpdated + ) + VALUES( + {$orderdetail_id}, + {$doctor_id}, + {$methode_id}, + '{$prm['halo_luas']}', + '{$prm['halo_sedang']}', + '{$prm['halo_sempit']}', + '{$prm['tanpa_halo']}', + '{$prm['dfi']}', + '{$prm['kesimpulan']}', + '{$prm['catatan']}', + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } else { + $sql = "UPDATE other_dnafragmentasi SET + Other_DnaFragmentasiT_OrderDetailID = {$orderdetail_id}, + Other_DnaFragmentasiM_DoctorID = {$doctor_id}, + Other_DnaFragmentasiOther_DnaFragmentasiMethodeID = '{$methode_id}', + Other_DnaFragmentasiHaloLuas = '{$prm['halo_luas']}', + Other_DnaFragmentasiHaloSedang = '{$prm['halo_sedang']}', + Other_DnaFragmentasiHaloSempit = '{$prm['halo_sempit']}', + Other_DnaFragmentasiTanpaHalo = '{$prm['tanpa_halo']}', + Other_DnaFragmentasiDFI = '{$prm['dfi']}', + Other_DnaFragmentasiKesimpulan = '{$prm['kesimpulan']}', + Other_DnaFragmentasiCatatan = '{$prm['catatan']}', + Other_DnaFragmentasiLastUpdated = NOW(), + Other_DnaFragmentasiUserID = {$userid} + WHERE + Other_DnaFragmentasiID = {$prm['xid']}"; + //echo $sql; + $this->db_smartone->query($sql); + } + + + $result = array("total" => 1, "records" => array(), "sql" => ''); + $this->sys_ok($result); + exit; + } +} diff --git a/application/controllers/mockup/process/westone_resultvalidation/Re_px.php b/application/controllers/mockup/process/westone_resultvalidation/Re_px.php index 8e1cbe21..dca767be 100644 --- a/application/controllers/mockup/process/westone_resultvalidation/Re_px.php +++ b/application/controllers/mockup/process/westone_resultvalidation/Re_px.php @@ -1,2513 +1,2510 @@ -db_smartone = $this->load->database("onedev", true); - $this->load->helper(array('form', 'url')); - } - function getMethodeID($natTestID) - { - $sql = "select M_MethodePriorityNat_MethodeID MethodeID, Nat_MethodeName - from - m_methode_priority - join nat_methode on Nat_MethodeID = M_MethodePriorityNat_MethodeID - and Nat_MethodeIsActive = 'Y' - join m_instrumentmethode on M_InstrumentMethodeNat_MethodeID = Nat_MethodeID and M_InstrumentMethodeIsActive = 'Y' - join nat_instrument on M_InstrumentMethodeNat_InstrumentID = Nat_InstrumentID - and Nat_InstrumentIsActive ='Y' - where M_MethodePriorityIsActive = 'Y' - and M_MethodePriorityNat_TestID = $natTestID - and M_MethodePriorityM_DayOfWeekID = dayofweek(now()) - order by M_MethodePriorityNumber desc - limit 0,1 "; - $qry = $this->db->query($sql); - if ($qry) { - $rows = $qry->result_array(); - if (count($rows) > 0) return array($rows[0]["MethodeID"], $rows[0]["Nat_MethodeName"]); - } - //2nd - $sql = "select - M_InstrumentMethodeNat_MethodeID MethodeID, Nat_MethodeName - from m_instrumentmethode - join nat_methode on M_InstrumentMethodeNat_MethodeID = Nat_MethodeID - and Nat_MethodeIsActive = 'Y' - join nat_instrument on M_InstrumentMethodeNat_InstrumentID = Nat_InstrumentID - and Nat_InstrumentIsActive ='Y' - where M_InstrumentMethodeNat_TestID = $natTestID - and M_InstrumentMethodeIsActive = 'Y' - order by M_InstrumentMethodePriority desc - limit 0,1"; - $qry = $this->db->query($sql); - if ($qry) { - $rows = $qry->result_array(); - if (count($rows) > 0) return array($rows[0]["MethodeID"], $rows[0]["Nat_MethodeName"]); - } - // - $sql = "select Nat_NormalValueNat_MethodeID MethodeID, Nat_MethodeName - from - nat_normalvalue - join nat_methode on Nat_NormalValueNat_MethodeID = Nat_MethodeID - and Nat_MethodeIsActive = 'Y' - where Nat_NormalValueNat_TestID = $natTestID - and Nat_NormalValueIsActive = 'Y' - order by Nat_NormalValueID - limit 0,1"; - $qry = $this->db->query($sql); - if ($qry) { - $rows = $qry->result_array(); - if (count($rows) > 0) return array($rows[0]["MethodeID"], $rows[0]["Nat_MethodeName"]); - } - return array(0, ""); - } - function get_normal_value($methodeID, $natTestID, $sexID, $ageInDay) - { - $sql = "select fn_sampling_get_normal($methodeID, $natTestID, $sexID, $ageInDay) as normalValueID"; - $qry = $this->db->query($sql); - if ($qry) { - $rows = $qry->result_array(); - if (count($rows) > 0) return $rows[0]["normalValueID"]; - } - return 0; - } - function fn_fix_normal($order_id) - { - $sql = "select - T_OrderDetailID, M_PatientM_SexID, fn_global_age_count_day(M_PatientDOB, date(T_OrderHeaderDate)) Dob , - T_TestNat_TestID - from t_orderheader - join m_patient on T_OrderHeaderID = $order_id and T_OrderHeaderM_PatientID = M_PatientID - join t_orderdetail on T_OrderDetailT_OrderHeaderID = T_OrderHeaderID - and T_OrderDetailIsACtive = 'Y' - and ( T_OrderDetailNat_NormalValueID is null or T_OrderDetailNat_NormalValueID = 0 ) - join t_test on T_OrderDetailT_TestID = T_TestID and T_TestIsResult = 'Y' "; - $qry = $this->db->query($sql); - if (! $qry) { - return; - } - $rows = $qry->result_array(); - if (count($rows) == 0) return; - $sql_u = "update t_orderdetail - join nat_normalvalue on T_OrderDetailID = ? and Nat_NormalValueID = ? - set - T_OrderDetailNat_NormalValueID = Nat_NormalValueID, - T_OrderDetailNormalValueNote = Nat_NormalValueNote, - T_OrderDetailNormalValueDescription = Nat_NormalValueDescription, - T_OrderDetailMinValue = Nat_NormalValueMinValue, - T_OrderDetailMaxValue = Nat_NormalValueMaxValue, - T_OrderDetailMinValueInclusive = Nat_NormalValueMinValueInclusive, - T_OrderDetailMaxValueInclusive = Nat_NormalValueMaxValueInclusive, - T_OrderDetailNat_MethodeID = ?, - T_OrderdetailNat_MethodeName =?"; - - foreach ($rows as $r) { - $T_OrderDetailID = $r["T_OrderDetailID"]; - $sexID = $r["M_PatientM_SexID"]; - $ageInDay = $r["Dob"]; - $natTestID = $r["T_TestNat_TestID"]; - list($methodeID, $methodeName) = $this->getMethodeID($natTestID); - if ($methodeID == 0) continue; - $normalValueID = $this->get_normal_value($methodeID, $natTestID, $sexID, $ageInDay); - if ($normalValueID == 0) return; - $this->db->query($sql_u, array($T_OrderDetailID, $normalValueID, $methodeID, $methodeName)); - } - } - function update_order_sample($targetID, $sourceID) - { - $sql = "update t_ordersample target - join t_ordersample source on - target.T_OrderSampleID = ? - and target.T_OrderSampleWorklistReceive = 'N' - and source.T_OrderSampleID = ? - set - target.T_OrderSampleSampling = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSampling, source.T_OrderSampleSampling), - target.T_OrderSampleSamplingDate = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingDate, source.T_OrderSampleSamplingDate), - target.T_OrderSampleSamplingTime = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingTime, source.T_OrderSampleSamplingTime), - target.T_OrderSampleSamplingUserID = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingUserID, source.T_OrderSampleSamplingUserID), - - target.T_OrderSampleReceive = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceive, source.T_OrderSampleReceive), - target.T_OrderSampleReceiveDate = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveDate, source.T_OrderSampleReceiveDate), - target.T_OrderSampleReceiveTime = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveTime, source.T_OrderSampleReceiveTime), - target.T_OrderSampleReceiveUserID = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveUserID, source.T_OrderSampleReceiveUserID), - - target.T_OrderSampleVerification = if(target.T_OrderSampleVerification='Y',target.T_OrderSampleVerification, source.T_OrderSampleVerification), - target.T_OrderSampleVerificationDate =if(target.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationDate, source.T_OrderSampleVerificationDate), - target.T_OrderSampleVerificationTime =if(source.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationTime, source.T_OrderSampleVerificationTime), - target.T_OrderSampleVerificationUserID =if(source.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationUserID, source.T_OrderSampleVerificationUserID), - - target.T_OrderSampleProcessing = if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessing, source.T_OrderSampleProcessing), - target.T_OrderSampleProcessingDate= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingDate, source.T_OrderSampleProcessingDate), - target.T_OrderSampleProcessingTime= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingTime, source.T_OrderSampleProcessingTime), - target.T_OrderSampleProcessingUserID= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingUserID, source.T_OrderSampleProcessingUserID), - - target.T_OrderSampleReceiveHandling =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandling, source.T_OrderSampleReceiveHandling ), - target.T_OrderSampleReceiveHandlingDate =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingDate, source.T_OrderSampleReceiveHandlingDate), - target.T_OrderSampleReceiveHandlingTime =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingTime, source.T_OrderSampleReceiveHandlingTime), - target.T_OrderSampleReceiveHandlingUserID =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingUserID, source.T_OrderSampleReceiveHandlingUserID), - - target.T_OrderSampleHandling = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandling, source.T_OrderSampleHandling), - target.T_OrderSampleHandlingDate = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingDate, source.T_OrderSampleHandlingDate), - target.T_OrderSampleHandlingTime = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingTime, source.T_OrderSampleHandlingTime), - target.T_OrderSampleHandlingUserID = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingUserID, source.T_OrderSampleHandlingUserID), - - target.T_OrderSampleWorklistReceive = source.T_OrderSampleWorklistReceive, - target.T_OrderSampleWorklistReceiveDatetime = source.T_OrderSampleWorklistReceiveDateTime, - target.T_OrderSampleWorklistReceiveUserID = source.T_OrderSampleWorklistReceiveUserID - "; - $qry = $this->db->query($sql, array($targetID, $sourceID)); - if (! $qry) { - echo json_encode(array("status" => "ERR", "message" => print_r($this->db->error(), true))); - exit; - } - } - function fix_sample_serum($headerID) - { - //cari t_ordersample yg belum worklist receive dengan code 017% - $sql = "select T_OrderSampleID - from t_ordersample - join t_sampletype on - T_OrderSampleT_OrderHeaderID = ? - and T_OrderSampleWorklistReceive = 'N' - and T_OrderSampleIsActive = 'Y' - and T_OrderSampleT_SampleTypeID = T_SampletypeID - and T_SampleTypeCode like '017%' - "; - $qry = $this->db->query($sql, array($headerID)); - if (!$qry) { - echo json_encode(array("status" => "ERR", "message" => print_r($this->db->error(), true))); - exit; - } - $rows = $qry->result_array(); - if (count($rows) == 0) return; - //cari T_OrderSample yang sudah di receive yg terakhir - $sql = "select T_OrderSampleID - from t_ordersample - join t_sampletype on - T_OrderSampleT_OrderHeaderID = ? - and T_OrderSampleWorklistReceive = 'Y' - and T_OrderSampleIsActive = 'Y' - and T_OrderSampleT_SampleTypeID = T_SampletypeID - and T_SampleTypeCode like '017%' - order by T_OrderSampleWorklistReceiveDatetime desc - limit 0,1 - "; - $qry = $this->db->query($sql, array($headerID)); - if (!$qry) { - echo json_encode(array("status" => "ERR", "message" => print_r($this->db->error(), true))); - exit; - } - $rcv_rows = $qry->result_array(); - if (count($rcv_rows) == 0) return; - - //print_r($rows); - //print_r($rcv_rows); - $rcv_T_OrderSampleID = $rcv_rows[0]["T_OrderSampleID"]; - //ada yg belum di receive - foreach ($rows as $r) { - $T_OrderSampleID = $r["T_OrderSampleID"]; - $this->update_order_sample($T_OrderSampleID, $rcv_T_OrderSampleID); - } - } - public function search() - { - $prm = $this->sys_input; - $max_rst = 99; - - $id = $prm["order_id"]; - if ($id > 0) { - $this->fix_sample_serum($id); - $this->fn_fix_normal($id); - } - $lang = $this->lang_default_code; - $lang_id = isset($prm['lang_id']) ? $prm['lang_id'] : '0'; - - if ($lang_id != 0) { - $l = $this->db_smartone->where("Nat_LangID", $lang_id)->get("nat_lang")->row(); - $lang = $l->Nat_LangCode; - } - - //tambahan fajri - $sql = " UPDATE t_orderdetail - JOIN t_test ON T_OrderDetailT_TestID = T_TestID - SET T_OrderDetailT_TestIsResult = T_TestIsResult - WHERE - T_OrderDetailT_OrderHeaderID = {$id} AND - T_OrderDetailT_TestIsResult = '' AND - T_OrderDetailIsActive = 'Y'"; - $this->db_smartone->query($sql); - - $tot_count = 0; - $lq = ""; - $group_id = 0; - if (isset($prm['group_id'])) - $group_id = $prm['group_id']; - - if ($group_id != 0) { - $sql = "select distinct T_WorklistDetailNat_TestID Nat_TestID - from t_worklistdetailv2 - where T_WorklistDetailT_WorklistID = {$group_id}"; - $qry = $this->db_smartone->query($sql); - $rows = $qry->result_array(); - $nat_test_ids = "0"; - foreach ($rows as $r) { - $nat_test_ids .= ", " . $r["Nat_TestID"]; - } - $q_group = " ( $nat_test_ids ) "; - - $sql = " - SELECT a1.*, cOUNT(a2.T_OrderDetailID) level - FROM ( - SELECT IFNULL(y.T_OrderDetailT_TestID, x.T_OrderDetailT_TestID) t_testid, - IFNULL(y.T_OrderDetailT_TestName, y.T_OrderDetailT_TestName) t_testname, - y.T_OrderDetailResult result, y.T_OrderDetailResult result_old, y.T_OrderDetailNote note, y.T_OrderDetailNote note_old, - y.T_OrderDetailID id, - y.T_OrderDetailT_TestIsResult is_result, a.T_TestIsQuantitative is_quantitative, - y.T_OrderDetailResultFlag result_flag, - y.T_OrderDetailNat_NormalValueID normal_id, - y.T_OrderDetailNormalValueNote normal_note, y.T_OrderDetailNat_UnitName unit_name, - y.T_OrderdetailNat_MethodeID methode_id, y.T_OrderdetailNat_MethodeName methode_name, - a.T_TestNat_TestID nattest_id, a.T_TestID tx_id, count(T_ResultInstrumentID) as result_instrument_n, - y.T_OrderDetailVerification, T_OrderSampleReceive sample_receive, - T_OrderSampleProcessing sample_processing, T_OrderSampleWorklistReceive sample_worklist_receive, - IF(T_OrderDetailAddOnPreAnalytic = 'Y', T_OrderDetailAddOnPreAnalytic, PreAnalyticIsOk) pre_analytic, - T_OrderDetailAddOnPreAnalytic, - T_OrderHeaderID order_id, y.T_OrderDetailT_TestSasCode test_sas_code, - tx.T_TestSasCode, - T_OrderDetailAddOnResample `resample`, T_OrderDetailAddOnResampleStatus resample_status, - T_OrderDetailAddOnRef ref, y.T_OrderDetailVerification verification, y.T_OrderDetailValidation validation, - T_OrderPromiseDateTime, Group_ResultName as ResultGroupName - FROM t_orderdetail x - left join t_orderpromise on x.T_OrderDetailT_OrderPromiseID = T_OrderPromiseID - JOIN t_test tx ON x.T_OrderDetailT_TestID = T_TestID - JOIN t_test tcheck on tcheck.T_TestNat_TestID in {$q_group} - and ( tx.T_TestID = tcheck.T_TestID or tx.T_TestSasCode like concat(tcheck.T_TestSasCode,'%')) - LEFT JOIN group_resultdetail ON Group_ResultDetailT_TestID = x.T_OrderDetailT_TestID AND Group_ResultDetailIsActive = 'Y' - LEFT JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND Group_ResultFlagNonLab = 'N' - LEFT JOIN t_orderdetail y ON x.T_OrderDetailT_TestSasCode LIKE CONCAT(y.T_OrderDetailT_TestSasCode, '%') - AND x.T_OrderDetailT_OrderHeaderID = y.T_OrderDetailT_OrderHeaderID - AND y.T_OrderDetailIsActive = 'Y' - LEFT JOIN t_orderdetailaddon ON x.T_OrderDetailID = T_OrderDetailAddOnT_OrderDetailID - JOIN t_orderheader ON y.T_OrderDetailT_OrderHeaderID = T_OrderHeaderID - LEFT JOIN t_test a ON y.T_OrderDetailT_TestID = a.T_TestID - AND a.T_TestIsNonLab = '' - LEFT JOIN (SELECT T_OrderSampleT_SampleTypeID, T_OrderSampleReceive, T_OrderSampleProcessing, T_OrderSampleWorklistReceive - FROM t_ordersample WHERE T_OrderSampleT_OrderHeaderID = {$id} - AND T_OrderSampleIsactive = 'Y' - GROUP BY T_OrderSampleT_SampleTypeID) os ON a.T_TestT_SampleTypeID = os.T_OrderSampleT_SampleTypeID - or os.T_OrderSampleT_SampleTypeID = fn_sampletype_from_local(a.T_TestNat_TestID) - - LEFT JOIN t_resultinstrument ON T_ResultInstrumentT_OrderDetailID = x.T_OrderDetailID - LEFT JOIN pre_analytic ON PreAnalyticNat_TestID = a.T_TestNat_TestID AND PreAnalyticDate = date(now()) and PreAnalyticIsActive = 'Y' - WHERE x.T_OrderDetailT_OrderHeaderID = {$id} - AND x.T_OrderDetailIsActive = 'Y' - GROUP BY y.T_OrderDetailT_TestID - ORDER BY y.T_OrderDetailT_TestSasCode ASC - ) a1 - - LEFT JOIN t_orderdetail a2 ON a2.T_OrderDetailT_OrderHeaderID = a1.order_id - AND a2.T_OrderDetailIsActive = 'Y' - AND a1.test_sas_code LIKE CONCAT(a2.T_OrderDetailT_testSasCode, '%') - GROUP BY a1.t_testid - order by a1.test_sas_code -"; - $query = $this->db_smartone->query($sql); - $lq = $this->db_smartone->last_query(); - } else { - $sql = " - SELECT a1.*, cOUNT(a2.T_OrderDetailID) level - FROM ( - SELECT IFNULL(y.T_OrderDetailT_TestID, x.T_OrderDetailT_TestID) t_testid, - IFNULL(y.T_OrderDetailT_TestName, y.T_OrderDetailT_TestName) t_testname, - y.T_OrderDetailResult result, y.T_OrderDetailResult result_old, y.T_OrderDetailNote note, y.T_OrderDetailNote note_old, - y.T_OrderDetailID id, - y.T_OrderDetailT_TestIsResult is_result, a.T_TestIsQuantitative is_quantitative, - y.T_OrderDetailResultFlag result_flag, - y.T_OrderDetailNat_NormalValueID normal_id, - y.T_OrderDetailNormalValueNote normal_note, y.T_OrderDetailNat_UnitName unit_name, - y.T_OrderdetailNat_MethodeID methode_id, y.T_OrderdetailNat_MethodeName methode_name, - a.T_TestNat_TestID nattest_id, a.T_TestID tx_id, count(T_ResultInstrumentID) as result_instrument_n, - y.T_OrderDetailVerification, T_OrderSampleReceive sample_receive, - T_OrderSampleProcessing sample_processing, T_OrderSampleWorklistReceive sample_worklist_receive, - IF(T_OrderDetailAddOnPreAnalytic = 'Y', T_OrderDetailAddOnPreAnalytic, PreAnalyticIsOk) pre_analytic, - T_OrderDetailAddOnPreAnalytic, - T_OrderHeaderID order_id, y.T_OrderDetailT_TestSasCode test_sas_code, - tx.T_TestSasCode, - T_OrderDetailAddOnResample `resample`, T_OrderDetailAddOnResampleStatus resample_status, - T_OrderDetailAddOnRef ref, y.T_OrderDetailVerification verification, y.T_OrderDetailValidation validation, - T_OrderPromiseDateTime , Group_ResultName as ResultGroupName - FROM t_orderdetail x - left join t_orderpromise on x.T_OrderDetailT_OrderPromiseID = T_OrderPromiseID - JOIN t_test tx ON x.T_OrderDetailT_TestID = T_TestID - LEFT JOIN group_resultdetail ON Group_ResultDetailT_TestID = x.T_OrderDetailT_TestID AND Group_ResultDetailIsActive = 'Y' - LEFT JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND Group_ResultFlagNonLab = 'N' - LEFT JOIN t_orderdetail y ON x.T_OrderDetailT_TestSasCode LIKE CONCAT(y.T_OrderDetailT_TestSasCode, '%') - AND x.T_OrderDetailT_OrderHeaderID = y.T_OrderDetailT_OrderHeaderID - AND y.T_OrderDetailIsActive = 'Y' - - LEFT JOIN t_orderdetailaddon ON x.T_OrderDetailID = T_OrderDetailAddOnT_OrderDetailID - - JOIN t_orderheader ON y.T_OrderDetailT_OrderHeaderID = T_OrderHeaderID - LEFT JOIN t_test a ON y.T_OrderDetailT_TestID = a.T_TestID - AND a.T_TestIsNonLab = '' - LEFT JOIN (SELECT T_OrderSampleT_SampleTypeID, T_OrderSampleReceive, T_OrderSampleProcessing, T_OrderSampleWorklistReceive - FROM t_ordersample WHERE T_OrderSampleT_OrderHeaderID = {$id} - AND T_OrderSampleIsactive = 'Y' - GROUP BY T_OrderSampleT_SampleTypeID) os ON a.T_TestT_SampleTypeID = os.T_OrderSampleT_SampleTypeID - or os.T_OrderSampleT_SampleTypeID = fn_sampletype_from_local(a.T_TestNat_TestID) - - LEFT JOIN t_resultinstrument ON T_ResultInstrumentT_OrderDetailID = x.T_OrderDetailID - LEFT JOIN pre_analytic ON PreAnalyticNat_TestID = a.T_TestNat_TestID AND PreAnalyticDate = date(now()) and PreAnalyticIsActive = 'Y' - WHERE x.T_OrderDetailT_OrderHeaderID = {$id} - AND x.T_OrderDetailIsActive = 'Y' - GROUP BY y.T_OrderDetailT_TestID - ORDER BY y.T_OrderDetailT_TestSasCode ASC - ) a1 - - LEFT JOIN t_orderdetail a2 ON a2.T_OrderDetailT_OrderHeaderID = a1.order_id - AND a2.T_OrderDetailIsActive = 'Y' - AND a1.test_sas_code LIKE CONCAT(a2.T_OrderDetailT_testSasCode, '%') - GROUP BY a1.t_testid - order by a1.test_sas_code -"; - //echo $sql; - $query = $this->db_smartone->query($sql); - $lq = $this->db_smartone->last_query(); - } - // file_put_contents("/xtmp/re-query.sql",$lq); - - if ($query) { - $rst = []; - $rows = $query->result_array(); - - foreach ($rows as $k => $v) { - - if ($v['is_result'] == "Y" && $v['is_quantitative'] == "N") { - $v['template'] = []; - $x = $this->db_smartone->query("CALL sp_master_resulttemplate_get('{$v['t_testid']}')"); - $this->clean_mysqli_connection($this->db_smartone->conn_id); - if ($x) - $v['template'] = $x->result_array(); - } - - // IF Rujukan, by pas Pre Analytik - if ($v['ref'] == 'Y') - $v['pre_analytic'] = 'Y'; - if ($v["id"] == "885455") { - //sipe workaround - //$v["sample_receive"] = "Y"; - $v["sample_worklist_receive"] = "Y"; - } - $rst[] = $v; - } - - $result = array("total" => $tot_count, "records" => $rst, "total_display" => sizeof($rows), "q" => $lq); - $this->sys_ok($result); - } else { - $this->sys_error_db("RE Px rows", $this->db_smartone); - exit; - } - } - - public function save() - { - $prm = $this->sys_input; - $data = json_decode($prm["data"]); - $lang = $this->lang_default_code; - $lang_id = isset($prm['lang_id']) ? $prm['lang_id'] : '0'; - - if ($lang_id != 0) { - $l = $this->db_smartone->where("Nat_LangID", $lang_id)->get("nat_lang")->row(); - $lang = $l->Nat_LangCode; - } - - $sql_norm = "select T_OrderDetailMinValue, T_OrderDetailMaxValue, - T_OrderDetailMinValueInclusive, T_OrderDetailMaxValueInclusive, - Nat_TestFlagLow, Nat_TestFlagHigh - from t_orderdetail - join t_test on T_OrderDetailT_TestID = T_TestID - join nat_test on T_TestNat_TestID = Nat_TestID and T_TestIsActive = 'Y' - where T_OrderDetailID = ? "; - - $ids = []; - foreach ($data as $k => $v) { - if ($v->resultInstrumentID > 0) { - $sql_i = "select T_ResultInstrumentNat_NormalValueID normalValueID - from t_resultinstrument - where T_ResultInstrumentID = ?"; - $qry_i = $this->db_smartone->query($sql_i, array($v->resultInstrumentID)); - if ($qry_i) { - $rows_i = $qry_i->result_array(); - - if (count($rows_i) > 0) { - $sql_iu = "update t_orderdetail, nat_normalvalue , nat_methode - set T_OrderDetailMinValue = Nat_NormalValueMinValue, - T_OrderDetailMinValueInclusive = Nat_NormalValueMinValueInclusive, - T_OrderDetailMaxValue = Nat_NormalValueMaxValue , - T_OrderDetailMaxValueInclusive = Nat_NormalValueMaxValueInclusive, - T_OrderDetailNormalValueNote = Nat_NormalValueNote, - T_OrderDetailNormalValueDescription = Nat_NormalValueDescription, - T_OrderDetailNat_NormalValueID = Nat_NormalValueID, - T_OrderDetailNat_MethodeID = Nat_NormalValueNat_MethodeID, - T_OrderDetailNat_MethodeName = Nat_MethodeName - where T_OrderDetailID = ? and Nat_NormalValueID = ? - and Nat_NormalValueNat_MethodeID = Nat_MethodeID - "; - $this->db_smartone->query($sql_iu, array($v->id, $rows_i[0]["normalValueID"])); - //file_put_contents("/xtmp/update-nilai-normal", $this->db_smartone->last_query() . "\n", FILE_APPEND); - } - } - } - $y = $this->db_smartone->query("SELECT fn_process_sample_handling_perfect('{$v->order_id}', '{$v->test_id}') c") - ->row(); - $req_status = $y->c; - $qry_norm = $this->db_smartone->query($sql_norm, $v->id); - $result_flag = ""; - if ($qry_norm) { - $rows_norm = $qry_norm->result_array(); - if (count($rows_norm) > 0) { - $r = $rows_norm[0]; - if (is_numeric($v->result)) { - - if ($r["T_OrderDetailMinValueInclusive"] == "Y" && $v->result < $r["T_OrderDetailMinValue"]) { - $result_flag = $r["Nat_TestFlagLow"]; - } - if ($r["T_OrderDetailMinValueInclusive"] == "N" && $v->result <= $r["T_OrderDetailMinValue"]) { - $result_flag = $r["Nat_TestFlagLow"]; - } - if ($r["T_OrderDetailMaxValueInclusive"] == "Y" && $v->result > $r["T_OrderDetailMaxValue"]) { - $result_flag = $r["Nat_TestFlagHigh"]; - } - if ($r["T_OrderDetailMaxValueInclusive"] == "N" && $v->result >= $r["T_OrderDetailMaxValue"]) { - $result_flag = $r["Nat_TestFlagHigh"]; - } - } - } - } - if ($lang == $this->lang_default_code) { - $this->db_smartone->set('T_OrderDetailResult', $v->result) - ->set('T_OrderDetailResultFlag', $result_flag) - ->set('T_OrderDetailNote', $v->note) - ->set('T_OrderDetailReqStatus', $req_status) - ->where('T_OrderDetailID', $v->id) - ->update('t_orderdetail'); - } else { - $this->db_smartone->set('T_OrderDetailLangResult', $v->result) - ->set('T_OrderDetailLangNote', $v->note) - ->where('T_OrderDetailLangID', $v->id) - ->update('t_orderdetaillang'); - } - - $ids[] = $v->id; - } - - // LOG Process - $order = $this->db_smartone->select('T_OrderDetailT_OrderHeaderID id, T_OrderHeaderLabNumber lab_number', false) - ->join('t_orderheader', 'T_OrderHeaderID = T_OrderDetailT_OrderHeaderID') - ->where('T_OrderDetailID', $data[0]->id) - ->get('t_orderdetail') - ->row(); - - $dblog = $this->load->database("onelog", true); - $dblog->set('Log_ProcessCode', 'PROCESS.Result.Entry') - ->set('Log_ProcessOrderID', $order->id) - ->set('Log_ProcessOrderNumber', $order->lab_number) - ->set('Log_ProcessJson', json_encode($data)) - ->set('Log_ProcessUserID', $this->sys_user['M_UserID']) - ->insert('log_process'); - // END OF Log Process - //auto calculation - $this->load->library("Resultcalc"); - $rows = $this->resultcalc->auto($order->id); - - try { - foreach ($ids as $id) { - $this->db_smartone->query("call sp_set_normal_value_flag($id)"); - $this->clean_mysqli_connection($this->db_smartone->conn_id); - } - } catch (Exception $e) { - } - - $this->sys_ok($ids); - } - - public function save_template() - { - $prm = $this->sys_input; - - $n = $this->db_smartone->select("COUNT(T_ResultTemplateID) n") - ->where("T_ResultTemplateT_TestID", $prm['test_id']) - ->where("T_ResultTemplateIsActive", "Y") - ->where("T_ResultTemplateValue", $prm['value']) - ->get('t_resulttemplate') - ->row(); - if ($n->n > 0) { - $this->sys_error_db("Insert Result Template", $this->db_smartone); - return; - } - - $r = $this->db_smartone->set("T_ResultTemplateT_TestID", $prm['test_id']) - ->set("T_ResultTemplateValue", $prm['value']) - ->insert('t_resulttemplate'); - if ($r) { - $template = []; - $x = $this->db_smartone->query("CALL sp_master_resulttemplate_get('{$prm['test_id']}')"); - $this->clean_mysqli_connection($this->db_smartone->conn_id); - if ($x) - $template = $x->result_array(); - - $this->sys_ok($template); - } - } - - public function export() - { - $prm = $this->sys_input; - - $sql = "CALL sp_process_result_lang(?, ?, ?, ?)"; - $query = $this->db_smartone->query($sql, [$prm['order_id'], $prm['lang_id'], $prm['is_si'], $this->sys_user['M_UserID']]); - if ($query) { - $r = $query->row(); - if ($r->status == "OK") { - $this->sys_ok($r->data); - return; - } - - $this->sys_error_db("Message : " . $r->message, $this->db_smartone); - } else { - $this->sys_error_db("Lang Result", $this->db_smartone); - return; - } - } - - public function search_group() - { - $prm = $this->sys_input; - $max_rst = 100; - - // QUERY TOTAL - $sql = "select count(*) total - from t_worklist - where T_WorklistIsActive = 'Y' - order by T_WorklistName ASC"; - $query = $this->db_smartone->query($sql); - - if ($query) { - $tot_count = $query->result_array()[0]["total"]; - } else { - $this->sys_error_db("worklist count", $this->db_smartone); - exit; - } - - $sql = "select T_WorklistID group_id, T_WorklistName group_name - from t_worklist - where T_WorklistIsActive = 'Y' - order by T_WorklistName ASC - limit 0, {$max_rst}"; - $query = $this->db_smartone->query($sql); - - if ($query) { - $rows = $query->result_array(); - foreach ($rows as $k => $v) - $rows[$k]['data'] = json_decode($v['data']); - $result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows), "q" => $this->db_smartone->last_query()); - $this->sys_ok($result); - } else { - $this->sys_error_db("worklist rows", $this->db_smartone); - exit; - } - } - - public function search_rerun() - { - $prm = $this->sys_input; - $id = $prm["detail_id"]; - - $sql = "CALL sp_process_result_rerun(?)"; - $query = $this->db_smartone->query($sql, [$id]); - - if ($query) { - $rows = $query->result_array(); - $this->sys_ok(["records" => $rows]); - } else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - - - function getdoctorsfna() - { - $prm = $this->sys_input; - // $id = $prm["id"]; - - $sql = " SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY M_DoctorName ASC"; - //echo $sql; - $query = $this->db_smartone->query($sql); - - if ($query) { - $rows = $query->result_array(); - $this->sys_ok(["records" => $rows]); - } else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - function getfnaresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT Other_FNADetailsID as xid, - Other_FNAT_OrderDetailID as orderdetail_id, - Other_FNADetailsCode as code, - Other_FNADetailsLabel as label, - Other_FNADetailsResult as result, - IFNULL(Other_FNAM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_FNAM_DoctorID) OR Other_FNAM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_fna - JOIN other_fnadetails ON Other_FNADetailsOther_FNAID = Other_FNAID AND Other_FNADetailsIsActive = 'Y' - LEFT JOIN m_doctor ON Other_FNAM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_FNAT_OrderDetailID = {$id} AND Other_FNAIsActive = 'Y' - GROUP BY Other_FNADetailsID - ORDER BY Other_FNADetailsCode ASC"; - $query = $this->db_smartone->query($sql); - - if ($query) { - $rows = $query->result_array(); - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $images = array(); - $sql = "SELECT So_ImageUploadID as xid, - CONCAT('/one-media/one-image-nonlab/',So_ImageUploadNewName) as image_url - FROM t_orderdetail - JOIN so_imageupload ON So_ImageUploadT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND - So_ImageUploadIsActive = 'Y' - WHERE - T_OrderDetailID = {$id} AND - T_OrderDetailIsActive = 'Y' - GROUP BY So_ImageUploadID"; - $images = $this->db_smartone->query($sql)->result_array(); - - $rst = array('doctors' => $doctors, 'results' => $rows, 'images' => $images); - $this->sys_ok(["records" => $rst]); - } else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - - function uploadimage() - { - if (! $this->isLogin) { - $this->sys_error("Invalid Token"); - exit; - } - - $userid = $this->sys_user["M_UserID"]; - $data = []; - //print_r($_SERVER); - - $prm = $this->sys_input; - $orderid = $this->input->post('orderid'); - $labnumber = $this->input->post('labnumber'); - $sql = "UPDATE so_imageupload SET - So_ImageUploadIsActive = 'N', - So_ImageUploadUserID = {$userid} - WHERE - So_ImageUploadT_OrderHeaderID = {$orderid}"; - //echo $sql; - $this->db_onedev->query($sql); - //$config['upload_path'] = 'assets/'; - - $path = '/home/one/project/one/one-media/one-image-nonlab/'; - //echo $path; - $config['upload_path'] = $path; - $config['allowed_types'] = 'jpg|jpeg|png|gif'; - - $config['max_size'] = '10000'; - $count = count($_FILES['files']['name']); - //echo $count; - $this->load->library('upload', $config); - - $error = []; - for ($i = 0; $i < $count; $i++) { - - - if (!empty($_FILES['files']['name'][$i])) { - - - - $_FILES['file']['name'] = $_FILES['files']['name'][$i]; - - $_FILES['file']['type'] = $_FILES['files']['type'][$i]; - - $_FILES['file']['tmp_name'] = $_FILES['files']['tmp_name'][$i]; - - $_FILES['file']['error'] = $_FILES['files']['error'][$i]; - - $_FILES['file']['size'] = $_FILES['files']['size'][$i]; - - - - $namex = $orderid . '-' . $labnumber . '-' . $this->generateRandomString(5); - //echo $namex; - - $config['file_name'] = $namex; - $this->upload->initialize($config); - //echo $config['file_name'] ; - - - - - - if ($this->upload->do_upload('file')) { - - $uploadData = $this->upload->data(); - - $filename = $uploadData['file_name']; - //echo $filename; - - - $sql = "INSERT INTO so_imageupload ( - So_ImageUploadT_OrderHeaderID, - So_ImageUploadT_OrderHeaderLabNumber, - So_ImageUploadT_SampleTypeID, - So_ImageUploadOldName, - So_ImageUploadNewName, - So_ImageUploadCreated, - So_ImageUploadUserID - ) - VALUES( - {$orderid}, - '{$labnumber}', - '150', - '{$_FILES['files']['name'][$i]}', - '{$filename}', - NOW(), - {$userid} - - )"; - //echo $sql; - $this->db_onedev->query($sql); - $xlast_id = $this->db_onedev->insert_id(); - $data['totalFiles'][] = array('xid' => $xlast_id, 'image_url' => '/one-media/one-image-nonlab/' . $filename); - } else { - $error = array('error' => $this->upload->display_errors()); - } - } - } - - $result = array("total" => count($data['totalFiles']), "records" => $data['totalFiles'], 'errors' => $error); - $this->sys_ok($result); - } - - - function getpatologianatomyresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT Other_PatologiAnatomyID as xid, - Other_PatologiAnatomyT_OrderDetailID as orderdetail_id, - Other_PatologiAnatomyNoSediaan as no_sediaan, - Other_PatologiAnatomyDiagnosaKlinis as diagnosa, - Other_PatologiAnatomyKeteranganKlinis as klinis, - Other_PatologiAnatomyLokasiOrgan as lokasi, - Other_PatologiAnatomyMakroskopik as makroskopik, - Other_PatologiAnatomyMikroskopik as mikroskopik, - Other_PatologiAnatomyKesimpulan as kesimpulan, - IFNULL(Other_PatologiAnatomyM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_PatologiAnatomyM_DoctorID) OR Other_PatologiAnatomyM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_patologi_anatomy - LEFT JOIN m_doctor ON Other_PatologiAnatomyM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_PatologiAnatomyT_OrderDetailID = {$id} AND Other_PatologiAnatomyIsActive = 'Y' - GROUP BY Other_PatologiAnatomyID - ORDER BY Other_PatologiAnatomyID ASC - LIMIT 1"; - $query = $this->db_smartone->query($sql); - - if ($query) { - $rows = $query->row_array(); - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - - $sql = "SELECT So_ImageUploadPatologyAnatomyID as xid, - CONCAT('/one-media/one-image-nonlab/',So_ImageUploadPatologyAnatomyNewName) as image_url, - So_ImageUploadPatologyAnatomyType as type - FROM t_orderdetail - JOIN so_imageupload_patology_anatomy ON So_ImageUploadPatologyAnatomyT_OrderHeaderID= T_OrderDetailT_OrderHeaderID AND - So_ImageUploadPatologyAnatomyIsActive= 'Y' - WHERE - T_OrderDetailID = {$id} AND - T_OrderDetailIsActive = 'Y' - GROUP BY So_ImageUploadPatologyAnatomyID"; - $images = $this->db_smartone->query($sql)->result_array(); - $mikro = []; - $makro = []; - - foreach ($images as $key => $value) { - - if ($value['type'] == 'mikro') { - $mikro[] = $value; - } - if ($value['type'] == 'makro') { - $makro[] = $value; - } - } - - $rst = array('doctors' => $doctors, 'result' => $rows, 'mikro' => $mikro, 'makro' => $makro); - $this->sys_ok(["records" => $rst]); - } else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - - - function generateRandomString($length = 10) - { - $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; - $charactersLength = strlen($characters); - $randomString = ''; - for ($i = 0; $i < $length; $i++) { - $randomString .= $characters[rand(0, $charactersLength - 1)]; - } - return $randomString; - } - - function getcytologiresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT Other_CytologiDetailsID as xid, - Other_CytologiT_OrderDetailID as orderdetail_id, - Other_CytologiDetailsCode as code, - Other_CytologiDetailsLabel as label, - Other_CytologiDetailsResult as result, - IFNULL(Other_CytologiM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_CytologiM_DoctorID) OR Other_CytologiM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_cytologi - JOIN other_cytologidetails ON Other_CytologiDetailsOther_CytologiID = Other_CytologiID AND Other_CytologiDetailsIsActive = 'Y' - LEFT JOIN m_doctor ON Other_CytologiM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_CytologiT_OrderDetailID = {$id} AND Other_CytologiIsActive = 'Y' - GROUP BY Other_CytologiDetailsID - ORDER BY Other_CytologiDetailsCode ASC"; - //echo $sql; - $query = $this->db_smartone->query($sql); - - if ($query) { - $rows = $query->result_array(); - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $rst = array('doctors' => $doctors, 'results' => $rows); - $this->sys_ok(["records" => $rst]); - } else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - function getmikroresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT - Other_MikroID as xid, - Other_MikroHasilBiakan as hasil_biakan, - Other_MikroSampleTypeName as sample_name, - Other_MikroT_OrderDetailID as orderdetail_id, - Other_MikroResult as result_value, - '' as result_other, - IFNULL(T_BacteriaID,0) as T_BacteriaID, - IFNULL(T_BacteriaName,'') as T_BacteriaName, - '' as details, - IFNULL(Other_MikroM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_MikroM_DoctorID) OR Other_MikroM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_mikro - LEFT JOIN t_bacteria ON Other_MikroT_BacteriaID = T_BacteriaID - LEFT JOIN m_doctor ON Other_MikroM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_MikroT_OrderDetailID = {$id} AND Other_MikroIsActive = 'Y' - GROUP BY Other_MikroID"; - //echo $sql; - $query = $this->db_smartone->query($sql); - - if ($query) { - $row = $query->row_array(); - if ($row) { - if ($row['result_value'] != 'Positif' && $row['result_value'] != 'Negatif') { - $row['result_other'] = $row['result_value']; - $row['result_value'] = 'other'; - } - $sql = "SELECT '' as xno, - Other_MikroDetailsID as xid, - Other_MikroDetailsValue as value, - IF(Other_MikroDetailsNote = 'R','Y','N') as chx_r, - IF(Other_MikroDetailsNote = 'I','Y','N') as chx_i, - IF(Other_MikroDetailsNote = 'S','Y','N') as chx_s, - Other_MikroDetailsNote as note, - t_antibiotic.* - FROM other_mikrodetails - LEFT JOIN t_antibiotic ON Other_MikroDetailsT_AntibioticID = T_AntibioticID - WHERE - Other_MikroDetailsOther_MikroID = {$row['xid']} AND Other_MikroDetailsIsActive = 'Y' - GROUP BY Other_MikroDetailsID - ORDER BY T_AntibioticName ASC"; - //echo $sql; - $details = $this->db_smartone->query($sql)->result_array(); - if (details) { - foreach ($details as $k => $v) { - $details[$k]['xno'] = $k + 1; - } - } - $row['details'] = $details; - } else { - $row = array('xid' => '0', 'hasil_biakan' => '', 'result_value' => 'Negatif', 'sample_name' => '', 'orderdetail_id' => $id, 'T_BacteriaID' => '0', 'T_BacteriaName' => '0', 'details' => array(), 'doctor_id' => '0', 'doctor_name' => '0'); - } - } else { - $row = array('xid' => '0', 'hasil_biakan' => '', 'result_value' => 'Negatif', 'sample_name' => '', 'orderdetail_id' => $id, 'T_BacteriaID' => '0', 'T_BacteriaName' => '0', 'details' => array(), 'doctor_id' => '0', 'doctor_name' => '0'); - } - //print_r($row); - - - - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 7 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $sql = " - SELECT '0' as id, 'Belum memilih bakteria' as name - UNION - SELECT T_BacteriaID as id, T_BacteriaName as name - FROM t_bacteria - WHERE - T_BacteriaIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $bacteries = $this->db_smartone->query($sql)->result_array(); - $rst = array('doctors' => $doctors, 'bacteries' => $bacteries, 'results' => $row); - $this->sys_ok(["records" => $rst]); - } - function getantibiotics() - { - $prm = $this->sys_input; - $id = $prm["id"]; - $sql = " SELECT '' as xno, - 0 as xid, - '' as hasil_biakan, - '' as sample_name, - 0 as value, - 'Y' as chx_r, - 'N' as chx_i, - 'N' as chx_s, - 'R' as note, - t_antibiotic.* - FROM t_antibiotic - WHERE - T_AntibioticT_BacteriaID = {$prm['id']} AND T_AntibioticIsActive= 'Y' - ORDER BY T_AntibioticName ASC"; - //echo $sql; - $rows = $this->db_smartone->query($sql)->result_array(); - if (rows) { - foreach ($rows as $k => $v) { - $rows[$k]['xno'] = $k + 1; - } - } - - $this->sys_ok(["records" => $rows]); - } - function getlcprepresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - $sql = " SELECT Other_LcprepDetailsID as xid, - Other_LcprepID as header_id, - Other_LcprepT_orderDetailID as orderdetail_id, - Other_LcprepDetailsCode as code, - Other_LcprepDetailsLabel as label, - Other_LcprepDetailsResult as result, - IFNULL(Other_LcprepM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_LcprepM_DoctorID) OR Other_LcprepM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_lcprep - JOIN other_lcprepdetails ON Other_LcprepDetailsOther_LcprepID = Other_LcprepID AND Other_LcprepDetailsIsActive = 'Y' - LEFT JOIN m_doctor ON Other_LcprepM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_LcprepT_orderDetailID = {$id} AND Other_LcprepIsActive = 'Y' - GROUP BY Other_LcprepDetailsOther_LcprepID, Other_LcprepDetailsCode - ORDER BY Other_LcprepDetailsCode ASC"; - //echo $sql; - $rows = $this->db_smartone->query($sql)->result_array(); - if (!$rows) { - $rows = array( - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'A', - 'label' => 'DESKRIPSI', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ), - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'B', - 'label' => 'KESIMPULAN', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ) - ); - } - - $header_id = $rows[0]['header_id']; - $sql = "SELECT IFNULL(Other_LcprepAdekuasiID,0) as xid, - Lcprep_AdekuasiID as id, - Lcprep_AdekuasiLabel as name, - IF(ISNULL(Other_LcprepAdekuasiID),'N',Other_LcprepAdekuasiChex) as chex - FROM lcprep_adekuasi - LEFT JOIN other_lcprepadekuasi ON Other_LcprepAdekuasiLcprep_AdekuasiID = Lcprep_AdekuasiID AND - Other_LcprepAdekuasiOther_LcprepID = {$header_id} AND - Other_LcprepAdekuasiIsActive = 'Y' - WHERE - Lcprep_AdekuasiIsActive = 'Y' - GROUP BY Lcprep_AdekuasiID - ORDER BY Lcprep_AdekuasiOrder ASC - "; - //echo $sql; - $adeakuasi = $this->db_smartone->query($sql)->result_array(); - foreach ($adeakuasi as $kc => $vc) { - $adeakuasi[$kc]['chex'] = $vc['chex'] == 'N' ? false : true; - } - - $sql = "SELECT IFNULL(Other_LcprepKategoriUmumID,0) as xid, - Lcprep_KategoriUmumID as id, - Lcprep_KategoriUmumLabel as name, - IF(ISNULL(Other_LcprepKategoriUmumID),'N',Other_LcprepKategoriUmumChex) as chex - FROM lcprep_kategoriumum - LEFT JOIN other_lcprepkategoriumum ON Other_LcprepKategoriUmumLcprep_KategoriUmumID = Lcprep_KategoriUmumID AND - Other_LcprepKategoriUmumOther_LcprepID = {$header_id} AND - Other_LcprepKategoriUmumIsActive = 'Y' - WHERE - Lcprep_KategoriUmumIsActive = 'Y' - GROUP BY Lcprep_KategoriUmumID - "; - //echo $sql; - $kategoriumum = $this->db_smartone->query($sql)->result_array(); - foreach ($kategoriumum as $kc => $vc) { - $kategoriumum[$kc]['chex'] = $vc['chex'] == 'N' ? false : true; - } - - $sql = " - SELECT Lcprep_InterpretasiGroupID as group_id, - Lcprep_InterpretasiGroupName as group_name, - '' as subgroups - FROM lcprep_interpretasigroup - WHERE - Lcprep_InterpretasiGroupIsActive = 'Y' - "; - //echo $sql; - $interpretasi = $this->db_smartone->query($sql)->result_array(); - foreach ($interpretasi as $k => $v) { - $subgroups = array(); - $sql = "SELECT Lcprep_InterpretasiSubgroupID as subgroup_id, - Lcprep_InterpretasiSubgroupName as subgroup_name, - '' as childs - FROM lcprep_interpretasisubgroup - WHERE - Lcprep_InterpretasiSubgroupLcprep_InterpretasiGroupID = {$v['group_id']} AND Lcprep_InterpretasiSubgroupIsActive = 'Y'"; - //echo $sql; - $subgroups = $this->db_smartone->query($sql)->result_array(); - if (count($subgroups) > 0) { - foreach ($subgroups as $ki => $vi) { - $childs = array(); - $sql = "SELECT IFNULL(Other_LcprepInterpretasiID,0) as xid, - IFNULL(Other_LcprepInterpretasiChex,'N') as chex, - IFNULL(Other_LcprepInterpretasiValue,'') as value, - Lcprep_InterpretasiID as id, - Lcprep_InterpretasiLcprep_InterpretasiSubgroupID as subgroup_id, - Lcprep_InterpretasiCode as code, - Lcprep_InterpretasiName as name, - Lcprep_InterpretasiParentID as parent_id, - Lcprep_InterpretasiIsParent as is_parent, - Lcprep_InterpretasiHasResult as has_result, - Lcprep_InterpretasiTypeResult as type_result - FROM lcprep_interpretasi - LEFT JOIN other_lcprepinterpretasi ON Other_LcprepInterpretasiOther_LcprepID = {$header_id} AND - Other_LcprepInterpretasiLcprep_InterpretasiID = Lcprep_InterpretasiID AND - Other_LcprepInterpretasiIsActive = 'Y' - WHERE - Lcprep_InterpretasiLcprep_InterpretasiSubgroupID = {$vi['subgroup_id']} AND Lcprep_InterpretasiIsActive = 'Y' - GROUP BY Lcprep_InterpretasiID Order BY Lcprep_InterpretasiCode ASC"; - $childs = $this->db_smartone->query($sql)->result_array(); - if ($childs) { - foreach ($childs as $kc => $vc) { - $childs[$kc]['chex'] = $vc['chex'] == 'N' ? false : true; - } - } - $subgroups[$ki]['childs'] = $childs; - } - } - - $interpretasi[$k]['subgroups'] = $subgroups; - } - - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $rst = array('doctors' => $doctors, 'results' => $rows, 'adekuasi' => $adeakuasi, 'kategoriumum' => $kategoriumum, 'interpretasi' => $interpretasi); - $this->sys_ok(["records" => $rst]); - } - - function getpapsmearresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT Other_PapSmearDetailsID as xid, - Other_PapSmearID as header_id, - Other_PapSmearT_OrderDetailID as orderdetail_id, - Other_PapSmearDetailsCode as code, - Other_PapSmearDetailsLabel as label, - Other_PapSmearDetailsResult as result, - IFNULL(Other_PapSmearM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_PapSmearM_DoctorID) OR Other_PapSmearM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name - FROM other_papsmear - JOIN other_papsmeardetails ON Other_PapSmearDetailsOther_PapSmearID = Other_PapSmearID AND Other_PapSmearDetailsIsActive = 'Y' - LEFT JOIN m_doctor ON Other_PapSmearM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - Other_PapSmearT_OrderDetailID = {$id} AND Other_PapSmearIsActive = 'Y' - GROUP BY Other_PapSmearDetailsID - ORDER BY Other_PapSmearDetailsCode ASC"; - //echo $sql; - $rows = $this->db_smartone->query($sql)->result_array(); - if (!$rows) { - $rows = array( - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'A', - 'label' => 'Makroskopik', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ), - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'B', - 'label' => 'Mikroskopik', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ), - array( - 'xid' => '0', - 'header_id' => '0', - 'orderdetail_id' => $id, - 'code' => 'C', - 'label' => 'Kesimpulan', - 'result' => '', - 'doctor_id' => '0', - 'doctor_name' => '' - ) - ); - } - - $header_id = $rows[0]['header_id']; - $sql = "SELECT Other_PapSmearMaturasiID as xid, - Other_PapSmearMaturasiValue as value - FROM other_papsmearmaturasi - WHERE - Other_PapSmearMaturasiOther_PapSmearID = {$header_id} AND - Other_PapSmearMaturasiIsActive = 'Y' - "; - //echo $sql; - $dt_maturasi = $this->db_smartone->query($sql)->row_array(); - if (!$dt_maturasi) { - $maturasi = array('xid' => '0', 'value' => array('', '', '')); - } else { - $value = explode('/', $dt_maturasi['value']); - $maturasi = array('xid' => $dt_maturasi['xid'], 'value' => $value); - } - - $sql = "SELECT IFNULL(Other_PapSmearBahanID,0) as xid, - M_PapSmearBahanID as bahan_id, - M_PapSmearBahanName as name, - IF(ISNULL(Other_PapSmearBahanID),'N','Y') as selected - FROM m_papsmearbahan - LEFT JOIN other_papsmearbahan ON Other_PapSmearBahanM_PapSmearBahanID = M_PapSmearBahanID AND - Other_PapSmearBahanOther_PapSmearID = {$header_id} AND - Other_PapSmearBahanIsActive = 'Y' - WHERE - M_PapSmearBahanIsActive = 'Y' - ORDER BY M_PapSmearBahanID ASC - "; - //echo $sql; - $bahans = $this->db_smartone->query($sql)->result_array(); - - $sql = "SELECT IFNULL(Other_PapsmearCategoryID,0) as xid, - M_PapSmearCategoryID as category_id, - M_PapSmearCategoryName as name, - IF(ISNULL(Other_PapsmearCategoryID),'N','Y') as selected - FROM m_papsmearcategory - LEFT JOIN other_papsmearcategory ON Other_PapsmearCategoryM_PapSmearCategoryID = M_PapSmearCategoryID AND - Other_PapsmearCategoryOther_PapSmearID = {$header_id} AND - Other_PapsmearCategoryIsActive = 'Y' - WHERE - M_PapSmearCategoryIsActive = 'Y' - ORDER BY M_PapSmearCategoryID ASC - "; - //echo $sql; - $categories = $this->db_smartone->query($sql)->result_array(); - - $sql = "SELECT IFNULL(Other_PapSmearCheckID,0) as xid, - M_PapSmearCheckID as check_id, - M_PapSmearCheckLabel as name, - IF(ISNULL(Other_PapSmearCheckID),'N','Y') as selected, - Other_PapSmearCheckNote as note - FROM m_papsmearcheck - LEFT JOIN other_papsmearcheck ON Other_PapSmearCheckM_PapSmearCheckID = M_PapSmearCheckID AND - Other_PapSmearCheckOther_PapSmearID = {$header_id} AND - Other_PapSmearCheckIsActive = 'Y' - WHERE - M_PapSmearCheckIsActive = 'Y' - ORDER BY M_PapSmearCheckCode ASC - "; - $checks = $this->db_smartone->query($sql)->result_array(); - - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 9 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $rst = array('doctors' => $doctors, 'checks' => $checks, 'bahans' => $bahans, 'categories' => $categories, 'maturasi' => $maturasi, 'results' => $rows); - $this->sys_ok(["records" => $rst]); - } - - function saveresult_lcprep() - { - $prm = $this->sys_input; - $detail_id = $prm['detail_id']; - $doctor_id = $prm['doctor']; - $adekuasi = $prm['adekuasi']; - $kategoriumum = $prm['kategoriumum']; - $interpretasi = $prm['interpretasi']; - $results = $prm['results']; - - $userid = $this->sys_user['M_UserID']; - - $header_id = 0; - $sql = "SELECT * FROM other_lcprep WHERE Other_LcprepT_orderDetailID = {$detail_id} AND Other_LcprepIsActive = 'Y'"; - $dt_header = $this->db_smartone->query($sql)->row_array(); - if ($dt_header) { - $header_id = $dt_header['Other_LcprepID']; - } - if ($header_id == 0) { - $sql = "INSERT INTO other_lcprep( - Other_LcprepT_orderDetailID, - Other_LcprepM_DoctorID, - Other_LcprepUserID, - Other_LcprepCreated - ) - VALUES( - {$detail_id}, - {$doctor_id}, - {$userid}, - NOW() - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } else { - $sql = "UPDATE other_lcprep SET Other_LcprepM_DoctorID = {$doctor_id}, Other_LcprepUserID = {$userid} WHERE Other_LcprepID = {$header_id}"; - $this->db_smartone->query($sql); - } - - if ($adekuasi) { - foreach ($adekuasi as $k => $v) { - $selected = $v['chex'] ? 'Y' : 'N'; - if (intval($v['xid'] == 0)) { - $sql = "UPDATE other_lcprepadekuasi SET Other_LcprepAdekuasiIsActive = 'N' - WHERE - Other_LcprepAdekuasiOther_LcprepID = {$header_id} AND - Other_LcprepAdekuasiIsActive = 'Y' AND - Other_LcprepAdekuasiLcprep_AdekuasiID = {$v['id']}"; - $this->db_smartone->query($sql); - $sql = "INSERT INTO other_lcprepadekuasi ( - Other_LcprepAdekuasiOther_LcprepID, - Other_LcprepAdekuasiLcprep_AdekuasiID, - Other_LcprepAdekuasiChex, - Other_LcprepAdekuasiUserID, - Other_LcprepAdekuasiCreated - ) - VALUES( - {$header_id}, - {$v['id']}, - '{$selected}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - //echo $sql; - } - if (intval($v['xid'] != 0)) { - - $sql = "UPDATE other_lcprepadekuasi SET - Other_LcprepAdekuasiChex = '{$selected}', - Other_LcprepAdekuasiUserID = {$userid} - WHERE - Other_LcprepAdekuasiID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - - //echo $sql; - } - } - - if ($kategoriumum) { - foreach ($kategoriumum as $k => $v) { - $selected = $v['chex'] ? 'Y' : 'N'; - if (intval($v['xid'] == 0)) { - $sql = "UPDATE other_lcprepkategoriumum SET Other_LcprepKategoriUmumIsActive = 'N' - WHERE - Other_LcprepKategoriUmumOther_LcprepID = {$header_id} AND - Other_LcprepKategoriUmumLcprep_KategoriUmumID = {$v['id']} AND - Other_LcprepKategoriUmumIsActive = 'Y' - "; - $this->db_smartone->query($sql); - $sql = "INSERT INTO other_lcprepkategoriumum ( - Other_LcprepKategoriUmumOther_LcprepID, - Other_LcprepKategoriUmumLcprep_KategoriUmumID, - Other_LcprepKategoriUmumChex, - Other_LcprepKategoriUmumUserID, - Other_LcprepKategoriUmumCreated - ) - VALUES( - {$header_id}, - {$v['id']}, - '{$selected}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if (intval($v['xid'] != 0)) { - $sql = "UPDATE other_lcprepkategoriumum SET - Other_LcprepKategoriUmumChex = '{$selected}', - Other_LcprepKategoriUmumUserID = {$userid} - WHERE - Other_LcprepKategoriUmumID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - - //echo $sql; - } - } - - if ($results) { - foreach ($results as $k => $v) { - if (intval($v['xid'] == 0)) { - $sql = "UPDATE other_lcprepdetails SET Other_LcprepDetailsIsActive = 'N' - WHERE - Other_LcprepDetailsOther_LcprepID = {$header_id} AND - Other_LcprepDetailsCode = '{$v['code']}' AND - Other_LcprepDetailsIsActive = 'Y'"; - $this->db_smartone->query($sql); - $sql = "INSERT INTO other_lcprepdetails ( - Other_LcprepDetailsOther_LcprepID, - Other_LcprepDetailsCode, - Other_LcprepDetailsLabel, - Other_LcprepDetailsResult, - Other_LcprepDetailsUserID, - Other_LcprepDetailsCreated - ) - VALUES( - {$header_id}, - '{$v['code']}', - '{$v['label']}', - '{$v['result']}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if (intval($v['xid'] != 0)) { - $sql = "UPDATE other_lcprepdetails SET - Other_LcprepDetailsCode = '{$v['code']}', - Other_LcprepDetailsLabel = '{$v['label']}', - Other_LcprepDetailsResult = '{$v['result']}', - Other_LcprepDetailsUserID = {$userid} - WHERE - Other_LcprepDetailsID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - //echo $sql; - } - } - - if ($interpretasi) { - foreach ($interpretasi as $k => $v) { - if (count($v['subgroups']) > 0) { - foreach ($v['subgroups'] as $ik => $iv) { - if (count($iv['childs']) > 0) { - foreach ($iv['childs'] as $iik => $iiv) { - if (intval($iiv['xid'] == 0)) { - $chex = $iiv['chex'] ? 'Y' : 'N'; - $sql = "UPDATE other_lcprepinterpretasi SET Other_LcprepInterpretasiIsActive = 'N' - WHERE - Other_LcprepInterpretasiOther_LcprepID = {$header_id} AND - Other_LcprepInterpretasiLcprep_InterpretasiID = '{$iiv['id']}' AND - Other_LcprepInterpretasiIsActive = 'Y'"; - $this->db_smartone->query($sql); - $sql = "INSERT INTO other_lcprepinterpretasi ( - Other_LcprepInterpretasiOther_LcprepID, - Other_LcprepInterpretasiLcprep_InterpretasiID, - Other_LcprepInterpretasiChex, - Other_LcprepInterpretasiValue, - Other_LcprepInterpretasiUserID, - Other_LcprepInterpretasiCreated - ) - VALUES( - {$header_id}, - '{$iiv['id']}', - '{$chex}', - '{$iiv['value']}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - - if (intval($iiv['xid'] != 0)) { - $chex = $iiv['chex'] ? 'Y' : 'N'; - $sql = "UPDATE other_lcprepinterpretasi SET - Other_LcprepInterpretasiChex = '{$chex}', - Other_LcprepInterpretasiValue = '{$iiv['value']}', - Other_LcprepInterpretasiUserID = {$userid} - WHERE - Other_LcprepInterpretasiID = {$iiv['xid']}"; - $this->db_smartone->query($sql); - //echo $sql; - - } - } - } - } - } - //echo $sql; - } - } - - - $result = array("total" => 1, "records" => array(), "sql" => ''); - $this->sys_ok($result); - exit; - } - - function saveresult_papsmear() - { - $prm = $this->sys_input; - $detail_id = $prm['detail_id']; - $doctor_id = $prm['doctor']; - $checks = $prm['checks']; - $maturasi = $prm['maturasi']; - $bahans = $prm['bahans']; - $categories = $prm['categories']; - $results = $prm['results']; - - $userid = $this->sys_user['M_UserID']; - - $header_id = 0; - $sql = "SELECT * FROM other_papsmear WHERE Other_PapSmearT_OrderDetailID = {$detail_id} AND Other_PapSmearIsActive = 'Y'"; - $dt_header = $this->db_smartone->query($sql)->row_array(); - if ($dt_header) { - $header_id = $dt_header['Other_PapSmearID']; - } - if ($header_id == 0) { - $sql = "INSERT INTO other_papsmear( - Other_PapSmearT_OrderDetailID, - Other_PapSmearM_DoctorID, - Other_PapSmearUserID, - Other_PapSmearCreated - ) - VALUES( - {$detail_id}, - {$doctor_id}, - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } else { - $sql = "UPDATE other_papsmear SET Other_PapSmearM_DoctorID = {$doctor_id}, Other_PapSmearUserID = {$userid} WHERE Other_PapSmearID = {$header_id}"; - $this->db_smartone->query($sql); - } - - if ($checks) { - foreach ($checks as $k => $v) { - if (intval($v['xid']) == 0 && $v['selected'] === 'Y') { - $sql = "INSERT INTO other_papsmearcheck ( - Other_PapSmearCheckOther_PapSmearID, - Other_PapSmearCheckM_PapSmearCheckID, - Other_PapSmearCheckNote, - Other_PapSmearCheckUserID, - Other_PapSmearCheckCreated - ) - VALUES( - {$header_id}, - {$v['check_id']}, - '{$v['note']}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if (intval($v['xid']) != 0 && $v['selected'] === 'N') { - $sql = "UPDATE other_papsmearcheck SET - Other_PapSmearCheckIsActive = 'N', - Other_PapSmearCheckUserID = {$userid} - WHERE - Other_PapSmearCheckID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - if (intval($v['xid']) != 0 && $v['selected'] === 'Y') { - $sql = "UPDATE other_papsmearcheck SET - Other_PapSmearCheckNote = '{$v['note']}', - Other_PapSmearCheckUserID = {$userid} - WHERE - Other_PapSmearCheckID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - //echo $sql; - } - } - - if ($maturasi) { - if (intval($maturasi['xid']) == 0) { - $value = join("/", $maturasi['value']); - $sql = "INSERT INTO other_papsmearmaturasi ( - Other_PapSmearMaturasiOther_PapSmearID, - Other_PapSmearMaturasiValue, - Other_PapSmearMaturasiUserID, - Other_PapSmearMaturasiCreated - ) - VALUE( - {$header_id}, - '{$value}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - //echo $sql; - } - if (intval($maturasi['xid']) != 0) { - $value = join("/", $maturasi['value']); - $sql = "UPDATE other_papsmearmaturasi SET - Other_PapSmearMaturasiValue = '{$value}', - Other_PapSmearMaturasiUserID = {$userid} - WHERE - Other_PapSmearMaturasiID = {$maturasi['xid']}"; - // echo $sql; - $this->db_smartone->query($sql); - } - } - - if ($bahans) { - foreach ($bahans as $k => $v) { - if (intval($v['xid']) == 0 && $v['selected'] === 'Y') { - $sql = "INSERT INTO other_papsmearbahan ( - Other_PapSmearBahanOther_PapSmearID, - Other_PapSmearBahanM_PapSmearBahanID, - Other_PapSmearBahanUserID, - Other_PapSmearBahanCreated - ) - VALUES( - {$header_id}, - {$v['bahan_id']}, - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if (intval($v['xid']) != 0 && $v['selected'] === 'N') { - $sql = "UPDATE other_papsmearbahan SET - Other_PapSmearBahanIsActive = 'N', - Other_PapsmearCategoryUserID = {$userid} - WHERE - Other_PapSmearBahanID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - if (intval($v['xid']) != 0 && $v['selected'] === 'Y') { - $sql = "UPDATE other_papsmearbahan SET - Other_PapSmearBahanIsActive = 'Y', - Other_PapsmearCategoryUserID = {$userid} - WHERE - Other_PapSmearBahanID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - //echo $sql; - } - } - - if ($categories) { - foreach ($categories as $k => $v) { - if (intval($v['xid']) == 0 && $v['selected'] === 'Y') { - $sql = "INSERT INTO other_papsmearcategory ( - Other_PapsmearCategoryOther_PapSmearID, - Other_PapsmearCategoryM_PapSmearCategoryID, - Other_PapsmearCategoryUserID, - Other_PapsmearCategoryCreated - ) - VALUES( - {$header_id}, - {$v['category_id']}, - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if (intval($v['xid']) != 0 && $v['selected'] === 'N') { - $sql = "UPDATE other_papsmearcategory SET - Other_PapsmearCategoryIsActive = 'N', - Other_PapsmearCategoryUserID = {$userid} - WHERE - Other_PapsmearCategoryID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - //echo $sql; - if (intval($v['xid']) != 0 && $v['selected'] === 'Y') { - $sql = "UPDATE other_papsmearcategory SET - Other_PapsmearCategoryIsActive = 'Y', - Other_PapsmearCategoryUserID = {$userid} - WHERE - Other_PapsmearCategoryID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - } - } - - if ($results) { - foreach ($results as $k => $v) { - if (intval($v['xid']) == 0) { - $sql = "INSERT INTO other_papsmeardetails ( - Other_PapSmearDetailsOther_PapSmearID, - Other_PapSmearDetailsCode, - Other_PapSmearDetailsLabel, - Other_PapSmearDetailsResult, - Other_PapSmearDetailsUserID, - Other_PapSmearDetailsCreated - ) - VALUES( - {$header_id}, - '{$v['code']}', - '{$v['label']}', - '{$v['result']}', - {$userid}, - NOW() - )"; - $this->db_smartone->query($sql); - } - if (intval($v['xid']) != 0) { - $sql = "UPDATE other_papsmeardetails SET - Other_PapSmearDetailsCode = '{$v['code']}', - Other_PapSmearDetailsLabel = '{$v['label']}', - Other_PapSmearDetailsResult = '{$v['result']}', - Other_PapSmearDetailsUserID = {$userid} - WHERE - Other_PapSmearDetailsID = {$v['xid']}"; - $this->db_smartone->query($sql); - } - //echo $sql; - } - } - - $result = array("total" => 1, "records" => array(), "sql" => ''); - $this->sys_ok($result); - exit; - } - - function saveresult_fna() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = $inp['doctor']; - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - if ($prm[0]['xid'] == '0') { - $sql = "INSERT INTO other_fna( - Other_FNAM_DoctorID, - Other_FNAT_OrderDetailID, - Other_FNAUserID, - Other_FNACreated - ) - VALUES( - {$doctor_id}, - {$prm[0]['orderdetail_id']}, - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } else { - $sql = "SELECT * FROM other_fna WHERE Other_FNAT_OrderDetailID = {$prm[0]['orderdetail_id']} AND Other_FNAIsActive = 'Y'"; - $data_header = $this->db_smartone->query($sql)->row_array(); - $header_id = $data_header['Other_FNAID']; - $sql = "UPDATE other_fna SET - Other_FNAM_DoctorID = {$doctor_id}, - Other_FNAUserID = {$userid} - WHERE - Other_FNAID = {$header_id}"; - $this->db_smartone->query($sql); - } - foreach ($prm as $k => $v) { - if ($v['xid'] == '0') { - $results = str_replace("'", "\\'", $v['result']); - $sql = "INSERT INTO other_fnadetails( - Other_FNADetailsOther_FNAID , - Other_FNADetailsCode, - Other_FNADetailsLabel, - Other_FNADetailsResult, - Other_FNADetailsCreated, - Other_FNADetailsUserID - ) - VALUES( - {$header_id}, - '{$v['code']}', - '{$v['label']}', - '{$results}', - NOW(), - {$userid} - )"; - $query = $this->db_smartone->query($sql); - } else { - $results = str_replace("'", "\\'", $v['result']); - $sql = "UPDATE other_fnadetails SET - Other_FNADetailsResult = '{$results}', - Other_FNADetailsUserID = {$userid} - WHERE - Other_FNADetailsID = {$v['xid']}"; - $query = $this->db_smartone->query($sql); - } - } - - $result = array("total" => 1, "records" => array(), "sql" => ''); - $this->sys_ok($result); - exit; - } - - function saveresult_cytologi() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = $inp['doctor']; - - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - if ($prm[0]['xid'] == '0') { - $sql = "INSERT INTO other_cytologi( - Other_CytologiT_OrderDetailID, - Other_CytologiM_DoctorID, - Other_CytologiUserID, - Other_CytologiCreated - ) - VALUES( - {$prm[0]['orderdetail_id']}, - {$doctor_id}, - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } else { - $sql = "SELECT * FROM other_cytologi WHERE Other_CytologiT_OrderDetailID = {$prm[0]['orderdetail_id']} AND Other_CytologiIsActive = 'Y'"; - $data_header = $this->db_smartone->query($sql)->row_array(); - $header_id = $data_header['Other_CytologiID']; - $sql = "UPDATE other_cytologi SET - Other_CytologiM_DoctorID = {$doctor_id}, - Other_CytologiUserID = {$userid} - WHERE - Other_CytologiID = {$header_id}"; - $this->db_smartone->query($sql); - } - foreach ($prm as $k => $v) { - if ($v['xid'] == '0') { - $results = str_replace("'", "\\'", $v['result']); - $sql = "INSERT INTO other_cytologidetails( - Other_CytologiDetailsOther_CytologiID , - Other_CytologiDetailsCode, - Other_CytologiDetailsLabel, - Other_CytologiDetailsResult, - Other_CytologiDetailsCreated, - Other_CytologiDetailsUserID - ) - VALUES( - {$header_id}, - '{$v['code']}', - '{$v['label']}', - '{$results}', - NOW(), - {$userid} - )"; - $query = $this->db_smartone->query($sql); - } else { - $results = str_replace("'", "\\'", $v['result']); - $sql = "UPDATE other_cytologidetails SET - Other_CytologiDetailsResult = '{$results}', - Other_CytologiDetailsUserID = {$userid} - WHERE - Other_CytologiDetailsID = {$v['xid']}"; - $query = $this->db_smartone->query($sql); - } - } - - $result = array("total" => 1, "records" => array(), "sql" => ''); - $this->sys_ok($result); - exit; - } - - function saveresult_mikro() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = $inp['doctor']; - $backteria_id = $inp['bacteria']; - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - - if ($inp['result_value'] != 'Negatif' && $inp['result_value'] != 'Positif') { - $prm['result_value'] = $prm['result_other']; - } else { - $prm['result_value'] = $inp['result_value']; - } - - if ($prm['xid'] == '0') { - $sql = "INSERT INTO other_mikro( - Other_MikroM_DoctorID, - Other_MikroResult, - Other_MikroT_BacteriaID, - Other_MikroT_OrderDetailID, - Other_MikroHasilBiakan, - Other_MikroSampleTypeName, - Other_MikroUserID, - Other_MikroCreated - ) - VALUES( - {$doctor_id}, - '{$prm['result_value']}', - {$backteria_id}, - {$prm['orderdetail_id']}, - '{$prm['hasil_biakan']}', - '{$prm['sample_name']}', - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } else { - $sql = "SELECT * FROM other_mikro WHERE Other_MikroT_OrderDetailID = {$prm['orderdetail_id']} AND Other_MikroIsActive = 'Y'"; - $data_header = $this->db_smartone->query($sql)->row_array(); - $header_id = $data_header['Other_MikroID']; - $sql = "UPDATE other_mikro SET - Other_MikroResult = '{$prm['result_value']}', - Other_MikroM_DoctorID = {$doctor_id}, - Other_MikroT_BacteriaID = {$backteria_id}, - Other_MikroHasilBiakan = '{$prm['hasil_biakan']}', - Other_MikroSampleTypeName = '{$prm['sample_name']}', - Other_MikroUserID = {$userid} - WHERE - Other_MikroID = {$header_id}"; - //echo $sql; - $this->db_smartone->query($sql); - } - - - - $sql = "UPDATE other_mikrodetails SET Other_MikroDetailsIsActive = 'N', Other_MikroDetailsUserID = 0 WHERE Other_MikroDetailsOther_MikroID = {$header_id}"; - $this->db_smartone->query($sql); - - $results = $prm['details']; - if ($inp['result_value'] == 'Positif') { - foreach ($results as $k => $v) { - if ($v['xid'] == '0') { - $sql = "INSERT INTO other_mikrodetails( - Other_MikroDetailsOther_MikroID , - Other_MikroDetailsT_AntibioticID, - Other_MikroDetailsValue, - Other_MikroDetailsNote, - Other_MikroDetailsCreated, - Other_MikroDetailsUserID - ) - VALUES( - {$header_id}, - '{$v['T_AntibioticID']}', - '{$v['value']}', - '{$v['note']}', - NOW(), - {$userid} - )"; - $query = $this->db_smartone->query($sql); - } else { - $sql = "UPDATE other_mikrodetails SET - Other_MikroDetailsT_AntibioticID = '{$v['T_AntibioticID']}', - Other_MikroDetailsValue = '{$v['value']}', - Other_MikroDetailsNote = '{$v['note']}', - Other_MikroDetailsIsActive = 'Y', - Other_MikroDetailsUserID = {$userid} - WHERE - Other_MikroDetailsID = {$v['xid']}"; - //echo $sql; - $query = $this->db_smartone->query($sql); - } - } - } - - - $result = array("total" => 1, "records" => array(), "sql" => ''); - $this->sys_ok($result); - exit; - } - - - function get_doctors_preparasi_sperma() - { - $prm = $this->sys_input; - // $id = $prm["id"]; - - $sql = " SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 10 AND - M_DoctorSOIsActive = 'Y' - ORDER BY M_DoctorName ASC"; - //echo $sql; - $query = $this->db_smartone->query($sql); - $rows = $query->result_array(); - $sql = " - SELECT '0' as id, 'Belum memilih metode' as name - UNION - SELECT M_MethodeSpermaID as id, M_MethodeSpermaName as name - FROM m_methodesperma - WHERE - M_MethodeSpermaIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $methodes = $this->db_smartone->query($sql)->result_array(); - - - $this->sys_ok(["records" => $rows, "methodes" => $methodes]); - } - - - function getpreparasispermaresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT other_preparasisperma.*, - Other_PreparasiSpermaID as xid, - Other_PreparasiSpermaT_OrderDetailID as orderdetail_id, - IFNULL(Other_PreparasiSpermaM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_PreparasiSpermaM_DoctorID) OR Other_PreparasiSpermaM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name, - IFNULL(M_MethodeSpermaID,0) as methode_id, - IFNULL(M_MethodeSpermaName,'') as methode_name - FROM other_preparasisperma - LEFT JOIN m_doctor ON Other_PreparasiSpermaM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - LEFT JOIN m_methodesperma ON Other_PreparasiSpermaM_MethodeSpermaID = M_MethodeSpermaID AND - M_MethodeSpermaIsActive = 'Y' - WHERE - Other_PreparasiSpermaT_OrderDetailID = {$id} AND Other_PreparasiSpermaIsActive = 'Y' - GROUP BY Other_PreparasiSpermaID"; - $query = $this->db_smartone->query($sql); - - if ($query) { - $rows = $query->row_array(); - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND - M_DoctorIsActive = 'Y' - WHERE - M_DoctorSONat_SubGroupID = 10 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - $sql = " - SELECT '0' as id, 'Belum memilih metode' as name - UNION - SELECT M_MethodeSpermaID as id, M_MethodeSpermaName as name - FROM m_methodesperma - WHERE - M_MethodeSpermaIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $methodes = $this->db_smartone->query($sql)->result_array(); - $images = array(); - $sql = "SELECT Other_PreparasiSpermaImgID as xid, - Other_PreparasiSpermaImgType as type, - CONCAT('/one-media/one-image-nonlab/',Other_PreparasiSpermaImgNewName) as image_url - FROM t_orderdetail - JOIN other_preparasisperma_img ON Other_PreparasiSpermaImgT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND - Other_PreparasiSpermaImgIsActive = 'Y' - WHERE - T_OrderDetailID = {$id} AND - T_OrderDetailIsActive = 'Y' - GROUP BY Other_PreparasiSpermaImgID"; - //echo $sql; - $images = $this->db_smartone->query($sql)->result_array(); - - $rst = array('doctors' => $doctors, 'methodes' => $methodes, 'results' => $rows, 'images' => $images); - $this->sys_ok(["records" => $rst]); - } else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - - function uploadimage_preparasi_sperma() - { - if (! $this->isLogin) { - $this->sys_error("Invalid Token"); - exit; - } - - $userid = $this->sys_user["M_UserID"]; - $data = []; - //print_r($_SERVER); - - $prm = $this->sys_input; - $orderid = $this->input->post('orderid'); - $type = $this->input->post('type'); - $labnumber = $this->input->post('labnumber'); - $sql = "UPDATE other_preparasisperma_img SET - Other_PreparasiSpermaImgIsActive = 'N', - Other_PreparasiSpermaImgUserID = {$userid} - WHERE - Other_PreparasiSpermaImgT_OrderHeaderID = {$orderid} AND - Other_PreparasiSpermaImgType = '{$type}'"; - //echo $sql; - $this->db_onedev->query($sql); - //$config['upload_path'] = 'assets/'; - - $path = '/home/one/project/one/one-media/one-image-nonlab/'; - //echo $path; - $config['upload_path'] = $path; - $config['allowed_types'] = 'jpg|jpeg|png|gif'; - - $config['max_size'] = '10000'; - $count = count($_FILES['files']['name']); - //echo $count; - $this->load->library('upload', $config); - - $error = []; - for ($i = 0; $i < $count; $i++) { - - - if (!empty($_FILES['files']['name'][$i])) { - - - - $_FILES['file']['name'] = $_FILES['files']['name'][$i]; - - $_FILES['file']['type'] = $_FILES['files']['type'][$i]; - - $_FILES['file']['tmp_name'] = $_FILES['files']['tmp_name'][$i]; - - $_FILES['file']['error'] = $_FILES['files']['error'][$i]; - - $_FILES['file']['size'] = $_FILES['files']['size'][$i]; - - - - $namex = $orderid . '-' . $labnumber . '-' . $this->generateRandomString(5); - //echo $namex; - - $config['file_name'] = $namex; - $this->upload->initialize($config); - //echo $config['file_name'] ; - - - - - - if ($this->upload->do_upload('file')) { - - $uploadData = $this->upload->data(); - - $filename = $uploadData['file_name']; - //echo $filename; - - - $sql = "INSERT INTO other_preparasisperma_img ( - Other_PreparasiSpermaImgT_OrderHeaderID, - Other_PreparasiSpermaImgType, - Other_PreparasiSpermaImgOldName, - Other_PreparasiSpermaImgNewName, - Other_PreparasiSpermaImgCreated, - Other_PreparasiSpermaImgUserID - ) - VALUES( - {$orderid}, - '{$type}', - '{$_FILES['files']['name'][$i]}', - '{$filename}', - NOW(), - {$userid} - - )"; - //echo $sql; - $this->db_onedev->query($sql); - $xlast_id = $this->db_onedev->insert_id(); - $data['totalFiles'][] = array('xid' => $xlast_id, 'type' => $type, 'image_url' => '/one-media/one-image-nonlab/' . $filename); - } else { - $error = array('error' => $this->upload->display_errors()); - } - } - } - - $result = array("total" => count($data['totalFiles']), "records" => $data['totalFiles'], 'errors' => $error); - $this->sys_ok($result); - } - - - function saveresult_preparasi_sperma() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = $inp['doctor']; - $orderdetail_id = $inp['orderdetailid']; - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - if ($prm['xid'] == '0') { - $sql = "INSERT INTO other_preparasisperma( - Other_PreparasiSpermaM_DoctorID, - Other_PreparasiSpermaT_OrderDetailID, - Other_PreparasiSpermaPreMotilitasA, - Other_PreparasiSpermaPreMotilitasB, - Other_PreparasiSpermaPreMotilitasC, - Other_PreparasiSpermaPreKonsentrasi, - Other_PreparasiSpermaPreKontaminan, - Other_PreparasiSpermaPostMotilitasA, - Other_PreparasiSpermaPostMotilitasB, - Other_PreparasiSpermaPostMotilitasC, - Other_PreparasiSpermaPostKonsentrasi, - Other_PreparasiSpermaPostKontaminan, - Other_PreparasiSpermaPreVolume, - Other_PreparasiSpermaPostVolume, - Other_PreparasiSpermaM_MethodeSpermaID, - Other_PreparasiSpermaNote, - Other_PreparasiSpermaUserID, - Other_PreparasiSpermaCreated - ) - VALUES( - {$doctor_id}, - {$orderdetail_id}, - '{$prm['Other_PreparasiSpermaPreMotilitasA']}', - '{$prm['Other_PreparasiSpermaPreMotilitasB']}', - '{$prm['Other_PreparasiSpermaPreMotilitasC']}', - '{$prm['Other_PreparasiSpermaPreKonsentrasi']}', - '{$prm['Other_PreparasiSpermaPreKontaminan']}', - '{$prm['Other_PreparasiSpermaPostMotilitasA']}', - '{$prm['Other_PreparasiSpermaPostMotilitasB']}', - '{$prm['Other_PreparasiSpermaPostMotilitasC']}', - '{$prm['Other_PreparasiSpermaPostKonsentrasi']}', - '{$prm['Other_PreparasiSpermaPostKontaminan']}', - '{$prm['Other_PreparasiSpermaPreVolume']}', - '{$prm['Other_PreparasiSpermaPostVolume']}', - '{$prm['Other_PreparasiSpermaM_MethodeSpermaID']}', - '{$prm['Other_PreparasiSpermaNote']}', - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } else { - $sql = "SELECT * FROM other_preparasisperma WHERE Other_PreparasiSpermaT_OrderDetailID = {$orderdetail_id} AND Other_PreparasiSpermaIsActive = 'Y'"; - $data_header = $this->db_smartone->query($sql)->row_array(); - $header_id = $data_header['Other_PreparasiSpermaID']; - $sql = "UPDATE other_preparasisperma SET - Other_PreparasiSpermaM_DoctorID = {$doctor_id}, - Other_PreparasiSpermaPreMotilitasA = '{$prm['Other_PreparasiSpermaPreMotilitasA']}', - Other_PreparasiSpermaPreMotilitasB = '{$prm['Other_PreparasiSpermaPreMotilitasB']}', - Other_PreparasiSpermaPreMotilitasC = '{$prm['Other_PreparasiSpermaPreMotilitasC']}', - Other_PreparasiSpermaPreKonsentrasi = '{$prm['Other_PreparasiSpermaPreKonsentrasi']}', - Other_PreparasiSpermaPreKontaminan = '{$prm['Other_PreparasiSpermaPreKontaminan']}', - Other_PreparasiSpermaPostMotilitasA = '{$prm['Other_PreparasiSpermaPostMotilitasA']}', - Other_PreparasiSpermaPostMotilitasB = '{$prm['Other_PreparasiSpermaPostMotilitasB']}', - Other_PreparasiSpermaPostMotilitasC = '{$prm['Other_PreparasiSpermaPostMotilitasC']}', - Other_PreparasiSpermaPostKonsentrasi = '{$prm['Other_PreparasiSpermaPostKonsentrasi']}', - Other_PreparasiSpermaPostKontaminan = '{$prm['Other_PreparasiSpermaPostKontaminan']}', - Other_PreparasiSpermaPreVolume = '{$prm['Other_PreparasiSpermaPreVolume']}', - Other_PreparasiSpermaPostVolume = '{$prm['Other_PreparasiSpermaPostVolume']}', - Other_PreparasiSpermaM_MethodeSpermaID = '{$prm['Other_PreparasiSpermaM_MethodeSpermaID']}', - Other_PreparasiSpermaNote = '{$prm['Other_PreparasiSpermaNote']}', - Other_PreparasiSpermaUserID = {$userid} - WHERE - Other_PreparasiSpermaID = {$header_id}"; - $this->db_smartone->query($sql); - } - - - $result = array("total" => 1, "records" => array(), "sql" => ''); - $this->sys_ok($result); - exit; - } - - function getdnafragmentasiresult() - { - $prm = $this->sys_input; - $id = $prm["id"]; - - $sql = " SELECT other_dnafragmentasi.*, - Other_DnaFragmentasiID as xid, - Other_DnaFragmentasiT_OrderDetailID as orderdetail_id, - IFNULL(Other_DnaFragmentasiM_DoctorID,0) as doctor_id, - IF(ISNULL(Other_DnaFragmentasiM_DoctorID) OR Other_DnaFragmentasiM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name, - IFNULL(Other_DnaFragmentasiOther_DnaFragmentasiMethodeID,0) as methode_id, - IFNULL(Other_DnaFragmentasiMethodeName,'') as methode_name, - Other_DnaFragmentasiHaloLuas as halo_luas, - Other_DnaFragmentasiHaloSedang as halo_sedang, - Other_DnaFragmentasiHaloSempit as halo_sempit, - Other_DnaFragmentasiTanpaHalo as tanpa_halo, - Other_DnaFragmentasiDFI as dfi, - Other_DnaFragmentasiKesimpulan as kesimpulan, - Other_DnaFragmentasiCatatan as catatan - FROM other_dnafragmentasi - LEFT JOIN m_doctor ON Other_DnaFragmentasiM_DoctorID = M_DoctorID - LEFT JOIN other_dnafragmentasimethode ON Other_DnaFragmentasiOther_DnaFragmentasiMethodeID = Other_DnaFragmentasiMethodeID - WHERE - Other_DnaFragmentasiT_OrderDetailID = {$id} AND Other_DnaFragmentasiIsActive = 'Y' - GROUP BY Other_DnaFragmentasiID - LIMIT 1"; - //echo $sql; - $query = $this->db_smartone->query($sql); - - if ($query) { - $rows = $query->row_array(); - if (!$rows) { - $rows = array( - 'xid' => 0, - 'orderdetail_id' => $id, - 'doctor_id' => 0, - 'doctor_name' => '', - 'methode_id' => 0, - 'methode_name' => '', - 'halo_luas' => '', - 'halo_sedang' => '', - 'tanpa_halo' => '', - 'dfi' => '', - 'kesimpulan' => '', - 'catatan' => '' - ); - } - $sql = " - SELECT '0' as id, 'Belum memilih dokter' as name - UNION - SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name - FROM m_doctorso - JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID - WHERE - M_DoctorSONat_SubGroupID = 4 AND - M_DoctorSOIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $doctors = $this->db_smartone->query($sql)->result_array(); - - $sql = " - SELECT '0' as id, 'Belum memilih metode' as name - UNION - SELECT Other_DnaFragmentasiMethodeID as id, Other_DnaFragmentasiMethodeName as name - FROM other_dnafragmentasimethode - WHERE - Other_DnaFragmentasiMethodeIsActive = 'Y' - ORDER BY name ASC"; - //echo $sql; - $methodes = $this->db_smartone->query($sql)->result_array(); - - - $rst = array('doctors' => $doctors, 'methodes' => $methodes, 'results' => $rows); - $this->sys_ok(["records" => $rst]); - } else { - $this->sys_error_db("Rerun rows", $this->db_smartone); - exit; - } - } - - function saveresult_dnafragmentasi() - { - $inp = $this->sys_input; - $prm = $inp['results']; - $doctor_id = $inp['doctor']['id']; - $methode_id = $inp['methode']['id']; - $orderdetail_id = $inp['results']['orderdetail_id']; - $userid = $this->sys_user['M_UserID']; - $header_id = 0; - if (intval($prm['xid']) == 0) { - $sql = "INSERT INTO other_dnafragmentasi( - Other_DnaFragmentasiT_OrderDetailID, - Other_DnaFragmentasiM_DoctorID, - Other_DnaFragmentasiOther_DnaFragmentasiMethodeID, - Other_DnaFragmentasiHaloLuas, - Other_DnaFragmentasiHaloSedang, - Other_DnaFragmentasiHaloSempit, - Other_DnaFragmentasiTanpaHalo, - Other_DnaFragmentasiDFI, - Other_DnaFragmentasiKesimpulan, - Other_DnaFragmentasiCatatan, - Other_DnaFragmentasiUserID, - Other_DnaFragmentasiLastUpdated - ) - VALUES( - {$orderdetail_id}, - {$doctor_id}, - {$methode_id}, - '{$prm['halo_luas']}', - '{$prm['halo_sedang']}', - '{$prm['halo_sempit']}', - '{$prm['tanpa_halo']}', - '{$prm['dfi']}', - '{$prm['kesimpulan']}', - '{$prm['catatan']}', - {$userid}, - NOW() - - )"; - //echo $sql; - $this->db_smartone->query($sql); - $header_id = $this->db_smartone->insert_id(); - } else { - $sql = "UPDATE other_dnafragmentasi SET - Other_DnaFragmentasiT_OrderDetailID = {$orderdetail_id}, - Other_DnaFragmentasiM_DoctorID = {$doctor_id}, - Other_DnaFragmentasiOther_DnaFragmentasiMethodeID = '{$methode_id}', - Other_DnaFragmentasiHaloLuas = '{$prm['halo_luas']}', - Other_DnaFragmentasiHaloSedang = '{$prm['halo_sedang']}', - Other_DnaFragmentasiHaloSempit = '{$prm['halo_sempit']}', - Other_DnaFragmentasiTanpaHalo = '{$prm['tanpa_halo']}', - Other_DnaFragmentasiDFI = '{$prm['dfi']}', - Other_DnaFragmentasiKesimpulan = '{$prm['kesimpulan']}', - Other_DnaFragmentasiCatatan = '{$prm['catatan']}', - Other_DnaFragmentasiLastUpdated = NOW(), - Other_DnaFragmentasiUserID = {$userid} - WHERE - Other_DnaFragmentasiID = {$prm['xid']}"; - //echo $sql; - $this->db_smartone->query($sql); - } - - - $result = array("total" => 1, "records" => array(), "sql" => ''); - $this->sys_ok($result); - exit; - } -} +db_smartone = $this->load->database("onedev", true); + $this->load->helper(array('form', 'url')); + } + function getMethodeID($natTestID) + { + $sql = "select M_MethodePriorityNat_MethodeID MethodeID, Nat_MethodeName + from + m_methode_priority + join nat_methode on Nat_MethodeID = M_MethodePriorityNat_MethodeID + and Nat_MethodeIsActive = 'Y' + join m_instrumentmethode on M_InstrumentMethodeNat_MethodeID = Nat_MethodeID and M_InstrumentMethodeIsActive = 'Y' + join nat_instrument on M_InstrumentMethodeNat_InstrumentID = Nat_InstrumentID + and Nat_InstrumentIsActive ='Y' + where M_MethodePriorityIsActive = 'Y' + and M_MethodePriorityNat_TestID = $natTestID + and M_MethodePriorityM_DayOfWeekID = dayofweek(now()) + order by M_MethodePriorityNumber desc + limit 0,1 "; + $qry = $this->db->query($sql); + if ($qry) { + $rows = $qry->result_array(); + if (count($rows) > 0) return array($rows[0]["MethodeID"], $rows[0]["Nat_MethodeName"]); + } + //2nd + $sql = "select + M_InstrumentMethodeNat_MethodeID MethodeID, Nat_MethodeName + from m_instrumentmethode + join nat_methode on M_InstrumentMethodeNat_MethodeID = Nat_MethodeID + and Nat_MethodeIsActive = 'Y' + join nat_instrument on M_InstrumentMethodeNat_InstrumentID = Nat_InstrumentID + and Nat_InstrumentIsActive ='Y' + where M_InstrumentMethodeNat_TestID = $natTestID + and M_InstrumentMethodeIsActive = 'Y' + order by M_InstrumentMethodePriority desc + limit 0,1"; + $qry = $this->db->query($sql); + if ($qry) { + $rows = $qry->result_array(); + if (count($rows) > 0) return array($rows[0]["MethodeID"], $rows[0]["Nat_MethodeName"]); + } + // + $sql = "select Nat_NormalValueNat_MethodeID MethodeID, Nat_MethodeName + from + nat_normalvalue + join nat_methode on Nat_NormalValueNat_MethodeID = Nat_MethodeID + and Nat_MethodeIsActive = 'Y' + where Nat_NormalValueNat_TestID = $natTestID + and Nat_NormalValueIsActive = 'Y' + order by Nat_NormalValueID + limit 0,1"; + $qry = $this->db->query($sql); + if ($qry) { + $rows = $qry->result_array(); + if (count($rows) > 0) return array($rows[0]["MethodeID"], $rows[0]["Nat_MethodeName"]); + } + return array(0, ""); + } + function get_normal_value($methodeID, $natTestID, $sexID, $ageInDay) + { + $this->load->library('ibl_sampling_normal'); + return $this->ibl_sampling_normal->get_normal_value_id($methodeID, $natTestID, $sexID, $ageInDay); + } + return 0; + } + function fn_fix_normal($order_id) + { + $sql = "select + T_OrderDetailID, M_PatientM_SexID, fn_global_age_count_day(M_PatientDOB, date(T_OrderHeaderDate)) Dob , + T_TestNat_TestID + from t_orderheader + join m_patient on T_OrderHeaderID = $order_id and T_OrderHeaderM_PatientID = M_PatientID + join t_orderdetail on T_OrderDetailT_OrderHeaderID = T_OrderHeaderID + and T_OrderDetailIsACtive = 'Y' + and ( T_OrderDetailNat_NormalValueID is null or T_OrderDetailNat_NormalValueID = 0 ) + join t_test on T_OrderDetailT_TestID = T_TestID and T_TestIsResult = 'Y' "; + $qry = $this->db->query($sql); + if (! $qry) { + return; + } + $rows = $qry->result_array(); + if (count($rows) == 0) return; + $sql_u = "update t_orderdetail + join nat_normalvalue on T_OrderDetailID = ? and Nat_NormalValueID = ? + set + T_OrderDetailNat_NormalValueID = Nat_NormalValueID, + T_OrderDetailNormalValueNote = Nat_NormalValueNote, + T_OrderDetailNormalValueDescription = Nat_NormalValueDescription, + T_OrderDetailMinValue = Nat_NormalValueMinValue, + T_OrderDetailMaxValue = Nat_NormalValueMaxValue, + T_OrderDetailMinValueInclusive = Nat_NormalValueMinValueInclusive, + T_OrderDetailMaxValueInclusive = Nat_NormalValueMaxValueInclusive, + T_OrderDetailNat_MethodeID = ?, + T_OrderdetailNat_MethodeName =?"; + + foreach ($rows as $r) { + $T_OrderDetailID = $r["T_OrderDetailID"]; + $sexID = $r["M_PatientM_SexID"]; + $ageInDay = $r["Dob"]; + $natTestID = $r["T_TestNat_TestID"]; + list($methodeID, $methodeName) = $this->getMethodeID($natTestID); + if ($methodeID == 0) continue; + $normalValueID = $this->get_normal_value($methodeID, $natTestID, $sexID, $ageInDay); + if ($normalValueID == 0) return; + $this->db->query($sql_u, array($T_OrderDetailID, $normalValueID, $methodeID, $methodeName)); + } + } + function update_order_sample($targetID, $sourceID) + { + $sql = "update t_ordersample target + join t_ordersample source on + target.T_OrderSampleID = ? + and target.T_OrderSampleWorklistReceive = 'N' + and source.T_OrderSampleID = ? + set + target.T_OrderSampleSampling = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSampling, source.T_OrderSampleSampling), + target.T_OrderSampleSamplingDate = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingDate, source.T_OrderSampleSamplingDate), + target.T_OrderSampleSamplingTime = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingTime, source.T_OrderSampleSamplingTime), + target.T_OrderSampleSamplingUserID = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingUserID, source.T_OrderSampleSamplingUserID), + + target.T_OrderSampleReceive = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceive, source.T_OrderSampleReceive), + target.T_OrderSampleReceiveDate = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveDate, source.T_OrderSampleReceiveDate), + target.T_OrderSampleReceiveTime = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveTime, source.T_OrderSampleReceiveTime), + target.T_OrderSampleReceiveUserID = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveUserID, source.T_OrderSampleReceiveUserID), + + target.T_OrderSampleVerification = if(target.T_OrderSampleVerification='Y',target.T_OrderSampleVerification, source.T_OrderSampleVerification), + target.T_OrderSampleVerificationDate =if(target.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationDate, source.T_OrderSampleVerificationDate), + target.T_OrderSampleVerificationTime =if(source.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationTime, source.T_OrderSampleVerificationTime), + target.T_OrderSampleVerificationUserID =if(source.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationUserID, source.T_OrderSampleVerificationUserID), + + target.T_OrderSampleProcessing = if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessing, source.T_OrderSampleProcessing), + target.T_OrderSampleProcessingDate= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingDate, source.T_OrderSampleProcessingDate), + target.T_OrderSampleProcessingTime= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingTime, source.T_OrderSampleProcessingTime), + target.T_OrderSampleProcessingUserID= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingUserID, source.T_OrderSampleProcessingUserID), + + target.T_OrderSampleReceiveHandling =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandling, source.T_OrderSampleReceiveHandling ), + target.T_OrderSampleReceiveHandlingDate =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingDate, source.T_OrderSampleReceiveHandlingDate), + target.T_OrderSampleReceiveHandlingTime =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingTime, source.T_OrderSampleReceiveHandlingTime), + target.T_OrderSampleReceiveHandlingUserID =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingUserID, source.T_OrderSampleReceiveHandlingUserID), + + target.T_OrderSampleHandling = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandling, source.T_OrderSampleHandling), + target.T_OrderSampleHandlingDate = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingDate, source.T_OrderSampleHandlingDate), + target.T_OrderSampleHandlingTime = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingTime, source.T_OrderSampleHandlingTime), + target.T_OrderSampleHandlingUserID = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingUserID, source.T_OrderSampleHandlingUserID), + + target.T_OrderSampleWorklistReceive = source.T_OrderSampleWorklistReceive, + target.T_OrderSampleWorklistReceiveDatetime = source.T_OrderSampleWorklistReceiveDateTime, + target.T_OrderSampleWorklistReceiveUserID = source.T_OrderSampleWorklistReceiveUserID + "; + $qry = $this->db->query($sql, array($targetID, $sourceID)); + if (! $qry) { + echo json_encode(array("status" => "ERR", "message" => print_r($this->db->error(), true))); + exit; + } + } + function fix_sample_serum($headerID) + { + //cari t_ordersample yg belum worklist receive dengan code 017% + $sql = "select T_OrderSampleID + from t_ordersample + join t_sampletype on + T_OrderSampleT_OrderHeaderID = ? + and T_OrderSampleWorklistReceive = 'N' + and T_OrderSampleIsActive = 'Y' + and T_OrderSampleT_SampleTypeID = T_SampletypeID + and T_SampleTypeCode like '017%' + "; + $qry = $this->db->query($sql, array($headerID)); + if (!$qry) { + echo json_encode(array("status" => "ERR", "message" => print_r($this->db->error(), true))); + exit; + } + $rows = $qry->result_array(); + if (count($rows) == 0) return; + //cari T_OrderSample yang sudah di receive yg terakhir + $sql = "select T_OrderSampleID + from t_ordersample + join t_sampletype on + T_OrderSampleT_OrderHeaderID = ? + and T_OrderSampleWorklistReceive = 'Y' + and T_OrderSampleIsActive = 'Y' + and T_OrderSampleT_SampleTypeID = T_SampletypeID + and T_SampleTypeCode like '017%' + order by T_OrderSampleWorklistReceiveDatetime desc + limit 0,1 + "; + $qry = $this->db->query($sql, array($headerID)); + if (!$qry) { + echo json_encode(array("status" => "ERR", "message" => print_r($this->db->error(), true))); + exit; + } + $rcv_rows = $qry->result_array(); + if (count($rcv_rows) == 0) return; + + //print_r($rows); + //print_r($rcv_rows); + $rcv_T_OrderSampleID = $rcv_rows[0]["T_OrderSampleID"]; + //ada yg belum di receive + foreach ($rows as $r) { + $T_OrderSampleID = $r["T_OrderSampleID"]; + $this->update_order_sample($T_OrderSampleID, $rcv_T_OrderSampleID); + } + } + public function search() + { + $prm = $this->sys_input; + $max_rst = 99; + + $id = $prm["order_id"]; + if ($id > 0) { + $this->fix_sample_serum($id); + $this->fn_fix_normal($id); + } + $lang = $this->lang_default_code; + $lang_id = isset($prm['lang_id']) ? $prm['lang_id'] : '0'; + + if ($lang_id != 0) { + $l = $this->db_smartone->where("Nat_LangID", $lang_id)->get("nat_lang")->row(); + $lang = $l->Nat_LangCode; + } + + //tambahan fajri + $sql = " UPDATE t_orderdetail + JOIN t_test ON T_OrderDetailT_TestID = T_TestID + SET T_OrderDetailT_TestIsResult = T_TestIsResult + WHERE + T_OrderDetailT_OrderHeaderID = {$id} AND + T_OrderDetailT_TestIsResult = '' AND + T_OrderDetailIsActive = 'Y'"; + $this->db_smartone->query($sql); + + $tot_count = 0; + $lq = ""; + $group_id = 0; + if (isset($prm['group_id'])) + $group_id = $prm['group_id']; + + if ($group_id != 0) { + $sql = "select distinct T_WorklistDetailNat_TestID Nat_TestID + from t_worklistdetailv2 + where T_WorklistDetailT_WorklistID = {$group_id}"; + $qry = $this->db_smartone->query($sql); + $rows = $qry->result_array(); + $nat_test_ids = "0"; + foreach ($rows as $r) { + $nat_test_ids .= ", " . $r["Nat_TestID"]; + } + $q_group = " ( $nat_test_ids ) "; + + $sql = " + SELECT a1.*, cOUNT(a2.T_OrderDetailID) level + FROM ( + SELECT IFNULL(y.T_OrderDetailT_TestID, x.T_OrderDetailT_TestID) t_testid, + IFNULL(y.T_OrderDetailT_TestName, y.T_OrderDetailT_TestName) t_testname, + y.T_OrderDetailResult result, y.T_OrderDetailResult result_old, y.T_OrderDetailNote note, y.T_OrderDetailNote note_old, + y.T_OrderDetailID id, + y.T_OrderDetailT_TestIsResult is_result, a.T_TestIsQuantitative is_quantitative, + y.T_OrderDetailResultFlag result_flag, + y.T_OrderDetailNat_NormalValueID normal_id, + y.T_OrderDetailNormalValueNote normal_note, y.T_OrderDetailNat_UnitName unit_name, + y.T_OrderdetailNat_MethodeID methode_id, y.T_OrderdetailNat_MethodeName methode_name, + a.T_TestNat_TestID nattest_id, a.T_TestID tx_id, count(T_ResultInstrumentID) as result_instrument_n, + y.T_OrderDetailVerification, T_OrderSampleReceive sample_receive, + T_OrderSampleProcessing sample_processing, T_OrderSampleWorklistReceive sample_worklist_receive, + IF(T_OrderDetailAddOnPreAnalytic = 'Y', T_OrderDetailAddOnPreAnalytic, PreAnalyticIsOk) pre_analytic, + T_OrderDetailAddOnPreAnalytic, + T_OrderHeaderID order_id, y.T_OrderDetailT_TestSasCode test_sas_code, + tx.T_TestSasCode, + T_OrderDetailAddOnResample `resample`, T_OrderDetailAddOnResampleStatus resample_status, + T_OrderDetailAddOnRef ref, y.T_OrderDetailVerification verification, y.T_OrderDetailValidation validation, + T_OrderPromiseDateTime, Group_ResultName as ResultGroupName + FROM t_orderdetail x + left join t_orderpromise on x.T_OrderDetailT_OrderPromiseID = T_OrderPromiseID + JOIN t_test tx ON x.T_OrderDetailT_TestID = T_TestID + JOIN t_test tcheck on tcheck.T_TestNat_TestID in {$q_group} + and ( tx.T_TestID = tcheck.T_TestID or tx.T_TestSasCode like concat(tcheck.T_TestSasCode,'%')) + LEFT JOIN group_resultdetail ON Group_ResultDetailT_TestID = x.T_OrderDetailT_TestID AND Group_ResultDetailIsActive = 'Y' + LEFT JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND Group_ResultFlagNonLab = 'N' + LEFT JOIN t_orderdetail y ON x.T_OrderDetailT_TestSasCode LIKE CONCAT(y.T_OrderDetailT_TestSasCode, '%') + AND x.T_OrderDetailT_OrderHeaderID = y.T_OrderDetailT_OrderHeaderID + AND y.T_OrderDetailIsActive = 'Y' + LEFT JOIN t_orderdetailaddon ON x.T_OrderDetailID = T_OrderDetailAddOnT_OrderDetailID + JOIN t_orderheader ON y.T_OrderDetailT_OrderHeaderID = T_OrderHeaderID + LEFT JOIN t_test a ON y.T_OrderDetailT_TestID = a.T_TestID + AND a.T_TestIsNonLab = '' + LEFT JOIN (SELECT T_OrderSampleT_SampleTypeID, T_OrderSampleReceive, T_OrderSampleProcessing, T_OrderSampleWorklistReceive + FROM t_ordersample WHERE T_OrderSampleT_OrderHeaderID = {$id} + AND T_OrderSampleIsactive = 'Y' + GROUP BY T_OrderSampleT_SampleTypeID) os ON a.T_TestT_SampleTypeID = os.T_OrderSampleT_SampleTypeID + or os.T_OrderSampleT_SampleTypeID = fn_sampletype_from_local(a.T_TestNat_TestID) + + LEFT JOIN t_resultinstrument ON T_ResultInstrumentT_OrderDetailID = x.T_OrderDetailID + LEFT JOIN pre_analytic ON PreAnalyticNat_TestID = a.T_TestNat_TestID AND PreAnalyticDate = date(now()) and PreAnalyticIsActive = 'Y' + WHERE x.T_OrderDetailT_OrderHeaderID = {$id} + AND x.T_OrderDetailIsActive = 'Y' + GROUP BY y.T_OrderDetailT_TestID + ORDER BY y.T_OrderDetailT_TestSasCode ASC + ) a1 + + LEFT JOIN t_orderdetail a2 ON a2.T_OrderDetailT_OrderHeaderID = a1.order_id + AND a2.T_OrderDetailIsActive = 'Y' + AND a1.test_sas_code LIKE CONCAT(a2.T_OrderDetailT_testSasCode, '%') + GROUP BY a1.t_testid + order by a1.test_sas_code +"; + $query = $this->db_smartone->query($sql); + $lq = $this->db_smartone->last_query(); + } else { + $sql = " + SELECT a1.*, cOUNT(a2.T_OrderDetailID) level + FROM ( + SELECT IFNULL(y.T_OrderDetailT_TestID, x.T_OrderDetailT_TestID) t_testid, + IFNULL(y.T_OrderDetailT_TestName, y.T_OrderDetailT_TestName) t_testname, + y.T_OrderDetailResult result, y.T_OrderDetailResult result_old, y.T_OrderDetailNote note, y.T_OrderDetailNote note_old, + y.T_OrderDetailID id, + y.T_OrderDetailT_TestIsResult is_result, a.T_TestIsQuantitative is_quantitative, + y.T_OrderDetailResultFlag result_flag, + y.T_OrderDetailNat_NormalValueID normal_id, + y.T_OrderDetailNormalValueNote normal_note, y.T_OrderDetailNat_UnitName unit_name, + y.T_OrderdetailNat_MethodeID methode_id, y.T_OrderdetailNat_MethodeName methode_name, + a.T_TestNat_TestID nattest_id, a.T_TestID tx_id, count(T_ResultInstrumentID) as result_instrument_n, + y.T_OrderDetailVerification, T_OrderSampleReceive sample_receive, + T_OrderSampleProcessing sample_processing, T_OrderSampleWorklistReceive sample_worklist_receive, + IF(T_OrderDetailAddOnPreAnalytic = 'Y', T_OrderDetailAddOnPreAnalytic, PreAnalyticIsOk) pre_analytic, + T_OrderDetailAddOnPreAnalytic, + T_OrderHeaderID order_id, y.T_OrderDetailT_TestSasCode test_sas_code, + tx.T_TestSasCode, + T_OrderDetailAddOnResample `resample`, T_OrderDetailAddOnResampleStatus resample_status, + T_OrderDetailAddOnRef ref, y.T_OrderDetailVerification verification, y.T_OrderDetailValidation validation, + T_OrderPromiseDateTime , Group_ResultName as ResultGroupName + FROM t_orderdetail x + left join t_orderpromise on x.T_OrderDetailT_OrderPromiseID = T_OrderPromiseID + JOIN t_test tx ON x.T_OrderDetailT_TestID = T_TestID + LEFT JOIN group_resultdetail ON Group_ResultDetailT_TestID = x.T_OrderDetailT_TestID AND Group_ResultDetailIsActive = 'Y' + LEFT JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND Group_ResultFlagNonLab = 'N' + LEFT JOIN t_orderdetail y ON x.T_OrderDetailT_TestSasCode LIKE CONCAT(y.T_OrderDetailT_TestSasCode, '%') + AND x.T_OrderDetailT_OrderHeaderID = y.T_OrderDetailT_OrderHeaderID + AND y.T_OrderDetailIsActive = 'Y' + + LEFT JOIN t_orderdetailaddon ON x.T_OrderDetailID = T_OrderDetailAddOnT_OrderDetailID + + JOIN t_orderheader ON y.T_OrderDetailT_OrderHeaderID = T_OrderHeaderID + LEFT JOIN t_test a ON y.T_OrderDetailT_TestID = a.T_TestID + AND a.T_TestIsNonLab = '' + LEFT JOIN (SELECT T_OrderSampleT_SampleTypeID, T_OrderSampleReceive, T_OrderSampleProcessing, T_OrderSampleWorklistReceive + FROM t_ordersample WHERE T_OrderSampleT_OrderHeaderID = {$id} + AND T_OrderSampleIsactive = 'Y' + GROUP BY T_OrderSampleT_SampleTypeID) os ON a.T_TestT_SampleTypeID = os.T_OrderSampleT_SampleTypeID + or os.T_OrderSampleT_SampleTypeID = fn_sampletype_from_local(a.T_TestNat_TestID) + + LEFT JOIN t_resultinstrument ON T_ResultInstrumentT_OrderDetailID = x.T_OrderDetailID + LEFT JOIN pre_analytic ON PreAnalyticNat_TestID = a.T_TestNat_TestID AND PreAnalyticDate = date(now()) and PreAnalyticIsActive = 'Y' + WHERE x.T_OrderDetailT_OrderHeaderID = {$id} + AND x.T_OrderDetailIsActive = 'Y' + GROUP BY y.T_OrderDetailT_TestID + ORDER BY y.T_OrderDetailT_TestSasCode ASC + ) a1 + + LEFT JOIN t_orderdetail a2 ON a2.T_OrderDetailT_OrderHeaderID = a1.order_id + AND a2.T_OrderDetailIsActive = 'Y' + AND a1.test_sas_code LIKE CONCAT(a2.T_OrderDetailT_testSasCode, '%') + GROUP BY a1.t_testid + order by a1.test_sas_code +"; + //echo $sql; + $query = $this->db_smartone->query($sql); + $lq = $this->db_smartone->last_query(); + } + // file_put_contents("/xtmp/re-query.sql",$lq); + + if ($query) { + $rst = []; + $rows = $query->result_array(); + + foreach ($rows as $k => $v) { + + if ($v['is_result'] == "Y" && $v['is_quantitative'] == "N") { + $v['template'] = []; + $x = $this->db_smartone->query("CALL sp_master_resulttemplate_get('{$v['t_testid']}')"); + $this->clean_mysqli_connection($this->db_smartone->conn_id); + if ($x) + $v['template'] = $x->result_array(); + } + + // IF Rujukan, by pas Pre Analytik + if ($v['ref'] == 'Y') + $v['pre_analytic'] = 'Y'; + if ($v["id"] == "885455") { + //sipe workaround + //$v["sample_receive"] = "Y"; + $v["sample_worklist_receive"] = "Y"; + } + $rst[] = $v; + } + + $result = array("total" => $tot_count, "records" => $rst, "total_display" => sizeof($rows), "q" => $lq); + $this->sys_ok($result); + } else { + $this->sys_error_db("RE Px rows", $this->db_smartone); + exit; + } + } + + public function save() + { + $prm = $this->sys_input; + $data = json_decode($prm["data"]); + $lang = $this->lang_default_code; + $lang_id = isset($prm['lang_id']) ? $prm['lang_id'] : '0'; + + if ($lang_id != 0) { + $l = $this->db_smartone->where("Nat_LangID", $lang_id)->get("nat_lang")->row(); + $lang = $l->Nat_LangCode; + } + + $sql_norm = "select T_OrderDetailMinValue, T_OrderDetailMaxValue, + T_OrderDetailMinValueInclusive, T_OrderDetailMaxValueInclusive, + Nat_TestFlagLow, Nat_TestFlagHigh + from t_orderdetail + join t_test on T_OrderDetailT_TestID = T_TestID + join nat_test on T_TestNat_TestID = Nat_TestID and T_TestIsActive = 'Y' + where T_OrderDetailID = ? "; + + $ids = []; + foreach ($data as $k => $v) { + if ($v->resultInstrumentID > 0) { + $sql_i = "select T_ResultInstrumentNat_NormalValueID normalValueID + from t_resultinstrument + where T_ResultInstrumentID = ?"; + $qry_i = $this->db_smartone->query($sql_i, array($v->resultInstrumentID)); + if ($qry_i) { + $rows_i = $qry_i->result_array(); + + if (count($rows_i) > 0) { + $sql_iu = "update t_orderdetail, nat_normalvalue , nat_methode + set T_OrderDetailMinValue = Nat_NormalValueMinValue, + T_OrderDetailMinValueInclusive = Nat_NormalValueMinValueInclusive, + T_OrderDetailMaxValue = Nat_NormalValueMaxValue , + T_OrderDetailMaxValueInclusive = Nat_NormalValueMaxValueInclusive, + T_OrderDetailNormalValueNote = Nat_NormalValueNote, + T_OrderDetailNormalValueDescription = Nat_NormalValueDescription, + T_OrderDetailNat_NormalValueID = Nat_NormalValueID, + T_OrderDetailNat_MethodeID = Nat_NormalValueNat_MethodeID, + T_OrderDetailNat_MethodeName = Nat_MethodeName + where T_OrderDetailID = ? and Nat_NormalValueID = ? + and Nat_NormalValueNat_MethodeID = Nat_MethodeID + "; + $this->db_smartone->query($sql_iu, array($v->id, $rows_i[0]["normalValueID"])); + //file_put_contents("/xtmp/update-nilai-normal", $this->db_smartone->last_query() . "\n", FILE_APPEND); + } + } + } + $y = $this->db_smartone->query("SELECT fn_process_sample_handling_perfect('{$v->order_id}', '{$v->test_id}') c") + ->row(); + $req_status = $y->c; + $qry_norm = $this->db_smartone->query($sql_norm, $v->id); + $result_flag = ""; + if ($qry_norm) { + $rows_norm = $qry_norm->result_array(); + if (count($rows_norm) > 0) { + $r = $rows_norm[0]; + if (is_numeric($v->result)) { + + if ($r["T_OrderDetailMinValueInclusive"] == "Y" && $v->result < $r["T_OrderDetailMinValue"]) { + $result_flag = $r["Nat_TestFlagLow"]; + } + if ($r["T_OrderDetailMinValueInclusive"] == "N" && $v->result <= $r["T_OrderDetailMinValue"]) { + $result_flag = $r["Nat_TestFlagLow"]; + } + if ($r["T_OrderDetailMaxValueInclusive"] == "Y" && $v->result > $r["T_OrderDetailMaxValue"]) { + $result_flag = $r["Nat_TestFlagHigh"]; + } + if ($r["T_OrderDetailMaxValueInclusive"] == "N" && $v->result >= $r["T_OrderDetailMaxValue"]) { + $result_flag = $r["Nat_TestFlagHigh"]; + } + } + } + } + if ($lang == $this->lang_default_code) { + $this->db_smartone->set('T_OrderDetailResult', $v->result) + ->set('T_OrderDetailResultFlag', $result_flag) + ->set('T_OrderDetailNote', $v->note) + ->set('T_OrderDetailReqStatus', $req_status) + ->where('T_OrderDetailID', $v->id) + ->update('t_orderdetail'); + } else { + $this->db_smartone->set('T_OrderDetailLangResult', $v->result) + ->set('T_OrderDetailLangNote', $v->note) + ->where('T_OrderDetailLangID', $v->id) + ->update('t_orderdetaillang'); + } + + $ids[] = $v->id; + } + + // LOG Process + $order = $this->db_smartone->select('T_OrderDetailT_OrderHeaderID id, T_OrderHeaderLabNumber lab_number', false) + ->join('t_orderheader', 'T_OrderHeaderID = T_OrderDetailT_OrderHeaderID') + ->where('T_OrderDetailID', $data[0]->id) + ->get('t_orderdetail') + ->row(); + + $dblog = $this->load->database("onelog", true); + $dblog->set('Log_ProcessCode', 'PROCESS.Result.Entry') + ->set('Log_ProcessOrderID', $order->id) + ->set('Log_ProcessOrderNumber', $order->lab_number) + ->set('Log_ProcessJson', json_encode($data)) + ->set('Log_ProcessUserID', $this->sys_user['M_UserID']) + ->insert('log_process'); + // END OF Log Process + //auto calculation + $this->load->library("Resultcalc"); + $rows = $this->resultcalc->auto($order->id); + + try { + foreach ($ids as $id) { + $this->db_smartone->query("call sp_set_normal_value_flag($id)"); + $this->clean_mysqli_connection($this->db_smartone->conn_id); + } + } catch (Exception $e) { + } + + $this->sys_ok($ids); + } + + public function save_template() + { + $prm = $this->sys_input; + + $n = $this->db_smartone->select("COUNT(T_ResultTemplateID) n") + ->where("T_ResultTemplateT_TestID", $prm['test_id']) + ->where("T_ResultTemplateIsActive", "Y") + ->where("T_ResultTemplateValue", $prm['value']) + ->get('t_resulttemplate') + ->row(); + if ($n->n > 0) { + $this->sys_error_db("Insert Result Template", $this->db_smartone); + return; + } + + $r = $this->db_smartone->set("T_ResultTemplateT_TestID", $prm['test_id']) + ->set("T_ResultTemplateValue", $prm['value']) + ->insert('t_resulttemplate'); + if ($r) { + $template = []; + $x = $this->db_smartone->query("CALL sp_master_resulttemplate_get('{$prm['test_id']}')"); + $this->clean_mysqli_connection($this->db_smartone->conn_id); + if ($x) + $template = $x->result_array(); + + $this->sys_ok($template); + } + } + + public function export() + { + $prm = $this->sys_input; + + $sql = "CALL sp_process_result_lang(?, ?, ?, ?)"; + $query = $this->db_smartone->query($sql, [$prm['order_id'], $prm['lang_id'], $prm['is_si'], $this->sys_user['M_UserID']]); + if ($query) { + $r = $query->row(); + if ($r->status == "OK") { + $this->sys_ok($r->data); + return; + } + + $this->sys_error_db("Message : " . $r->message, $this->db_smartone); + } else { + $this->sys_error_db("Lang Result", $this->db_smartone); + return; + } + } + + public function search_group() + { + $prm = $this->sys_input; + $max_rst = 100; + + // QUERY TOTAL + $sql = "select count(*) total + from t_worklist + where T_WorklistIsActive = 'Y' + order by T_WorklistName ASC"; + $query = $this->db_smartone->query($sql); + + if ($query) { + $tot_count = $query->result_array()[0]["total"]; + } else { + $this->sys_error_db("worklist count", $this->db_smartone); + exit; + } + + $sql = "select T_WorklistID group_id, T_WorklistName group_name + from t_worklist + where T_WorklistIsActive = 'Y' + order by T_WorklistName ASC + limit 0, {$max_rst}"; + $query = $this->db_smartone->query($sql); + + if ($query) { + $rows = $query->result_array(); + foreach ($rows as $k => $v) + $rows[$k]['data'] = json_decode($v['data']); + $result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows), "q" => $this->db_smartone->last_query()); + $this->sys_ok($result); + } else { + $this->sys_error_db("worklist rows", $this->db_smartone); + exit; + } + } + + public function search_rerun() + { + $prm = $this->sys_input; + $id = $prm["detail_id"]; + + $sql = "CALL sp_process_result_rerun(?)"; + $query = $this->db_smartone->query($sql, [$id]); + + if ($query) { + $rows = $query->result_array(); + $this->sys_ok(["records" => $rows]); + } else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + + + function getdoctorsfna() + { + $prm = $this->sys_input; + // $id = $prm["id"]; + + $sql = " SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY M_DoctorName ASC"; + //echo $sql; + $query = $this->db_smartone->query($sql); + + if ($query) { + $rows = $query->result_array(); + $this->sys_ok(["records" => $rows]); + } else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + function getfnaresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT Other_FNADetailsID as xid, + Other_FNAT_OrderDetailID as orderdetail_id, + Other_FNADetailsCode as code, + Other_FNADetailsLabel as label, + Other_FNADetailsResult as result, + IFNULL(Other_FNAM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_FNAM_DoctorID) OR Other_FNAM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_fna + JOIN other_fnadetails ON Other_FNADetailsOther_FNAID = Other_FNAID AND Other_FNADetailsIsActive = 'Y' + LEFT JOIN m_doctor ON Other_FNAM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_FNAT_OrderDetailID = {$id} AND Other_FNAIsActive = 'Y' + GROUP BY Other_FNADetailsID + ORDER BY Other_FNADetailsCode ASC"; + $query = $this->db_smartone->query($sql); + + if ($query) { + $rows = $query->result_array(); + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $images = array(); + $sql = "SELECT So_ImageUploadID as xid, + CONCAT('/one-media/one-image-nonlab/',So_ImageUploadNewName) as image_url + FROM t_orderdetail + JOIN so_imageupload ON So_ImageUploadT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND + So_ImageUploadIsActive = 'Y' + WHERE + T_OrderDetailID = {$id} AND + T_OrderDetailIsActive = 'Y' + GROUP BY So_ImageUploadID"; + $images = $this->db_smartone->query($sql)->result_array(); + + $rst = array('doctors' => $doctors, 'results' => $rows, 'images' => $images); + $this->sys_ok(["records" => $rst]); + } else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + + function uploadimage() + { + if (! $this->isLogin) { + $this->sys_error("Invalid Token"); + exit; + } + + $userid = $this->sys_user["M_UserID"]; + $data = []; + //print_r($_SERVER); + + $prm = $this->sys_input; + $orderid = $this->input->post('orderid'); + $labnumber = $this->input->post('labnumber'); + $sql = "UPDATE so_imageupload SET + So_ImageUploadIsActive = 'N', + So_ImageUploadUserID = {$userid} + WHERE + So_ImageUploadT_OrderHeaderID = {$orderid}"; + //echo $sql; + $this->db_onedev->query($sql); + //$config['upload_path'] = 'assets/'; + + $path = '/home/one/project/one/one-media/one-image-nonlab/'; + //echo $path; + $config['upload_path'] = $path; + $config['allowed_types'] = 'jpg|jpeg|png|gif'; + + $config['max_size'] = '10000'; + $count = count($_FILES['files']['name']); + //echo $count; + $this->load->library('upload', $config); + + $error = []; + for ($i = 0; $i < $count; $i++) { + + + if (!empty($_FILES['files']['name'][$i])) { + + + + $_FILES['file']['name'] = $_FILES['files']['name'][$i]; + + $_FILES['file']['type'] = $_FILES['files']['type'][$i]; + + $_FILES['file']['tmp_name'] = $_FILES['files']['tmp_name'][$i]; + + $_FILES['file']['error'] = $_FILES['files']['error'][$i]; + + $_FILES['file']['size'] = $_FILES['files']['size'][$i]; + + + + $namex = $orderid . '-' . $labnumber . '-' . $this->generateRandomString(5); + //echo $namex; + + $config['file_name'] = $namex; + $this->upload->initialize($config); + //echo $config['file_name'] ; + + + + + + if ($this->upload->do_upload('file')) { + + $uploadData = $this->upload->data(); + + $filename = $uploadData['file_name']; + //echo $filename; + + + $sql = "INSERT INTO so_imageupload ( + So_ImageUploadT_OrderHeaderID, + So_ImageUploadT_OrderHeaderLabNumber, + So_ImageUploadT_SampleTypeID, + So_ImageUploadOldName, + So_ImageUploadNewName, + So_ImageUploadCreated, + So_ImageUploadUserID + ) + VALUES( + {$orderid}, + '{$labnumber}', + '150', + '{$_FILES['files']['name'][$i]}', + '{$filename}', + NOW(), + {$userid} + + )"; + //echo $sql; + $this->db_onedev->query($sql); + $xlast_id = $this->db_onedev->insert_id(); + $data['totalFiles'][] = array('xid' => $xlast_id, 'image_url' => '/one-media/one-image-nonlab/' . $filename); + } else { + $error = array('error' => $this->upload->display_errors()); + } + } + } + + $result = array("total" => count($data['totalFiles']), "records" => $data['totalFiles'], 'errors' => $error); + $this->sys_ok($result); + } + + + function getpatologianatomyresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT Other_PatologiAnatomyID as xid, + Other_PatologiAnatomyT_OrderDetailID as orderdetail_id, + Other_PatologiAnatomyNoSediaan as no_sediaan, + Other_PatologiAnatomyDiagnosaKlinis as diagnosa, + Other_PatologiAnatomyKeteranganKlinis as klinis, + Other_PatologiAnatomyLokasiOrgan as lokasi, + Other_PatologiAnatomyMakroskopik as makroskopik, + Other_PatologiAnatomyMikroskopik as mikroskopik, + Other_PatologiAnatomyKesimpulan as kesimpulan, + IFNULL(Other_PatologiAnatomyM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_PatologiAnatomyM_DoctorID) OR Other_PatologiAnatomyM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_patologi_anatomy + LEFT JOIN m_doctor ON Other_PatologiAnatomyM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_PatologiAnatomyT_OrderDetailID = {$id} AND Other_PatologiAnatomyIsActive = 'Y' + GROUP BY Other_PatologiAnatomyID + ORDER BY Other_PatologiAnatomyID ASC + LIMIT 1"; + $query = $this->db_smartone->query($sql); + + if ($query) { + $rows = $query->row_array(); + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + + $sql = "SELECT So_ImageUploadPatologyAnatomyID as xid, + CONCAT('/one-media/one-image-nonlab/',So_ImageUploadPatologyAnatomyNewName) as image_url, + So_ImageUploadPatologyAnatomyType as type + FROM t_orderdetail + JOIN so_imageupload_patology_anatomy ON So_ImageUploadPatologyAnatomyT_OrderHeaderID= T_OrderDetailT_OrderHeaderID AND + So_ImageUploadPatologyAnatomyIsActive= 'Y' + WHERE + T_OrderDetailID = {$id} AND + T_OrderDetailIsActive = 'Y' + GROUP BY So_ImageUploadPatologyAnatomyID"; + $images = $this->db_smartone->query($sql)->result_array(); + $mikro = []; + $makro = []; + + foreach ($images as $key => $value) { + + if ($value['type'] == 'mikro') { + $mikro[] = $value; + } + if ($value['type'] == 'makro') { + $makro[] = $value; + } + } + + $rst = array('doctors' => $doctors, 'result' => $rows, 'mikro' => $mikro, 'makro' => $makro); + $this->sys_ok(["records" => $rst]); + } else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + + + function generateRandomString($length = 10) + { + $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; + $charactersLength = strlen($characters); + $randomString = ''; + for ($i = 0; $i < $length; $i++) { + $randomString .= $characters[rand(0, $charactersLength - 1)]; + } + return $randomString; + } + + function getcytologiresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT Other_CytologiDetailsID as xid, + Other_CytologiT_OrderDetailID as orderdetail_id, + Other_CytologiDetailsCode as code, + Other_CytologiDetailsLabel as label, + Other_CytologiDetailsResult as result, + IFNULL(Other_CytologiM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_CytologiM_DoctorID) OR Other_CytologiM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_cytologi + JOIN other_cytologidetails ON Other_CytologiDetailsOther_CytologiID = Other_CytologiID AND Other_CytologiDetailsIsActive = 'Y' + LEFT JOIN m_doctor ON Other_CytologiM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_CytologiT_OrderDetailID = {$id} AND Other_CytologiIsActive = 'Y' + GROUP BY Other_CytologiDetailsID + ORDER BY Other_CytologiDetailsCode ASC"; + //echo $sql; + $query = $this->db_smartone->query($sql); + + if ($query) { + $rows = $query->result_array(); + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $rst = array('doctors' => $doctors, 'results' => $rows); + $this->sys_ok(["records" => $rst]); + } else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + function getmikroresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT + Other_MikroID as xid, + Other_MikroHasilBiakan as hasil_biakan, + Other_MikroSampleTypeName as sample_name, + Other_MikroT_OrderDetailID as orderdetail_id, + Other_MikroResult as result_value, + '' as result_other, + IFNULL(T_BacteriaID,0) as T_BacteriaID, + IFNULL(T_BacteriaName,'') as T_BacteriaName, + '' as details, + IFNULL(Other_MikroM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_MikroM_DoctorID) OR Other_MikroM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_mikro + LEFT JOIN t_bacteria ON Other_MikroT_BacteriaID = T_BacteriaID + LEFT JOIN m_doctor ON Other_MikroM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_MikroT_OrderDetailID = {$id} AND Other_MikroIsActive = 'Y' + GROUP BY Other_MikroID"; + //echo $sql; + $query = $this->db_smartone->query($sql); + + if ($query) { + $row = $query->row_array(); + if ($row) { + if ($row['result_value'] != 'Positif' && $row['result_value'] != 'Negatif') { + $row['result_other'] = $row['result_value']; + $row['result_value'] = 'other'; + } + $sql = "SELECT '' as xno, + Other_MikroDetailsID as xid, + Other_MikroDetailsValue as value, + IF(Other_MikroDetailsNote = 'R','Y','N') as chx_r, + IF(Other_MikroDetailsNote = 'I','Y','N') as chx_i, + IF(Other_MikroDetailsNote = 'S','Y','N') as chx_s, + Other_MikroDetailsNote as note, + t_antibiotic.* + FROM other_mikrodetails + LEFT JOIN t_antibiotic ON Other_MikroDetailsT_AntibioticID = T_AntibioticID + WHERE + Other_MikroDetailsOther_MikroID = {$row['xid']} AND Other_MikroDetailsIsActive = 'Y' + GROUP BY Other_MikroDetailsID + ORDER BY T_AntibioticName ASC"; + //echo $sql; + $details = $this->db_smartone->query($sql)->result_array(); + if (details) { + foreach ($details as $k => $v) { + $details[$k]['xno'] = $k + 1; + } + } + $row['details'] = $details; + } else { + $row = array('xid' => '0', 'hasil_biakan' => '', 'result_value' => 'Negatif', 'sample_name' => '', 'orderdetail_id' => $id, 'T_BacteriaID' => '0', 'T_BacteriaName' => '0', 'details' => array(), 'doctor_id' => '0', 'doctor_name' => '0'); + } + } else { + $row = array('xid' => '0', 'hasil_biakan' => '', 'result_value' => 'Negatif', 'sample_name' => '', 'orderdetail_id' => $id, 'T_BacteriaID' => '0', 'T_BacteriaName' => '0', 'details' => array(), 'doctor_id' => '0', 'doctor_name' => '0'); + } + //print_r($row); + + + + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 7 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $sql = " + SELECT '0' as id, 'Belum memilih bakteria' as name + UNION + SELECT T_BacteriaID as id, T_BacteriaName as name + FROM t_bacteria + WHERE + T_BacteriaIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $bacteries = $this->db_smartone->query($sql)->result_array(); + $rst = array('doctors' => $doctors, 'bacteries' => $bacteries, 'results' => $row); + $this->sys_ok(["records" => $rst]); + } + function getantibiotics() + { + $prm = $this->sys_input; + $id = $prm["id"]; + $sql = " SELECT '' as xno, + 0 as xid, + '' as hasil_biakan, + '' as sample_name, + 0 as value, + 'Y' as chx_r, + 'N' as chx_i, + 'N' as chx_s, + 'R' as note, + t_antibiotic.* + FROM t_antibiotic + WHERE + T_AntibioticT_BacteriaID = {$prm['id']} AND T_AntibioticIsActive= 'Y' + ORDER BY T_AntibioticName ASC"; + //echo $sql; + $rows = $this->db_smartone->query($sql)->result_array(); + if (rows) { + foreach ($rows as $k => $v) { + $rows[$k]['xno'] = $k + 1; + } + } + + $this->sys_ok(["records" => $rows]); + } + function getlcprepresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + $sql = " SELECT Other_LcprepDetailsID as xid, + Other_LcprepID as header_id, + Other_LcprepT_orderDetailID as orderdetail_id, + Other_LcprepDetailsCode as code, + Other_LcprepDetailsLabel as label, + Other_LcprepDetailsResult as result, + IFNULL(Other_LcprepM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_LcprepM_DoctorID) OR Other_LcprepM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_lcprep + JOIN other_lcprepdetails ON Other_LcprepDetailsOther_LcprepID = Other_LcprepID AND Other_LcprepDetailsIsActive = 'Y' + LEFT JOIN m_doctor ON Other_LcprepM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_LcprepT_orderDetailID = {$id} AND Other_LcprepIsActive = 'Y' + GROUP BY Other_LcprepDetailsOther_LcprepID, Other_LcprepDetailsCode + ORDER BY Other_LcprepDetailsCode ASC"; + //echo $sql; + $rows = $this->db_smartone->query($sql)->result_array(); + if (!$rows) { + $rows = array( + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'A', + 'label' => 'DESKRIPSI', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ), + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'B', + 'label' => 'KESIMPULAN', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ) + ); + } + + $header_id = $rows[0]['header_id']; + $sql = "SELECT IFNULL(Other_LcprepAdekuasiID,0) as xid, + Lcprep_AdekuasiID as id, + Lcprep_AdekuasiLabel as name, + IF(ISNULL(Other_LcprepAdekuasiID),'N',Other_LcprepAdekuasiChex) as chex + FROM lcprep_adekuasi + LEFT JOIN other_lcprepadekuasi ON Other_LcprepAdekuasiLcprep_AdekuasiID = Lcprep_AdekuasiID AND + Other_LcprepAdekuasiOther_LcprepID = {$header_id} AND + Other_LcprepAdekuasiIsActive = 'Y' + WHERE + Lcprep_AdekuasiIsActive = 'Y' + GROUP BY Lcprep_AdekuasiID + ORDER BY Lcprep_AdekuasiOrder ASC + "; + //echo $sql; + $adeakuasi = $this->db_smartone->query($sql)->result_array(); + foreach ($adeakuasi as $kc => $vc) { + $adeakuasi[$kc]['chex'] = $vc['chex'] == 'N' ? false : true; + } + + $sql = "SELECT IFNULL(Other_LcprepKategoriUmumID,0) as xid, + Lcprep_KategoriUmumID as id, + Lcprep_KategoriUmumLabel as name, + IF(ISNULL(Other_LcprepKategoriUmumID),'N',Other_LcprepKategoriUmumChex) as chex + FROM lcprep_kategoriumum + LEFT JOIN other_lcprepkategoriumum ON Other_LcprepKategoriUmumLcprep_KategoriUmumID = Lcprep_KategoriUmumID AND + Other_LcprepKategoriUmumOther_LcprepID = {$header_id} AND + Other_LcprepKategoriUmumIsActive = 'Y' + WHERE + Lcprep_KategoriUmumIsActive = 'Y' + GROUP BY Lcprep_KategoriUmumID + "; + //echo $sql; + $kategoriumum = $this->db_smartone->query($sql)->result_array(); + foreach ($kategoriumum as $kc => $vc) { + $kategoriumum[$kc]['chex'] = $vc['chex'] == 'N' ? false : true; + } + + $sql = " + SELECT Lcprep_InterpretasiGroupID as group_id, + Lcprep_InterpretasiGroupName as group_name, + '' as subgroups + FROM lcprep_interpretasigroup + WHERE + Lcprep_InterpretasiGroupIsActive = 'Y' + "; + //echo $sql; + $interpretasi = $this->db_smartone->query($sql)->result_array(); + foreach ($interpretasi as $k => $v) { + $subgroups = array(); + $sql = "SELECT Lcprep_InterpretasiSubgroupID as subgroup_id, + Lcprep_InterpretasiSubgroupName as subgroup_name, + '' as childs + FROM lcprep_interpretasisubgroup + WHERE + Lcprep_InterpretasiSubgroupLcprep_InterpretasiGroupID = {$v['group_id']} AND Lcprep_InterpretasiSubgroupIsActive = 'Y'"; + //echo $sql; + $subgroups = $this->db_smartone->query($sql)->result_array(); + if (count($subgroups) > 0) { + foreach ($subgroups as $ki => $vi) { + $childs = array(); + $sql = "SELECT IFNULL(Other_LcprepInterpretasiID,0) as xid, + IFNULL(Other_LcprepInterpretasiChex,'N') as chex, + IFNULL(Other_LcprepInterpretasiValue,'') as value, + Lcprep_InterpretasiID as id, + Lcprep_InterpretasiLcprep_InterpretasiSubgroupID as subgroup_id, + Lcprep_InterpretasiCode as code, + Lcprep_InterpretasiName as name, + Lcprep_InterpretasiParentID as parent_id, + Lcprep_InterpretasiIsParent as is_parent, + Lcprep_InterpretasiHasResult as has_result, + Lcprep_InterpretasiTypeResult as type_result + FROM lcprep_interpretasi + LEFT JOIN other_lcprepinterpretasi ON Other_LcprepInterpretasiOther_LcprepID = {$header_id} AND + Other_LcprepInterpretasiLcprep_InterpretasiID = Lcprep_InterpretasiID AND + Other_LcprepInterpretasiIsActive = 'Y' + WHERE + Lcprep_InterpretasiLcprep_InterpretasiSubgroupID = {$vi['subgroup_id']} AND Lcprep_InterpretasiIsActive = 'Y' + GROUP BY Lcprep_InterpretasiID Order BY Lcprep_InterpretasiCode ASC"; + $childs = $this->db_smartone->query($sql)->result_array(); + if ($childs) { + foreach ($childs as $kc => $vc) { + $childs[$kc]['chex'] = $vc['chex'] == 'N' ? false : true; + } + } + $subgroups[$ki]['childs'] = $childs; + } + } + + $interpretasi[$k]['subgroups'] = $subgroups; + } + + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $rst = array('doctors' => $doctors, 'results' => $rows, 'adekuasi' => $adeakuasi, 'kategoriumum' => $kategoriumum, 'interpretasi' => $interpretasi); + $this->sys_ok(["records" => $rst]); + } + + function getpapsmearresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT Other_PapSmearDetailsID as xid, + Other_PapSmearID as header_id, + Other_PapSmearT_OrderDetailID as orderdetail_id, + Other_PapSmearDetailsCode as code, + Other_PapSmearDetailsLabel as label, + Other_PapSmearDetailsResult as result, + IFNULL(Other_PapSmearM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_PapSmearM_DoctorID) OR Other_PapSmearM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name + FROM other_papsmear + JOIN other_papsmeardetails ON Other_PapSmearDetailsOther_PapSmearID = Other_PapSmearID AND Other_PapSmearDetailsIsActive = 'Y' + LEFT JOIN m_doctor ON Other_PapSmearM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + Other_PapSmearT_OrderDetailID = {$id} AND Other_PapSmearIsActive = 'Y' + GROUP BY Other_PapSmearDetailsID + ORDER BY Other_PapSmearDetailsCode ASC"; + //echo $sql; + $rows = $this->db_smartone->query($sql)->result_array(); + if (!$rows) { + $rows = array( + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'A', + 'label' => 'Makroskopik', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ), + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'B', + 'label' => 'Mikroskopik', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ), + array( + 'xid' => '0', + 'header_id' => '0', + 'orderdetail_id' => $id, + 'code' => 'C', + 'label' => 'Kesimpulan', + 'result' => '', + 'doctor_id' => '0', + 'doctor_name' => '' + ) + ); + } + + $header_id = $rows[0]['header_id']; + $sql = "SELECT Other_PapSmearMaturasiID as xid, + Other_PapSmearMaturasiValue as value + FROM other_papsmearmaturasi + WHERE + Other_PapSmearMaturasiOther_PapSmearID = {$header_id} AND + Other_PapSmearMaturasiIsActive = 'Y' + "; + //echo $sql; + $dt_maturasi = $this->db_smartone->query($sql)->row_array(); + if (!$dt_maturasi) { + $maturasi = array('xid' => '0', 'value' => array('', '', '')); + } else { + $value = explode('/', $dt_maturasi['value']); + $maturasi = array('xid' => $dt_maturasi['xid'], 'value' => $value); + } + + $sql = "SELECT IFNULL(Other_PapSmearBahanID,0) as xid, + M_PapSmearBahanID as bahan_id, + M_PapSmearBahanName as name, + IF(ISNULL(Other_PapSmearBahanID),'N','Y') as selected + FROM m_papsmearbahan + LEFT JOIN other_papsmearbahan ON Other_PapSmearBahanM_PapSmearBahanID = M_PapSmearBahanID AND + Other_PapSmearBahanOther_PapSmearID = {$header_id} AND + Other_PapSmearBahanIsActive = 'Y' + WHERE + M_PapSmearBahanIsActive = 'Y' + ORDER BY M_PapSmearBahanID ASC + "; + //echo $sql; + $bahans = $this->db_smartone->query($sql)->result_array(); + + $sql = "SELECT IFNULL(Other_PapsmearCategoryID,0) as xid, + M_PapSmearCategoryID as category_id, + M_PapSmearCategoryName as name, + IF(ISNULL(Other_PapsmearCategoryID),'N','Y') as selected + FROM m_papsmearcategory + LEFT JOIN other_papsmearcategory ON Other_PapsmearCategoryM_PapSmearCategoryID = M_PapSmearCategoryID AND + Other_PapsmearCategoryOther_PapSmearID = {$header_id} AND + Other_PapsmearCategoryIsActive = 'Y' + WHERE + M_PapSmearCategoryIsActive = 'Y' + ORDER BY M_PapSmearCategoryID ASC + "; + //echo $sql; + $categories = $this->db_smartone->query($sql)->result_array(); + + $sql = "SELECT IFNULL(Other_PapSmearCheckID,0) as xid, + M_PapSmearCheckID as check_id, + M_PapSmearCheckLabel as name, + IF(ISNULL(Other_PapSmearCheckID),'N','Y') as selected, + Other_PapSmearCheckNote as note + FROM m_papsmearcheck + LEFT JOIN other_papsmearcheck ON Other_PapSmearCheckM_PapSmearCheckID = M_PapSmearCheckID AND + Other_PapSmearCheckOther_PapSmearID = {$header_id} AND + Other_PapSmearCheckIsActive = 'Y' + WHERE + M_PapSmearCheckIsActive = 'Y' + ORDER BY M_PapSmearCheckCode ASC + "; + $checks = $this->db_smartone->query($sql)->result_array(); + + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 9 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $rst = array('doctors' => $doctors, 'checks' => $checks, 'bahans' => $bahans, 'categories' => $categories, 'maturasi' => $maturasi, 'results' => $rows); + $this->sys_ok(["records" => $rst]); + } + + function saveresult_lcprep() + { + $prm = $this->sys_input; + $detail_id = $prm['detail_id']; + $doctor_id = $prm['doctor']; + $adekuasi = $prm['adekuasi']; + $kategoriumum = $prm['kategoriumum']; + $interpretasi = $prm['interpretasi']; + $results = $prm['results']; + + $userid = $this->sys_user['M_UserID']; + + $header_id = 0; + $sql = "SELECT * FROM other_lcprep WHERE Other_LcprepT_orderDetailID = {$detail_id} AND Other_LcprepIsActive = 'Y'"; + $dt_header = $this->db_smartone->query($sql)->row_array(); + if ($dt_header) { + $header_id = $dt_header['Other_LcprepID']; + } + if ($header_id == 0) { + $sql = "INSERT INTO other_lcprep( + Other_LcprepT_orderDetailID, + Other_LcprepM_DoctorID, + Other_LcprepUserID, + Other_LcprepCreated + ) + VALUES( + {$detail_id}, + {$doctor_id}, + {$userid}, + NOW() + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } else { + $sql = "UPDATE other_lcprep SET Other_LcprepM_DoctorID = {$doctor_id}, Other_LcprepUserID = {$userid} WHERE Other_LcprepID = {$header_id}"; + $this->db_smartone->query($sql); + } + + if ($adekuasi) { + foreach ($adekuasi as $k => $v) { + $selected = $v['chex'] ? 'Y' : 'N'; + if (intval($v['xid'] == 0)) { + $sql = "UPDATE other_lcprepadekuasi SET Other_LcprepAdekuasiIsActive = 'N' + WHERE + Other_LcprepAdekuasiOther_LcprepID = {$header_id} AND + Other_LcprepAdekuasiIsActive = 'Y' AND + Other_LcprepAdekuasiLcprep_AdekuasiID = {$v['id']}"; + $this->db_smartone->query($sql); + $sql = "INSERT INTO other_lcprepadekuasi ( + Other_LcprepAdekuasiOther_LcprepID, + Other_LcprepAdekuasiLcprep_AdekuasiID, + Other_LcprepAdekuasiChex, + Other_LcprepAdekuasiUserID, + Other_LcprepAdekuasiCreated + ) + VALUES( + {$header_id}, + {$v['id']}, + '{$selected}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + //echo $sql; + } + if (intval($v['xid'] != 0)) { + + $sql = "UPDATE other_lcprepadekuasi SET + Other_LcprepAdekuasiChex = '{$selected}', + Other_LcprepAdekuasiUserID = {$userid} + WHERE + Other_LcprepAdekuasiID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + + //echo $sql; + } + } + + if ($kategoriumum) { + foreach ($kategoriumum as $k => $v) { + $selected = $v['chex'] ? 'Y' : 'N'; + if (intval($v['xid'] == 0)) { + $sql = "UPDATE other_lcprepkategoriumum SET Other_LcprepKategoriUmumIsActive = 'N' + WHERE + Other_LcprepKategoriUmumOther_LcprepID = {$header_id} AND + Other_LcprepKategoriUmumLcprep_KategoriUmumID = {$v['id']} AND + Other_LcprepKategoriUmumIsActive = 'Y' + "; + $this->db_smartone->query($sql); + $sql = "INSERT INTO other_lcprepkategoriumum ( + Other_LcprepKategoriUmumOther_LcprepID, + Other_LcprepKategoriUmumLcprep_KategoriUmumID, + Other_LcprepKategoriUmumChex, + Other_LcprepKategoriUmumUserID, + Other_LcprepKategoriUmumCreated + ) + VALUES( + {$header_id}, + {$v['id']}, + '{$selected}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if (intval($v['xid'] != 0)) { + $sql = "UPDATE other_lcprepkategoriumum SET + Other_LcprepKategoriUmumChex = '{$selected}', + Other_LcprepKategoriUmumUserID = {$userid} + WHERE + Other_LcprepKategoriUmumID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + + //echo $sql; + } + } + + if ($results) { + foreach ($results as $k => $v) { + if (intval($v['xid'] == 0)) { + $sql = "UPDATE other_lcprepdetails SET Other_LcprepDetailsIsActive = 'N' + WHERE + Other_LcprepDetailsOther_LcprepID = {$header_id} AND + Other_LcprepDetailsCode = '{$v['code']}' AND + Other_LcprepDetailsIsActive = 'Y'"; + $this->db_smartone->query($sql); + $sql = "INSERT INTO other_lcprepdetails ( + Other_LcprepDetailsOther_LcprepID, + Other_LcprepDetailsCode, + Other_LcprepDetailsLabel, + Other_LcprepDetailsResult, + Other_LcprepDetailsUserID, + Other_LcprepDetailsCreated + ) + VALUES( + {$header_id}, + '{$v['code']}', + '{$v['label']}', + '{$v['result']}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if (intval($v['xid'] != 0)) { + $sql = "UPDATE other_lcprepdetails SET + Other_LcprepDetailsCode = '{$v['code']}', + Other_LcprepDetailsLabel = '{$v['label']}', + Other_LcprepDetailsResult = '{$v['result']}', + Other_LcprepDetailsUserID = {$userid} + WHERE + Other_LcprepDetailsID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + //echo $sql; + } + } + + if ($interpretasi) { + foreach ($interpretasi as $k => $v) { + if (count($v['subgroups']) > 0) { + foreach ($v['subgroups'] as $ik => $iv) { + if (count($iv['childs']) > 0) { + foreach ($iv['childs'] as $iik => $iiv) { + if (intval($iiv['xid'] == 0)) { + $chex = $iiv['chex'] ? 'Y' : 'N'; + $sql = "UPDATE other_lcprepinterpretasi SET Other_LcprepInterpretasiIsActive = 'N' + WHERE + Other_LcprepInterpretasiOther_LcprepID = {$header_id} AND + Other_LcprepInterpretasiLcprep_InterpretasiID = '{$iiv['id']}' AND + Other_LcprepInterpretasiIsActive = 'Y'"; + $this->db_smartone->query($sql); + $sql = "INSERT INTO other_lcprepinterpretasi ( + Other_LcprepInterpretasiOther_LcprepID, + Other_LcprepInterpretasiLcprep_InterpretasiID, + Other_LcprepInterpretasiChex, + Other_LcprepInterpretasiValue, + Other_LcprepInterpretasiUserID, + Other_LcprepInterpretasiCreated + ) + VALUES( + {$header_id}, + '{$iiv['id']}', + '{$chex}', + '{$iiv['value']}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + + if (intval($iiv['xid'] != 0)) { + $chex = $iiv['chex'] ? 'Y' : 'N'; + $sql = "UPDATE other_lcprepinterpretasi SET + Other_LcprepInterpretasiChex = '{$chex}', + Other_LcprepInterpretasiValue = '{$iiv['value']}', + Other_LcprepInterpretasiUserID = {$userid} + WHERE + Other_LcprepInterpretasiID = {$iiv['xid']}"; + $this->db_smartone->query($sql); + //echo $sql; + + } + } + } + } + } + //echo $sql; + } + } + + + $result = array("total" => 1, "records" => array(), "sql" => ''); + $this->sys_ok($result); + exit; + } + + function saveresult_papsmear() + { + $prm = $this->sys_input; + $detail_id = $prm['detail_id']; + $doctor_id = $prm['doctor']; + $checks = $prm['checks']; + $maturasi = $prm['maturasi']; + $bahans = $prm['bahans']; + $categories = $prm['categories']; + $results = $prm['results']; + + $userid = $this->sys_user['M_UserID']; + + $header_id = 0; + $sql = "SELECT * FROM other_papsmear WHERE Other_PapSmearT_OrderDetailID = {$detail_id} AND Other_PapSmearIsActive = 'Y'"; + $dt_header = $this->db_smartone->query($sql)->row_array(); + if ($dt_header) { + $header_id = $dt_header['Other_PapSmearID']; + } + if ($header_id == 0) { + $sql = "INSERT INTO other_papsmear( + Other_PapSmearT_OrderDetailID, + Other_PapSmearM_DoctorID, + Other_PapSmearUserID, + Other_PapSmearCreated + ) + VALUES( + {$detail_id}, + {$doctor_id}, + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } else { + $sql = "UPDATE other_papsmear SET Other_PapSmearM_DoctorID = {$doctor_id}, Other_PapSmearUserID = {$userid} WHERE Other_PapSmearID = {$header_id}"; + $this->db_smartone->query($sql); + } + + if ($checks) { + foreach ($checks as $k => $v) { + if (intval($v['xid']) == 0 && $v['selected'] === 'Y') { + $sql = "INSERT INTO other_papsmearcheck ( + Other_PapSmearCheckOther_PapSmearID, + Other_PapSmearCheckM_PapSmearCheckID, + Other_PapSmearCheckNote, + Other_PapSmearCheckUserID, + Other_PapSmearCheckCreated + ) + VALUES( + {$header_id}, + {$v['check_id']}, + '{$v['note']}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if (intval($v['xid']) != 0 && $v['selected'] === 'N') { + $sql = "UPDATE other_papsmearcheck SET + Other_PapSmearCheckIsActive = 'N', + Other_PapSmearCheckUserID = {$userid} + WHERE + Other_PapSmearCheckID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + if (intval($v['xid']) != 0 && $v['selected'] === 'Y') { + $sql = "UPDATE other_papsmearcheck SET + Other_PapSmearCheckNote = '{$v['note']}', + Other_PapSmearCheckUserID = {$userid} + WHERE + Other_PapSmearCheckID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + //echo $sql; + } + } + + if ($maturasi) { + if (intval($maturasi['xid']) == 0) { + $value = join("/", $maturasi['value']); + $sql = "INSERT INTO other_papsmearmaturasi ( + Other_PapSmearMaturasiOther_PapSmearID, + Other_PapSmearMaturasiValue, + Other_PapSmearMaturasiUserID, + Other_PapSmearMaturasiCreated + ) + VALUE( + {$header_id}, + '{$value}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + //echo $sql; + } + if (intval($maturasi['xid']) != 0) { + $value = join("/", $maturasi['value']); + $sql = "UPDATE other_papsmearmaturasi SET + Other_PapSmearMaturasiValue = '{$value}', + Other_PapSmearMaturasiUserID = {$userid} + WHERE + Other_PapSmearMaturasiID = {$maturasi['xid']}"; + // echo $sql; + $this->db_smartone->query($sql); + } + } + + if ($bahans) { + foreach ($bahans as $k => $v) { + if (intval($v['xid']) == 0 && $v['selected'] === 'Y') { + $sql = "INSERT INTO other_papsmearbahan ( + Other_PapSmearBahanOther_PapSmearID, + Other_PapSmearBahanM_PapSmearBahanID, + Other_PapSmearBahanUserID, + Other_PapSmearBahanCreated + ) + VALUES( + {$header_id}, + {$v['bahan_id']}, + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if (intval($v['xid']) != 0 && $v['selected'] === 'N') { + $sql = "UPDATE other_papsmearbahan SET + Other_PapSmearBahanIsActive = 'N', + Other_PapsmearCategoryUserID = {$userid} + WHERE + Other_PapSmearBahanID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + if (intval($v['xid']) != 0 && $v['selected'] === 'Y') { + $sql = "UPDATE other_papsmearbahan SET + Other_PapSmearBahanIsActive = 'Y', + Other_PapsmearCategoryUserID = {$userid} + WHERE + Other_PapSmearBahanID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + //echo $sql; + } + } + + if ($categories) { + foreach ($categories as $k => $v) { + if (intval($v['xid']) == 0 && $v['selected'] === 'Y') { + $sql = "INSERT INTO other_papsmearcategory ( + Other_PapsmearCategoryOther_PapSmearID, + Other_PapsmearCategoryM_PapSmearCategoryID, + Other_PapsmearCategoryUserID, + Other_PapsmearCategoryCreated + ) + VALUES( + {$header_id}, + {$v['category_id']}, + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if (intval($v['xid']) != 0 && $v['selected'] === 'N') { + $sql = "UPDATE other_papsmearcategory SET + Other_PapsmearCategoryIsActive = 'N', + Other_PapsmearCategoryUserID = {$userid} + WHERE + Other_PapsmearCategoryID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + //echo $sql; + if (intval($v['xid']) != 0 && $v['selected'] === 'Y') { + $sql = "UPDATE other_papsmearcategory SET + Other_PapsmearCategoryIsActive = 'Y', + Other_PapsmearCategoryUserID = {$userid} + WHERE + Other_PapsmearCategoryID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + } + } + + if ($results) { + foreach ($results as $k => $v) { + if (intval($v['xid']) == 0) { + $sql = "INSERT INTO other_papsmeardetails ( + Other_PapSmearDetailsOther_PapSmearID, + Other_PapSmearDetailsCode, + Other_PapSmearDetailsLabel, + Other_PapSmearDetailsResult, + Other_PapSmearDetailsUserID, + Other_PapSmearDetailsCreated + ) + VALUES( + {$header_id}, + '{$v['code']}', + '{$v['label']}', + '{$v['result']}', + {$userid}, + NOW() + )"; + $this->db_smartone->query($sql); + } + if (intval($v['xid']) != 0) { + $sql = "UPDATE other_papsmeardetails SET + Other_PapSmearDetailsCode = '{$v['code']}', + Other_PapSmearDetailsLabel = '{$v['label']}', + Other_PapSmearDetailsResult = '{$v['result']}', + Other_PapSmearDetailsUserID = {$userid} + WHERE + Other_PapSmearDetailsID = {$v['xid']}"; + $this->db_smartone->query($sql); + } + //echo $sql; + } + } + + $result = array("total" => 1, "records" => array(), "sql" => ''); + $this->sys_ok($result); + exit; + } + + function saveresult_fna() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = $inp['doctor']; + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + if ($prm[0]['xid'] == '0') { + $sql = "INSERT INTO other_fna( + Other_FNAM_DoctorID, + Other_FNAT_OrderDetailID, + Other_FNAUserID, + Other_FNACreated + ) + VALUES( + {$doctor_id}, + {$prm[0]['orderdetail_id']}, + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } else { + $sql = "SELECT * FROM other_fna WHERE Other_FNAT_OrderDetailID = {$prm[0]['orderdetail_id']} AND Other_FNAIsActive = 'Y'"; + $data_header = $this->db_smartone->query($sql)->row_array(); + $header_id = $data_header['Other_FNAID']; + $sql = "UPDATE other_fna SET + Other_FNAM_DoctorID = {$doctor_id}, + Other_FNAUserID = {$userid} + WHERE + Other_FNAID = {$header_id}"; + $this->db_smartone->query($sql); + } + foreach ($prm as $k => $v) { + if ($v['xid'] == '0') { + $results = str_replace("'", "\\'", $v['result']); + $sql = "INSERT INTO other_fnadetails( + Other_FNADetailsOther_FNAID , + Other_FNADetailsCode, + Other_FNADetailsLabel, + Other_FNADetailsResult, + Other_FNADetailsCreated, + Other_FNADetailsUserID + ) + VALUES( + {$header_id}, + '{$v['code']}', + '{$v['label']}', + '{$results}', + NOW(), + {$userid} + )"; + $query = $this->db_smartone->query($sql); + } else { + $results = str_replace("'", "\\'", $v['result']); + $sql = "UPDATE other_fnadetails SET + Other_FNADetailsResult = '{$results}', + Other_FNADetailsUserID = {$userid} + WHERE + Other_FNADetailsID = {$v['xid']}"; + $query = $this->db_smartone->query($sql); + } + } + + $result = array("total" => 1, "records" => array(), "sql" => ''); + $this->sys_ok($result); + exit; + } + + function saveresult_cytologi() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = $inp['doctor']; + + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + if ($prm[0]['xid'] == '0') { + $sql = "INSERT INTO other_cytologi( + Other_CytologiT_OrderDetailID, + Other_CytologiM_DoctorID, + Other_CytologiUserID, + Other_CytologiCreated + ) + VALUES( + {$prm[0]['orderdetail_id']}, + {$doctor_id}, + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } else { + $sql = "SELECT * FROM other_cytologi WHERE Other_CytologiT_OrderDetailID = {$prm[0]['orderdetail_id']} AND Other_CytologiIsActive = 'Y'"; + $data_header = $this->db_smartone->query($sql)->row_array(); + $header_id = $data_header['Other_CytologiID']; + $sql = "UPDATE other_cytologi SET + Other_CytologiM_DoctorID = {$doctor_id}, + Other_CytologiUserID = {$userid} + WHERE + Other_CytologiID = {$header_id}"; + $this->db_smartone->query($sql); + } + foreach ($prm as $k => $v) { + if ($v['xid'] == '0') { + $results = str_replace("'", "\\'", $v['result']); + $sql = "INSERT INTO other_cytologidetails( + Other_CytologiDetailsOther_CytologiID , + Other_CytologiDetailsCode, + Other_CytologiDetailsLabel, + Other_CytologiDetailsResult, + Other_CytologiDetailsCreated, + Other_CytologiDetailsUserID + ) + VALUES( + {$header_id}, + '{$v['code']}', + '{$v['label']}', + '{$results}', + NOW(), + {$userid} + )"; + $query = $this->db_smartone->query($sql); + } else { + $results = str_replace("'", "\\'", $v['result']); + $sql = "UPDATE other_cytologidetails SET + Other_CytologiDetailsResult = '{$results}', + Other_CytologiDetailsUserID = {$userid} + WHERE + Other_CytologiDetailsID = {$v['xid']}"; + $query = $this->db_smartone->query($sql); + } + } + + $result = array("total" => 1, "records" => array(), "sql" => ''); + $this->sys_ok($result); + exit; + } + + function saveresult_mikro() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = $inp['doctor']; + $backteria_id = $inp['bacteria']; + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + + if ($inp['result_value'] != 'Negatif' && $inp['result_value'] != 'Positif') { + $prm['result_value'] = $prm['result_other']; + } else { + $prm['result_value'] = $inp['result_value']; + } + + if ($prm['xid'] == '0') { + $sql = "INSERT INTO other_mikro( + Other_MikroM_DoctorID, + Other_MikroResult, + Other_MikroT_BacteriaID, + Other_MikroT_OrderDetailID, + Other_MikroHasilBiakan, + Other_MikroSampleTypeName, + Other_MikroUserID, + Other_MikroCreated + ) + VALUES( + {$doctor_id}, + '{$prm['result_value']}', + {$backteria_id}, + {$prm['orderdetail_id']}, + '{$prm['hasil_biakan']}', + '{$prm['sample_name']}', + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } else { + $sql = "SELECT * FROM other_mikro WHERE Other_MikroT_OrderDetailID = {$prm['orderdetail_id']} AND Other_MikroIsActive = 'Y'"; + $data_header = $this->db_smartone->query($sql)->row_array(); + $header_id = $data_header['Other_MikroID']; + $sql = "UPDATE other_mikro SET + Other_MikroResult = '{$prm['result_value']}', + Other_MikroM_DoctorID = {$doctor_id}, + Other_MikroT_BacteriaID = {$backteria_id}, + Other_MikroHasilBiakan = '{$prm['hasil_biakan']}', + Other_MikroSampleTypeName = '{$prm['sample_name']}', + Other_MikroUserID = {$userid} + WHERE + Other_MikroID = {$header_id}"; + //echo $sql; + $this->db_smartone->query($sql); + } + + + + $sql = "UPDATE other_mikrodetails SET Other_MikroDetailsIsActive = 'N', Other_MikroDetailsUserID = 0 WHERE Other_MikroDetailsOther_MikroID = {$header_id}"; + $this->db_smartone->query($sql); + + $results = $prm['details']; + if ($inp['result_value'] == 'Positif') { + foreach ($results as $k => $v) { + if ($v['xid'] == '0') { + $sql = "INSERT INTO other_mikrodetails( + Other_MikroDetailsOther_MikroID , + Other_MikroDetailsT_AntibioticID, + Other_MikroDetailsValue, + Other_MikroDetailsNote, + Other_MikroDetailsCreated, + Other_MikroDetailsUserID + ) + VALUES( + {$header_id}, + '{$v['T_AntibioticID']}', + '{$v['value']}', + '{$v['note']}', + NOW(), + {$userid} + )"; + $query = $this->db_smartone->query($sql); + } else { + $sql = "UPDATE other_mikrodetails SET + Other_MikroDetailsT_AntibioticID = '{$v['T_AntibioticID']}', + Other_MikroDetailsValue = '{$v['value']}', + Other_MikroDetailsNote = '{$v['note']}', + Other_MikroDetailsIsActive = 'Y', + Other_MikroDetailsUserID = {$userid} + WHERE + Other_MikroDetailsID = {$v['xid']}"; + //echo $sql; + $query = $this->db_smartone->query($sql); + } + } + } + + + $result = array("total" => 1, "records" => array(), "sql" => ''); + $this->sys_ok($result); + exit; + } + + + function get_doctors_preparasi_sperma() + { + $prm = $this->sys_input; + // $id = $prm["id"]; + + $sql = " SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 10 AND + M_DoctorSOIsActive = 'Y' + ORDER BY M_DoctorName ASC"; + //echo $sql; + $query = $this->db_smartone->query($sql); + $rows = $query->result_array(); + $sql = " + SELECT '0' as id, 'Belum memilih metode' as name + UNION + SELECT M_MethodeSpermaID as id, M_MethodeSpermaName as name + FROM m_methodesperma + WHERE + M_MethodeSpermaIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $methodes = $this->db_smartone->query($sql)->result_array(); + + + $this->sys_ok(["records" => $rows, "methodes" => $methodes]); + } + + + function getpreparasispermaresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT other_preparasisperma.*, + Other_PreparasiSpermaID as xid, + Other_PreparasiSpermaT_OrderDetailID as orderdetail_id, + IFNULL(Other_PreparasiSpermaM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_PreparasiSpermaM_DoctorID) OR Other_PreparasiSpermaM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name, + IFNULL(M_MethodeSpermaID,0) as methode_id, + IFNULL(M_MethodeSpermaName,'') as methode_name + FROM other_preparasisperma + LEFT JOIN m_doctor ON Other_PreparasiSpermaM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + LEFT JOIN m_methodesperma ON Other_PreparasiSpermaM_MethodeSpermaID = M_MethodeSpermaID AND + M_MethodeSpermaIsActive = 'Y' + WHERE + Other_PreparasiSpermaT_OrderDetailID = {$id} AND Other_PreparasiSpermaIsActive = 'Y' + GROUP BY Other_PreparasiSpermaID"; + $query = $this->db_smartone->query($sql); + + if ($query) { + $rows = $query->row_array(); + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND + M_DoctorIsActive = 'Y' + WHERE + M_DoctorSONat_SubGroupID = 10 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + $sql = " + SELECT '0' as id, 'Belum memilih metode' as name + UNION + SELECT M_MethodeSpermaID as id, M_MethodeSpermaName as name + FROM m_methodesperma + WHERE + M_MethodeSpermaIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $methodes = $this->db_smartone->query($sql)->result_array(); + $images = array(); + $sql = "SELECT Other_PreparasiSpermaImgID as xid, + Other_PreparasiSpermaImgType as type, + CONCAT('/one-media/one-image-nonlab/',Other_PreparasiSpermaImgNewName) as image_url + FROM t_orderdetail + JOIN other_preparasisperma_img ON Other_PreparasiSpermaImgT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND + Other_PreparasiSpermaImgIsActive = 'Y' + WHERE + T_OrderDetailID = {$id} AND + T_OrderDetailIsActive = 'Y' + GROUP BY Other_PreparasiSpermaImgID"; + //echo $sql; + $images = $this->db_smartone->query($sql)->result_array(); + + $rst = array('doctors' => $doctors, 'methodes' => $methodes, 'results' => $rows, 'images' => $images); + $this->sys_ok(["records" => $rst]); + } else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + + function uploadimage_preparasi_sperma() + { + if (! $this->isLogin) { + $this->sys_error("Invalid Token"); + exit; + } + + $userid = $this->sys_user["M_UserID"]; + $data = []; + //print_r($_SERVER); + + $prm = $this->sys_input; + $orderid = $this->input->post('orderid'); + $type = $this->input->post('type'); + $labnumber = $this->input->post('labnumber'); + $sql = "UPDATE other_preparasisperma_img SET + Other_PreparasiSpermaImgIsActive = 'N', + Other_PreparasiSpermaImgUserID = {$userid} + WHERE + Other_PreparasiSpermaImgT_OrderHeaderID = {$orderid} AND + Other_PreparasiSpermaImgType = '{$type}'"; + //echo $sql; + $this->db_onedev->query($sql); + //$config['upload_path'] = 'assets/'; + + $path = '/home/one/project/one/one-media/one-image-nonlab/'; + //echo $path; + $config['upload_path'] = $path; + $config['allowed_types'] = 'jpg|jpeg|png|gif'; + + $config['max_size'] = '10000'; + $count = count($_FILES['files']['name']); + //echo $count; + $this->load->library('upload', $config); + + $error = []; + for ($i = 0; $i < $count; $i++) { + + + if (!empty($_FILES['files']['name'][$i])) { + + + + $_FILES['file']['name'] = $_FILES['files']['name'][$i]; + + $_FILES['file']['type'] = $_FILES['files']['type'][$i]; + + $_FILES['file']['tmp_name'] = $_FILES['files']['tmp_name'][$i]; + + $_FILES['file']['error'] = $_FILES['files']['error'][$i]; + + $_FILES['file']['size'] = $_FILES['files']['size'][$i]; + + + + $namex = $orderid . '-' . $labnumber . '-' . $this->generateRandomString(5); + //echo $namex; + + $config['file_name'] = $namex; + $this->upload->initialize($config); + //echo $config['file_name'] ; + + + + + + if ($this->upload->do_upload('file')) { + + $uploadData = $this->upload->data(); + + $filename = $uploadData['file_name']; + //echo $filename; + + + $sql = "INSERT INTO other_preparasisperma_img ( + Other_PreparasiSpermaImgT_OrderHeaderID, + Other_PreparasiSpermaImgType, + Other_PreparasiSpermaImgOldName, + Other_PreparasiSpermaImgNewName, + Other_PreparasiSpermaImgCreated, + Other_PreparasiSpermaImgUserID + ) + VALUES( + {$orderid}, + '{$type}', + '{$_FILES['files']['name'][$i]}', + '{$filename}', + NOW(), + {$userid} + + )"; + //echo $sql; + $this->db_onedev->query($sql); + $xlast_id = $this->db_onedev->insert_id(); + $data['totalFiles'][] = array('xid' => $xlast_id, 'type' => $type, 'image_url' => '/one-media/one-image-nonlab/' . $filename); + } else { + $error = array('error' => $this->upload->display_errors()); + } + } + } + + $result = array("total" => count($data['totalFiles']), "records" => $data['totalFiles'], 'errors' => $error); + $this->sys_ok($result); + } + + + function saveresult_preparasi_sperma() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = $inp['doctor']; + $orderdetail_id = $inp['orderdetailid']; + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + if ($prm['xid'] == '0') { + $sql = "INSERT INTO other_preparasisperma( + Other_PreparasiSpermaM_DoctorID, + Other_PreparasiSpermaT_OrderDetailID, + Other_PreparasiSpermaPreMotilitasA, + Other_PreparasiSpermaPreMotilitasB, + Other_PreparasiSpermaPreMotilitasC, + Other_PreparasiSpermaPreKonsentrasi, + Other_PreparasiSpermaPreKontaminan, + Other_PreparasiSpermaPostMotilitasA, + Other_PreparasiSpermaPostMotilitasB, + Other_PreparasiSpermaPostMotilitasC, + Other_PreparasiSpermaPostKonsentrasi, + Other_PreparasiSpermaPostKontaminan, + Other_PreparasiSpermaPreVolume, + Other_PreparasiSpermaPostVolume, + Other_PreparasiSpermaM_MethodeSpermaID, + Other_PreparasiSpermaNote, + Other_PreparasiSpermaUserID, + Other_PreparasiSpermaCreated + ) + VALUES( + {$doctor_id}, + {$orderdetail_id}, + '{$prm['Other_PreparasiSpermaPreMotilitasA']}', + '{$prm['Other_PreparasiSpermaPreMotilitasB']}', + '{$prm['Other_PreparasiSpermaPreMotilitasC']}', + '{$prm['Other_PreparasiSpermaPreKonsentrasi']}', + '{$prm['Other_PreparasiSpermaPreKontaminan']}', + '{$prm['Other_PreparasiSpermaPostMotilitasA']}', + '{$prm['Other_PreparasiSpermaPostMotilitasB']}', + '{$prm['Other_PreparasiSpermaPostMotilitasC']}', + '{$prm['Other_PreparasiSpermaPostKonsentrasi']}', + '{$prm['Other_PreparasiSpermaPostKontaminan']}', + '{$prm['Other_PreparasiSpermaPreVolume']}', + '{$prm['Other_PreparasiSpermaPostVolume']}', + '{$prm['Other_PreparasiSpermaM_MethodeSpermaID']}', + '{$prm['Other_PreparasiSpermaNote']}', + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } else { + $sql = "SELECT * FROM other_preparasisperma WHERE Other_PreparasiSpermaT_OrderDetailID = {$orderdetail_id} AND Other_PreparasiSpermaIsActive = 'Y'"; + $data_header = $this->db_smartone->query($sql)->row_array(); + $header_id = $data_header['Other_PreparasiSpermaID']; + $sql = "UPDATE other_preparasisperma SET + Other_PreparasiSpermaM_DoctorID = {$doctor_id}, + Other_PreparasiSpermaPreMotilitasA = '{$prm['Other_PreparasiSpermaPreMotilitasA']}', + Other_PreparasiSpermaPreMotilitasB = '{$prm['Other_PreparasiSpermaPreMotilitasB']}', + Other_PreparasiSpermaPreMotilitasC = '{$prm['Other_PreparasiSpermaPreMotilitasC']}', + Other_PreparasiSpermaPreKonsentrasi = '{$prm['Other_PreparasiSpermaPreKonsentrasi']}', + Other_PreparasiSpermaPreKontaminan = '{$prm['Other_PreparasiSpermaPreKontaminan']}', + Other_PreparasiSpermaPostMotilitasA = '{$prm['Other_PreparasiSpermaPostMotilitasA']}', + Other_PreparasiSpermaPostMotilitasB = '{$prm['Other_PreparasiSpermaPostMotilitasB']}', + Other_PreparasiSpermaPostMotilitasC = '{$prm['Other_PreparasiSpermaPostMotilitasC']}', + Other_PreparasiSpermaPostKonsentrasi = '{$prm['Other_PreparasiSpermaPostKonsentrasi']}', + Other_PreparasiSpermaPostKontaminan = '{$prm['Other_PreparasiSpermaPostKontaminan']}', + Other_PreparasiSpermaPreVolume = '{$prm['Other_PreparasiSpermaPreVolume']}', + Other_PreparasiSpermaPostVolume = '{$prm['Other_PreparasiSpermaPostVolume']}', + Other_PreparasiSpermaM_MethodeSpermaID = '{$prm['Other_PreparasiSpermaM_MethodeSpermaID']}', + Other_PreparasiSpermaNote = '{$prm['Other_PreparasiSpermaNote']}', + Other_PreparasiSpermaUserID = {$userid} + WHERE + Other_PreparasiSpermaID = {$header_id}"; + $this->db_smartone->query($sql); + } + + + $result = array("total" => 1, "records" => array(), "sql" => ''); + $this->sys_ok($result); + exit; + } + + function getdnafragmentasiresult() + { + $prm = $this->sys_input; + $id = $prm["id"]; + + $sql = " SELECT other_dnafragmentasi.*, + Other_DnaFragmentasiID as xid, + Other_DnaFragmentasiT_OrderDetailID as orderdetail_id, + IFNULL(Other_DnaFragmentasiM_DoctorID,0) as doctor_id, + IF(ISNULL(Other_DnaFragmentasiM_DoctorID) OR Other_DnaFragmentasiM_DoctorID = 0 ,'0', CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_name, + IFNULL(Other_DnaFragmentasiOther_DnaFragmentasiMethodeID,0) as methode_id, + IFNULL(Other_DnaFragmentasiMethodeName,'') as methode_name, + Other_DnaFragmentasiHaloLuas as halo_luas, + Other_DnaFragmentasiHaloSedang as halo_sedang, + Other_DnaFragmentasiHaloSempit as halo_sempit, + Other_DnaFragmentasiTanpaHalo as tanpa_halo, + Other_DnaFragmentasiDFI as dfi, + Other_DnaFragmentasiKesimpulan as kesimpulan, + Other_DnaFragmentasiCatatan as catatan + FROM other_dnafragmentasi + LEFT JOIN m_doctor ON Other_DnaFragmentasiM_DoctorID = M_DoctorID + LEFT JOIN other_dnafragmentasimethode ON Other_DnaFragmentasiOther_DnaFragmentasiMethodeID = Other_DnaFragmentasiMethodeID + WHERE + Other_DnaFragmentasiT_OrderDetailID = {$id} AND Other_DnaFragmentasiIsActive = 'Y' + GROUP BY Other_DnaFragmentasiID + LIMIT 1"; + //echo $sql; + $query = $this->db_smartone->query($sql); + + if ($query) { + $rows = $query->row_array(); + if (!$rows) { + $rows = array( + 'xid' => 0, + 'orderdetail_id' => $id, + 'doctor_id' => 0, + 'doctor_name' => '', + 'methode_id' => 0, + 'methode_name' => '', + 'halo_luas' => '', + 'halo_sedang' => '', + 'tanpa_halo' => '', + 'dfi' => '', + 'kesimpulan' => '', + 'catatan' => '' + ); + } + $sql = " + SELECT '0' as id, 'Belum memilih dokter' as name + UNION + SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name + FROM m_doctorso + JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID + WHERE + M_DoctorSONat_SubGroupID = 4 AND + M_DoctorSOIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $doctors = $this->db_smartone->query($sql)->result_array(); + + $sql = " + SELECT '0' as id, 'Belum memilih metode' as name + UNION + SELECT Other_DnaFragmentasiMethodeID as id, Other_DnaFragmentasiMethodeName as name + FROM other_dnafragmentasimethode + WHERE + Other_DnaFragmentasiMethodeIsActive = 'Y' + ORDER BY name ASC"; + //echo $sql; + $methodes = $this->db_smartone->query($sql)->result_array(); + + + $rst = array('doctors' => $doctors, 'methodes' => $methodes, 'results' => $rows); + $this->sys_ok(["records" => $rst]); + } else { + $this->sys_error_db("Rerun rows", $this->db_smartone); + exit; + } + } + + function saveresult_dnafragmentasi() + { + $inp = $this->sys_input; + $prm = $inp['results']; + $doctor_id = $inp['doctor']['id']; + $methode_id = $inp['methode']['id']; + $orderdetail_id = $inp['results']['orderdetail_id']; + $userid = $this->sys_user['M_UserID']; + $header_id = 0; + if (intval($prm['xid']) == 0) { + $sql = "INSERT INTO other_dnafragmentasi( + Other_DnaFragmentasiT_OrderDetailID, + Other_DnaFragmentasiM_DoctorID, + Other_DnaFragmentasiOther_DnaFragmentasiMethodeID, + Other_DnaFragmentasiHaloLuas, + Other_DnaFragmentasiHaloSedang, + Other_DnaFragmentasiHaloSempit, + Other_DnaFragmentasiTanpaHalo, + Other_DnaFragmentasiDFI, + Other_DnaFragmentasiKesimpulan, + Other_DnaFragmentasiCatatan, + Other_DnaFragmentasiUserID, + Other_DnaFragmentasiLastUpdated + ) + VALUES( + {$orderdetail_id}, + {$doctor_id}, + {$methode_id}, + '{$prm['halo_luas']}', + '{$prm['halo_sedang']}', + '{$prm['halo_sempit']}', + '{$prm['tanpa_halo']}', + '{$prm['dfi']}', + '{$prm['kesimpulan']}', + '{$prm['catatan']}', + {$userid}, + NOW() + + )"; + //echo $sql; + $this->db_smartone->query($sql); + $header_id = $this->db_smartone->insert_id(); + } else { + $sql = "UPDATE other_dnafragmentasi SET + Other_DnaFragmentasiT_OrderDetailID = {$orderdetail_id}, + Other_DnaFragmentasiM_DoctorID = {$doctor_id}, + Other_DnaFragmentasiOther_DnaFragmentasiMethodeID = '{$methode_id}', + Other_DnaFragmentasiHaloLuas = '{$prm['halo_luas']}', + Other_DnaFragmentasiHaloSedang = '{$prm['halo_sedang']}', + Other_DnaFragmentasiHaloSempit = '{$prm['halo_sempit']}', + Other_DnaFragmentasiTanpaHalo = '{$prm['tanpa_halo']}', + Other_DnaFragmentasiDFI = '{$prm['dfi']}', + Other_DnaFragmentasiKesimpulan = '{$prm['kesimpulan']}', + Other_DnaFragmentasiCatatan = '{$prm['catatan']}', + Other_DnaFragmentasiLastUpdated = NOW(), + Other_DnaFragmentasiUserID = {$userid} + WHERE + Other_DnaFragmentasiID = {$prm['xid']}"; + //echo $sql; + $this->db_smartone->query($sql); + } + + + $result = array("total" => 1, "records" => array(), "sql" => ''); + $this->sys_ok($result); + exit; + } +} diff --git a/application/libraries/Ibl_sampling_normal.php b/application/libraries/Ibl_sampling_normal.php new file mode 100644 index 00000000..c5abb4a2 --- /dev/null +++ b/application/libraries/Ibl_sampling_normal.php @@ -0,0 +1,546 @@ +db = $CI->load->database('onedev', true); + } + + // ------------------------------------------------------------------------- + // Public API + // ------------------------------------------------------------------------- + + /** + * Cari Nat_NormalValueID sesuai methode, test, sex, dan umur (dalam hari). + * Urutan prioritas: + * Type 1 — sex + age range + * Type 2 — age range saja + * Type 3 — sex saja + * Type 4 — fallback + */ + public function get_normal_value_id($methodeID, $natTestID, $sexID, $ageInDay) + { + $methodeID = intval($methodeID); + $natTestID = intval($natTestID); + $sexID = intval($sexID); + $ageInDay = intval($ageInDay); + + $min_days = $this->_age_sql('Nat_NormalValueMinAge'); + $max_days = $this->_age_sql('Nat_NormalValueMaxAge'); + + $age_filter = " + AND ( + (Nat_NormalValueMinAgeInclusive = 'Y' AND ($min_days) <= $ageInDay) + OR (Nat_NormalValueMinAgeInclusive = 'N' AND ($min_days) < $ageInDay) + ) + AND ( + (Nat_NormalValueMaxAgeInclusive = 'Y' AND ($max_days) >= $ageInDay) + OR (Nat_NormalValueMaxAgeInclusive = 'N' AND ($max_days) > $ageInDay) + )"; + + $base = "FROM nat_normalvalue + WHERE (Nat_NormalValueValidDate IS NULL OR Nat_NormalValueValidDate < NOW()) + AND Nat_NormalValueIsActive = 'Y' + AND Nat_NormalValueIsAbnormal = 'N' + AND Nat_NormalValueNat_MethodeID = $methodeID + AND Nat_NormalValueNat_TestID = $natTestID + AND Nat_NormalValueNat_FlagID = 1"; + + $id = $this->_query_one("SELECT Nat_NormalValueID $base + AND Nat_NormalValueNat_NormalValueTypeID = 1 + AND Nat_NormalValueNat_SexID = $sexID + $age_filter LIMIT 1"); + if ($id) return $id; + + $id = $this->_query_one("SELECT Nat_NormalValueID $base + AND Nat_NormalValueNat_NormalValueTypeID = 2 + $age_filter LIMIT 1"); + if ($id) return $id; + + $id = $this->_query_one("SELECT Nat_NormalValueID $base + AND Nat_NormalValueNat_NormalValueTypeID = 3 + AND Nat_NormalValueNat_SexID = $sexID + LIMIT 1"); + if ($id) return $id; + + $id = $this->_query_one("SELECT Nat_NormalValueID $base + AND Nat_NormalValueNat_NormalValueTypeID = 4 + LIMIT 1"); + if ($id) return $id; + + return 0; + } + + /** + * Pengganti sp_sampling_check_normal_setting. + * Mengembalikan array compat dengan call_multi_result_procedure(): + * ok, message, result_sets[0]=summary, [1]=checks, [2]=branches, [3]=candidates + */ + public function check_setting_by_order_detail($orderDetailID) + { + $orderDetailID = intval($orderDetailID); + $data = $this->_load_order_detail_data($orderDetailID); + if ($data === null) { + return [ + 'ok' => false, + 'message' => "T_OrderDetailID {$orderDetailID} tidak ditemukan atau tidak aktif", + 'result_sets' => [], + ]; + } + + list($sexID, $dobStr, $orderDate, $ageInDay, + $orderHeaderID, $patientID, $natTestID, + $row) = $data; + + $methods = $this->_resolve_method_sources($natTestID); + list($selID, $selName, $selSource) = $this->_pick_method($methods); + + $normalValueID = 0; + if ($selID > 0 && $natTestID > 0 && $sexID > 0 && $ageInDay !== null) { + $normalValueID = $this->get_normal_value_id($selID, $natTestID, $sexID, $ageInDay); + } + + $summary = [[ + 'T_OrderDetailID' => $orderDetailID, + 'T_OrderHeaderID' => $orderHeaderID, + 'M_PatientID' => $patientID, + 'M_PatientM_SexID' => $sexID ?: null, + 'M_PatientDOB' => $dobStr ?: null, + 'T_OrderHeaderDate' => $row['order_date'], + 'AgeInDay' => $ageInDay, + 'T_TestID' => intval($row['t_test_id']), + 'T_TestName' => $row['t_test_name'], + 'Nat_TestID' => $natTestID ?: null, + 'Nat_TestCode' => $row['nat_test_code'], + 'Nat_TestName' => $row['nat_test_name'], + 'T_OrderDetailNat_MethodeID'=> intval($row['order_detail_methode_id']), + 'MethodeIDFromPriority' => $methods['priority_id'] ?: null, + 'MethodeNameFromPriority' => $methods['priority_name'], + 'MethodeIDFromInstrument' => $methods['instrument_id'] ?: null, + 'MethodeNameFromInstrument' => $methods['instrument_name'], + 'MethodeIDFromNormalValue' => $methods['normalvalue_id'] ?: null, + 'MethodeNameFromNormalValue'=> $methods['normalvalue_name'], + 'SelectedMethodeID' => $selID, + 'SelectedMethodeName' => $selName, + 'SelectedMethodeSource' => $selSource, + 'FnSamplingGetNormalResult' => $normalValueID, + ]]; + + $nvCount = 0; + if ($natTestID > 0) { + $r = $this->db->query( + "SELECT COUNT(*) AS cnt FROM nat_normalvalue + WHERE Nat_NormalValueNat_TestID = ? + AND Nat_NormalValueNat_MethodeID = ? + AND Nat_NormalValueIsActive = 'Y' + AND Nat_NormalValueIsAbnormal = 'N'", + [$natTestID, $selID ?: 0] + )->row_array(); + $nvCount = intval($r['cnt'] ?? 0); + } + + $checks = [ + $this->_chk('ORDER_DETAIL_ACTIVE', true, (string) $orderDetailID, 't_orderdetail aktif harus ditemukan'), + $this->_chk('PATIENT_SEX', $sexID > 0, (string) ($sexID ?: 'NULL'), 'Dipakai pada type 1 dan type 3'), + $this->_chk('PATIENT_DOB', $dobStr !== '', ($dobStr ?: 'NULL'), 'DOB dipakai untuk hitung AgeInDay'), + $this->_chk('ORDER_DATE', !empty($row['order_date']), ($row['order_date'] ?: 'NULL'), 'Tanggal order dipakai untuk hitung AgeInDay'), + $this->_chk('AGE_IN_DAY', $ageInDay !== null, ($ageInDay !== null ? (string) $ageInDay : 'NULL'), 'Dipakai pada type 1 dan type 2'), + $this->_chk('NAT_TEST', $natTestID > 0, (string) ($natTestID ?: 'NULL'), 'Harus ada mapping T_TestNat_TestID'), + $this->_chk('METHOD_PRIORITY', $methods['priority_id'] > 0, (string) ($methods['priority_id'] ?: 'NULL'), 'Sumber metode prioritas pertama'), + $this->_chk('METHOD_INSTRUMENT', $methods['instrument_id'] > 0, (string) ($methods['instrument_id'] ?: 'NULL'), 'Fallback metode kedua'), + $this->_chk('METHOD_NORMALVALUE', $methods['normalvalue_id'] > 0, (string) ($methods['normalvalue_id'] ?: 'NULL'), 'Fallback metode ketiga'), + $this->_chk('SELECTED_METHOD', $selID > 0, (string) ($selID ?: 'NULL'), ($selSource ?: 'Tidak ada metode yang bisa dipakai')), + $this->_chk('NORMALVALUE_TEST_METHOD_ACTIVE', $nvCount > 0, (string) $nvCount, 'Jumlah nat_normalvalue aktif non-abnormal untuk test + metode terpilih'), + ['check_name' => 'FN_RESULT', 'check_status' => ($normalValueID > 0 ? 'OK' : 'NOT_FOUND'), 'check_value' => (string) $normalValueID, 'check_note' => 'Hasil akhir fn_sampling_get_normal'], + ]; + + $branches = $selID > 0 + ? $this->_query_branches($selID, $natTestID, $sexID, $ageInDay) + : [['branch_name' => 'NO_SELECTED_METHOD', 'matched_count' => 0, 'first_normalvalue_id' => null]]; + $candidates = $natTestID > 0 ? $this->_query_candidates($selID, $natTestID, $sexID, $ageInDay) : []; + + return [ + 'ok' => true, + 'message' => '', + 'result_sets' => [$summary, $checks, $branches, $candidates], + ]; + } + + /** + * Pengganti sp_sampling_fix_normal_by_orderdetail. + * Mengembalikan array compat dengan call_multi_result_procedure(): + * ok, message, result_sets[0]=result_row, [1]=order_detail_row + */ + public function fix_by_order_detail($orderDetailID) + { + $orderDetailID = intval($orderDetailID); + $data = $this->_load_order_detail_data($orderDetailID); + if ($data === null) { + $errRow = [[ + 'status' => 'ERR', + 'message' => "T_OrderDetailID {$orderDetailID} tidak ditemukan atau tidak aktif", + 'selected_methode_id' => null, + 'selected_methode_name'=> null, + 'selected_methode_source' => null, + 'nat_normalvalue_id' => null, + 'updated_rows' => 0, + ]]; + return ['ok' => true, 'message' => '', 'result_sets' => [$errRow, []]]; + } + + list($sexID, $dobStr, $orderDate, $ageInDay, + $orderHeaderID, $patientID, $natTestID, + $row) = $data; + + $methods = $this->_resolve_method_sources($natTestID); + list($selID, $selName, $selSource) = $this->_pick_method($methods); + + $normalValueID = 0; + if ($selID > 0 && $natTestID > 0 && $sexID > 0 && $ageInDay !== null) { + $normalValueID = $this->get_normal_value_id($selID, $natTestID, $sexID, $ageInDay); + } + + if ($normalValueID > 0) { + $this->db->query( + "UPDATE t_orderdetail od + JOIN nat_normalvalue nn ON nn.Nat_NormalValueID = ? + SET od.T_OrderDetailNat_NormalValueID = nn.Nat_NormalValueID, + od.T_OrderDetailNormalValueNote = nn.Nat_NormalValueNote, + od.T_OrderDetailNormalValueDescription = nn.Nat_NormalValueDescription, + od.T_OrderDetailMinValue = nn.Nat_NormalValueMinValue, + od.T_OrderDetailMaxValue = nn.Nat_NormalValueMaxValue, + od.T_OrderDetailMinValueInclusive = nn.Nat_NormalValueMinValueInclusive, + od.T_OrderDetailMaxValueInclusive = nn.Nat_NormalValueMaxValueInclusive, + od.T_OrderDetailNat_MethodeID = ?, + od.T_OrderdetailNat_MethodeName = ? + WHERE od.T_OrderDetailID = ? + AND od.T_OrderDetailIsActive = 'Y'", + [$normalValueID, $selID, $selName, $orderDetailID] + ); + $updatedRows = $this->db->affected_rows(); + $resultRow = [[ + 'status' => 'OK', + 'message' => "Normal value berhasil diupdate untuk T_OrderDetailID {$orderDetailID}", + 'selected_methode_id' => $selID, + 'selected_methode_name'=> $selName, + 'selected_methode_source' => $selSource, + 'nat_normalvalue_id' => $normalValueID, + 'updated_rows' => $updatedRows, + ]]; + } else { + $resultRow = [[ + 'status' => 'NOT_FOUND', + 'message' => "Normal value tidak ditemukan untuk T_OrderDetailID {$orderDetailID}", + 'selected_methode_id' => $selID, + 'selected_methode_name'=> $selName, + 'selected_methode_source' => $selSource, + 'nat_normalvalue_id' => $normalValueID, + 'updated_rows' => 0, + ]]; + } + + $odRow = $this->db->query( + "SELECT T_OrderDetailID, T_OrderDetailNat_NormalValueID, T_OrderDetailNat_MethodeID, + T_OrderdetailNat_MethodeName, T_OrderDetailNormalValueDescription, + T_OrderDetailMinValue, T_OrderDetailMaxValue, + T_OrderDetailMinValueInclusive, T_OrderDetailMaxValueInclusive + FROM t_orderdetail WHERE T_OrderDetailID = ? LIMIT 1", + [$orderDetailID] + )->result_array(); + + return ['ok' => true, 'message' => '', 'result_sets' => [$resultRow, $odRow]]; + } + + // ------------------------------------------------------------------------- + // Private helpers + // ------------------------------------------------------------------------- + + /** Inline pengganti fn_normal_get_age: konversi kolom usia ke hari di SQL. */ + private function _age_sql($col) + { + return "CASE Nat_NormalValueAgeUnit + WHEN 'HARI' THEN {$col} + WHEN 'BULAN' THEN {$col} * 30 + WHEN 'TAHUN' THEN {$col} * 365 + ELSE {$col} + END"; + } + + /** + * Ambil data dasar order detail termasuk DOB terenkripsi. + * Return [sexID, dobStr, orderDate, ageInDay, orderHeaderID, patientID, natTestID, $row] + * atau null jika tidak ditemukan. + */ + private function _load_order_detail_data($orderDetailID) + { + $row = $this->db->query( + "SELECT + od.T_OrderDetailT_OrderHeaderID AS order_header_id, + oh.T_OrderHeaderM_PatientID AS patient_id, + p.M_PatientM_SexID AS sex_id, + p.M_PatientDOB_enc, + p.M_PatientDOB, + DATE(oh.T_OrderHeaderDate) AS order_date, + od.T_OrderDetailT_TestID AS t_test_id, + tt.T_TestName AS t_test_name, + tt.T_TestNat_TestID AS nat_test_id, + nt.Nat_TestCode AS nat_test_code, + nt.Nat_TestName AS nat_test_name, + od.T_OrderDetailNat_MethodeID AS order_detail_methode_id + FROM t_orderdetail od + JOIN t_orderheader oh ON oh.T_OrderHeaderID = od.T_OrderDetailT_OrderHeaderID + JOIN m_patient p ON p.M_PatientID = oh.T_OrderHeaderM_PatientID + LEFT JOIN t_test tt ON tt.T_TestID = od.T_OrderDetailT_TestID + LEFT JOIN nat_test nt ON nt.Nat_TestID = tt.T_TestNat_TestID + WHERE od.T_OrderDetailID = ? + AND od.T_OrderDetailIsActive = 'Y' + LIMIT 1", + [$orderDetailID] + )->row_array(); + + if (!$row) return null; + + $dobStr = ''; + if (!empty($row['M_PatientDOB_enc'])) { + $CI = &get_instance(); + $CI->load->library('ibl_encryptor'); + $dobStr = (string) ($CI->ibl_encryptor->decrypt($row['M_PatientDOB_enc']) ?? ''); + } + if ($dobStr === '' && !empty($row['M_PatientDOB'])) { + $dobStr = $row['M_PatientDOB']; + } + + $ageInDay = null; + if ($dobStr !== '' && !empty($row['order_date'])) { + try { + $dob = new DateTime($dobStr); + $oDate = new DateTime($row['order_date']); + $ageInDay = (int) $oDate->diff($dob)->days; + } catch (Exception $e) {} + } + + return [ + intval($row['sex_id']), + $dobStr, + $row['order_date'], + $ageInDay, + intval($row['order_header_id']), + intval($row['patient_id']), + intval($row['nat_test_id']), + $row, + ]; + } + + /** Resolusi metode dari 3 sumber: priority → instrument → normalvalue. */ + private function _resolve_method_sources($natTestID) + { + $r = $this->db->query( + "SELECT mp.M_MethodePriorityNat_MethodeID, nm.Nat_MethodeName + FROM m_methode_priority mp + JOIN nat_methode nm ON nm.Nat_MethodeID = mp.M_MethodePriorityNat_MethodeID AND nm.Nat_MethodeIsActive = 'Y' + JOIN m_instrumentmethode im ON im.M_InstrumentMethodeNat_MethodeID = nm.Nat_MethodeID AND im.M_InstrumentMethodeIsActive = 'Y' + JOIN nat_instrument ni ON ni.Nat_InstrumentID = im.M_InstrumentMethodeNat_InstrumentID AND ni.Nat_InstrumentIsActive = 'Y' + WHERE mp.M_MethodePriorityIsActive = 'Y' + AND mp.M_MethodePriorityNat_TestID = ? + AND mp.M_MethodePriorityM_DayOfWeekID = DAYOFWEEK(NOW()) + ORDER BY mp.M_MethodePriorityNumber DESC LIMIT 1", + [$natTestID] + )->row_array(); + $priorityID = intval($r['M_MethodePriorityNat_MethodeID'] ?? 0); + $priorityName = $r['Nat_MethodeName'] ?? null; + + $r = $this->db->query( + "SELECT im.M_InstrumentMethodeNat_MethodeID, nm.Nat_MethodeName + FROM m_instrumentmethode im + JOIN nat_methode nm ON nm.Nat_MethodeID = im.M_InstrumentMethodeNat_MethodeID AND nm.Nat_MethodeIsActive = 'Y' + JOIN nat_instrument ni ON ni.Nat_InstrumentID = im.M_InstrumentMethodeNat_InstrumentID AND ni.Nat_InstrumentIsActive = 'Y' + WHERE im.M_InstrumentMethodeNat_TestID = ? + AND im.M_InstrumentMethodeIsActive = 'Y' + ORDER BY im.M_InstrumentMethodePriority DESC LIMIT 1", + [$natTestID] + )->row_array(); + $instrumentID = intval($r['M_InstrumentMethodeNat_MethodeID'] ?? 0); + $instrumentName = $r['Nat_MethodeName'] ?? null; + + $r = $this->db->query( + "SELECT nn.Nat_NormalValueNat_MethodeID, nm.Nat_MethodeName + FROM nat_normalvalue nn + JOIN nat_methode nm ON nm.Nat_MethodeID = nn.Nat_NormalValueNat_MethodeID AND nm.Nat_MethodeIsActive = 'Y' + WHERE nn.Nat_NormalValueNat_TestID = ? + AND nn.Nat_NormalValueIsActive = 'Y' + ORDER BY nn.Nat_NormalValueID LIMIT 1", + [$natTestID] + )->row_array(); + $normalID = intval($r['Nat_NormalValueNat_MethodeID'] ?? 0); + $normalName = $r['Nat_MethodeName'] ?? null; + + return [ + 'priority_id' => $priorityID, + 'priority_name' => $priorityName, + 'instrument_id' => $instrumentID, + 'instrument_name'=> $instrumentName, + 'normalvalue_id' => $normalID, + 'normalvalue_name' => $normalName, + ]; + } + + /** Pilih metode terbaik dari hasil _resolve_method_sources(). */ + private function _pick_method(array $methods) + { + if ($methods['priority_id'] > 0) { + return [$methods['priority_id'], $methods['priority_name'], 'm_methode_priority']; + } + if ($methods['instrument_id'] > 0) { + return [$methods['instrument_id'], $methods['instrument_name'], 'm_instrumentmethode']; + } + if ($methods['normalvalue_id'] > 0) { + return [$methods['normalvalue_id'], $methods['normalvalue_name'], 'nat_normalvalue']; + } + return [0, null, null]; + } + + /** Hitung matched_count per TYPE (1..4) untuk branch summary. */ + private function _query_branches($methodeID, $natTestID, $sexID, $ageInDay) + { + $min = $this->_age_sql('Nat_NormalValueMinAge'); + $max = $this->_age_sql('Nat_NormalValueMaxAge'); + $base = "FROM nat_normalvalue + WHERE (Nat_NormalValueValidDate IS NULL OR Nat_NormalValueValidDate < NOW()) + AND Nat_NormalValueIsActive = 'Y' + AND Nat_NormalValueIsAbnormal = 'N' + AND Nat_NormalValueNat_FlagID = 1 + AND Nat_NormalValueNat_MethodeID = $methodeID + AND Nat_NormalValueNat_TestID = $natTestID"; + + $ageFilter = " + AND ((Nat_NormalValueMinAgeInclusive='Y' AND ($min)<=$ageInDay) OR (Nat_NormalValueMinAgeInclusive='N' AND ($min)<$ageInDay)) + AND ((Nat_NormalValueMaxAgeInclusive='Y' AND ($max)>=$ageInDay) OR (Nat_NormalValueMaxAgeInclusive='N' AND ($max)>$ageInDay))"; + + $types = [ + ['TYPE_1', "AND Nat_NormalValueNat_NormalValueTypeID=1 AND Nat_NormalValueNat_SexID=$sexID $ageFilter"], + ['TYPE_2', "AND Nat_NormalValueNat_NormalValueTypeID=2 $ageFilter"], + ['TYPE_3', "AND Nat_NormalValueNat_NormalValueTypeID=3 AND Nat_NormalValueNat_SexID=$sexID"], + ['TYPE_4', "AND Nat_NormalValueNat_NormalValueTypeID=4"], + ]; + + $branches = []; + foreach ($types as list($label, $filter)) { + $r = $this->db->query("SELECT COUNT(*) AS cnt, MIN(Nat_NormalValueID) AS first_id $base $filter")->row_array(); + $branches[] = [ + 'branch_name' => $label, + 'matched_count' => intval($r['cnt'] ?? 0), + 'first_normalvalue_id'=> $r['first_id'] ?? null, + ]; + } + return $branches; + } + + /** Ambil semua kandidat nat_normalvalue dengan kolom diagnostik match/fail. */ + private function _query_candidates($methodeID, $natTestID, $sexID, $ageInDay) + { + if (!$natTestID) return []; + + $min = $this->_age_sql('Nat_NormalValueMinAge'); + $max = $this->_age_sql('Nat_NormalValueMaxAge'); + $a = intval($ageInDay); + $s = intval($sexID); + $m = intval($methodeID); + + $matchMinAge = "( + (Nat_NormalValueMinAgeInclusive='Y' AND ($min)<=$a) + OR (Nat_NormalValueMinAgeInclusive='N' AND ($min)<$a))"; + $matchMaxAge = "( + (Nat_NormalValueMaxAgeInclusive='Y' AND ($max)>=$a) + OR (Nat_NormalValueMaxAgeInclusive='N' AND ($max)>$a))"; + + $sql = "SELECT + nn.Nat_NormalValueID, + nn.Nat_NormalValueNat_TestID, + nn.Nat_NormalValueNat_MethodeID, + nm.Nat_MethodeName, + nn.Nat_NormalValueNat_NormalValueTypeID, + nn.Nat_NormalValueNat_SexID, + nn.Nat_NormalValueValidDate, + nn.Nat_NormalValueMinAge, + nn.Nat_NormalValueMaxAge, + nn.Nat_NormalValueAgeUnit, + nn.Nat_NormalValueMinAgeInclusive, + nn.Nat_NormalValueMaxAgeInclusive, + ($min) AS MinAgeInDay, + ($max) AS MaxAgeInDay, + nn.Nat_NormalValueNat_FlagID, + nn.Nat_NormalValueIsAbnormal, + nn.Nat_NormalValueIsActive, + IF((nn.Nat_NormalValueValidDate IS NULL OR nn.Nat_NormalValueValidDate < NOW()),'Y','N') AS MatchValidDate, + IF(nn.Nat_NormalValueIsActive='Y','Y','N') AS MatchActive, + IF(nn.Nat_NormalValueIsAbnormal='N','Y','N') AS MatchNotAbnormal, + IF(nn.Nat_NormalValueNat_FlagID=1,'Y','N') AS MatchFlag, + IF(nn.Nat_NormalValueNat_TestID=$natTestID,'Y','N') AS MatchNatTest, + IF($m>0 AND nn.Nat_NormalValueNat_MethodeID=$m,'Y','N') AS MatchSelectedMethod, + IF(nn.Nat_NormalValueNat_SexID=$s,'Y','N') AS MatchSex, + IF($matchMinAge,'Y','N') AS MatchMinAge, + IF($matchMaxAge,'Y','N') AS MatchMaxAge, + CASE nn.Nat_NormalValueNat_NormalValueTypeID + WHEN 1 THEN IF(nn.Nat_NormalValueNat_SexID=$s AND $matchMinAge AND $matchMaxAge,'Y','N') + WHEN 2 THEN IF($matchMinAge AND $matchMaxAge,'Y','N') + WHEN 3 THEN IF(nn.Nat_NormalValueNat_SexID=$s,'Y','N') + WHEN 4 THEN 'Y' + ELSE 'N' + END AS MatchTypeRule, + CONCAT_WS('; ', + IF(NOT(nn.Nat_NormalValueValidDate IS NULL OR nn.Nat_NormalValueValidDate'Y','inactive',NULL), + IF(nn.Nat_NormalValueIsAbnormal<>'N','abnormal_row',NULL), + IF(nn.Nat_NormalValueNat_FlagID<>1,'flag_not_1',NULL), + IF(nn.Nat_NormalValueNat_TestID<>$natTestID,'nat_test_mismatch',NULL), + IF($m>0 AND nn.Nat_NormalValueNat_MethodeID<>$m,'methode_mismatch',NULL), + IF(nn.Nat_NormalValueNat_NormalValueTypeID IN(1,3) AND nn.Nat_NormalValueNat_SexID<>$s,'sex_mismatch',NULL), + IF(nn.Nat_NormalValueNat_NormalValueTypeID IN(1,2) AND NOT $matchMinAge,'age_below_min',NULL), + IF(nn.Nat_NormalValueNat_NormalValueTypeID IN(1,2) AND NOT $matchMaxAge,'age_above_max',NULL) + ) AS FailReason + FROM nat_normalvalue nn + LEFT JOIN nat_methode nm ON nm.Nat_MethodeID = nn.Nat_NormalValueNat_MethodeID + WHERE nn.Nat_NormalValueNat_TestID = $natTestID + AND nn.Nat_NormalValueIsActive = 'Y' + AND nn.Nat_NormalValueIsAbnormal = 'N' + ORDER BY + CASE WHEN $m>0 AND nn.Nat_NormalValueNat_MethodeID=$m THEN 0 ELSE 1 END, + nn.Nat_NormalValueNat_MethodeID, + nn.Nat_NormalValueNat_NormalValueTypeID, + nn.Nat_NormalValueID"; + + $qry = $this->db->query($sql); + return $qry ? $qry->result_array() : []; + } + + private function _chk($name, $ok, $value, $note) + { + return [ + 'check_name' => $name, + 'check_status' => $ok ? 'OK' : 'MISSING', + 'check_value' => $value, + 'check_note' => $note, + ]; + } + + private function _query_one($sql) + { + $qry = $this->db->query($sql); + if (!$qry) return 0; + $row = $qry->row_array(); + return intval($row['Nat_NormalValueID'] ?? 0); + } +}