From f55d3009248b75a70d6afe069b82d436f69b93aa Mon Sep 17 00:00:00 2001 From: DevSoftTech Server Date: Sun, 7 Jun 2026 20:12:58 +0530 Subject: [PATCH] Fix: SIGNATURE_BLOCK placeholder and cached content issue ISSUE 1: {{SIGNATURE_BLOCK}} placeholder not working - Signature extraction was using wrong end markers - Start: 'Signature of Consultant' - End: 'Signature of Medical Officer', 'Signature of Receiver / Date' - Problem: All three texts are in SAME table row - Extraction cut off too early (found end marker immediately after start) FIX: Remove end markers for signature block extraction - Signature table is LAST element in content - Extract from 'Signature of Consultant' to end of content - Now captures entire signature table correctly ISSUE 2: Other Advice not showing in PDF - Cached content was generated BEFORE 'Other Advice:' label was added - Database has data but cached HTML doesn't include label FIX: Created cache clearing utility - clear_discharge_cache.php script - Clears cached content for specified IPD - Forces regeneration with new labels DEBUG TOOLS ADDED: - debug_discharge_content.php - Check what's in cached content - clear_discharge_cache.php - Clear cache to force regeneration TESTING: 1. php clear_discharge_cache.php 1 2. Visit /Ipd_discharge/preview_discharge_report/1?regen=1 3. Verify PDF shows Other Advice: and Discharge Summary: labels 4. Verify {{SIGNATURE_BLOCK}} placeholder works in templates --- app/Controllers/Ipd_discharge.php | 3 +- clear_discharge_cache.php | 45 ++++++++++++++++++ debug_discharge_content.php | 77 +++++++++++++++++++++++++++++++ 3 files changed, 124 insertions(+), 1 deletion(-) create mode 100644 clear_discharge_cache.php create mode 100644 debug_discharge_content.php diff --git a/app/Controllers/Ipd_discharge.php b/app/Controllers/Ipd_discharge.php index 1d7d905..20cc88d 100644 --- a/app/Controllers/Ipd_discharge.php +++ b/app/Controllers/Ipd_discharge.php @@ -566,7 +566,8 @@ class Ipd_discharge extends BaseController $dischargeInstructions = $section(['Discharge Advice/Instructions/Summary']); $drugAllergyAdr = $section(['Drug Allergy / ADR']); $coMorbidities = $section(['Co-Morbidities']); - $signatureBlock = $section(['Signature of Consultant'], ['Signature of Medical Officer', 'Signature of Receiver / Date']); + // Extract entire signature table - no end markers (it's the last section) + $signatureBlock = $section(['Signature of Consultant'], []); // Extract individual instruction fields for template flexibility $otherAdvice = $section(['Other Advice:']); diff --git a/clear_discharge_cache.php b/clear_discharge_cache.php new file mode 100644 index 0000000..af26cb5 --- /dev/null +++ b/clear_discharge_cache.php @@ -0,0 +1,45 @@ +connect_error) { + die("ERROR: Connection failed: " . $conn->connect_error . "\n"); +} + +$ipdId = isset($argv[1]) ? intval($argv[1]) : 1; + +echo "=== Clearing discharge cache for IPD ID: {$ipdId} ===\n\n"; + +$stmt = $conn->prepare("DELETE FROM ipd_discharge WHERE ipd_id = ?"); +$stmt->bind_param("i", $ipdId); + +if ($stmt->execute()) { + echo "✅ Cleared cached content for IPD ID {$ipdId}\n"; + echo "Affected rows: " . $stmt->affected_rows . "\n\n"; + echo "Now visit the discharge preview page to regenerate content with the new 'Other Advice:' label.\n"; + echo "URL: /Ipd_discharge/preview_discharge_report/{$ipdId}?regen=1\n"; +} else { + echo "❌ Failed to clear: " . $stmt->error . "\n"; +} + +$stmt->close(); +$conn->close(); +echo "\n=== Done ===\n"; diff --git a/debug_discharge_content.php b/debug_discharge_content.php new file mode 100644 index 0000000..581b056 --- /dev/null +++ b/debug_discharge_content.php @@ -0,0 +1,77 @@ + +connect_error) { + die("ERROR: Connection failed: " . $conn->connect_error . "\n"); +} + +$ipdId = isset($argv[1]) ? intval($argv[1]) : 1; + +echo "=== Checking discharge content for IPD ID: {$ipdId} ===\n\n"; + +// Check if cached content exists +$stmt = $conn->prepare("SELECT content FROM ipd_discharge WHERE ipd_id = ? LIMIT 1"); +$stmt->bind_param("i", $ipdId); +$stmt->execute(); +$result = $stmt->get_result(); + +if ($row = $result->fetch_assoc()) { + $content = $row['content']; + echo "=== CACHED CONTENT FOUND ===\n\n"; + + // Check for signature block + if (stripos($content, 'Signature of Consultant') !== false) { + echo "✅ 'Signature of Consultant' text FOUND in content\n"; + } else { + echo "❌ 'Signature of Consultant' text NOT FOUND in content\n"; + } + + // Check for Other Advice + if (stripos($content, 'Other Advice') !== false) { + echo "✅ 'Other Advice' text FOUND in content\n"; + } else { + echo "❌ 'Other Advice' text NOT FOUND in content\n"; + } + + // Check for Discharge Summary + if (stripos($content, 'Discharge Summary:') !== false) { + echo "✅ 'Discharge Summary:' label FOUND in content\n"; + } else { + echo "❌ 'Discharge Summary:' label NOT FOUND in content\n"; + } + + echo "\n=== CONTENT PREVIEW (first 2000 chars) ===\n"; + echo substr($content, 0, 2000) . "\n...\n\n"; + + echo "=== CONTENT PREVIEW (last 1000 chars) ===\n"; + echo "..." . substr($content, -1000) . "\n\n"; +} else { + echo "No cached content found for IPD ID {$ipdId}\n"; + echo "Content is generated on-demand. Try accessing the preview page first.\n"; +} + +$stmt->close(); +$conn->close(); +echo "=== Done ===\n";