001/** 002The contents of this file are subject to the Mozilla Public License Version 1.1 003(the "License"); you may not use this file except in compliance with the License. 004You may obtain a copy of the License at http://www.mozilla.org/MPL/ 005Software distributed under the License is distributed on an "AS IS" basis, 006WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the 007specific language governing rights and limitations under the License. 008 009The Original Code is "Segment.java". Description: 010"Represents an HL7 message segment, which is a unit of data that contains multiple fields. 011@author Bryan Tripp (bryan_tripp@sourceforge.net)" 012 013The Initial Developer of the Original Code is University Health Network. Copyright (C) 0142001. All Rights Reserved. 015 016Contributor(s): ______________________________________. 017 018Alternatively, the contents of this file may be used under the terms of the 019GNU General Public License (the �GPL�), in which case the provisions of the GPL are 020applicable instead of those above. If you wish to allow use of your version of this 021file only under the terms of the GPL and not to allow others to use your version 022of this file under the MPL, indicate your decision by deleting the provisions above 023and replace them with the notice and other provisions required by the GPL License. 024If you do not delete the provisions above, a recipient may use your version of 025this file under either the MPL or the GPL. 026 027 */ 028package ca.uhn.hl7v2.model; 029 030import ca.uhn.hl7v2.HL7Exception; 031 032/** 033 * Represents an HL7 message segment, which is a unit of data that contains multiple fields. 034 * @author Bryan Tripp (bryan_tripp@sourceforge.net) 035 */ 036public interface Segment extends Structure { 037 038 /** 039 * Encodes this message using the parser returned by {@link Message#getParser() } 040 */ 041 public String encode() throws HL7Exception; 042 043 /** 044 * Returns the array of Fields at the specified index. The array will be of length 1 for 045 * non-repeating fields, and >1 for repeating fields. Fields are numbered from 1. 046 * @throws HL7Exception if field index is out of range. 047 */ 048 public Type[] getField(int number) throws HL7Exception; 049 050 /** 051 * Returns a specific repetition of field at the specified index. If there exist 052 * fewer repetitions than are required, the number of repetitions can be increased 053 * by specifying the lowest repetition that does not yet exist. For example 054 * if there are two repetitions but three are needed, the third can be created 055 * and accessed using the following code: <br> 056 * <code>Type t = getField(x, 2);</code> 057 * @param number the field number (starting at 1) 058 * @param rep the repetition number (starting at 0) 059 * @throws HL7Exception if field index is out of range, or if the specified 060 * repetition is more than 1 greater than the highest index of existing repetitions. 061 * NOTE: to facilitate local extensions, no exception is thrown if 062 * rep > max cardinality 063 */ 064 public Type getField(int number, int rep) throws HL7Exception; 065 066 /** 067 * Returns the maximum length of the field at the given index, in characters. 068 * @throws HL7Exception if field index is out of range. 069 */ 070 public int getLength(int number) throws HL7Exception; 071 072 /** 073 * Returns the maximum number of repetitions of this field that are allowed. 074 * The current cardinality can be obtained by checking the length 075 * of the array returned by getLength(n). 076 * @throws HL7Exception if field index is out of range. 077 */ 078 public int getMaxCardinality(int number) throws HL7Exception; 079 080 /** 081 * Returns the names of the fields in this segment. 082 * 083 * @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. 084 */ 085 public String[] getNames(); 086 087 /** 088 * Returns true if the field at the given index is required, false otherwise. 089 * @throws HL7Exception if field index is out of range. 090 */ 091 public boolean isRequired(int number) throws HL7Exception; 092 093 094 /** 095 * Returns the number of fields defined by this segment (repeating 096 * fields are not counted multiple times). 097 */ 098 public int numFields(); 099 100 101 /** 102 * Parses the string into this segment using the parser returned by {@link Message#getParser() } 103 */ 104 public void parse(String string) throws HL7Exception; 105 106 107}