Skip to content

HL7 Templates & Filters ​

DICOM7 uses two template languages. Each one goes in a different direction:

LanguageSyntaxDirectionUsed by
HL7 message templates#{0010,0020}DICOM → HL7DICOM2ORM, DICOM2ORU
Report tokens and filters{PatientId}, {OBR-4.2|trim}HL7 → documentORU2REPORT (HTML template and file names)

The other services have no editable template:

  • ORM2DICOM maps ORM fields to worklist attributes in code.
  • ORU2DICOM builds a Basic Text SR from the ORU's observations, and an Encapsulated PDF when the ORU carries one. It reads the ORU with the same field rules as the named report values below (for example, the study description comes from OBR-4.2).
  • HL72HL7 changes outbound messages with per-destination transforms in its config.yaml, not with templates.

HL7 message templates ​

DICOM2ORM and DICOM2ORU build each outgoing HL7 message from a template file. The file is a complete HL7 v2 message in which DICOM attribute placeholders stand in for the values.

Template files ​

ServiceFileDefault location
DICOM2ORMormTemplate.hl7C:\ProgramData\Flux Inc\DICOM7\DICOM2ORM\ormTemplate.hl7
DICOM2ORUoruTemplate.hl7C:\ProgramData\Flux Inc\DICOM7\DICOM2ORU\oruTemplate.hl7

The file name is fixed. It sits in the service's data folder, which is the folder given by --path when that option is used (see Configuration).

  • If the file doesn't exist at startup, the service writes the default template there and uses it.
  • The template is read once, at startup. Restart the service after you edit it.
  • The template must parse as an HL7 message. If it doesn't, the service logs a fatal error ("Failed to parse ORM template" or "Failed to parse ORU template") and exits.

Starting fresh

To go back to the default template, stop the service, delete or rename the template file, and start the service again.

Placeholder syntax ​

text
#{GGGG,EEEE}

GGGG and EEEE are the hexadecimal group and element of a DICOM attribute, for example #{0010,0010} for Patient's Name. Keywords such as #{PatientName} are not supported. Only the special placeholders below are written as names.

Each placeholder is replaced with the attribute's value from the DICOM dataset:

  • Attribute in the top-level dataset: its value is used.
  • Attribute not at the top level: every sequence is searched, recursively, and the first occurrence is used. This is how Scheduled Procedure Step attributes such as #{0040,0002} (inside (0040,0100)) resolve from a worklist response.
  • Placeholder names a sequence attribute: the text [Sequence] is inserted.
  • Attribute not found: the placeholder becomes an empty string.
  • Value contains |: each | is replaced with ^. DICOM multi-valued names therefore stay inside one HL7 field.

Several placeholders can share one field. #{0040,0002}#{0040,0003} joins the scheduled date and time into a single HL7 timestamp.

Special placeholders ​

PlaceholderServiceValue
#{CurrentDateTime}DICOM2ORM, DICOM2ORUCurrent local time, yyyyMMddHHmmss
#{ScheduledDateTime}DICOM2ORMScheduled Procedure Step Start Date + Time (0040,0002)+(0040,0003). If either is missing, the current time plus 24 hours.
#{ScheduledProcedureStepID}DICOM2ORMScheduled Procedure Step ID (0040,0009) from the first item of (0040,0100), or from the top level
#{StudyDateTime}DICOM2ORUStudy Date + Study Time (0008,0020)+(0008,0030). The time is normalized to HHMMSS, with fractions removed. If either is missing, the current time.

Default ORM template ​

DICOM2ORM writes this HL7 v2.3 ORM^O01 template:

FieldValue
MSH-3 Sending ApplicationDICOM7
MSH-5 / MSH-6 Receiving Application / FacilityRECEIVER_APPLICATION / RECEIVER_FACILITY
MSH-9 Message TypeORM^O01
MSH-10 Message Control ID#{0020,000D} (Study Instance UID)
MSH-11 / MSH-12P / 2.3
PID-11
PID-2, PID-3 Patient ID#{0010,0020}
PID-5 Patient Name#{0010,0010}
PID-7 Date of Birth#{0010,0030}
PID-8 Sex#{0010,0040}
PV1-1 / PV1-21 / O
PV1-19 Visit Number#{0008,0050} (Accession Number)
PV1-44 Admit Date/Time#{0040,0002}#{0040,0003}
ORC-1 Order ControlNW
ORC-2 Placer Order Number#{0008,0050}
ORC-3 Filler Order Number#{0020,000D}
ORC-4 Order StatusSC
OBR-11
OBR-2 Placer Order Number#{0008,0050}
OBR-4 Universal Service ID#{0008,1030} (Study Description)
OBR-6 Requested Date/Time#{0040,0002}#{0040,0003}

Sender and receiver names. When DICOM2ORM sends an order, MSH-3 equal to DICOM7 becomes HL7.SenderName. HL7.ReceiverName and HL7.ReceiverFacility are applied only to a literal RECEIVER_APPLICATION in MSH-4 and a literal RECEIVER_FACILITY in MSH-5, so the placeholders in MSH-5 and MSH-6 of the default template are sent as written. Type the receiving application and facility directly into MSH-5 and MSH-6 of the template, and check the first message the receiver logs. In other segments, any whole field holding one of the three literals is replaced with the configured value.

Default ORU template ​

DICOM2ORU writes this HL7 v2.5.1 ORU^R01^ORU_R01 template:

FieldValue
MSH-3 / MSH-4DICOM7_DICOM2ORU / FLUXINC
MSH-5 / MSH-6FLUX^fluxinc.co^DNS / fluxinc^2.16.840.1.113883.3.8873^ISO
MSH-9 Message TypeORU^R01^ORU_R01
MSH-10 Message Control ID#{0020,000D} (Study Instance UID)
MSH-11 / MSH-12P / 2.5.1
PID-11
PID-2, PID-3 Patient ID#{0010,0020}
PID-5 Patient Name#{0010,0010}
PID-7 Date of Birth#{0010,0030}
PID-8 Sex#{0010,0040}
PV1-1 / PV1-21 / O
PV1-3 Assigned Location#{0008,0080} (Institution Name)
PV1-19 Visit Number#{0008,0050} (Accession Number)
PV1-44 Admit Date/Time#{CurrentDateTime}
ORC-1 / ORC-4RE / CM
ORC-2 Placer Order Number#{0008,0050}
ORC-3 Filler Order Number#{0020,000D}
OBR-11
OBR-2 Placer Order Number#{0008,0050}
OBR-3 Filler Order Number#{0020,000D}
OBR-4 Universal Service ID#{0008,1030} (Study Description)
OBR-7 Observation Date/Time#{0008,0020}#{0008,0030}
OBR-8 Observation End Date/Time#{CurrentDateTime}
OBR-16 Ordering Provider#{0008,1070} (Operators' Name)
OBR-25 Result StatusF
OBX-1 / OBX-21 / ED
OBX-3 Observation Identifier47045-0^Study report^LN
OBX-41
OBX-5 Observation Value^AP^Octet-stream^Base64^ (filled at runtime, see below)
OBX-11F

Sender and receiver names. DICOM2ORU sends MSH-3 to MSH-6 exactly as they appear in the template. To change the identity it announces, edit those fields in oruTemplate.hl7.

Embedded documents. DICOM2ORU looks for an OBX whose OBX-3 is exactly 47045-0^Study report^LN and replaces its OBX-5:

Received SOP ClassOBX-5 written
Encapsulated PDF Storage^Application^PDF^Base64^<PDF bytes>
Secondary Capture Image Storage^AP^Octet-stream^Base64^<first frame pixel data>

If you remove that OBX from the template or change its OBX-3, the message is still sent but the document isn't embedded, and a warning is logged.

Example: custom ORM template ​

text
MSH|^~\&|DICOM7||RECEIVER_APPLICATION|RECEIVER_FACILITY|#{CurrentDateTime}||ORM^O01|#{0020,000D}|P|2.3
PID|1|#{0010,0020}|#{0010,0020}||#{0010,0010}||#{0010,0030}|#{0010,0040}
PV1|1|O|||||||||||||||||#{0008,0050}
ORC|NW|#{0008,0050}|#{0020,000D}|SC
OBR|1|#{0008,0050}||#{0008,1030}||#{ScheduledDateTime}

This sends the current time in MSH-7 and uses #{ScheduledDateTime} in OBR-6, so an order without a scheduled time still gets a requested date/time.

Report tokens and filters ​

ORU2REPORT fills these templates from the incoming ORU:

TemplateSettingValues HTML-encoded?
Report HTMLReport.TemplateFile (default reportTemplate.html)Yes, unless |raw
Output file nameReport.FileNameTemplateNo
Passthrough file nameReport.Attachment.FileNameTemplateNo

The HTML template lives in the ORU2REPORT data folder, by default C:\ProgramData\Flux Inc\DICOM7\ORU2REPORT\reportTemplate.html. A relative TemplateFile resolves against that folder. If the file is missing at startup, the default report template is written there. The template is read once, at startup, so restart the service after editing it.

See ORU2REPORT for the rules applied to file names after the tokens are filled in.

Token syntax ​

text
{Name}
{Name|filter}
{Name|filter1|filter2:argument}
  • A token is {, a name, optional |filter steps, then }, with no spaces. Only letters, digits and _ - . [ ] * | : % / are allowed between the braces. To use a space or another character in a filter argument, URL-encode it (for example %20) in replace: and fallback:.
  • Name is a named value, a field path or, in passthrough file names, an attachment token.
  • Named values are case-sensitive: {PatientId} works and {patientid} does not. Filter names are case-insensitive.
  • A name that doesn't resolve produces an empty string. It is not left in the output.
  • Filters run left to right. Unknown filters are ignored.

CSS and scripts in the HTML template

Any text in braces that contains only the characters above is treated as a token. A compact CSS rule such as .x{margin:0} would be replaced with an empty string. Put a space inside CSS braces (.x { margin: 0; }), as the default template does.

Named values ​

TokenSource
{MessageControlId}MSH-10
{UUID}Message ID used for cache files: MSH-10 reduced to letters, digits, _ and -, or a 32-character hash of the message when MSH-10 is empty
{SendingApplication}MSH-3
{SendingFacility}MSH-4
{FacilityIdentifier}MSH-4 (same as SendingFacility)
{ReceivingApplication}MSH-5
{ReceivingFacility}MSH-6
{PatientId}PID-3.1 (first repetition). If empty, PID-2.1, then PID-2.2.
{PatientName}PID-5 as Family^Given^Middle^Prefix^Suffix, with empty parts omitted
{PatientNameDisplay}PID-5 as Family, Given
{DateOfBirth}PID-7 formatted MM/dd/yyyy (empty if it can't be parsed)
{Gender}PID-8
{AccessionNumber}OBR-3.1. If empty, OBR-2.1.
{PlacerOrderNumber}OBR-2.1
{ProcedureCode}OBR-4.1 (first repetition)
{ProcedureDescription}OBR-4.2 (first repetition)
{StudyDescription}Same as ProcedureDescription
{ProcedureDescriptionShort}First three characters of ProcedureDescription. Empty when the description starts with ***.
{ResultStatus}OBR-25
{ObservationDateTime}OBR-7 formatted yyyy-MM-dd HH:mm:ss
{ExamDate}, {ExamDateDisplay}OBR-7 formatted MM/dd/yyyy
{OrderingPhysician}OBR-16 as Family, Given. If empty, ORC-12.
{ReportText}Every non-empty OBX-5, one per line. <br> tags become line breaks and HTML entities are decoded. If there are no OBX values, the whole raw message.
{ObservationSummary}Numbered list, one line per OBX: 1. <OBX-3.2 or OBX-3.1>: <OBX-5> <OBX-6.1> (ref <OBX-7>) [status <OBX-11>]. If there are no OBX values, the whole raw message.

Field paths ​

A field path reads a value straight from the message:

FormExampleValue
SEG-F{PV1-19}Field F of the first SEG segment, as it appears in the message (components still joined by ^)
SEG-F.C{OBR-4.2}Component C of field F
SEG[n]-F.C{OBX[2]-5}The n-th SEG segment (1-based)
SEG[*]-F.C{OBX[*]-5}That field from every SEG segment, with empty values skipped, joined by line breaks

Fields and components are numbered as in the HL7 standard, so {MSH-10} is the message control ID. A missing segment, field or component gives an empty value. There is no syntax for choosing a repetition or subcomponent.

Free text with carets

A whole field such as {OBX-5} keeps its ^ separators. Add |nocarets to turn them into spaces, or pick one component with .C.

Attachment tokens ​

These are available only in passthrough file names (Report.FileNameTemplate or Report.Attachment.FileNameTemplate when a PDF attachment is delivered):

TokenValue
{SourceFileName}File name of the referenced PDF. For an embedded PDF, OBX-3.2, or OBX-3.1 if that is empty. Defaults to attachment.pdf.
{SourceFileBaseName}SourceFileName without its extension
{SourceFileExtension}Extension of SourceFileName, including the dot
{SourcePath}The reference path as it appeared in OBX-5. Empty for embedded PDFs.

Attachment token names are case-insensitive.

Filters ​

FilterEffect
rawDon't HTML-encode the value. Only matters in the HTML template.
trimRemove leading and trailing whitespace.
upper / lowerConvert to upper or lower case (culture-invariant).
nocaretsReplace every ^ with a space.
nl2brConvert line breaks to <br />. Applied after HTML encoding, so the tags survive.
prefix:N / truncate:NKeep at most the first N characters.
date:FORMATParse the value as an HL7 date/time and reformat it with a .NET custom date format such as MM/dd/yyyy or yyyyMMdd. A value that can't be parsed is left unchanged and a warning is logged.
replace:FROM:TOReplace every occurrence of FROM with TO. Both are URL-decoded. The split is at the first :, so encode a : in FROM as %3A. An empty FROM does nothing.
fallback:VALUEIf the value is empty or whitespace at this point in the chain, use VALUE (URL-decoded).
filenameReplace characters that aren't allowed in file names with _, collapse runs of spaces, turn spaces into _, and trim _ and . from the ends.
filename_keepspacesReplace characters that aren't allowed in file names (including \ and /) with _, collapse runs of _ to one, keep spaces, and trim _ and . from the ends.

Useful URL-encoded characters for replace: and fallback::

CharacterEncoding
space%20
line break%0A
:%3A
|%7C
,%2C
~%7E
^%5E
&%26
\%5C

Characters outside the allowed set, such as ~, , or a space, end the token: a token like {OBR-4|replace:~:,} is not recognized and stays in the output as plain text. Write it as {OBR-4|replace:%7E:%2C}.

date: accepts HL7 values in these shapes:

  • yyyyMMdd
  • yyyyMMddHH
  • yyyyMMddHHmm
  • yyyyMMddHHmmss, with optional fractional seconds
  • any of the above with a +hhmm/-hhmm offset

Its format argument can't contain spaces.

Encoding order ​

In the HTML template, a token is processed in this order:

  1. The value is resolved.
  2. Filters run left to right.
  3. The result is HTML-encoded (skipped with raw).
  4. Line breaks become <br /> if nl2br is in the chain.

<, > and & in HL7 data therefore show up as text, not markup.

|raw

{ReportText|raw} inserts the observation text as HTML. Use it only when the sending system's text is trusted, and when you actually want its markup to render.

In file name templates nothing is HTML-encoded. Use filename or filename_keepspaces on any value that might contain \, /, : or other characters that aren't allowed in file names.

Examples ​

html
<h1>{ProcedureDescription|upper}</h1>
<p>{PatientNameDisplay} &middot; DOB {DateOfBirth} &middot; MRN {PatientId}</p>
<p>Exam: {OBR-7|date:yyyy-MM-dd}</p>                       <!-- 2026-05-07 -->
<p>Exam time: {OBR-7|date:HH:mm}</p>                       <!-- 15:41 -->
<div class="notes">{OBX[*]-5|nocarets|trim|nl2br}</div>
<span>{SendingFacility|replace:_:%20}</span>               <!-- MAIN_CAMPUS → MAIN CAMPUS -->
<td>{ResultStatus|fallback:Pending}</td>

File names:

yaml
FileNameTemplate: "{AccessionNumber}_{PatientId}_{FacilityIdentifier|filename}_{ProcedureDescriptionShort|filename|fallback:NA}.pdf"
FileNameTemplate: "{PV1-19}_{OBR-7|date:MMddyyyy}_{SourceFileBaseName}.pdf"
FileNameTemplate: "{PatientName|nocarets|filename|replace:_:-}_{OBR-7|date:yyyyMMddHHmm}.pdf"

Default report template ​

ORU2REPORT writes this template when reportTemplate.html doesn't exist. It uses US Letter pages with 0.5 in margins and pure-black serif text sized for legibility when the output is later stored as an image.

html
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8" />
  <title>{ProcedureDescription}</title>
  <style>
    @page { size: Letter; margin: 0.5in; }
    body { font-family: "Times New Roman", Times, serif; color: #000; font-size: 13pt; line-height: 1.15; margin: 0; }
    .page { width: 6.9in; }
    .section-title { font-weight: 700; font-size: 13pt; margin: 0 0 0.14in 0; }
    .block { margin-bottom: 0.18in; }
    .line { margin: 0 0 0.03in 0; }
    .label { font-weight: 700; }
    .patient-name { font-weight: 700; font-size: 14pt; margin: 0 0 0.04in 0; }
    table { border-collapse: collapse; }
    .details td { padding: 0 0.12in 0.03in 0; vertical-align: top; }
    .details .detail-label { font-weight: 700; white-space: nowrap; }
    .notes { white-space: normal; }
  </style>
</head>
<body>
  <div class="page">
    <div class="block">
      <div class="section-title">Technologist Notes</div>
      <div class="line"><span class="label">Procedure:</span> {ProcedureDescription}</div>
    </div>
    <div class="block">
      <div class="line"><span class="label">Date of Exam:</span> {ExamDateDisplay}</div>
      <div class="line"><span class="label">Accession Number:</span> {AccessionNumber}</div>
    </div>
    <div class="block">
      <div class="section-title">Patient Information</div>
      <div class="patient-name">{PatientNameDisplay}</div>
      <table class="details">
        <tr><td class="detail-label">Patient ID:</td><td>{PatientId}</td></tr>
        <tr><td class="detail-label">Gender:</td><td>{Gender}</td></tr>
        <tr><td class="detail-label">Date of Birth:</td><td>{DateOfBirth}</td></tr>
        <tr><td class="detail-label">Ordering Physician:</td><td>{OrderingPhysician}</td></tr>
      </table>
    </div>
    <div class="block">
      <div class="section-title">Notes</div>
      <div class="notes">{ReportText|nl2br}</div>
    </div>
  </div>
</body>
</html>

Page size

The browser takes the PDF page size and margins from the @page rule. To print on A4, change it to @page { size: A4; margin: 12mm; }. PNG output is always captured at 8.5 × 11 inches, at Report.PngDpi.