Correct fix: Remove patient table from auto-generated content, add as token
OLD CI3 BEHAVIOR (correct):
- Patient demographic table was IN the template file
- Content variables contained ONLY clinical sections
- Template controlled entire layout
NEW CI4 FIX (matching CI3):
- Patient table removed from buildAutoDischargeContent completely
- Added {{PATIENT_INFO_TABLE}} token for templates to use if needed
- Auto-generated content now contains ONLY clinical sections
- Blank template = blank output (no patient table forced)
- Templates can add patient table using token or individual tokens
Changes:
- Removed includeSummaryTable parameter from buildAutoDischargeContent
- Removed templateHasDemographicTokens helper (no longer needed)
- Added PATIENT_INFO_TABLE token in buildDischargeTemplateTokenVars
- Simplified show_discharge and preview_discharge_report (no template detection)
- Added comment explaining CI3 compatibility
This matches the old CI3 chamunda_discharge_template_html.php pattern where:
- Template had hardcoded patient table structure
- Variables like \, \ were injected
- Content did NOT include patient demographics by default
This commit is contained in:
parent
00a70ce731
commit
6d72a5ec04
|
|
@ -372,6 +372,9 @@ class Ipd_discharge extends BaseController
|
||||||
'hospital_email' => esc($hEmail),
|
'hospital_email' => esc($hEmail),
|
||||||
];
|
];
|
||||||
|
|
||||||
|
// Add patient info table as a token (not included in CONTENT by default)
|
||||||
|
$tokens['PATIENT_INFO_TABLE'] = $this->buildAutoDischargeSummaryTable($panelData);
|
||||||
|
|
||||||
$summaryTokens = $this->buildDischargeSummaryTokenVars($panelData);
|
$summaryTokens = $this->buildDischargeSummaryTokenVars($panelData);
|
||||||
foreach ($summaryTokens as $key => $value) {
|
foreach ($summaryTokens as $key => $value) {
|
||||||
$tokens[$key] = $value;
|
$tokens[$key] = $value;
|
||||||
|
|
@ -909,34 +912,6 @@ class Ipd_discharge extends BaseController
|
||||||
return 'user-' . (string) ($user->id ?? 0);
|
return 'user-' . (string) ($user->id ?? 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function templateHasDemographicTokens(string $templateHtml): bool
|
|
||||||
{
|
|
||||||
$templateHtml = trim($templateHtml);
|
|
||||||
if ($templateHtml === '' || $templateHtml === '{{CONTENT}}') {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$demographicTokens = [
|
|
||||||
'{{PATIENT_NAME}}',
|
|
||||||
'{{UHID}}',
|
|
||||||
'{{IPD_CODE}}',
|
|
||||||
'{{AGE_GENDER}}',
|
|
||||||
'{{ADMIT_DATE}}',
|
|
||||||
'{{DISCHARGE_DATE}}',
|
|
||||||
'{{GUARDIAN}}',
|
|
||||||
'{{PATIENT_ADDRESS}}',
|
|
||||||
'{{DEPARTMENT}}',
|
|
||||||
];
|
|
||||||
|
|
||||||
foreach ($demographicTokens as $token) {
|
|
||||||
if (stripos($templateHtml, $token) !== false) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function saveDischargeContent(int $ipdId, string $content): bool
|
private function saveDischargeContent(int $ipdId, string $content): bool
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
|
|
@ -1446,7 +1421,7 @@ class Ipd_discharge extends BaseController
|
||||||
return '<p><b>' . esc($title) . ' : </b><br/>' . implode('<br/>', $lines) . '</p>';
|
return '<p><b>' . esc($title) . ' : </b><br/>' . implode('<br/>', $lines) . '</p>';
|
||||||
}
|
}
|
||||||
|
|
||||||
private function buildAutoDischargeContent(int $ipdId, array $panelData, bool $includeSummaryTable = true): string
|
private function buildAutoDischargeContent(int $ipdId, array $panelData): string
|
||||||
{
|
{
|
||||||
$ipd = $panelData['ipd_info'] ?? null;
|
$ipd = $panelData['ipd_info'] ?? null;
|
||||||
$person = $panelData['person_info'] ?? null;
|
$person = $panelData['person_info'] ?? null;
|
||||||
|
|
@ -1478,13 +1453,9 @@ class Ipd_discharge extends BaseController
|
||||||
|
|
||||||
$sections = [];
|
$sections = [];
|
||||||
|
|
||||||
// Only include summary table if explicitly requested
|
// NOTE: Patient demographic table is NOT included in auto-generated content.
|
||||||
if ($includeSummaryTable) {
|
// It is available as {{PATIENT_INFO_TABLE}} token for templates to use if needed.
|
||||||
$summaryTable = $this->buildAutoDischargeSummaryTable($panelData);
|
// This matches CI3 behavior where template controlled the patient info display.
|
||||||
if ($summaryTable !== '') {
|
|
||||||
$sections[] = $summaryTable;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$complaints = $this->byIpdRows('ipd_discharge_complaint', ['comp_report', 'comp_remark'], 'id ASC', $ipdId);
|
$complaints = $this->byIpdRows('ipd_discharge_complaint', ['comp_report', 'comp_remark'], 'id ASC', $ipdId);
|
||||||
$complaintRemark = $this->firstRowByIpd('ipd_discharge_complaint_remark', $ipdId);
|
$complaintRemark = $this->firstRowByIpd('ipd_discharge_complaint_remark', $ipdId);
|
||||||
|
|
@ -5401,38 +5372,8 @@ class Ipd_discharge extends BaseController
|
||||||
$shouldRegenerate = (int) ($this->request->getGet('regen') ?? 0) === 1;
|
$shouldRegenerate = (int) ($this->request->getGet('regen') ?? 0) === 1;
|
||||||
$requestedTemplateId = (int) ($this->request->getGet('tpl') ?? 0);
|
$requestedTemplateId = (int) ($this->request->getGet('tpl') ?? 0);
|
||||||
|
|
||||||
// Get requested template to check if it has demographic tokens
|
|
||||||
$templates = $this->getDischargeTemplateRows();
|
|
||||||
$selectedTemplate = null;
|
|
||||||
|
|
||||||
if ($requestedTemplateId > 0) {
|
|
||||||
foreach ($templates as $row) {
|
|
||||||
if ((int) ($row['id'] ?? 0) === $requestedTemplateId) {
|
|
||||||
$selectedTemplate = $row;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($selectedTemplate === null) {
|
|
||||||
foreach ($templates as $row) {
|
|
||||||
if ((int) ($row['is_default'] ?? 0) === 1) {
|
|
||||||
$selectedTemplate = $row;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($selectedTemplate === null && ! empty($templates)) {
|
|
||||||
$selectedTemplate = $templates[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
$templateHtml = (string) ($selectedTemplate['template_html'] ?? '{{CONTENT}}');
|
|
||||||
$templateHasDemographics = $this->templateHasDemographicTokens($templateHtml);
|
|
||||||
|
|
||||||
if ($shouldRegenerate || trim(strip_tags($content)) === '') {
|
if ($shouldRegenerate || trim(strip_tags($content)) === '') {
|
||||||
// Skip auto-summary table if template has demographic tokens
|
$generated = $this->buildAutoDischargeContent($ipdId, $panelData);
|
||||||
$generated = $this->buildAutoDischargeContent($ipdId, $panelData, !$templateHasDemographics);
|
|
||||||
if (trim(strip_tags($generated)) !== '') {
|
if (trim(strip_tags($generated)) !== '') {
|
||||||
$content = $generated;
|
$content = $generated;
|
||||||
if ($this->saveDischargeContent($ipdId, $content)) {
|
if ($this->saveDischargeContent($ipdId, $content)) {
|
||||||
|
|
@ -5483,45 +5424,15 @@ class Ipd_discharge extends BaseController
|
||||||
return $this->response->setStatusCode(404)->setBody('IPD not found');
|
return $this->response->setStatusCode(404)->setBody('IPD not found');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get requested template first to check if it has demographic tokens
|
|
||||||
$requestedTemplateId = (int) ($this->request->getGet('tpl') ?? 0);
|
|
||||||
$templates = $this->getDischargeTemplateRows();
|
|
||||||
$selectedTemplate = null;
|
|
||||||
|
|
||||||
if ($requestedTemplateId > 0) {
|
|
||||||
foreach ($templates as $row) {
|
|
||||||
if ((int) ($row['id'] ?? 0) === $requestedTemplateId) {
|
|
||||||
$selectedTemplate = $row;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($selectedTemplate === null) {
|
|
||||||
foreach ($templates as $row) {
|
|
||||||
if ((int) ($row['is_default'] ?? 0) === 1) {
|
|
||||||
$selectedTemplate = $row;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($selectedTemplate === null && ! empty($templates)) {
|
|
||||||
$selectedTemplate = $templates[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
$templateHtml = (string) ($selectedTemplate['template_html'] ?? '{{CONTENT}}');
|
|
||||||
$templateHasDemographics = $this->templateHasDemographicTokens($templateHtml);
|
|
||||||
|
|
||||||
$content = $this->getDischargeContent($ipdId);
|
$content = $this->getDischargeContent($ipdId);
|
||||||
if (trim(strip_tags($content)) === '') {
|
if (trim(strip_tags($content)) === '') {
|
||||||
// Skip auto-summary table if template has demographic tokens
|
$content = $this->buildAutoDischargeContent($ipdId, $panelData);
|
||||||
$content = $this->buildAutoDischargeContent($ipdId, $panelData, !$templateHasDemographics);
|
|
||||||
if (trim(strip_tags($content)) !== '') {
|
if (trim(strip_tags($content)) !== '') {
|
||||||
$this->saveDischargeContent($ipdId, $content);
|
$this->saveDischargeContent($ipdId, $content);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$requestedTemplateId = (int) ($this->request->getGet('tpl') ?? 0);
|
||||||
$templatePack = $this->applyDischargeTemplate($content, $panelData, $requestedTemplateId > 0 ? $requestedTemplateId : null);
|
$templatePack = $this->applyDischargeTemplate($content, $panelData, $requestedTemplateId > 0 ? $requestedTemplateId : null);
|
||||||
$templateSettings = is_array($templatePack['selected_template_settings'] ?? null)
|
$templateSettings = is_array($templatePack['selected_template_settings'] ?? null)
|
||||||
? $templatePack['selected_template_settings']
|
? $templatePack['selected_template_settings']
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user