Set Operations Tool

Set Operations Tool

The Set Operations tool lets you compare two sets of HL7 messages side by side using set operations. Select two open message tabs, define a link key (an expression that identifies related messages), and then find which messages appear in both sets, only in one set, or have duplicate keys.

Common use cases:

  • Linking 2 sets of messages together, for instance HL7 Messages and their corresponding ACK message

  • Finding messages that exist in a source system but are missing from a destination (difference)

  • Identifying messages that were successfully received by both systems (intersection)

  • Combining two message sets into one view (union)

  • Detecting duplicate messages within a single tab based on a key (duplicates)

  • Correlating messages across systems using a shared identifier like Message Control ID

Opening the Tool

Open the A ∩ B tool from the tool windows area at the bottom of the HL7Spy window. It appears in the tool windows list as A ∩ B. You can toggle it from the Tools header button or the tool windows popup menu.

User Interface

The tool is divided into two side-by-side panels, labeled A (left) and B (right). Each side has its own toolbar, options, and results grid.

Layout

Area

Description

Area

Description

Tab A / Tab B selector

A dropdown on each side’s toolbar to choose which open message tab to use as the source for that set. The dropdown shows the tab name, message count, first message date, and file path.

Set label

Displays the currently active set operation for that side (e.g. “A ∩ B”, “A - B”).

Actions

Opens a menu with set operations, result export, and clipboard copy commands.

Options

Opens the configuration panel for that side (SELECT columns, WHERE filter, Link Key, and toggle switches).

Results Grid

Shows the query results after a set operation is applied. Columns are determined by the SELECT list plus a Link Key column.

The caption bar at the top shows Set (A,B) = (Tab A Name, Tab B Name) when both sides are configured, or Set Operations when no tabs are selected.

Configuration

Click the Options button on either side’s toolbar to configure the query for that set. Each side (A and B) has independent settings.

Options Panel

Setting

Description

Default

Setting

Description

Default

Link Key

An HL7 expression that produces a unique key for matching messages between Set A and Set B. This is how the tool determines which messages are “the same” across the two sets. You can use HL7 paths, string concatenation, and functions.

MSH-4 + '-' + MSH-10

SELECT

A comma-separated list of HL7 paths to include as additional columns in the results grid. These columns provide context alongside the link key.

MSH-4, MSH-7, MSH-9, PID-3

WHERE

An optional filter expression. Only messages that satisfy this condition are included in the set. Uses the same expression syntax as HL7 SQL.

(empty — all messages included)

Synchronize Grids

When enabled, selecting a row in one grid automatically navigates to the matching row (same link key) in the other grid. Also navigates to the corresponding message in the source tab.

On

Auto Position Tab Windows

When enabled, the two source message tabs are automatically arranged side by side in a vertical split after the query runs.

On

The Link Key is the most important setting. Choose a key that uniquely identifies a message across both systems. Common choices:

  • MSH-10 — Message Control ID (if unique across both sets)

  • MSH-4 + '-' + MSH-10 — Sending Facility + Message Control ID (default)

  • PID-3.1 — Patient Identifier (to correlate all messages for the same patient)

  • PID-3.1 + '-' + MSH-9 — Patient ID + Message Type (for type-specific correlation)

If no Link Key is specified, MSH-10 (Message Control ID) is used automatically.

Set Operations

Once you have selected a tab for each side and configured the link key, use the Actions menu on either side to apply a set operation. The results appear in that side’s grid.

The following set operations are available:

Operation

Symbol

Description

Operation

Symbol

Description

None

Clear the results grid. No operation applied.

Intersection

A ∩ B

Show messages whose link key exists in both Set A and Set B. This answers: “Which messages are in both sets?”

Difference

A - B

Show messages whose link key exists in this set but not in the other set. This answers: “Which messages are in A but missing from B?”

Symmetric Difference

A △ B

Show messages whose link key exists in only one of the two sets (A-B combined with B-A). This answers: “Which messages are in one set but not both?”

Union

A ∪ B

Show all messages from both sets combined (intersection plus both sides’ unique messages). This answers: “What is the complete combined set?”

Duplicates

Show messages within this set that have the same link key as another message in the same set. This answers: “Are there duplicate messages?”

Each side can have a different operation active. For example, side A might show the intersection while side B shows the difference.

Using the Tool

Basic Workflow

  1. Load two sets of HL7 messages into separate tabs in HL7Spy (e.g. messages from System A and System B).

  2. Open the A ∩ B tool from the tool windows area.

  3. On the left toolbar, select the first message tab from the Tab A dropdown.

  4. On the right toolbar, select the second message tab from the Tab B dropdown.

  5. Optionally click Options on either side to adjust the Link Key, SELECT columns, or WHERE filter.

  6. Click Actions on either side and choose a set operation (e.g. Intersection).

  7. The query executes against both tabs, matching messages by link key, and the results appear in the grids.

Navigating Results

When Synchronize Grids is enabled (the default):

  • Clicking a row in grid A automatically highlights the matching row (same link key) in grid B.

  • The corresponding message is also selected in the source message tab, so you can view the full message content.

  • This makes it easy to compare the details of linked messages side by side.

Grid synchronization is disabled for the Difference and Symmetric Difference operations, since by definition those results do not have a matching row on the other side.

Exporting Results to a New Tab

After running a set operation, you can export the results to a new message tab:

  1. Open the Actions menu on the side whose results you want to export.

  2. Click Results to New Tab (the label changes to reflect the active operation, e.g. “Intersection to New Tab”).

  3. A new tab is created in HL7Spy containing only the messages from the operation result.

This is useful for extracting a subset of messages for further analysis — for example, exporting all missing messages (difference) to send to a support team.

Copying Results to Clipboard

The Actions menu also provides clipboard operations:

  • Copy Selected to Clipboard — copies the selected rows from the grid

  • Copy All to Clipboard — copies all rows from the grid

Examples

Example 1: Find Missing Messages

Scenario: You have messages from a sending system (Tab “Source”) and messages received by a destination system (Tab “Destination”). You want to find which messages were sent but never received.

  1. Select Source as Tab A and Destination as Tab B.

  2. Set the Link Key to MSH-10 (Message Control ID) on both sides.

  3. On side A, click Actions → A - B (A not in B).

  4. The grid shows all messages from Source whose Message Control ID does not appear in Destination — these are your missing messages.

  5. Click Difference to New Tab to export the missing messages for investigation.

Example 2: Detect Duplicate Messages

Scenario: You suspect a message tab contains duplicate messages.

  1. Select the suspect tab as Tab A (Tab B can be anything or the same tab).

  2. Set the Link Key to the field that should be unique (e.g. MSH-10).

  3. On side A, click Actions → Show A Duplicate Keys.

  4. The grid shows all messages that share a link key with at least one other message in the same tab.

Example 3: Correlate Messages Across Systems

Scenario: You want to see which patients have messages in both System A and System B.

  1. Select each system’s messages as Tab A and Tab B.

  2. Set the Link Key to PID-3.1 (Patient Identifier) on both sides.

  3. Add PID-5, MSH-9 to the SELECT list for context.

  4. On side A, click Actions → A ∩ B (in both A and B).

  5. The grid shows one row per patient that exists in both systems, with the patient name and message type as extra columns.

  6. With Synchronize Grids on, clicking a patient in grid A highlights the same patient in grid B for side-by-side comparison.

How It Works

Behind the scenes, the tool:

  1. Runs an HL7 query against each tab’s messages. The query is built from your Link Key, SELECT, and WHERE settings, producing a results table where the first column is the Link Key.

  2. Indexes each side’s results by link key value.

  3. Applies the selected set operation by comparing key sets:

    • Intersection: keys present in both A’s index and B’s index

    • Difference: keys in this side’s index but absent from the other

    • Symmetric Difference: keys unique to either side (A-only + B-only)

    • Union: intersection results plus both sides’ remaining results

    • Duplicates: keys that appear more than once within the same side

  4. Displays the matching rows in the results grid, with a Source column (A or B) indicating which tab each row came from.

Settings Persistence

All configuration (Link Key, SELECT, WHERE, toggle switches) is automatically saved when you close the Options panel and restored the next time you open the tool.