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 SRT (sort order) data type.
019 * This type consists of the following components:</p>
020 * <ul>
021 * <li>sort-by field (ST)
022 * <li>sequencing (ID)
023 * </ul>
024 */
025 public class SRT extends AbstractType implements Composite {
026
027 private Type[] data;
028
029 /**
030 * Creates a new SRT type
031 */
032 public SRT(Message message) {
033 super(message);
034 init();
035 }
036
037 private void init() {
038 data = new Type[2];
039 data[0] = new ST(getMessage());
040 data[1] = new ID(getMessage(), 0);
041 }
042
043
044 /**
045 * Returns an array containing the data elements.
046 */
047 public Type[] getComponents() {
048 return this.data;
049 }
050
051 /**
052 * Returns an individual data component.
053 *
054 * @param number The component number (0-indexed)
055 * @throws DataTypeException if the given element number is out of range.
056 */
057 public Type getComponent(int number) throws DataTypeException {
058
059 try {
060 return this.data[number];
061 } catch (ArrayIndexOutOfBoundsException e) {
062 throw new DataTypeException("Element " + number + " doesn't exist (Type " + getClass().getName() + " has only " + this.data.length + " components)");
063 }
064 }
065
066
067 /**
068 * Returns sort-by field (component #1). This is a convenience method that saves you from
069 * casting and handling an exception.
070 */
071 public ST getSortByField() {
072 ST ret = null;
073 try {
074 ret = (ST)getComponent(0);
075 } catch (DataTypeException e) {
076 HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem accessing known data type component - this is a bug.", e);
077 throw new RuntimeException(e);
078 }
079 return ret;
080 }
081
082
083 /**
084 * Returns sort-by field (component #1). This is a convenience method that saves you from
085 * casting and handling an exception.
086 */
087 public ST getSrt1_SortByField() {
088 ST ret = null;
089 try {
090 ret = (ST)getComponent(0);
091 } catch (DataTypeException e) {
092 HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem accessing known data type component - this is a bug.", e);
093 throw new RuntimeException(e);
094 }
095 return ret;
096 }
097
098
099 /**
100 * Returns sequencing (component #2). This is a convenience method that saves you from
101 * casting and handling an exception.
102 */
103 public ID getSequencing() {
104 ID ret = null;
105 try {
106 ret = (ID)getComponent(1);
107 } catch (DataTypeException e) {
108 HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem accessing known data type component - this is a bug.", e);
109 throw new RuntimeException(e);
110 }
111 return ret;
112 }
113
114
115 /**
116 * Returns sequencing (component #2). This is a convenience method that saves you from
117 * casting and handling an exception.
118 */
119 public ID getSrt2_Sequencing() {
120 ID ret = null;
121 try {
122 ret = (ID)getComponent(1);
123 } catch (DataTypeException e) {
124 HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem accessing known data type component - this is a bug.", e);
125 throw new RuntimeException(e);
126 }
127 return ret;
128 }
129
130
131
132 }
133