Skip to content

HL7

Split, validate, and pull fields out of HL7 v2.x clinical messages such as ADT and ORU feeds

Connector software
Free and open source
Service credentials
Not needed
Use with an agent

Install the Orchard skill in your project to help your agent find connectors, configure them, and verify SQL results.

npx skills add Query-farm/vgi-skills --skill orchard

Copy this request into your coding agent to get started.

Use https://query.farm/products/orchard/connectors/hl7/index.md to help me query HL7 with DuckDB or Haybarn 2.0.1 and VGI protocol 3.4. Ask only for missing details about the result I need or whether I want local execution, self-hosting or Query Farm hosting. Check the connector's actual hosting availability, credentials and input requirements. Read one format of each needed reference and the exact object declarations before writing SQL. Use a released connector, and distinguish a saved example result from anything you actually execute. If you cannot run the query, tell me what remains to verify.

Read an HL7 admission message as SQL rows

Example output · captured
Connector release
v0.5.0
Engine
2.0.1
VGI protocol
3.4.0
SELECT seq, segment, field_count
FROM hl7.main.hl7_segments(E'MSH|^~\\&|SENDING_APP|SENDING_FAC|RECV_APP|RECV_FAC|20240101120000||ADT^A01|MSG00001|P|2.5\rEVN|A01|20240101120000\rPID|1||10001^^^HOSP^MR||Doe^John||19800101|M\rPV1|1|I')
ORDER BY seq
Result
seq segment field_count
1 MSH 12
2 EVN 2
3 PID 8
4 PV1 2

Quick start

Choose where to run HL7, then follow the steps below.

The connector runs alongside DuckDB or Haybarn. No Query Farm account is needed.

1. Install the vgi extension

Run this in your SQL client. On DuckDB, keep FROM query_farm on LOAD in later sessions.

setup.sql
SET allow_extension_repositories = 'allowed';

CREATE EXTENSION REPOSITORY IF NOT EXISTS query_farm
    WITH PREFIX 'https://duckdb-extensions.query.farm';

INSTALL vgi FROM query_farm;
LOAD vgi FROM query_farm;

2. Attach the connector

Attach the signed image

Needs Docker, Podman or another OCI runtime. The extension runs the container and talks to it over stdio.

ATTACH 'hl7' AS hl7 (
  TYPE vgi,
  LOCATION 'oci://ghcr.io/query-farm/vgi-hl7:0.5.0'
);

3. Run a query

query.sql
SELECT seq, segment, field_count
FROM hl7.main.hl7_segments(E'MSH|^~\\&|SENDING_APP|SENDING_FAC|RECV_APP|RECV_FAC|20240101120000||ADT^A01|MSG00001|P|2.5\rEVN|A01|20240101120000\rPID|1||10001^^^HOSP^MR||Doe^John||19800101|M\rPV1|1|I')
ORDER BY seq
More example queries →
Technical details
Verified connector release
v0.5.0
Engine
2.0.1
VGI protocol
3.4.0
Verified on
December 1, 2026
Release notes on GitHub
Pin a version for production

When running the connector yourself, keep a specific release until you’re ready to upgrade. Replace the ATTACH statement above with this one and follow the same extension and credential setup.

Attach the signed image

Needs Docker, Podman or another OCI runtime. The extension runs the container and talks to it over stdio.

ATTACH 'hl7' AS hl7 (
  TYPE vgi,
  LOCATION 'oci://ghcr.io/query-farm/vgi-hl7:0.5.0'
);

Overview

HL7 v2.x clinical message parsing (pure-Java, no HAPI)

Catalog

Everything hl7 exposes once attached — read straight from the worker's released build.

hl7 1 schema
main 1 view · 7 functions

HL7 v2.x message-parsing functions.

Schema examples (9)
Examples (9)

Split an admit message into its segments, in message order.

SELECT seq, segment, field_count
FROM hl7.main.hl7_segments(E'MSH|^~\\&|SENDING_APP|SENDING_FAC|RECV_APP|RECV_FAC|20240101120000||ADT^A01|MSG00001|P|2.5\rEVN|A01|20240101120000\rPID|1||10001^^^HOSP^MR||Doe^John||19800101|M\rPV1|1|I')
ORDER BY seq;
Result
seq segment field_count
1 MSH 12
2 EVN 2
3 PID 8
4 PV1 2

Explode the PID segment into long-format field rows.

SELECT segment, field, repetition, value
FROM hl7.main.hl7_fields(E'MSH|^~\\&|SENDING_APP|SENDING_FAC|RECV_APP|RECV_FAC|20240101120000||ADT^A01|MSG00001|P|2.5\rEVN|A01|20240101120000\rPID|1||10001^^^HOSP^MR||Doe^John||19800101|M\rPV1|1|I')
WHERE segment = 'PID'
ORDER BY field, repetition;

Extract the patient family name (component 1 of PID-5) by location.

SELECT hl7.main.hl7_get(E'MSH|^~\\&|SENDING_APP|SENDING_FAC|RECV_APP|RECV_FAC|20240101120000||ADT^A01|MSG00001|P|2.5\rEVN|A01|20240101120000\rPID|1||10001^^^HOSP^MR||Doe^John||19800101|M\rPV1|1|I', 'PID-5.1') AS family_name;

Read the message type (MSH-9) for routing a mixed feed.

SELECT hl7.main.hl7_message_type(E'MSH|^~\\&|SENDING_APP|SENDING_FAC|RECV_APP|RECV_FAC|20240101120000||ADT^A01|MSG00001|P|2.5\rEVN|A01|20240101120000\rPID|1||10001^^^HOSP^MR||Doe^John||19800101|M\rPV1|1|I') AS message_type;
5 more examples

Read the HL7 version id (MSH-12) the message claims to conform to.

SELECT hl7.main.hl7_version(E'MSH|^~\\&|SENDING_APP|SENDING_FAC|RECV_APP|RECV_FAC|20240101120000||ADT^A01|MSG00001|P|2.5\rEVN|A01|20240101120000\rPID|1||10001^^^HOSP^MR||Doe^John||19800101|M\rPV1|1|I') AS version;

Read the message control id (MSH-10) used for ACK correlation and dedupe.

SELECT hl7.main.hl7_message_control_id(E'MSH|^~\\&|SENDING_APP|SENDING_FAC|RECV_APP|RECV_FAC|20240101120000||ADT^A01|MSG00001|P|2.5\rEVN|A01|20240101120000\rPID|1||10001^^^HOSP^MR||Doe^John||19800101|M\rPV1|1|I') AS control_id;

Validate that a well-formed HL7 v2 message parses.

SELECT hl7.main.is_valid_hl7(E'MSH|^~\\&|SENDING_APP|SENDING_FAC|RECV_APP|RECV_FAC|20240101120000||ADT^A01|MSG00001|P|2.5\rEVN|A01|20240101120000\rPID|1||10001^^^HOSP^MR||Doe^John||19800101|M\rPV1|1|I') AS ok;

Turn a table of raw messages into an ordered message log: skip malformed rows with is_valid_hl7, read the send time (MSH-7) with hl7_get as a TIMESTAMP, and add the control id, message type, and version from the MSH accessors (here: MSG00001 ADT^A01 at 12:00, then MSG00002 ORU^R01 at 12:30).

SELECT strptime(hl7.main.hl7_get(message, 'MSH-7'), '%Y%m%d%H%M%S') AS sent_at,
  hl7.main.hl7_message_control_id(message) AS control_id,
  hl7.main.hl7_message_type(message) AS message_type,
  hl7.main.hl7_version(message) AS version
FROM hl7.main.example_messages
WHERE hl7.main.is_valid_hl7(message)
ORDER BY sent_at, control_id;

Flatten an ORU^R01 lab report into one row per OBX result (test name, numeric value, units, reference range, abnormal flag) by pivoting hl7_fields on segment_rep, stamped with the patient MRN from hl7_get('PID-3.1') (two rows: White Blood Cell Count 7.2 and Hemoglobin 14.1 for MRN 10001).

SELECT hl7.main.hl7_get(E'MSH|^~\\&|LAB|HOSP|EHR|HOSP|20240101123000||ORU^R01|MSG00002|P|2.5\rPID|1||10001^^^HOSP^MR||Doe^John||19800101|M\rOBR|1||ORD123|CBC^Complete Blood Count\rOBX|1|NM|WBC^White Blood Cell Count||7.2|10*3/uL|4.0-11.0|N\rOBX|2|NM|HGB^Hemoglobin||14.1|g/dL|13.5-17.5|N', 'PID-3.1') AS mrn,
  f.segment_rep + 1 AS obx_set_id,
  split_part(max(f.value) FILTER (WHERE f.field = 3), '^', 2) AS test,
  TRY_CAST(max(f.value) FILTER (WHERE f.field = 5) AS DOUBLE) AS result,
  max(f.value) FILTER (WHERE f.field = 6) AS units,
  max(f.value) FILTER (WHERE f.field = 7) AS reference_range,
  max(f.value) FILTER (WHERE f.field = 8) AS abnormal_flag
FROM hl7.main.hl7_fields(E'MSH|^~\\&|LAB|HOSP|EHR|HOSP|20240101123000||ORU^R01|MSG00002|P|2.5\rPID|1||10001^^^HOSP^MR||Doe^John||19800101|M\rOBR|1||ORD123|CBC^Complete Blood Count\rOBX|1|NM|WBC^White Blood Cell Count||7.2|10*3/uL|4.0-11.0|N\rOBX|2|NM|HGB^Hemoglobin||14.1|g/dL|13.5-17.5|N') AS f
WHERE f.segment = 'OBX'
GROUP BY f.segment_rep
ORDER BY obx_set_id;
Views
example_messages 2 examples6 cols

Curated, browsable registry of ready-to-use sample HL7 v2 messages.

Columns
name VARCHAR
Short slug identifier for the sample (e.g. `adt_a01`).
message_type VARCHAR
HL7 message type as `type^event` (e.g. `ADT^A01`, `ORU^R01`).
trigger_event VARCHAR
HL7 trigger-event code for the sample (e.g. `A01`, `R01`).
segment_count INTEGER
Number of segments in the sample message (a small integer count).
description VARCHAR
One-line human summary of what the sample represents.
message VARCHAR
Raw, carriage-return-delimited HL7 v2 message text for the sample.
Examples (2)

List the built-in sample messages, richest first, showing their type, trigger event, and segment count.

SELECT name, message_type, trigger_event, segment_count
FROM hl7.main.example_messages
ORDER BY segment_count DESC, name;

Turn a table of raw messages into an ordered message log: skip malformed rows with is_valid_hl7, read the send time (MSH-7) with hl7_get as a TIMESTAMP, and add the control id, message type, and version from the MSH accessors (here: MSG00001 ADT^A01 at 12:00, then MSG00002 ORU^R01 at 12:30).

SELECT strptime(hl7.main.hl7_get(message, 'MSH-7'), '%Y%m%d%H%M%S') AS sent_at,
  hl7.main.hl7_message_control_id(message) AS control_id,
  hl7.main.hl7_message_type(message) AS message_type,
  hl7.main.hl7_version(message) AS version
FROM hl7.main.example_messages
WHERE hl7.main.is_valid_hl7(message)
ORDER BY sent_at, control_id;
Link
Scalar functions
hl7_get (message ANY, location VARCHAR) 4 examples

Extract a value from an HL7 v2.x message by location (e.g. 'PID-5', 'PID-5.1', 'MSH-9.1', 'DG1[2]-3'); 1-based field/component/subcomponent indices.

Arguments
message ANY
The HL7 v2.x message to read from, supplied inline as the message itself (either its text or its raw bytes), never a file path. Evaluated per row; NULL or malformed input yields NULL.
location VARCHAR
The HL7 location path identifying the value to extract, supplied as a constant string. A path addresses a value by naming a segment and a field number within it, and may optionally drill deeper into a component and then a subcomponent of that field, as well as pick which repeated occurrence of the segment to read. Indices are numbered from one per HL7 convention. The path is an open-ended grammar spanning arbitrary HL7 segments, not a short fixed vocabulary; the function documentation gives the full syntax and worked examples. An unparseable or absent path yields NULL.
ReturnsVARCHAR
Examples (4)

Extract the patient's family name (component 1 of PID-5).

SELECT hl7.main.hl7_get(E'MSH|^~\\&|SENDING_APP|SENDING_FAC|RECV_APP|RECV_FAC|20240101120000||ADT^A01|MSG00001|P|2.5\rEVN|A01|20240101120000\rPID|1||10001^^^HOSP^MR||Doe^John||19800101|M\rPV1|1|I', 'PID-5.1');

Extract the message type field (MSH-9) by location.

SELECT hl7.main.hl7_get(E'MSH|^~\\&|SENDING_APP|SENDING_FAC|RECV_APP|RECV_FAC|20240101120000||ADT^A01|MSG00001|P|2.5\rEVN|A01|20240101120000\rPID|1||10001^^^HOSP^MR||Doe^John||19800101|M\rPV1|1|I', 'MSH-9');

Address a repeated segment: read the value (OBX-5) of the second OBX result via the 1-based repetition `OBX[2]`.

SELECT hl7.main.hl7_get(E'MSH|^~\\&|LAB|HOSP|EHR|HOSP|20240101123000||ORU^R01|MSG00002|P|2.5\rPID|1||10001^^^HOSP^MR||Doe^John||19800101|M\rOBR|1||ORD123|CBC^Complete Blood Count\rOBX|1|NM|WBC^White Blood Cell Count||7.2|10*3/uL|4.0-11.0|N\rOBX|2|NM|HGB^Hemoglobin||14.1|g/dL|13.5-17.5|N', 'OBX[2]-5');
1 more example

Turn a table of raw messages into an ordered message log: skip malformed rows with is_valid_hl7, read the send time (MSH-7) with hl7_get as a TIMESTAMP, and add the control id, message type, and version from the MSH accessors (here: MSG00001 ADT^A01 at 12:00, then MSG00002 ORU^R01 at 12:30).

SELECT strptime(hl7.main.hl7_get(message, 'MSH-7'), '%Y%m%d%H%M%S') AS sent_at,
  hl7.main.hl7_message_control_id(message) AS control_id,
  hl7.main.hl7_message_type(message) AS message_type,
  hl7.main.hl7_version(message) AS version
FROM hl7.main.example_messages
WHERE hl7.main.is_valid_hl7(message)
ORDER BY sent_at, control_id;
Link
hl7_message_control_id (message ANY) 1 example

The message control ID from MSH-10.

Arguments
message ANY
The HL7 v2.x message to read MSH-10 from, supplied inline as the message itself (either its text or its raw bytes), never a file path. Evaluated per row; NULL or malformed input yields NULL.
ReturnsVARCHAR
Example

Read the message control ID (MSH-10) used for acknowledgements.

SELECT hl7.main.hl7_message_control_id(E'MSH|^~\\&|SENDING_APP|SENDING_FAC|RECV_APP|RECV_FAC|20240101120000||ADT^A01|MSG00001|P|2.5\rEVN|A01|20240101120000\rPID|1||10001^^^HOSP^MR||Doe^John||19800101|M\rPV1|1|I');
Link
hl7_message_type (message ANY) 1 example

The HL7 message type from MSH-9 (e.g. 'ADT^A01' or 'ADT^A01^ADT_A01').

Arguments
message ANY
The HL7 v2.x message to read MSH-9 from, supplied inline as the message itself (either its text or its raw bytes), never a file path. Evaluated per row; NULL or malformed input yields NULL.
ReturnsVARCHAR
Example

Read the message type (MSH-9) from an admit message.

SELECT hl7.main.hl7_message_type(E'MSH|^~\\&|SENDING_APP|SENDING_FAC|RECV_APP|RECV_FAC|20240101120000||ADT^A01|MSG00001|P|2.5\rEVN|A01|20240101120000\rPID|1||10001^^^HOSP^MR||Doe^John||19800101|M\rPV1|1|I');
Link
hl7_version (message ANY) 1 example

The HL7 version ID from MSH-12 (e.g. '2.5').

Arguments
message ANY
The HL7 v2.x message to read MSH-12 from, supplied inline as the message itself (either its text or its raw bytes), never a file path. Evaluated per row; NULL or malformed input yields NULL.
ReturnsVARCHAR
Example

Read the HL7 version (MSH-12) from a message.

SELECT hl7.main.hl7_version(E'MSH|^~\\&|SENDING_APP|SENDING_FAC|RECV_APP|RECV_FAC|20240101120000||ADT^A01|MSG00001|P|2.5\rEVN|A01|20240101120000\rPID|1||10001^^^HOSP^MR||Doe^John||19800101|M\rPV1|1|I');
Link
is_valid_hl7 (message ANY) 2 examples

True when the input parses as a well-formed HL7 v2.x message (begins with an MSH segment defining the field separator and encoding characters).

Arguments
message ANY
The candidate HL7 text to test, supplied inline as the message itself (either its text or its raw bytes), never a file path. Evaluated per row; returns true for a well-formed HL7 v2.x message, false for malformed text, and NULL for NULL input.
ReturnsBOOLEAN
Examples (2)

Check that a well-formed ADT^A01 message validates.

SELECT hl7.main.is_valid_hl7(E'MSH|^~\\&|SENDING_APP|SENDING_FAC|RECV_APP|RECV_FAC|20240101120000||ADT^A01|MSG00001|P|2.5\rEVN|A01|20240101120000\rPID|1||10001^^^HOSP^MR||Doe^John||19800101|M\rPV1|1|I');

Malformed text validates as false (never errors).

SELECT hl7.main.is_valid_hl7('not an hl7 message');
Link
Table functions
hl7_fields (message ANY) 2 examples

Explode an HL7 v2.x message into long format: one row per field value (repetitions expanded), keyed by segment, segment occurrence, field, and repetition. Component structure is preserved in the raw value text.

Arguments
message ANY
The HL7 v2.x message to explode into long format, supplied inline as the message itself (either its text or its raw bytes), never a file path. Every field of every segment becomes a row, with repeating fields expanded; NULL or malformed input yields no rows.
Returns columns
segment VARCHAR
3-letter segment identifier (e.g. MSH, PID).
segment_rep INTEGER
0-based occurrence index of this segment within the message.
field INTEGER
1-based HL7 field number within the segment.
repetition INTEGER
0-based repetition index of the field value.
value VARCHAR
Raw field-value text (component/subcomponent structure preserved).
Examples (2)

List every field of the PID (patient identification) segment as long-format rows.

SELECT field, value
FROM hl7.main.hl7_fields(E'MSH|^~\\&|SENDING_APP|SENDING_FAC|RECV_APP|RECV_FAC|20240101120000||ADT^A01|MSG00001|P|2.5\rEVN|A01|20240101120000\rPID|1||10001^^^HOSP^MR||Doe^John||19800101|M\rPV1|1|I')
WHERE segment = 'PID';

Flatten an ORU^R01 lab report into one row per OBX result (test name, numeric value, units, reference range, abnormal flag) by pivoting hl7_fields on segment_rep, stamped with the patient MRN from hl7_get('PID-3.1') (two rows: White Blood Cell Count 7.2 and Hemoglobin 14.1 for MRN 10001).

SELECT hl7.main.hl7_get(E'MSH|^~\\&|LAB|HOSP|EHR|HOSP|20240101123000||ORU^R01|MSG00002|P|2.5\rPID|1||10001^^^HOSP^MR||Doe^John||19800101|M\rOBR|1||ORD123|CBC^Complete Blood Count\rOBX|1|NM|WBC^White Blood Cell Count||7.2|10*3/uL|4.0-11.0|N\rOBX|2|NM|HGB^Hemoglobin||14.1|g/dL|13.5-17.5|N', 'PID-3.1') AS mrn,
  f.segment_rep + 1 AS obx_set_id,
  split_part(max(f.value) FILTER (WHERE f.field = 3), '^', 2) AS test,
  TRY_CAST(max(f.value) FILTER (WHERE f.field = 5) AS DOUBLE) AS result,
  max(f.value) FILTER (WHERE f.field = 6) AS units,
  max(f.value) FILTER (WHERE f.field = 7) AS reference_range,
  max(f.value) FILTER (WHERE f.field = 8) AS abnormal_flag
FROM hl7.main.hl7_fields(E'MSH|^~\\&|LAB|HOSP|EHR|HOSP|20240101123000||ORU^R01|MSG00002|P|2.5\rPID|1||10001^^^HOSP^MR||Doe^John||19800101|M\rOBR|1||ORD123|CBC^Complete Blood Count\rOBX|1|NM|WBC^White Blood Cell Count||7.2|10*3/uL|4.0-11.0|N\rOBX|2|NM|HGB^Hemoglobin||14.1|g/dL|13.5-17.5|N') AS f
WHERE f.segment = 'OBX'
GROUP BY f.segment_rep
ORDER BY obx_set_id;
Link
hl7_segments (message ANY) 7 examples

Split an HL7 v2.x message into its segments: one row per segment with its 3-letter id, field count, and raw text.

Arguments
message ANY
The HL7 v2.x message to split, supplied inline as the message itself (either its text or its raw bytes), never a file path. Segments are separated by carriage returns and the first must be MSH. NULL or malformed input (no leading MSH) yields no rows.
Returns columns
seq INTEGER
1-based ordinal of the segment within the message.
segment VARCHAR
3-letter segment identifier (e.g. MSH, PID, PV1).
field_count INTEGER
Number of fields in the segment (HL7 numbering; MSH-1 counts).
raw VARCHAR
Raw text of the entire segment.
Examples (7)

List every segment of an admit message in order (MSH, EVN, PID, PV1) with its field count.

SELECT seq, segment, field_count
FROM hl7.main.hl7_segments(E'MSH|^~\\&|SENDING_APP|SENDING_FAC|RECV_APP|RECV_FAC|20240101120000||ADT^A01|MSG00001|P|2.5\rEVN|A01|20240101120000\rPID|1||10001^^^HOSP^MR||Doe^John||19800101|M\rPV1|1|I');
SELECT seq, segment, field_count
FROM hl7.main.hl7_segments(E'MSH|^~\&|SENDING_APP|SENDING_FAC|RECV_APP|RECV_FAC|20240101120000||ADT^A01|MSG00001|P|2.5
EVN|A01|20240101120000
PID|1||10001^^^HOSP^MR||Doe^John||19800101|M
PV1|1|I')
ORDER BY seq;
SELECT field, repetition, value
FROM hl7.main.hl7_fields(E'MSH|^~\&|SENDING_APP|SENDING_FAC|RECV_APP|RECV_FAC|20240101120000||ADT^A01|MSG00001|P|2.5
EVN|A01|20240101120000
PID|1||10001^^^HOSP^MR||Doe^John||19800101|M
PV1|1|I')
WHERE segment = 'PID'
ORDER BY field;
4 more examples
SELECT hl7.main.hl7_get(E'MSH|^~\&|SENDING_APP|SENDING_FAC|RECV_APP|RECV_FAC|20240101120000||ADT^A01|MSG00001|P|2.5
EVN|A01|20240101120000
PID|1||10001^^^HOSP^MR||Doe^John||19800101|M
PV1|1|I', 'PID-5.1') AS family_name;
SELECT hl7.main.hl7_message_type(E'MSH|^~\&|SENDING_APP|SENDING_FAC|RECV_APP|RECV_FAC|20240101120000||ADT^A01|MSG00001|P|2.5
EVN|A01|20240101120000
PID|1||10001^^^HOSP^MR||Doe^John||19800101|M
PV1|1|I') AS type,
  hl7.main.hl7_version(E'MSH|^~\&|SENDING_APP|SENDING_FAC|RECV_APP|RECV_FAC|20240101120000||ADT^A01|MSG00001|P|2.5
EVN|A01|20240101120000
PID|1||10001^^^HOSP^MR||Doe^John||19800101|M
PV1|1|I') AS version,
  hl7.main.hl7_message_control_id(E'MSH|^~\&|SENDING_APP|SENDING_FAC|RECV_APP|RECV_FAC|20240101120000||ADT^A01|MSG00001|P|2.5
EVN|A01|20240101120000
PID|1||10001^^^HOSP^MR||Doe^John||19800101|M
PV1|1|I') AS control_id;
SELECT hl7.main.is_valid_hl7(E'MSH|^~\&|SENDING_APP|SENDING_FAC|RECV_APP|RECV_FAC|20240101120000||ADT^A01|MSG00001|P|2.5
EVN|A01|20240101120000
PID|1||10001^^^HOSP^MR||Doe^John||19800101|M
PV1|1|I') AS ok;
SELECT strptime(hl7.main.hl7_get(message, 'MSH-7'), '%Y%m%d%H%M%S') AS sent_at,
  hl7.main.hl7_message_control_id(message) AS control_id,
  hl7.main.hl7_message_type(message) AS message_type,
  hl7.main.hl7_version(message) AS version
FROM hl7.main.example_messages
WHERE hl7.main.is_valid_hl7(message)
ORDER BY sent_at, control_id;
Link

Try these queries

Explode the PID segment into long-format field rows.

SELECT segment, field, repetition, value
FROM hl7.main.hl7_fields(E'MSH|^~\\&|SENDING_APP|SENDING_FAC|RECV_APP|RECV_FAC|20240101120000||ADT^A01|MSG00001|P|2.5\rEVN|A01|20240101120000\rPID|1||10001^^^HOSP^MR||Doe^John||19800101|M\rPV1|1|I')
WHERE segment = 'PID'
ORDER BY field, repetition

Uses hl7_fields

Extract the patient family name (component 1 of PID-5) by location.

SELECT hl7.main.hl7_get(E'MSH|^~\\&|SENDING_APP|SENDING_FAC|RECV_APP|RECV_FAC|20240101120000||ADT^A01|MSG00001|P|2.5\rEVN|A01|20240101120000\rPID|1||10001^^^HOSP^MR||Doe^John||19800101|M\rPV1|1|I', 'PID-5.1') AS family_name

Uses hl7_get

Read the message type (MSH-9) for routing a mixed feed.

SELECT hl7.main.hl7_message_type(E'MSH|^~\\&|SENDING_APP|SENDING_FAC|RECV_APP|RECV_FAC|20240101120000||ADT^A01|MSG00001|P|2.5\rEVN|A01|20240101120000\rPID|1||10001^^^HOSP^MR||Doe^John||19800101|M\rPV1|1|I') AS message_type

Uses hl7_message_type

Read the HL7 version id (MSH-12) the message claims to conform to.

SELECT hl7.main.hl7_version(E'MSH|^~\\&|SENDING_APP|SENDING_FAC|RECV_APP|RECV_FAC|20240101120000||ADT^A01|MSG00001|P|2.5\rEVN|A01|20240101120000\rPID|1||10001^^^HOSP^MR||Doe^John||19800101|M\rPV1|1|I') AS version

Uses hl7_version

Read the message control id (MSH-10) used for ACK correlation and dedupe.

SELECT hl7.main.hl7_message_control_id(E'MSH|^~\\&|SENDING_APP|SENDING_FAC|RECV_APP|RECV_FAC|20240101120000||ADT^A01|MSG00001|P|2.5\rEVN|A01|20240101120000\rPID|1||10001^^^HOSP^MR||Doe^John||19800101|M\rPV1|1|I') AS control_id

Uses hl7_message_control_id

Validate that a well-formed HL7 v2 message parses.

SELECT hl7.main.is_valid_hl7(E'MSH|^~\\&|SENDING_APP|SENDING_FAC|RECV_APP|RECV_FAC|20240101120000||ADT^A01|MSG00001|P|2.5\rEVN|A01|20240101120000\rPID|1||10001^^^HOSP^MR||Doe^John||19800101|M\rPV1|1|I') AS ok

Uses is_valid_hl7

18 more examples in the Catalog, each listed under the table or function it uses.

HL7 is an independent open-source connector from Query.Farm. It is not affiliated with, endorsed by or sponsored by the services, projects or organisations it works with. Product names, logos and trademarks belong to their respective owners.