diff --git a/app/Controllers/Opd.php b/app/Controllers/Opd.php index af14e1d..a70c2a3 100644 --- a/app/Controllers/Opd.php +++ b/app/Controllers/Opd.php @@ -2796,20 +2796,24 @@ class Opd extends BaseController }; $rxInvestigation = $rxRead($rx, ['investigation', 'Investigations', 'investigations', 'Investigation']); + + // Build test list independently from textarea content $rxInvestigationTestList = ''; - if ($rxInvestigation === '' && !empty($data['rx_investigations']) && is_array($data['rx_investigations'])) { - $parts = []; + 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 !== '') { - $parts[] = $txt; $testNames[] = $txt; } } - $rxInvestigation = implode(', ', $parts); - // Build formatted test list for {{Tadvise_test_list}} placeholder + // 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 = '