db_onedev = $this->load->database("onedev", true); } function scan_patient_checkout() { $prm = $this->sys_input; $sql = "SELECT * FROM t_orderheader WHERE T_OrderHeaderLabNumber = ?"; $query = $this->db_onedev->query($sql, array([$prm['labnumber']])); if (!$query) { $this->sys_error_db("data patient"); exit; } $data_patient = $query->row_array(); //print_r($data_patient); $result = $this->get_patient($prm['labnumber'], $data_patient['T_OrderHeaderID']); $this->sys_ok($result); exit; } function search_patient() { $prm = $this->sys_input; $result = $this->get_patient($prm['noreg'], $prm['order_id']); $this->sys_ok($result); exit; } function get_patient($labnumber, $orderid) { //# ambil parameter input $data_patient = []; $sql = " SELECT DATE_FORMAT(T_OrderHeaderDate,'%d-%m-%Y %H:%i') as order_date, T_OrderHeaderLabNumber as labnumber, T_OrderHeaderM_PatientAge as patient_age, M_PatientName as patient_name, M_PatientNoReg as noreg, IF(M_PatientGender = 'male','Laki-laki','Perempuan') as gender, DATE_FORMAT(M_PatientDOB,'%d-%m-%Y') as dob, M_PatientJob as job, M_PatientPosisi as posisi, IF(M_PatientDivisi = '','-',M_PatientDivisi) as divisi, M_PatientHp as hp, M_PatientEmail as email, M_PatientNIP as nip, CorporateName as corporate_name, M_PatientPhoto as photo FROM t_orderheader JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID JOIN corporate ON T_OrderHeaderCorporateID = CorporateID WHERE T_OrderHeaderID = {$orderid} AND T_OrderHeaderLabNumber = '{$labnumber}' "; //echo $sql; $query = $this->db_onedev->query($sql); if (!$query) { $this->sys_error_db("data patient"); exit; } $data_patient = $query->row_array(); // print_r($sql); // exit; $data_packet = []; $sql = " SELECT T_PacketName as packet_name, T_PacketID as packet_id, '' as active, '' as details FROM t_orderdetailorder JOIN t_packet ON T_OrderDetailOrderT_PacketID = T_PacketID WHERE T_OrderDetailOrderT_OrderHeaderID = {$orderid} AND T_OrderDetailOrderIsPacket = 'Y' AND T_OrderDetailOrderIsActive = 'Y' "; //echo $sql; $query = $this->db_onedev->query($sql); if (!$query) { $this->sys_error_db("data packet"); exit; } $data_packet = $query->result_array(); if ($data_packet) { foreach ($data_packet as $key => $value) { $data_packet[$key]['active'] = false; $sql = "SELECT T_TestName as test_name FROM t_packetdetail JOIN t_test ON T_PacketDetailT_TestID = T_TestID WHERE T_PacketDetailT_PacketID = {$value['packet_id']} AND T_PacketDetailIsActive = 'Y'"; $query = $this->db_onedev->query($sql); if (!$query) { $this->sys_error_db("data packet detail"); exit; } $data_packet_details = $query->result_array(); if (count($data_packet_details) > 0) $data_packet[$key]['details'] = $data_packet_details; else $data_packet[$key]['details'] = []; } } $data_tests = []; $sql = " SELECT T_TestName as test_name FROM t_orderdetailorder JOIN t_test ON T_OrderDetailOrderT_TestID = T_TestID WHERE T_OrderDetailOrderT_OrderHeaderID = {$orderid} AND T_OrderDetailOrderIsPacket = 'N' AND T_OrderDetailOrderIsActive = 'Y' "; //echo $sql; $query = $this->db_onedev->query($sql); if (!$query) { $this->sys_error_db("data tests"); exit; } $data_tests = $query->result_array(); $data_sample_lab = []; $sql = " SELECT T_SampleTypeName as sampletype_name, T_OrderSampleBarcode as barcode, IF(ISNULL(T_OrderSampleSamplingDate),'Belum diambil',DATE_FORMAT(T_OrderSampleSamplingDate,'%d-%m-%Y')) as sampling_date, IF(ISNULL(T_OrderSampleSamplingTime),'',T_OrderSampleSamplingTime) as sample_time, IF(ISNULL(T_OrderSampleReceiveDate),'Belum dilakukan',DATE_FORMAT(T_OrderSampleReceiveDate,'%d-%m-%Y')) as receive_date, IF(ISNULL(T_OrderSampleReceiveTime),'',DATE_FORMAT(T_OrderSampleReceiveTime,'%H:%i')) as receive_time, T_OrderSampleSampling as is_sampling, T_OrderSampleReceive as is_received, IFNULL(M_StaffName,'') as staff_name FROM t_ordersample JOIN t_sampletype ON T_OrderSampleT_SampleTypeID = T_SampleTypeID LEFT JOIN m_user ON T_OrderSampleReceiveUserID = M_UserID LEFT JOIN m_staff ON M_UserM_StaffID = M_StaffID WHERE T_OrderSampleT_OrderHeaderID = {$orderid} AND T_OrderSampleIsActive = 'Y' Order BY T_SampleTypeName ASC "; //echo $sql; $query = $this->db_onedev->query($sql); if (!$query) { $this->sys_error_db("data sample lab"); exit; } $data_sample_lab = $query->result_array(); $data_sample_radiodiagnostic = []; $sql = " SELECT T_TestName as sampletype_name, T_OrderHeaderLabNumber as barcode, IFNULL(T_SamplingSoID, 0) as soID, T_OrderHeaderID as orderID, IF(ISNULL(T_SamplingSoProcessDate),'Belum dilakukan',DATE_FORMAT(T_SamplingSoProcessDate,'%d-%m-%Y')) as sampling_date, IF(ISNULL(T_SamplingSoProcessTime),'',T_SamplingSoProcessTime) as sample_time, IF(ISNULL(T_SamplingSoDoneDate),'Belum dilakukan',DATE_FORMAT(T_SamplingSoDoneDate,'%d-%m-%Y')) as receive_date, IF(ISNULL(T_SamplingSoDoneTime),'',DATE_FORMAT(T_SamplingSoDoneTime,'%H:%i')) as receive_time, IF(ISNULL(T_SamplingSoFlag),'N','Y') as is_sampling, IF(ISNULL(T_SamplingSoFlag) OR T_SamplingSoFlag <> 'D','N','Y') as is_received, IFNULL(M_StaffName,'') as staff_name FROM t_orderdetail JOIN t_orderheader ON T_OrderDetailT_OrderHeaderID = T_OrderHeaderID JOIN t_test ON T_OrderDetailT_TestID = T_TestID JOIN t_sampletype ON T_TestT_SampleTypeID = T_SampleTypeID JOIN t_bahan ON T_SampleTypeT_BahanID = T_BahanID JOIN t_samplestation ON T_BahanT_SampleStationID = T_SampleStationID AND T_SampleStationIsNonLab = 'RADIODIAGNOSTIC' LEFT JOIN t_samplingso ON T_SamplingSoT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND T_SamplingSoT_TestID = T_TestID LEFT JOIN m_user ON T_SamplingSoDoneUserID = M_UserID LEFT JOIN m_staff ON M_UserM_StaffID = M_StaffID WHERE T_OrderDetailT_OrderHeaderID = {$orderid} AND T_OrderDetailIsActive = 'Y' "; //echo $sql; $query = $this->db_onedev->query($sql); if (!$query) { $this->sys_error_db("data sample radiodiagnostic"); exit; } $data_sample_radiodiagnostic = $query->result_array(); $data_sample_electromedic = []; $sql = " SELECT T_TestName as sampletype_name, T_OrderHeaderLabNumber as barcode, IFNULL(T_SamplingSoID, 0) as soID, T_OrderHeaderID as orderID, IF(ISNULL(T_SamplingSoProcessDate),'Belum dilakukan',DATE_FORMAT(T_SamplingSoProcessDate,'%d-%m-%Y')) as sampling_date, IF(ISNULL(T_SamplingSoProcessTime),'',T_SamplingSoProcessTime) as sample_time, IF(ISNULL(T_SamplingSoDoneDate),'Belum dilakukan',DATE_FORMAT(T_SamplingSoDoneDate,'%d-%m-%Y')) as receive_date, IF(ISNULL(T_SamplingSoDoneTime),'',DATE_FORMAT(T_SamplingSoDoneTime,'%H:%i')) as receive_time, IF(ISNULL(T_SamplingSoFlag),'N','Y') as is_sampling, IF(ISNULL(T_SamplingSoFlag) OR T_SamplingSoFlag <> 'D','N','Y') as is_received, IFNULL(M_StaffName,'') as staff_name FROM t_orderdetail JOIN t_orderheader ON T_OrderDetailT_OrderHeaderID = T_OrderHeaderID JOIN t_test ON T_OrderDetailT_TestID = T_TestID JOIN t_sampletype ON T_TestT_SampleTypeID = T_SampleTypeID JOIN t_bahan ON T_SampleTypeT_BahanID = T_BahanID JOIN t_samplestation ON T_BahanT_SampleStationID = T_SampleStationID AND T_SampleStationIsNonLab = 'ELEKTROMEDIS' LEFT JOIN t_samplingso ON T_SamplingSoT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND T_SamplingSoT_TestID = T_TestID LEFT JOIN m_user ON T_SamplingSoDoneUserID = M_UserID LEFT JOIN m_staff ON M_UserM_StaffID = M_StaffID WHERE T_OrderDetailT_OrderHeaderID = {$orderid} AND T_OrderDetailIsActive = 'Y' "; //echo $sql; $query = $this->db_onedev->query($sql); if (!$query) { $this->sys_error_db("data sample electromedis"); exit; } $data_sample_electromedic = $query->result_array(); $data_sample_other = []; $sql = " SELECT T_TestName as sampletype_name, T_OrderHeaderLabNumber as barcode, IFNULL(T_SamplingSoID, 0) as soID, T_OrderHeaderID as orderID, IF(ISNULL(T_SamplingSoProcessDate),'Belum dilakukan',DATE_FORMAT(T_SamplingSoProcessDate,'%d-%m-%Y')) as sampling_date, IF(ISNULL(T_SamplingSoProcessTime),'',T_SamplingSoProcessTime) as sample_time, IF(ISNULL(T_SamplingSoDoneDate),'Belum dilakukan',DATE_FORMAT(T_SamplingSoDoneDate,'%d-%m-%Y')) as receive_date, IF(ISNULL(T_SamplingSoDoneTime),'',DATE_FORMAT(T_SamplingSoDoneTime,'%H:%i')) as receive_time, IF(ISNULL(T_SamplingSoFlag),'N','Y') as is_sampling, IF(ISNULL(T_SamplingSoFlag) OR T_SamplingSoFlag <> 'D','N','Y') as is_received, IFNULL(M_StaffName,'') as staff_name FROM t_orderdetail JOIN t_orderheader ON T_OrderDetailT_OrderHeaderID = T_OrderHeaderID JOIN t_test ON T_OrderDetailT_TestID = T_TestID JOIN t_sampletype ON T_TestT_SampleTypeID = T_SampleTypeID JOIN t_bahan ON T_SampleTypeT_BahanID = T_BahanID JOIN t_samplestation ON T_BahanT_SampleStationID = T_SampleStationID AND T_SampleStationIsNonLab = 'OTHERS' LEFT JOIN t_samplingso ON T_SamplingSoT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND T_SamplingSoT_TestID = T_TestID LEFT JOIN m_user ON T_SamplingSoDoneUserID = M_UserID LEFT JOIN m_staff ON M_UserM_StaffID = M_StaffID WHERE T_OrderDetailT_OrderHeaderID = {$orderid} AND T_OrderDetailIsActive = 'Y' "; //echo $sql; $query = $this->db_onedev->query($sql); if (!$query) { $this->sys_error_db("data sample other"); exit; } $data_sample_other = $query->result_array(); $sql = " SELECT COUNT(*) as xcount, IF(T_SurveyID IS NULL, 'N','Y') as is_sampling, IF(T_SurveyID IS NULL, 'N','Y') as is_received, IFNULL(DATE_FORMAT(T_SurveyCreated,'%d-%m-%Y'),'Klik untuk mengisi survey') as xcreated_date, IFNULL(DATE_FORMAT(T_SurveyCreated,'%H:%i'),'') as xcreated_time FROM t_orderheader LEFT JOIN t_survey ON T_OrderHeaderID = T_SurveyT_OrderHeaderID AND T_SurveyIsActive = 'Y' WHERE T_OrderHeaderID = {$orderid} AND T_OrderHeaderLabNumber = '{$labnumber}' "; //echo $sql; $query = $this->db_onedev->query($sql); if (!$query) { $this->sys_error_db("data exist"); exit; } $data_exist = $query->row(); $data_survey = []; if ($data_exist->xcount > 0) { $status = "SUCCESS"; $data_survey = [ "sampletype_name" => "Survey", "barcode" => $labnumber, "sampling_date" => $data_exist->xcreated_date, "sample_time" => $data_exist->xcreated_time, "receive_date" => $data_exist->xcreated_date, "receive_time" => $data_exist->xcreated_time, "is_sampling" => $data_exist->is_sampling, "is_received" => $data_exist->is_received ]; } $result = array( "data_patient" => $data_patient ? $data_patient : [], "data_packet" => $data_packet ? $data_packet : [], "data_tests" => $data_tests ? $data_tests : [], "data_sample_lab" => $data_sample_lab ? $data_sample_lab : [], "data_sample_radiodiagnostic" => $data_sample_radiodiagnostic ? $data_sample_radiodiagnostic : [], "data_sample_electromedic" => $data_sample_electromedic ? $data_sample_electromedic : [], "data_sample_other" => $data_sample_other ? $data_sample_other : [], "data_survey" => $data_survey ); return $result; } function load_survey() { //# ambil parameter input $prm = $this->sys_input; $status = "FORM"; $results = []; $sql = " SELECT COUNT(*) as xcount FROM t_survey JOIN t_orderheader ON T_OrderHeaderID = T_SurveyT_OrderHeaderID AND T_OrderHeaderID = {$prm['order_id']} AND T_OrderHeaderLabNumber = '{$prm['noreg']}' WHERE T_SurveyIsActive = 'Y' "; //echo $sql; $query = $this->db_onedev->query($sql); if (!$query) { $this->sys_error_db("data exist"); exit; } $data_exist = $query->row()->xcount; if ($data_exist > 0) { $status = "SUCCESS"; } else { $sql = " SELECT COUNT(*) as xcount FROM t_orderheader WHERE T_OrderHeaderID = {$prm['order_id']} AND T_OrderHeaderLabNumber = '{$prm['noreg']}' AND T_OrderHeaderIsActive = 'Y' "; //echo $sql; $query = $this->db_onedev->query($sql); if (!$query) { $this->sys_error_db("data patient"); exit; } $data_exist_patient = $query->row()->xcount; if ($data_exist_patient == 0) { $status = "PATIENT_NOT_FOUND"; } else { $sql = " SELECT M_SurveyID as id, M_SurveyName as name, '' as value FROM m_survey WHERE M_SurveyIsActive = 'Y' "; //echo $sql; $query = $this->db_onedev->query($sql); if (!$query) { $this->sys_error_db("data survey"); exit; } $results = $query->result_array(); } } $result = array( "records" => $results, "status" => $status ); $this->sys_ok($result); exit; } function save_survey() { //# ambil parameter input $prm = $this->sys_input; $status = "FORM"; $results = []; $sql = " INSERT INTO t_survey ( T_SurveyT_OrderHeaderID, T_SurveySaran, T_SurveyCreated ) VALUES( ?, ?, NOW()) "; //echo $sql; $query = $this->db_onedev->query($sql, array( $prm['order_id'], $prm['saran'] )); if (!$query) { $this->sys_error_db("insert header"); exit; } $header_id = $this->db_onedev->insert_id(); foreach ($prm['surveys'] as $key => $value) { $sql = " INSERT INTO t_surveydetail ( T_SurveryDetailT_SurveyID, T_SurveryDetailM_SurveyID, T_SurveryDetailValue, T_SurveryDetailCreated ) VALUES( ?,?,?,NOW() ) "; //echo $sql; $query = $this->db_onedev->query($sql, array( $header_id, $value['id'], $value['value'] )); if (!$query) { //echo $this->db_onedev->last_query(); $this->sys_error_db("insert detail "); exit; } } $status = "SUCCESS"; $result = array( "status" => $status ); $this->sys_ok($result); exit; } public function check_dir($path) { if (!file_exists($path)) { mkdir($path, 0777, true); return true; } return true; } public function check_size($base64string) { $file_size = 3000000; $size = @getimagesize($base64string); $exploded = explode(',', $base64string); $base64Data = end($exploded); // Ambil hanya data base64 tanpa prefix (data:image/...;base64,) $sizeInBytes = strlen(base64_decode($base64Data)); $sizeInKB = round($sizeInBytes / 1024, 2); $sizeInMB = round($sizeInBytes / (1024 * 1024), 2); if ($sizeInKB >= $file_size) { return false; } return true; } public function check_file_type($base64string) { $mime_type = @mime_content_type($base64string); // print_r($mime_type); $allowed_file_types = [ 'image/png', 'image/jpeg', 'application/pdf', "application/msword", "application/vnd.openxmlformats-officedocument.wordprocessingml.document", "application/vnd.ms-excel", "text/xml", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" ]; if (!in_array($mime_type, $allowed_file_types)) { // File type is NOT allowed // print_r(json_encode(array('status' =>false,'message' => 'File type is NOT allowed !')));exit; return false; } return true; } function uploadDocument() { if (!$this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $userid = $this->sys_user["M_UserID"]; // $path = "/home/one/project/one/one-media/one-image-nonlab/"; $path = "/mnt/volume_sgp1_1778902074763/one-document-nonlab/"; // file_put_contents("/home/one/project/one/pettycash-media/attachment/" . $newFilename, $file); // if (file_exists($path)) { // print_r("File path exist"); // exit; // } $data = $prm['data']; $test = $prm['test']; if (count($data) == 0) { $this->sys_error("Tidak ada yang bisa diupload"); exit; } $validation = array(); for ($i = 0; $i < count($data); $i++) { if (!$this->check_file_type($data[$i]['base64'])) { array_push($validation, $data[$i]['imageName'] . " file type tidak sesuai"); } if (!$this->check_size($data[$i]['base64'])) { array_push($validation, $data[$i]['imageName'] . " file size tidak sesuai"); } } if (count($validation) > 0) { $this->sys_error("Gagal validasi, file tidak sesuai" . implode($validation)); exit; } for ($i = 0; $i < count($data); $i++) { $e = $data[$i]; $file = base64_decode($e['base64']); $fileName = $e['imageName']; $fileNameParts = explode('.', $fileName); $ext = end($fileNameParts); $filename = uniqid() . "_" . str_replace(' ', '_', $e['imageName']); file_put_contents($path . $filename, file_get_contents($e['base64'])); $sql = "INSERT INTO t_nonlabdocument( T_NonlabDocumentT_OrderHeaderID, T_NonlabDocumentT_SamplingSoID, T_NonlabDocumentFile, T_NonlabDocumentCreated, T_NonlabDocumentCreatedUserID, T_NonlabDocumentType) VALUES(?,?,?, NOW(),?,?)"; $query = $this->db_onedev->query($sql, array( $test['orderID'], $test['soID'], $filename, $userid, $ext )); if (!$query) { echo $this->db_onedev->last_query(); $this->sys_error_db("Error insert db"); exit; } } $this->sys_ok("ok"); } function uploadattachment(){ if (!$this->isLogin) { $this->sys_error("Invalid Token"); exit; } $userid = $this->sys_user["M_UserID"]; $data = []; $prm = $this->sys_input; $orderid = $this->input->post('orderid'); $soid = $this->input->post('soid'); $error = []; $path = '/mnt/volume_sgp1_1778902074763/one-document-nonlab/'; //echo $path; $config['upload_path'] = $path; $config['allowed_types'] = 'jpg|jpeg|png|gif|pdf'; $config['max_size'] = 3000; // Maksimal 3000 KB $count = count($_FILES['files']['name']); $this->load->library('upload',$config); $file_uploaded = 1; if($file_uploaded > 2){ $error[] = "Jumlah file yang diupload maksimal 2"; }else{ for ($i = 0; $i < $count; $i++) { if (!empty($_FILES['files']['name'][$i])) { // Validasi ukuran file secara manual if ($_FILES['files']['size'][$i] > 3000 * 1024) { // 3000 KB dalam byte $error[] = "File " . $_FILES['files']['name'][$i] . " melebihi ukuran maksimal 500 KB."; //print_r($error); continue; // Skip file yang terlalu besar } //echo $_FILES['files']['name'][$i]; //exit; $_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 = $_FILES['files']['name'][$i]; $ext = $_FILES['files']['type'][$i]; $config['file_name'] = $namex; $this->upload->initialize($config); if ($this->upload->do_upload('file')) { $uploadData = $this->upload->data(); $filename = $uploadData['file_name']; //echo $filename; // Proses SQL atau penyimpanan data lainnya $sql = "INSERT INTO t_nonlabdocument( T_NonlabDocumentT_OrderHeaderID, T_NonlabDocumentT_SamplingSoID, T_NonlabDocumentFile, T_NonlabDocumentCreated, T_NonlabDocumentCreatedUserID, T_NonlabDocumentType) VALUES(?,?,?, NOW(),?,?)"; $query = $this->db_onedev->query($sql, array( $orderid, $soid, $filename, $userid, $ext )); } else { $error[] = $this->upload->display_errors(); } } } } $result = array("total" =>count( $data['totalFiles']), "records" => $data['totalFiles'],'errors'=>$error); $this->sys_ok($result); } function getdocument() { if (!$this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $orderid = $prm['orderID']; $soid = $prm['soID']; $sql = "SELECT T_NonlabDocumentID documentID, T_NonlabDocumentT_OrderHeaderID orderID, T_NonlabDocumentT_SamplingSoID soID, T_NonlabDocumentFile file, T_NonlabDocumentType type FROM t_nonlabdocument WHERE T_NonlabDocumentT_OrderHeaderID = ? AND T_NonlabDocumentT_SamplingSoID = ? AND T_NonlabDocumentIsActive = 'Y'"; $query = $this->db_onedev->query($sql, array( $orderid, $soid )); if (!$query) { //echo $this->db_onedev->last_query(); $this->sys_error_db("Error get document"); exit; } $this->sys_ok(array("records" => $query->result_array())); } function deleteFile() { if (!$this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $id = $prm['id']; $userid = $this->sys_user["M_UserID"]; $sql = "UPDATE t_nonlabdocument SET T_NonlabDocumentIsActive = 'N', T_NonlabDocumentLastUpdated = NOW(), T_NonlabDocumentLastUpdatedUserID = {$userid} WHERE T_NonlabDocumentID = ? "; $query = $this->db_onedev->query($sql, array( $id )); if (!$query) { //echo $this->db_onedev->last_query(); $this->sys_error_db("Error hapus db"); exit; } $this->sys_ok('OK'); } function downloadfile(string $fileName) { $file_path = "/mnt/volume_sgp1_1778902074763/one-document-nonlab/" . $fileName; print_r(mime_content_type($file_path)); header('Content-Type: ' . mime_content_type($file_path)); header('Content-Length: ' . filesize($file_path)); // echo file_get_contents($file_path); $this->load->helper('download'); force_download($file_path, NULL); } }