The HAPIMessage object enables HL7 messages to be modified using the HAPI API libraryThe object is available in all JavaScript components that process messages.

To create a HAPIMessage object, use the getHapiMessage() method provided by the ROMessage object.

Refer to Segment Notation for details on the notation used by HAPIMessage object for sequential and non-sequential segment repeats.

Parameters

 All HL7 messages parsed into the HAPIMessage object observe an indexing structure represented by the following parameters:

Parameter Description

segmentName

Denotes the name of the HL7 segment. It must be a non-empty string with no more than 256 characters in length.

segmentRepeat

Denotes the segment repeat index. The parameter is indexed from 0. When attempting to interact with a non-repeating segment or the first repeating segment, a value of 0 must be used. The parameter is an Int type.

fieldIndex

Denotes the HL7 field location index. It is indexed from 1. The parameter is an Int type.

fieldRepeat

Denotes the field repeat index. The parameter is indexed from 0. When attempting to interact with a non-repeating field or the first repeating field, a value of 0 must be used. The parameter is an Int type.

componentIndex

Denotes the HL7 component location index. It is indexed from 1. The parameter is an Int type.

subcomponentIndex

Denotes the HL7 sub-component location index. It is indexed from 1. The parameter is an Int type.

Methods

Method

Description

getOutput()

Returns the transformed HAPI message as an HL7 string.

This method removes successive empty fields at the end of segments and successive empty segments at the end of the message.

getOutputAsXml()

Returns the transformed HAPI message as an HL7 XML string.

This method removes successive empty fields at the end of segments and successive empty segments at the end of the message.

getValue(segmentName, segmentRepeat, fieldIndex, fieldRepeat, componentIndex, subcomponentIndex)

Retrieves the value of a sub-component based on its full location. If a field or component has no child structures, a value of 1 must be inserted into the subcomponentIndex and/or componentIndex.

If the sub-component does not exist in the input message, then getValue throws an exception. If this exception is not handled, then the message is sent to the filter's error connector. 

The exception can be handled with the JavaScript try...catch construct. Another approach is to avoid the exception by always using the fieldExists method to confirm that the field exists before attempting to get its value.

setValue(segmentName, segmentRepeat, fieldIndex, fieldRepeat, componentIndex, subcomponentIndex, string value)

Sets the value of a sub-component at the given full location to the provided string value. If a field or component has no child structures, a value of 1 must be inserted into the subcomponentIndex and/or componentIndex.

Setting a value in a field, component, or sub-component that is not present results in the creation of empty fields, components, or sub-components, respectively, in lieu of of any preceding fields, components, or sub-components that are also not present.

getSegmentNames()
Returns a Java array object of HL7 segment names present in the message. Only unique segment names are listed; segment repeats are only listed under one name.
numberOfSegments() Returns the number of unique segments in a message. Repeating segments are not included in this count.
numberOfSegmentRepeats(segmentName)

Returns the number of repeating segments found in the message for a given segmentName.

numberOfFields(segmentName, segmentRepeat) Returns the number of fields for a given segment. Repeating fields are not included in this count.
numberOfFieldRepeats(segmentName, segmentRepeat, fieldindex) Returns the number of repeating fields found in the message for a given fieldIndex.
numberOfComponents(segmentName, segmentRepeat, fieldIndex, fieldRepeat) Returns the number of components for a given field.
numberOfSubcomponents(segmentName, segmentRepeat, fieldIndex, fieldRepeat, componentIndex) Returns the number of sub-components for a given component.
clearField(segmentName, segmentRepeat, fieldIndex, fieldRepeat) Clears all components and sub-components at a given field location. The repeating field separator character (~) is removed if the field repeat is empty.
clearFieldKeepSeparator(segmentName, segmentRepeat, fieldIndex, fieldRepeat) Clears all components and sub-components at a given field location. The repeating field separator character is not removed even if the field repeat is empty.

clearValue(segmentName, segmentRepeat, fieldIndex, fieldRepeat, componentIndex, subcomponentIndex)

Clears the value at a provided location. The repeating field separator characters are removed if the field repeat is empty.
clearValueKeepSeparator(segmentName, segmentRepeat, fieldIndex, fieldRepeat, componentIndex, subcomponentIndex) Clears the value at a provided location. The repeating field separator characters are not removed even if the field repeat is empty.
segmentExists(segmentName, segmentRepeat) Returns true if the segment exists, or false if it does not.
fieldExists(segmentName, segmentRepeat, fieldIndex, fieldRepeat) Returns true if the field exists, or false if it does not.

deleteFieldRepeat(segmentName, segmentRepeat, fieldIndex, fieldRepeat)

Deletes a field repeat at a given location. Field repeat indexing is changed appropriately if other repeats still remain.
addSegment(segmentName, index)

Inserts a segment at the specified message index. The segment is added only after a field is populated.

Indexed from 0 (before the first segment in the message). The index does not include repeats.

addSegmentRepeat(segmentName, index)

Inserts a repeating segment at the location specified by the segment name (of a segment that is already present in the message) and repeat index. The segment repeat is added only after its fields is populated. If the first repeat of the repeating segment you want to add does not exist, then you must first use addSegement to add the first repeat.

Indexed from 0 (before the first repeat of the segment).

deleteSegment(segmentName, segmentRepeat)

Deletes a segment at the location specified by the segment name and repeat index.

Indexed from 0 (the first repeat of the segment).

If you are deleting a segment and then adding segments with the same name, ensure you re-parse the message using reparseHapiMessage() before adding the segments.

reparseHapiMessage()

Re-parses the current HAPIMessage object. When a segment has been deleted from a particular location in a message, attempting to add a segment with the same name to a different location does not work - the segment is added to the deleted location. This occurs because deleteSegment() does completely remove the segment from the message structure. However, calling reparseHapiMessage() after the segment deletion re-parses the message thereby enabling segments with the same name to be added anywhere in the message.

setReturnEmptyString(boolean returnEmptyString)

Configures getValue() to return either an empty string or throw an exception, when accessing a non-existent value.

It also configures clearField() and clearFieldKeepSeparator() to clear the value or throw an exception, when accessing a non-existent value.

The setting applies to all subsequent calls. By default, it is set to true (return an empty string, or clear the value).

Examples

// Sample message used in examples:
// MSH|^~\&|CANNS|CANNT|CANAB|CANNT|19871010031642||ADT^A01^ADT_A45|10215605xgfd|D^Not|2.1^23^14|6789||AL|AL|VCT||19|2.3
// NK1|1654|ROMINES^QUEENIE^19851010174850&19891023003156~YOUNGSTEAD^FARICA^19921011094736&20021010061819
// NK1|4567|WHORTON^CLODIA^19811016051025&19871015063310~FARLEY^JACQUELINE^19941010161033&19911010152916
// ZKX|1234|F2rep1~F2rep2~F2rep3|F3rep1~~F3rep3|~F4rep2
// NK1|1654|ROMINES^QUEENIE^19851010174850&19891023003156~YOUNGSTEAD^FARICA^19921011094736&20021010061819
// NK1|4567|WHORTON^CLODIA^19811016051025&19871015063310~FARLEY^JACQUELINE^19941010161033&19911010152916
// ABC|1213|Field|Field
// NK1|4567|WHORTON^CLODIA^19811016051025&19871015063310~FARLEY^JACQUELINE^19941010161033&19911010152916

getHapiMessage

// Create the output message 
var next = output.append(input[0]);

// Create transformable HAPI message
var hapiMessage = next.getHapiMessage();

getOutput

 
// Create the output message 
var next = output.append(input[0]);

// Create transformable hapi message
var hapiMessage = next.getHapiMessage();

// Make some changes
hapiMessage.deleteSegment("ZKX");
hapiMessage.setValue("ABC",0,1,0,1,1,"TEST");

// Get the transformed message
next.text = hapiMessage.getOutput();

getValue

// Input: 
// NK1|1654|ROMINES^QUEENIE^19851010174850&19891023003156~YOUNGSTEAD^FARICA^19921011094736&20021010061819
// NK1|4567|WHORTON^CLODIA^19811016051025&19871015063310~FARLEY^JACQUELINE^19941010161033&19911010152916

// Retrieve from segment NK1, repeat 0 (first repeat), field 1, field repeat 0 (first repeat), component 1, sub-component 1
var extracted = hapiMessage.getValue("NK1",0,1,0,1,1); 
// extracted = 1654

// Retrieve from segment NK1, repeat 1 (second repeat), field 1, field repeat 0 (first repeat), component 1, sub-component 1
var extracted = hapiMessage.getValue("NK1",1,1,0,1,1);
// extracted = 4567

setValue

// Input: NK1|1654|ROMINES^QUEENIE^19851010174850&19891023003156~YOUNGSTEAD^FARICA^19921011094736&20021010061819

// Retrieve from segment NK1, repeat 0 (first repeat), field 1, field repeat 0 (first repeat), component 1, sub-component 1
hapiMessage.setValue("NK1",0,1,0,1,1,"TEST"); 
 
// Output: NK1|TEST|ROMINES^QUEENIE^19851010174850&19891023003156~YOUNGSTEAD^FARICA^19921011094736&20021010061819

getSegmentNames

var segment_names = hapiMessage.getSegmentNames();

// segment_names = [MSH, NK1, ZKX, ABC] 
// The repeating NK1 segments are not included

numberOfSegments

var totalNumberSegments = hapiMessage.numberOfSegments();

// totalNumberSegments = 6
// MSH + NK1 + ZKX + NK1 + ABC + NK1
// Sequential segment repeats are not counted. Non-sequential repeats are counted.

numberOfSegmentRepeats

// Number of segment repeats are applied on a per group basis.
// Square brackets [] are needed where grouping is done. These are specified in the method argument.
// The first grouping of a segment does not use square bracket notation

var NK1SegmentRepeatsGroup1 = hapiMessage.numberOfSegmentRepeats("NK1")
// NK1SegmentRepeatsGroup1 = 2

var NK1SegmentRepeatsGroup2 = hapiMessage.numberOfSegmentRepeats("NK1[2]")
// NK1SegmentRepeatsGroup2 = 2

var NK1SegmentRepeatsGroup3 = hapiMessage.numberOfSegmentRepeats("NK1[3]")
// NK1SegmentRepeatsGroup3 = 1

numberOfFields

// Count fields in NK1|1654|ROMINES^QUEENIE^19851010174850&19891023003156~YOUNGSTEAD^FARICA^19921011094736&20021010061819
var number_of_Fields = hapiMessage.numberOfFields("NK1",0); 

// number_of_Fields = 2
 
// field1 contains 1654
// field2 contains ROMINES^QUEENIE^19851010174850&19891023003156 (repeat not included)

numberOfFieldRepeats

// Count number of field repeats in NK1|1654|ROMINES^QUEENIE^19851010174850&19891023003156~YOUNGSTEAD^FARICA^19921011094736&20021010061819
var number_of_Field_repeats = hapiMessage.numberOfFieldRepeats("NK1",0,2); 

// number_of_Field_repeats = 2

// Two repeats at field 2:
// rep1 contains ROMINES^QUEENIE^19851010174850&19891023003156
// rep2 contains YOUNGSTEAD^FARICA^19921011094736&2002101006181

numberOfComponents

// Count components in NK1|1654|ROMINES^QUEENIE^19851010174850&19891023003156~YOUNGSTEAD^FARICA^19921011094736&20021010061819
var number_of_components = hapiMessage.numberOfComponents("NK1",0,2,0);

// number_of_components = 3

// field 2 repeat 0 : ROMINES^QUEENIE^19851010174850&19891023003156
// Components are separated by '^':
// comp1 contains ROMINES
// comp2 contains QUEENIE
// comp3 contains 19851010174850&19891023003156

numberOfSubcomponents

// Count subcomponents in NK1|1654|ROMINES^QUEENIE^19851010174850&19891023003156~YOUNGSTEAD^FARICA^19921011094736&20021010061819
var number_of_sub_components = hapiMessage.numberOfSubcomponents("NK1",0,2,0,3);

// number_of_sub_components = 2

// Field 2, repeat 0, component 3 contains 19851010174850&19891023003156
// Sub-components are separated by '&':
// subcomp1 contains 19851010174850
// subcomp2 contains 19891023003156

clearField

// Input: ZKX|1234|F2rep1~F2rep2~F2rep3|F3rep1~~F3rep3|~F4rep2

// Clears the field containing the value F2rep2
hapiMessage.clearField("ZKX",0,2,1);

// Output: ZKX|1234|F2rep1~~F2rep3|F3rep1~~F3rep3|~F4rep2
// Input: ZKX|1234|F2rep1~F2rep2~F2rep3|F3rep1~~F3rep3|~F4rep2
 
// Clears the field containing the value F3rep3 and removes the field separator characters '~'
hapiMessage.clearField("ZKX",0,3,2); 

// Output: ZKX|1234|F2rep1~F2rep2~F2rep3|F3rep1|~F4rep2

clearFieldKeepSeparator

// Input: ZKX|1234|F2rep1~F2rep2~F2rep3|F3rep1~~F3rep3|~F4rep2
 
// Clears the field containing the value F2rep2
hapiMessage.clearField("ZKX",0,2,1);

// Output: ZKX|1234|F2rep1~~F2rep3|F3rep1~~F3rep3|~F4rep2
// Input: ZKX|1234|F2rep1~F2rep2~F2rep3|F3rep1~~F3rep3|~F4rep2

// Clears the field containing the value F3rep3 and retains the field separator characters '~'
hapiMessage.clearFieldKeepSeparator("ZKX",0,3,2); 

// Output: ZKX|1234|F2rep1~F2rep2~F2rep3|F3rep1~~|~F4rep2

clearValue

// Input: NK1|1654|ROMINES^QUEENIE^19851010174850&19891023003156~YOUNGSTEAD^FARICA^19921011094736&20021010061819

// Clears the value 1654
hapiMessage.clearValue("NK1",0,1,0,1,1);

// Output: NK1||ROMINES^QUEENIE^19851010174850&19891023003156~YOUNGSTEAD^FARICA^19921011094736&20021010061819
// Input: NK1|1654|ROMINES^QUEENIE^19851010174850&19891023003156~YOUNGSTEAD^FARICA^19921011094736&20021010061819

// Clears the value 19851010174850
hapiMessage.clearValue("NK1",0,2,0,3,1);

// Output: NK1|1654|ROMINES^QUEENIE^&19891023003156~YOUNGSTEAD^FARICA^19921011094736&20021010061819
// Input: NK1|1654|ROMINES^QUEENIE^19851010174850&19891023003156~YOUNGSTEAD^FARICA^19921011094736&20021010061819

// Clears the values represented by YOUNGSTEAD^FARICA^19921011094736&20021010061819 and removes the field separator character '~'
hapiMessage.clearValue("NK1",0,2,1,3,1);
hapiMessage.clearValue("NK1",0,2,1,3,2);
hapiMessage.clearValue("NK1",0,2,1,2,1);
hapiMessage.clearValue("NK1",0,2,1,1,1); 

// Output: NK1|1654|ROMINES^QUEENIE^19851010174850&19891023003156

clearValueKeepSeparator

// Behaves the same as clearValue but does not remove the field separator '~' if the field is empty after clearing value

// Input: NK1|1654|ROMINES^QUEENIE^19851010174850&19891023003156~YOUNGSTEAD^FARICA^19921011094736&20021010061819

// Clears the value 19921011094736
hapiMessage.clearValueKeepSeparator("NK1",0,2,1,3,1);
// Output: NK1|1654|ROMINES^QUEENIE^19851010174850&19891023003156~YOUNGSTEAD^FARICA^&20021010061819

// Clears the value 20021010061819
hapiMessage.clearValueKeepSeparator("NK1",0,2,1,3,2);
// Output: NK1|1654|ROMINES^QUEENIE^19851010174850&19891023003156~YOUNGSTEAD^FARICA

// Clears the value FARICA
hapiMessage.clearValueKeepSeparator("NK1",0,2,1,2,1);
// Output: NK1|1654|ROMINES^QUEENIE^19851010174850&19891023003156~YOUNGSTEAD

// Clears the value YOUNGSTEAD
hapiMessage.clearValueKeepSeparator("NK1",0,2,1,1,1);
// Output: NK1|1654|ROMINES^QUEENIE^19851010174850&19891023003156~

segmentExists

// Input: 
// NK1|1654|ROMINES^QUEENIE^19851010174850&19891023003156~YOUNGSTEAD^FARICA^19921011094736&20021010061819
// NK1|4567|WHORTON^CLODIA^19811016051025&19871015063310~FARLEY^JACQUELINE^19941010161033&19911010152916
// ZKX|1234|F2rep1~F2rep2~F2rep3|F3rep1~~F3rep3|~F4rep2
// NK1|1654|ROMINES^QUEENIE^19851010174850&19891023003156~YOUNGSTEAD^FARICA^19921011094736&20021010061819
 
// Segment called NK1 exists
var exist = hapiMessage.segmentExists("NK1",0);
// exist = true

// Segment called NK1 (first repeat) exists
var exist = hapiMessage.segmentExists("NK1",1);
// exist = true 

// Segment called NK1 (second repeat) does not exist
var exist = hapiMessage.segmentExists("NK1",2);
// exist = false 

// Segment called NK1[2] exists
var exist = hapiMessage.segmentExists("NK1[2]",0);
// exist = true 
 
// Segment called XYZ does not exist
var exist = hapiMessage.segmentExists("XYZ",0) 
// exist = false

fieldExists

// Input: NK1|1654|ROMINES^QUEENIE^19851010174850&19891023003156~YOUNGSTEAD^FARICA^19921011094736&20021010061819

// Field exists
var exist = hapiMessage.fieldExists("NK1",0,1,0);
// exist = true

// Field repeat exists
var exist = hapiMessage.fieldExists("NK1",0,2,1);  //YOUNGSTEAD^FARICA^19921011094736&20021010061819
// exist = true

// Field does not exist
var exist = hapiMessage.fieldExists("NK1",0,7,0);
// exist = false

// Field repeat does not exist
var exist = hapiMessage.fieldExists("NK1",0,3,1);
// exist = false

deleteFieldRepeat

// Input: NK1|1654|ROMINES^QUEENIE^19851010174850&19891023003156~YOUNGSTEAD^FARICA^19921011094736&20021010061819

hapiMessage.deleteFieldRepeat("NK1",0,2,1);

// Output: NK1|1654|ROMINES^QUEENIE^19851010174850&19891023003156
// Input: NK1|1654|ROMINES^QUEENIE^19851010174850&19891023003156~YOUNGSTEAD^FARICA^19921011094736&20021010061819

hapiMessage.deleteFieldRepeat("NK1",0,2,0);
 
// Output: NK1|1654|YOUNGSTEAD^FARICA^19921011094736&20021010061819

addSegment

// Input:
// MSH|^~\&|CANNS|CANNT|CANAB|CANNT|19871010031642||ADT^A01^ADT_A45|10215605xgfd|D^Not|2.1^23^14|6789||AL|AL|VCT||19|2.3
// NK1|1654|ROMINES^QUEENIE^19851010174850&19891023003156~YOUNGSTEAD^FARICA^19921011094736&20021010061819
// NK1|4567|WHORTON^CLODIA^19811016051025&19871015063310~FARLEY^JACQUELINE^19941010161033&19911010152916

// Creates the segment. The segment is not yet added
hapiMessage.addSegment("XYZ",1); 

// Output:
// MSH|^~\&|CANNS|CANNT|CANAB|CANNT|19871010031642||ADT^A01^ADT_A45|10215605xgfd|D^Not|2.1^23^14|6789||AL|AL|VCT||19|2.3
// NK1|1654|ROMINES^QUEENIE^19851010174850&19891023003156~YOUNGSTEAD^FARICA^19921011094736&20021010061819
// NK1|4567|WHORTON^CLODIA^19811016051025&19871015063310~FARLEY^JACQUELINE^19941010161033&19911010152916

// Populates the segment. The segment is added
hapiMessage.setValue("XYZ",0,1,0,1,1,"TEST");

// Output:
// MSH|^~\&|CANNS|CANNT|CANAB|CANNT|19871010031642||ADT^A01^ADT_A45|10215605xgfd|D^Not|2.1^23^14|6789||AL|AL|VCT||19|2.3
// XYZ|TEST
// NK1|1654|ROMINES^QUEENIE^19851010174850&19891023003156~YOUNGSTEAD^FARICA^19921011094736&20021010061819
// NK1|4567|WHORTON^CLODIA^19811016051025&19871015063310~FARLEY^JACQUELINE^19941010161033&19911010152916

addSegmentRepeat

// Input:
// MSH|^~\&|CANNS|CANNT|CANAB|CANNT|19871010031642||ADT^A01^ADT_A45|10215605xgfd|D^Not|2.1^23^14|6789||AL|AL|VCT||19|2.3
// NK1|1654|ROMINES^QUEENIE^19851010174850&19891023003156~YOUNGSTEAD^FARICA^19921011094736&20021010061819
// NK1|4567|WHORTON^CLODIA^19811016051025&19871015063310~FARLEY^JACQUELINE^19941010161033&19911010152916

// Creates the repeating segment. The segment is not yet added.
hapiMessage.addSegmentRepeat("NK1",1);

// Output:
// MSH|^~\&|CANNS|CANNT|CANAB|CANNT|19871010031642||ADT^A01^ADT_A45|10215605xgfd|D^Not|2.1^23^14|6789||AL|AL|VCT||19|2.3
// NK1|1654|ROMINES^QUEENIE^19851010174850&19891023003156~YOUNGSTEAD^FARICA^19921011094736&20021010061819
// NK1|4567|WHORTON^CLODIA^19811016051025&19871015063310~FARLEY^JACQUELINE^19941010161033&19911010152916

// Populates the segment. The segment is added
hapiMessage.setValue("NK1",1,1,0,1,1,"TEST"); 

// Output:
// MSH|^~\&|CANNS|CANNT|CANAB|CANNT|19871010031642||ADT^A01^ADT_A45|10215605xgfd|D^Not|2.1^23^14|6789||AL|AL|VCT||19|2.3
// NK1|1654|ROMINES^QUEENIE^19851010174850&19891023003156~YOUNGSTEAD^FARICA^19921011094736&20021010061819
// NK1|TEST
// NK1|4567|WHORTON^CLODIA^19811016051025&19871015063310~FARLEY^JACQUELINE^19941010161033&19911010152916

deleteSegment

// Input:
// MSH|^~\&|CANNS|CANNT|CANAB|CANNT|19871010031642||ADT^A01^ADT_A45|10215605xgfd|D^Not|2.1^23^14|6789||AL|AL|VCT||19|2.3
// NK1|1654|ROMINES^QUEENIE^19851010174850&19891023003156~YOUNGSTEAD^FARICA^19921011094736&20021010061819
// NK1|4567|WHORTON^CLODIA^19811016051025&19871015063310~FARLEY^JACQUELINE^19941010161033&19911010152916

hapiMessage.deleteSegment("NK1",1);

// Output:
// MSH|^~\&|CANNS|CANNT|CANAB|CANNT|19871010031642||ADT^A01^ADT_A45|10215605xgfd|D^Not|2.1^23^14|6789||AL|AL|VCT||19|2.3
// NK1|1654|ROMINES^QUEENIE^19851010174850&19891023003156~YOUNGSTEAD^FARICA^19921011094736&20021010061819
// Input:
// MSH|^~\&|CANNS|CANNT|CANAB|CANNT|19871010031642||ADT^A01^ADT_A45|10215605xgfd|D^Not|2.1^23^14|6789||AL|AL|VCT||19|2.3
// NK1|1654|ROMINES^QUEENIE^19851010174850&19891023003156~YOUNGSTEAD^FARICA^19921011094736&20021010061819
// NK1|4567|WHORTON^CLODIA^19811016051025&19871015063310~FARLEY^JACQUELINE^19941010161033&19911010152916

hapiMessage.deleteSegment("NK1",0);

// Output:
// MSH|^~\&|CANNS|CANNT|CANAB|CANNT|19871010031642||ADT^A01^ADT_A45|10215605xgfd|D^Not|2.1^23^14|6789||AL|AL|VCT||19|2.3
// NK1|4567|WHORTON^CLODIA^19811016051025&19871015063310~FARLEY^JACQUELINE^19941010161033&19911010152916

reparseHapiMessage

// Move existing segments in a message
 
// Input:
// MSH|^~\&|CANNS|CANNT|CANAB|CANNT|19871010031642||ADT^A01^ADT_A45|10215605xgfd|D^Not|2.1^23^14|6789||AL|AL|VCT||19|2.3
// ABC|abc
// XYZ|xyz

hapiMessage.deleteSegment("ABC",0);
hapiMessage.deleteSegment("XYZ",0);
hapiMessage.reparseHapiMessage();

// Output:
// MSH|^~\&|CANNS|CANNT|CANAB|CANNT|19871010031642||ADT^A01^ADT_A45|10215605xgfd|D^Not|2.1^23^14|6789||AL|AL|VCT||19|2.3

hapiMessage.addSegment("XYZ",1);
hapiMessage.setValue("XYZ",0,1,0,1,1,"xyz");
hapiMessage.addSegment("ABC",2);
hapiMessage.setValue("ABC",0,1,0,1,1,"abc");

// Output:
// MSH|^~\&|CANNS|CANNT|CANAB|CANNT|19871010031642||ADT^A01^ADT_A45|10215605xgfd|D^Not|2.1^23^14|6789||AL|AL|VCT||19|2.3
// XYZ|xyz
// ABC|abc