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