2024-12-09 13:10:16 +07:00
|
|
|
<?php
|
|
|
|
|
namespace App\Controllers;
|
|
|
|
|
|
|
|
|
|
class PrintLabel extends BaseController {
|
|
|
|
|
|
2025-03-07 01:02:05 +07:00
|
|
|
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() {
|
2025-06-25 12:47:55 +07:00
|
|
|
exec('net use K: \\\\10.148.5.68\\Labelshare /user:Administrator 2>&1', $output, $return_var);
|
|
|
|
|
$pathNetworkFolder = 'K:/Sampling_Labels/';
|
|
|
|
|
$letterPath = 'K:';
|
2025-03-07 01:02:05 +07:00
|
|
|
return array($pathNetworkFolder, $letterPath);
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-18 23:08:34 +08:00
|
|
|
public function splitName($fullName) {
|
|
|
|
|
$words = explode(' ', $fullName); // Pisahkan nama berdasarkan spasi
|
|
|
|
|
$line1 = '';
|
|
|
|
|
$line2 = '';
|
|
|
|
|
|
|
|
|
|
// Tambahkan kata-kata ke baris pertama hingga mencapai batas 20 karakter
|
|
|
|
|
foreach ($words as $word) {
|
|
|
|
|
if (strlen($line1 . ' ' . $word) <= 27) {
|
|
|
|
|
$line1 .= (empty($line1) ? '' : ' ') . $word;
|
|
|
|
|
} else {
|
|
|
|
|
// Setelah line1 penuh, pindahkan kata ke line2
|
|
|
|
|
if (strlen($line2 . ' ' . $word) <= 19) {
|
|
|
|
|
$line2 .= (empty($line2) ? '' : ' ') . $word;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Jika Line 2 lebih dari 19 karakter, hapus kata terakhir sampai sesuai
|
|
|
|
|
while (strlen($line2) > 19) {
|
|
|
|
|
$wordsLine2 = explode(' ', $line2);
|
|
|
|
|
array_pop($wordsLine2); // Hapus kata terakhir
|
|
|
|
|
$line2 = implode(' ', $wordsLine2); // Gabungkan kembali
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Kembalikan kedua baris sebagai array
|
|
|
|
|
return ['line1' => $line1, 'line2' => $line2];
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-26 11:17:40 +07:00
|
|
|
// Untuk Ruang Laboratorium
|
2025-03-07 01:02:05 +07:00
|
|
|
public function labelCollection($access) {
|
2024-12-19 09:23:12 +08:00
|
|
|
|
|
|
|
|
$time = microtime(true);
|
|
|
|
|
$logTime = date('d-m-Y_H_i_s', $time) . sprintf('_%03d', ($time - floor($time)) * 1000);
|
2025-03-07 01:02:05 +07:00
|
|
|
$filename = "collection(".$access.")_".$logTime;
|
2024-12-19 09:23:12 +08:00
|
|
|
|
|
|
|
|
$networkPath = "";
|
|
|
|
|
|
|
|
|
|
$db = \Config\Database::connect();
|
2025-03-15 14:30:09 +08:00
|
|
|
$sql = "SELECT p.PATNUMBER as UHID, ctr.REQNUMBER as BV, concat (p.FIRSTNAMESK, ' ', p.NAME) as NAME, p.SEX,
|
2024-12-19 09:23:12 +08:00
|
|
|
DATEDIFF(YEAR, BirthDate, GETDATE()) -
|
|
|
|
|
CASE WHEN MONTH(BirthDate) > MONTH(GETDATE()) OR (MONTH(BirthDate) = MONTH(GETDATE()) AND DAY(BirthDate) > DAY(GETDATE())) THEN 1
|
2025-02-26 11:17:40 +07:00
|
|
|
ELSE 0 END AS AGE, sr.COLLECTIONDATE, p.BIRTHDATE
|
2024-12-19 09:23:12 +08:00
|
|
|
from SP_REQUESTS sr
|
2025-03-15 13:51:02 +08:00
|
|
|
left join cmod.dbo.CM_TM_REQUESTS ctr on ctr.REFFID=sr.HOSTORDERNUMBER
|
2024-12-19 09:23:12 +08:00
|
|
|
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];
|
|
|
|
|
|
2025-03-15 13:51:02 +08:00
|
|
|
$uhid = ltrim($item['UHID'], '0');
|
2024-12-19 09:23:12 +08:00
|
|
|
$bv = $item['BV'];
|
|
|
|
|
$sex = $item['SEX'] == 1 ? "M" : "F";
|
|
|
|
|
$title = $item['SEX'] == 1 ? "Mr" : "Mrs";
|
|
|
|
|
$name = $item['NAME'];
|
|
|
|
|
$age = $item['AGE'];
|
2025-02-26 11:17:40 +07:00
|
|
|
$birthdate = $item['BIRTHDATE'];
|
|
|
|
|
$date = \DateTime::createFromFormat('Y-m-d H:i:s.v', $birthdate);
|
|
|
|
|
if ($date) {
|
|
|
|
|
$birthdate = $date->format('d/m/Y');
|
|
|
|
|
} else {
|
|
|
|
|
$birthdate = "";
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-19 09:23:12 +08:00
|
|
|
$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';
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-07 01:02:05 +07:00
|
|
|
$label="";
|
|
|
|
|
$role = session()->get('userrole');
|
2026-01-05 15:16:13 +07:00
|
|
|
// Ruang Analis Printer POSTEK C168/200s + 15 untuk sudut Y
|
2025-03-07 01:02:05 +07:00
|
|
|
if ($role == 'admin' || $role == 'user') {
|
|
|
|
|
$label = "N
|
2024-12-19 09:23:12 +08:00
|
|
|
OD
|
|
|
|
|
q400
|
|
|
|
|
Q200,10+0
|
|
|
|
|
I8,A,001
|
|
|
|
|
D10
|
2026-01-05 15:16:13 +07:00
|
|
|
A5,18,0,2,1,1,N,\"$title.$name1\"
|
|
|
|
|
A$jarak,35,0,2,1,1,N,\"$name2\"
|
|
|
|
|
A5,57,0,1,1,1,N,\"DoB: $birthdate\"
|
|
|
|
|
A337,57,0,1,1,1,N,\"$sex {$age}Y\"
|
|
|
|
|
B16,66,0,1,4,8,70,N,\"$access\"
|
|
|
|
|
A120,147,0,1,1,1,N,\"REQ# $access\"
|
|
|
|
|
A5,164,0,2,1,1,N,\"VN:$bv\"
|
|
|
|
|
A5,181,0,2,1,1,N,\"RM:$uhid\"
|
|
|
|
|
A195,181,0,2,1,1,N,\"$collectiondate\"
|
2024-12-19 09:23:12 +08:00
|
|
|
|
|
|
|
|
P1
|
|
|
|
|
";
|
|
|
|
|
$printer = $this->printerLab();
|
2025-03-07 01:02:05 +07:00
|
|
|
|
|
|
|
|
} else if ($role == 'sampling') {
|
|
|
|
|
$label = "N
|
|
|
|
|
OD
|
|
|
|
|
q400
|
|
|
|
|
Q185,10+0
|
|
|
|
|
I8,A,001
|
|
|
|
|
D10
|
|
|
|
|
A4,3,0,2,1,1,N,\"$title.$name1\"
|
|
|
|
|
A$jarak,20,0,2,1,1,N,\"$name2\"
|
|
|
|
|
A4,42,0,1,1,1,N,\"DoB: $birthdate\"
|
|
|
|
|
A337,42,0,1,1,1,N,\"$sex {$age}Y\"
|
|
|
|
|
B15,57,0,1,4,8,70,N,\"$access\"
|
|
|
|
|
A120,132,0,1,1,1,N,\"REQ# $access\"
|
|
|
|
|
A4,164,0,2,1,1,N,\"RM:$uhid\"
|
|
|
|
|
A4,147,0,2,1,1,N,\"VN:$bv\"
|
|
|
|
|
A195,164,0,2,1,1,N,\"$collectiondate\"
|
|
|
|
|
|
|
|
|
|
P1
|
|
|
|
|
";
|
2024-12-19 09:23:12 +08:00
|
|
|
$printer = $this->printerSampling();
|
2025-03-07 01:02:05 +07:00
|
|
|
|
2024-12-19 09:23:12 +08: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,
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// $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,
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-26 11:17:40 +07:00
|
|
|
// Untuk Ruang Laboratorium
|
|
|
|
|
public function labelPostek($sample, $title, $name, $sex, $age, $barcode, $uhid, $bv, $collection_date, $birthdate) {
|
2024-12-18 23:08:34 +08:00
|
|
|
$fixName = $this->splitName($name);
|
|
|
|
|
$name1 = $fixName['line1'];
|
|
|
|
|
$name2 = $fixName['line2'];
|
|
|
|
|
|
|
|
|
|
if ($sex == 'M') {
|
|
|
|
|
$jarak = '42';
|
|
|
|
|
} else {
|
|
|
|
|
$jarak = '53';
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-05 15:16:13 +07:00
|
|
|
// Printer Posteck + 15 untuk sudut Y
|
2024-12-09 13:10:16 +07:00
|
|
|
$sampleLabel ="N
|
|
|
|
|
OD
|
|
|
|
|
q400
|
|
|
|
|
Q200,10+0
|
|
|
|
|
I8,A,001
|
|
|
|
|
D10
|
2026-01-05 15:16:13 +07:00
|
|
|
A5,18,0,2,1,1,N,\"$title.$name1\"
|
|
|
|
|
A$jarak,35,0,2,1,1,N,\"$name2\"
|
|
|
|
|
A325,40,0,2,1,1,N,\"$sex {$age}Y\"
|
|
|
|
|
A5,62,0,2,1,1,N,\"$sample\"
|
|
|
|
|
A204,62,0,2,1,1,N,\"DoB: $birthdate\"
|
|
|
|
|
B37,83,0,1,4,8,70,N,\"$barcode\"
|
|
|
|
|
A115,158,0,2,1,1,N,\"SAM# $barcode\"
|
|
|
|
|
A5,180,0,2,1,1,N,\"RM:$uhid\"
|
|
|
|
|
A195,180,0,2,1,1,N,\"$collection_date\"
|
2024-12-09 13:10:16 +07:00
|
|
|
|
|
|
|
|
P1
|
|
|
|
|
";
|
|
|
|
|
return $sampleLabel;
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-26 11:17:40 +07:00
|
|
|
// Untuk Ruang Sampling
|
2025-03-07 01:02:05 +07:00
|
|
|
public function labelZebra($sample, $title, $name, $sex, $age, $barcode, $uhid, $bv, $collection_date, $birthdate) {
|
|
|
|
|
$fixName = $this->splitName($name);
|
|
|
|
|
$name1 = $fixName['line1'];
|
|
|
|
|
$name2 = $fixName['line2'];
|
|
|
|
|
|
|
|
|
|
if ($sex == 'M') {
|
|
|
|
|
$jarak = '42';
|
|
|
|
|
} else {
|
|
|
|
|
$jarak = '53';
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-09 13:10:16 +07:00
|
|
|
$sampleLabel ="N
|
|
|
|
|
OD
|
|
|
|
|
q400
|
|
|
|
|
Q185,10+0
|
|
|
|
|
I8,A,001
|
|
|
|
|
D10
|
2025-03-07 01:02:05 +07:00
|
|
|
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\"
|
|
|
|
|
A4,47,0,2,1,1,N,\"$sample\"
|
|
|
|
|
A204,47,0,2,1,1,N,\"DoB: $birthdate\"
|
|
|
|
|
B37,68,0,1,4,8,70,N,\"$barcode\"
|
|
|
|
|
A115,143,0,2,1,1,N,\"SAM# $barcode\"
|
|
|
|
|
A4,165,0,2,1,1,N,\"RM:$uhid\"
|
|
|
|
|
A195,165,0,2,1,1,N,\"$collection_date\"
|
2024-12-09 13:10:16 +07:00
|
|
|
|
|
|
|
|
P1
|
|
|
|
|
";
|
2025-03-07 01:02:05 +07:00
|
|
|
return $sampleLabel;
|
2024-12-09 13:10:16 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function printSingle($access, $sampletype) {
|
|
|
|
|
|
|
|
|
|
$time = microtime(true);
|
|
|
|
|
$logTime = date('d-m-Y_H_i_s', $time) . sprintf('_%03d', ($time - floor($time)) * 1000);
|
2025-03-07 01:02:05 +07:00
|
|
|
$filename = "sample(".$sampletype.")_".$logTime;
|
2024-12-09 13:10:16 +07:00
|
|
|
|
|
|
|
|
$role = session()->get('userrole');
|
|
|
|
|
$networkPath = "";
|
|
|
|
|
|
|
|
|
|
$db = \Config\Database::connect();
|
2025-02-26 11:17:40 +07:00
|
|
|
$sql = "select p.PATNUMBER as UHID, sr.HOSTORDERNUMBER as BV, concat (p.FIRSTNAMESK, ' ',p.NAME) as NAME, p.SEX,
|
2024-12-17 08:42:59 +08:00
|
|
|
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,
|
2025-03-15 12:55:40 +08:00
|
|
|
ds.SHORTTEXT AS FULLTEXT, st.SAMPLETYPE+right(sr.SP_ACCESSNUMBER,5) as BARCODE, sr.COLLECTIONDATE, p.BIRTHDATE
|
2024-12-17 08:42:59 +08:00
|
|
|
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];
|
|
|
|
|
|
2025-03-15 13:51:02 +08:00
|
|
|
$uhid = ltrim($item['UHID'], '0');
|
2024-12-09 13:10:16 +07:00
|
|
|
$bv = $item['BV'];
|
|
|
|
|
$sex = $item['SEX'] == 1 ? "M" : "F";
|
|
|
|
|
$title = $item['SEX'] == 1 ? "Mr" : "Mrs";
|
|
|
|
|
$name = $item['NAME'];
|
2024-12-18 09:29:45 +08:00
|
|
|
|
|
|
|
|
if ($sampletype == '200'){
|
|
|
|
|
$sample = 'SERUM KIMIA';
|
|
|
|
|
} else if ($sampletype == '250'){
|
|
|
|
|
$sample = 'SERUM IMUN';
|
|
|
|
|
} else {
|
|
|
|
|
$sample = $item['FULLTEXT'];
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-09 13:10:16 +07:00
|
|
|
$barcode = $item['BARCODE'];
|
|
|
|
|
$age = $item['AGE'];
|
2025-02-26 11:17:40 +07:00
|
|
|
$birthdate = $item['BIRTHDATE'];
|
|
|
|
|
$date = \DateTime::createFromFormat('Y-m-d H:i:s.v', $birthdate);
|
|
|
|
|
if ($date) {
|
|
|
|
|
$birthdate = $date->format('d/m/Y');
|
|
|
|
|
} else {
|
|
|
|
|
$birthdate = "";
|
|
|
|
|
}
|
2024-12-17 08:42:59 +08:00
|
|
|
$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') {
|
2024-12-16 09:03:51 +08:00
|
|
|
$printer = $this->printerLab();
|
2025-02-26 11:17:40 +07:00
|
|
|
$label = $this->labelPostek($sample, $title, $name, $sex, $age, $barcode, $uhid, $bv, $collectiondate, $birthdate);
|
2024-12-09 13:10:16 +07:00
|
|
|
} else if ($role === 'sampling') {
|
2024-12-16 09:03:51 +08:00
|
|
|
$printer = $this->printerSampling();
|
2025-03-07 01:02:05 +07:00
|
|
|
$label = $this->labelZebra($sample, $title, $name, $sex, $age, $barcode, $uhid, $bv, $collectiondate, $birthdate);
|
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,
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-16 09:03:51 +08:00
|
|
|
// $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( [
|
2024-12-17 08:42:59 +08:00
|
|
|
'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);
|
|
|
|
|
}
|
2025-03-07 01:02:05 +07:00
|
|
|
$this->labelCollection($access);
|
2024-12-09 13:10:16 +07:00
|
|
|
}
|
|
|
|
|
}
|