Problem:
- {{DISCHARGE_SUMMARY}} always showed 'Discharge Summary' header
- User wants header to change based on patient discharge status
- 'Date of Discharge' line was unwanted
- Need to see HTML source to check spacing between placeholders
Solution:
1. Added getDischargeStatusText() method:
- Queries ipd_discharge_status table
- Uses ipd_master.ipd_status as lookup key
- Returns status_details or status_desc from table
- Fallback: 'Discharge Summary' if status not found
2. Modified buildDischargeSectionTokenVars():
- Now accepts panelData parameter (has ipd info)
- Gets discharge status text via getDischargeStatusText()
- Replaces 'Discharge Summary' heading with status text
- Removes 'Date of Discharge: YYYY-MM-DD' line
- Uses regex to handle multiple HTML tag formats (h1-h6, b, strong, p)
3. Added debug_discharge_html() endpoint:
- URL: /Ipd_discharge/debug_discharge_html/{ipdId}
- Shows complete HTML source with syntax highlighting
- Displays rendered template with all placeholders replaced
- Useful for checking spacing and HTML structure
- Auto-generates content if not saved yet
Database Schema:
- ipd_master.ipd_status: 0-7 (discharge status ID)
- ipd_discharge_status table:
- id: 0-7
- status_desc: 'Status Pending', 'Improved/Recovered', 'LAMA', 'Referred', etc.
- status_details: 'Discharge Summary', 'Leave Against Medical Advice', etc.
Status Mapping (from user's data):
- 0: Status Pending
- 1: Improved/Recovered -> 'Discharge Summary'
- 2: LAMA -> 'Leave Against Medical Advice'
- 3: Referred -> 'Refer To Higher Centre'
- 4: Satisfactory -> 'Discharge Summary'
- 5: Expired -> 'Dead Summary'
- 6: Admission Cancelled
- 7: Discharge on Request
Regex Replacements:
1. Header replacement: /<h[1-6][^>]*>\s*Discharge\s+Summary\s*<\/h[1-6]>/i
2. Bold replacement: /<(b|strong)>\s*Discharge\s+Summary\s*<\/\1>/i
3. Date removal (br): /Date\s+of\s+Discharge\s*:\s*[0-9\-\/]+\s*<br\s*\/?>/i
4. Date removal (p): /<p[^>]*>\s*Date\s+of\s+Discharge\s*:\s*[0-9\-\/]+\s*<\/p>/i
Usage:
- When ipd_status = 1: Shows 'Discharge Summary' (from status_details)
- When ipd_status = 2: Shows 'Leave Against Medical Advice'
- When ipd_status = 5: Shows 'Dead Summary'
- 'Date of Discharge: 2026-06-07' line is removed from all sections
Debug Endpoints:
1. /Ipd_discharge/debug_ipd_fields/{ipdId} - Shows database field values
2. /Ipd_discharge/debug_discharge_html/{ipdId} - Shows complete HTML source
Testing:
- Change ipd_master.ipd_status value
- Regenerate discharge summary
- Header should change based on status
- Date line should not appear
- Use debug_discharge_html to see full HTML structure