org.vmdb.hl7
Class HL7Segment

java.lang.Object
  |
  +--org.vmdb.hl7.HL7Object
        |
        +--org.vmdb.hl7.HL7Segment
Direct Known Subclasses:
CTDSegment, CTISegment, DSCSegment, ERRSegment, FT1Segment, MSASegment, MSHSegment, NK1Segment, NTESegment, OBRSegment, OBXSegment, ORCSegment, PD1Segment, PIDSegment, PV1Segment, PV2Segment, QAKSegment, QPDSegment, RCPSegment

public class HL7Segment
extends HL7Object

Base Class for All Types of HL7 Segments.

Description: HL7 Network Connectivity For VMDB.

Copyright: Copyright (c) 2002-2003.

Company: Veterinary Medical Database (VMDB).

A segment is a collection of related fields whose positions are specified in the segment rule. The primary function of the base class is to handle the complex processes of parsing and building segments from and to HL7 and XML. Each derived class provides a rule. The base class passes that rule to a RuleParser object which acts as a director with calls back to this object to read the input string, add fields, etc..

The base segment class also provides the mechanics for accessing fields by position based upon an index. Most of the class is made up of a huge variety of methods for getting, setting, and listing fields. These are normally intended to be used by derived classes to implement named accessor methods. In most cases, an application should use these higher-level set, get, and list methods that provide more segment and message specific access. The base getField() and setField() methods are made public to provide the ability to extend messages to any of the infinite possible variations allowed under HL7.


Constructor Summary
HL7Segment(HL7SegmentContainer msgParent)
          Construct a segment as part of a specific message or loop.
 
Method Summary
 void clearField(int iFieldNo)
          Clear the value in the specified field and remove any components and subcomponents.
 HL7Element getField(int iFieldNo)
          Get Field in Segment by position as named in HL7, i.e., 1 based index (zero is the segment name).
 java.lang.String getFieldValue(int iFieldNo)
          Get Field Value in Segment by position as named in HL7, i.e., 1 based index.
 java.util.Iterator iterator()
          Get an Iterator over the HL7Element derived objects that make up this segment.
 java.util.Iterator listFields(int iFieldNo)
          Get Iterator over all instances of a repeatable Field in Segment by position as named in HL7, i.e., 1 based index (zero is the segment name).
 void setField(HL7Element eField, int iFieldNo)
          Set the field at position specified to the HL7Element derived object provided.
 void setField(HL7Element eField, int iFieldNo, boolean bAdd)
          Set the field at position specified to the HL7Element derived object provided.
 void setField(HL7Element eField, java.lang.String sFieldName)
          Set the field at position specified to the HL7Element derived object provided.
 void setField(HL7Element eField, java.lang.String sFieldName, boolean bRepeatable)
          Set the field at position specified to the HL7Element derived object provided.
 void setField(java.lang.String sValue, int iFieldNo)
          Set the field at position specified to a SimpleElement with the value provided.
 void setField(java.lang.String sValue, int iFieldNo, boolean bAdd)
          Set the field at position specified to a SimpleElement with the value provided.
 void setField(java.lang.String sField, java.lang.String sFieldName)
          Set the field at position specified to a SimpleElement with the value provided.
 java.lang.String toString()
          Output this segment as an HL7 String.
 java.lang.String toXML(int iDepth)
          Output the this segment as XML.
 
Methods inherited from class org.vmdb.hl7.HL7Object
getRule
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

HL7Segment

public HL7Segment(HL7SegmentContainer msgParent)
Construct a segment as part of a specific message or loop.

Parameters:
msgParent - HL7SegmentContainer to allow this segment to make calls to its parent message or loop.
Method Detail

iterator

public java.util.Iterator iterator()
Get an Iterator over the HL7Element derived objects that make up this segment.

Returns:
Iterator over all the Elements in this segment.

toString

public java.lang.String toString()
Output this segment as an HL7 String.

Overrides:
toString in class java.lang.Object
Returns:
String with segment and all contained fields as delimited HL7.

toXML

public java.lang.String toXML(int iDepth)
Output the this segment as XML.

Output is the DOM element for that segment and all its contained objects.

Overrides:
toXML in class HL7Object
Parameters:
iDepth - int value for the number of spaces to indent this object. Used just to make the XML easier to read as unformatted text.
Returns:
foratted XML text.

setField

public void setField(HL7Element eField,
                     java.lang.String sFieldName,
                     boolean bRepeatable)
              throws java.lang.NumberFormatException,
                     java.lang.ArrayIndexOutOfBoundsException,
                     MalformedSegmentException
Set the field at position specified to the HL7Element derived object provided.

The following allow set and get by position and will be used by named segment subclasses for their setters and accessors. Based on HL7 field number i.e., 1 based index.

Parameters:
eField - The specific object to be inserted by reference.
sFieldName - String with field name based on segment and position. Example: "PID.3"
bRepeatable - Boolean true if this is a repeatable field.
Throws:
java.lang.NumberFormatException - if the string in sFieldName cannot be parsed to a string segment name plus a period and an integer.
java.lang.ArrayIndexOutOfBoundsException - if the field specified in sFieldName is either zero or less or greater than the number of fields.
MalformedSegmentException - if the HL7Element provided as eField does not have the type required by rule for this field or when attempting to add to a non-repeatable field.

setField

public void setField(HL7Element eField,
                     java.lang.String sFieldName)
              throws java.lang.NumberFormatException,
                     java.lang.ArrayIndexOutOfBoundsException,
                     MalformedSegmentException
Set the field at position specified to the HL7Element derived object provided.

The following allow set and get by position and will be used by named segment subclasses for their setters and accessors. Based on HL7 field number i.e., 1 based index.

Parameters:
eField - The specific object to be inserted by reference.
sFieldName - String with field name based on segment and position. Example: "PID.3"
Throws:
java.lang.NumberFormatException - if the string in sFieldName cannot be parsed to a string segment name plus a period and an integer.
java.lang.ArrayIndexOutOfBoundsException - if the field specified in sFieldName is either zero or less or greater than the number of fields.
MalformedSegmentException - if the HL7Element provided as eField does not have the type required by rule for this field.

setField

public void setField(java.lang.String sField,
                     java.lang.String sFieldName)
              throws java.lang.NumberFormatException,
                     java.lang.ArrayIndexOutOfBoundsException,
                     MalformedSegmentException
Set the field at position specified to a SimpleElement with the value provided.

The following allow set and get by position and will be used by named segment subclasses for their setters and accessors. Based on HL7 field number i.e., 1 based index.

Parameters:
sField - String value for any of the simple types.
sFieldName - String with field name based on segment and position. Example: "PID.3"
Throws:
java.lang.NumberFormatException - if the string in sFieldName cannot be parsed to a string segment name plus a period and an integer.
java.lang.ArrayIndexOutOfBoundsException - if the field specified in sFieldName is either zero or less or greater than the number of fields.
MalformedSegmentException - if the HL7Element provided as eField does not have the type required by rule for this field.

setField

public void setField(HL7Element eField,
                     int iFieldNo,
                     boolean bAdd)
              throws java.lang.ArrayIndexOutOfBoundsException,
                     MalformedSegmentException
Set the field at position specified to the HL7Element derived object provided.

The following allow set and get by position and will be used by named segment subclasses for their setters and accessors. Based on HL7 field number i.e., 1 based index.

Parameters:
eField - The specific object to be inserted by reference.
iFieldNo - Integer field number.
Throws:
java.lang.ArrayIndexOutOfBoundsException - if iFieldNo points to a field less than zero or greater than the number of fields allowed in the message rule
MalformedSegmentException - if the HL7Element provided as eField does not have the type required by rule for this field or when attempting to add to a non-repeatable field.

setField

public void setField(HL7Element eField,
                     int iFieldNo)
              throws java.lang.ArrayIndexOutOfBoundsException,
                     MalformedSegmentException
Set the field at position specified to the HL7Element derived object provided.

The following allow set and get by position and will be used by named segment subclasses for their setters and accessors. Based on HL7 field number i.e., 1 based index.

Parameters:
eField - The specific object to be inserted by reference.
iFieldNo - Integer field number.
Throws:
java.lang.ArrayIndexOutOfBoundsException - if iFieldNo points to a field less than zero or greater than the number of fields allowed in the message rule
MalformedSegmentException - if the HL7Element provided as eField does not have the type required by rule for this field.

setField

public void setField(java.lang.String sValue,
                     int iFieldNo,
                     boolean bAdd)
              throws java.lang.ArrayIndexOutOfBoundsException,
                     MalformedSegmentException
Set the field at position specified to a SimpleElement with the value provided.

The following allow set and get by position and will be used by named segment subclasses for their setters and accessors. Based on HL7 field number i.e., 1 based index.

Parameters:
iFieldNo - Integer field number.
bAdd - Boolean true to add rather than replace an existing value in a repeatable field.
Throws:
java.lang.ArrayIndexOutOfBoundsException - if iFieldNo points to a field less than zero or greater than the number of fields allowed in the message rule
MalformedSegmentException - if attempting to add to a non-repeatable field.

setField

public void setField(java.lang.String sValue,
                     int iFieldNo)
              throws java.lang.ArrayIndexOutOfBoundsException
Set the field at position specified to a SimpleElement with the value provided.

The following allow set and get by position and will be used by named segment subclasses for their setters and accessors. Based on HL7 field number i.e., 1 based index.

Parameters:
iFieldNo - Integer field number.
Throws:
java.lang.ArrayIndexOutOfBoundsException - if iFieldNo points to a field less than zero or greater than the number of fields allowed in the message rule

clearField

public void clearField(int iFieldNo)
                throws java.lang.ArrayIndexOutOfBoundsException
Clear the value in the specified field and remove any components and subcomponents.

Parameters:
iFieldNo - One based index (zero is the segment name) of field to clear.
Throws:
java.lang.ArrayIndexOutOfBoundsException - if iFieldNo points to a field less than zero or greater than the number of fields allowed in the message rule

getField

public HL7Element getField(int iFieldNo)
                    throws java.lang.ArrayIndexOutOfBoundsException
Get Field in Segment by position as named in HL7, i.e., 1 based index (zero is the segment name).

If this is a repeating field, returns the first value.

Parameters:
iFieldNo - One based index (zero is the segment name) of field.
Returns:
The element at position iFieldNo as an HL7Element derived object.
Throws:
java.lang.ArrayIndexOutOfBoundsException - if iFieldNo points to a field less than zero or greater than the number of fields allowed in the message rule

listFields

public java.util.Iterator listFields(int iFieldNo)
                              throws java.lang.ArrayIndexOutOfBoundsException
Get Iterator over all instances of a repeatable Field in Segment by position as named in HL7, i.e., 1 based index (zero is the segment name).

Parameters:
iFieldNo - One based index (zero is the segment name) of field.
Returns:
Iterator over the elements at position iFieldNo as an HL7Element derived objects.
Throws:
java.lang.ArrayIndexOutOfBoundsException - if iFieldNo points to a field less than zero or greater than the number of fields allowed in the message rule

getFieldValue

public java.lang.String getFieldValue(int iFieldNo)
                               throws java.lang.ArrayIndexOutOfBoundsException
Get Field Value in Segment by position as named in HL7, i.e., 1 based index.

Parameters:
iFieldNo - One based index (zero is the segment name) of field.
Returns:
String value of the field or the first componet of the field specified.
Throws:
java.lang.ArrayIndexOutOfBoundsException - if iFieldNo points to a field less than zero or greater than the number of fields allowed in the message rule

SourceForge.net Logo