Appearance
ORU2REPORT — HL7 ORU to PDF/PNG/HTML Reports
ORU2REPORT listens for HL7 ORU result messages over MLLP and turns each one into a report file in an outbox folder. A downstream process — a document sweep, a DICOM Printer 2 drop folder, a file share — picks the file up from there.
ORU2REPORT produces a report in one of two ways:
- Render. The ORU is merged into an HTML template. A headless Microsoft Edge or Google Chrome then prints the page to PDF or captures it as a PNG. You can also write the merged HTML as-is.
- Passthrough. The ORU already carries a finished PDF, either embedded as Base64 in OBX-5 or referenced as a file path in OBX-5. ORU2REPORT delivers that PDF under a templated file name.
The Windows service is DICOM7_ORU2REPORT. Its display name is "DICOM7 HL7 ORU to report bridge".
How it works
- Receive. The service accepts MLLP connections on
HL7.ListenPort(default7778) and reads each framed message as UTF-8. - Check for duplicates. The message ID is MSH-10 with every character other than letters, digits,
_and-removed. When MSH-10 is empty, the service uses a hash of the message instead. If a message with the same ID is already incache\incoming\sent\, ORU2REPORT acknowledges it withAAand does nothing else. - Persist. The raw message is written to
cache\incoming\<id>.hl7before any processing. - Produce output according to
Report.SourceMode:- Render: tokens in the HTML template are replaced with values from the ORU. The result goes to
cache\working\<id>.html. The browser then prints it to PDF or captures it as PNG directly into the outbox. WithOutputFormat: Html, the merged HTML is written to the outbox and no browser is launched. - Passthrough: the embedded PDF is decoded, or the referenced file is copied (or moved), into the outbox.
- Render: tokens in the HTML template are replaced with values from the ORU. The result goes to
- Finish. On success, the incoming message moves to
cache\incoming\sent\with a.metafile that lists the output files, and the working HTML is deleted. If the attempt fails, any partial output is removed and the message is queued for retry (see Retries, deferral and errors). - Acknowledge. The ACK is sent once this first attempt has finished, so the sender waits while the report renders. See Acknowledgements.
HTML output and passthrough PDFs are written to the outbox under a temporary .tmp name and then renamed. The browser writes PDF and PNG files directly to their final name, and ORU2REPORT waits until that file is complete and no longer changing before it counts the report as delivered.
Downstream sweeps
If the process that collects the outbox could open a file while the browser is still writing it, have that process skip files modified in the last few seconds.
Source modes
Report.SourceMode selects where the delivered document comes from.
| Mode | Behavior |
|---|---|
Render (default) | Always render from Report.TemplateFile. Any attachments in the ORU are ignored. |
Attachment | Deliver only the embedded or referenced PDF. If no PDF is found or it can't be read, the message is deferred or rejected according to Attachment.DeferOnMissing. |
Auto | Deliver the attachment when the ORU contains one. If it contains none, render from the template. If it contains one that can't be read yet, the message is always deferred and retried, regardless of DeferOnMissing. |
Both | Render a report and deliver the attachment as two separate files. The PDFs are never merged. If the attachment step fails, the rendered file is deleted too, so the message is retried or rejected as a unit. |
An unrecognized value logs a warning and falls back to Render.
Choosing a mode
Use Attachment when every ORU in the feed points at a finished PDF. Use Auto only for mixed feeds, where some ORUs carry a PDF and others must be rendered. Use Both only when the downstream system needs both documents for the same result.
Requirements
Headless browser
Rendering to PDF or PNG needs a Chromium-based browser on the server. When Report.BrowserExecutablePath is empty, ORU2REPORT uses the first of these that exists:
C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exeC:\Program Files\Microsoft\Edge\Application\msedge.exeC:\Program Files\Google\Chrome\Application\chrome.exeC:\Program Files (x86)\Google\Chrome\Application\chrome.exe
If you set BrowserExecutablePath, only that path is tried. If no browser is found, the render fails with "No supported headless browser executable was found" and the message is deferred for retry.
No browser is needed for OutputFormat: Html or for attachment-only delivery.
Each render launches its own browser process with a throwaway profile directory, which is deleted afterwards. The profile is created under %TEMP%\DICOM7-ORU2REPORT-browser\ of the service account.
Service account
Browser rendering often depends on the user context of the account that runs the service.
- Fresh install: configure the
DICOM7_ORU2REPORTservice to log on as a dedicated, non-expiring account that is allowed to launch the selected browser. Grant that account Modify access toC:\ProgramData\Flux Inc\DICOM7\ORU2REPORTbefore you send production traffic. - Upgrades: the installer keeps the existing service registration, so the logon account you configured is preserved.
The account also needs:
- write access to
Report.OutputFolder(for example, a network share); - read access to every folder that referenced PDFs come from;
- delete access to those folders when
Attachment.OperationisMove.
See Installation and Starting and Stopping.
Configuration
The settings live in config.yaml in the service's data folder, by default C:\ProgramData\Flux Inc\DICOM7\ORU2REPORT\config.yaml. Keys are PascalCase. Relative paths resolve against the data folder, except Report.WorkingFolder, which resolves against the cache folder. See Configuration for the general file layout and the --path override.
Invalid YAML falls back to defaults
If config.yaml is missing or can't be parsed, the service logs an error and starts with the built-in defaults listed below. After you edit the file, check the log at startup.
Configuration and the report template are read once, at startup. Restart the service to apply changes.
Default config.yaml
yaml
HL7:
ListenIP: 0.0.0.0
ListenPort: 7778
SenderName: DICOM7
ReceiverName: RECEIVER_APPLICATION
ReceiverFacility: RECEIVER_FACILITY
DeferredAckCode: AA
Cache:
Folder: "cache"
RetentionDays: 3
KeepSentItems: true
AutoCleanup: true
CleanupIntervalMinutes: 60
OutboxRetentionHours: 24
Retry:
RetryIntervalMinutes: 2
MaxAttempts: 10
Report:
OutputFolder: "outbox"
WorkingFolder: "working"
TemplateFile: "reportTemplate.html"
FileNameTemplate: "{AccessionNumber}_{PatientId}_{FacilityIdentifier|filename}_{ProcedureDescriptionShort|filename}.pdf"
OutputFormat: "Pdf"
SourceMode: "Render"
Attachment:
Strategy: "Auto"
ReferenceValueTypes: [ "RP", "ST" ]
ReferenceObservationIdentifiers: []
PathMappings: []
Operation: "Copy"
StrictMove: false
DeferOnMissing: true
MinFileAgeSeconds: 0
FileNameTemplate: ""
SuffixOnBoth: ""
BrowserExecutablePath: ""
BrowserRenderTimeoutSeconds: 30
PngDpi: 300
KeepHtmlCopy: false
BrowserPdfArguments: ""
BrowserPngArguments: ""HL7
| Key | Type | Default | Description |
|---|---|---|---|
ListenIP | string | 0.0.0.0 | Address to listen on. An IPv4 address binds only that address. 0.0.0.0, an empty value or anything that isn't an IP address binds the loopback address plus every IPv4 address on the network interfaces that are up when the service starts. |
ListenPort | number | 7778 | TCP port for the MLLP listener. |
DeferredAckCode | string | AA | ACK code returned when the first attempt is deferred for retry. An empty value means AA. See Acknowledgements. |
SenderName | string | DICOM7 | Accepted for consistency with other DICOM7 services. ORU2REPORT does not use it, because the ACK header is built from the incoming MSH. |
ReceiverName | string | RECEIVER_APPLICATION | Not used by ORU2REPORT (see SenderName). |
ReceiverFacility | string | RECEIVER_FACILITY | Not used by ORU2REPORT (see SenderName). |
Cache
| Key | Type | Default | Description |
|---|---|---|---|
Folder | string | cache | Root of the internal cache. Relative paths resolve against the data folder. |
RetentionDays | number | 3 | Age in days after which files in incoming\, incoming\sent\ and the working folder are deleted at startup. Values of 0 or less are treated as 3. |
KeepSentItems | boolean | true | Moves processed messages to cache\incoming\sent\ (with a .meta file listing the output files). When false, processed messages are deleted. Duplicate detection relies on this folder, so with false a resent message is processed again. |
OutboxRetentionHours | number | 24 | At startup, files in Report.OutputFolder older than this many hours are deleted. The minimum is 1 hour. |
AutoCleanup | boolean | true | Not used by ORU2REPORT. Cleanup runs once, at service start. |
CleanupIntervalMinutes | number | 60 | Not used by ORU2REPORT (see AutoCleanup). |
The outbox is cleaned at startup
ORU2REPORT treats Report.OutputFolder as a pickup area, not an archive. Each time the service starts, it deletes files there that are older than OutboxRetentionHours. If reports must be kept, make sure the downstream process collects them, or point OutputFolder somewhere that holds nothing else.
Retry
| Key | Type | Default | Description |
|---|---|---|---|
RetryIntervalMinutes | number | 2 | How often the retry sweep runs, and how long a deferred message waits before it is retried. Minimum 1. A sweep also runs at startup. |
MaxAttempts | number | 10 | Number of retry attempts before a deferred message is moved to cache\error\. 0 or a negative value retries indefinitely. |
Report
| Key | Type | Default | Description |
|---|---|---|---|
TemplateFile | string | reportTemplate.html | HTML template used for rendering. Relative paths resolve against the data folder. If the file doesn't exist, the default template is written there at startup. |
OutputFolder | string | outbox | Where finished reports are delivered. This can be an absolute or UNC path. Relative paths resolve against the data folder. The folder is created if it is missing. |
WorkingFolder | string | working | Scratch folder for merged HTML before the browser renders it. Relative paths resolve against the cache folder. |
FileNameTemplate | string | {AccessionNumber}_{PatientId}_{FacilityIdentifier|filename}_{ProcedureDescriptionShort|filename}.pdf | Output file name, built from tokens and filters. See Output file naming. |
OutputFormat | string | Pdf | Format for rendered reports: Pdf, Png or Html. Any other value renders a PDF. This doesn't affect passthrough attachments, which are always delivered as .pdf. |
SourceMode | string | Render | Render, Attachment, Auto or Both. See Source modes. |
Attachment | object | see below | Passthrough settings, used when SourceMode is Attachment, Auto or Both. |
BrowserExecutablePath | string | "" | Full path to msedge.exe or chrome.exe. Leave empty to auto-detect (see Headless browser). |
BrowserRenderTimeoutSeconds | number | 30 | How long to wait for the browser to exit, and then for the output file to be complete and stable. Minimum 5. On timeout the browser process is terminated and the message is deferred. |
PngDpi | number | 300 | Resolution of PNG output. The page is captured at 8.5 × 11 inches at this DPI (2550 × 3300 pixels at 300), and the DPI is written into the PNG. Minimum 72. |
KeepHtmlCopy | boolean | false | For Pdf and Png output, also write the merged HTML to the outbox under the same base name with an .html extension. |
BrowserPdfArguments | string | "" | Replaces the browser command line used for PDF rendering. Leave empty for the built-in defaults. See Browser command line. |
BrowserPngArguments | string | "" | Replaces the browser command line used for PNG rendering. Leave empty for the built-in defaults. |
Report.Attachment
| Key | Type | Default | Description |
|---|---|---|---|
Strategy | string | Auto | Embedded looks only for Base64 PDFs in OBX-5. Reference looks only for file paths in OBX-5. Auto looks for an embedded PDF first, then a reference. |
ReferenceValueTypes | list | [ "RP", "ST" ] | OBX-2 value types that may carry a file reference. An empty list means RP and ST. |
ReferenceObservationIdentifiers | list | [] | OBX-3 codes that mark the reference, matched case-insensitively against OBX-3.1 or OBX-3.2 (for example IMAGE_REF). When empty, any OBX with a matching value type is accepted, provided its OBX-5 contains pdf. |
PathMappings | list | [] | Rewrites the sender's path prefix to one this server can reach. Each entry has From and To. See Path remapping. |
Operation | string | Copy | Copy leaves the source PDF in place. Move deletes the source after it has been copied into the outbox. |
StrictMove | boolean | false | With Move: if the source can't be deleted, true fails the delivery (and the message is retried), while false logs a warning and delivers anyway. |
DeferOnMissing | boolean | true | In Attachment and Both modes, what to do when no PDF is found or a referenced file can't be read. true defers and retries. false moves the message to cache\error\ and returns AE. |
MinFileAgeSeconds | number | 0 | A referenced file must not have been modified for at least this many seconds before it is picked up. Use it when the sender may still be writing the PDF. |
FileNameTemplate | string | "" | File name template for passthrough PDFs. Empty means Report.FileNameTemplate. |
SuffixOnBoth | string | "" | In Both mode only, text appended to the attachment's base name (before .pdf) so it can't collide with the rendered report. |
Report templates
The HTML template is ordinary HTML with {Token} placeholders, for example {PatientNameDisplay}, {OBR-4.2} or {ReportText|nl2br}. Values are HTML-encoded by default. Filters such as |trim, |nocarets, |date:MM/dd/yyyy and |replace:FROM:TO clean them up. The page size and margins come from the template's CSS @page rule; the default template uses US Letter with 0.5 in margins.
The full token list, field-path syntax, filter reference and the default template are on HL7 Templates & Filters.
Report text
{ReportText} joins every OBX-5 value with line breaks. <br> tags are converted to line breaks and HTML entities are decoded. Use {ReportText|nl2br} to keep the line breaks in the rendered page.
Output file naming
The output name is built from FileNameTemplate with the same tokens and filters as the HTML template, but values are not HTML-encoded. After the tokens are substituted:
- Any directory part is dropped, so only the file name is kept.
- The extension is forced to match the output:
.pdf,.pngor.htmlfor rendered reports, and always.pdffor passthrough attachments. - Characters that aren't allowed in Windows file names are replaced with
_, and leading or trailing_and.are trimmed.- Rendered reports: runs of spaces collapse and every space becomes
_. This includes spaces in the literal text of the template. - Passthrough attachments: spaces are kept, and runs of
_collapse to one.
- Rendered reports: runs of spaces collapse and every space becomes
- In
Bothmode,Attachment.SuffixOnBothis appended to the attachment's base name. - If the result is empty, the message ID is used as the name.
- If a file with that name is already in the outbox,
_2,_3, … is appended.
With the default template, a synthetic ORU with accession EXAMPLE-001, patient ID EXAMPLE-PATIENT, MSH-4 FACILITY and OBR-4.2 CT CHEST W IV CONTRAST produces:
text
EXAMPLE-001_EXAMPLE-PATIENT_FACILITY_CT.pdfPassthrough attachments can also use these tokens:
| Token | Value |
|---|---|
{SourceFileName} | File name of the referenced PDF (after path mapping). For an embedded PDF, OBX-3.2, or OBX-3.1 if that is empty. Falls back to attachment.pdf. |
{SourceFileBaseName} | SourceFileName without its extension. |
{SourceFileExtension} | Extension of SourceFileName, including the dot. |
{SourcePath} | The reference path exactly as it appeared in OBX-5. Empty for embedded PDFs. |
Keep multi-part names stable
When a file name token resolves to an empty value, the service logs a warning naming the token, and that part of the name is simply missing. A template such as {A}_{B}_{C}_{D}.pdf can then produce a three-part name. If a downstream system splits names on _:
- add
|fallback:VALUEto keep a placeholder, for example{ProcedureDescriptionShort|filename|fallback:NA}; - add
|replace:_:-after|filenamefor values that may themselves contain spaces or underscores.
Attachment passthrough
Embedded PDFs
ORU2REPORT uses the first OBX segment that matches all of these:
- OBX-2 is
ED; - OBX-5.4 (encoding) is
Base64orB64; - OBX-5.5 (data) is not empty;
- OBX-5.3 (subtype) or OBX-5.2 (type of data) contains
pdf, case-insensitively.
The data is Base64-decoded and written to the outbox. An OBX whose Base64 can't be decoded is skipped with a warning.
text
OBX|1|ED|PDF^Report||^Application^PDF^Base64^JVBERi0xLjQK...||||||FReferenced PDFs
ORU2REPORT uses the first OBX segment that matches all of these:
- OBX-2 is in
ReferenceValueTypes; - OBX-3.1 or OBX-3.2 is in
ReferenceObservationIdentifiers, or that list is empty; - OBX-5 is not empty, and contains
pdfwhenReferenceObservationIdentifiersis empty.
OBX-5 is taken as a file path. Surrounding quotes are removed, and a file:// URI is converted to a local path.
text
OBX|1|ST|IMAGE_REF||C:\Reports\example-report.pdf||||||FBefore delivery, the referenced file is checked. If any check fails, the reason is logged and the message is deferred (or, in Attachment/Both mode with DeferOnMissing: false, rejected):
| Check | Logged reason |
|---|---|
| OBX-5 is empty | attachment file reference is empty |
| File doesn't exist (after path mapping) | attachment file missing: <path> |
Modified less than MinFileAgeSeconds ago | attachment file too young (...) |
| Another process has it open for writing | attachment file locked for read: <path> |
| Access denied | attachment file not readable: <path> |
| Zero bytes | attachment file is empty: <path> |
Path remapping
The path in OBX-5 is usually local to the sending system (for example C:\Reports\...). PathMappings translates it into a path that the ORU2REPORT service account can reach:
yaml
Attachment:
PathMappings:
- From: 'C:\Reports\'
To: '\\reports.example.org\Reports\'Mappings are checked in order. The first From that is a case-insensitive prefix of the path is replaced with its To, and later mappings are ignored. A path that matches no mapping is used as-is.
TIP
Use single quotes in YAML for Windows paths so backslashes aren't treated as escape characters. Keep the trailing backslash on both From and To so the prefix lines up on a folder boundary.
Copy or move
The source file is first copied into the outbox under a .tmp name.
- With
Operation: Copy, the source is left in place. - With
Operation: Move, the source is deleted. If that fails andStrictMoveisfalse, a warning is logged and delivery continues. IfStrictMoveistrue, the delivery fails and the message is retried.
The .tmp file is then renamed to its final name.
Retries, deferral and errors
A processing attempt that fails is deferred. This happens when:
- the browser is missing, times out or exits with an error;
- the output file never becomes stable;
- an attachment is missing or not yet readable;
- an outbox write fails.
Any partial output from the attempt is deleted.
On the first attempt, a deferred message is written to the retry queue in the cache folder as two files:
<id>.pending— the raw HL7;<id>.attempts— the attempt counter.
A sweep runs at startup and then every RetryIntervalMinutes. It retries each pending message that has waited at least RetryIntervalMinutes:
- Success: the pending files are removed and the message moves to
cache\incoming\sent\. - Still failing: the counter goes up. Once it would exceed
MaxAttempts, the message is written tocache\error\<id>.hl7, the reason (Exceeded retry attempts) goes tocache\error\<id>.hl7.meta, and the message leaves the queue. - Unparseable on retry: the message moves straight to
cache\error\.
Messages in cache\error\ are not retried automatically.
Acknowledgements
The service replies on the same connection once the first processing attempt has finished:
| Outcome | MSA-1 |
|---|---|
| Report delivered | AA |
| Duplicate of an already processed message | AA |
| Deferred for retry | HL7.DeferredAckCode (default AA) |
| Message could not be parsed | AE |
Attachment missing/unreadable with DeferOnMissing: false (Attachment/Both modes) | AE |
| Unexpected processing error | AE |
The default DeferredAckCode of AA tells the sender the message is accepted while ORU2REPORT keeps retrying in the background. Set it to AE if the sender should treat a deferral as a failure (for example, so it resends).
The ACK is an HL7 v2.3 ACK message:
- The incoming sending and receiving application/facility are swapped into MSH-3 to MSH-6.
- MSH-10 is
ACKfollowed by the incoming control ID. - MSA-2 echoes the incoming MSH-10.
- For
AE, MSA-3 carries the error text.
See HL7 Conformance.
Unique MSH-10 required
Duplicate detection uses MSH-10 only. If a sender reuses a control ID for a different result while the earlier message is still in cache\incoming\sent\ (within RetentionDays), the new result is acknowledged with AA but not rendered.
Folders
With the default settings, under C:\ProgramData\Flux Inc\DICOM7\ORU2REPORT\:
| Path | Contents |
|---|---|
config.yaml | Service configuration |
reportTemplate.html | HTML report template |
outbox\ | Delivered reports (Report.OutputFolder) |
cache\incoming\ | Raw messages being processed |
cache\incoming\sent\ | Processed messages, with .meta files listing their outputs |
cache\working\ | Merged HTML awaiting rendering (deleted after each attempt) |
cache\error\ | Messages that failed permanently, with .meta reason files |
cache\<id>.pending, cache\<id>.attempts | Retry queue |
logs\dicom7-oru2report.log | Service log |
Browser command line
The built-in arguments are designed for running under a Windows service account:
- no sandbox;
- a fresh profile directory for each render;
- the browser's own diagnostics written to stderr, which ORU2REPORT records in its log;
- for PDF, no browser-generated headers or footers.
PDF default:
text
--headless --disable-gpu --no-sandbox --disable-dev-shm-usage --allow-file-access-from-files --user-data-dir="{userDataDir}" --enable-logging=stderr --v=0 --print-to-pdf="{outPath}" --no-pdf-header-footer "{htmlUri}"PNG default:
text
--headless --disable-gpu --no-sandbox --disable-dev-shm-usage --allow-file-access-from-files --user-data-dir="{userDataDir}" --enable-logging=stderr --v=0 --hide-scrollbars --force-device-scale-factor=1 --window-size={width},{height} --default-background-color=16777215 --screenshot="{outPath}" "{htmlUri}"To change them, set BrowserPdfArguments or BrowserPngArguments to a complete argument string. It is used exactly as written, after these placeholders are substituted:
| Placeholder | PNG | Value | |
|---|---|---|---|
{outPath} | ✓ | ✓ | Full path of the file to write in the outbox |
{htmlUri} | ✓ | ✓ | file:// URI of the merged HTML |
{userDataDir} | ✓ | ✓ | A new temporary profile directory, created only if referenced and deleted after the render |
{width} | ✓ | 8.5 × PngDpi | |
{height} | ✓ | 11 × PngDpi | |
{dpi} | ✓ | PngDpi |
Each launch is logged with the full command line. If the browser exits with a non-zero code, its stdout and stderr are logged and the message is deferred.
Examples
Rendered PDF (default)
yaml
HL7:
ListenPort: 7778
Report:
OutputFolder: 'D:\ReportOutbox'
OutputFormat: "Pdf"
SourceMode: "Render"
FileNameTemplate: "{AccessionNumber}_{PatientId}_{OBR-7|date:yyyyMMdd}.pdf"PNG for image-based pickup
yaml
Report:
OutputFormat: "Png"
PngDpi: 200
FileNameTemplate: "{AccessionNumber|filename|fallback:NOACC}_{PatientId}.png"
KeepHtmlCopy: trueReferenced-PDF passthrough to a sweep folder
The sender writes the PDF to its own C:\Reports\ folder and puts the path in an ST OBX coded IMAGE_REF. ORU2REPORT reads the PDF through a share, moves it into the pickup folder and renames it.
yaml
Report:
OutputFolder: '\\pickup.example.org\reports\Inbox'
FileNameTemplate: "{PV1-19}_{OBR-7|date:MMddyyyy}_Example Report.pdf"
SourceMode: "Attachment"
Attachment:
Strategy: "Reference"
ReferenceValueTypes: [ "RP", "ST" ]
ReferenceObservationIdentifiers: [ "IMAGE_REF" ]
PathMappings:
- From: 'C:\Reports\'
To: '\\reports.example.org\Reports\'
Operation: "Move"
MinFileAgeSeconds: 5For an ORU with PV1-19 VISIT-001 and OBR-7 20260115120000, this delivers VISIT-001_01152026_Example Report.pdf. Spaces are kept because this is a passthrough attachment.
Embedded PDF when present, otherwise render
yaml
Report:
SourceMode: "Auto"
Attachment:
Strategy: "Embedded"Rendered report plus original PDF
yaml
Report:
SourceMode: "Both"
FileNameTemplate: "{AccessionNumber}_{PatientId}.pdf"
Attachment:
SuffixOnBoth: "_original"This produces ACC123_PID456.pdf (rendered) and ACC123_PID456_original.pdf (attachment).
Custom browser path and more verbose browser logging
yaml
Report:
BrowserExecutablePath: 'C:\Program Files\Google\Chrome\Application\chrome.exe'
BrowserRenderTimeoutSeconds: 60
BrowserPdfArguments: '--headless --disable-gpu --no-sandbox --disable-dev-shm-usage --allow-file-access-from-files --user-data-dir="{userDataDir}" --enable-logging=stderr --v=1 --print-to-pdf="{outPath}" --no-pdf-header-footer "{htmlUri}"'Related
- HL7 Templates & Filters — tokens, field paths, filters and the default report template
- ORU2DICOM — turns ORU results into DICOM objects instead of files
- Configuration · Cache · Logs