Overview
High-level overview of the lh-print utility: purpose, architecture, and core concepts.
Overview
lh-print (LiveHealth Barcode Printer) is a Python-based utility designed to bridge the gap between modern web-based laboratory management systems and physical label printers. It enables seamless printing of patient and sample barcodes directly from a browser by translating web data into printer-specific commands (PRN).
Remote Printer
The lh-print utility acts as a local protocol handler. When a user clicks a "Print" button in the LiveHealth web application, the browser triggers a custom URI scheme (lhprint://). The local lh-print application intercepts this trigger, parses the patient data, hydrates a predefined PRN template, and sends the raw commands directly to the shared thermal printer.
In engineering terms: this utility solves the "last-mile" connectivity issue for legacy hardware. Since web browsers cannot directly communicate with local COM/LPT ports or specific UNC paths for raw PRN delivery due to security sandboxing, lh-print serves as the trusted local agent that executes these low-level OS operations.
Related Jira Tickets
| Ticket | Title | Notes |
|---|---|---|
EN-9789 | Barcode Printer Utility | Support for Multiple Printers in PRN Application (Shipping + Barcode Labels) |
EN-10033 | Remote Print Integration | Support for same sample id multiple tests printing in PRN2 mode |
Prerequisites
| Requirement | Why it matters | Where it is enforced |
|---|---|---|
| Windows OS | The protocol handler registration and UNC path moving logic are Windows-specific | lhprint/config.py, lhprint/utils.py |
| Shared Printer | The application "moves" PRN files to a UNC path (\\machine\printer) | lhprint/prn_printer.py |
| Registry Entry | The lhprint:// protocol must be registered in the Windows Registry to be triggered by browsers | lh-print.reg (Generated by config.py) |
| Directory Access | Application must have write access to C:\livehealth\LHBarcodePrinter | lhprint/__init__.py |
| Config File | config.json must specify the correct printer share name and template | lhprint/barcode_printer.py |
What Is It For
Frontend perspective
- Seamless UX: Print barcodes without downloading files or opening search/print dialogs.
- Bulk Support: Trigger multiple barcode prints for a single order in one click.
- Dynamic Feedback: Leverage local logging to troubleshoot printer connectivity issues.
Backend/Local perspective
- Protocol Interception: Register and handle
lhprint://URI schemes. - Data Parsing: Extract patient names, IDs, and test details from encoded URI strings.
- Template Hydration: Dynamically inject patient data into EPL, ZPL, EZPL, etc. templates.
- Physical Execution: Send raw commands to thermal printers via OS-level
movecommands to UNC paths.
Key Features
- Multi-Dialect Support: Default templates provided for EPL, ZPL, EZPL, TSPL, and ESCP.
- Custom URI Scheme: Uses
lhprint://to allow cross-browser compatibility. - Zero-Dependency Core: Designed to run as a standalone executable (via PyInstaller).
- Flexible Configuration:
config.jsonallows fine-grained control over field splitting and character limits. - Bulk Print Modes: Supports single barcode, bulk (delimited by
$), and API-based fetch modes. - Auto-Initialization: Automatically creates directories, registry files, and default templates on first run.