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([]);
$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;
}