diff --git a/app/Config/Routes.php b/app/Config/Routes.php index d9975d0..83febde 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -109,5 +109,6 @@ $routes->group('fo', ['filter' => 'role:fo'], static function ($routes) { // Printers $routes->get('printLabel/single/(:any)/(:any)', 'PrintLabel::printSingle/$1/$2'); +$routes->get('printLabel/collection/(:any)', 'PrintLabel::labelPostekCollection/$1'); $routes->get('printLabel/all/(:any)', 'PrintLabel::printAll/$1'); $routes->get('printResult/(:any)', 'PrintResult::printResultTest/$1'); \ No newline at end of file diff --git a/app/Controllers/PrintLabel.php b/app/Controllers/PrintLabel.php index e5693e9..fcf826a 100644 --- a/app/Controllers/PrintLabel.php +++ b/app/Controllers/PrintLabel.php @@ -31,6 +31,110 @@ class PrintLabel extends BaseController { return ['line1' => $line1, 'line2' => $line2]; } + public function labelPostekCollection($access) { + + $time = microtime(true); + $logTime = date('d-m-Y_H_i_s', $time) . sprintf('_%03d', ($time - floor($time)) * 1000); + $filename = "sample_".$logTime; + + $role = session()->get('userrole'); + $networkPath = ""; + + $db = \Config\Database::connect(); + $sql = "select p.PATNUMBER as UHID, sr.HOSTORDERNUMBER as BV, p.NAME, p.SEX, + DATEDIFF(YEAR, BirthDate, GETDATE()) - + CASE WHEN MONTH(BirthDate) > MONTH(GETDATE()) OR (MONTH(BirthDate) = MONTH(GETDATE()) AND DAY(BirthDate) > DAY(GETDATE())) THEN 1 + ELSE 0 END AS AGE, sr.COLLECTIONDATE + from SP_REQUESTS sr + left join SP_REQUESTS st on sr.SP_ACCESSNUMBER=st.SP_ACCESSNUMBER + left join PATIENTS p on p.PATID=sr.PATID + where st.SP_ACCESSNUMBER='$access'"; + $query = $db->query($sql); + $results = $query->getResultArray(); + $item = $results[0]; + + $uhid = substr($item['UHID'], -10); + $bv = $item['BV']; + $sex = $item['SEX'] == 1 ? "M" : "F"; + $title = $item['SEX'] == 1 ? "Mr" : "Mrs"; + $name = $item['NAME']; + $age = $item['AGE']; + $collectiondate = $item['COLLECTIONDATE']; + $date = \DateTime::createFromFormat('Y-m-d H:i:s.v', $collectiondate); + if ($date) { + $collectiondate = $date->format('d/m/Y H:i'); + } else { + $collectiondate = ""; + } + + $fixName = $this->splitName($name); + $name1 = $fixName['line1']; + $name2 = $fixName['line2']; + + if ($sex == 'M') { + $jarak = '42'; + } else { + $jarak = '53'; + } + + $label = "N +OD +q400 +Q200,10+0 +I8,A,001 +D10 +A4,3,0,2,1,1,N,\"$title.$name1\" +A$jarak,20,0,2,1,1,N,\"$name2\" +A325,25,0,2,1,1,N,\"$sex {$age}Y\" +B15,50,0,1,4,8,70,N,\"$access\" +A130,125,0,1,1,1,N,\"REQ# $access\" +A4,167,0,2,1,1,N,\"RM:$uhid\" +A4,150,0,2,1,1,N,\"VN:$bv\" +A195,167,0,2,1,1,N,\"$collectiondate\" + +P1 +"; + // Ruang Analis Printer POSTEK C168/200s + if ($role === 'admin' || $role === 'user') { + $printer = $this->printerLab(); + } else if ($role === 'sampling') { + $printer = $this->printerSampling(); + } else { + // Eksekusi Kode Berikut Apabila Role Bukan Analis atau Sampling + return $this->response->setJSON([ + 'message' => "Akses Tidak Berwenang", + 'error' => "Hak Akses Anda Tidak Dikenali", + 'status' => false, + ]); + } + + // $folder = "C:/data/"; + $folder = $printer[0]; + $fullPath = $folder . $filename; + + // Tulis file ke folder tujuan + if (!file_put_contents($fullPath, $label)) { + + //exec('net use '. $letterPath .' /delete 2>&1', $output, $return_var); + // Eksekusi Kode Berikut Apabila Ada Error + return $this->response->setJSON([ + 'error' => $output, + 'message' => "Gagal Melakukan Print, Mohon Ulangi Atau Cek Koneksi Printer Anda", + 'status' => false, + ]); + + } else { + + // Hapus Koneksi + //exec('net use '. $letterPath .' /delete 2>&1', $output, $return_var); + return $this->response->setJSON( [ + 'message' => "Print Berhasil!" , + 'status' => true, + ]); + } + + } + public function labelPostek($sample, $title, $name, $sex, $age, $barcode, $uhid, $bv, $collection_date) { $fixName = $this->splitName($name); $name1 = $fixName['line1']; @@ -183,7 +287,6 @@ P1 ]); } - // var_dump($printer);die(); // $folder = "C:/data/"; $folder = $printer[0]; $fullPath = $folder . $filename; diff --git a/app/Views/admin/dashboard_viewAccess.php b/app/Views/admin/dashboard_viewAccess.php index 7913701..10a40ee 100644 --- a/app/Views/admin/dashboard_viewAccess.php +++ b/app/Views/admin/dashboard_viewAccess.php @@ -56,10 +56,10 @@ $name = $row['NAME'];

Sample List

- + +
Coll. Recv. Sample Name Action Comment
All @@ -107,6 +107,26 @@ $name = $row['NAME'];