diff --git a/app/Controllers/Opd.php b/app/Controllers/Opd.php index de3b776..5c8c08b 100644 --- a/app/Controllers/Opd.php +++ b/app/Controllers/Opd.php @@ -2806,29 +2806,43 @@ class Opd extends BaseController // Build test list independently from textarea content $rxInvestigationTestList = ''; + $testNames = []; + + // First, try to get tests from rx_investigations table if (!empty($data['rx_investigations']) && is_array($data['rx_investigations'])) { - $testNames = []; foreach ($data['rx_investigations'] as $inv) { $txt = trim((string) ($inv['investigation_name'] ?? $inv['investigation'] ?? '')); if ($txt !== '') { $testNames[] = $txt; } } - - // If textarea is empty, also populate it with comma-separated tests - if ($rxInvestigation === '' && !empty($testNames)) { - $rxInvestigation = implode(', ', $testNames); - } - - // Always build formatted HTML test list for {{Tadvise_test_list}} placeholder - if (!empty($testNames)) { - $rxInvestigationTestList = ''; } } + + // If textarea is empty, populate it with comma-separated tests from table + if ($rxInvestigation === '' && !empty($testNames)) { + $rxInvestigation = implode(', ', $testNames); + } + + // Always build formatted HTML test list for {{Tadvise_test_list}} placeholder + if (!empty($testNames)) { + $rxInvestigationTestList = ''; + } $rxAdvice = $rxRead($rx, ['advice', 'Advice', 'prescription_advice', 'advice_notes', 'advice_note']); $rxAdviceLocal = '';