Interface Segment

All Superinterfaces:
Serializable, Structure, Visitable
All Known Implementing Classes:
AbstractSegment, GenericSegment

public interface Segment extends Structure
Represents an HL7 message segment, which is a unit of data that contains multiple fields.
Author:
Bryan Tripp (bryan_tripp@sourceforge.net)
  • Method Summary

    Modifier and Type
    Method
    Description
    Encodes this message using the parser returned by Message.getParser()
    getField(int number)
    Returns the array of Fields at the specified index.
    getField(int number, int rep)
    Returns a specific repetition of field at the specified index.
    int
    getLength(int number)
    Returns the maximum length of the field at the given index, in characters.
    int
    getMaxCardinality(int number)
    Returns the maximum number of repetitions of this field that are allowed.
    Returns the names of the fields in this segment.
    boolean
    isRequired(int number)
    Returns true if the field at the given index is required, false otherwise.
    int
    Returns the number of fields defined by this segment (repeating fields are not counted multiple times).
    void
    parse(String string)
    Parses the string into this segment using the parser returned by Message.getParser()

    Methods inherited from interface ca.uhn.hl7v2.model.Structure

    getMessage, getName, getParent

    Methods inherited from interface ca.uhn.hl7v2.model.Visitable

    accept, isEmpty, provideLocation
  • Method Details

    • encode

      Encodes this message using the parser returned by Message.getParser()
      Returns:
      the string-encoded segment
      Throws:
      HL7Exception - if errors occurred during encoding
    • getField

      Type[] getField(int number) throws HL7Exception
      Returns the array of Fields at the specified index. The array will be of length 1 for non-repeating fields, and >1 for repeating fields. Fields are numbered from 1.
      Parameters:
      number - field number (starting at 1)
      Returns:
      the array of Fields at the specified field number
      Throws:
      HL7Exception - if field index is out of range.
    • getField

      Type getField(int number, int rep) throws HL7Exception
      Returns a specific repetition of field at the specified index. If there exist fewer repetitions than are required, the number of repetitions can be increased by specifying the lowest repetition that does not yet exist. For example if there are two repetitions but three are needed, the third can be created and accessed using the following code:
      Type t = getField(x, 2);
      Parameters:
      number - the field number (starting at 1)
      rep - the repetition number (starting at 0)
      Returns:
      field at the specified field number and repetition
      Throws:
      HL7Exception - if field index is out of range, or if the specified repetition is more than 1 greater than the highest index of existing repetitions. NOTE: to facilitate local extensions, no exception is thrown if rep > max cardinality
    • getLength

      int getLength(int number) throws HL7Exception
      Returns the maximum length of the field at the given index, in characters.
      Parameters:
      number - field number starting at 1
      Returns:
      maximum length of the field
      Throws:
      HL7Exception - if field index is out of range.
    • getMaxCardinality

      int getMaxCardinality(int number) throws HL7Exception
      Returns the maximum number of repetitions of this field that are allowed. The current cardinality can be obtained by checking the length of the array returned by getLength(n).
      Parameters:
      number - field number starting at 1
      Returns:
      maximum number of repetitions of this field
      Throws:
      HL7Exception - if field index is out of range.
    • getNames

      Returns the names of the fields in this segment.
      Returns:
      array of names
      Since:
      1.0 - Note that if user defined types are being used, there is a possibility that some entries may be null. All official hapi structures will have all entries populated, but older user defined structures may not have populated all values, since this feature did not exist prior to release 1.0.
    • isRequired

      boolean isRequired(int number) throws HL7Exception
      Returns true if the field at the given index is required, false otherwise.
      Parameters:
      number - field number starting at 1
      Returns:
      true if the field is required
      Throws:
      HL7Exception - if field index is out of range.
    • numFields

      int numFields()
      Returns the number of fields defined by this segment (repeating fields are not counted multiple times).
      Returns:
      number of fields
    • parse

      void parse(String string) throws HL7Exception
      Parses the string into this segment using the parser returned by Message.getParser()
      Parameters:
      string - encoded segment
      Throws:
      HL7Exception - if errors occurred during parsing