pbmc-cmod/app/Controllers/PrinterController.php

545 lines
17 KiB
PHP

<?php
namespace App\Controllers;
class PrinterController extends BaseController {
// Data ZPL untuk mencetak label
// $startSection = "^XA\n^PW400\n^LL224\n";
// $nameSection = "^FO10,2\n^A0N,23,23\n^FD MRS. I PUTU AYU PUTRI PERTIWI ^FS\n";
// $yearSection = "^FO12,25\n^A0N,22,22\n^FD F 24Y ^FS\n";
// $labelBarcodeSection = "^FO85,50\n^BY2,2.0,45\n^BCN,100,N,N,N\n^FD25082257^FS\n";
// $numberCodeSection = "^FO374,43\n^A0B,25,25\n^FD 25082257 ^FS\n";
// $sampleSection = "^FO19,45\n^A0B,27,27\n^FD $sample ^FS\n";
// $parameterSection = "^FO10,165\n^A0N,23,23\n^FD PSA, HDL, LDL, BUN, SGOT ^FS\n";
// $lisNumSection = "^FO10,195\n^A0N,17,20\n^FD LIS 4112082257 ^FS\n";
// $hisNumSection = "^FO10,210\n^A0N,20,20\n^FD HIS 01241101855 ^FS\n";
// $numSampleSection = "^FO240,200\n^A0N,27,27\n^FD $access 115 ^FS\n";
// $endSection = "^XZ";
public function printSingleSampleBarcode($access, $sample) {
$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, p.BIRTHDATE, st.SAMPLETYPE, ds.FULLTEXT, st.SAMPLETYPE+right(sr.SP_ACCESSNUMBER,5) as barcode
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.FULLTEXT = '$sample'";
$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'];
// Ruang Analis Printer POSTEK C168/200s
if ($role === 'admin' || $role === 'user') {
// Buka Mapping Drive PC Laboratorium
exec('net use L: \\\\10.148.5.20\\Labelshare /user:Administrator 2>&1', $output, $return_var);
$pathNetworkFolder = 'L:/Sampling_Labels/';
$letterPath = 'L:';
// Printer Posteck
$sampleLable ="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 USIA\"
A4,55,0,2,1,1,N,\"$sample\"
A4,75,0,2,1,1,N,\"Chapter\"
B149,35,0,1,3,8,70,N,\"$barcode\"
A199,110,0,2,1,1,N,\"LAB $barcode\"
A4,140,0,2,1,1,N,\"UH : $uhid\"
A4,160,0,2,1,1,N,\"BV : $bv\"
A195,156,0,2,1,1,N,\"Tgl Coll\"
P1
";
// Ruang Analis Printer Zebra
} else if ($role === 'sampling') {
// Buka Mapping Drive PC Sampling
exec('net use S: \\\\10.148.3.169\\Labelshare /user:Administrator 2>&1', $output, $return_var);
$pathNetworkFolder = 'S:/Sampling_Labels/';
$letterPath = 'S:';
// Printer Zebra
$sampleLable ="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 USIA\"
A4,55,0,2,1,1,N,\"$sample\"
A4,75,0,2,1,1,N,\"Chapter\"
B149,35,0,1,3,8,70,N,\"$barcode\"
A199,110,0,2,1,1,N,\"LAB $barcode\"
A4,140,0,2,1,1,N,\"UH : $uhid\"
A4,160,0,2,1,1,N,\"BV : $bv\"
A195,156,0,2,1,1,N,\"Tgl Coll\"
P1
";
} 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,
]);
}
$fullPath = $pathNetworkFolder . $filename;
// Tulis file ke folder tujuan
if (!file_put_contents($fullPath, $sampleLable)) {
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 printAllSampleBarcode($access) {
$role = session()->get('userrole');
$networkPath = "";
$db = \Config\Database::connect();
$sql = "select p.PATNUMBER as UHID, sr.HOSTORDERNUMBER as BV, p.NAME, p.SEX, p.BIRTHDATE, st.SAMPLETYPE, ds.FULLTEXT, st.SAMPLETYPE+right(sr.SP_ACCESSNUMBER,5) as barcode
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'";
$query = $db->query($sql);
$results = $query->getResultArray();
// Ruang Analis Printer POSTEK
if ($role === 'admin' || $role === 'user') {
// Buka Mapping Drive PC Laboratorium
exec('net use L: \\\\10.148.5.20\\Labelshare /user:Administrator 2>&1', $output, $return_var);
$pathNetworkFolder = 'L:/Sampling_Labels/';
$letterPath = 'L:';
// for ($i=0; $i<$data; $i++) {
foreach($results as $item) {
$time = microtime(true);
$logTime = date('d-m-Y_H_i_s', $time) . sprintf('_%03d', ($time - floor($time)) * 1000);
$filename = "sample_".$logTime;
$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'];
// Printer Posteck
$sampleLable ="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 USIA\"
A4,55,0,2,1,1,N,\"$sample\"
A4,75,0,2,1,1,N,\"Chapter\"
B149,35,0,1,3,8,70,N,\"$barcode\"
A199,110,0,2,1,1,N,\"LAB $barcode\"
A4,140,0,2,1,1,N,\"UH : $uhid\"
A4,160,0,2,1,1,N,\"BV : $bv\"
A195,156,0,2,1,1,N,\"Tgl Coll\"
P1
";
$fullPath = $pathNetworkFolder . $filename;
// Tulis file ke folder tujuan
if (!file_put_contents($fullPath, $sampleLable)) {
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,
]);
}
}
// Ruang Analis Printer Zebra
} else if ($role === 'sampling') {
// Buka Mapping Drive PC Sampling
exec('net use S: \\\\10.148.3.169\\Labelshare /user:Administrator 2>&1', $output, $return_var);
$pathNetworkFolder = 'S:/Sampling_Labels/';
$letterPath = 'S:';
foreach($results as $item) {
$time = microtime(true);
$logTime = date('d-m-Y_H_i_s', $time) . sprintf('_%03d', ($time - floor($time)) * 1000);
$filename = "sample_".$logTime;
$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'];
// Printer Zebra
$sampleLable ="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 USIA\"
A4,55,0,2,1,1,N,\"$sample\"
A4,75,0,2,1,1,N,\"Chapter\"
B149,35,0,1,3,8,70,N,\"$barcode\"
A199,110,0,2,1,1,N,\"LAB $barcode\"
A4,140,0,2,1,1,N,\"UH : $uhid\"
A4,160,0,2,1,1,N,\"BV : $bv\"
A195,156,0,2,1,1,N,\"Tgl Coll\"
P1
";
$fullPath = $pathNetworkFolder . $filename;
// Tulis file ke folder tujuan
if (!file_put_contents($fullPath, $sampleLable)) {
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 {
// 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,
]);
}
// Hapus Koneksi
exec('net use '. $letterPath .' /delete 2>&1', $output, $return_var);
return $this->response->setJSON(
[
'message' => "Print Berhasil",
'status' => true,
]
);
}
public function otherTests($access){
$fullPage="";
$headPage = "
<div id='page'>
<div id='pagetop' style='height:0.01cm'> </div>
<img src='".base_url()."assets/img/padma-header.png' class='img' />
<div id='dinfo'>
<table class='information t_center'>
<tr>
<th class='padmaColor' colspan='6' align='center'>CLINICAL LABORATORY</th>
</tr>
<tr>
<th style='width:12%' align='left'>UHID</th>
<td style='width:2%'>:</td>
<td style='width:44%'>1BCJJAJSDK</td>
<th style='width:20%' align='left'>Sample ID</th>
<td style='width:2%'>:</td>
<td style='width:20%'>LAB2420076951</td>
</tr>
<tr>
<th align='left'>Name</th>
<td>:</td>
<td>Ni Luh Putu Eka Putri Saraswati </td>
<th align='left'>Specimen</th>
<td>:</td>
<td>Serum</td>
</tr>
<tr>
<th align='left'>Age/Gender</th>
<td>:</td>
<td>22 year(s) / Male</td>
<th align='left'>Collection Date/Time</th>
<td>:</td>
<td>26-10-2024 / 11:55:04</td>
</tr>
<tr>
<th align='left'>Speciality</th>
<td>:</td>
<td></td>
<th align='left'>Result Date/Time</th>
<td>:</td>
<td>26-10-2024 / 11:52:04</td>
</tr>
</table>
</div>
<div id='dresult'>
<br>
<table class='result t_center'>
<tr align='left'>
<th class='padmaColor' style='width:35%'>Parameter</th>
<th class='padmaColor' style='width:14%'>Result</th>
<th class='padmaColor' style='width:14%'>Unit</th>
<th class='padmaColor' style='width:17%'>Normal Range</th>
<th class='padmaColor' style='width:20%'>Notes</th>
</tr>
";
$resultTest ="";
$item = end($access);
$resultNoteandSpecimen = "
<br>
<table class='result t_center'>
<tr>
<th align='left' class='padmaColor'>Notes</th>
</tr>
<tr>
<td>
".$item['RESVALUE']."
</td>
</tr>
</table>
<br>
<table class='t_center table_collection' >
<tr>
<td><pre>Collection datetime : - </pre></td>
</tr>
<tr>
<td><pre>Reception datetime : - </pre></td>
</tr>
</table>
";
$footerPage = "
<div id='footer'>
<table class='table_footer t_center'>
<tr>
<td></td>
<td align='right'><img src='http://cmod.id/assets/img/ttd.png' alt=''></td>
</tr>
<tr>
<td><u>Entered By</u></td>
<td align='right'><u>Verified By</u></td>
</tr>
<tr>
<td>Lab Technician</td>
<td align='right'>dr. I Komang Parwata Sp.PK</td>
</tr>
<tr>
<td>Mrs. Gst Ayu Riska Mastari</td>
<td align='right'>Reg. No: 570/SIPDS/0001/I/DPMPTSP/2023</td>
</tr>
</table>
</div>
";
$lastDiv="</div>";
$tempChapEng = "";
$tempChapInd = "";
array_pop($access);
$i=0;
foreach ($access as $item) {
if ($tempChapEng != $item['chap_eng']) {
$tempChapEng = $item['chap_eng'];
$tempChapInd = $item['chap_ind'];
$i++;
// Untuk Chapter
$resultTest .= "
<tr align='left' class='chapter'>
<td colspan='5'>
<pre><b>".$tempChapEng."</b></pre>
<pre> <small><b>".$tempChapInd."</b></small></pre>
</td>
</tr>
";
}
// Melebihi batas Kertas
if($i % 24 == 0) {
$resultTest .= "</table></div>";
$fullPage .= $headPage.$resultTest.$footerPage.$lastDiv;
$i=0;
$resultTest = "";
}
$i++;
if ($item['RESTYPE'] == "CE"){
$resvalue = $item['RESULT'];
} else {
$resvalue = $item['RESVALUE'];
}
$resultTest .= "
<tr>
<td colspan='1' class=''>
<pre> ".$item["test_eng"]."</pre>
<pre> <small>".$item["test_ind"]."</small></pre>
</td>
<td class=''>" . $resvalue . "</td>
<td class=''>" . $item["UNIT"] . "</td>
<td class=''>" . $item["REFRANGE"] . "</td>
<td class=''>" . " " . "</td>
</tr>
";
// Melebihi batas Kertas
if($i % 24 == 0) {
$resultTest .= "</table></div>";
$fullPage .= $headPage.$resultTest.$footerPage.$lastDiv;
$i=0;
$resultTest = "";
}
}
$resultTest .= "
</table>
".$resultNoteandSpecimen."
</div>";
$fullPage .= $headPage.$resultTest.$footerPage.$lastDiv;
return $fullPage;
}
public function printResultTest($access) {
$db = \Config\Database::connect();
$sql = "
select dc.CHAPID, dc.FULLTEXT as chap_eng,dc.FULLTEXT as chap_ind,
RESULT=case when cr.RESTYPE in('NM','TX') then cr.RESVALUE when cr.RESTYPE='CE' then tx.FULLTEXT end,
cr.*, cdt.TEXT1 as test_eng, cdt.TEXT2 as test_ind
from cmod.dbo.CM_RESULTS cr
left join REQUESTS r on r.ACCESSNUMBER=cr.ACCESSNUMBER
left join cmod.dbo.CM_DICT_TESTS cdt on cr.TESTCODE=cdt.TESTCODE
left join DICT_TESTS dt on dt.TESTCODE=cr.TESTCODE and dt.ENDVALIDDATE is null
left join TESTS t on t.REQUESTID = r.REQUESTID and t.TESTID=dt.TESTID
left join DICT_TEXTS tx on tx.TEXTID=t.CODEDRESULTID
left join DICT_CHAPTERS dc on dc.CHAPID=dt.CHAPID and dc.ENDVALIDDATE is null
left join cmod.dbo.CM_DICT_CHAPTERS cdc on cdc.CHAPCODE=dc.CHAPCODE
where cr.ACCESSNUMBER='$access'
ORDER BY
CASE
WHEN cr.TESTCODE = 'NOTE' THEN 1
ELSE 0
END,
t.TESTORDER;
";
$query = $db->query($sql);
$results = $query->getResultArray();
$data_urine = array_filter($results, function($item) {
$chapterid = $item["CHAPID"];
// Memfilter data dengan CHAPID 3, 61, atau 62
return $chapterid == 3 || $chapterid == 61 || $chapterid == 62;
});
// Seleksi data yang mengandung "FESES"
$data_feces = array_filter($results, function($item) {
$chapterid = $item["CHAPID"];
// Memfilter data yang 4
return $chapterid == 4;
});
// Seleksi data yang tidak mengandung "urine" dan "feces"
$data_others = array_filter($results, function($item) {
$chapterid = $item["CHAPID"];
// Memfilter data yang bukan 61 atau 3
return $chapterid !== 3 && $chapterid !== 4 && $chapterid !== 61 && $chapterid !== 62;
});
$fullPage = "";
if ($data_urine != null) {
$fullPage .= $this->otherTests($data_urine);
}
if ($data_feces != null) {
$fullPage .= $this->otherTests($data_feces);
}
if ($data_others != null) {
$fullPage .= $this->otherTests($data_others);
}
return view('result_report', ['data' => $fullPage]);
}
}