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,30 +2806,44 @@ class Opd extends BaseController
|
||||||
|
|
||||||
// Build test list independently from textarea content
|
// Build test list independently from textarea content
|
||||||
$rxInvestigationTestList = '';
|
$rxInvestigationTestList = '';
|
||||||
|
$testNames = [];
|
||||||
|
|
||||||
|
// First, try to get tests from rx_investigations table
|
||||||
if (!empty($data['rx_investigations']) && is_array($data['rx_investigations'])) {
|
if (!empty($data['rx_investigations']) && is_array($data['rx_investigations'])) {
|
||||||
$testNames = [];
|
|
||||||
foreach ($data['rx_investigations'] as $inv) {
|
foreach ($data['rx_investigations'] as $inv) {
|
||||||
$txt = trim((string) ($inv['investigation_name'] ?? $inv['investigation'] ?? ''));
|
$txt = trim((string) ($inv['investigation_name'] ?? $inv['investigation'] ?? ''));
|
||||||
if ($txt !== '') {
|
if ($txt !== '') {
|
||||||
$testNames[] = $txt;
|
$testNames[] = $txt;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// If textarea is empty, also populate it with comma-separated tests
|
// If no tests from table but textarea has content, parse textarea as fallback
|
||||||
if ($rxInvestigation === '' && !empty($testNames)) {
|
if (empty($testNames) && $rxInvestigation !== '') {
|
||||||
$rxInvestigation = implode(', ', $testNames);
|
// Split by newlines or common delimiters
|
||||||
}
|
$lines = preg_split('/[\r\n]+/', $rxInvestigation);
|
||||||
|
foreach ($lines as $line) {
|
||||||
// Always build formatted HTML test list for {{Tadvise_test_list}} placeholder
|
$line = trim($line);
|
||||||
if (!empty($testNames)) {
|
if ($line !== '' && $line !== 'null') {
|
||||||
$rxInvestigationTestList = '<ul style="margin:3px 0 0 16px;padding:0;list-style-type:disc;">';
|
$testNames[] = $line;
|
||||||
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>';
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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']);
|
$rxAdvice = $rxRead($rx, ['advice', 'Advice', 'prescription_advice', 'advice_notes', 'advice_note']);
|
||||||
$rxAdviceLocal = '';
|
$rxAdviceLocal = '';
|
||||||
if ($rxAdvice === '' && !empty($data['rx_advices']) && is_array($data['rx_advices'])) {
|
if ($rxAdvice === '' && !empty($data['rx_advices']) && is_array($data['rx_advices'])) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user