This commit is contained in:
Dwi Swandhana
2026-04-20 15:37:11 +07:00
parent e3086919b7
commit 7ca1e3a96e
2 changed files with 44 additions and 37 deletions
@@ -618,8 +618,7 @@ class ReportController extends Controller
]; ];
return [ return [
'A' => array_merge($tableC, ['Nama Spesies Bakteri', 'ESBL', 'MRSA'], $tableAAntibiotics), 'A' => array_merge($tableC, ['Nama Spesies Bakteri', 'Pertumbuhan Bakteri', 'SIR Bakteri', 'ESBL', 'MRSA'], $tableAAntibiotics, $tableBAntibiotics),
'B' => array_merge($tableC, ['Nama Spesies Jamur'], $tableBAntibiotics),
'C' => $tableC, 'C' => $tableC,
'A_antibiotics' => $tableAAntibiotics, 'A_antibiotics' => $tableAAntibiotics,
'B_antibiotics' => $tableBAntibiotics, 'B_antibiotics' => $tableBAntibiotics,
@@ -738,7 +737,7 @@ class ReportController extends Controller
$komponen = DB::table('db_komponenjawaban') $komponen = DB::table('db_komponenjawaban')
->select('accnumber', 'komponen', 'isidata') ->select('accnumber', 'komponen', 'isidata')
->whereIn('accnumber', $accnumbers) ->whereIn('accnumber', $accnumbers)
->whereIn('komponen', ['bakteri', 'id_bakteri01', 'id_bakteri02', 'id_mikroorganisme']) ->whereIn('komponen', ['bakteri', 'id_bakteri01', 'id_bakteri02', 'id_mikroorganisme', 'id_biakankultur', 'bakterisir', 'id_bakterisir01', 'id_bakterisir02'])
->whereNotNull('isidata') ->whereNotNull('isidata')
->where('isidata', '!=', '') ->where('isidata', '!=', '')
->get() ->get()
@@ -757,7 +756,7 @@ class ReportController extends Controller
private function splitGlassReportRows($rows, $lookups) { private function splitGlassReportRows($rows, $lookups) {
$headers = $this->getGlassReportHeaders(); $headers = $this->getGlassReportHeaders();
$aliases = $this->getGlassReportAntibioticAliases(); $aliases = $this->getGlassReportAntibioticAliases();
$tables = ['A' => [], 'B' => [], 'C' => []]; $tables = ['A' => [], 'C' => []];
foreach ($rows as $row) { foreach ($rows as $row) {
$baseRow = $this->buildGlassReportBaseRow($row); $baseRow = $this->buildGlassReportBaseRow($row);
@@ -765,6 +764,12 @@ class ReportController extends Controller
$antibioticRows = $lookups['antibiotik'][$row->id] ?? collect([]); $antibioticRows = $lookups['antibiotik'][$row->id] ?? collect([]);
$speciesNames = []; $speciesNames = [];
$growthValue = '';
$sirValues = [
'bakteri' => '',
'id_bakteri01' => '',
'id_bakteri02' => '',
];
foreach ($komponenRows as $komponenRow) { foreach ($komponenRows as $komponenRow) {
$value = trim(strip_tags((string) $komponenRow->isidata)); $value = trim(strip_tags((string) $komponenRow->isidata));
@@ -773,12 +778,31 @@ class ReportController extends Controller
} }
if (in_array($komponenRow->komponen, ['bakteri', 'id_bakteri01', 'id_bakteri02'], true) && stripos($value, 'Ditemukan morfologi') === false) { if (in_array($komponenRow->komponen, ['bakteri', 'id_bakteri01', 'id_bakteri02'], true) && stripos($value, 'Ditemukan morfologi') === false) {
$speciesNames[] = $value; $speciesNames[] = [
'name' => $value,
'component' => $komponenRow->komponen,
];
}
if ($komponenRow->komponen === 'id_biakankultur' && $growthValue === '') {
$growthValue = $value;
}
if ($komponenRow->komponen === 'bakterisir' && $sirValues['bakteri'] === '') {
$sirValues['bakteri'] = $value;
}
if ($komponenRow->komponen === 'id_bakterisir01' && $sirValues['id_bakteri01'] === '') {
$sirValues['id_bakteri01'] = $value;
}
if ($komponenRow->komponen === 'id_bakterisir02' && $sirValues['id_bakteri02'] === '') {
$sirValues['id_bakteri02'] = $value;
} }
} }
$speciesNames = array_values(array_filter($speciesNames, function ($value) { $speciesNames = array_values(array_filter($speciesNames, function ($value) {
return trim((string) $value) !== ''; return trim((string) ($value['name'] ?? '')) !== '';
})); }));
$antibioticValues = []; $antibioticValues = [];
@@ -802,14 +826,15 @@ class ReportController extends Controller
} }
$hasJenisSpesimen = trim((string) ($baseRow[10] ?? '')) !== ''; $hasJenisSpesimen = trim((string) ($baseRow[10] ?? '')) !== '';
$hasFungalAntibiotic = collect($headers['B_antibiotics'])->contains(function ($antibioticHeader) use ($antibioticValues) {
return array_key_exists($antibioticHeader, $antibioticValues);
});
if (!empty($speciesNames) && $hasJenisSpesimen && !$hasFungalAntibiotic) { if (!empty($speciesNames) && $hasJenisSpesimen) {
foreach ($speciesNames as $speciesName) { foreach ($speciesNames as $speciesData) {
$sirKey = $speciesData['component'] ?? 'bakteri';
$sirValue = $sirValues[$sirKey] ?? '';
$tableRow = array_merge($baseRow, [ $tableRow = array_merge($baseRow, [
$speciesName, $speciesData['name'] ?? '',
$growthValue,
$sirValue,
$row->id_esbl ?? '', $row->id_esbl ?? '',
$row->id_mrsa ?? '', $row->id_mrsa ?? '',
]); ]);
@@ -818,22 +843,11 @@ class ReportController extends Controller
$tableRow[] = $antibioticValues[$antibioticHeader] ?? ''; $tableRow[] = $antibioticValues[$antibioticHeader] ?? '';
} }
$tables['A'][] = $tableRow;
}
continue;
}
if (!empty($speciesNames) && $hasJenisSpesimen && $hasFungalAntibiotic) {
foreach ($speciesNames as $speciesName) {
$tableRow = array_merge($baseRow, [
$speciesName,
]);
foreach ($headers['B_antibiotics'] as $antibioticHeader) { foreach ($headers['B_antibiotics'] as $antibioticHeader) {
$tableRow[] = $antibioticValues[$antibioticHeader] ?? ''; $tableRow[] = $antibioticValues[$antibioticHeader] ?? '';
} }
$tables['B'][] = $tableRow; $tables['A'][] = $tableRow;
} }
continue; continue;
} }
@@ -902,7 +916,6 @@ class ReportController extends Controller
$headers = $this->getGlassReportHeaders(); $headers = $this->getGlassReportHeaders();
$tables = [ $tables = [
'A' => [], 'A' => [],
'B' => [],
'C' => [], 'C' => [],
]; ];
@@ -917,14 +930,14 @@ class ReportController extends Controller
$lookups = $this->getGlassReportLookups($rows); $lookups = $this->getGlassReportLookups($rows);
$chunkTables = $this->splitGlassReportRows($rows, $lookups); $chunkTables = $this->splitGlassReportRows($rows, $lookups);
foreach (['A', 'B', 'C'] as $tableKey) { foreach (['A', 'C'] as $tableKey) {
foreach ($chunkTables[$tableKey] as $tableRow) { foreach ($chunkTables[$tableKey] as $tableRow) {
$tables[$tableKey][] = $tableRow; $tables[$tableKey][] = $tableRow;
} }
} }
}); });
foreach (['A', 'B', 'C'] as $tableKey) { foreach (['A', 'C'] as $tableKey) {
fputcsv($handle, ['TABEL '.$tableKey]); fputcsv($handle, ['TABEL '.$tableKey]);
fputcsv($handle, $headers[$tableKey]); fputcsv($handle, $headers[$tableKey]);
@@ -69,9 +69,12 @@
<div class="alert alert-info"> <div class="alert alert-info">
Preview Glass Report ditampilkan per halaman 50 pemeriksaan agar aman di memori. Untuk data lengkap gunakan tombol download CSV. Preview Glass Report ditampilkan per halaman 50 pemeriksaan agar aman di memori. Untuk data lengkap gunakan tombol download CSV.
</div> </div>
@foreach (['A', 'B', 'C'] as $tableKey) @foreach (['A', 'C'] as $tableKey)
<div class="table-responsive" style="margin-bottom: 24px;"> <div class="table-responsive" style="margin-bottom: 24px;">
<h4>TABEL {{ $tableKey }}</h4> <h4>TABEL {{ $tableKey }}</h4>
<button type="button" class="btn btn-primary" id="btnexporttabel{{ $tableKey }}" style="margin-bottom: 10px;">
<i class="fa fa-print"></i> Export
</button>
<table class="table table-bordered table-sm" id="tabel{{ $tableKey }}"> <table class="table table-bordered table-sm" id="tabel{{ $tableKey }}">
<thead> <thead>
<tr> <tr>
@@ -171,15 +174,6 @@
console.error('Tabel dengan ID "tabelA" tidak ditemukan.'); console.error('Tabel dengan ID "tabelA" tidak ditemukan.');
} }
}); });
document.getElementById('btnexporttabelB').addEventListener('click', function() {
var table = document.getElementById('tabelB');
if (table) {
var wb = XLSX.utils.table_to_book(table, { sheet: "Jamur" });
XLSX.writeFile(wb, "TABEL_B_{{$bulan}}_Tahun{{$tahun}}.xlsx");
} else {
console.error('Tabel dengan ID "tabelB" tidak ditemukan.');
}
});
document.getElementById('btnexporttabelC').addEventListener('click', function() { document.getElementById('btnexporttabelC').addEventListener('click', function() {
var table = document.getElementById('tabelC'); var table = document.getElementById('tabelC');
if (table) { if (table) {