Support multiple species rows in glass report

This commit is contained in:
Dwi Swandhana
2026-04-20 09:38:05 +07:00
parent 5c5bf0ce19
commit 2abb6027a6
@@ -764,9 +764,7 @@ class ReportController extends Controller
$komponenRows = $lookups['komponen'][$row->nofoto] ?? collect([]); $komponenRows = $lookups['komponen'][$row->nofoto] ?? collect([]);
$antibioticRows = $lookups['antibiotik'][$row->id] ?? collect([]); $antibioticRows = $lookups['antibiotik'][$row->id] ?? collect([]);
$bacterialName = ''; $speciesNames = [];
$fungalName = '';
$foundMorphology = false;
foreach ($komponenRows as $komponenRow) { foreach ($komponenRows as $komponenRow) {
$value = trim(strip_tags((string) $komponenRow->isidata)); $value = trim(strip_tags((string) $komponenRow->isidata));
@@ -774,18 +772,14 @@ class ReportController extends Controller
continue; continue;
} }
if (stripos($value, 'Ditemukan morfologi') !== false) { if (in_array($komponenRow->komponen, ['bakteri', 'id_bakteri01', 'id_bakteri02'], true) && stripos($value, 'Ditemukan morfologi') === false) {
$foundMorphology = true; $speciesNames[] = $value;
}
} }
if (in_array($komponenRow->komponen, ['bakteri', 'id_bakteri01', 'id_bakteri02'], true) && $bacterialName === '' && stripos($value, 'Ditemukan morfologi') === false) { $speciesNames = array_values(array_filter($speciesNames, function ($value) {
$bacterialName = $value; return trim((string) $value) !== '';
} }));
if ($komponenRow->komponen === 'id_mikroorganisme' && $fungalName === '') {
$fungalName = $value;
}
}
$antibioticValues = []; $antibioticValues = [];
foreach ($antibioticRows as $antibioticRow) { foreach ($antibioticRows as $antibioticRow) {
@@ -808,9 +802,14 @@ class ReportController extends Controller
} }
$hasJenisSpesimen = trim((string) ($baseRow[10] ?? '')) !== ''; $hasJenisSpesimen = trim((string) ($baseRow[10] ?? '')) !== '';
if ($bacterialName !== '' && $hasJenisSpesimen) { $hasFungalAntibiotic = collect($headers['B_antibiotics'])->contains(function ($antibioticHeader) use ($antibioticValues) {
return array_key_exists($antibioticHeader, $antibioticValues);
});
if (!empty($speciesNames) && $hasJenisSpesimen && !$hasFungalAntibiotic) {
foreach ($speciesNames as $speciesName) {
$tableRow = array_merge($baseRow, [ $tableRow = array_merge($baseRow, [
$bacterialName, $speciesName,
$row->id_esbl ?? '', $row->id_esbl ?? '',
$row->id_mrsa ?? '', $row->id_mrsa ?? '',
]); ]);
@@ -820,12 +819,14 @@ class ReportController extends Controller
} }
$tables['A'][] = $tableRow; $tables['A'][] = $tableRow;
}
continue; continue;
} }
if ($foundMorphology || $fungalName !== '') { if (!empty($speciesNames) && $hasJenisSpesimen && $hasFungalAntibiotic) {
foreach ($speciesNames as $speciesName) {
$tableRow = array_merge($baseRow, [ $tableRow = array_merge($baseRow, [
$fungalName !== '' ? $fungalName : 'Ditemukan morfologi', $speciesName,
]); ]);
foreach ($headers['B_antibiotics'] as $antibioticHeader) { foreach ($headers['B_antibiotics'] as $antibioticHeader) {
@@ -833,6 +834,7 @@ class ReportController extends Controller
} }
$tables['B'][] = $tableRow; $tables['B'][] = $tableRow;
}
continue; continue;
} }