L
Leaphealth - OSDocs

PDF Invoices

Generating, customising, and sharing printable invoice PDFs.

PDF Invoices

The system generates PDF invoices for bills, prescriptions, and diagnostic reports using customizable HTML templates stored in the database.

Template System

PDF templates are stored in the database with the following structure:

Field

Description

Template Code

Unique identifier per tenant (e.g., HOS_BILL_STANDARD, HOS_PRESCRIPTION_STANDARD)

Template Name

Human-readable name

Content HTML

Full HTML template with variable placeholders

Variables

List of supported variable names

Paper Size

A4 (default), A3, or Letter

Orientation

Portrait (default) or Landscape

Version

Template version number for tracking changes

Active

Whether this template is currently in use

Each tenant can have its own branded template. The template code is unique per tenant, so different hospitals can use different layouts.

Template Variables

Templates use double-curly-brace placeholders that are replaced with actual values during PDF generation. For bill PDFs, the available variables include:

Variable

Description

bill_uuid

Unique bill identifier

bill_number

Human-readable bill number

bill_date

Formatted bill date

due_date

Payment due date

patient_name

Patient's full name

patient_id

Patient's UHID or reference

patient_phone

Patient's phone number

patient_email

Patient's email address

centre_name

Hospital/centre name

doctor_name

Consulting doctor's name

line_items_html

Pre-rendered HTML table of bill line items

subtotal

Sum before discounts and taxes

total_discount

Total discount amount

total_tax

Total tax amount

grand_total

Final amount payable

payment_status

Current payment status

payment_method

Payment method used

payment_reference

Transaction reference number

terms_and_conditions

Terms text

qr_code_url

URL for payment QR code image

PDF Generation Process

When a PDF is generated, the system:

  1. Fetches the correct template from the database based on tenant and template code
  2. Collects all variable values from the bill, patient, and centre records
  3. Replaces all placeholders in the HTML template with actual values (unsafe values are escaped)
  4. Renders the HTML to a PDF using a headless browser
  5. Uploads the PDF to cloud storage and stores the resulting URL

Billing Configuration Snapshot

When a bill is created, the system captures a snapshot of the billing configuration at that moment:

  • Auto-Generate Bills: whether bills are created automatically on appointment completion
  • Auto-Email on Issue: whether to email the PDF to the patient when the bill is issued
  • Auto-WhatsApp on Issue: whether to send the PDF via WhatsApp when issued
  • PDF Template Code: which template to use for PDF generation
  • Bill Consolidation: whether to merge multiple items into a single bill
  • Approval Threshold: amount above which bills need approval before issuing

PDF Delivery Channels

Generated PDFs can be delivered through:

  • Email: sent as an attachment or link via the email system
  • WhatsApp: sent via a pre-approved WhatsApp template message
  • Patient Portal: patients can download PDFs from their bill details page
  • Direct URL: a signed URL is generated for direct download
invoicespdfreceiptsbilling-documents

Last updated on

On this page