From dbda578d684b6ee423bc91e972a68b9d902accd7 Mon Sep 17 00:00:00 2001 From: DevSoftTech Server Date: Fri, 5 Jun 2026 04:18:48 +0530 Subject: [PATCH] Harden OPD block spacing and add debug_html output mode --- app/Controllers/Opd.php | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/app/Controllers/Opd.php b/app/Controllers/Opd.php index 9d4ec37..70ddeca 100644 --- a/app/Controllers/Opd.php +++ b/app/Controllers/Opd.php @@ -2105,6 +2105,7 @@ class Opd extends BaseController public function opd_lettre_pdf(int $opdId) { $sessionId = (int) $this->request->getGet('session_id'); + $debugHtml = ((int) $this->request->getGet('debug_html')) === 1; $layoutMode = strtolower(trim((string) $this->request->getGet('layout'))); if ($layoutMode === '') { $layoutMode = 'full'; @@ -2164,6 +2165,12 @@ class Opd extends BaseController $html = $this->applyOpdPdfTemplateTokens($customHtml, $tokenVars); $html = $this->sanitizeOpdNamedHeaderFooterReferences($html); + if ($debugHtml) { + return $this->response + ->setHeader('Content-Type', 'text/plain; charset=UTF-8') + ->setBody($html); + } + $mpdf = new Mpdf([ 'mode' => 'utf-8', 'format' => 'A4', @@ -2380,6 +2387,13 @@ class Opd extends BaseController $mpdf->WriteHTML($prefixHtml, HTMLParserMode::HTML_HEADER_BUFFER); } + if ($debugHtml) { + $debugOutput = $prefixHtml !== '' ? ($prefixHtml . "\n" . $html) : $html; + return $this->response + ->setHeader('Content-Type', 'text/plain; charset=UTF-8') + ->setBody($debugOutput); + } + $opdCode = (string) ($data['opd_master'][0]->opd_code ?? ('OPD-' . $opdId)); $mpdf->SetTitle('OPD Prescription ' . $opdCode); $mpdf->WriteHTML($html); @@ -3594,7 +3608,7 @@ class Opd extends BaseController // List-style sections (Complaint, Diagnosis …): // heading on its own line, content block below with a small left indent. // margin-bottom:18px gives clear visual separation between consecutive sections. - return '
' + return '
' . $headingHtml . '
' . $value @@ -3603,7 +3617,7 @@ class Opd extends BaseController // Inline sections (Vitals, Investigation, Next Visit): // heading + value on the same line; same 18px gap after block. - return '
' + return '
' . $headingHtml . ' ' . $value @@ -3840,12 +3854,12 @@ class Opd extends BaseController $medicalHtml = trim((string) ($tokens['medical'] ?? '')); $tokens['Rx'] = $medicalHtml !== '' - ? '
Rx :
' . $medicalHtml . '
' + ? '
Rx :
' . $medicalHtml . '
' : ''; $tokens['rx'] = $tokens['Rx']; // {{medical}} used directly in templates: wrap with the same top/bottom margin. $tokens['medical'] = $medicalHtml !== '' - ? '
' . $medicalHtml . '
' + ? '
' . $medicalHtml . '
' : ''; $tokens['VitalsBlock'] = (string) ($tokens['vital_content'] ?? '');