001 /*
002 * This class is an auto-generated source file for a HAPI
003 * HL7 v2.x standard structure class.
004 *
005 * For more information, visit: http://hl7api.sourceforge.net/
006 */
007
008 package ca.uhn.hl7v2.model.v24.datatype;
009
010 import ca.uhn.hl7v2.model.Composite;
011 import ca.uhn.hl7v2.model.DataTypeException;
012 import ca.uhn.hl7v2.model.Message;
013 import ca.uhn.hl7v2.model.Type;
014 import ca.uhn.hl7v2.model.AbstractType;
015 import ca.uhn.log.HapiLogFactory;
016
017 /**
018 * <p>Represents an HL7 HD (hierarchic designator) data type.
019 * This type consists of the following components:</p>
020 * <ul>
021 * <li>namespace ID (IS)
022 * <li>universal ID (ST)
023 * <li>universal ID type (ID)
024 * </ul>
025 */
026 public class HD extends AbstractType implements Composite {
027
028 private Type[] data;
029
030 /**
031 * Creates a new HD type
032 */
033 public HD(Message message) {
034 super(message);
035 init();
036 }
037
038 private void init() {
039 data = new Type[3];
040 data[0] = new IS(getMessage(), 300);
041 data[1] = new ST(getMessage());
042 data[2] = new ID(getMessage(), 301);
043 }
044
045
046 /**
047 * Returns an array containing the data elements.
048 */
049 public Type[] getComponents() {
050 return this.data;
051 }
052
053 /**
054 * Returns an individual data component.
055 *
056 * @param number The component number (0-indexed)
057 * @throws DataTypeException if the given element number is out of range.
058 */
059 public Type getComponent(int number) throws DataTypeException {
060
061 try {
062 return this.data[number];
063 } catch (ArrayIndexOutOfBoundsException e) {
064 throw new DataTypeException("Element " + number + " doesn't exist (Type " + getClass().getName() + " has only " + this.data.length + " components)");
065 }
066 }
067
068
069 /**
070 * Returns namespace ID (component #1). This is a convenience method that saves you from
071 * casting and handling an exception.
072 */
073 public IS getNamespaceID() {
074 IS ret = null;
075 try {
076 ret = (IS)getComponent(0);
077 } catch (DataTypeException e) {
078 HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem accessing known data type component - this is a bug.", e);
079 throw new RuntimeException(e);
080 }
081 return ret;
082 }
083
084
085 /**
086 * Returns namespace ID (component #1). This is a convenience method that saves you from
087 * casting and handling an exception.
088 */
089 public IS getHd1_NamespaceID() {
090 IS ret = null;
091 try {
092 ret = (IS)getComponent(0);
093 } catch (DataTypeException e) {
094 HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem accessing known data type component - this is a bug.", e);
095 throw new RuntimeException(e);
096 }
097 return ret;
098 }
099
100
101 /**
102 * Returns universal ID (component #2). This is a convenience method that saves you from
103 * casting and handling an exception.
104 */
105 public ST getUniversalID() {
106 ST ret = null;
107 try {
108 ret = (ST)getComponent(1);
109 } catch (DataTypeException e) {
110 HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem accessing known data type component - this is a bug.", e);
111 throw new RuntimeException(e);
112 }
113 return ret;
114 }
115
116
117 /**
118 * Returns universal ID (component #2). This is a convenience method that saves you from
119 * casting and handling an exception.
120 */
121 public ST getHd2_UniversalID() {
122 ST ret = null;
123 try {
124 ret = (ST)getComponent(1);
125 } catch (DataTypeException e) {
126 HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem accessing known data type component - this is a bug.", e);
127 throw new RuntimeException(e);
128 }
129 return ret;
130 }
131
132
133 /**
134 * Returns universal ID type (component #3). This is a convenience method that saves you from
135 * casting and handling an exception.
136 */
137 public ID getUniversalIDType() {
138 ID ret = null;
139 try {
140 ret = (ID)getComponent(2);
141 } catch (DataTypeException e) {
142 HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem accessing known data type component - this is a bug.", e);
143 throw new RuntimeException(e);
144 }
145 return ret;
146 }
147
148
149 /**
150 * Returns universal ID type (component #3). This is a convenience method that saves you from
151 * casting and handling an exception.
152 */
153 public ID getHd3_UniversalIDType() {
154 ID ret = null;
155 try {
156 ret = (ID)getComponent(2);
157 } catch (DataTypeException e) {
158 HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem accessing known data type component - this is a bug.", e);
159 throw new RuntimeException(e);
160 }
161 return ret;
162 }
163
164
165
166 }
167