View Javadoc
1   /*
2    * Copyright 2016 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *       http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.openehealth.ipf.commons.ihe.hl7v2.definitions.pam.v25.segment;
17  
18  import ca.uhn.hl7v2.HL7Exception;
19  import ca.uhn.hl7v2.model.AbstractSegment;
20  import ca.uhn.hl7v2.model.Group;
21  import ca.uhn.hl7v2.model.Message;
22  import ca.uhn.hl7v2.model.v25.datatype.NM;
23  import ca.uhn.hl7v2.model.v25.datatype.ST;
24  import ca.uhn.hl7v2.parser.ModelClassFactory;
25  import org.openehealth.ipf.modules.hl7.HL7v2Exception;
26  
27  /**
28   * The ZZI segment is intended to be used for information that support distributed
29   * tracing across system boundaries using Zipkin. Also see http://zipkin.io/pages/instrumenting.html
30   * for details
31   * 
32   * @author Christian Ohr
33   */
34  @SuppressWarnings("serial")
35  public class ZZI extends AbstractSegment {
36  
37      /**
38       * @param parent
39       * @param factory
40       */
41      public ZZI(Group parent, ModelClassFactory factory) {
42          super(parent, factory);
43          Message message = getMessage();
44          try {
45              add(ST.class, true, 1, 8, new Object[] { message }, "Trace ID");
46              add(ST.class, true, 1, 8, new Object[] { message }, "Span ID");
47              add(ST.class, false, 1, 8, new Object[] { message }, "Parent Span ID");
48              add(NM.class, false, 1, 1, new Object[] { message }, "Sampled");
49              add(NM.class, false, 1, 1, new Object[] { message }, "Flag");
50          } catch (HL7Exception he) {
51              throw new HL7v2Exception(he);
52          }
53      }
54  
55      /**
56       * Returns trace ID (ZZI-1).
57       *
58       * @return trace ID
59       */
60      public ST getTraceID() {
61          return getTypedField(1, 0);
62      }
63  
64      /**
65       * Returns span ID (ZZI-2).
66       *
67       * @return span ID
68       */
69      public ST getSpanID() {
70          return getTypedField(2, 0);
71      }
72  
73      /**
74       * Returns parent span ID (ZZI-3).
75       *
76       * @return parent span ID
77       */
78      public ST getParentSpanID() {
79          return getTypedField(3, 0);
80      }
81  
82      /**
83       * Returns the flag whether this span is to be sampled (ZZI-4).
84       *
85       * @return sample indicator
86       */
87      public NM getSampled() {
88          return getTypedField(4, 0);
89      }
90  
91      /**
92       * Returns flag whether debugging shall be turned on (ZZI-5).
93       *
94       * @return debug flag
95       */
96      public NM getFlags() {
97          return getTypedField(5, 0);
98      }
99  
100 }