View Javadoc
1   /**
2   The contents of this file are subject to the Mozilla Public License Version 1.1 
3   (the "License"); you may not use this file except in compliance with the License. 
4   You may obtain a copy of the License at http://www.mozilla.org/MPL/ 
5   Software distributed under the License is distributed on an "AS IS" basis, 
6   WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the 
7   specific language governing rights and limitations under the License. 
8   
9   The Original Code is "Segment.java".  Description: 
10  "Represents an HL7 message segment, which is a unit of data that contains multiple fields.
11  @author Bryan Tripp (bryan_tripp@sourceforge.net)" 
12  
13  The Initial Developer of the Original Code is University Health Network. Copyright (C) 
14  2001.  All Rights Reserved. 
15  
16  Contributor(s): ______________________________________. 
17  
18  Alternatively, the contents of this file may be used under the terms of the 
19  GNU General Public License (the  �GPL�), in which case the provisions of the GPL are 
20  applicable instead of those above.  If you wish to allow use of your version of this 
21  file only under the terms of the GPL and not to allow others to use your version 
22  of this file under the MPL, indicate your decision by deleting  the provisions above 
23  and replace  them with the notice and other provisions required by the GPL License.  
24  If you do not delete the provisions above, a recipient may use your version of 
25  this file under either the MPL or the GPL. 
26  
27   */
28  package ca.uhn.hl7v2.model;
29  
30  import ca.uhn.hl7v2.HL7Exception;
31  
32  /**
33   * Represents an HL7 message segment, which is a unit of data that contains multiple fields.
34   * @author Bryan Tripp (bryan_tripp@sourceforge.net)
35   */
36  public interface Segment extends Structure {
37  
38      /**
39       * Encodes this message using the parser returned by {@link Message#getParser() }
40       *
41       * @return the string-encoded segment
42       * @throws HL7Exception if errors occurred during encoding
43       */
44      String encode() throws HL7Exception;
45  
46      /**
47       * Returns the array of Fields at the specified index.  The array will be of length 1 for
48       * non-repeating fields, and >1 for repeating fields.  Fields are numbered from 1.
49       *
50       * @param number field number (starting at 1)
51       * @return the array of Fields at the specified field number
52       * @throws HL7Exception if field index is out of range.
53       */
54      Type[] getField(int number) throws HL7Exception;
55  
56      /**
57       * Returns a specific repetition of field at the specified index.  If there exist
58       * fewer repetitions than are required, the number of repetitions can be increased
59       * by specifying the lowest repetition that does not yet exist.  For example
60       * if there are two repetitions but three are needed, the third can be created
61       * and accessed using the following code: <br>
62       * <code>Type t = getField(x, 2);</code>
63       * @param number the field number (starting at 1)
64       * @param rep the repetition number (starting at 0)
65       * @return field at the specified field number and repetition
66       * @throws HL7Exception if field index is out of range, or if the specified
67       *    repetition is more than 1 greater than the highest index of existing repetitions.
68       *    NOTE: to facilitate local extensions, no exception is thrown if
69       *    rep > max cardinality
70       */
71      Type getField(int number, int rep) throws HL7Exception;
72  
73      /**
74       * Returns the maximum length of the field at the given index, in characters.
75       * @param number field number starting at 1
76       * @return maximum length of the field
77       * @throws HL7Exception if field index is out of range.
78       */
79      int getLength(int number) throws HL7Exception;
80  
81      /**
82       * Returns the maximum number of repetitions of this field that are allowed.
83       * The current cardinality can be obtained by checking the length
84       * of the array returned by getLength(n).
85       * @param number field number starting at 1
86       * @return maximum number of repetitions of this field
87       * @throws HL7Exception if field index is out of range.
88       */
89      int getMaxCardinality(int number) throws HL7Exception;
90  
91      /**
92       * Returns the names of the fields in this segment.
93       * @return array of names
94       *
95       * @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.
96       */
97      String[] getNames();
98  
99      /**
100      * Returns true if the field at the given index is required, false otherwise.
101      *
102      * @param number field number starting at 1
103      * @return true if the field is required
104      * @throws HL7Exception if field index is out of range.
105      */
106     boolean isRequired(int number) throws HL7Exception;
107 
108 
109     /**
110      * Returns the number of fields defined by this segment (repeating
111      * fields are not counted multiple times).
112      * @return number of fields
113      */
114     int numFields();
115 
116 
117     /**
118      * Parses the string into this segment using the parser returned by {@link Message#getParser() }
119      * @param string encoded segment
120      * @throws HL7Exception if errors occurred during parsing
121      */
122     void parse(String string) throws HL7Exception;
123 
124     
125 }