pbmc-cmod/app/Controllers/PrintResult.php

381 lines
11 KiB
PHP
Raw Normal View History

2024-12-09 13:10:16 +07:00
<?php
namespace App\Controllers;
class PrintResult extends BaseController {
2024-12-11 17:54:38 +08:00
public function otherTests($resultData, $data){
2024-12-09 13:10:16 +07:00
2024-12-11 17:54:38 +08:00
// var_dump($data);die();
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'];
$dateTime = \DateTime::createFromFormat('Y-m-d H:i:s.u', $birth_date);
if ($dateTime) {
$birth_date = $dateTime->format('d-m-Y');
}
$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:s');
}
} 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>
2024-12-11 17:54:38 +08:00
<td> </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:34%'>Parameter</th>
<th class='padmaColor' style='width:1%'> </th>
2024-12-11 17:54:38 +08:00
<th class='padmaColor' style='width:13%'>Result</th>
<th class='padmaColor' style='width:13%'>Unit</th>
<th class='padmaColor' style='width:20%'>Normal Range</th>
<th class='padmaColor' style='width:20%'>Sample Type</th>
2024-12-09 13:10:16 +07:00
</tr>
";
$resultTest ="";
$notes = end($resultData);
$note = $notes['RESULT'] == "" ? "-" : $notes['RESULT'];
2024-12-09 13:10:16 +07:00
2024-12-09 20:53:46 +08:00
// Untuk Collection
2024-12-11 17:54:38 +08:00
if ($data[1] != null) {
2024-12-09 20:53:46 +08:00
$cm_output = [];
$sp_output = [];
2024-12-11 17:54:38 +08:00
foreach ($data[1] as $item) {
2024-12-09 20:53:46 +08:00
$cm_output[] = "{$item['SHORTTEXT']} " . date('Y-m-d H:i:s', strtotime($item['CM_collection_datetime']));
$sp_output[] = "{$item['SHORTTEXT']} " . date('Y-m-d H:i:s', strtotime($item['SP_reception_datetime']));
}
$collectionText = implode(' | ', $cm_output) . "\n";
$receptionText = implode(' | ', $sp_output) . "\n";
}
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-11 17:54:38 +08:00
<td>Collection datetime : $collectionText </td>
2024-12-09 13:10:16 +07:00
</tr>
<tr>
2024-12-11 17:54:38 +08:00
<td>Reception datetime &nbsp;: $receptionText </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. Gst Ayu Riska Mastari</td>
<td align='right'>Reg. No: 570/SIPDS/0001/I/DPMPTSP/2023</td>
</tr>
</table>
</div>
";
$lastDiv="</div>";
$tempChapEng = "";
$tempChapInd = "";
2024-12-11 17:54:38 +08:00
array_pop($resultData);
2024-12-09 13:10:16 +07:00
$i=0;
2024-12-11 17:54:38 +08:00
foreach ($resultData as $item) {
2024-12-09 13:10:16 +07:00
$space="";
if ($item['DEPTH'] > 0) {
$j=0;
for ($j=0; $j<$item['DEPTH']; $j++) {
$space .= "&nbsp;";
}
}
$resflag = $item["RESFLAG"] == "N" ? '' : $item["RESFLAG"];
2024-12-09 13:10:16 +07:00
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>
</td>
</tr>
";
}
// Melebihi batas Kertas
if($i % 20 == 0) {
2024-12-09 13:10:16 +07:00
$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> ".$space . $item["test_eng"]."</pre>
<pre> ".$space."<small>".$item["test_ind"]."</small></pre>
2024-12-09 13:10:16 +07:00
</td>
<td class=''>" . $resflag . "</td>
2024-12-09 13:10:16 +07:00
<td class=''>" . $resvalue . "</td>
<td class=''>" . $item["UNIT"] . "</td>
<td class=''>" . $item["REFRANGE"] . "</td>
<td class=''>" . $item["serum_type"] . "</td>
2024-12-09 13:10:16 +07:00
</tr>
";
// Melebihi batas Kertas
2024-12-11 17:54:38 +08:00
if($i % 21 == 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
from PATIENTS p
left join SP_REQUESTS sr on p.PATID=sr.PATID
where sr.SP_ACCESSNUMBER='$access'";
$query = $db->query($sql);
$results = $query->getResultArray();
$header = $results[0];
2024-12-09 20:53:46 +08:00
// Untuk Collection
$sql = "select tu.SAMPLETYPE, ds.SHORTTEXT, tu.COLLECTIONDATE as CM_collection_datetime, ct.COLLECTIONDATE as SP_reception_datetime
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
where tu.SP_ACCESSNUMBER='$access'
";
$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;
// ";
$sql = "
select
dc.CHAPID,
dc.FULLTEXT as chap_eng,
dc.FULLTEXT as chap_ind,
st.FULLTEXT as serum_type,
cdt.TEXT1 as test_eng,
cdt.TEXT2 as test_ind,
t.DEPTH,
t.TESTORDER,
dt.SHORTTEXT,
RESULT = case when t.RESVALUE is null then tx.FULLTEXT else t.RESVALUE end,
cr.*
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'
ORDER BY t.TESTORDER
";
2024-12-09 13:10:16 +07:00
$query = $db->query($sql);
$results = $query->getResultArray();
2024-12-09 13:10:16 +07:00
$data_urine = array_filter($results, function($item) {
$chapterid = $item["CHAPID"];
$tesscode = $item['TESTCODE'];
// Memfilter data dengan CHAPID 3, 61, atau 62
2024-12-09 13:10:16 +07:00
return $chapterid == 3 || $chapterid == 61 || $chapterid == 62 || $tesscode == 'NOTE';
});
// Seleksi data yang mengandung "FESES"
$data_feces = array_filter($results, function($item) {
$chapterid = $item["CHAPID"];
$tesscode = $item['TESTCODE'];
// Memfilter data yang 4
return $chapterid == 4 || $tesscode == 'NOTE';
});
// Seleksi data yang tidak mengandung "urine" dan "feces"
$data_others = array_filter($results, function($item) {
$chapterid = $item["CHAPID"];
$tesscode = $item['TESTCODE'];
// Memfilter data yang bukan 61 atau 3
return $chapterid !== 3 && $chapterid !== 4 && $chapterid !== 61 && $chapterid !== 62 || $tesscode == 'NOTE';
});
2024-12-09 13:10:16 +07:00
$fullPage = "";
2024-12-09 13:10:16 +07:00
if ($data_urine != null && count($data_urine) > 1) {
2024-12-11 17:54:38 +08:00
$fullPage .= $this->otherTests($data_urine, $data);
2024-12-09 13:10:16 +07:00
}
if ($data_feces != null && count($data_feces) > 1) {
2024-12-11 17:54:38 +08:00
$fullPage .= $this->otherTests($data_feces, $data);
2024-12-09 13:10:16 +07:00
}
if ($data_others != null && count($data_others) > 1) {
2024-12-11 17:54:38 +08:00
$fullPage .= $this->otherTests($data_others, $data);
2024-12-09 13:10:16 +07:00
}
return view('result_report', ['data' => $fullPage]);
}
}