You are here: Jython Script Interfaces > HL7Segment

HL7Segment

 

An instance of this class represents one segment of a pipe-delimited HL7 message. HL7Message objects are made up of one or more instances of this class. Instances of this segment class are generally not useful by themselves, unless they are retrieved from or added to a message object. See HL7Message.

You can create an instance of this class by calling:

util.makeHL7Segment("ZYX", 3) # (to create a segment with 3 empty fields, initially.)

or

util.makeHL7Segment("ZYX|a|b|c").

Functions

HL7Segment clone()

Returns

a copy of this segment.

string getComponent(fieldLocation, int componentIndex)

Returns the value of the specified component.

Parameters

fieldLocation - May be either an integer (a 1-based field index) or an (int,int) tuple (a 1-based field index and a 1-based field repetition index - eg. (3,2) or (3,-1) for last repetition of third field).

string getAllComponents(fieldLocation)

Returns the value of all components in the specified field. On a message like 'MSH|^~\&|one^two~three^four',

getAllComponents("MSH", 3) will return 'one^two', and

getAllComponents("MSH", (3, 2)) will return 'three^four'.

Parameters

fieldLocation - May be either an integer (a 1-based field index) or an (int,int) tuple (a 1-based field index and a 1-based field repetition index - eg. (3,2) or (3,-1) for last repetition of third field).

string getField(fieldLocation)

Returns the value of the specified field. Unlike setField() does with its input value, this method will not return multiple components or repetitions. On a message like 'MSH|^~\&|one^two~three^four',

getField("MSH", 3) will return 'one', and

getField("MSH", (3, 2)) will return 'three'.

Parameters

fieldLocation - May be either an integer (a 1-based field index) or an (int,int) tuple (a 1-based field index and a 1-based field repetition index - eg. (3,2) or (3,-1) for last repetition of third field).

string getAllFieldRepetitions(fieldLocation)

Returns the value of all repetitions of the specified field. On a message like 'MSH|^~\&|one^two~three^four',

getAllFieldRepetitions("MSH", 3) will return 'one^two~three^four'.

Parameters

fieldLocation - May be either an integer (a 1-based field index) or an (int,int) tuple (a 1-based field index and a 1-based field repetition index - eg. (3,2) or (3,-1) for last repetition of third field).

list of strings getAllFieldRepetitionsAsList(fieldLocation)

Returns the value of all repetitions of the specified field as a list of strings. On a message like 'MSH|^~\&|one^two~three^four',

getAllFieldRepetitions("MSH", 3) will return ['one^two', 'three^four'].

Parameters

fieldLocation - May be either an integer (a 1-based field index) or an (int,int) tuple (a 1-based field index and a 1-based field repetition index - eg. (3,2) or (3,-1) for last repetition of third field).

string getId()

Returns

the ID of this segment. eg. 'MSH', 'EVN', etc.

int numComponents(fieldLocation)

Parameters

fieldLocation - May be either an integer (a 1-based field index) or an (int,int) tuple (a 1-based field index and a 1-based field repetition index - eg. (3,2) or (3,-1) for last repetition of third field).

Returns

the number of components that the specified field (and repetition) contains, or 0 if the specified field (and repetition) does not exist.

int numFieldRepetitions(int fieldIdx)

Returns

the number of repetitions that the specified field contains, or 0 if the specified field does not exist.

Grammatically speaking, the returned value does not represent the number of repetitions -- eg. for a segment like ZYX|one|two~two|, field 1 clearly does not repeat, so one could say that it has 0 repetitions. But the way we count, we still say (and this method still returns) that it has one repetition.

int numFields()

Returns

the number of fields in this segment. "field 0" (i.e. the segment ID) does not count towards this total.

void removeComponent(fieldLocation, int componentIdx)

Remove the specified component and all subsequent components in the specified field (+ repetition). If the specified component does not exist, then do nothing. If component 1 is specified then it is cleared, not removed.

Parameters

fieldLocation - May be either an integer (a 1-based field index) or an (int,int) tuple (a 1-based field index and a 1-based field repetition index - eg. (3,2) or (3,-1) for last repetition of third field).

void removeField(int fieldIdx)

Remove the specified field and all subsequent fields in the specified segment.

If the specified field does not exist, then do nothing.

void removeFieldRepetition(fieldLocation)

Remove the specified field repetition and all subsequent field repetitions in the specified field. If the specified field repetition does not exist, then do nothing. If repetition 1 is specified then it is cleared, not removed.

Parameters

fieldLocation - May be either an integer (a 1-based field index) or an (int,int) tuple (a 1-based field index and a 1-based field repetition index - eg. (3,2) or (3,-1) for last repetition of third field).

void setComponent(string newComponentValue, fieldLocation, int componentIndex)

Sets the specified component to the specified value.

Parameters

newComponentValue - may contain subcomponent delimiters (typically "&") if desired. These characters are not treated specially; since this class does not go down to the subcomponent level, the only way to insert subcomponents into a message is to include subcomponent delimiters as part of a component value.

fieldLocation - May be either an integer (a 1-based field index) or an (int,int) tuple (a 1-based field index and a 1-based field repetition index - eg. (3,2) or (3,-1) for last repetition of third field).

void setField(string newFieldValue, fieldLocation)

Set the specified field to the specified value.

Parameters

newFieldValue - If fieldLocation doesn't identify a field repetition then this method will overwrite the entire specified field, including all field repetitions and components within. (Naturally this argument can contain field repetition and component delimiters in this case.)

If fieldLocation does identify a field repetition then this method will only overwrite the specified field repetition and any components within it -- other repetitions will not be modified. (Naturally this argument can contain component delimiters, but not field repetition delimiters, in this case.)

Also, this argument may contain subcomponent delimiters (typically "&") if desired. These characters are not treated specially; since this class does not go down to the subcomponent level, the only way to insert subcomponents into a message is to include subcomponent delimiters as part of a component value.

fieldLocation - May be either an integer (a 1-based field index) or an (int,int) tuple (a 1-based field index and a 1-based field repetition index - eg. (3,2) or (3,-1) for last repetition of third field).

string toString()

Returns

a string version of the segment. This is the reverse of creating an object with util.makeHL7Segment(textvar).

list of integers getFieldRepetitionNums(int fieldIndex)

Returns a list of field repetition indices which are convenient for writing loops. For example:

for repNum in segment.getFieldRepetitionNums(4):
  print segment.getAllComponents((4,repNum))

Returns

a list of integers, which are 1-based field repetition indices.

 

int getSegmentPositionWithinMessage()

Returns

the absolute index of this segment within it's owner message. If this segment does not belong to a message, an exception is thrown.