View Javadoc

1   /*
2    * To change this template, choose Tools | Templates
3    * and open the template in the editor.
4    */
5   package ca.uhn.hl7v2.examples.custommodel.v25.segment;
6   
7   import ca.uhn.hl7v2.HL7Exception;
8   import ca.uhn.hl7v2.model.AbstractSegment;
9   import ca.uhn.hl7v2.model.Group;
10  import ca.uhn.hl7v2.model.Type;
11  import ca.uhn.hl7v2.model.v25.datatype.NM;
12  import ca.uhn.hl7v2.model.v25.datatype.ST;
13  import ca.uhn.hl7v2.parser.ModelClassFactory;
14  
15  /**
16   * ZPI custom segment example
17   *
18   * Note that custom segments extend from {@link AbstractSegment}
19   */
20  public class ZPI extends AbstractSegment {
21  
22      /**
23       * Adding a serial UID is always a good idea, but optional
24       */
25      private static final long serialVersionUID = 1;
26  
27      public ZPI(Group parent, ModelClassFactory factory) {
28          super(parent, factory);
29          
30          // By convention, an init() method is created which adds
31          // the specific fields to this segment class
32          init(factory);
33       }
34  
35       private void init(ModelClassFactory factory) {
36          try {
37          	/*
38          	 * For each field in the custom segment, the add() method is
39          	 * called once. In this example, there are two fields in
40          	 * the ZPI segment.
41          	 * 
42          	 * See here for information on the arguments to this method:
43          	 * http://hl7api.sourceforge.net/base/apidocs/ca/uhn/hl7v2/model/AbstractSegment.html#add%28java.lang.Class,%20boolean,%20int,%20int,%20java.lang.Object[],%20java.lang.String%29
44          	 */
45          	add(ST.class, true, 0, 100, new Object[]{ getMessage() }, "Pet Name(s)");
46          	add(NM.class, false, 1, 4, new Object[]{ getMessage() }, "Shoe Size");
47          } catch (HL7Exception e) {
48              log.error("Unexpected error creating ZPI - this is probably a bug in the source code generator.", e);
49          }
50       }
51  
52      /**
53       * This method must be overridden. The easiest way is just to return null.
54       */
55      @Override
56      protected Type createNewTypeWithoutReflection(int field) {
57          return null;
58      }
59  
60      /**
61       * Create an accessor for each field
62       */
63      public ST[] getPetName() throws HL7Exception {
64      	return getTypedField(1, new ST[0]);
65      }
66  
67      /**
68       * Create an accessor for each field
69       */
70      public NM getShoeSize() throws HL7Exception {
71      	return getTypedField(2, 0);
72      }
73  
74  }