get('usercityid'); if ($cityid == 1) { $doctor = "dr. I Komang Parwata Sp.PK"; $analyst = "Mrs. Gusti Ayu Riska Mastari"; $noreg = "Reg. No: 570/SIPDS/0001/I/DPMPTSP/2023"; $signature = ""; } elseif ($cityid == 2) { $doctor = "dr. I.G.A.A Putri Sri Rejeki, Sp.PK"; $noreg = "SIP : 503.446/1091/B/IP.DS/436.7.15/2022"; $signature = ""; // Digunakan untuk mengetahui user yang melakukan Validasi khusus analis surabaya $uservalidator = $resultData[0]['validator']; if ($uservalidator == "MG") { $analyst = "Mrs. Mega Rahayu Ningsih"; } else if ($uservalidator == "ACP") { $analyst = "Mrs. Afrita Catur Pratiwi"; } else { $analyst = "-"; } } else { $doctor = " "; $noreg = " "; } 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'); } $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 =""; // 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
Notes
".$note."

Collection datetime : $colltext
Reception datetime : $recvtext
"; $footerPage = " "; $lastDiv="
"; $tempChapEng = ""; $tempChapInd = ""; $i=0; foreach ($resultData as $item) { // Untuk Spasi Depth $space=""; if ($item['RESULT'] != null) { $j=0; $space.=" "; for ($j=0; $j<=$item['DEPTH']; $j++) { $space .= "  "; } if ($item['DEPTH']==0){ $space.=" "; } } else { for ($j=0; $j<=$item['DEPTH']; $j++) { $space .= "  "; } } // Untuk Penamaan Serum Khusus test if ($item["RESULT"] == null) { $serum_type = ""; }else { $serum_type = $item["serum_type"]; } $resflag = $item["RESFLAG"] == "N" ? '' : $item["RESFLAG"]; if ($tempChapEng != $item['chap_eng']) { $tempChapEng = $item['chap_eng']; $tempChapInd = $item['chap_ind']; $i++; // Melebihi batas Kertas if($i % 28 == 0) { $resultTest .= "
"; $fullPage .= $headPage.$resultTest.$footerPage.$lastDiv; $i=0; $resultTest = ""; } if($i==0){ $i++; } // Untuk Chapter $resultTest .= "
".$tempChapEng."
"; } // Melebihi batas Kertas if($i % 28 == 0 && $i!=0) { $resultTest .= ""; $fullPage .= $headPage.$resultTest.$footerPage.$lastDiv; $i=0; $resultTest = ""; } $i++; if ($item['RESTYPE'] == "CE"){ $resvalue = $item['RESULT']; } else if ($item['RESTYPE'] == null) { $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;} // Untuk mewarnai value yang tidak beda dengan nilai normal $color = ""; if ($resflag == 'L' || $resflag == 'H') { $color = "red_font"; } // Untuk mewarnai value yang tidak sama dengan nilai normal if ($item['RESULT'] != $item['REFFTEXT'] && $item['code_type'] == 6 && $item['REFFTEXT'] != null) { $color = "red_font"; } $test = ""; // Untuk Nama Test Apakah lebih dari 24 karaktera if ( strlen($item['test_eng']) > 24 || strlen($item['test_ind']) > 24) { $test = "
" . $space . $item["test_eng"]."
$space".$item["test_ind"]."
"; } else { $test = "
" . $space . $item["test_eng"]." "."".$item["test_ind"]."
"; } if ($item['code_type'] == 5) { $resultTest .= " ".$test." " . $resflag . " " . $resvalue . " " . $serum_type . " "; } else { $resultTest .= " ".$test." " . $resflag . " " . $resvalue . " " . $unit . " " . $reff . " " . $serum_type . " "; } // Melebihi batas Kertas if($i % 28 == 0 && $i != 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, cdt.REFFTEXT, t.DEPTH, t.NOTPRINTABLE, t.TESTORDER, t.RESTYPE as code_type, t.VALIDATIONINITIALS as validator, 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 "; $query = $db->query($sql); $results = $query->getResultArray(); $data_pregnancy = array_filter($results, function($item) { $serum_type = $item["serum_type"]; $tesscode = $item["TESTCODE"]; $test_eng = $item["test_eng"]; $printable = $item['NOTPRINTABLE']; return $serum_type == 'Urine' && ($tesscode == 'PPT' || $test_eng == "Pregnancy Test") && $printable !=1; }); $data_urine_lengkap = array_filter($results, function($item) { $serum_type = $item["serum_type"]; $tesscode = $item["TESTCODE"]; $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; }); $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; }); $data_feces_stc2 = array_filter($results, function($item) { $serum_type = $item["serum_type"]; $tesscode = $item["TESTCODE"]; $printable = $item['NOTPRINTABLE']; return $serum_type == 'Feces' && in_array($tesscode, ['STC2', 'SCSAL', 'SCSHI']) && $printable !=1; }); $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; }); $data_feces_lengkap = array_filter($results, function($item) { $serum_type = $item["serum_type"]; $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; }); $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; }); $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 $fullPage = ""; if ($data_others != null) { $fullPage .= $this->otherTests($data_others, $data, $note); } if ($data_RCS != null) { $fullPage .= $this->otherTests($data_RCS, $data, $note); } if ($data_urine_kultur != null) { $fullPage .= $this->otherTests($data_urine_kultur, $data, $note); } if ($data_pregnancy != null) { $fullPage .= $this->otherTests($data_pregnancy, $data, $note); } if ($data_urine_lengkap != null) { $fullPage .= $this->otherTests($data_urine_lengkap, $data, $note); } if ($data_feces_stc2 != null) { $fullPage .= $this->otherTests($data_feces_stc2, $data, $note); } if ($data_feces_stc4 != null) { $fullPage .= $this->otherTests($data_feces_stc4, $data, $note); } if ($data_feces_lengkap != null) { $fullPage .= $this->otherTests($data_feces_lengkap, $data, $note); } return view('result_report', ['data' => $fullPage]); } }