Custom Code - Getting Started

Custom Code - Getting Started

Getting Started — Hello World

The traditional way to introduce any programming tool is with a “Hello World” example. In HL7Spy, we will set MSH-3 (Sending Application) to “Hello World!” for every message in the active tab.

  1. Open the Custom Code tool.

  2. Click the + button in the Plugin List to add a new function. Give it a name, for example “Hello World”.

  3. Replace the body of the Run() method with the following code:

csharpHello World

  1. Load some HL7 messages into a tab in HL7Spy.

  2. Press F5 (Run).

  3. A new tab named “Hello World Tab” appears with every message having MSH-3 set to “Hello World!”.

You can also access fields using the strongly-typed model: message.MSH.SendingApplication_03.NamespaceID_01.Value = "Hello World!";

 

Sample Source Code

public override void Run() { // Get an HL7 Message in parsed format HL7Message message = GetParsedMessage(); // Set MSH-3 to "Hello World!" message["MSH-3"] = "Hello World"; // Same thing, but using a different syntax message.MSH.SendingApplication_03.NamespaceID_01.Value = "Hello World!"; // Save the altered message into a new tab SaveMessage(message,"Hello World Tab"); }

 

Sample Output

image-20260411-210154.png