Commit Graph

558 Commits

Author SHA1 Message Date
0c0dbf78b4 EAtria pushRecord: fallback to /v1/bridge dispatcher on auth-scoped 403 2026-06-26 17:16:36 +05:30
bf3345b2ce EAtria auth: include bridge hospital id in header and records.push body 2026-06-26 16:59:40 +05:30
c632f28482 EAtria connector: retry alternate DB token keys on 401/403 and log token source 2026-06-26 16:55:07 +05:30
ab564c77f8 ABDM OPD share: fix null-consent crash in care-context fallback 2026-06-26 16:46:10 +05:30
5d1d7ea552 ABDM OPD share: allow care-context push without active consent and log to bridge log 2026-06-26 16:43:19 +05:30
e7e5cf88e7 ABDM submit: release session lock before internal handoff and extend client timeout 2026-06-26 16:39:53 +05:30
a23d1f215a ABDM submit: prevent indefinite loading with fetch timeout and safer response handling 2026-06-26 16:35:36 +05:30
428dcd2aa9 ABDM: treat transient handoff timeout as queued when recent OPD record exists 2026-06-26 16:30:52 +05:30
fbaa985857 feat(abdm): implement M2 gateway contract endpoints and live test tooling 2026-06-24 04:50:03 +05:30
985d476bc1 ABDM: finalize ABHA verify persistence, M2 routes/workflows, and location masters seeding 2026-06-24 03:15:22 +05:30
75e71c2343 Fix new patient create 500 from undefined ABHA lock flag 2026-06-22 08:30:36 +05:30
386055a0cd fix(discharge): unify history panel behavior and form nav sync 2026-06-22 02:40:50 +05:30
a602bf555d feat(discharge): unify history sections into single risk profile panel 2026-06-22 02:07:49 +05:30
96c030b72d chore: checkpoint before discharge history panel refactor 2026-06-22 02:05:24 +05:30
8fc60e893e Fix pharmacy stock sync for invoice, purchase edit, challan and return flows 2026-06-20 11:25:40 +05:30
fe2fabc5b8 Make OPD placeholder headings consistently bold 2026-06-19 13:20:29 +05:30
b19d1d40c2 Fix OPD PDF overflow and compact consult placeholders 2026-06-19 13:12:34 +05:30
1bac1f6e04 feat: update storestock flow and ABDM bridge handling 2026-06-18 17:38:20 +05:30
1790be3fca ABDM M2: records push, discover/fetch, non-ABHA local storage, consent table compat
- EAtriaBridgeConnector: fix OPConsultRecord hi_type normalization (was wrongly
  mapping to PrescriptionRecord); allow push with either abha_address or abha_id;
  add careContextId alias for care_context_reference in pushRecord payload

- AbdmGateway: migrate OPD share to records/push semantics with unique
  care_context_reference, ABHA id/address resolution, bridge_record_id capture,
  and 409 DUPLICATE_RECORD non-fatal handling

- AbdmGateway: add non-ABHA local-only storage path for OPD/IPD/Lab share
  (push_status=local_only, no bridge call, audit logged)

- AbdmGateway: add POST /records/discover endpoint with ABHA-first + fallback
  matching by mobile, hospital ID, patient UHID+birthYear (PHR-compatible)

- AbdmGateway: add GET /records/fetch/{careContextId} endpoint returning
  decrypted FHIR payload from health_records

- AbdmGateway: dual-write consent artefacts to abdm_consent_records AND
  consents table when both present; getActiveConsentRecord falls back to
  consents table when abdm_consent_records is absent

- AbdmAuditService: write to audit_logs (generic schema) when present,
  fallback to abdm_audit_logs; field-aware insert supports both schemas

- Routes: register /records/discover and /records/fetch/(:any)

- Webhook signature validator: check EKA_WEBHOOK_SECRET then HMS_WEBHOOK_SECRET
  for gateway compatibility
2026-06-17 20:07:39 +05:30
5a1a87ebe1 Adjust IPD bill print signature spacing 2026-06-14 14:38:59 +05:30
d4b4c95cbc Fix IPD discharge and bill print issues 2026-06-14 14:34:33 +05:30
4e8c5c691f Update OPD history profile view 2026-06-11 19:38:55 +05:30
cad5a477bf Sync OPD history flow and discharge UI refinements 2026-06-11 19:30:02 +05:30
eefda96dca Preserve investigation profile test master order 2026-06-11 19:22:09 +05:30
0c2e1385cb Refine IPD discharge summary layout 2026-06-11 11:53:39 +05:30
191c25de68 Refine discharge placeholders and status heading 2026-06-11 10:24:04 +05:30
c0f7e213e6 Discharge templates: add status heading token and refine placeholders 2026-06-11 09:57:04 +05:30
f2a7546a9d Simplify discharge summary placeholders - eliminate confusion
Changes:
- Rename main placeholder: DISCHARGE_SUMMARY → CLINICAL_SUMMARY (clearer name)
- Keep DISCHARGE_SUMMARY as legacy alias for backward compatibility
- Rename: DISCHARGE_ADVICE → FOLLOW_UP_INSTRUCTIONS (more descriptive)
- Remove: INSTRUCTION_REMARK (duplicate removed)
- Group placeholders by category in code with comments
- Create comprehensive reference guide: DISCHARGE_PLACEHOLDERS_REFERENCE.md

Benefits:
- Clear distinction between clinical summary and discharge instructions
- Organized placeholder groups (clinical, instructions, other)
- Easy migration guide for existing templates
- Complete documentation with examples
2026-06-11 08:18:43 +05:30
586d3bde46 Add HTML debug mode to discharge summary for troubleshooting
- Add ?html=1 parameter to show_discharge to output HTML directly
- Shows debug info: IPD ID, template name, content lengths
- Bypass PDF generation to see rendered HTML content
- Helps diagnose PHP/rendering errors before PDF conversion

Usage: /Ipd_discharge/show_discharge/1007168/1?html=1&tpl=3
2026-06-11 08:08:15 +05:30
35893e1a33 Fix discharge summary section extraction by keeping standard heading
- Restore "Discharge Summary" heading for template extraction to work
- Show status as strong text below heading (not as replacement)
- Include discharge summary HTML editor content (instruction_remark)
- Section extraction requires consistent heading names

Previous fix broke section extraction by changing heading text
2026-06-11 07:59:56 +05:30
c091b60168 Add discharge summary free-text content to PDF output
- Include ipd_discharge_instructions.comp_remark in discharge summary section
- Previously only showed status header, missing actual discharge narrative
- Reuse existing instructionRowForMeta query to avoid duplicate DB calls
- Apply renderRichText() to properly display HTML editor content

Fixes missing discharge summary text for IPD 1007168 and similar cases
2026-06-11 07:47:35 +05:30
3dc9fe1df6 Fix discharge summary not appearing in PDF after HTML editor conversion
- Enhanced normalizeRichText() to detect and preserve HTML from HTML editors
- Added renderRichText() helper to safely render HTML vs plain text content
- Updated 4 rendering locations (narrative sections, systemic exams, investigations)
- Backward compatible: plain textarea fields still work correctly
- Fixes issue where strip_tags() removed all HTML formatting from editor content

Resolves blank discharge summaries in PDF when content saved from TinyMCE/HTML editors
2026-06-11 07:38:40 +05:30
203481b8df Fix all patient_master_exten references in pharmacy module
- Replace all patient_master_exten checks with patient_master across Medical.php
- Fixes blank patient info in multiple pharmacy pages:
  * /Medical/ipd_print/{id}/credit - IPD print bills (UHID, Patient name)
  * Counter sale forms and invoice editing
  * Patient search functionality
  * IPD group print consolidated views
  * Auto UHID lookup endpoints
- patient_master_exten table exists but lacks core patient fields (p_fname, p_rname, p_code)
- Ensures consistent patient data display throughout pharmacy module
- Matches earlier fixes for billing and invoice list pages
2026-06-10 13:53:15 +05:30
1c87edcf03 Fix blank patient info in pharmacy invoice list
- Use patient_master directly in list_med_inv and list_med_orginv methods
- patient_master_exten exists but lacks p_fname, p_rname, p_code fields
- Fixes blank Name/Age/Gender/P Code in /Medical/list_med_inv page
- Consistent with earlier fix for list_org_ipd
2026-06-10 13:37:45 +05:30
0428c4d656 Fix blank patient names in pharmacy IPD list
- Use patient_master table directly instead of patient_master_exten
- patient_master_exten may exist but lacks p_fname, p_rname fields
- Matches pattern used in IpdBillingModel::baseIpdListQuery()
- Fixes blank patient names/codes in /Medical/list_org_ipd page
2026-06-10 13:24:35 +05:30
a4e6f69728 Fix IpdModel method call in toggleStatus endpoint
- Change getById() to find() - IpdBillingModel doesn't have getById method
- Use ipdEditModel (IpdModel extends Model) which has standard find() method
- Fixes 500 error: Call to undefined method IpdBillingModel::getById
2026-06-10 13:14:27 +05:30
54d120e2bb Fix IPD status toggle route registration
- Rename toggleIpdStatus() to updateDischargeToggleStatus() to match naming pattern
- Add route mapping for /billing/ipd/panel/{id}/discharge/toggle-status endpoint
- Fixes 404 error when clicking toggle button in discharge panel
- Follows same pattern as other discharge operations (discount, charge, update)
2026-06-10 13:10:03 +05:30
c437652b79 Add IPD status management with strict ipd_status check
- Update isIpdDischargedInvoice to check ONLY ipd_status field (remove fallback checks)
- Add IPD status toggle UI in discharge panel (Active/Discharged control)
- Create toggleIpdStatus controller method with permission check
- Add billing.ipd.status.manage permission for controlling bill edit lock
- Allows editing bills when needed by toggling status independently of discharge_date
- Auto-releases bed when setting status to discharged
2026-06-10 12:55:47 +05:30
15458715a8 Fix bill print summary rows colspan - align amounts to Amount column
- Change colspan from 3 to 4 (normal mode) and 4 to 5 (discount mode)
- Ensures Gross Total, Net Amount, Payment Recd., Balance amounts appear in Amount column
- Fixes blank cells in Rate column by properly spanning Description through Rate columns
2026-06-10 12:00:08 +05:30
342f54e509 Fix bed number not showing in bill print - add bed_assignment_history fallback
- Use COALESCE to check both bed_master.current_ipd_id and bed_assignment_history
- Join with bed_assignment_history where released_date IS NULL for active beds
- Handles cases where bed is assigned in history but current_ipd_id not set
- Fixes bill print showing blank Bed No when assignment exists in history
2026-06-10 11:47:18 +05:30
7cf13bffd1 Fix IPD bill print showing blank bed number and doctor name
- Add bed_master join to fetch current bed assignment via current_ipd_id
- Add ipd_master_doc_list and doctor_master joins to fetch assigned doctors
- Use GROUP_CONCAT to handle multiple doctors in single query
- Fixes bill print displaying empty Bed No and Doctor Name fields
2026-06-10 11:41:44 +05:30
bb95756700 Fix IPD Discharge medicine section: dose labels, Rx-Groups, and substitutes
- Fix dose columns showing IDs instead of labels (OD, BID, TDS, etc.)
- Add Rx-Group functionality with modal, search, and bulk add
- Add substitute medicine suggestions with one-click use
- Improve medicine autocomplete with debouncing and scope=all
- Load dose master maps in controller and pass to view
- Match OPD Consult UI/UX patterns for consistency
2026-06-09 17:23:34 +05:30
d722714ef1 feat: Complete bed management system with transfer and time tracking
- Implemented automatic bed release on patient discharge
- Added bed transfer functionality in nursing workspace
- Added date/time tracking for bed assignments with duration calculation
- Fixed bed_master.current_ipd_id as source of truth for occupancy
- Created data fix scripts for existing records
- Added bed assignment history with duration display (hours/minutes)
- Fixed display issues in bed assignment tab
- Added route for bed transfer endpoint
- Supports custom assignment datetime for backdated entries
- Automatically marks previous bed as released on transfer
2026-06-09 08:39:48 +05:30
8e293c4ffb Fix Chrome PDF corruption by clearing output buffers and adding X-Content-Type-Options header
- Clear all output buffers before sending PDF binary to prevent corruption
- Add X-Content-Type-Options: nosniff to force Chrome to treat response as PDF
- Apply fixes to main, fallback, and ultimate fallback PDF response paths
- Fixes issue where Chrome fails to open PDF while Firefox/Edge work
- Critical for PDFs with Hindi/UTF-8 content where output buffering can corrupt binary data
2026-06-08 23:30:12 +05:30
46315ac5ed Fix Chrome PDF display issue by adding Content-Length, proper filename encoding, Cache-Control, and Accept-Ranges headers 2026-06-08 23:20:06 +05:30
52f5041c5c Add dynamic margin system for letterhead printing - 5cm top, 2cm bottom when header hidden 2026-06-08 17:21:54 +05:30
0568851783 Add Print Header checkbox for IPD bill printing - allows printing on letterhead 2026-06-08 17:18:02 +05:30
f55d300924 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
2026-06-07 20:12:58 +05:30
5f052945d2 Fix: Add Discharge Summary label and separate placeholders for instruction fields
ISSUE 1: Discharge Summary showing in PDF but without label
ISSUE 2: Need separate placeholders for Other Advice and Discharge Summary

FIX 1: Added label to instruction_remark in PDF
- Added Discharge Summary: label before instruction_remark content

FIX 2: Added new placeholders for template flexibility
- OTHER_ADVICE - Shows only Other Advice field
- INSTRUCTION_REMARK or DISCHARGE_ADVICE - Shows only Discharge Summary field
- DISCHARGE_INSTRUCTIONS - Shows full section with all advice

Now templates can control what appears where using specific placeholders.

CHANGES:
1. Line 2248 - Added Discharge Summary: label
2. Line 574-575 - Extract new tokens from content
3. Line 579-581 - Add tokens to vars array
4. Line 520-522 - Add markers to extraction list

TESTING: Go to discharge PDF and verify labels show correctly
2026-06-07 20:07:34 +05:30
2b95bb8b7c Fix: Data mixing between instruction_other and instruction_remark fields
ISSUE: instruction_remark (Discharge Summary) data appearing in instruction_other (Other Advice) field after save

ROOT CAUSE: Legacy table sync was writing wrong variable
- Save handler at line 5478 was writing \ to legacy food_text
- Should have been writing \
- When legacy fallback loads (if food_ids empty), wrong data copied to instruction_other

FIX: Changed line 5478 in Ipd_discharge.php
- Before: \['food_text'] = \;
- After:  \['food_text'] = \;

FILES MODIFIED:
1. app/Controllers/Ipd_discharge.php - Fixed legacy save handler
2. app/Views/billing/ipd/discharge_create.php - Removed debug comments

TESTING STEPS:
1. Clear corrupt legacy data: php clear_legacy_food.php 1
2. Go to /Ipd_discharge/ipd_select/1
3. Clear both fields
4. Type 'Hello Other' in Other Advice
5. Type 'Hello Discharge' in Discharge Summary
6. Click 'Save Discharge Advice'
7. After reload: Other Advice should show 'Hello Other', NOT 'Hello Discharge'

SCRIPTS ADDED:
- check_instruction_db.php - Check database values
- check_legacy_food.php - Check legacy table
- clear_legacy_food.php - Clean corrupt legacy data
- list_instruction_records.php - List all records
2026-06-07 20:00:59 +05:30