1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 package ca.uhn.hl7v2.testpanel.model.conf;
27
28 import ca.uhn.hl7v2.HL7Exception;
29 import ca.uhn.hl7v2.conf.spec.message.SegGroup;
30 import ca.uhn.hl7v2.model.AbstractGroup;
31 import ca.uhn.hl7v2.model.GenericSegment;
32 import ca.uhn.hl7v2.model.Group;
33 import ca.uhn.hl7v2.model.Message;
34 import ca.uhn.hl7v2.model.Structure;
35
36 public class ConformanceGroup extends AbstractGroup implements ConformanceStructure<ConformanceGroup>, ConformanceStructureHolder {
37
38 private SegGroup myConfDefinition;
39
40 private ConformanceStructureHolderSupport mySupport;
41
42 public ConformanceGroup(Group theParent, SegGroup theConfDefinition) {
43 super(theParent, (((ConformanceMessage) theParent.getMessage()).getModelClassFactory()));
44
45 mySupport = new ConformanceStructureHolderSupport(this, theConfDefinition);
46 myConfDefinition = theConfDefinition;
47 }
48
49 public ConformanceGroup(Message theMessage, ConformanceStructureHolderSupport theSupport, SegGroup theConfDefinition) {
50 this(theMessage, theConfDefinition);
51
52 myConfDefinition = theConfDefinition;
53 mySupport = theSupport;
54 }
55
56
57
58
59 public void addChild(ConformanceStructure<?> theStructure, String theName, short theMinReps, short theMaxReps) throws HL7Exception {
60 int num = mySupport.getChildCount();
61 mySupport.addChild(theStructure, theName, theMinReps, theMaxReps);
62 super.insert(theStructure.getClass(), mySupport.isRequired(theName), mySupport.isRepeating(theName), num, theName);
63 }
64
65
66
67
68 @Override
69 public Structure get(String theName, int theRep) throws HL7Exception {
70
71 Structure retVal = mySupport.getNonStandardSegmentIfNameExists(theName, theRep);
72 if (retVal != null) {
73 return retVal;
74 }
75
76 Structure[] currentReps = getAll(theName);
77 int currentRepsNum = currentReps.length;
78 if (theRep > currentRepsNum) {
79 throw new HL7Exception("Can't create rep " + theRep + " as there are currently only " + currentRepsNum);
80 }
81
82 if (theRep < currentRepsNum) {
83 return super.get(theName, theRep);
84 }
85
86 if (getClass(theName) == GenericSegment.class) {
87 retVal = super.get(theName, theRep);
88 } else {
89 retVal = mySupport.get(theName, theRep);
90 }
91 insertRepetition(theName, retVal, theRep);
92 return retVal;
93 }
94
95
96
97
98 @Override
99 public Structure[] getAll(String theName) throws HL7Exception {
100 Structure[] retVal = mySupport.getAllNonStandardSegmentsIfNameExists(theName);
101 if (retVal == null) {
102 return super.getAll(theName);
103 }
104 return retVal;
105 }
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127 public SegGroup getConfDefinition() {
128 return myConfDefinition;
129 }
130
131 @Override
132 public ConformanceMessage getMessage() {
133 return (ConformanceMessage) super.getMessage();
134 }
135
136
137
138
139 @Override
140 public String getName() {
141 return mySupport.getName();
142 }
143
144
145
146
147
148
149
150
151
152
153
154
155 public ConformanceGroup instantiateClone() throws HL7Exception {
156 ConformanceStructureHolderSupport support = mySupport.instantiateClone();
157 ConformanceGroup retVal = new ConformanceGroup(getMessage(), support, myConfDefinition);
158
159 int idx = 0;
160 for (String next : getNames()) {
161 Class<? extends Structure> clazz = getClass(next);
162 boolean rep = isRepeating(next);
163 boolean req = isRequired(next);
164
165 retVal.insert(clazz, req, rep, idx, next);
166
167 idx++;
168 }
169
170 return retVal;
171 }
172
173
174
175
176 @Override
177 protected Structure tryToInstantiateStructure(Class<? extends Structure> theC, String theName) throws HL7Exception {
178 return mySupport.get(theName, 0);
179 }
180
181 }