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 "SegmentElement.java".  Description: 
10  "A structure for storing a single data element of a segment .." 
11  
12  The Initial Developer of the Original Code is University Health Network. Copyright (C) 
13  2001.  All Rights Reserved. 
14  
15  Contributor(s): ______________________________________. 
16  
17  Alternatively, the contents of this file may be used under the terms of the 
18  GNU General Public License (the  �GPL�), in which case the provisions of the GPL are 
19  applicable instead of those above.  If you wish to allow use of your version of this 
20  file only under the terms of the GPL and not to allow others to use your version 
21  of this file under the MPL, indicate your decision by deleting  the provisions above 
22  and replace  them with the notice and other provisions required by the GPL License.  
23  If you do not delete the provisions above, a recipient may use your version of 
24  this file under either the MPL or the GPL. 
25  
26   */
27  
28  package ca.uhn.hl7v2.sourcegen;
29  
30  /**
31   * A structure for storing a single data element of a segment ...
32   * 
33   * @author Bryan Tripp (bryan_tripp@sourceforge.net)
34   */
35  public class SegmentElement {
36  
37  	public String desc;
38  	public int field;
39  	public int length;
40  	private final int myIndexWithinSegment;
41  	private final String mySegmentName;
42  	private final String myVersion;
43  	public String opt;
44  	public String rep;
45  	public int repetitions;
46  	public int table;
47  	public String tableNamespace;
48  	public String type;
49  	private String myAlternateType;
50  
51  	/** Creates new SegmentElement */
52  	public SegmentElement(String theSegmentName, String theVersion, int theIndexWithinSegment) {
53  		mySegmentName = theSegmentName;
54  		myVersion = theVersion;
55  		myIndexWithinSegment = theIndexWithinSegment;
56  	}
57  
58  	public String getAccessorName() {
59  		return SourceGenerator.makeAccessorName(desc, mySegmentName);
60  	}
61  
62  	public String getAlternateAccessorName() {
63  		return SourceGenerator.makeAlternateAccessorName(desc, mySegmentName, myIndexWithinSegment + 1);
64  	}
65  
66  	public String getAlternateType() {
67  		if (myAlternateType != null) {
68  			return myAlternateType;
69  		}
70  		return SourceGenerator.getAlternateType(type, myVersion);
71  	}
72  
73  	/**
74  	 * @param theAlternateType the alternateType to set
75  	 */
76  	public void setAlternateType(String theAlternateType) {
77  		myAlternateType = theAlternateType;
78  	}
79  
80  	public String getDesc() {
81  		return desc;
82  	}
83  
84  	public String getDescEscaped() {
85  		return desc.replace("\"", "\\\"");
86  	}
87  
88  	public int getField() {
89  		return field;
90  	}
91  
92  	public int getLength() {
93  		return length;
94  	}
95  
96  	public int getRepetitions() {
97  		return repetitions;
98  	}
99  
100 	public int getTable() {
101 		return table;
102 	}
103 
104 	/**
105 	 * @return the tableNamespace
106 	 */
107 	public String getTableNamespace() {
108 		return tableNamespace;
109 	}
110 
111 	/**
112 	 * @return the tableNamespace
113 	 */
114 	public String getTableNamespaceInQuotes() {
115 		return '"' + tableNamespace + '"';
116 	}
117 
118 	/**
119 	 * @return the tableNamespace
120 	 */
121 	public boolean isHasTableNamespace() {
122 		return tableNamespace != null && tableNamespace.length() > 0;
123 	}
124 
125 	public String getType() {
126 		return type;
127 	}
128 
129 	public boolean isIdType() {
130 		return (type.equals("ID") || type.equals("IS"));
131 	}
132 
133 	public boolean isRepeating() {
134 		return repetitions != 1;
135 	}
136 
137 	public boolean isRequired() {
138 		return "R".equalsIgnoreCase(opt);
139 	}
140 
141 	/**
142 	 * @param theTableNamespace
143 	 *            the tableNamespace to set
144 	 */
145 	public void setTableNamespace(String theTableNamespace) {
146 		tableNamespace = theTableNamespace;
147 	}
148 }