From 2abb6027a6ba9b7fa61831f9e6ffc4ee45071b01 Mon Sep 17 00:00:00 2001 From: Dwi Swandhana Date: Mon, 20 Apr 2026 09:38:05 +0700 Subject: [PATCH] Support multiple species rows in glass report --- .../app/Http/Controllers/ReportController.php | 64 ++++++++++--------- 1 file changed, 33 insertions(+), 31 deletions(-) diff --git a/htdocs/app/Http/Controllers/ReportController.php b/htdocs/app/Http/Controllers/ReportController.php index f08fcdbe..f115979e 100644 --- a/htdocs/app/Http/Controllers/ReportController.php +++ b/htdocs/app/Http/Controllers/ReportController.php @@ -764,9 +764,7 @@ class ReportController extends Controller $komponenRows = $lookups['komponen'][$row->nofoto] ?? collect([]); $antibioticRows = $lookups['antibiotik'][$row->id] ?? collect([]); - $bacterialName = ''; - $fungalName = ''; - $foundMorphology = false; + $speciesNames = []; foreach ($komponenRows as $komponenRow) { $value = trim(strip_tags((string) $komponenRow->isidata)); @@ -774,19 +772,15 @@ class ReportController extends Controller continue; } - if (stripos($value, 'Ditemukan morfologi') !== false) { - $foundMorphology = true; - } - - if (in_array($komponenRow->komponen, ['bakteri', 'id_bakteri01', 'id_bakteri02'], true) && $bacterialName === '' && stripos($value, 'Ditemukan morfologi') === false) { - $bacterialName = $value; - } - - if ($komponenRow->komponen === 'id_mikroorganisme' && $fungalName === '') { - $fungalName = $value; + if (in_array($komponenRow->komponen, ['bakteri', 'id_bakteri01', 'id_bakteri02'], true) && stripos($value, 'Ditemukan morfologi') === false) { + $speciesNames[] = $value; } } + $speciesNames = array_values(array_filter($speciesNames, function ($value) { + return trim((string) $value) !== ''; + })); + $antibioticValues = []; foreach ($antibioticRows as $antibioticRow) { $matchedHeader = null; @@ -808,31 +802,39 @@ class ReportController extends Controller } $hasJenisSpesimen = trim((string) ($baseRow[10] ?? '')) !== ''; - if ($bacterialName !== '' && $hasJenisSpesimen) { - $tableRow = array_merge($baseRow, [ - $bacterialName, - $row->id_esbl ?? '', - $row->id_mrsa ?? '', - ]); + $hasFungalAntibiotic = collect($headers['B_antibiotics'])->contains(function ($antibioticHeader) use ($antibioticValues) { + return array_key_exists($antibioticHeader, $antibioticValues); + }); - foreach ($headers['A_antibiotics'] as $antibioticHeader) { - $tableRow[] = $antibioticValues[$antibioticHeader] ?? ''; + if (!empty($speciesNames) && $hasJenisSpesimen && !$hasFungalAntibiotic) { + foreach ($speciesNames as $speciesName) { + $tableRow = array_merge($baseRow, [ + $speciesName, + $row->id_esbl ?? '', + $row->id_mrsa ?? '', + ]); + + foreach ($headers['A_antibiotics'] as $antibioticHeader) { + $tableRow[] = $antibioticValues[$antibioticHeader] ?? ''; + } + + $tables['A'][] = $tableRow; } - - $tables['A'][] = $tableRow; continue; } - if ($foundMorphology || $fungalName !== '') { - $tableRow = array_merge($baseRow, [ - $fungalName !== '' ? $fungalName : 'Ditemukan morfologi', - ]); + if (!empty($speciesNames) && $hasJenisSpesimen && $hasFungalAntibiotic) { + foreach ($speciesNames as $speciesName) { + $tableRow = array_merge($baseRow, [ + $speciesName, + ]); - foreach ($headers['B_antibiotics'] as $antibioticHeader) { - $tableRow[] = $antibioticValues[$antibioticHeader] ?? ''; + foreach ($headers['B_antibiotics'] as $antibioticHeader) { + $tableRow[] = $antibioticValues[$antibioticHeader] ?? ''; + } + + $tables['B'][] = $tableRow; } - - $tables['B'][] = $tableRow; continue; }