` - Inline styling (remarks)
-- `
` - Line breaks
-
----
-
-## Debug Endpoints
-
-To view the actual rendered HTML:
-
-1. **View full HTML source:**
- ```
- /Ipd_discharge/debug_discharge_html/{ipdId}
- ```
- Example: `http://localhost:8080/Ipd_discharge/debug_discharge_html/1`
-
-2. **View database field values:**
- ```
- /Ipd_discharge/debug_ipd_fields/{ipdId}
- ```
- Example: `http://localhost:8080/Ipd_discharge/debug_ipd_fields/1`
-
----
-
-## Notes
-
-- All placeholders support both `{{TOKEN}}` and `{TOKEN}` formats
-- All placeholders also support lowercase and Ucfirst variants
-- Empty sections are NOT rendered (no HTML output)
-- Rich text fields preserve HTML formatting from CKEditor
-- All user input is escaped using `esc()` for XSS protection
-- Date formats: `dd-mm-yyyy` (e.g., 07-06-2026)
-- Time formats: `hh:mm AM/PM` (e.g., 02:44 PM)
-
----
-
-**Generated:** 2026-06-07
-**File Location:** `d:\Workplace\HMS_CI4_OLD\DISCHARGE_PLACEHOLDER_HTML_REFERENCE.md`
diff --git a/DISCHARGE_SUMMARY_HTML_EDITOR_FIX.md b/DISCHARGE_SUMMARY_HTML_EDITOR_FIX.md
deleted file mode 100644
index 3ab8c2d..0000000
--- a/DISCHARGE_SUMMARY_HTML_EDITOR_FIX.md
+++ /dev/null
@@ -1,64 +0,0 @@
-# Discharge Summary HTML Editor Fix
-
-## Problem
-After converting textarea controls to HTML editors (TinyMCE/similar) in the discharge form, saved discharge summaries were not appearing in the generated PDF.
-
-## Root Cause
-The `normalizeRichText()` function at line 1591 in `Ipd_discharge.php` was stripping ALL HTML tags using `strip_tags()`. This was designed for plain textarea input, but when HTML editors save formatted content with ``, ``, ``, `
`, etc., all the markup was being removed, leaving empty or malformed content.
-
-## Affected Fields
-- Presenting Complaints (complaint_remark)
-- Final Diagnosis (diagnosis_remark)
-- Course in Hospital (course_remark)
-- Summary of Key Investigations (inhos_remark)
-- Other/Systemic Examinations (systemic exam text)
-- Other Examinations/Provisional Diagnosis (other_exam_text)
-
-## Solution
-Modified the following methods in `app/Controllers/Ipd_discharge.php`:
-
-### 1. Enhanced `normalizeRichText()` (line 1591)
-- Detects if content contains HTML tags from HTML editor
-- **If HTML detected**: Preserves HTML structure, only cleans whitespace
-- **If plain text**: Uses original logic (strip tags, convert to plain text)
-- Backward compatible with existing plain textarea fields
-
-### 2. Added `renderRichText()` (new method after normalizeRichText)
-- Detects HTML vs plain text content
-- **If HTML**: Returns content as-is for HTML rendering
-- **If plain text**: Applies `esc()` and `nl2br()` for safe output
-
-### 3. Updated rendering methods
-- `buildNarrativeSection()`: Changed `nl2br(esc($remark))` to `$this->renderRichText($remark)`
-- Systemic exam section: Changed `nl2br(esc($value))` to `$this->renderRichText($value)`
-- Other exam section: Changed `nl2br(esc($otherExamText))` to `$this->renderRichText($otherExamText)`
-- Key investigations section: Changed `nl2br(esc($inhosRemark))` to `$this->renderRichText($inhosRemark)`
-
-## Changes Made
-```
-File: app/Controllers/Ipd_discharge.php
-- Line ~1591: Enhanced normalizeRichText() to preserve HTML
-- Line ~1625: Added new renderRichText() helper method
-- Line ~1768: Updated buildNarrativeSection() to use renderRichText()
-- Line ~1932: Updated systemic exam rendering to use renderRichText()
-- Line ~2094: Updated other exam rendering to use renderRichText()
-- Line ~2113: Updated key investigations rendering to use renderRichText()
-```
-
-## Testing
-1. Open discharge form: `/Ipd_discharge/ipd_select/1007170`
-2. Verify HTML editor content is saved correctly
-3. Preview discharge PDF
-4. Check that formatted content (bold, lists, paragraphs) appears correctly
-5. Test with both HTML editor and plain textarea fields (backward compatibility)
-
-## Backward Compatibility
-ā
Existing plain textarea fields continue to work
-ā
HTML editor fields now render correctly
-ā
No database changes required
-ā
Automatic detection of content type (HTML vs plain text)
-
-## Security
-- HTML editor content is NOT escaped (assumes HTML editor provides safe content)
-- Plain text content continues to be escaped with `esc()` function
-- No XSS risk if HTML editor properly sanitizes input
diff --git a/DISCHARGE_TEMPLATE_GUIDE.md b/DISCHARGE_TEMPLATE_GUIDE.md
deleted file mode 100644
index 1ac0961..0000000
--- a/DISCHARGE_TEMPLATE_GUIDE.md
+++ /dev/null
@@ -1,492 +0,0 @@
-# IPD Discharge Template System - CI3 to CI4 Migration Guide
-
-## Overview
-
-The CI4 discharge template system now **correctly matches** CI3 behavior where:
-- **Patient demographic table is NOT auto-generated in content**
-- **Content contains ONLY clinical sections** (complaints, diagnosis, medications, etc.)
-- **Templates control the entire layout** using tokens
-
----
-
-## How It Works (CI3 vs CI4)
-
-### CI3 System (Old - chamunda_discharge_template_html.php)
-
-```php
-
-
-
- | Name |
- = ucwords($ipd_master[0]->p_fname) ?> |
- UHID |
- = $ipd_master[0]->p_code ?> |
-
-
-
-
-
-
- = $FinalDiagnosis ?>
-
-
-
- = $Surgery ?>
-
-```
-
-**Key Points:**
-- Template was a **PHP file** with hardcoded HTML for patient info
-- Content variables (`$FinalDiagnosis`, `$Surgery`, etc.) were **HTML fragments**
-- Template decided what to show and in what order
-
-### CI4 System (New - Database Templates with Tokens)
-
-```html
-
-
-
- | Name | {{PATIENT_NAME}} |
- UHID | {{UHID}} |
-
-
- | Age/Gender | {{AGE_GENDER}} |
- IPD No | {{IPD_CODE}} |
-
-
-
-
-{{PATIENT_INFO_TABLE}}
-
-
-{{CONTENT}}
-
-
-{{FINAL_DIAGNOSIS}}
-{{SURGERY}}
-{{PROCEDURE}}
-{{DISCHARGE_MEDICATIONS}}
-```
-
-**Key Points:**
-- Templates are stored in **database** (`discharge_template` table)
-- Use **{{TOKEN}}** syntax instead of PHP variables
-- Content ({{CONTENT}}) contains **ONLY clinical sections** (NO patient table)
-- Patient table available as `{{PATIENT_INFO_TABLE}}` token
-
----
-
-## Available Tokens
-
-### Patient Demographic Tokens
-
-| Token | Description | Example Output |
-|-------|-------------|----------------|
-| `{{PATIENT_NAME}}` | Full patient name | KAMLA SINGH |
-| `{{UHID}}` | Patient UHID/code | P26051000001 |
-| `{{IPD_CODE}}` | IPD admission number | A26050000001 |
-| `{{AGE_GENDER}}` | Age and gender | 26 Year / Female |
-| `{{GUARDIAN}}` | Guardian relation and name | W/O of RAM SINGH |
-| `{{GUARDIAN_RELATION}}` | Guardian relation only | W/O of |
-| `{{GUARDIAN_NAME}}` | Guardian name only | RAM SINGH |
-| `{{PATIENT_ADDRESS}}` | Full address | KASHIPUR, District, State |
-| `{{PATIENT_PHONE}}` | Patient phone number | 9876543210 |
-
-### IPD Information Tokens
-
-| Token | Description | Example Output |
-|-------|-------------|----------------|
-| `{{DEPARTMENT}}` | Department name | General Medicine |
-| `{{ADMIT_DATE}}` | Admission date | 23-05-2026 |
-| `{{DISCHARGE_DATE}}` | Discharge date | 05-06-2026 |
-| `{{ADMIT_DATE_ONLY}}` | Admission date (same as ADMIT_DATE) | 23-05-2026 |
-| `{{DISCHARGE_DATE_ONLY}}` | Discharge date (same as DISCHARGE_DATE) | 05-06-2026 |
-| `{{ADMISSION_TIME}}` | Admission time | 10:30 AM |
-| `{{DISCHARGE_TIME}}` | Discharge time | 03:45 PM |
-| `{{ADMIT_TIME}}` | Admission time (same as ADMISSION_TIME) | 10:30 AM |
-| `{{INSURANCE_COMPANY}}` | Insurance company name | Star Health Insurance |
-| `{{DOCTOR_NAMES}}` | Treating doctor(s) with specialties | Dr. Rajesh Kumar [General Medicine], Dr. Priya Sharma [Cardiology] |
-| `{{DOCTOR_NAME}}` | Same as DOCTOR_NAMES | Dr. Rajesh Kumar [General Medicine] |
-
-### Hospital Information Tokens
-
-| Token | Description |
-|-------|-------------|
-| `{{H_Name}}` | Hospital name |
-| `{{hospital_address}}` | Combined hospital address |
-| `{{hospital_phone}}` | Hospital phone number |
-| `{{hospital_email}}` | Hospital email |
-| `{{H_logo}}` | Logo filename |
-| `{{H_logo_abs}}` | Absolute path to logo |
-
-### Pre-Built Table Token
-
-| Token | Description |
-|-------|-------------|
-| `{{PATIENT_INFO_TABLE}}` | Complete patient demographic table (matches CI3 format) |
-
-### Content Tokens
-
-| Token | Description |
-|-------|-------------|
-| `{{CONTENT}}` | **All clinical sections** (complaints, diagnosis, course, medications, etc.) |
-
-### Individual Section Tokens
-
-| Token | Description |
-|-------|-------------|
-| `{{FINAL_DIAGNOSIS}}` | Final diagnosis at discharge |
-| `{{SURGERY}}` | Surgical procedures performed |
-| `{{PROCEDURE}}` | Medical procedures |
-| `{{PRESENTING_COMPLAINTS}}` | Complaints with duration |
-| `{{GENERAL_EXAM_ADMISSION}}` | General examination on admission |
-| `{{CLINICAL_INVESTIGATION_REPORTS}}` | Lab and imaging reports |
-| `{{COURSE_IN_HOSPITAL}}` | Course during hospitalization |
-| `{{EXAMINATION_ON_DISCHARGE}}` | Examination findings at discharge |
-| `{{DISCHARGE_MEDICATIONS}}` | Medications prescribed |
-| `{{DIETARY_ADVICE}}` | Diet instructions |
-| `{{DISCHARGE_INSTRUCTIONS}}` | Discharge instructions and advice |
-| `{{PAIN_MEASUREMENT_SCALE}}` | Pain assessment |
-| `{{DRUG_ALLERGY_ADR}}` | Drug allergies and ADR history |
-| `{{CO_MORBIDITIES}}` | Co-morbid conditions |
-| `{{PERSONAL_HISTORY}}` | Personal history (smoking, alcohol, etc.) |
-
-### Meta Tokens
-
-| Token | Description |
-|-------|-------------|
-| `{{CURRENT_DATE}}` | Current date (dd-mm-yyyy) |
-| `{{PRINT_TIME}}` | Current timestamp |
-
----
-
-## Template Examples
-
-### Example 1: Blank Template (CI3-like, Just Content)
-
-```html
-
-```
-
-**Output:** Only clinical sections (complaints, diagnosis, medications, etc.)
-**No patient table** is shown automatically!
-
----
-
-### Example 2: Minimal Template with Patient Table Token
-
-```html
-{{PATIENT_INFO_TABLE}}
-{{CONTENT}}
-```
-
-**Output:** Patient demographic table + all clinical sections
-**Closest to CI3 default behavior**
-
----
-
-### Example 3: Custom Layout with Individual Tokens
-
-```html
-
-
{{H_Name}}
-
Discharge Summary
-
-
-
- | Name: |
- {{PATIENT_NAME}} |
- UHID: |
- {{UHID}} |
-
-
- | Age/Gender: |
- {{AGE_GENDER}} |
- IPD No: |
- {{IPD_CODE}} |
-
-
- | Admission: |
- {{ADMIT_DATE}} |
- Discharge: |
- {{DISCHARGE_DATE}} |
-
-
- | Phone: |
- {{PATIENT_PHONE}} |
- Insurance: |
- {{INSURANCE_COMPANY}} |
-
-
- | Department: |
- {{DEPARTMENT}} |
- Doctor(s): |
- {{DOCTOR_NAMES}} |
-
-
-
-
-
- {{CONTENT}}
-
-```
-
-**Output:** Custom-styled discharge with full control over layout, including phone, insurance, and doctor information
-
----
-
-### Example 4: Selective Sections (Pick What to Show)
-
-```html
-Discharge Summary
-
-{{PATIENT_INFO_TABLE}}
-
-
- {{FINAL_DIAGNOSIS}}
- {{SURGERY}}
- {{DISCHARGE_MEDICATIONS}}
- {{DISCHARGE_INSTRUCTIONS}}
-
-
-
-```
-
-**Output:** Shows ONLY diagnosis, surgery, medications, and instructions
-**Skips** complaints, course, examination, etc.
-
----
-
-### Example 5: CI3 Chamunda Template Converted to CI4
-
-```html
-
-
-Discharge Summary
-
-
-
-
- | Name |
- {{PATIENT_NAME}} |
- UHID |
- {{UHID}} |
-
-
- | Age & Gender |
- {{AGE_GENDER}} |
- IPD No. |
- {{IPD_CODE}} |
-
-
- | Guardian |
- {{GUARDIAN}} |
- Admission |
- {{ADMIT_DATE}} {{ADMISSION_TIME}} |
-
-
- | Phone No. |
- {{hospital_phone}} |
- Discharge |
- {{DISCHARGE_DATE}} {{DISCHARGE_TIME}} |
-
-
- | Address |
- {{PATIENT_ADDRESS}} |
- Org. Name |
- Direct |
-
-
- | Department |
- {{DEPARTMENT}} |
- |
- |
-
-
-
-
-{{CONTENT}}
-```
-
-**Output:** Exact replica of CI3 Chamunda template using CI4 tokens!
-
----
-
-## Migration Steps from CI3 to CI4
-
-### Step 1: Convert PHP Template to Token Template
-
-**Old CI3 Template:**
-```php
-= $h1_head ?>
-Patient: = ucwords($ipd_master[0]->p_fname) ?>
-
- = $FinalDiagnosis ?>
-
-```
-
-**New CI4 Template:**
-```html
-Discharge Summary
-Patient: {{PATIENT_NAME}}
-{{FINAL_DIAGNOSIS}}
-```
-
-### Step 2: Replace PHP Variables with Tokens
-
-| CI3 Variable | CI4 Token |
-|--------------|-----------|
-| `$ipd_master[0]->p_fname` | `{{PATIENT_NAME}}` |
-| `$ipd_master[0]->p_code` | `{{UHID}}` |
-| `$ipd_master[0]->ipd_code` | `{{IPD_CODE}}` |
-| `$ipd_master[0]->str_age . ' / ' . $xgender` | `{{AGE_GENDER}}` |
-| `$person->mphone1` | `{{PATIENT_PHONE}}` |
-| `$ipd_master[0]->ins_company_name` | `{{INSURANCE_COMPANY}}` |
-| `$doc_list_main_sign` (doctor names) | `{{DOCTOR_NAMES}}` |
-| `$FinalDiagnosis` | `{{FINAL_DIAGNOSIS}}` |
-| `$Surgery` | `{{SURGERY}}` |
-| `$Procedure` | `{{PROCEDURE}}` |
-| `$discharge_complaint` | `{{PRESENTING_COMPLAINTS}}` |
-| `$Course_in_the_hospital` | `{{COURSE_IN_HOSPITAL}}` |
-| `$Discharge_Medications` | `{{DISCHARGE_MEDICATIONS}}` |
-| `$Discharge_Instructions` | `{{DISCHARGE_INSTRUCTIONS}}` |
-
-### Step 3: Remove PHP Conditionals
-
-**Before:**
-```php
-
- = $Surgery ?>
-
-```
-
-**After:**
-```html
-{{SURGERY}}
-```
-
-Tokens automatically handle empty values (nothing shown if no data).
-
-### Step 4: Save to Database
-
-1. Go to Template Management UI (if available)
-2. **OR** Insert directly into `discharge_template` table:
-
-```sql
-INSERT INTO discharge_template (template_name, template_html, is_default, page_size)
-VALUES ('Chamunda Template', '', 1, 'A4');
-```
-
----
-
-## Testing Your Template
-
-### Test Case 1: Blank Template
-1. Create template with NO content (empty string)
-2. View discharge: `http://localhost:8080/Ipd_discharge/show_discharge/1/1?tpl=1`
-3. **Expected:** ONLY clinical sections (no patient table)
-
-### Test Case 2: Just {{CONTENT}}
-1. Create template with: `{{CONTENT}}`
-2. View discharge
-3. **Expected:** ONLY clinical sections (no patient table)
-
-### Test Case 3: Patient Table + Content
-1. Create template with: `{{PATIENT_INFO_TABLE}}{{CONTENT}}`
-2. View discharge
-3. **Expected:** Patient table + clinical sections
-
-### Test Case 4: Custom Layout
-1. Create template with individual tokens
-2. View discharge
-3. **Expected:** Your custom layout with data filled in
-
----
-
-## Common Issues and Solutions
-
-### Issue 1: Patient table still showing when template is blank
-
-**Cause:** Old cached discharge content in database
-**Solution:** Clear cached content:
-```bash
-php clear_discharge_content.php [ipd_id]
-```
-
-### Issue 2: Token not replaced (shows {{TOKEN_NAME}})
-
-**Cause:** Token name is misspelled or doesn't exist
-**Solution:** Check available tokens list above (case-insensitive)
-
-### Issue 3: Want old CI3 behavior exactly
-
-**Solution:** Use this template:
-```html
-{{PATIENT_INFO_TABLE}}
-{{CONTENT}}
-```
-
-### Issue 4: Need to show patient table in some templates but not others
-
-**Solution:**
-- Template A: Include `{{PATIENT_INFO_TABLE}}`
-- Template B: Omit it (blank or just `{{CONTENT}}`)
-
----
-
-## Best Practices
-
-### ā
DO:
-- Use `{{PATIENT_INFO_TABLE}}` for quick CI3-style patient demographics
-- Use individual tokens for custom layouts
-- Use `{{CONTENT}}` to show all clinical sections at once
-- Clear cached content after template changes
-- Test with different IPD cases (with/without surgery, delivery, etc.)
-
-### ā DON'T:
-- Don't expect patient table to auto-appear (it's a token now!)
-- Don't use PHP code in templates (use tokens instead)
-- Don't manually edit `ipd_discharge.content` column (use regenerate button)
-- Don't forget to set `is_default=1` for your primary template
-
----
-
-## Quick Reference
-
-### Viewing Options
-
-| URL | Description |
-|-----|-------------|
-| `/Ipd_discharge/show_discharge/{id}/1` | PDF with default template |
-| `/Ipd_discharge/show_discharge/{id}/1?tpl=5` | PDF with template ID 5 |
-| `/Ipd_discharge/preview_discharge_report/{id}` | Preview in browser |
-| `/Ipd_discharge/preview_discharge_report/{id}?tpl=5` | Preview with template ID 5 |
-| `/Ipd_discharge/preview_discharge_report/{id}?regen=1` | Force regenerate content |
-
-### Database Tables
-
-- `discharge_template` - Template definitions
-- `ipd_discharge` - Generated content (cached)
-- `ipd_discharge_complaint` - Complaints data
-- `ipd_discharge_diagnosis` - Diagnosis data
-- `ipd_discharge_drug` - Medications data
-- etc.
-
----
-
-## Summary
-
-**CI3 Way:**
-- Template = PHP file with hardcoded patient table
-- Content = Variables injected into template
-
-**CI4 Way (Corrected):**
-- Template = Database record with {{TOKENS}}
-- Content = ONLY clinical sections (no patient table by default)
-- Patient table = Available as `{{PATIENT_INFO_TABLE}}` token
-
-**Result:** Full control over layout, matches CI3 flexibility! š
diff --git a/DISCHARGE_TEMPLATE_PLACEHOLDERS.md b/DISCHARGE_TEMPLATE_PLACEHOLDERS.md
deleted file mode 100644
index f676a14..0000000
--- a/DISCHARGE_TEMPLATE_PLACEHOLDERS.md
+++ /dev/null
@@ -1,217 +0,0 @@
-# IPD Discharge Template Placeholders
-
-This document lists all available placeholders that can be used in IPD discharge templates.
-
-## How to Use Placeholders
-
-Placeholders can be used in templates using double curly braces: `{{PLACEHOLDER_NAME}}`
-
-Example:
-```html
-{{HOSPITAL_NAME}}
-Patient: {{PATIENT_NAME}} ({{UHID}})
-{{CONTENT}}
-{{SIGNATURE_BLOCK}}
-```
-
----
-
-## Hospital Information
-
-| Placeholder | Description | Example |
-|------------|-------------|---------|
-| `{{H_Name}}` or `{{HOSPITAL_NAME}}` | Hospital name | "City Hospital" |
-| `{{H_address_1}}` | Hospital address line 1 | "123 Main Street" |
-| `{{H_address_2}}` | Hospital address line 2 | "Medical District" |
-| `{{H_phone_No}}` or `{{HOSPITAL_PHONE}}` | Hospital phone number | "+91-123-4567890" |
-| `{{H_Email}}` or `{{HOSPITAL_EMAIL}}` | Hospital email | "info@hospital.com" |
-| `{{H_logo}}` | Hospital logo filename | "logo.png" |
-| `{{H_logo_abs}}` | Absolute path to logo | "/path/to/public/assets/images/logo.png" |
-| `{{HOSPITAL_ADDRESS}}` | Combined address (line 1 + line 2) | "123 Main Street, Medical District" |
-
----
-
-## Patient Information
-
-| Placeholder | Description | Example |
-|------------|-------------|---------|
-| `{{PATIENT_TITLE}}` | Patient title/prefix | "Mr." / "Mrs." / "Miss" |
-| `{{PATIENT_NAME}}` | Patient full name | "John Doe" |
-| `{{UHID}}` | Patient UHID/Registration number | "UHID123456" |
-| `{{IPD_CODE}}` | IPD admission code | "IPD001234" |
-| `{{AGE_GENDER}}` | Age and gender | "45 Years / Male" |
-| `{{GUARDIAN}}` or `{{GUARDIAN_NAME}}` | Guardian/relative name | "S/o Ramesh Kumar" |
-| `{{GUARDIAN_RELATION}}` | Guardian relation | "S/o" or "W/o" |
-| `{{PATIENT_ADDRESS}}` | Patient full address | "456 Park Lane, City" |
-| `{{PATIENT_PHONE}}` | Patient phone number | "+91-9876543210" |
-| `{{INSURANCE_COMPANY}}` | Insurance company name | "HDFC Ergo" or "Direct" |
-| `{{PATIENT_INFO_TABLE}}` | Auto-generated patient info table | (HTML table) |
-
----
-
-## Admission & Discharge Dates
-
-| Placeholder | Description | Example |
-|------------|-------------|---------|
-| `{{ADMIT_DATE}}` | Admission date | "05-06-2026" |
-| `{{DISCHARGE_DATE}}` | Discharge date | "07-06-2026" |
-| `{{ADMIT_DATE_ONLY}}` | Admission date (alternative) | "05-06-2026" |
-| `{{DISCHARGE_DATE_ONLY}}` | Discharge date (alternative) | "07-06-2026" |
-| `{{ADMISSION_TIME}}` | Admission time | "10:30 AM" |
-| `{{DISCHARGE_TIME}}` | Discharge time | "04:15 PM" |
-| `{{ADMIT_TIME}}` | Admission time (alternative) | "10:30 AM" |
-| `{{CURRENT_DATE}}` | Current date (when PDF generated) | "07-06-2026" |
-| `{{PRINT_TIME}}` | PDF generation timestamp | "07-06-2026 16:45:30" |
-
----
-
-## Medical Information
-
-| Placeholder | Description | Example |
-|------------|-------------|---------|
-| `{{DEPARTMENT}}` | Admission department | "General Medicine" |
-| `{{DOCTOR_NAMES}}` or `{{DOCTOR_NAME}}` | Treating doctor(s) | "Dr. Sharma, Dr. Patel" |
-
----
-
-## Clinical Content Sections
-
-### Full Content
-| Placeholder | Description |
-|------------|-------------|
-| `{{CONTENT}}` | **Complete discharge content** - includes all sections below |
-
-### Individual Sections
-| Placeholder | Description |
-|------------|-------------|
-| `{{DISCHARGE_SUMMARY}}` | Discharge status header (e.g., "Discharged", "LAMA") |
-| `{{PRESENTING_COMPLAINTS}}` | Presenting complaints and reason for admission |
-| `{{PAIN_MEASUREMENT_SCALE}}` | Pain scale measurement (if recorded) |
-| `{{GENERAL_EXAM_ADMISSION}}` | General examination findings on admission |
-| `{{PERSONAL_HISTORY}}` | Personal history (smoking, alcohol, etc.) |
-| `{{DRUG_ALLERGY_ADR}}` | Drug allergy status and ADR history |
-| `{{CO_MORBIDITIES}}` | Co-morbidities |
-| `{{CLINICAL_INVESTIGATION_REPORTS}}` | Lab reports, X-rays, CT/MRI results |
-| `{{FINAL_DIAGNOSIS}}` | Final diagnosis |
-| `{{COURSE_IN_HOSPITAL}}` | Course in the hospital / treatment details |
-| `{{EXAMINATION_ON_DISCHARGE}}` | Physical examination on discharge |
-| `{{SURGERY}}` | Surgical procedures performed |
-| `{{PROCEDURE}}` | Other procedures performed |
-| `{{DISCHARGE_MEDICATIONS}}` | Discharge medications table |
-
-### Discharge Instructions
-| Placeholder | Description |
-|------------|-------------|
-| `{{DISCHARGE_INSTRUCTIONS}}` | **Full instruction section** (Dietary + Other + Discharge Summary) |
-| `{{DIETARY_ADVICE}}` | Dietary advice (selected food items) |
-| `{{OTHER_ADVICE}}` | Other Advice field only |
-| `{{INSTRUCTION_REMARK}}` or `{{DISCHARGE_ADVICE}}` | Discharge Summary field only |
-
-**NEW FEATURE:** You can now use `{{OTHER_ADVICE}}` and `{{DISCHARGE_ADVICE}}` separately to control layout!
-
-Example:
-```html
-Other Advice
-{{OTHER_ADVICE}}
-
-Discharge Summary
-{{DISCHARGE_ADVICE}}
-```
-
-Or use the combined section:
-```html
-{{DISCHARGE_INSTRUCTIONS}}
-```
-
-### Signature Block
-| Placeholder | Description |
-|------------|-------------|
-| `{{SIGNATURE_BLOCK}}` | Signature table for Consultant, Medical Officer, and Receiver |
-
----
-
-## Legacy Aliases
-
-These are provided for CI3 compatibility:
-
-| Legacy Placeholder | Modern Equivalent |
-|-------------------|------------------|
-| `{FinalDiagnosis}` | `{{FINAL_DIAGNOSIS}}` |
-| `{Surgery}` | `{{SURGERY}}` |
-| `{Procedure}` | `{{PROCEDURE}}` |
-| `{personal_history}` | `{{PERSONAL_HISTORY}}` |
-| `{discharge_complaint}` | `{{PRESENTING_COMPLAINTS}}` |
-| `{discharge_general_exam}` | `{{GENERAL_EXAM_ADMISSION}}` |
-| `{Course_in_the_hospital}` | `{{COURSE_IN_HOSPITAL}}` |
-| `{Discharge_Medications}` | `{{DISCHARGE_MEDICATIONS}}` |
-| `{diet_advice}` | `{{DIETARY_ADVICE}}` |
-| `{Discharge_Instructions}` | `{{DISCHARGE_INSTRUCTIONS}}` |
-
----
-
-## Example Template
-
-```html
-
-
-
- Discharge Summary
-
-
-
-
-
-
-
-
- | Patient Name: |
- {{PATIENT_NAME}} |
- UHID: |
- {{UHID}} |
-
-
- | Age/Gender: |
- {{AGE_GENDER}} |
- IPD Code: |
- {{IPD_CODE}} |
-
-
- | Admission Date: |
- {{ADMIT_DATE}} {{ADMISSION_TIME}} |
- Discharge Date: |
- {{DISCHARGE_DATE}} {{DISCHARGE_TIME}} |
-
-
- | Department: |
- {{DEPARTMENT}} |
- Doctor: |
- {{DOCTOR_NAMES}} |
-
-
-
-
- {{CONTENT}}
-
-
- {{SIGNATURE_BLOCK}}
-
-
-
-```
-
----
-
-## Notes
-
-- All placeholders are **case-insensitive**: `{{PATIENT_NAME}}`, `{{patient_name}}`, and `{{Patient_Name}}` all work
-- Use `{{CONTENT}}` for the complete discharge content, or use individual section placeholders for custom layouts
-- If a placeholder has no data, it will be replaced with an empty string
-- HTML content is preserved - sections already include proper formatting
diff --git a/DISCHARGE_TEMPLATE_TOKENS.md b/DISCHARGE_TEMPLATE_TOKENS.md
deleted file mode 100644
index 4c5e2ff..0000000
--- a/DISCHARGE_TEMPLATE_TOKENS.md
+++ /dev/null
@@ -1,286 +0,0 @@
-# IPD Discharge Template Placeholders - Quick Reference
-
-## 1. Hospital Information
-*From Hospital Setting table*
-
-```
-{{H_Name}} - Hospital name
-{{H_address_1}} - Hospital address line 1
-{{H_address_2}} - Hospital address line 2
-{{H_phone_No}} - Hospital phone number
-{{H_Email}} - Hospital email
-{{H_logo}} - Logo filename
-{{H_logo_abs}} - Absolute path to logo file
-{{hospital_name}} - Hospital name (same as H_Name)
-{{hospital_address}} - Combined address (address_1 + address_2)
-{{hospital_phone}} - Hospital phone (same as H_phone_No)
-{{hospital_email}} - Hospital email (same as H_Email)
-```
-
----
-
-## 2. Patient Information
-*From Patient_Master table*
-
-```
-{{PATIENT_NAME}} - Full patient name
-{{PATIENT_TITLE}} - Patient title/prefix (e.g., "Mr.", "Mrs.", "Miss")
-{{UHID}} - Patient UHID/registration code
-{{AGE_GENDER}} - Age and gender combined (e.g., "26 Year / Female")
-{{GUARDIAN}} - Guardian relation and name (e.g., "W/O RAM SINGH")
-{{GUARDIAN_RELATION}} - Guardian relation only (e.g., "W/O")
-{{GUARDIAN_NAME}} - Guardian name only (e.g., "RAM SINGH")
-{{PATIENT_ADDRESS}} - Full patient address
-{{PATIENT_PHONE}} - Patient phone number ⨠NEW
-```
-
----
-
-## 3. IPD Information
-*From IPD_Master table*
-
-```
-{{IPD_CODE}} - IPD admission number (e.g., "A26050000001")
-{{DEPARTMENT}} - Department name (e.g., "General Medicine")
-{{ADMIT_DATE}} - Admission date (dd-mm-yyyy format)
-{{DISCHARGE_DATE}} - Discharge date (dd-mm-yyyy format)
-{{ADMIT_DATE_ONLY}} - Admission date (same as ADMIT_DATE)
-{{DISCHARGE_DATE_ONLY}} - Discharge date (same as DISCHARGE_DATE)
-{{ADMISSION_TIME}} - Admission time (HH:MM AM/PM)
-{{DISCHARGE_TIME}} - Discharge time (HH:MM AM/PM)
-{{ADMIT_TIME}} - Admission time (same as ADMISSION_TIME)
-{{ISDELIVERY}} - Delivery case flag (1 for yes, 0 for no)
-{{INSURANCE_COMPANY}} - Insurance company name (defaults to "Direct") ⨠NEW
-{{DOCTOR_NAMES}} - Treating doctors with specialties ⨠NEW
-{{DOCTOR_NAME}} - Same as DOCTOR_NAMES ⨠NEW
-```
-
----
-
-## 4. IPD Discharge Content
-
-### 4.1 Complete Content Token
-
-```
-{{CONTENT}} - All clinical sections combined (NO patient table)
-```
-
-### 4.2 Section Placeholders for Custom Layout/Order
-
-```
-{{DISCHARGE_SUMMARY}} - High-level summary (department, treating doctors, dates)
-{{FINAL_DIAGNOSIS}} - Final diagnosis at discharge
-{{SURGERY}} - Surgical procedures performed
-{{PROCEDURE}} - Medical procedures
-{{PERSONAL_HISTORY}} - Personal history (smoking, alcohol, etc.)
-{{PRESENTING_COMPLAINTS}} - Complaints with duration and reason for admission
-{{PAIN_MEASUREMENT_SCALE}} - Pain assessment scale
-{{GENERAL_EXAM_ADMISSION}} - General examination on admission
-{{CLINICAL_INVESTIGATION_REPORTS}} - Lab and imaging investigation reports
-{{COURSE_IN_HOSPITAL}} - Course during hospitalization
-{{EXAMINATION_ON_DISCHARGE}} - Examination findings at discharge
-{{DRUG_ALLERGY_ADR}} - Drug allergies and adverse drug reactions
-{{CO_MORBIDITIES}} - Co-morbid conditions
-{{DISCHARGE_MEDICATIONS}} - Medications prescribed at discharge
-{{DIETARY_ADVICE}} - Dietary advice and instructions
-{{DISCHARGE_INSTRUCTIONS}} - Discharge instructions and follow-up advice
-{{SIGNATURE_BLOCK}} - Signature block for consultant
-```
-
-**Note:** `{{DISCHARGE_SUMMARY}}` section now includes:
-- Department name (from `ipd_master.dept_id` or `department_id`)
-- Treating doctor(s) with specializations (from `ipd_master.doc_list`)
-- Date of admission
-- Date of discharge
-
-### 4.3 Pre-Built Patient Table
-
-```
-{{PATIENT_INFO_TABLE}} - Complete patient demographic table (HTML)
- Includes: Name, UHID, Age/Gender, IPD No, Guardian,
- Phone, Admission, Discharge, Address, Insurance, Department
-```
-
----
-
-## 5. Common / Meta Tokens
-
-```
-{{CURRENT_DATE}} - Current date (dd-mm-yyyy format)
-{{PRINT_TIME}} - Current date and time (dd-mm-yyyy HH:MM:SS)
-```
-
----
-
-## Token Usage Examples
-
-### Example 1: Minimal Template (Just Content)
-```html
-{{CONTENT}}
-```
-**Result:** Shows only clinical sections (no patient table)
-
----
-
-### Example 2: With Patient Table
-```html
-{{PATIENT_INFO_TABLE}}
-{{CONTENT}}
-```
-**Result:** Patient demographics + all clinical sections
-
----
-
-### Example 3: Custom Layout with New Tokens
-```html
-{{H_Name}}
-Discharge Summary
-
-
-
- | Patient Name: |
- {{PATIENT_NAME}} |
- UHID: |
- {{UHID}} |
-
-
- | Phone: |
- {{PATIENT_PHONE}} |
- Insurance: |
- {{INSURANCE_COMPANY}} |
-
-
- | Treating Doctor(s): {{DOCTOR_NAMES}} |
-
-
-
-
-
-{{CONTENT}}
-```
-
----
-
-### Example 4: Selective Sections Only
-```html
-Discharge Summary
-
-{{PATIENT_INFO_TABLE}}
-
-Clinical Information
-{{FINAL_DIAGNOSIS}}
-{{SURGERY}}
-{{PROCEDURE}}
-
-Treatment Plan
-{{DISCHARGE_MEDICATIONS}}
-{{DIETARY_ADVICE}}
-{{DISCHARGE_INSTRUCTIONS}}
-```
-**Result:** Shows only selected sections, omits complaints, examination, etc.
-
----
-
-## Notes
-
-- **All tokens are case-insensitive** ({{PATIENT_NAME}}, {{patient_name}}, {{Patient_Name}} all work)
-- **Empty values show nothing** - No need for conditionals, tokens auto-hide if data is missing
-- **{{CONTENT}} never includes patient table** - Add {{PATIENT_INFO_TABLE}} explicitly if needed
-- **Doctor names from ipd_master.doc_list** - Automatically formatted as "Dr. Name [Specialty]"
-- **Insurance defaults to "Direct"** - Shows "Direct" when no insurance company assigned
-
----
-
-## Testing Your Template
-
-1. Create/edit template in `discharge_template` table
-2. Clear cached content: `php clear_discharge_content.php [ipd_id]`
-3. View discharge: `http://localhost:8080/Ipd_discharge/show_discharge/[ipd_id]/1?tpl=[template_id]`
-4. Check output for correct token replacement
-
----
-
-## Complete Template Example (Full Featured)
-
-```html
-
-
-
-
-
-
-
-
-
-
-
-
- | Patient Name |
- {{PATIENT_NAME}} |
- UHID |
- {{UHID}} |
-
-
- | Age / Gender |
- {{AGE_GENDER}} |
- IPD No. |
- {{IPD_CODE}} |
-
-
- | Guardian |
- {{GUARDIAN}} |
- Phone |
- {{PATIENT_PHONE}} |
-
-
- | Address |
- {{PATIENT_ADDRESS}} |
-
-
- | Department |
- {{DEPARTMENT}} |
- Insurance |
- {{INSURANCE_COMPANY}} |
-
-
- | Admission Date/Time |
- {{ADMIT_DATE}} {{ADMISSION_TIME}} |
- Discharge Date/Time |
- {{DISCHARGE_DATE}} {{DISCHARGE_TIME}} |
-
-
- | Treating Doctor(s) |
- {{DOCTOR_NAMES}} |
-
-
-
-
- {{CONTENT}}
-
-
-
-
-
-```
-
-This template includes:
-- ā
All new tokens (PATIENT_PHONE, INSURANCE_COMPANY, DOCTOR_NAMES)
-- ā
Complete patient demographics in custom table
-- ā
All clinical sections via {{CONTENT}}
-- ā
Professional styling
-- ā
Hospital header and footer
diff --git a/DUAL_BRIDGE_ARCHITECTURE.md b/DUAL_BRIDGE_ARCHITECTURE.md
deleted file mode 100644
index 0f84030..0000000
--- a/DUAL_BRIDGE_ARCHITECTURE.md
+++ /dev/null
@@ -1,296 +0,0 @@
-# Dual-Bridge Architecture Configuration Guide
-
-## Architecture Overview
-
-```
-HMS CI4 Queues Events
- ā Routes by event_type prefix
- āāā snomed.* events
- ā ā POST to BRIDGE_SYNC_URL
- ā https://csnotk.e-atria.in/api/bridge
- ā (CSNOtk Bridge: Codes diagnosis ā FHIR)
- ā
- āāā abdm.* events
- ā POST to ABDM_BRIDGE_URL
- https://abdm-bridge.e-atria.in/api/v1/bridge
- (ABDM Bridge: Routes to ABDM M1 server)
-```
-
----
-
-## Event Type Routing Table
-
-| Event Type | Destination | Purpose |
-|-----------|-------------|---------|
-| `snomed.diagnosis.validate` | CSNOtk `/api/bridge` | Validate & code diagnosis with SNOMED CT |
-| `snomed.medication.validate` | CSNOtk `/api/bridge` | Validate & code medication with SNOMED CT |
-| `abdm.abha.validate` | ABDM Bridge `/api/v1/bridge` | Validate ABHA number with ABDM M1 |
-| `abdm.scan_share.lookup` | ABDM Bridge `/api/v1/bridge` | QR code lookup for health records |
-| `abdm.fhir.share.requested` | ABDM Bridge `/api/v1/bridge` | Push FHIR bundle to ABDM M1 |
-| `abdm.opd.prescription.share.requested` | ABDM Bridge `/api/v1/bridge` | Push OPD prescription bundle |
-| `abdm.ipd.discharge.share.requested` | ABDM Bridge `/api/v1/bridge` | Push IPD discharge bundle |
-| `abdm.diagnosis.report.share.requested` | ABDM Bridge `/api/v1/bridge` | Push diagnosis report bundle |
-| `abdm.consent.requested` | ABDM Bridge `/api/v1/bridge` | Request patient consent for data access |
-
----
-
-## HMS .env Configuration Required
-
-### Step 1: Dual Bridge URLs
-
-Replace the current BRIDGE configuration with this:
-
-```env
-# ==================== CSNOtk Bridge (SNOMED CT Terminology) ====================
-# Purpose: Receive diagnosis/medication events, validate with SNOMED CT, return FHIR-coded data
-# Endpoint: POST /api/bridge
-# Used by: BridgeSyncService when routing snomed.* events
-BRIDGE_SYNC_URL = https://csnotk.e-atria.in/api/bridge
-BRIDGE_SYNC_TOKEN =
-BRIDGE_SYNC_TIMEOUT = 20
-
-# ==================== ABDM Bridge (ABDM M1 Communication) ====================
-# Purpose: Receive ABDM events, route to ABDM Live/Sandbox M1 server
-# Endpoint: POST /api/v1/bridge
-# Used by: BridgeSyncService when routing abdm.* events
-# Architecture: Multiple HMS instances ā Single ABDM Bridge ā ABDM M1 Server
-ABDM_BRIDGE_URL = https://abdm-bridge.e-atria.in/api/v1/bridge
-ABDM_BRIDGE_TOKEN =
-
-# ==================== Bridge Configuration ====================
-BRIDGE_SOURCE_CODE = SBXID_033661
-BRIDGE_SYNC_PROVIDER = bridge
-
-# ==================== SNOMED CT Terminology Service (Direct REST API) ====================
-# Purpose: Direct access to CSNOtk REST API for autocomplete (OPD diagnosis search)
-# Endpoints: /rest/search/suggest, /rest/search/lookup, /rest/search/validate/id
-# Used by: CsnotkTerminologyService in OPD_Prescription controller
-snomed.csnotk.baseUrl = https://csnotk.e-atria.in/csnoserv
-snomed.csnotk.enabled = true
-snomed.csnotk.timeoutSec = 10
-```
-
-### Step 2: Generate Bearer Tokens
-
-Generate TWO random tokens (one for each bridge):
-
-```bash
-# Token 1 for CSNOtk Bridge
-openssl rand -hex 32
-# Example: a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6q7r8s9t0u1v2w3x4y5z6a7b8c9d0e1f2
-
-# Token 2 for ABDM Bridge
-openssl rand -hex 32
-# Example: f2e1d0c9b8a7z6y5x4w3v2u1t0s9r8q7p6o5n4m3l2k1j0i9h8g7f6e5d4c3b2a1
-```
-
-### Step 3: Update .env Tokens
-
-```env
-BRIDGE_SYNC_TOKEN = a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6q7r8s9t0u1v2w3x4y5z6a7b8c9d0e1f2
-ABDM_BRIDGE_TOKEN = f2e1d0c9b8a7z6y5x4w3v2u1t0s9r8q7p6o5n4m3l2k1j0i9h8g7f6e5d4c3b2a1
-```
-
----
-
-## BridgeSyncService Routing Logic (To Be Implemented)
-
-Update `app/Libraries/BridgeSyncService.php` buildBridgeDispatchContext() to route based on event prefix:
-
-### Pseudocode Logic
-
-```php
-private function buildBridgeDispatchContext(array $row, array $payload): array
-{
- $eventType = (string) ($row['event_type'] ?? '');
-
- // Route snomed.* events to CSNOtk
- if (str_starts_with($eventType, 'snomed.')) {
- return [
- 'ok' => true,
- 'channel' => 'csnotk',
- 'endpoint' => $this->readSetting('BRIDGE_SYNC_URL'), // CSNOtk bridge
- 'method' => 'POST',
- 'headers' => [
- 'Content-Type' => 'application/json',
- 'Authorization' => 'Bearer ' . $this->readSetting('BRIDGE_SYNC_TOKEN'),
- ],
- 'body' => [
- 'queue_id' => (int) ($row['id'] ?? 0),
- 'source' => $source,
- 'event_type' => $eventType,
- 'payload' => $payload,
- 'occurred_at' => (string) ($row['created_at'] ?? ''),
- ],
- ];
- }
-
- // Route abdm.* events to ABDM Bridge
- if (str_starts_with($eventType, 'abdm.')) {
- return [
- 'ok' => true,
- 'channel' => 'abdm',
- 'endpoint' => $this->readSetting('ABDM_BRIDGE_URL'), // ABDM bridge
- 'method' => 'POST',
- 'headers' => [
- 'Content-Type' => 'application/json',
- 'Authorization' => 'Bearer ' . $this->readSetting('ABDM_BRIDGE_TOKEN'),
- ],
- 'body' => [
- 'queue_id' => (int) ($row['id'] ?? 0),
- 'source' => $source,
- 'event_type' => $eventType,
- 'payload' => $payload,
- 'occurred_at' => (string) ($row['created_at'] ?? ''),
- ],
- ];
- }
-
- // Unknown event type
- return ['ok' => false, 'error' => 'Unsupported event_type prefix'];
-}
-```
-
----
-
-## CSNOtk Bridge `/api/bridge` Contract
-
-### Request Format
-
-```json
-{
- "queue_id": 12345,
- "source": "SBXID_033661",
- "event_type": "snomed.diagnosis.validate",
- "payload": {
- "diagnosis_text": "fever",
- "return_limit": 10
- },
- "occurred_at": "2024-05-13T10:30:00+05:30"
-}
-```
-
-### Response Format (Expected)
-
-```json
-{
- "ok": 1,
- "event_type": "snomed.diagnosis.validate",
- "data": [
- {
- "concept_id": "25064002",
- "term": "Headache",
- "hierarchy": "disorder",
- "is_preferred": 1,
- "concept_fsn": "Headache (disorder)"
- }
- ],
- "request_id": "REQ-abc123"
-}
-```
-
----
-
-## ABDM Bridge `/api/v1/bridge` Contract
-
-**(See `gateway-php-ci4/README.md` for full API contract)**
-
-### Request Format
-
-```json
-{
- "queue_id": 12345,
- "source": "SBXID_033661",
- "event_type": "abdm.abha.validate",
- "payload": {
- "abha_id": "00-0000-0000-0000"
- },
- "occurred_at": "2024-05-13T10:30:00+05:30"
-}
-```
-
-### Response Format (Expected)
-
-```json
-{
- "ok": 1,
- "event_type": "abdm.abha.validate",
- "request_id": "REQ-abc123",
- "data": {
- "abha": "00-0000-0000-0000",
- "status": "VALID"
- }
-}
-```
-
----
-
-## Implementation Checklist
-
-### Phase 1: Configuration
-- [ ] Update HMS `.env` with both `BRIDGE_SYNC_URL` (CSNOtk) and `ABDM_BRIDGE_URL` (ABDM)
-- [ ] Generate two separate bearer tokens
-- [ ] Set `BRIDGE_SYNC_TOKEN` and `ABDM_BRIDGE_TOKEN` in .env
-- [ ] Document tokens in secure location (password manager)
-
-### Phase 2: Code Changes
-- [ ] Update `BridgeSyncService::buildBridgeDispatchContext()` with routing logic
-- [ ] Update `BridgeSyncService::buildDispatchContext()` to handle snomed.* routing
-- [ ] Update `BridgeSyncService::readSetting()` to support `ABDM_BRIDGE_URL` and `ABDM_BRIDGE_TOKEN`
-- [ ] Add logging to distinguish between CSNOtk and ABDM bridge calls in `abdm_api_logs` table
-
-### Phase 3: Testing
-- [ ] Queue a `snomed.diagnosis.validate` event and verify it goes to CSNOtk
-- [ ] Queue an `abdm.abha.validate` event and verify it goes to ABDM Bridge
-- [ ] Check `abdm_api_logs` for successful routing
-- [ ] Verify CSNOtk returns SNOMED-coded data
-- [ ] Verify ABDM Bridge routes to ABDM M1 correctly
-
-### Phase 4: Deployment
-- [ ] Deploy PHP gateway to https://abdm-bridge.e-atria.in (if not already live)
-- [ ] Configure gateway `.env` with `GATEWAY_BEARER_TOKEN` matching HMS `ABDM_BRIDGE_TOKEN`
-- [ ] Run `php spark bridge:sync --limit 10` to test both bridge types
-- [ ] Monitor logs for any routing or authentication errors
-
----
-
-## Database Logging
-
-The `abdm_api_logs` table will now record:
-- `channel` = 'csnotk' or 'abdm' (for routing differentiation)
-- `event_type` = snomed.* or abdm.*
-- `endpoint` = CSNOtk or ABDM bridge URL used
-- `status` = 'success' or 'error'
-- `error_message` = 403 Unauthorized, 404 Not Found, etc.
-
----
-
-## Troubleshooting
-
-### Problem: 403 Unauthorized on CSNOtk
-- **Check:** BRIDGE_SYNC_TOKEN matches CSNOtk Bridge expectation
-- **Verify:** Request to `https://csnotk.e-atria.in/api/bridge` includes bearer token
-
-### Problem: 403 Unauthorized on ABDM Bridge
-- **Check:** ABDM_BRIDGE_TOKEN matches PHP gateway `GATEWAY_BEARER_TOKEN`
-- **Verify:** PHP gateway `.env` has the same token as HMS `ABDM_BRIDGE_TOKEN`
-
-### Problem: Events stuck in pending status
-- **Check:** Routing logic correctly identifies event prefix (snomed.* vs abdm.*)
-- **Query:** `SELECT * FROM bridge_sync_queue WHERE status='pending' ORDER BY created_at DESC`
-- **Debug:** Add logging to see which endpoint was called
-
-### Problem: CSNOtk returns 404 on /api/bridge
-- **Cause:** `/api/bridge` endpoint may not be exposed on the CSNOtk public server
-- **Fallback:** Check if CSNOtk only exposes `/rest/search/*` endpoints (direct API calls only)
-- **Action:** If needed, create intermediate queue processor for CSNOtk terminology service
-
----
-
-## References
-
-- **CSNOtk REST API Reference:** `docs/CSNOTK_API_REFERENCE.md`
-- **CSNOtk Database:** `SnomedCT_InternationalRF2_PRODUCTION_20260501T120000Z/`
-- **ABDM PHP Gateway:** `gateway-php-ci4/` (deployment guide: `ABDM_GATEWAY_PHP_DEPLOYMENT.md`)
-- **Current CSNOtk Direct API Integration:** `app/Libraries/CsnotkTerminologyService.php`
-- **Bridge Service:** `app/Libraries/BridgeSyncService.php`
diff --git a/FILE_INDEX_ABDM_GATEWAY.md b/FILE_INDEX_ABDM_GATEWAY.md
deleted file mode 100644
index c5fd0af..0000000
--- a/FILE_INDEX_ABDM_GATEWAY.md
+++ /dev/null
@@ -1,334 +0,0 @@
-# ABDM Integration - Complete File Index
-
-**Date:** May 12, 2026
-**Status:** Configuration + Middleware Gateway Complete ā
-
----
-
-## š ABDM Configuration Files
-
-### Location: `docs/`
-
-| File | Purpose | Size | Read Time |
-|------|---------|------|-----------|
-| `ABDM_QUICK_START.md` | Fast-track 7-step testing guide | 8KB | 5 min |
-| `ABDM_SANDBOX_SETUP.md` | Complete integration reference | 15KB | 15 min |
-| `ABDM_SANDBOX_CHECKLIST.md` | Implementation status tracking | 10KB | 5 min |
-| `ABDM_GATEWAY_ARCHITECTURE.md` | CSNOtk vs Custom gateway comparison | 20KB | 10 min |
-
----
-
-## š Middleware Gateway Files
-
-### Location: `middleware-gateway/`
-
-| File | Purpose | Type | Priority |
-|------|---------|------|----------|
-| `server.js` | Main Node.js application (400+ lines) | Code | āāā |
-| `package.json` | NPM dependencies (15 packages) | Config | āāā |
-| `Dockerfile` | Docker image definition | Config | āāā |
-| `docker-compose.yml` | Gateway + Nginx containers | Config | āāā |
-| `nginx.conf` | Reverse proxy + SSL config | Config | āāā |
-| `deploy.sh` | Automated Ubuntu deployment | Script | āāā |
-| `.env.example` | Configuration template | Config | āā |
-| `setup-ubuntu.sh` | System dependency installer | Script | ā |
-| `README.md` | Quick reference guide | Docs | āā |
-| `DEPLOYMENT_GUIDE.md` | Detailed deployment steps | Docs | āā |
-
----
-
-## š Session Summaries
-
-| File | Purpose | Date |
-|------|---------|------|
-| `SESSION_SUMMARY_ABDM_SANDBOX.md` | ABDM Sandbox configuration summary | May 12, 2026 |
-| `SESSION_SUMMARY_MIDDLEWARE_GATEWAY.md` | Middleware gateway creation summary | May 12, 2026 |
-
----
-
-## š Updated Configuration Files
-
-| File | Change | Status |
-|------|--------|--------|
-| `.env` | Added ABDM gateway options documentation | ā
Complete |
-
----
-
-## šÆ Quick Navigation
-
-### For Testing ABDM (This Week)
-1. Start: `docs/ABDM_QUICK_START.md` (7 tests)
-2. Reference: `docs/ABDM_SANDBOX_SETUP.md`
-3. Track: `docs/ABDM_SANDBOX_CHECKLIST.md`
-
-### For Deploying Custom Gateway (Next Week)
-1. Overview: `middleware-gateway/README.md`
-2. Deploy: `middleware-gateway/DEPLOYMENT_GUIDE.md`
-3. Run: `sudo ./middleware-gateway/deploy.sh`
-
-### For Architecture Understanding
-1. Read: `docs/ABDM_GATEWAY_ARCHITECTURE.md`
-2. Compare: CSNOtk vs Custom gateway options
-3. Decide: Which approach for your project
-
----
-
-## š What's Ready Now
-
-### ā
Configuration (5 files)
-- ABDM sandbox credentials in .env
-- SNOMED service endpoints
-- Gateway URLs (both options)
-- Middleware authentication setup
-
-### ā
Middleware Gateway (10 files)
-- Complete Node.js application
-- Docker containerization
-- Nginx reverse proxy
-- Automated deployment script
-- Full documentation
-
-### ā
Documentation (6 files)
-- Quick start guide
-- Full deployment guide
-- Architecture comparison
-- Implementation checklist
-- Session summaries
-
----
-
-## š Deployment Paths
-
-### Path 1: Quick Testing (Today)
-```
-Current State:
-āā ABDM credentials: ā
Configured
-āā CSNOtk gateway: ā
Ready to use
-āā OPD ABDM form: ā
Ready to test
-
-Action:
-ā docs/ABDM_QUICK_START.md (7 steps)
-ā Complete testing this week
-```
-
-### Path 2: Custom Gateway (Next Week)
-```
-Preparation:
-āā Provision Ubuntu server (DigitalOcean, AWS, etc)
-āā DNS: Create A record for abdm-bridge.e-atria.in
-āā Upload middleware-gateway/ folder
-
-Deployment:
-ā ssh root@server
-ā cd /opt/middleware-gateway
-ā sudo ./deploy.sh
-
-Time: 15 minutes (fully automated)
-```
-
-### Path 3: Hybrid (Recommended)
-```
-Week 1: Use CSNOtk for testing
-Week 2: Deploy custom gateway in parallel
-Week 3: Switch HMS to new gateway
-Week 4+: Production operations
-```
-
----
-
-## š§ Key Commands
-
-### Deploy Custom Gateway
-```bash
-cd /opt/middleware-gateway
-sudo ./deploy.sh
-```
-
-### Configure HMS
-```bash
-# Edit .env
-BRIDGE_SYNC_URL = https://abdm-bridge.e-atria.in/api/v3
-
-# Restart
-docker-compose restart
-```
-
-### Test Gateway
-```bash
-curl https://abdm-bridge.e-atria.in/api/v3/health
-```
-
-### View Logs
-```bash
-docker logs -f abdm-bridge-gateway
-```
-
----
-
-## š Feature Completeness
-
-### ABDM Integration
-- ā
Sandbox credentials configured
-- ā
FHIR bundle generation
-- ā
OPD ABDM compliance
-- ā
SNOMED coding
-- ā
ABHA validation ready
-- ā
Consent workflow ready
-- ā³ Bundle push infrastructure ready
-
-### Gateway Infrastructure
-- ā
Node.js application
-- ā
Docker containerization
-- ā
Nginx reverse proxy
-- ā
SSL/TLS (Let's Encrypt)
-- ā
Rate limiting
-- ā
Request logging
-- ā
Health checks
-- ā
Auto-restart
-- ā
Automated deployment
-- ā
Complete documentation
-
----
-
-## š File Purpose Summary
-
-### Core Gateway Code
-- **server.js** ā Main application logic (6 ABDM endpoints)
-- **package.json** ā Dependencies (Express, Axios, Winston, etc)
-
-### Containerization
-- **Dockerfile** ā Build gateway image
-- **docker-compose.yml** ā Orchestrate gateway + nginx
-
-### Web Server
-- **nginx.conf** ā Reverse proxy, SSL, rate limiting, headers
-
-### Deployment
-- **deploy.sh** ā Automated setup (10 steps in 15 min)
-- **.env.example** ā Configuration template
-
-### Documentation
-- **README.md** ā Quick reference (5 min read)
-- **DEPLOYMENT_GUIDE.md** ā Detailed steps (30 min read)
-
----
-
-## š”ļø Security Features
-
-- ā
SSL/TLS 1.2+ encryption
-- ā
Bearer token authentication
-- ā
Request ID tracking
-- ā
Rate limiting (100 req/15min)
-- ā
Security headers (HSTS, CSP, etc)
-- ā
CORS policy
-- ā
No credentials in logs
-- ā
Auto certificate renewal
-
----
-
-## š Support Documentation
-
-### Getting Started
-ā `middleware-gateway/README.md` (Quick reference)
-
-### Detailed Setup
-ā `middleware-gateway/DEPLOYMENT_GUIDE.md` (Step-by-step)
-
-### Architecture Decision
-ā `docs/ABDM_GATEWAY_ARCHITECTURE.md` (CSNOtk vs Custom)
-
-### ABDM Integration
-ā `docs/ABDM_SANDBOX_SETUP.md` (Full reference)
-
-### Quick Testing
-ā `docs/ABDM_QUICK_START.md` (7-step validation)
-
----
-
-## ā
Verification Checklist
-
-Before going live:
-
-- [ ] Middleware gateway deployed
-- [ ] Health check responding
-- [ ] ABHA endpoint working
-- [ ] Consent endpoint working
-- [ ] Bundle push working
-- [ ] SNOMED search working
-- [ ] HMS configured to use gateway
-- [ ] OPD ABHA flow tested end-to-end
-- [ ] Logs being collected
-- [ ] SSL certificate valid
-- [ ] Rate limiting active
-- [ ] Auto-renewal configured
-
----
-
-## šÆ Next Steps (Immediate)
-
-### If Testing This Week:
-1. Read: `docs/ABDM_QUICK_START.md`
-2. Follow: 7-step test sequence
-3. Report: Results from tests
-
-### If Deploying Gateway Next Week:
-1. Provision: Ubuntu server
-2. Upload: `middleware-gateway/` folder
-3. Execute: `sudo ./deploy.sh`
-4. Verify: Health check passing
-5. Configure: HMS .env for new gateway
-
----
-
-## š Complete File Tree
-
-```
-HMS_CI4_OLD/
-āāā middleware-gateway/
-ā āāā server.js # Main application
-ā āāā package.json # Dependencies
-ā āāā Dockerfile # Container image
-ā āāā docker-compose.yml # Orchestration
-ā āāā nginx.conf # Reverse proxy
-ā āāā deploy.sh # Auto deployment
-ā āāā setup-ubuntu.sh # Dependencies
-ā āāā .env.example # Config template
-ā āāā README.md # Quick guide
-ā āāā DEPLOYMENT_GUIDE.md # Full guide
-ā āāā logs/ # Application logs
-ā
-āāā docs/
-ā āāā ABDM_QUICK_START.md # 7-step testing
-ā āāā ABDM_SANDBOX_SETUP.md # Full reference
-ā āāā ABDM_SANDBOX_CHECKLIST.md # Tracking
-ā āāā ABDM_GATEWAY_ARCHITECTURE.md # Comparison
-ā āāā ...
-ā
-āāā SESSION_SUMMARY_ABDM_SANDBOX.md
-āāā SESSION_SUMMARY_MIDDLEWARE_GATEWAY.md
-āāā .env # Updated config
-āāā ...
-```
-
----
-
-## š Ready to Deploy?
-
-1. **This Week:** Test with CSNOtk (docs/ABDM_QUICK_START.md)
-2. **Next Week:** Deploy gateway (middleware-gateway/deploy.sh)
-3. **Week 3:** Switch HMS to new gateway
-4. **Week 4+:** Production operations
-
----
-
-**Status:** š¢ COMPLETE & PRODUCTION-READY
-**Total Files Created:** 10 (gateway) + 6 (docs) = 16 files
-**Deployment Time:** 15 minutes (automated)
-**Complexity:** Simple (one script)
-
----
-
-**Questions?** ā Check the relevant guide above.
-**Ready to deploy?** ā Run `sudo ./middleware-gateway/deploy.sh` on Ubuntu server.
-
-š **Everything is ready!**
diff --git a/HMS_MEDICAL_STORE_SESSION.md b/HMS_MEDICAL_STORE_SESSION.md
deleted file mode 100644
index 485b9be..0000000
--- a/HMS_MEDICAL_STORE_SESSION.md
+++ /dev/null
@@ -1,77 +0,0 @@
-# HMS Multi-Building Medical Store & ABDM Pharmacy System
-**Session Name:** `HMS Multi-Store Pharmacy & ABDM Integration`
-**Antigravity Conversation ID:** `3731d0c5-f4df-435e-b54f-f690562e18e3`
-**Last Updated:** September 8, 2026
-
----
-
-## Quick Resume Instructions After Computer Restart
-
-### 1. In Antigravity IDE
-1. Open Antigravity IDE and reopen the workspace `HMS_CI4_OLD`.
-2. In the Chat panel, click the **Chat History / Clock icon** (or open the left conversation drawer).
-3. Select this session: **`HMS Multi-Store Pharmacy & ABDM Integration`** (ID: `3731d0c5-f4df-435e-b54f-f690562e18e3`).
-4. Type your message and continue seamlessly!
-
-*Tip: If you ever open a new chat, you can type `@HMS_MEDICAL_STORE_SESSION.md` or `@conversation` to instantly restore all context.*
-
----
-
-## System Access & Credentials Summary
-
-### Development Server
-- Command: `php spark serve` (in `d:\Workplace\HMS_CI4_OLD`)
-- Server URL: `http://localhost:8080`
-
-### HMS Admin Management
-- **URL:** [http://localhost:8080/setting/admin/medical-store](http://localhost:8080/setting/admin/medical-store)
-- **Features:** Store configuration, DL 20B/21B licenses, GSTIN, Pharmacist details, ABDM HFR/HIP/HPR registries, 60-min OTP generator, terminal device authorization, and Excel / CSV stock import.
-
-### Direct Counter Desks (React PWA)
-- **Counter A (Main Hospital Block A):**
- - Direct Link: [http://localhost:8080/MedicalStore/storeA](http://localhost:8080/MedicalStore/storeA)
- - Store Code: `ST-MAIN`
- - Permanent Security Key: `STORE-SEC-A91B4C72`
- - ABDM HFR ID: `IN0710001234`
- - Pharmacist HPR ID: `91-8822-4411-9901`
-- **Counter B (OPD Block B):**
- - Direct Link: [http://localhost:8080/MedicalStore/storeB](http://localhost:8080/MedicalStore/storeB)
- - Store Code: `ST-OPD-B2`
- - Permanent Security Key: `STORE-SEC-B84F29D1`
- - ABDM HFR ID: `IN0710001234-OPD`
- - Pharmacist HPR ID: `91-8822-4411-9902`
-
----
-
-## Core Technical Reference
-
-1. **Zero Legacy Disturbance:**
- - Legacy pharmacy tables (`invoice_med_master`, `inv_med_item`, `med_*`) and controllers remain 100% untouched.
- - All new tables use the **`mst_*`** prefix (15 tables).
-2. **ABDM Compatibility (M1 & M2):**
- - Patient search by 14-digit ABHA Number or ABHA Address.
- - Care Context generation: `PHARM-{store_code}-{invoice_no}`.
- - NRCES FHIR R4 Bundle profile: `https://nrces.in/ndhm/fhir/r4/StructureDefinition/MedicationDispenseDocument`.
- - Coded with SNOMED-CT clinical terminology.
- - Gateway Bridge queue integration: `abdm_sync_record`.
- - Bundle preview endpoint: `GET /api/v1/medical-store/abdm/bundle/{sale_id}`.
-3. **Multi-Format Invoices:**
- - 80mm Thermal Slip (Fast 1ā5 item OTC/OPD).
- - A5 Invoice (Normal OPD/Walk-in with GST summary).
- - A4 Hospital Tax Invoice (IPD admissions & large bills).
-4. **Excel / CSV Stock Migration:**
- - Supported CSV import with auto-detected columns.
-5. **Double-Entry Accounting & Statutory Drug Register:**
- - Automated ledger postings, Daily Cash Book, GSTR-1 outward reports, and mandatory Schedule H1 drug register.
-6. **Retail Loose Tablet & Unit Dispensing:**
- - Exact per-tablet pricing (`Strip MRP / units_per_pack`), exact stock deduction in individual tablets, and support for Loose Tab, Strip, and Combo sales.
-7. **Split / Mixed Payment Mode & Audit:**
- - Supports partial payments (e.g. ā¹35 Cash + ā¹100 UPI) with 12-digit UTR and bank name capturing for bank reconciliation and audit.
-8. **Keyboard-First Zero-Mouse POS Workflow (Desktop Pharmacy Standard):**
- - High-contrast single-line Quick Keys ribbon.
- - Hotkeys: `F2` (Medicine Search), `F4` (Patient Search), `F7` (Whole Discount), `F8` (Payment Mode), `F9 / Ctrl+Enter` (Complete Sale & Print), `Alt+T` (Loose Tab), `Alt+S` (Strip), `Shift+Delete` (Remove Item).
- - Auto-focus on Medicine Search on page load; `Enter` on quantity immediately commits and jumps focus back to Medicine Lookup for the next scan.
-9. **Compact "Qty & Unit" Cell:**
- - Single-line input group with type selector dropdown (`Tab`, `Strip`, `Str+Tab`) positioned before the quantity box.
- - Automatically defaults to `Tab` (loose units).
-
diff --git a/M1_ABHA_CREATION_AND_VERIFICATION_WITH_APIS_UPDATED_V1_1_f656c93440.xlsx b/M1_ABHA_CREATION_AND_VERIFICATION_WITH_APIS_UPDATED_V1_1_f656c93440.xlsx
deleted file mode 100644
index e72d3b2..0000000
Binary files a/M1_ABHA_CREATION_AND_VERIFICATION_WITH_APIS_UPDATED_V1_1_f656c93440.xlsx and /dev/null differ
diff --git a/M2_BUILDING_HIP_WITH_APIS_UPDATED_22_Aug_871c2f7fcd(1).xlsx b/M2_BUILDING_HIP_WITH_APIS_UPDATED_22_Aug_871c2f7fcd(1).xlsx
deleted file mode 100644
index 5f1a19f..0000000
Binary files a/M2_BUILDING_HIP_WITH_APIS_UPDATED_22_Aug_871c2f7fcd(1).xlsx and /dev/null differ
diff --git a/MPDF_HINDI_FONT_CONFIGURATION.md b/MPDF_HINDI_FONT_CONFIGURATION.md
deleted file mode 100644
index f3f2c63..0000000
--- a/MPDF_HINDI_FONT_CONFIGURATION.md
+++ /dev/null
@@ -1,282 +0,0 @@
-# mPDF Hindi (Devanagari) Font Configuration
-
-## Summary of Changes
-
-### Problem
-- **Old font:** `dejavusans` - Very thin/light weight, limited Hindi glyph coverage
-- **Issue:** Poor rendering of Hindi/Devanagari text in PDFs
-
-### Solution Implemented
-- **New font:** `freeserif` - Medium weight serif font with excellent Hindi/Devanagari support
-- **Result:** Better readability, proper glyph rendering, professional appearance
-
-## Files Updated (2026-06-06)
-
-### 1. Opd.php (3 instances)
-- Line ~2036: Invoice PDF generation
-- Line ~2192: Prescription PDF generation
-- Line ~2308: Document print with custom templates
-
-### 2. Ipd_discharge.php
-- Already using `freeserif` ā
(Lines 5485, 5532, 5581)
-
-### 3. Billing\Ipd.php
-- Already using `freeserif` ā
(Line 982)
-
-### 4. Diagnosis.php (3 instances)
-- Line ~1517: Lab report with print settings
-- Line ~2201: Invoice PDF generation
-- Line ~2456: PDF create with timing logs
-
-### 5. Billing\Charges.php (2 instances)
-- Line ~1140: Landscape invoice (A4-L format)
-- Line ~1151: Portrait invoice (A4 format)
-
-### 6. Storestock.php (1 instance)
-- Line ~782: Indent/stock PDF generation
-
-### 7. AbdmGateway.php (1 instance)
-- Line ~2043: ABDM health record PDF generation
-
-### 8. DoctorDocument.php
-- Already using `freesans` ā
(Line 1298) - Another good Unicode font
-
----
-
-## Available mPDF Fonts for Hindi
-
-### Built-in Fonts (No Additional Setup)
-
-| Font Name | Type | Weight | Hindi Support | Best Use Case |
-|-----------|------|--------|---------------|---------------|
-| **freeserif** ā
| Serif | Medium | Excellent | **Current choice** - Reports, prescriptions |
-| **freesans** | Sans-serif | Medium | Excellent | Modern documents, UI-heavy PDFs |
-| **dejavusans** ā | Sans-serif | Thin | Limited | Avoid - too thin |
-| **dejavusanscondensed** | Sans-serif | Medium | Good | Space-constrained layouts |
-
-### Custom Font Installation (Advanced)
-
-For production-grade Hindi typography, you can add custom fonts:
-
-#### Option 1: Noto Sans Devanagari (Google Fonts)
-```php
-$mpdf = new Mpdf([
- 'fontDir' => [
- __DIR__ . '/../../public/fonts',
- realpath(__DIR__ . '/../../vendor/mpdf/mpdf/ttfonts')
- ],
- 'fontdata' => [
- 'notosansdevanagari' => [
- 'R' => 'NotoSansDevanagari-Regular.ttf',
- 'B' => 'NotoSansDevanagari-Bold.ttf',
- ]
- ],
- 'default_font' => 'notosansdevanagari',
-]);
-```
-
-**Download:** https://fonts.google.com/noto/specimen/Noto+Sans+Devanagari
-
-#### Option 2: Lohit Devanagari (Open Source)
-```php
-$mpdf = new Mpdf([
- 'fontDir' => [__DIR__ . '/../../public/fonts'],
- 'fontdata' => [
- 'lohitdevanagari' => [
- 'R' => 'lohit-devanagari.ttf',
- ]
- ],
- 'default_font' => 'lohitdevanagari',
-]);
-```
-
-**Download:** https://github.com/pravins/lohit
-
-#### Option 3: Windows Mangal Font
-If running on Windows server with Mangal installed:
-```php
-$mpdf = new Mpdf([
- 'fontDir' => ['C:/Windows/Fonts'],
- 'fontdata' => [
- 'mangal' => [
- 'R' => 'mangal.ttf',
- 'B' => 'mangalb.ttf',
- ]
- ],
- 'default_font' => 'mangal',
-]);
-```
-
----
-
-## Testing the Changes
-
-### Quick Test
-1. Generate any PDF (OPD prescription, discharge summary, lab report)
-2. Check Hindi text rendering
-3. Compare with old PDFs - new font should be:
- - **Thicker/bolder** than before
- - **More readable** at all zoom levels
- - **Proper glyph rendering** for all Hindi characters
-
-### Sample Hindi Text for Testing
-```
-ą¤Øą¤®ą¤øą„ą¤¤ą„ą„¤ यह ą¤ą¤ ą¤Ŗą¤°ą„ą¤ą„षण ą¤¹ą„ą„¤
-ą¤®ą¤°ą„ą¤ ą¤ą¤¾ नाम: ą¤°ą¤¾ą¤ ą¤ą„मार ą¤¶ą¤°ą„ą¤®ą¤¾
-निदान: ą¤¬ą„ą¤ą¤¾ą¤° ą¤ą¤° ą¤øą¤æą¤°ą¤¦ą¤°ą„ą¤¦
-```
-
----
-
-## Font Weight Comparison
-
-### Before (dejavusans)
-- Font weight: 300-400 (Light to Normal)
-- Line thickness: Very thin
-- Best for: English text only
-
-### After (freeserif)
-- Font weight: 500-600 (Medium to Semi-bold)
-- Line thickness: Medium
-- Best for: Multilingual documents including Hindi
-
----
-
-## Configuration Options
-
-### Current Standard Configuration
-```php
-$mpdf = new Mpdf([
- 'mode' => 'utf-8',
- 'format' => 'A4',
- 'orientation' => 'P',
- 'margin_left' => 10,
- 'margin_right' => 10,
- 'margin_top' => 10,
- 'margin_bottom' => 10,
- 'default_font' => 'freeserif', // ā
Changed
- 'autoScriptToLang' => true, // Auto-detect language
- 'autoLangToFont' => true, // Auto-switch font for different scripts
- 'tempDir' => WRITEPATH . 'cache',
-]);
-```
-
-### Additional Options for Better Hindi Support
-```php
-$mpdf = new Mpdf([
- 'default_font' => 'freeserif',
- 'autoScriptToLang' => true,
- 'autoLangToFont' => true,
- 'useSubstitutions' => true, // Enable font substitution
- 'CSSselectMedia' => 'print', // Better print styling
-]);
-```
-
----
-
-## Inline Font Override
-
-If you need different fonts for specific sections within the same PDF:
-
-```html
-
-
-
- ą¤®ą¤°ą„ą¤ ą¤ą¤¾ नाम: ą¤°ą¤¾ą¤ ą¤ą„मार ą¤¶ą¤°ą„ą¤®ą¤¾
-
-
- Patient Name: Raj Kumar Sharma
-
-```
-
----
-
-## Troubleshooting
-
-### Issue: Hindi text shows squares/boxes
-**Solution:** Ensure UTF-8 encoding in database and PHP files
-```php
-// In controller before PDF generation
-header('Content-Type: text/html; charset=utf-8');
-```
-
-### Issue: Font looks different in different PDFs
-**Check:** Verify all controllers use same font configuration
-
-### Issue: Need even bolder font
-**Options:**
-1. Use CSS: `ą¤¹ą¤æą¤ą¤¦ą„ पाठ`
-2. Switch to `freesans` (slightly bolder than freeserif)
-3. Install custom bold font (see Custom Font Installation above)
-
----
-
-## Performance Notes
-
-- `freeserif` is built-in to mPDF - **no performance impact**
-- Custom fonts add ~2-3 MB to memory usage per font file
-- Font substitution (`autoLangToFont`) adds negligible overhead (~0.1s per PDF)
-
----
-
-## Rollback Instructions
-
-If you need to revert to old font:
-
-```bash
-# Search and replace in all PHP files
-git diff # Review changes
-git checkout -- app/Controllers/ # Revert all controller changes
-```
-
-Or manually change:
-```php
-'default_font' => 'dejavusans', // Old font
-```
-
----
-
-## Next Steps (Optional)
-
-### 1. For Professional Hindi Typography
-- Download Noto Sans Devanagari from Google Fonts
-- Place TTF files in `public/fonts/` directory
-- Update mPDF configuration in each controller
-
-### 2. For System-wide Font Configuration
-- Create a helper function `getPdfConfig()` in `app/Helpers/pdf_helper.php`
-- Centralize all mPDF configuration
-- Call from all controllers: `$mpdf = new Mpdf(getPdfConfig());`
-
-### 3. For Font Testing
-- Create a test endpoint: `/test-pdf-fonts`
-- Generate sample PDF with all available fonts
-- Compare rendering quality
-
----
-
-## Support
-
-**mPDF Documentation:**
-- Fonts: https://mpdf.github.io/fonts-languages/fonts-in-mpdf-7-x.html
-- Indic Scripts: https://mpdf.github.io/fonts-languages/indic-fonts-v6.html
-
-**Font Resources:**
-- Google Fonts: https://fonts.google.com/?subset=devanagari
-- Font Squirrel: https://www.fontsquirrel.com/fonts/list/language/hindi
-
----
-
-## Changelog
-
-- **2026-06-06:** Changed default font from `dejavusans` to `freeserif` across all controllers for better Hindi rendering and font weight
diff --git a/MPDF_REFERENCE.md b/MPDF_REFERENCE.md
deleted file mode 100644
index 903af8e..0000000
--- a/MPDF_REFERENCE.md
+++ /dev/null
@@ -1,292 +0,0 @@
-# mPDF Reference ā HMS E-Atria Project
-
-Source: https://mpdf.github.io/
-Version used: mpdf/mpdf (composer, see vendor/)
-
----
-
-## 1. Core Pattern ā Single WriteHTML Call (used in this project)
-
-mPDF does NOT require a full HTML document (``, ``, ``, ``).
-Pass a plain HTML fragment to `WriteHTML()`.
-
-### Correct structure for a templated PDF with header/footer:
-
-```
-
-
-
- Hospital Name
-
-
-
-
- Page {PAGENO} of {nbpg}
-
-
-Discharge Summary
-Patient content hereā¦
-```
-
-**Rules:**
-- `@page` block MUST be in a `
-
- header_html (tokens replaced)
- footer_html (tokens replaced)
- rendered template body (template_html with tokens replaced)
-5. $mpdf->WriteHTML($pdfHtml)
-6. Output as binary PDF string ā CI4 response
-```
-
-**Token replacement**: `{{TOKEN_NAME}}` or `{{token_name}}` ā case-insensitive.
-Available tokens: H_Name, H_logo_abs, PATIENT_NAME, UHID, IPD_CODE, ADMIT_DATE,
-DISCHARGE_DATE, FINAL_DIAGNOSIS, SURGERY, DISCHARGE_MEDICATIONS, DISCHARGE_SUMMARY,
-CONTENT (all sections), and many more ā see placeholder list in template editor.
-
-**Debug**: `/Ipd_discharge/show_discharge/{ipdId}/1?tpl={tplId}&html=1`
-Shows the exact HTML string passed to `WriteHTML()`.
-
----
-
-## 11. Common Issues and Fixes
-
-| Problem | Cause | Fix |
-|---|---|---|
-| Header not repeating on every page | Missing `header: html_myHeader` in `@page` | Add `header: html_myHeader;` to `@page` block in CSS textarea |
-| CSS appears as visible text | CSS injected inside body ``, not in `
Discharge Summary
-
-
-
-
-
- | Patient Name |
- SUNITA DEVI |
- |
- |
- UHID / Patient ID |
- P26061331171 |
-
-
- | Guardian |
- Wife of of JOGENDRA KUMAR |
- |
- |
- IPD No. |
- A26061007144 |
-
-
- | Age / Gender |
- 40 Year / Female |
- |
- |
- Admission Date |
- 04-06-2026 03:14 PM |
-
-
- | Address |
- MALDHAN***** |
- |
- |
- Discharge Date |
- 07-06-2026 10:00 AM |
-
-
- | Phone No. |
- 9520497324 |
- |
- |
- TPA |
- Direct |
-
-
- | Department |
- General Surgery |
- |
- |
- |
- |
-
-
-
-
-
-Final Diagnosis :
RIGHT CERVICAL LYMPHADENOPATHY WITH ABSCESS
-
Procedure :
I & D WITH L. N. EXCISION DONE UNDER GA / Date of Procedure : 2026-06-05
Presenting Complaints and Reason for Admission :
PAIN WITH SWELLING RIGHT SIDE NECK 1 MONTH
-
Drug Allergy / ADR
Drug Allergy Status: No Known Drug Allergy
-
General Examination on Admission :
Pulse /min :72/min Respiration /min :16/min BP mmHg :172/92mmHg
-
Course in the hospital :
IVF IV ANTIBIOTICS , ANALGESIC ATT STARTED FROM 6/6/26
Examination on Discharge : Pulse /min :
76/min Respiration /min :
18/min BP mmHg :
132/84mmHg
-
Discharge Medications
| Medicine Name | Dosage | Qty | Day |
|---|
| TAB POP DSR | BID (TWO TIME A DAY) / दिन ą¤®ą„ą¤ ą¤¦ą„ ą¤¬ą¤¾ą¤° | 1 | 5 DAYS |
| TAB CEFUBON CV | BID (TWO TIME A DAY) / दिन ą¤®ą„ą¤ ą¤¦ą„ ą¤¬ą¤¾ą¤° | 1 | 5 DAYS |
| TAB DICLOSIS SP | TID (THREE TIME A DAY) / दिन ą¤®ą„ą¤ ą¤¤ą„ą¤Ø बार | 1 | 5 DAYS |
| TAB FORECOX | BID (TWO TIME A DAY) / दिन ą¤®ą„ą¤ ą¤¦ą„ ą¤¬ą¤¾ą¤° | 1 | 15 DAYS |
| TAB BONCORED | BID (TWO TIME A DAY) / दिन ą¤®ą„ą¤ ą¤¦ą„ ą¤¬ą¤¾ą¤° | 1 | 15 DAYS |
Dietary Advice:- DIET AS ADVICE: DIET AS ADVICE
- Balanced Meals: ą¤Ŗą„ą¤°ą¤¤ą„ą¤Æą„ą¤ ą¤ą„ą¤ą¤Ø ą¤®ą„ą¤ ą¤ą¤¾ą¤°ą„ą¤¬ą„ą¤¹ą¤¾ą¤ą¤”ą„ą¤°ą„ą¤, ą¤Ŗą„ą¤°ą„ą¤ą„न ą¤ą¤° ą¤øą„ą¤µą¤øą„ऄ वसा ą¤ą¤¾ ą¤®ą¤æą¤¶ą„ą¤°ą¤£ शामिल ą¤ą¤°ą„ą¤ą„¤
- Small, Frequent Meals: ą¤Ŗą¤¾ą¤ą¤Ø ą¤¤ą¤ą¤¤ą„र पर ą¤
ą¤§ą¤æą¤ ą¤¬ą„ą¤ ą¤øą„ ą¤¬ą¤ą¤Øą„ ą¤ą„ ą¤²ą¤æą¤ ą¤¤ą„ą¤Ø बार ą¤
ą¤§ą¤æą¤ ą¤ą„ą¤ą¤Ø ą¤ą¤°ą¤Øą„ ą¤ą„ ą¤¬ą¤ą¤¾ą¤Æ दिन ą¤®ą„ą¤ 5-6 बार ą¤ą„ą¤ą„ ą¤®ą¤¾ą¤¤ą„ą¤°ą¤¾ ą¤®ą„ą¤ ą¤ą„ą¤ą¤Ø ą¤ą¤°ą„ą¤ą„¤
- Avoid Processed Foods: ą¤®ą„ą¤ ą„, ą¤Øą¤®ą¤ą„न ą¤ą¤° ą¤¤ą¤²ą„ ą¤¹ą„ą¤ ą¤ą¤¾ą¤¦ą„य ą¤Ŗą¤¦ą¤¾ą¤°ą„ą¤„ą„ą¤ ą¤ą¤¾ ą¤øą„ą¤µą¤Ø ą¤øą„ą¤®ą¤æą¤¤ ą¤ą¤°ą„ą¤ą„¤ ą¤”ą¤æą¤¬ą„ą¤¬ą¤¾ą¤¬ą¤ą¤¦ ą¤øą„ą¤Øą„ą¤ą„स ą¤ą¤° ą¤ą¤¼ą„यादा ą¤Ŗą„ą¤°ą¤æą¤ą¤¼ą¤°ą„ą¤µą„ą¤ą¤æą¤µ ą¤µą¤¾ą¤²ą„ ą¤Ŗą„ą¤Æ ą¤Ŗą¤¦ą¤¾ą¤°ą„ą¤„ą„ą¤ ą¤øą„ ą¤¬ą¤ą„ą¤ą„¤
PT WAS K/C/O RT CERVICAL LYMPHADENOPATHY WITH ABSCESS NOW ADMITTED FOR OPERATION . ALL NECESSARY INVESTIGATION WERE CARRIED OUT. PT WAS OPERATED I & D WITH L. N . EXCISION DONE UNDER GA AND MANAGED WITH IVF IV ANTIBIOTICS ANALGESIC AND OTHER SUPPORTIVE MEASURES.
-
-
NOW PT IS BEING DISCHARGED IN A STABLE CONDITION WITH MEDICATION .
-| | | |
| _________________________ | _________________________ | _________________________ |
Discharge Advice/Instructions/Summary
Discharge Summary
-
Signature of Consultant |
\ No newline at end of file
diff --git a/raw_bridge_status_check.php b/raw_bridge_status_check.php
deleted file mode 100644
index 08b4868..0000000
--- a/raw_bridge_status_check.php
+++ /dev/null
@@ -1,44 +0,0 @@
-query("SELECT s_name, s_value FROM hospital_setting WHERE s_name IN ('EATRIA_BRIDGE_TOKEN','ABDM_HFR_ID')");
-$settings = [];
-while ($r = $rows->fetch_assoc()) {
- $settings[$r['s_name']] = $r['s_value'];
-}
-$db->close();
-
-$token = trim((string) ($settings['EATRIA_BRIDGE_TOKEN'] ?? ''));
-$hfrId = trim((string) ($settings['ABDM_HFR_ID'] ?? ''));
-
-$requestId = $argv[1] ?? 'REQ-20260728030125-b03b873b';
-
-$url = 'https://abdm-bridge.e-atria.in/api/v1/hiu/consent/status?' . http_build_query([
- 'request_id' => $requestId,
- 'hfr_id' => $hfrId,
-]);
-
-$ch = curl_init();
-curl_setopt_array($ch, [
- CURLOPT_URL => $url,
- CURLOPT_RETURNTRANSFER => true,
- CURLOPT_HEADER => true,
- CURLOPT_TIMEOUT => 30,
- CURLOPT_HTTPHEADER => [
- 'Accept: application/json',
- 'Authorization: Bearer ' . $token,
- ],
-]);
-$raw = curl_exec($ch);
-$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
-$headerSize = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
-$err = curl_error($ch);
-curl_close($ch);
-
-echo "URL: {$url}\n";
-echo "HTTP Code: {$httpCode}\n";
-echo "Curl error: {$err}\n";
-if ($raw !== false) {
- echo "--- Headers ---\n" . substr($raw, 0, $headerSize) . "\n";
- echo "--- Body (raw bytes length=" . strlen(substr($raw, $headerSize)) . ") ---\n";
- echo substr($raw, $headerSize) . "\n";
-}
diff --git a/run_bed_fix.php b/run_bed_fix.php
deleted file mode 100644
index f100763..0000000
--- a/run_bed_fix.php
+++ /dev/null
@@ -1,189 +0,0 @@
-connect_error) {
- die("Connection failed: " . $db->connect_error);
-}
-
-echo "==============================================\n";
-echo "Bed Management Fix Script\n";
-echo "==============================================\n\n";
-
-// Step 0: Check current state BEFORE fix
-echo "BEFORE FIX - Current State:\n";
-echo "----------------------------\n";
-
-$query = "
- SELECT
- COUNT(CASE WHEN bed_status = 'available' THEN 1 END) as available_beds,
- COUNT(CASE WHEN bed_status = 'occupied' THEN 1 END) as occupied_beds,
- COUNT(*) as total_beds
- FROM bed_master
- WHERE status = 'active'
-";
-$result = $db->query($query);
-$row = $result->fetch_object();
-echo "Total Beds: {$row->total_beds}\n";
-echo "Available: {$row->available_beds}\n";
-echo "Occupied: {$row->occupied_beds}\n";
-
-$query = "SELECT COUNT(*) as current_admissions FROM ipd_master WHERE ipd_status = 0";
-$result = $db->query($query);
-$row = $result->fetch_object();
-echo "Current Admissions: {$row->current_admissions}\n";
-
-$query = "
- SELECT COUNT(*) as problem_beds
- FROM bed_master bm
- INNER JOIN ipd_master i ON i.id = bm.current_ipd_id
- WHERE i.ipd_status = 1
- AND bm.current_ipd_id IS NOT NULL
-";
-$result = $db->query($query);
-$row = $result->fetch_object();
-echo "Beds stuck with discharged patients: {$row->problem_beds}\n\n";
-
-// Step 1: Release beds for discharged patients (MAIN FIX)
-echo "Step 1: Releasing beds for discharged patients...\n";
-$sql = "
- UPDATE bed_master bm
- INNER JOIN ipd_master i ON i.id = bm.current_ipd_id
- SET
- bm.bed_status = 'available',
- bm.current_ipd_id = NULL
- WHERE i.ipd_status = 1
- AND bm.current_ipd_id IS NOT NULL
-";
-$db->query($sql);
-$affected = $db->affected_rows;
-echo "ā Released {$affected} beds\n\n";
-
-// Step 1b: Fix phantom occupied beds (occupied status but no patient assigned)
-echo "Step 1b: Fixing phantom occupied beds (occupied but no current_ipd_id)...\n";
-$sql = "
- UPDATE bed_master
- SET bed_status = 'available'
- WHERE bed_status = 'occupied'
- AND current_ipd_id IS NULL
-";
-$db->query($sql);
-$affected = $db->affected_rows;
-echo "ā Fixed {$affected} phantom occupied beds\n\n";
-
-// Step 1c: Sync bed_assignment_history to bed_master.current_ipd_id
-echo "Step 1c: Syncing bed assignments from history to bed_master...\n";
-$sql = "
- UPDATE bed_master bm
- INNER JOIN bed_assignment_history bah ON bah.bed_id = bm.id
- INNER JOIN ipd_master i ON i.id = bah.ipd_id
- SET
- bm.current_ipd_id = bah.ipd_id,
- bm.bed_status = 'occupied'
- WHERE i.ipd_status = 0
- AND bah.released_date IS NULL
- AND bm.current_ipd_id IS NULL
-";
-$db->query($sql);
-$affected = $db->affected_rows;
-echo "ā Synced {$affected} bed assignments\n\n";
-
-// Step 2: Update bed_assignment_history (if table exists)
-$tableCheck = $db->query("SHOW TABLES LIKE 'bed_assignment_history'");
-if ($tableCheck->num_rows > 0) {
- echo "Step 2: Updating bed_assignment_history...\n";
- $sql = "
- UPDATE bed_assignment_history bah
- INNER JOIN ipd_master i ON i.id = bah.ipd_id
- SET
- bah.released_date = COALESCE(i.discharge_date, NOW()),
- bah.release_reason = 'Patient Discharged (Data Fix)'
- WHERE i.ipd_status = 1
- AND bah.released_date IS NULL
- ";
- $db->query($sql);
- $affected = $db->affected_rows;
- echo "ā Updated {$affected} history records\n\n";
-} else {
- echo "Step 2: bed_assignment_history table not found, skipping...\n\n";
-}
-
-// Step 3: Verify the fix
-echo "AFTER FIX - Verification:\n";
-echo "-------------------------\n";
-
-$query = "
- SELECT
- COUNT(CASE WHEN bed_status = 'available' THEN 1 END) as available_beds,
- COUNT(CASE WHEN bed_status = 'occupied' THEN 1 END) as occupied_beds,
- COUNT(*) as total_beds
- FROM bed_master
- WHERE status = 'active'
-";
-$result = $db->query($query);
-$row = $result->fetch_object();
-echo "Total Beds: {$row->total_beds}\n";
-echo "Available: {$row->available_beds}\n";
-echo "Occupied: {$row->occupied_beds}\n";
-
-$query = "SELECT COUNT(*) as current_admissions FROM ipd_master WHERE ipd_status = 0";
-$result = $db->query($query);
-$row = $result->fetch_object();
-echo "Current Admissions: {$row->current_admissions}\n";
-
-$query = "
- SELECT COUNT(*) as problem_beds
- FROM bed_master bm
- INNER JOIN ipd_master i ON i.id = bm.current_ipd_id
- WHERE i.ipd_status = 1
- AND bm.current_ipd_id IS NOT NULL
-";
-$result = $db->query($query);
-$row = $result->fetch_object();
-echo "Beds stuck with discharged patients: {$row->problem_beds}\n\n";
-
-// Check for any mismatches
-$query = "
- SELECT
- bm.id,
- bm.bed_number,
- bm.bed_code,
- bm.bed_status,
- bm.current_ipd_id
- FROM bed_master bm
- LEFT JOIN ward_master w ON w.id = bm.ward_id
- WHERE bm.bed_status = 'occupied'
- AND bm.current_ipd_id IS NULL
- LIMIT 5
-";
-$result = $db->query($query);
-if ($result->num_rows > 0) {
- echo "ā Warning: Found beds marked 'occupied' but no current_ipd_id:\n";
- while ($bed = $result->fetch_assoc()) {
- echo " - Bed #{$bed['bed_number']} (ID: {$bed['id']})\n";
- }
- echo "\n";
-} else {
- echo "ā No status mismatches found\n\n";
-}
-
-$db->close();
-
-echo "==============================================\n";
-echo "Fix completed successfully!\n";
-echo "==============================================\n";
-echo "\nNext steps:\n";
-echo "1. Check bed status at: /setting/admin/bed-status\n";
-echo "2. Test discharge a patient and verify bed is released\n";
-echo "3. Test admitting a patient and verify bed is assigned\n";
diff --git a/setup_git_config.sh b/setup_git_config.sh
deleted file mode 100644
index 3b9901e..0000000
--- a/setup_git_config.sh
+++ /dev/null
@@ -1,86 +0,0 @@
-#!/bin/bash
-# Setup script to configure git for www-data user
-# For PUBLIC repositories - no authentication required
-# Run this on your live server as root to fix git pull issues
-
-set -e
-
-echo "========================================="
-echo "HMS Git Configuration (Public Repo)"
-echo "========================================="
-echo ""
-
-# Check if running as root
-if [ "$EUID" -ne 0 ]; then
- echo "ERROR: This script must be run as root"
- echo "Usage: sudo bash setup_git_config.sh"
- exit 1
-fi
-
-# Determine web server user
-WEB_USER="www-data"
-if ! id "$WEB_USER" &>/dev/null; then
- echo "ERROR: User '$WEB_USER' not found. Please adjust WEB_USER variable."
- exit 1
-fi
-
-# HMS installation directory
-HMS_DIR="/var/www/html/hms_etria"
-if [ ! -d "$HMS_DIR" ]; then
- echo "ERROR: HMS directory not found at $HMS_DIR"
- echo "Please update HMS_DIR in this script"
- exit 1
-fi
-
-echo "Configuration Details:"
-echo " Web user: $WEB_USER"
-echo " HMS dir: $HMS_DIR"
-echo " Repo type: PUBLIC (no authentication needed)"
-echo ""
-
-# 1. Fix directory permissions
-echo "[1/4] Fixing directory permissions..."
-chown -R "$WEB_USER:$WEB_USER" "$HMS_DIR"
-chmod -R 755 "$HMS_DIR"
-chmod -R 755 "$HMS_DIR/.git"
-echo " Directory ownership set to $WEB_USER"
-
-# 2. Set local git config (repository-specific, avoids /var/www/.gitconfig permission issues)
-echo "[2/4] Setting git user name (local repository config)..."
-cd "$HMS_DIR"
-sudo -u "$WEB_USER" git config user.name "www-data"
-
-# 3. Set git email (local repository config)
-echo "[3/4] Setting git email (local repository config)..."
-cd "$HMS_DIR"
-sudo -u "$WEB_USER" git config user.email "deploy@localhost"
-
-# 4. Test git status
-echo "[4/4] Testing git status..."
-cd "$HMS_DIR"
-if sudo -u "$WEB_USER" git status >/dev/null 2>&1; then
- echo "ā Git status check PASSED"
-else
- echo "ā Git status check FAILED"
- echo " Output:"
- sudo -u "$WEB_USER" git status
- exit 1
-fi
-
-echo ""
-echo "========================================="
-echo "ā Git setup completed successfully!"
-echo "========================================="
-echo ""
-echo "Configuration stored in: $HMS_DIR/.git/config"
-echo "Remote: $(cd $HMS_DIR && sudo -u $WEB_USER git config --get remote.origin.url)"
-echo "Branch: main"
-echo ""
-echo "Next steps:"
-echo " 1. Go to System Operations panel"
-echo " 2. Click 'Update HMS' button"
-echo " 3. Confirm the git pull action"
-echo ""
-
-
-
diff --git a/test_panel_tab.php b/test_panel_tab.php
deleted file mode 100644
index 625f5b1..0000000
--- a/test_panel_tab.php
+++ /dev/null
@@ -1,69 +0,0 @@
-query($query);
-if ($result && $result->num_rows > 0) {
- echo "ā IPD data found\n\n";
-} else {
- echo "ā IPD not found\n";
- exit;
-}
-
-// Step 2: Get bed assignments
-echo "Step 2: Get bed assignments...\n";
-$query = "
- SELECT
- bed_assignment_history.*,
- bed_master.bed_code,
- bed_master.bed_number,
- ward_master.ward_name
- FROM bed_assignment_history
- LEFT JOIN bed_master ON bed_master.id = bed_assignment_history.bed_id
- LEFT JOIN ward_master ON ward_master.id = bed_assignment_history.ward_id
- WHERE bed_assignment_history.ipd_id = {$ipdId}
- ORDER BY bed_assignment_history.id DESC
-";
-$result = $db->query($query);
-echo "ā Query executed\n";
-echo "ā Rows found: {$result->num_rows}\n\n";
-
-if ($result->num_rows > 0) {
- echo "Step 3: Render view with data...\n";
- $bed_assignments = [];
- while ($row = $result->fetch_object()) {
- $bed_assignments[] = $row;
- }
-
- echo "ā Data prepared\n";
- echo "ā Array count: " . count($bed_assignments) . "\n\n";
-
- echo "Step 4: Check if view can access data...\n";
- echo "Sample data from first record:\n";
- if (!empty($bed_assignments)) {
- $first = $bed_assignments[0];
- echo " bed_code: " . ($first->bed_code ?? 'NULL') . "\n";
- echo " bed_number: " . ($first->bed_number ?? 'NULL') . "\n";
- echo " ward_name: " . ($first->ward_name ?? 'NULL') . "\n";
- echo " assigned_date: " . ($first->assigned_date ?? 'NULL') . "\n";
- echo " assignment_type: " . ($first->assignment_type ?? 'NULL') . "\n";
- }
-
- echo "\nā View should display this data\n";
-} else {
- echo "ā No bed assignments found - view will show empty message\n";
-}
-
-$db->close();
diff --git a/verify_no_dupes.php b/verify_no_dupes.php
deleted file mode 100644
index 23426dd..0000000
--- a/verify_no_dupes.php
+++ /dev/null
@@ -1,6 +0,0 @@
-query("SELECT COUNT(*) c FROM abdm_hiu_documents WHERE abha_address = '91510165305101@sbx'")->fetch_assoc());
-$res = $db->query("SELECT id, request_id, care_context_reference, updated_at FROM abdm_hiu_documents WHERE abha_address = '91510165305101@sbx'");
-while ($row = $res->fetch_assoc()) { print_r($row); }
-$db->close();
diff --git a/wipe_hiu_data_for_abha.php b/wipe_hiu_data_for_abha.php
deleted file mode 100644
index d666327..0000000
--- a/wipe_hiu_data_for_abha.php
+++ /dev/null
@@ -1,100 +0,0 @@
- (dry run)
- * php83 wipe_hiu_data_for_abha.php
--confirm (actually delete)
- */
-
-$envPath = __DIR__ . '/.env';
-if (! is_file($envPath)) {
- fwrite(STDERR, "Could not find .env at {$envPath}\n");
- exit(1);
-}
-
-$lines = file($envPath, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
-$env = [];
-foreach ($lines as $line) {
- $line = trim($line);
- if ($line === '' || $line[0] === '#' || strpos($line, '=') === false) {
- continue;
- }
- [$k, $v] = explode('=', $line, 2);
- $env[trim($k)] = trim($v, " \t\n\r\0\x0B\"'");
-}
-
-$host = $env['database.default.hostname'] ?? 'localhost';
-$db = $env['database.default.database'] ?? '';
-$user = $env['database.default.username'] ?? '';
-$pass = $env['database.default.password'] ?? '';
-$port = (int) ($env['database.default.port'] ?? 3306);
-
-$mysqli = @new mysqli($host, $user, $pass, $db, $port ?: 3306);
-if ($mysqli->connect_errno) {
- fwrite(STDERR, "DB connect failed: " . $mysqli->connect_error . "\n");
- exit(1);
-}
-
-echo "Connected to DB '{$db}' on {$host}.\n";
-
-$abha = $argv[1] ?? '';
-$confirm = in_array('--confirm', $argv, true);
-
-if ($abha === '') {
- fwrite(STDERR, "Usage: php83 wipe_hiu_data_for_abha.php [--confirm]\n");
- exit(1);
-}
-
-$tables = [
- 'abdm_hiu_documents' => 'abha_address',
- 'abdm_hiu_workflows' => 'abha_address',
- 'abdm_hiu_consent_artifacts' => 'abha_address',
-];
-
-$counts = [];
-foreach ($tables as $table => $column) {
- $checkTable = $mysqli->query("SHOW TABLES LIKE '{$table}'");
- if (! $checkTable || $checkTable->num_rows === 0) {
- echo "\n(table '{$table}' does not exist, skipping)\n";
- continue;
- }
-
- $stmt = $mysqli->prepare("SELECT COUNT(*) AS c FROM {$table} WHERE {$column} = ?");
- $stmt->bind_param('s', $abha);
- $stmt->execute();
- $row = $stmt->get_result()->fetch_assoc();
- $counts[$table] = (int) ($row['c'] ?? 0);
-
- echo "\n=== {$table} rows matching {$column}='{$abha}' ===\n";
- echo "Count: {$counts[$table]}\n";
-}
-
-$total = array_sum($counts);
-if ($total === 0) {
- echo "\n(no rows found in any table ā nothing to delete)\n";
- exit(0);
-}
-
-if (! $confirm) {
- echo "\nDry run only. Total rows across all tables: {$total}.\n";
- echo "Re-run with --confirm to actually delete these rows.\n";
- exit(0);
-}
-
-foreach ($tables as $table => $column) {
- if (! isset($counts[$table]) || $counts[$table] === 0) {
- continue;
- }
- $del = $mysqli->prepare("DELETE FROM {$table} WHERE {$column} = ?");
- $del->bind_param('s', $abha);
- $del->execute();
- echo "\nDeleted {$mysqli->affected_rows} row(s) from {$table} for {$column}='{$abha}'.\n";
-}
-
-echo "\nDone. All M3 HIU data wiped for abha_address='{$abha}'. Ready for a fresh consent request test.\n";