Add textarea fallback for {{Tadvise_test_list}} placeholder
When opd_prescription_investigation table is empty but investigation textarea has content, parse textarea content (split by newlines) to populate the test list. This handles cases where tests are entered as free-text in the "Advise Investigation" textarea instead of selecting from master list. Parsing logic: - Try rx_investigations table first - If empty, split investigation textarea by newlines - Filter out empty lines and 'null' values - Build HTML bullet list from either source Example textarea content: USG WHOLE ABDOMEN CECT ABDOMEN PAC COMPLETE CARDIAC CHECK UP PAP SMEAR Will render as: • USG WHOLE ABDOMEN • CECT ABDOMEN • PAC • COMPLETE CARDIAC CHECK UP • PAP SMEAR
This commit is contained in:
parent
1ca2dbce4c
commit
0b865f41cd
|
|
@ -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 = '<ul style="margin:3px 0 0 16px;padding:0;list-style-type:disc;">';
|
||||
foreach ($testNames as $testName) {
|
||||
$rxInvestigationTestList .= '<li style="margin-bottom:3px;font-weight:400;line-height:1.5;color:#111;">' . htmlspecialchars($testName, ENT_QUOTES, 'UTF-8') . '</li>';
|
||||
}
|
||||
|
||||
// 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 .= '</ul>';
|
||||
}
|
||||
}
|
||||
|
||||
// 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 = '<ul style="margin:3px 0 0 16px;padding:0;list-style-type:disc;">';
|
||||
foreach ($testNames as $testName) {
|
||||
$rxInvestigationTestList .= '<li style="margin-bottom:3px;font-weight:400;line-height:1.5;color:#111;">' . htmlspecialchars($testName, ENT_QUOTES, 'UTF-8') . '</li>';
|
||||
}
|
||||
$rxInvestigationTestList .= '</ul>';
|
||||
}
|
||||
|
||||
$rxAdvice = $rxRead($rx, ['advice', 'Advice', 'prescription_advice', 'advice_notes', 'advice_note']);
|
||||
$rxAdviceLocal = '';
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user