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'); } $resultdate = date('d-m-Y H:i', time()); } else { $sex =''; $accessnumber = ""; $rm_number = ""; $first_name = ""; $last_name = ""; $birth_date = ""; $hostordernumber = ""; $collection_date = ""; } $fullPage=""; $headPage = "
CLINICAL LABORATORY
RM Number : $rm_number Visit Number : $hostordernumber
First Name : $first_name Request Number : $accessnumber
Last Name : $last_name Order Date/Time : $collection_date
DoB/Gender : $birth_date / $sex Result Date/Time : $resultdate

"; $resultTest =""; $notes = end($resultData); $note = $notes['RESULT'] == "" ? "-" : $notes['RESULT']; // Untuk Collection if ($data[1] != null) { $colltext = ''; $recvtext = ''; $qcolldate = ''; $qcolltime = ''; $qrecvdate = ''; $qrecvtime = ''; foreach ($data[1] as $item) { $samp = $item['SHORTTEXT']; $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"; } } } 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"; } } } } } $resultNoteandSpecimen = "
Parameter Result Unit Normal Range Sample Type
Notes
".$note."

Collection datetime : $colltext
Reception datetime : $recvtext
"; $footerPage = " "; $lastDiv="
"; $tempChapEng = ""; $tempChapInd = ""; array_pop($resultData); $i=0; foreach ($resultData as $item) { $space=""; if ($item['DEPTH'] > 0) { $j=0; for ($j=0; $j<$item['DEPTH']; $j++) { $space .= " "; } } $resflag = $item["RESFLAG"] == "N" ? '' : $item["RESFLAG"]; if ($tempChapEng != $item['chap_eng']) { $tempChapEng = $item['chap_eng']; $tempChapInd = $item['chap_ind']; $i++; // Untuk Chapter $resultTest .= "
".$tempChapEng."
"; } // Melebihi batas Kertas if($i % 20 == 0) { $resultTest .= "
"; $fullPage .= $headPage.$resultTest.$footerPage.$lastDiv; $i=0; $resultTest = ""; } $i++; if ($item['RESTYPE'] == "CE"){ $resvalue = $item['RESULT']; } else { $resvalue = $item['RESVALUE']; } $reff = $item["REFRANGE"]; $refftext = $item["REFFTEXT"]; if($refftext !='') {$reff = $refftext;} $unit = $item['UNIT']; $unittext = $item['UNITTEXT']; if($unittext !='') {$unit = $unittext;} $resultTest .= "
 ".$space . $item["test_eng"]."
 ".$space."".$item["test_ind"]."
" . $resflag . " " . $resvalue . " " . $unit . " " . $reff . " " . $item["serum_type"] . " "; // Melebihi batas Kertas if($i % 21 == 0) { $resultTest .= ""; $fullPage .= $headPage.$resultTest.$footerPage.$lastDiv; $i=0; $resultTest = ""; } } $resultTest .= " ".$resultNoteandSpecimen." "; $fullPage .= $headPage.$resultTest.$footerPage.$lastDiv; return $fullPage; } public function printResultTest($access) { $db = \Config\Database::connect(); // 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]; // Untuk Collection $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 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; $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, cdt.UNIT as UNITTEXT, t.DEPTH, t.TESTORDER, dt.SHORTTEXT, RESULT = case when t.RESVALUE is null then tx.FULLTEXT else t.RESVALUE end, 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' ORDER BY t.TESTORDER "; $query = $db->query($sql); $results = $query->getResultArray(); $data_urine = array_filter($results, function($item) { $chapterid = $item["CHAPID"]; $tesscode = $item['TESTCODE']; // Memfilter data dengan CHAPID 3, 61, atau 62 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'; }); $fullPage = ""; if ($data_urine != null && count($data_urine) > 1) { $fullPage .= $this->otherTests($data_urine, $data); } if ($data_feces != null && count($data_feces) > 1) { $fullPage .= $this->otherTests($data_feces, $data); } if ($data_others != null && count($data_others) > 1) { $fullPage .= $this->otherTests($data_others, $data); } return view('result_report', ['data' => $fullPage]); } }