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 = '
';
- foreach ($testNames as $testName) {
- $rxInvestigationTestList .= '- ' . htmlspecialchars($testName, ENT_QUOTES, 'UTF-8') . '
';
+ }
+
+ // If no tests from table but textarea has content, parse textarea as fallback
+ if (empty($testNames) && $rxInvestigation !== '') {
+ // Split by newlines or common delimiters
+ $lines = preg_split('/[\r\n]+/', $rxInvestigation);
+ foreach ($lines as $line) {
+ $line = trim($line);
+ if ($line !== '' && $line !== 'null') {
+ $testNames[] = $line;
}
- $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 = '';
+ foreach ($testNames as $testName) {
+ $rxInvestigationTestList .= '- ' . htmlspecialchars($testName, ENT_QUOTES, 'UTF-8') . '
';
+ }
+ $rxInvestigationTestList .= '
';
+ }
$rxAdvice = $rxRead($rx, ['advice', 'Advice', 'prescription_advice', 'advice_notes', 'advice_note']);
$rxAdviceLocal = '';