pbmc-cmod/app/Controllers/PrintResult.php

518 lines
16 KiB
PHP
Raw Normal View History

2024-12-09 13:10:16 +07:00
<?php
namespace App\Controllers;
class PrintResult extends BaseController {
2025-01-02 16:14:56 +07:00
public function otherTests($resultData, $data, $note){
2024-12-09 13:10:16 +07:00
2024-12-11 17:54:38 +08:00
if($data[0] != null) {
$accessnumber = $data[0]['SP_ACCESSNUMBER'];
$sex = $data[0]['sex'] == 1 ? "Male" : "Female";
$rm_number = $data[0]['PATNUMBER'];
$rm_number = substr($rm_number, -10);
$first_name = $data[0]['FIRSTNAME'];
$last_name = $data[0]['NAME'];
$birth_date = $data[0]['BIRTHDATE'];
$birth_date = \DateTime::createFromFormat('Y-m-d H:i:s.u', $birth_date);
if ($birth_date) { $birth_date = $birth_date->format('d-m-Y'); }
2024-12-11 17:54:38 +08:00
$hostordernumber = $data[0]['HOSTORDERNUMBER'];
$collection_date = $data[0]['COLLECTIONDATE'];
$dateTime = \DateTime::createFromFormat('Y-m-d H:i:s.u', $collection_date);
if ($dateTime) {
$collection_date = $dateTime->format('d-m-Y H:i');
2024-12-11 17:54:38 +08:00
}
$resultdate = date('d-m-Y H:i', time());
2024-12-11 17:54:38 +08:00
} else {
$sex ='';
$accessnumber = "";
$rm_number = "";
$first_name = "";
$last_name = "";
$birth_date = "";
$hostordernumber = "";
$collection_date = "";
}
2024-12-09 13:10:16 +07:00
$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>
2024-12-11 17:54:38 +08:00
2024-12-09 13:10:16 +07:00
<tr>
2024-12-11 17:54:38 +08:00
<th style='width:18%' align='left'>RM Number</th>
2024-12-09 13:10:16 +07:00
<td style='width:2%'>:</td>
2024-12-11 17:54:38 +08:00
<td style='width:35%'>$rm_number</td>
<th style='width:18%' align='left'>Visit Number</th>
2024-12-09 13:10:16 +07:00
<td style='width:2%'>:</td>
2024-12-11 17:54:38 +08:00
<td style='width:35%'>$hostordernumber</td>
2024-12-09 13:10:16 +07:00
</tr>
<tr>
2024-12-11 17:54:38 +08:00
<th align='left'>First Name</th>
2024-12-09 13:10:16 +07:00
<td>:</td>
2024-12-11 17:54:38 +08:00
<td>$first_name</td>
<th align='left'>Request Number</th>
2024-12-09 13:10:16 +07:00
<td>:</td>
2024-12-11 17:54:38 +08:00
<td>$accessnumber</td>
2024-12-09 13:10:16 +07:00
</tr>
<tr>
2024-12-11 17:54:38 +08:00
<th align='left'>Last Name</th>
2024-12-09 13:10:16 +07:00
<td>:</td>
2024-12-11 17:54:38 +08:00
<td>$last_name</td>
<th align='left'>Order Date/Time</th>
2024-12-09 13:10:16 +07:00
<td>:</td>
2024-12-11 17:54:38 +08:00
<td>$collection_date</td>
2024-12-09 13:10:16 +07:00
</tr>
<tr>
2024-12-11 17:54:38 +08:00
<th align='left'>DoB/Gender</th>
2024-12-09 13:10:16 +07:00
<td>:</td>
2024-12-11 17:54:38 +08:00
<td>$birth_date / $sex</td>
2024-12-09 13:10:16 +07:00
<th align='left'>Result Date/Time</th>
<td>:</td>
<td>$resultdate</td>
2024-12-09 13:10:16 +07:00
</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:1%'> </th>
<th class='padmaColor' style='width:23%'>Result</th>
<th class='padmaColor' style='width:14%'>Unit</th>
<th class='padmaColor' style='width:19%'>Normal Range</th>
<th class='padmaColor' style='width:9%'>Sample</th>
2024-12-09 13:10:16 +07:00
</tr>
";
$resultTest ="";
2024-12-09 20:53:46 +08:00
// Untuk Collection
2024-12-19 08:13:27 +07:00
if ($data[1] != null) {
$colltext = '';
$recvtext = '';
$qcolldate = '';
$qcolltime = '';
$qrecvdate = '';
$qrecvtime = '';
2024-12-11 17:54:38 +08:00
foreach ($data[1] as $item) {
$samp = $item['SHORTTEXT'];
2024-12-19 08:13:27 +07:00
$colldate = $item['colldate'];
$recvdate = $item['recvdate'];
$colltime = $item['colltime'];
$recvtime = $item['recvtime'];
if($colldate !='') {
if($colldate != $qcolldate) { $colltext .= "$colldate $colltime $samp"; $qcolldate = $colldate; $qcolltime = $colltime; }
else {
if($colltime != $qcolltime) { $colltext .= ", $colltime $samp"; $qcolltime = $colltime; }
else { $colltext .= ", $samp"; }
}
}
2024-12-19 08:13:27 +07:00
if($recvdate !='') {
if($recvdate != $qrecvdate) { $recvtext .= "$recvdate $recvtime $samp"; $qrecvdate = $recvdate; $qrecvtime = $recvtime; }
else {
if($recvtime != $qrecvtime) { $recvtext .= ", $recvtime $samp"; $qrecvtime = $recvtime; }
else { $recvtext .= ", $samp"; }
}
}
}
2024-12-09 20:53:46 +08:00
}
2024-12-09 13:10:16 +07:00
$resultNoteandSpecimen = "
<br>
<table class='result t_center'>
<tr>
<th align='left' class='padmaColor'>Notes</th>
</tr>
<tr>
<td>
".$note."
2024-12-09 13:10:16 +07:00
</td>
</tr>
</table>
<br>
2024-12-11 17:54:38 +08:00
2024-12-09 13:10:16 +07:00
<table class='t_center table_collection' >
<tr>
2024-12-30 09:29:14 +07:00
<td width='15%'>Collection datetime : </td>
<td>$colltext</td>
2024-12-09 13:10:16 +07:00
</tr>
<tr>
2024-12-30 09:29:14 +07:00
<td>Reception datetime : </td>
<td>$recvtext</td>
2024-12-09 13:10:16 +07:00
</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. Gusti Ayu Riska Mastari</td>
2024-12-09 13:10:16 +07:00
<td align='right'>Reg. No: 570/SIPDS/0001/I/DPMPTSP/2023</td>
</tr>
</table>
</div>
";
$lastDiv="</div>";
$tempChapEng = "";
$tempChapInd = "";
$i=0;
2024-12-11 17:54:38 +08:00
foreach ($resultData as $item) {
2024-12-09 13:10:16 +07:00
2025-01-02 16:14:56 +07:00
// Untuk Spasi Depth
$space="";
2024-12-30 09:29:14 +07:00
if ($item['RESULT'] != null) {
$j=0;
2024-12-30 09:29:14 +07:00
$space.="&nbsp;";
for ($j=0; $j<=$item['DEPTH']; $j++) {
$space .= "&nbsp;&nbsp;";
}
if ($item['DEPTH']==0){
$space.="&nbsp;";
}
} else {
for ($j=0; $j<=$item['DEPTH']; $j++) {
$space .= "&nbsp;&nbsp;";
}
2024-12-30 09:29:14 +07:00
}
2025-01-02 16:14:56 +07:00
// Untuk Penamaan Serum Khusus test
2024-12-30 09:29:14 +07:00
if ($item["RESULT"] == null) {
$serum_type = "";
}else {
$serum_type = $item["serum_type"];
}
$resflag = $item["RESFLAG"] == "N" ? '' : $item["RESFLAG"];
2025-01-02 16:14:56 +07:00
2024-12-09 13:10:16 +07:00
if ($tempChapEng != $item['chap_eng']) {
$tempChapEng = $item['chap_eng'];
$tempChapInd = $item['chap_ind'];
$i++;
2025-01-02 16:14:56 +07:00
// Melebihi batas Kertas
if($i % 28 == 0) {
2025-01-02 16:14:56 +07:00
$resultTest .= "</table></div>";
$fullPage .= $headPage.$resultTest.$footerPage.$lastDiv;
$i=0;
$resultTest = "";
}
if($i==0){
$i++;
}
// Untuk Chapter
$resultTest .= "
<tr align='left' class='chapter'>
<td colspan='5'>
<pre><b>".$tempChapEng."</b></pre>
2024-12-30 09:29:14 +07:00
<!-- <pre><b>".$i.". ".$tempChapEng."</b></pre> -->
2025-01-02 16:14:56 +07:00
</td>
</tr>
";
2024-12-09 13:10:16 +07:00
}
2025-01-02 16:14:56 +07:00
// Melebihi batas Kertas
if($i % 28 == 0 && $i!=0) {
2025-01-02 16:14:56 +07:00
$resultTest .= "</table></div>";
$fullPage .= $headPage.$resultTest.$footerPage.$lastDiv;
$i=0;
$resultTest = "";
}
2024-12-09 13:10:16 +07:00
$i++;
if ($item['RESTYPE'] == "CE"){
$resvalue = $item['RESULT'];
2025-01-02 16:14:56 +07:00
} else if ($item['RESTYPE'] == null) {
$resvalue = $item['RESULT'];
} else {
2024-12-09 13:10:16 +07:00
$resvalue = $item['RESVALUE'];
}
2024-12-17 09:52:07 +07:00
$reff = $item["REFRANGE"];
$refftext = $item["REFFTEXT"];
if($refftext !='') {$reff = $refftext;}
2024-12-19 08:13:27 +07:00
$unit = $item['UNIT'];
$unittext = $item['UNITTEXT'];
if($unittext !='') {$unit = $unittext;}
$color = "";
if($resflag == 'L' || $resflag == 'H'){
$color = "red_font";
}
2025-01-06 16:39:12 +07:00
$test = "";
// Untuk Nama Test Apakah lebih dari 24 karakter
if ( strlen($item['test_eng']) > 24 || strlen($item['test_ind']) > 24) {
2025-01-06 16:39:12 +07:00
$test = "<pre>" . $space . $item["test_eng"]."<br>$space<small><i>".$item["test_ind"]."</i></small></pre>";
} else {
$test = "<pre>" . $space . $item["test_eng"]." "."<small><i>".$item["test_ind"]."</i></small></pre>";
}
if ($item['code_type'] == 5) {
$resultTest .= "
<tr>
<td colspan='1' class=''>
2025-01-06 16:39:12 +07:00
".$test."
</td>
<td class='".$color."'>" . $resflag . "</td>
2025-01-06 16:39:12 +07:00
<td colspan='3' class='".$color."'>" . $resvalue . "</td>
<td class=''>" . $serum_type . "</td>
</tr>
";
} else {
$resultTest .= "
<tr>
<td colspan='1' class=''>
2025-01-06 16:39:12 +07:00
".$test."
</td>
<td class='".$color."'>" . $resflag . "</td>
<td class='".$color."'>" . $resvalue . "</td>
<td class=''>" . $unit . "</td>
<td class=''>" . $reff . "</td>
<td class=''>" . $serum_type . "</td>
</tr>
";
}
2025-01-06 16:39:12 +07:00
2024-12-09 13:10:16 +07:00
// Melebihi batas Kertas
if($i % 28 == 0 && $i != 0) {
2024-12-09 13:10:16 +07:00
$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();
2024-12-09 20:53:46 +08:00
2024-12-11 17:54:38 +08:00
// Untuk Header
$sql = "select p.PATNUMBER, p.FIRSTNAME, p.NAME, p.BIRTHDATE, sr.HOSTORDERNUMBER, sr.COLLECTIONDATE, sr.SP_ACCESSNUMBER, p.sex
2024-12-19 08:13:27 +07:00
from PATIENTS p
left join SP_REQUESTS sr on p.PATID=sr.PATID
where sr.SP_ACCESSNUMBER='$access'";
2024-12-11 17:54:38 +08:00
$query = $db->query($sql);
$results = $query->getResultArray();
$header = $results[0];
2024-12-09 20:53:46 +08:00
// Untuk Collection
2024-12-19 08:13:27 +07:00
$sql = "select ds.SHORTTEXT,
format(tu.COLLECTIONDATE, 'dd-MM-yyyy') as recvdate, format(tu.COLLECTIONDATE, 'hh:mm') as recvtime,
format(ct.COLLECTIONDATE, 'dd-MM-yyyy') as colldate, format(ct.COLLECTIONDATE, 'hh:mm') as colltime
2024-12-09 20:53:46 +08:00
from SP_TUBES tu
left join DICT_SAMPLES_TYPES ds on ds.SAMPCODE= tu.SAMPLETYPE
left join cmod.dbo.CM_TUBES ct on ct.SAMPLETYPE=tu.SAMPLETYPE and ct.ACCESSNUMBER=tu.SP_ACCESSNUMBER
2024-12-19 08:13:27 +07:00
where tu.SP_ACCESSNUMBER='$access'";
2024-12-09 20:53:46 +08:00
$query = $db->query($sql);
$results = $query->getResultArray();
$collection = $results;
2024-12-11 17:54:38 +08:00
$data = [$header, $collection];
// var_dump($data[0]['PATNUMBER']);die();
// BACKUP
// $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;
// ";
2025-01-06 16:39:12 +07:00
$sql = "
select
dc.CHAPID,
dc.FULLTEXT as chap_eng,
dc.FULLTEXT as chap_ind,
st.FULLTEXT as serum_type,
cdt.TEXT1 as test_eng,
2024-12-19 08:13:27 +07:00
cdt.TEXT2 as test_ind,
cdt.UNIT as UNITTEXT,
t.DEPTH,
t.NOTPRINTABLE,
t.TESTORDER,
dt.SHORTTEXT,
2025-01-06 16:39:12 +07:00
t.RESTYPE as code_type,
RESULT = case when t.RESVALUE is null then tx.FULLTEXT else t.RESVALUE end,
2024-12-17 09:52:07 +07:00
cr.*, cdt.REFFTEXT
from REQUESTS r
left join TESTS t on t.REQUESTID = r.REQUESTID
left join DICT_TESTS dt on dt.ENDVALIDDATE is null 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 DICT_TEST_SAMPLES ts on ts.TESTID=t.TESTID and dt.TESTID=ts.TESTID
left join DICT_SAMPLES_TYPES st on st.SAMPTYPEID=ts.SAMPTYPEID
left join cmod.dbo.CM_DICT_TESTS cdt on dt.TESTCODE=cdt.TESTCODE
left join cmod.dbo.CM_RESULTS cr on cr.ACCESSNUMBER=r.ACCESSNUMBER and cr.TESTCODE=cdt.TESTCODE and cr.TESTCODE=dt.TESTCODE
where r.ACCESSNUMBER='$access'
2025-01-02 16:14:56 +07:00
ORDER BY t.TESTORDER
";
2024-12-09 13:10:16 +07:00
$query = $db->query($sql);
$results = $query->getResultArray();
2025-01-06 16:39:12 +07:00
2024-12-30 11:26:28 +07:00
$data_pregnancy = array_filter($results, function($item) {
$serum_type = $item["serum_type"];
$tesscode = $item["TESTCODE"];
2025-01-02 16:14:56 +07:00
$test_eng = $item["test_eng"];
$printable = $item['NOTPRINTABLE'];
return $serum_type == 'Urine' && ($tesscode == 'PPT' || $test_eng == "Pregnancy Test") && $printable !=1;
2024-12-30 11:26:28 +07:00
});
2024-12-30 09:29:14 +07:00
$data_urine_lengkap = array_filter($results, function($item) {
$serum_type = $item["serum_type"];
2024-12-30 11:26:28 +07:00
$tesscode = $item["TESTCODE"];
2025-01-02 16:14:56 +07:00
$test_eng = $item["test_eng"];
$chap_eng = $item["chap_eng"];
$printable = $item['NOTPRINTABLE'];
return $serum_type == 'Urine' && $tesscode != 'PPT' && $test_eng != "Pregnancy Test" && $chap_eng != "MICROBIOLOGY" && $printable !=1;
2025-01-02 16:14:56 +07:00
});
$data_urine_kultur = array_filter($results, function($item) {
$serum_type = $item["serum_type"];
$chap_eng = $item["chap_eng"];
$printable = $item['NOTPRINTABLE'];
return $serum_type == 'Urine' && $chap_eng == "MICROBIOLOGY" && $printable !=1;
2024-12-09 13:10:16 +07:00
});
2024-12-30 11:26:28 +07:00
$data_feces_stc2 = array_filter($results, function($item) {
2024-12-30 09:29:14 +07:00
$serum_type = $item["serum_type"];
2024-12-30 11:26:28 +07:00
$tesscode = $item["TESTCODE"];
$printable = $item['NOTPRINTABLE'];
return $serum_type == 'Feces' && in_array($tesscode, ['STC2', 'SCSAL', 'SCSHI']) && $printable !=1;
2024-12-30 11:26:28 +07:00
});
$data_feces_stc4 = array_filter($results, function($item) {
$serum_type = $item["serum_type"];
$tesscode = $item["TESTCODE"];
$printable = $item['NOTPRINTABLE'];
return $serum_type == 'Feces' && in_array($tesscode, ['STC4', 'FCSAL', 'FCSHI', 'FCVIB', 'FCESC']) && $printable !=1;
2024-12-09 13:10:16 +07:00
});
2024-12-30 09:29:14 +07:00
$data_feces_lengkap = array_filter($results, function($item) {
$serum_type = $item["serum_type"];
2024-12-30 11:26:28 +07:00
$tesscode = $item["TESTCODE"];
$printable = $item['NOTPRINTABLE'];
return $serum_type == 'Feces' && !in_array($tesscode, ['STC2', 'SCSAL', 'SCSHI', 'STC4', 'FCSAL', 'FCSHI', 'FCVIB', 'FCESC']) && $printable !=1;
});
$data_RCS = array_filter($results, function($item) {
$serum_type = $item["serum_type"];
$printable = $item['NOTPRINTABLE'];
return $serum_type == 'Swab Tenggorokan' && $printable !=1;
2024-12-30 09:29:14 +07:00
});
$data_others = array_filter($results, function($item) {
$serum_type = $item["serum_type"];
$chapter_eng = $item['chap_eng'];
$printable = $item['NOTPRINTABLE'];
return $serum_type != 'Feces' && $serum_type != 'Urine' && $chapter_eng != 'Note' && $serum_type != 'Swab Tenggorokan' && $printable !=1;
2024-12-09 13:10:16 +07:00
});
2025-01-02 16:14:56 +07:00
$notes = array_filter($results, function($item) {
$chap_id = $item["CHAPID"];
$chap_eng = $item["chap_eng"];
return $chap_id == 54 && $chap_eng == "Note";
});
// Mengambil elemen pertama dari hasil filter
$notes = reset($notes); // Ambil elemen pertama
$note = $notes["RESULT"] ?? "-"; // Ambil nilai RESULT, atau null jika tidak ada
2024-12-09 13:10:16 +07:00
$fullPage = "";
2025-01-02 16:14:56 +07:00
if ($data_others != null) {
$fullPage .= $this->otherTests($data_others, $data, $note);
}
if ($data_RCS != null) {
$fullPage .= $this->otherTests($data_RCS, $data, $note);
}
2025-01-02 16:14:56 +07:00
if ($data_urine_kultur != null) {
$fullPage .= $this->otherTests($data_urine_kultur, $data, $note);
2024-12-30 09:29:14 +07:00
}
2024-12-30 11:26:28 +07:00
if ($data_pregnancy != null) {
2025-01-02 16:14:56 +07:00
$fullPage .= $this->otherTests($data_pregnancy, $data, $note);
2024-12-09 13:10:16 +07:00
}
2025-01-02 16:14:56 +07:00
if ($data_urine_lengkap != null) {
$fullPage .= $this->otherTests($data_urine_lengkap, $data, $note);
2024-12-09 13:10:16 +07:00
}
2025-01-02 16:14:56 +07:00
if ($data_feces_stc2 != null) {
$fullPage .= $this->otherTests($data_feces_stc2, $data, $note);
2024-12-30 11:26:28 +07:00
}
if ($data_feces_stc4 != null) {
2025-01-02 16:14:56 +07:00
$fullPage .= $this->otherTests($data_feces_stc4, $data, $note);
2024-12-30 11:26:28 +07:00
}
2025-01-02 16:14:56 +07:00
if ($data_feces_lengkap != null) {
$fullPage .= $this->otherTests($data_feces_lengkap, $data, $note);
2024-12-09 13:10:16 +07:00
}
2025-01-02 16:14:56 +07:00
2024-12-09 13:10:16 +07:00
return view('result_report', ['data' => $fullPage]);
}
}