db_one = $this->load->database("onedev", true); } function raw() { $param = $this->sys_input; try { $instrumentID = $param["instrumentID"]; $data = $param["data"]; $sql = "insert into itf_raw(itf_RawNat_InstrumentID,itf_RawData) values(?,?)"; $this->db_one->query($sql, array($instrumentID, base64_decode($data))); echo json_encode( array("status" => "OK", "id" => $this->db_one->insert_id(), "message" => "") ); } catch (exception $e) { echo json_encode( array("status" => "ERR", "id" => 0, "message" => $e . message()) ); } } function do_result($rawID, $debug = "") { $sql = "select * from itf_result where itf_ResultItf_RawID = ? and itf_ResultIsSent ='N'"; $qry = $this->db->query($sql, [$rawID]); if (!$qry) { echo json_encode(["status" => "ERR", "message" => "Error do_result | " . $this->db->error()["message"]]); exit; } $rows = $qry->result_array(); $otherHeaderID = 0; $bacteriID = 0; foreach ($rows as $r) { $id = $r["Itf_ResultID"]; $kode = $r["Itf_ResultKode"]; $nolab = $r["Itf_ResultNoreg"]; $instrumentID = $r["Itf_ResultNat_InstrumentID"]; $bacteri = $r["Itf_ResultBacteri"]; $anti = $r["Itf_ResultAnti"]; $result = $r["Itf_ResultResult"]; if ($debug != "") { echo "$nolab | $kode , $id, $instrumentID\n"; } $orderDetailID = $this->get_order_detail_id($instrumentID, $kode, $nolab); if ($orderDetailID != 0) { if ($debug != "") { echo " Order Found $orderDetailID\n"; } } //header if ($otherHeaderID == 0) { $bacteriID = $this->get_bacteri_id($bacteri); if ($bacteriID == 0) { if ($debug != "") { echo "bacteri $bacteri not found\n"; continue; } } $otherHeaderID = $this->get_mikro_header($orderDetailID, $bacteri, $bacteriID); } if ($otherHeaderID == 0) { if ($debug != "") { echo "Other Mikro ID error\n"; continue; } } //detail $antibioticID = $this->get_anti($anti, $bacteriID); if ($antibioticID == 0) { if ($debug != "") { echo "$anti not found"; } continue; } $prefix = ""; $note = ""; if(stripos($result,">=") !== false) { $prefix = ">="; $result = str_replace(">=","",$result); list($result,$note)= explode("^",$result); } else if(stripos($result,">") !== false){ $result = str_replace(">","",$result); $prefix = ">"; list($result,$note)= explode("^",$result); } else if(stripos($result,"<=") !== false){ $result = str_replace("<=","",$result); $prefix = "<="; list($result,$note)= explode("^",$result); } else if(stripos($result,"<") !== false) { $result = str_replace("<","",$result); $prefix = "<"; list($result,$note)= explode("^",$result); } echo "prefix : $prefix, result : $result, note : $note \n"; } } function get_anti($anti, $bacteriID) { $sql = "select * from t_antibiotic where T_AntibioticName = ? and T_AntibioticT_BacteriaID = ?"; $qry = $this->db->query($sql, [$anti, $bacteriID]); if (!$qry) { echo json_encode(["status" => "ERR", "message" => "Error get anti | " . $this->db->error()["message"]]); exit; } $rows = $qry->result_array(); if (count($rows) == 0) { return 0; } return $rows[0]["T_AntibioticID"]; } function get_mikro_header($orderDetailID, $bacteri, $bacteriID) { $sql = "select * from other_mikro where Other_MikroT_OrderDetailID =? and Other_MikroIsActive = 'Y'"; $qry = $this->db->query($sql, [$orderDetailID]); if (!$qry) { echo json_encode(["status" => "ERR", "message" => "Error mikro header| " . $this->db->error()["message"]]); exit; } $rows = $qry->result_array(); if (count($rows) == 0) { if ($bacteriID == 0) { $sql = "insert into other_mikro(Other_MikroT_OrderDetailID, Other_MikroT_BacteriaID) values(?,?)"; $qry = $this->db->query($sql, [$orderDetailID, $bacteriID]); } else { $sql = "insert into other_mikro(Other_MikroT_OrderDetailID, Other_MikroT_BacteriaID,Other_MikroResult) values(?,?,?)"; $qry = $this->db->query($sql, [$orderDetailID, $bacteriID, "Bacteria $bacteri not settup"]); } if (!$qry) { echo json_encode(["status" => "ERR", "message" => "Error mikro header| " . $this->db->error()["message"]]); exit; } return $this->db->insert_id(); } else { return $rows[0]["Other_MikroID"]; } } function get_bacteri_id($bacteri) { $sql = "select * from t_bacteria where T_BacteriaName = ?"; $qry = $this->db->query($sql, [$bacteri]); if (!$qry) { echo json_encode(["status" => "ERR", "message" => "Error get bacteri | " . $this->db->error()["message"]]); } $rows = $qry->result_array(); if (count($rows) == 0) { return 0; } return $rows[0]["T_BacteriaID"]; } function get_order_detail_id($instrumentID, $kode, $nolab) { $sql = "select t_orderdetail.* from t_orderdetail join t_orderheader on T_OrderHeaderLabNumber = ? and T_OrderDetailT_OrderHeaderID = T_OrderHeaderID join t_test on T_OrderDetailT_TestID = T_TestID join m_instrumentassay on T_TestNat_TestID = M_InstrumentAssayNat_TestID and M_InstrumentAssayCode = ? and M_InstrumentAssayNat_InstrumentID = ?"; $qry = $this->db->query($sql, [$nolab, $kode, $instrumentID]); if (!$qry) { echo json_encode(["status" => "ERR", "message" => "Error do_result | " . $this->db->error()["message"]]); } $rows = $qry->result_array(); if (count($rows) == 0) { return 0; } return $rows[0]["T_OrderDetailID"]; } function result() { $param = $this->sys_input; try { $instrumentID = $param["instrumentID"]; $rawID = $param["rawID"]; $result = $param["result"]; $noreg = $result["nolab"]; $sql = "insert into itf_result(itf_ResultNat_InstrumentID, itf_ResultItf_RawID, Itf_ResultNoreg, Itf_ResultInstrumentDate, itf_ResultKode, itf_ResultResult, itf_ResultFlag, itf_ResultBacteri, itf_ResultAnti) values(?,?,?,?,?,?,?, ?,?)"; foreach ($result["result"] as $r) { $tgl = $r["date"]; $px = $r["px"]; $bacteri = $r["bacteri"]; $anti = $r["anti"]; $result = $r["result"]; $this->db_one->query( $sql, array( $instrumentID, $rawID, $noreg, $tgl, $px, $result, $r["flag"], $bacteri, $anti ) ); } // change echo json_encode( array("status" => "OK", "message" => "") ); } catch (exception $e) { echo json_encode( array("status" => "ERR", "message" => $e->message()) ); } } }