pbmc-cmod/app/Controllers/PrintLabel.php

158 lines
4.7 KiB
PHP
Raw Normal View History

2024-12-09 13:10:16 +07:00
<?php
namespace App\Controllers;
class PrintLabel extends BaseController {
public function labelPostek($sample, $title, $name, $sex, $age, $barcode, $uhid, $bv, $collection_date) {
2024-12-09 13:10:16 +07:00
// Printer Posteck
$sampleLabel ="N
OD
q400
Q200,10+0
I8,A,001
D10
A4,3,0,2,1,1,N,\"$title.$name\"
A4,25,0,2,1,1,N,\"$sex {$age}Y\"
A4,55,0,2,1,1,N,\"$sample\"
A4,75,0,2,1,1,N,\"Chapter\"
2024-12-09 13:10:16 +07:00
B149,35,0,1,3,8,70,N,\"$barcode\"
A195,110,0,2,1,1,N,\"SAM# $barcode\"
A4,140,0,2,1,1,N,\"RM : $uhid\"
A4,160,0,2,1,1,N,\"VN : $bv\"
A195,156,0,2,1,1,N,\"$collection_date\"
2024-12-09 13:10:16 +07:00
P1
";
return $sampleLabel;
}
public function labelZebra($sample, $title, $name, $sex, $age, $barcode, $uhid, $bv, $collection_date) {
2024-12-09 13:10:16 +07:00
$sampleLabel ="N
OD
q400
Q185,10+0
I8,A,001
D10
A4,3,0,2,1,1,N,\"$title.$name\"
A4,25,0,2,1,1,N,\"$sex {$age}Y\"
A4,55,0,2,1,1,N,\"$sample\"
A4,75,0,2,1,1,N,\"Chapter\"
2024-12-09 13:10:16 +07:00
B149,35,0,1,3,8,70,N,\"$barcode\"
A195,110,0,2,1,1,N,\"SAM# $barcode\"
A4,140,0,2,1,1,N,\"RM : $uhid\"
A4,160,0,2,1,1,N,\"VN : $bv\"
A195,156,0,2,1,1,N,\"$collection_date\"
2024-12-09 13:10:16 +07:00
P1
";
}
public function printerLab() {
exec('net use L: \\\\10.148.5.20\\Labelshare /user:Administrator 2>&1', $output, $return_var);
$pathNetworkFolder = 'L:/Sampling_Labels/';
$letterPath = 'L:';
return array($pathNetworkFolder, $letterPath);
}
public function printerSampling() {
exec('net use S: \\\\10.148.3.169\\Labelshare /user:Administrator 2>&1', $output, $return_var);
$pathNetworkFolder = 'S:/Sampling_Labels/';
$letterPath = 'S:';
return array($pathNetworkFolder, $letterPath);
}
public function printSingle($access, $sampletype) {
$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,
ds.FULLTEXT, st.SAMPLETYPE+right(sr.SP_ACCESSNUMBER,5) as BARCODE, sr.COLLECTIONDATE
from SP_TUBES st
left join SP_REQUESTS sr on st.SP_ACCESSNUMBER=sr.SP_ACCESSNUMBER
left join PATIENTS p on p.PATID=sr.PATID
left join DICT_SAMPLES_TYPES ds on ds.SAMPCODE=st.SAMPLETYPE
where st.SP_ACCESSNUMBER='$access' AND ds.SAMPCODE = '$sampletype'";
2024-12-09 13:10:16 +07:00
$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'];
$sample = $item['FULLTEXT'];
$barcode = $item['BARCODE'];
$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 = "";
}
2024-12-09 13:10:16 +07:00
// Ruang Analis Printer POSTEK C168/200s
if ($role === 'admin' || $role === 'user') {
$printer = $this->printerLab();
$label = $this->labelPostek($sample, $title, $name, $sex, $age, $barcode, $uhid, $bv, $collectiondate);
2024-12-09 13:10:16 +07:00
} else if ($role === 'sampling') {
$printer = $this->printerSampling();
$label = $this->labelZebra($sample, $title, $name, $sex, $age, $barcode, $uhid, $bv, $collectiondate);
2024-12-09 13:10:16 +07:00
} 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,
]);
}
// var_dump($printer);die();
// $folder = "C:/data/";
$folder = $printer[0];
2024-12-09 13:10:16 +07:00
$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!" ,
2024-12-09 13:10:16 +07:00
'status' => true,
]);
}
}
public function printAll($access) {
$db = \Config\Database::connect();
$sql = "select SAMPLETYPE from SP_TUBES where SP_ACCESSNUMBER='$access'";
$query = $db->query($sql);
$results = $query->getResultArray();
foreach($results as $data) {
$sample = $data['SAMPLETYPE'];
$this->printSingle($access, $sample);
}
}
}