# RADENVO HL7 v2 Conformance Statement

| | |
|---|---|
| Product | RADENVO (formerly Lumen PACS) (DICOM/HL7 gateway, web application) |
| Document date | 2026-11-05 |
| HL7 version | v2.x; inbound accepts any 2.x version, outbound per interface (default 2.5) |
| Sources | `gateway/hl7.mjs`, `hl7-codec.mjs`, `hl7-inbound.mjs`, `hl7-outbound.mjs`, `hl7-sftp.mjs`, `hl7-docs.mjs`, `server.mjs`; `src/app/api/hl7/[interface]/route.ts`; migrations `20261104110000_hl7_conformance.sql`, `20261104111000_hl7_more.sql`, `20261105040000_final_misc.sql` |

This statement describes what the code does. Message coverage follows the RamSoft RMC message set so that RADENVO can replace or sit beside a RamSoft RIS/PACS, but nothing here should be read as a statement about RamSoft.

---

## 1. Overview

### 1.1 Messages received

| Message | Trigger events | Purpose | Response |
|---|---|---|---|
| ADT | A01, A02, A03, A04, A05, A06, A07, A08, A09, A10, A11, A12, A13, A14, A16, A21, A22, A25, A26, A27, A28, A31, A32, A33, A38 (empty event = A08) | create or update patient, visit, allergies, observations, guarantor, insurance | ACK |
| ADT | A18, A30, A34, A35, A36, A39, A40, A41, A42, A44, A46, A47, A48, A49 | merge, identifier change, move account | ACK |
| ADT | A23, A29 | delete patient: visits and open orders are cancelled, images and reports are kept | ACK |
| ORM | O01 | new, change, cancel, hold, release order | ACK |
| OMI / OMG | O23 / O19 | same as ORM^O01 | ACK |
| ORU | R01, R30, R32 | outside reports (text, RTF, HTML, base64 PDF/Word) and lab results | ACK |
| SIU | S12 - S26 | appointments and blocked time | ACK |
| BAR | P01, P05, P12 / P06 | guarantor and insurance / deactivate insurance | ACK |
| DFT | P03, P11 | financial transactions, procedures, balance, authorization | ACK |
| MFN | M02 | staff master file, applied to referring physicians ([MFN](#mfn-inbound)) | ACK |
| MFN | M08, M13, M04 (and M02 whose MFI-1 names a procedure file: OMA, OMB, OMC, OMD, CDM, PRC, PROC, LMN, OM1) | procedure catalogue | ACK |
| QRY | A19 (also QBP^Q22 when it carries QRD/QRF) | patient demographics query | ADR^A19 |
| SQM | S25 | slot search (SSA) and booked/blocked time (SBK) | SQR^S25 |
| ACK | any | application acknowledgment of RADENVO's enhanced-mode messages | none |

Any other ADT, ORM, OMI, ORU, SIU, BAR, DFT or MFN event is rejected with error 201; any other message type with error 200.

### 1.2 Messages sent

| Message | Structure | Sent when |
|---|---|---|
| ADT^A04 | ADT_A01 | a patient is registered |
| ADT^A08 | ADT_A01 | name (incl. prefix, suffix, degree), sex, birth date, MRN, phone, email, address, alerts or emergency contact change |
| ADT^A40 | ADT_A39 | a patient is merged into another |
| ADT^A23 | ADT_A21 | a patient record is deleted |
| ORM^O01 (or OMI^O23) | ORM_O01 / OMI_O23 | order created (NW), status changed (SC), cancelled (CA), held / released (HD / RL), details changed (XO) |
| SIU^S12 / S14 / S15 / S17 | SIU_S12 | appointment booked / changed (time, room, status) / cancelled or no-show / deleted |
| DFT^P03 | DFT_P03 | a charge becomes ready for billing |
| BAR^P01 / P05 | BAR_P01 / BAR_P05 | an insurance policy is added / changed |
| ORU^R01 | ORU_R01 | report preliminary (P), final (F), or addended / re-signed after final (C) |
| MFN^M02 | MFN_M02 | a referring physician is added (MAD), changed (MUP), deactivated (MDC, delivery set to none), reactivated (MAC) or deleted (MDL) |
| MFN^M08 | MFN_M08 | a procedure-catalogue entry is added (MAD), changed (MUP: code, name, modality, duration or fee), deactivated (MDC), reactivated (MAC) or deleted (MDL) |
| ACK | ACK | application acknowledgment in enhanced mode ([section 3.2](#32-enhanced-mode)) |
| ADR^A19, SQR^S25 | | query responses on the same connection |

Outbound events are produced by database triggers and queued for every enabled outbound interface whose message-type filter matches (empty filter = all; `ORM` also matches an interface configured for `OMI`). MFN messages go only to interfaces whose filter lists `MFN` (or `MFN^M02` / `MFN^M08`) explicitly; an empty filter does not include them. Interfaces with option `is_ihe_image_manager` never receive ADT or BAR (they are not queued, and rows already queued are cancelled at delivery). Changes that were themselves made by an inbound HL7 message are **not** sent back out, unless the interface option `forward_inbound` is on.

A legacy per-organization result sender (organization settings `hl7_result_host` / `hl7_result_port`) also sends ORU^R01 v2.5 for signed reports and addenda; it can be disabled with `HL7_LEGACY_RESULTS=off`.

Not sent: VXU^V04, ADT A01/A02/A03 visit events, MDM.

---

## 2. Transports

| Transport | Inbound | Outbound |
|---|---|---|
| MLLP over TCP | `HL7_PORT` (default 2575); on by default when the gateway runs HL7; `HL7_PLAIN=off` closes the plaintext listener so only MLLP/TLS accepts connections | host and port per interface; ACK timeout 10 s (3 s for application ACKs) |
| MLLP over TLS | `HL7_TLS_PORT` with `HL7_TLS_CERT`/`HL7_TLS_KEY` (falls back to the DICOM TLS files); TLS 1.2 minimum; client certificates required when `HL7_TLS_CA` is set | per interface `tls`; remote verified against the interface's CA bundle (verification can be disabled with option `tls_insecure`); client certificate from `HL7_TLS_CLIENT_CERT`/`KEY` (or the DICOM client/server pair); TLS 1.2 minimum |
| HTTPS | `POST https://<host>/api/hl7/{interface id}` with `Authorization: Bearer <interface token>`; body = the raw message, at most 2 MB; response body = the ACK (or ADR/SQR), `text/plain; charset=UTF-8`. HTTP 401 for a wrong token, 413 too large, 400 empty | `POST <url>` with `content-type: text/plain; charset=UTF-8` and the interface's bearer token; 15 s timeout; the response body must contain an MSA segment |

- **Framing**: VT (0x0B) ... FS CR (0x1C 0x0D). Frames larger than 2,000,000 bytes close the connection.
- **Ordering**: messages on one MLLP connection are processed strictly in order. Outbound messages are delivered in order per interface.
**SFTP batch files**

| | Inbound | Outbound |
|---|---|---|
| Connection | SFTP (SSH) to the interface's host and port (default 22) with `sftp_username` and password and/or private key; when `options.sftp.host_fingerprint` (`SHA256:...`, OpenSSH form) is set the server key must match it; 15 s connect timeout | same |
| Files | the folder `options.sftp.inbound_dir` is polled every `poll_seconds` (default 30, minimum 2); files matching `file_pattern` (default `\.(hl7|txt|dat|batch|msg)$`, case-insensitive), skipping `.tmp`, `.part`, `.done`, `.error`; at most `max_files_per_poll` (default 50) per poll, in name order | all messages claimed for the interface in one dispatcher pass are written as **one** batch file `<file_prefix>_<timestamp>_<seq>_<random>.hl7` (prefix default `LUMEN`) in `outbound_dir`; uploaded as `.tmp`, then renamed |
| Format | an HL7 batch (FHS/BHS ... BTS/FTS) or a file of plain messages; envelope segments are dropped, a BTS count that differs from the messages found is logged; charset from the first message's MSH-18 | FHS, BHS (MSH-3..6 of the interface, file name in FHS-9), the messages, `BTS|<count>`, `FTS|1`; encoded in the interface charset |
| Processing | each message goes through the same inbound path as MLLP (tenant and interface = the polled interface; MSH-6 naming another organization is rejected with 204) | build failures mark that message as error; the rest of the batch is still written |
| Acknowledgment | when `ack_dir` is set, the responses are written there as a batch `ACK_<file name>.hl7` (sender and receiver swapped) | no ACK is read back; a written file marks its messages as sent (`batch_file` recorded). A failed upload retries every message of the batch with the usual back-off and retry limit |
| After processing | the file is moved to `archive_dir` (`.error` appended if any message failed), else deleted when `delete_after` is true and all succeeded, else renamed to `<name>.done` / `<name>.error`. If the move fails, polling of that folder stops for this round so the file is not read twice | |
| Several gateways | one gateway at a time owns an inbound folder (`hl7_sftp_claim` lock, 300 s); poll state, counters and last error per interface in `hl7_sftp_state` | |

`HL7_SFTP=off` disables the inbound poller on a gateway. Outbound SFTP rows are only claimed by gateways that support SFTP (`hl7_claim_outbound_v2`).

### 2.1 Tenant and interface resolution

- **MLLP**: the receiving facility (MSH-6) selects the organization: organization slug, then the organization's configured HL7 facility (must be unique), then a registered DICOM AE title. An unknown MSH-6 is rejected (AR, error 204). The inbound interface is the enabled MLLP interface whose sending-facility match equals MSH-4, else the one without a match.
- **HTTPS**: the interface (and therefore the organization) comes from the URL and token. MSH-6 naming a different organization is rejected (AR, error 204).
- **SFTP**: the interface (and organization) is the one whose folder was polled; the same MSH-6 check applies.
- An interface's message-type filter rejects other types (AR, error 200).

---

## 3. Acknowledgment

### 3.1 Original mode (default)

| MSA-1 | Meaning |
|---|---|
| AA | processed; MSA-3 "Request was Successfully processed" (or a short result text) |
| AE | processing error (database or internal error, conflicts); ERR segment included |
| AR | rejected (missing or invalid required data, unsupported message, unknown facility or resource); ERR segment included |

MSA-2 echoes MSH-10. The ACK's MSH swaps sending and receiving application/facility, keeps the inbound version (MSH-12) and processing ID, and echoes MSH-18 when present.

**ERR segment**: for versions 2.0 - 2.4, `ERR|^^^<code>&<text>`; for 2.5 and later, ERR-2 location, ERR-3 `<code>^<description>^HL70357`, ERR-4 `E`, ERR-8 text.

| Code | Meaning (HL7 table 0357) | Typical cause |
|---|---|---|
| 100 | Segment sequence error | MSH, PID, MRG, ORC/OBR, OBR, SCH, MFE or QRD segment missing |
| 101 | Required field missing | PID-3.1, MRG-1.1, accession (OBR-18.1 / OBR-3), MFE-1, STF-3, ZLI-1 (when ZLI is sent), STF-4 (option `require_staff_role`), procedure code OM1-2 / MFE-4 and name (new procedures), appointment start, blocked-time duration, QRD-8, QRD-10, QRF-1, APR-2, PV1-46 (DFT) |
| 102 | Data type error | invalid date of birth in QRF-5, end before start, unsupported QRD-2/QRD-3 |
| 103 | Table value not found | unknown QRD-9 query filter |
| 200 | Unsupported message type | |
| 201 | Unsupported event code | |
| 204 | Unknown key identifier | unknown facility, resource (room), study type, or order for HD/RL |
| 205 | Duplicate key identifier | accession belongs to another patient, signed report UID already exists, slot conflict |
| 207 | Application internal error | database or unexpected error |

### 3.2 Enhanced mode

Used when the inbound interface is set to enhanced acknowledgment, or when MSH-15 is present.

- The commit acknowledgment on the connection uses CA / CE / CR.
- An application acknowledgment (AA / AE / AR) is queued as a separate ACK message to the interface's return interface (option `return_interface_id`, else the first enabled outbound interface that lists `ACK`), as MSH-16 requests: AL always, ER only on error, SU only on success, NE never. When MSH-16 is empty and the interface is enhanced, AL is assumed.
- Outbound interfaces in enhanced mode send MSH-15 `AL` and MSH-16 `NE`.

### 3.3 Duplicates

A message whose MSH-10, MSH-3 and MSH-4 match a message already processed successfully for the same organization is not processed again; the original response is returned and the message is logged as a duplicate.

### 3.4 Outbound retries

| Remote response | RADENVO behavior |
|---|---|
| AA or CA | sent |
| AE or CE | error, not retried (RamSoft semantics) |
| AR, CR, other, no ACK, network error | retried with back-off (5 s, doubling, up to 10 min) until the interface's retry limit (default 50), then error |
| ACK message without a reply | treated as sent |

Administrators can retry or cancel an outbound message, reprocess an inbound message after fixing configuration, and queue a hand-written test message. Every message, in and out, is logged with its raw text, acknowledgment, status and error.

---

## 4. Character sets and time

### 4.1 Character sets (MSH-18)

| MSH-18 | Decoding |
|---|---|
| (empty), ASCII, UNICODE UTF-8, UTF-8, UNICODE, ISO IR192 | UTF-8; a message declared or assumed UTF-8 that is not valid UTF-8 is read as ISO 8859-1 |
| 8859/1, ISO IR100 | ISO 8859-1 |
| 8859/2, ISO IR101 | ISO 8859-2 |
| 8859/3, 8859/4, 8859/5 (ISO IR144), 8859/6, 8859/7, 8859/8, 8859/9, 8859/15 | corresponding ISO 8859 part |
| WINDOWS-1252, CP1252 | Windows-1252 |
| anything else | UTF-8 |

Responses are encoded in the charset of the request. Outbound messages use the interface's charset (default UTF-8, MSH-18 `UNICODE UTF-8`); for single-byte charsets, characters outside Latin-1 are sent as `?`.

Escape sequences: `\F\ \S\ \T\ \R\ \E\` are decoded, `\.br\` and `\.sp\` become line breaks, `\Xhh\` is decoded (CR/LF codes become line breaks), formatting commands (`\H\ \N\ \.fi\ \.nf\ \.in\ \.ti\ \.sk\ \.ce\`) are dropped. Outbound text escapes the delimiters and encodes line breaks as `\.br\`.

### 4.2 Time stamps

Inbound TS/DTM values honor a `+/-ZZZZ` offset; without an offset they are read as local time of the interface time zone (option `timezone`), else of the organization's first facility, else UTC. Outbound time stamps carry the offset of that time zone (`yyyyMMddHHmmss+ZZZZ`). Appointments use the room's facility time zone.

---

## 5. Inbound processing

### 5.1 Patient identification

- **Identifiers**: every PID-3 repetition (3.1 value, 3.4 assigning authority, 3.5 identifier type) plus PID-2. A missing assigning authority defaults to the interface option `default_issuer`, else MSH-4, else `UNKNOWN`.
- The patient is found by issuer-qualified identifier first, then by MRN. The same number from a different assigning authority is treated as a different patient (stored as `<value>^<issuer>`).
- The primary identifier is the first PID-3 repetition of type MR, else the first one.
- **ADT and BAR** are the registration source: they create the patient and overwrite demographics; an HL7 null (`""`) in PID-11 or PID-13 clears the address or phone. **Orders, results and scheduling** create the patient if needed but only fill blank demographics (ORM can be set to overwrite with option `orders_update_demographics`).
- A11, A12, A13 and A38 can be prevented from creating a patient with option `no_create_on_cancel`.

### 5.2 Segment and field usage (inbound)

R = required (message rejected without it), O = used when present.

**PID**

| Field | Use |
|---|---|
| PID-2 | secondary identifier (O) |
| PID-3 | identifiers, all repetitions: 3.1, 3.4, 3.5 (R: PID-3.1) |
| PID-5 | names, all repetitions: 5.1 family, 5.2 given, 5.3 middle, 5.7 type; type L (or the first) is the record name, others are aliases. 5.4 suffix, 5.5 prefix and 5.6 degree of the record name are stored |
| PID-7 | date of birth |
| PID-8 | sex (M, F, O, U, A, N) |
| PID-11 | address (11.1 - 11.6) |
| PID-13 | phone (13.1, or 13.6 + 13.7, or 13.12) and e-mail (13.4 or a value containing @) |

**PV1 / PV2 / DG1 / PRB / EVN** (ADT)

| Field | Use |
|---|---|
| PV1-2 | patient class (default O) |
| PV1-3 | location (3.1 - 3.4); 3.4 also names the facility for orders |
| PV1-7 / PV1-8 | attending / referring physician |
| PV1-9 | consulting physicians, all repetitions (orders: stored on the order) |
| PV1-10 | hospital service |
| PV1-19 | visit number (visit key) |
| PV1-44 / PV1-45 | admit / discharge date-time (A03 falls back to EVN-2) |
| PV1-46 | patient balance (required in DFT unless option `dft_balance_optional`) |
| PV2-3 / PV2-8 | admit reason / expected admit date-time |
| DG1-3, DG1-6 | diagnoses on the visit; ICD-10 codes also on orders |
| PRB-1 / PRB-3 | problems on the visit: merged by code (PRB-1 AD/UP add or update, DE removes); with option `delete_problem_codes` the message's list replaces the stored one |
| ACC-1 / ACC-2 / ACC-4 / ACC-5 | accident date-time, type code (AUTO, EMP, OTH), state, job-related indicator: stored on the patient (latest), on the visit and on the order |
| NK1 with NK1-7 = `C` | emergency contact: NK1-2 name, NK1-3 relationship (SEL, SPO, CHD, PAR, else OTH), NK1-4 address, NK1-5 phone; stored on the patient (ADT and orders) |

Visit status by event: A01, A02, A13 admitted; A03 discharged; A04 registered; A05, A14 preadmit; A11, A38 cancelled.

**AL1, OBX (patient level), GT1, IN1, AUT**

| Segment / field | Use |
|---|---|
| AL1-3 (3.2 or 3.1), AL1-4 (SV, MO, MI, U), AL1-5 (repeats) | allergy alert line added to the patient's alerts (no duplicates) |
| OBX with OBX-3 BODY HEIGHT or LOINC 8302-2 | height, stored in cm (OBX-6 M, CM, IN; unknown unit = cm) |
| OBX with OBX-3 BODY WEIGHT or LOINC 29463-7 | weight, stored in kg (KG, LB, G; unknown unit = kg) |
| OBX with coding system LN/LOINC or type NM, SN, ST, CE, CWE | patient observation: code, system, name, value, units (OBX-6), reference range (OBX-7), abnormal flags (OBX-8), status (OBX-11), time (OBX-14) |
| GT1-3, 5, 6/7, 8, 9, 11, 16 | guarantor (one per patient) |
| IN1-1 | coverage level 1 - 3, with positional activation rules: first IN1 sets primary/secondary/tertiary from IN1-1; later IN1s become active only in sequence; others are stored inactive. Active policies not in the message are deactivated |
| IN1-3 / IN1-4 / IN1-8 | payer ID / payer name / group number |
| IN1-12 / IN1-13 | coverage start / end |
| IN1-16 / IN1-17 | subscriber name / relationship (SEL, SPO, CHD, PAR, EME, other) |
| IN1-49, IN1-36, IN1-2.1 | member ID (first present) |
| IN1-14.1 / IN1-14.2 | authorization number / date when AUT is absent |
| AUT-4 / AUT-5 / AUT-6 | authorization start / end / number (order) |

ADT applies IN1 unless option `adt_insurance` is false. NK1 segments with a contact role other than `C` are ignored.

**MRG** (merge events)

| Field | Use |
|---|---|
| MRG-1 (1.1 value, 1.4 issuer), fallback MRG-4 | prior patient (R: MRG-1.1 or MRG-4.1) |
| MRG-3 | account (visit) to move for A44 |

Behavior: if both patients exist they are merged (prior into survivor; studies, orders and documents move). If only the prior exists, it takes the new identifier (A47-style identifier change). If the prior does not exist, the survivor is registered. A44 moves the named visit, or the prior patient's open orders, to the survivor.

**ORC / OBR / IPC / TQ1 / NTE / ZDS / ZVI** (orders)

| Field | Use |
|---|---|
| ORC-1 | order control: NW, XO, XX, RO, SC, SN (create or update); CA, OC, DC, OD, DR, CR (cancel); HD / RL (hold / release); OK, UA, UC, UD, UF, UH, UM, UN, UR, UX, XR, OR, CH (acknowledged, no change) |
| ORC-5 (or OBR-25) | order status with SC/SN: SC scheduled, IP and A arrived, CM completed, CA and DC cancelled |
| ORC-2 / OBR-2 | placer order number |
| ORC-3 / OBR-3 | filler number; accession fallback |
| ORC-7.4 / ORC-7.6 | scheduled time / priority |
| ORC-12 | ordering provider (fallback for referrer) |
| ORC-17 (17.2 or 17.1) | facility name |
| OBR-4 (4.1 code, 4.2 text), OBR-44 | procedure code and description, matched to the procedure catalogue |
| OBR-5, OBR-27.6, TQ1-9 | priority: S and C stat, A urgent, R, T, P routine |
| OBR-7, OBR-27.4, OBR-36, TQ1-7 | scheduled date-time (OBR-36 first) |
| OBR-12 (12.1 or 12.2) | danger code, stored on the order; a single-letter priority code (S, A, C, R, T, P) is read as priority instead |
| OBR-13 | clinical notes; indication (fallback). With option `append_clinical_notes` appended to the stored indication |
| OBR-15 (15.4 or 15.1) | body part |
| OBR-16 | referring physician (16.1 NPI when 10 digits, 16.2 family, 16.3 given) |
| OBR-18 | accession number; **each repetition creates a separate order** (option `accession_field = OBR-3` uses OBR-3 instead) |
| OBR-24 | modality |
| OBR-31 | reason for exam: ICD-10 codes (all repetitions), 31.2 text (symptoms; appended with option `append_symptoms`) |
| IPC-1 / IPC-3 / IPC-5 / IPC-9 | accession / Study Instance UID / modality / scheduled station AE title (OMI) |
| NTE-3 | order notes (appended to the stored notes with option `append_comments`) |
| OBX in the order group | height, weight and observations linked to the order |
| ZDS-1 | Study Instance UID (1.1 UID, 1.4 `DICOM`); handed to the modality worklist and used to link an existing study |
| ZVI-1 / ZVI-2 / ZVI-3 | DLP / CTDIvol / effective dose |
| DG1-3 | ICD-10 diagnoses |

Several ORC/OBR groups in one message are processed one by one. A message with only ORC cancels may omit PID. An accession that already belongs to another patient is rejected (AE, 205). A cancelled order that receives NW, XO, XX, RO or SC is reinstated. A completed order is not moved back by a status update.

**ORU^R01** (results)

| Field | Use |
|---|---|
| OBR-18 / OBR-3 | accession (R for reports) |
| OBR-4 | report title |
| OBR-25, OBX-11 | result status P, F, C, A |
| OBX-2 TX, FT, ST and others | report text; all OBX-5 repetitions; inline RTF is converted to text and the RTF kept as the document; HTML is kept as HTML. Option `report_content_type` TXT or HTML sets the text type |
| OBX-2 ED | OBX-5.3 subtype (PDF, DOC, DOCX, RTF, TIF), OBX-5.5 base64 data: stored as the document; RTF and DOCX text is extracted. Without a subtype, option `report_content_type` (PDF, DOC, DOCX, DOCM, JPG, TIFF, RTF, or RamSoft codes 1-9) decides, default PDF |
| OBX-2 RP | link stored as text |
| OBX-3.1 | a UID (four or more dot-separated numbers) is the report UID |
| OBX-14 / OBX-16 | observation time / observer |
| NTE-3 | notes prepended to the text |
| MSH-4 | source facility |

Reports are filed as outside reports linked to the order and study with that accession. With option `file_outside_as_prior`, a report without a matching study creates a read-only outside prior study (no accession, never on a reading list). A second final report with the same report UID is rejected (205) unless the earlier one was preliminary, the new one is C or A, or option `allow_duplicate_signed` is on. Lab results (OBX coded LN/LOINC, or SPM with specimen data) are stored as patient observations.

**SIU** (scheduling)

| Field | Use |
|---|---|
| SCH-1 / SCH-2 | placer / filler appointment ID (external ID) |
| SCH-6 / SCH-7 | event reason / appointment reason (blocked-time reason) |
| SCH-9 / SCH-10 | duration and units (fallback) |
| SCH-11 | timing: 11.2 interval (Q<n>D, W, M, Y, L for recurring blocked time), 11.3 duration, 11.4 start, 11.5 end |
| SCH-15 (15.2 room, 15.4 facility) | fallback resource |
| SCH-20 | `Y` = blocked time |
| SCH-25, AIS-10 | filler status: PENDING, WAITLIST booked; BOOKED, OVERBOOK confirmed; STARTED, ARRIVED arrived; COMPLETE completed; CANCELLED, DC, DELETED cancelled; NOSHOW no-show; BLOCKED = blocked time |
| SCH-26 / SCH-27 | accession (creates the order when it does not exist) |
| AIS-3 | procedure code and name (unknown codes are added to the catalogue) |
| AIS-4 / AIS-7 / AIS-8 | start / duration / units |
| AIL-3 (3.1, 3.2, 3.4 facility), AIG-3, RGS-3 | room, matched by name or station AE (R: an existing room, else AR 204) |
| NTE-3 | notes |

S15, S16, S17 cancel; S26 marks no-show. Bookings that overlap another appointment or blocked time in the same room are refused (AE, 205). Recurring blocked time is expanded into at most 400 occurrences, keeping local wall-clock time across daylight-saving changes.

**BAR / DFT / FT1 / PR1**

| Field | Use |
|---|---|
| BAR P01, P05, P12 | patient (overwrite), GT1, IN1 |
| BAR P06 | deactivate all active insurance |
| FT1-4.1 / FT1-6 | transaction date / type |
| FT1-7.1, FT1-25.1 | procedure (CPT) code |
| FT1-10 / FT1-11 | quantity / amount |
| FT1-19 | diagnosis codes (repeats) |
| FT1-20 / FT1-21 | performing / ordering physician (fallback PV1-7 / PV1-8); referring physician filled on the study when empty |
| FT1-23 | accession |
| FT1-26 | modifiers (repeats) |
| PR1-3, 5, 11/12, 15, 16 | procedure code, date, surgeon, diagnosis, modifiers |
| AUT | authorization applied to the order with the FT1-23 accession |

<a id="mfn-inbound"></a>**MFN^M02 (staff)**

| Field | Use |
|---|---|
| MFI-1 | selects the master file: a procedure file identifier (OMA, OMB, OMC, OMD, CDM, PRC, PROC, LMN, OM1) routes the message to the procedure catalogue below; anything else is the staff file |
| MFE-1 | MAD, MUP, MAC (activate, portal delivery), MDL / MDC (deactivate) (R) |
| MFE-4.1 | NPI when 10 digits |
| STF-2 | identifiers; one typed NPI is used |
| STF-3 | name (R for new records) |
| STF-4 | staff type; required (except MDL) only with option `require_staff_role` |
| STF-10 / STF-15 | phone / e-mail |
| PRA-6 | practitioner ID; type NPI is used |
| ZLI-1 | user name; when a ZLI segment is sent, an empty ZLI-1 rejects the message (101). The value is not otherwise used |

Records are applied to RADENVO's **referring physician** directory, matched by NPI then name. Staff user accounts and logins are not created or changed by MFN.

**MFN^M08 / M13 / M04 (procedure catalogue)**

| Field | Use |
|---|---|
| MFE-1 | MAD / MUP add or update (MAD and MAC activate), MDC / MDL deactivate (procedures are never deleted) (R) |
| OM1-2 (2.1 code, 2.2 name), else MFE-4, else CDM-1 / CDM-3 | procedure code (R) and name (R for new procedures) |
| ZPR-1 or OM1-6 | modality |
| ZPR-2 / ZPR-3 (or CDM-12) | duration in minutes / fee |
| OM1-47 | `I` deactivates |

### 5.3 Queries

**QRY^A19 → ADR^A19** (QRD-2 `R`, QRD-3 `I`, QRD-9 `DEM` required)

| Field | Use |
|---|---|
| QRD-7 | quantity limit (default 50, max 500) |
| QRD-8 | 8.1 patient ID, 8.2 family name (prefix), 8.3 given name; family name or ID required |
| QRF-5 | date of birth |

Response: MSH, MSA, the QRD and QRF echoed, one PID per match (PID-3 `MRN^^^issuer`, PID-5 family^given^middle, PID-7, PID-8), and `ZDS|TOTAL_MATCHES|<n>` when there are matches. Merged patients are excluded. Errors return MSA AE/AR with ERR.

**SQM^S25 → SQR^S25** (QRD-2 `R`, QRD-3 `I`)

| Field | Use |
|---|---|
| QRD-4 | query ID, echoed in QAK-1 |
| QRD-9 | SSA (free slots) or SBK (booked and blocked time) |
| QRD-10 | study type (procedure code), required for SSA |
| QRF-1 | facility name (R) |
| QRF-9.4 / QRF-9.5 | window start / end; the start is never in the past; window capped at 7 days (SSA) or 5 days (SBK) |
| APR-2 | room name (required for SBK) |

SSA response: up to 100 slots in rooms of the procedure's modality at that facility, from room opening hours minus appointments and blocked time, each as SCH (SCH-11 with duration, start, end and display times, SCH-19 facility), RGS (room) and AIL (start, UTC offset, duration). SBK response: SCH and RGS for the room, one AIS per blocked time (start^end, offset, duration, recurrence and reason) and one AIL per booked appointment. QAK-2 is OK or NF.

---

## 6. Outbound messages

### 6.1 MSH

| Field | Value |
|---|---|
| MSH-3 / MSH-4 | interface sending application (default `LUMEN`) / sending facility (default organization name) |
| MSH-5 / MSH-6 | interface receiving application / facility |
| MSH-7 | time with UTC offset |
| MSH-9 | type^event^structure |
| MSH-10 | `LMN<message id>` |
| MSH-11 | P |
| MSH-12 | interface version (default 2.5) |
| MSH-15 / MSH-16 | AL / NE in enhanced mode, else empty |
| MSH-18 | interface charset label |

### 6.2 Segments by message

| Message | Segments |
|---|---|
| ADT^A04, A08 | MSH, EVN, PID, PV1, AL1 (one per allergy alert), [DG1 from the latest visit, `send_dg1`], [NK1, `send_nk1`], [GT1, IN1 with option `send_insurance`], [ACC, `send_acc`] |
| ADT^A40 | MSH, EVN, PID (survivor), MRG (prior MRN in MRG-1 and MRG-4), PV1, AL1, [DG1], [NK1], [GT1, IN1], [ACC] |
| ADT^A23 | MSH, EVN, PID (snapshot of the deleted patient) |
| ORM^O01 | MSH, [EVN, `send_evn`], PID, [NK1], PV1, ORC, OBR, [NTE], [DG1, `send_dg1`], [OBX height/weight, `send_height_weight`], [ACC], [PR1, AUT, ZVI by option], ZDS, [GT1, IN1] |
| OMI^O23 | MSH, [EVN], PID, [NK1], PV1, ORC, TQ1, OBR, [NTE], [DG1], [OBX height/weight], [ACC], [PR1, AUT, ZVI], IPC, [GT1, IN1] |
| SIU^S12/S14/S15/S17 | MSH, SCH, PID, PV1, RGS, AIS, AIL, [NTE] |
| DFT^P03 | MSH, EVN, PID, PV1 (PV1-46 balance), FT1, DG1 (one per ICD-10), [PR1, AUT, ZVI], GT1, IN1 (unless `send_insurance` is false) |
| BAR^P01/P05 | MSH, EVN, PID, PV1, GT1, IN1 |
| ORU^R01 | MSH, [EVN, `send_evn`], PID, PV1, ORC, OBR, [DG1, `send_dg1`], [OBX height/weight, `send_height_weight`], OBX..., [PR1, AUT, ZVI], ZDS |
| MFN^M02 | MSH, MFI (`PRA`, UPD, NE), MFE (event, NPI or id^name, CE), STF (STF-4 `REFERRING PHYSICIAN`, STF-7 A/I, phone, fax, e-mail), PRA (practice, NPI) |
| MFN^M08 | MSH, MFI (`OMA`), MFE, OM1 (OM1-2 `code^name^<coding system>`, default CPT-4, option `procedure_coding_system`; OM1-6 modality; OM1-47 A/I), ZPR (modality, minutes, fee) |

### 6.3 Field usage

| Segment | Fields sent |
|---|---|
| PID | 1; 2 `MRN^^^issuer^MR`; 3 MRN (type MR) plus other identifiers (type PI), repeating; 5 legal name (family^given^middle^suffix^prefix^degree) and aliases; 7; 8; 11 address (one component); 13 `phone^^^email` |
| PV1 | 1; 2 patient class (default O); 3 `^^^location`; 7 attending; 8 referring; 9 consulting physicians (ORM/OMI/ORU; at most `max_consulting_physicians`, default 50); 19 visit number; 46 balance (DFT) |
| NK1 (option `send_nk1`) | 1; 2 name; 3 relationship; 4 address; 5 phone; 7 `C^Emergency Contact` |
| ACC (option `send_acc`) | 1 accident time; 2 type code (default OTH); 4 state; 5 job related Y/N |
| OBX height/weight (option `send_height_weight`) | ST OBX, OBX-3 `^BODY HEIGHT` in m / `^BODY WEIGHT` in kg, latest values |
| EVN | 1 event; 2 time |
| AL1 | 1; 3 `^allergen`; 4 SV, MO, MI; 5 reaction |
| GT1 | 1; 3 name; 5 address; 6 phone; 8 birth date; 9 sex; 11 relationship (SEL when the patient is the guarantor); 16 employer |
| IN1 | 1 level (empty for inactive); 2 and 3 payer ID; 4 payer name; 8 group; 12 / 13 coverage dates; 16 subscriber; 17 relationship (SEL, SPO, CHD, PAR, OTH); 36 and 49 member ID. Inactive policies only with option `send_inactive_insurances` |
| ORC | 1 order control (NW, SC, CA, HD, RL, XO; RE in ORU); 2 placer number; 3 accession; 5 status (SC, IP, CM, CA, HD; CM in ORU); 7 `^^^start^^priority` (ORM); 9 time; 12 referring |
| TQ1 (OMI) | 1; 7 start; 9 priority |
| OBR | 1; 2 placer; 3 accession; 4 code^description; 5 priority S, A, R (ORM); 7 scheduled or study time; 12 danger code (ORM: priority when no danger code; ORU: danger code only); 13 indication; 15 `^^^body part`; 16 referring; 18 accession; 22 signed time (ORU); 24 modality; 25 result status (F when completed in ORM; P, F, C in ORU); 27 timing (ORM); 31 ICD-10 codes `code^^I10` (repeats) or indication; 32 principal result interpreter (ORU); 36 scheduled time; 44 procedure |
| OBX (ORU) | default: one TX OBX per report line, OBX-3 `SECTION^SECTION` (TECHNIQUE, COMPARISON, FINDINGS, IMPRESSION, RECOMMENDATIONS, ADDENDUM), OBX-4 line number, OBX-11 status, OBX-14 signed time, OBX-16 signer. Option `obx_mode = ft`: one FT OBX with the whole report. Critical result: `OBX|n|ST|^CRITICAL||Y`. Option `report_link_base`: RP OBX with a link to the study. Option `embed_pdf`: ED OBX `^AP^PDF^Base64^<data>` with a text PDF of the report. Option `send_entire_report = false`: a corrected (C) result whose report has an addendum carries only the addendum text OBX |
| IPC (OMI) | 1 / 2 / 4 accession; 3 `StudyUID^^Application^DICOM`; 5 modality; 9 scheduled station AE |
| SCH | 1 accession or appointment ID; 2 external ID; 6 `^Scheduled`; 11 `1^^duration^start^end^R`; 16 referring; 20 N; 25 status (BOOKED, STARTED, COMPLETE, CANCELLED, NOSHOW, DELETED); 26 / 27 accession |
| RGS | 1; 3 room |
| AIS | 1; 3 procedure code^name; 4 start; 5 0; 6 min; 7 duration; 8 min; 10 status |
| AIL | 1; 3 `^room^^facility`; 6 start; 9 duration; 10 min; 12 status |
| FT1 | 1; 2 charge ID; 4 service date; 5 posting time; 6 CG; 7 `CPT^^CPT-4`; 8 description; 10 units; 11 extended amount; 12 unit fee; 19 ICD-10 (repeats); 20 rendering NPI; 21 referring (NPI^name); 23 accession; 25 CPT; 26 modifiers |
| DG1 | DFT: 1; 2 I10; 3 `code^^I10`; 6 F. ORM/ORU (`send_dg1`): order ICD-10 codes, DG1-6 W. ADT (`send_dg1`): latest visit diagnoses with their system and type |
| PR1 (option `send_pr1`) | 1; 2 CPT-4; 3 code^description^CPT-4; 4; 5 date; 6 D; 15 ICD-10; 16 modifiers |
| AUT (option `send_aut`) | 4 start; 5 end; 6 number |
| ZDS | 1 `StudyInstanceUID^RAMSOFT^Application^DICOM` |
| ZVI (option `send_zvi`) | 1 DLP (mGy·cm); 2 CTDIvol (mGy); 3 effective dose (mSv) |

Order Study Instance UID: the UID received with the order, else the study's UID, else `2.25.<order UUID>` (the same UID the modality worklist hands out).

---

## 7. Z-segments

| Segment | Direction | Fields |
|---|---|---|
| ZDS | in (ORM, OMI, ORU) and out (ORM, ORU) | ZDS-1: Study Instance UID^RAMSOFT^Application^DICOM. Inbound only component 1 (a dotted UID) and 4 (`DICOM` or empty) are checked |
| ZDS (query) | out (ADR^A19) | `ZDS|TOTAL_MATCHES|<n>` |
| ZVI | in (ORM) and out (option) | ZVI-1 DLP, ZVI-2 CT dose index (CTDIvol), ZVI-3 effective dose |

| ZPR | in (MFN procedure catalogue) and out (MFN^M08) | ZPR-1 modality, ZPR-2 duration (minutes), ZPR-3 fee |
| ZLI | in (MFN^M02) | ZLI-1 must not be empty when ZLI is sent; otherwise not used |

Other Z-segments are ignored.

---

## 8. Interface configuration

| Setting | Values |
|---|---|
| Direction, enabled | inbound / outbound |
| Transport | mllp, https or sftp; host, port, TLS and CA bundle (MLLP); URL and bearer token (outbound HTTPS); token hash (inbound HTTPS, token issued by RADENVO); host, port, `sftp_username`, `sftp_password` / `sftp_private_key` and `options.sftp` (`inbound_dir`, `outbound_dir`, `ack_dir`, `archive_dir`, `poll_seconds`, `file_pattern`, `max_files_per_poll`, `delete_after`, `file_prefix`, `host_fingerprint`) for SFTP |
| Message types | filter list, e.g. `ADT`, `ADT^A08`, `ORM`, `ORU`; empty = all |
| MSH-3 to MSH-6 | sending application (default LUMEN), sending facility, receiving application, receiving facility |
| Match sending facility | inbound MLLP: MSH-4 value that selects this interface |
| HL7 version | default 2.5 (outbound) |
| Charset | default UTF-8 |
| Acknowledgment mode | original or enhanced |
| Retry limit | default 50 (0 - 1000) |

Interface options:

| Option | Direction | Effect |
|---|---|---|
| `timezone` | both | time zone for times without an offset |
| `default_issuer` | both | assigning authority when PID-3.4 is empty, and for outbound PID |
| `no_create_on_cancel` | in | A11, A12, A13, A38 do not create patients |
| `orders_update_demographics` | in | ORM/OMI overwrite demographics |
| `accession_field` | in | `OBR-3` to take the accession from OBR-3 |
| `allow_duplicate_signed` | in | accept a second final report with the same UID |
| `file_outside_as_prior` | in | outside reports without a study create an outside prior |
| `adt_insurance` | in | false: ADT does not apply IN1 |
| `dft_balance_optional` | in | DFT without PV1-46 accepted |
| `return_interface_id` | in | where enhanced-mode application ACKs go |
| `append_symptoms`, `append_clinical_notes`, `append_comments`, `append_delimiter` | in | append OBR-31 symptoms / OBR-13 clinical notes to the stored indication, NTE comments to the stored notes, instead of replacing them (delimiter default newline; text already present is not repeated) |
| `report_content_type` | in | content type of inbound ORU reports: TXT, HTML (text) or PDF, DOC, DOCX, DOCM, JPG, TIFF, RTF (ED without subtype); RamSoft numeric codes 1-9 accepted |
| `delete_problem_codes` | in | PRB list in the message replaces the stored problem list |
| `require_staff_role` | in | MFN^M02 rejected without STF-4 |
| `forward_inbound` | out | also send changes made by inbound HL7 |
| `send_insurance`, `send_inactive_insurances` | out | GT1/IN1 in ADT and ORM (DFT sends them unless `send_insurance` is false) |
| `order_message` | out | `OMI` to send OMI^O23 instead of ORM^O01 |
| `obx_mode` | out | `ft` for one FT OBX |
| `embed_pdf` | out | add an ED OBX with a PDF |
| `report_link_base` | out | add an RP OBX with a link |
| `send_pr1`, `send_aut`, `send_zvi` | out | optional segments |
| `send_evn`, `send_dg1`, `send_height_weight`, `send_nk1`, `send_acc` | out | EVN in ORM/OMI/ORU; DG1 in ADT/ORM/ORU; height/weight OBX in ORM/OMI/ORU; NK1 emergency contact; ACC accident |
| `max_consulting_physicians` | out | PV1-9 repetition limit (default 50) |
| `send_entire_report` | out | false: corrected results with an addendum send only the addendum |
| `is_ihe_image_manager` | out | IHE Image Manager receiver: ADT and BAR are not sent |
| `procedure_coding_system` | out | coding system in MFN^M08 OM1-2 (default CPT-4) |
| `tls_insecure` | out | do not verify the remote certificate (MLLP/TLS) |

---

## 9. Security

- MLLP/TLS (TLS 1.2+, optional mutual TLS) inbound and outbound; HTTPS with per-interface bearer tokens (stored as SHA-256 hashes, compared in constant time) inbound, bearer tokens outbound.
- The plain MLLP listener (default 2575) is unencrypted and on by default; set `HL7_PLAIN=off` to close it so that only MLLP/TLS (`HL7_TLS_PORT`) and HTTPS accept messages. Otherwise keep it on a trusted network or tunnel it.
- SFTP: SSH transport; pin the server with `options.sftp.host_fingerprint` (without it, any host key is accepted). The SFTP password and private key are stored in the interface row (`sftp_password`, `sftp_private_key`), readable by the gateway's service-role connection.
- Every message is logged with its raw text in the tenant's HL7 message log (admin-only). Admin actions on messages are written to the audit log.
- The gateway's HL7 component still uses the database service-role key; it does not run when the gateway is configured with only a scoped gateway token.

---

## 10. Known limitations

1. Inbound MFN^M02 updates RADENVO's referring-physician directory, not RADENVO user accounts or logins; ZLI content is only checked for an empty ZLI-1. Outbound MFN^M02 is a physician master built from referring physicians, not from staff users.
2. SFTP batches are file transfers only: outbound files are not acknowledged by the receiver (a written file counts as delivered), and inbound batches are not checked for duplicate files beyond moving each processed file out of the poll folder (per-message MSH-10 duplicate detection still applies). No FTP/FTPS.
3. QBP^Q22 is answered only when it carries QRD/QRF (no QPD/RCP support).
4. PV1-9 consulting physicians are stored on orders only (not on ADT visits) and sent only in ORM/OMI/ORU.
5. HL7 does not run on a gateway configured with only a scoped gateway token: the HL7 component still needs the database service-role key.
6. The plain MLLP listener is on by default; TLS-only operation needs `HL7_PLAIN=off` and an `HL7_TLS_PORT` certificate.
