View Javadoc
1   /*
2    * To change this template, choose Tools | Templates
3    * and open the template in the editor.
4    */
5   
6   package ca.uhn.hl7v2.examples.custommodel.v25.message;
7   
8   import ca.uhn.hl7v2.HL7Exception;
9   import ca.uhn.hl7v2.examples.custommodel.v25.segment.ZPI;
10  import ca.uhn.hl7v2.model.v25.message.ADT_A01;
11  import ca.uhn.hl7v2.parser.DefaultModelClassFactory;
12  import ca.uhn.hl7v2.parser.ModelClassFactory;
13  import java.util.Arrays;
14  
15  /**
16   * Example custom model class. This is a ZDT^A01, which is an ADT^A01 with an
17   * extra ZPI segment after the PID segment
18   * 
19   * Since we're extending an existing HL7 message type, we just extend from the
20   * model class representing that type
21   */
22  @SuppressWarnings("serial")
23  public class ZDT_A01 extends ADT_A01 {
24  
25     /**
26      * Constructor
27      */
28     public ZDT_A01() throws HL7Exception {
29        this(new DefaultModelClassFactory());
30     }
31  
32     /**
33      * Constructor
34      * 
35      * We always have to have a constructor with this one argument
36      */
37     public ZDT_A01(ModelClassFactory factory) throws HL7Exception {
38        super(factory);
39  
40        // Now, let's add the ZPI segment at the right spot
41        String[] segmentNames = getNames();
42        int indexOfPid = Arrays.asList(segmentNames).indexOf("PID");
43  
44        // Put the ZPI segment right after the PID segment
45        int index = indexOfPid + 1;
46  
47        Class<ZPI> type = ZPI.class;
48        boolean required = true;
49        boolean repeating = false;
50  
51        this.add(type, required, repeating, index);
52     }
53  
54     /**
55      * Add an accessor for the ZPI segment
56      */
57     public ZPI getZPI() {
58        return getTyped("ZPI", ZPI.class);
59     }
60  
61  }