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
27
28
29
30
31
32 package ca.uhn.hl7v2.conf.classes.generator.builders;
33
34 import java.util.Objects;
35 import java.util.regex.Pattern;
36
37 import ca.uhn.hl7v2.conf.spec.message.*;
38 import ca.uhn.hl7v2.conf.classes.generator.genclasses.*;
39 import ca.uhn.hl7v2.conf.spec.*;
40
41
42
43
44
45
46
47
48 public final class DocumentationBuilder {
49
50 private static DocumentationBuilder documentationBuilder;
51
52
53
54
55 public static DocumentationBuilder getDocumentationBuilder() {
56 if (documentationBuilder == null)
57 documentationBuilder = new DocumentationBuilder();
58
59 return documentationBuilder;
60 }
61
62
63 private DocumentationBuilder() {
64 }
65
66
67
68
69
70
71 private void addOptionalComment(
72 GeneratedConformanceContainer genClass,
73 String label,
74 String data) {
75 if (data != null && !Objects.equals(data, ""))
76 genClass.addClassComment(
77 " <tr><td>" + label + "</td><td>" + data + "</td></tr>");
78 }
79
80
81
82
83
84
85 private void addOptionalComment(
86 GeneratedPrimitive genClass,
87 String label,
88 String data) {
89 if (data != null && !Objects.equals(data, ""))
90 genClass.addClassComment(
91 " <tr><td>" + label + "</td><td>" + data + "</td></tr>");
92 }
93
94
95
96
97
98 public void decorateComponent(
99 GeneratedConformanceContainer genClass,
100 Component comp) {
101 genClass.addClassComment(
102 "This class contains and provides access to all SubComponents");
103 genClass.addClassComment("<table>");
104 addOptionalComment(genClass, "Name", comp.getName());
105 addOptionalComment(genClass, "Usage", comp.getUsage());
106 addOptionalComment(genClass, "Data Type", comp.getDatatype());
107 addOptionalComment(genClass, "Constant Value", comp.getConstantValue());
108 addOptionalComment(genClass, "Description", comp.getDescription());
109 addOptionalComment(genClass, "Implementation Note", comp.getImpNote());
110 addOptionalComment(genClass, "Predicate", comp.getPredicate());
111 addOptionalComment(genClass, "Reference", comp.getReference());
112 addOptionalComment(genClass, "Length", comp.getLength() + "");
113 if (comp.getLength() != 0)
114 addOptionalComment(genClass, "Table", comp.getTable() + "");
115 genClass.addClassComment("</table>");
116 }
117
118
119
120
121
122 public void decorateConformanceMessage(
123 GeneratedConformanceMessage genClass,
124 RuntimeProfile runtimeProfile) {
125 genClass.addToClassComments(
126 "This class is the primary access class for the HL7 "
127 + runtimeProfile.getHL7Version()
128 + " "
129 + runtimeProfile.getMessage().getMsgType()
130 + " Conformance");
131 genClass.addToClassComments(
132 "Class Set. This message has the following attributes:<br>");
133 genClass.addToClassComments("<table>");
134 genClass.addToClassComments(
135 "<tr><td>Message Type</td><td>"
136 + runtimeProfile.getMessage().getMsgType()
137 + "</td></tr>");
138 genClass.addToClassComments(
139 "<tr><td>Event Type</td><td>"
140 + runtimeProfile.getMessage().getEventType()
141 + "</td></tr>");
142 genClass.addToClassComments(
143 "<tr><td>HL7 Version</td><td>"
144 + runtimeProfile.getHL7Version()
145 + "</td></tr>");
146 genClass.addToClassComments("</table><br><br>");
147 genClass.addToClassComments("<b>Purpose</b><br>");
148 genClass.addToClassComments(runtimeProfile.getMessage().getEventDesc());
149 }
150
151
152
153
154 public void decorateConstantValue(GeneratedMethod genMethod) {
155 genMethod.addToDescription(
156 "Returns the constant value associated with this Data Type");
157 genMethod.addToComments(
158 "@return the constant value associated with this Data Type, or <code>null</code> if there is none");
159
160 }
161
162
163
164
165
166 public void decorateConstructor(GeneratedMethod constructor, String className) {
167 constructor.addToDescription("Default constructor for Conformance_HL7_" + className + ". Has the");
168 constructor.addToDescription("following functions:");
169 constructor.addToDescription("<ul><li>Instantiating all required Conformance Classes in the structure");
170 constructor.addToDescription(" <li>Instantiating the underlying HAPI Message object");
171 constructor.addToDescription(" <li>Populating any constant values");
172 constructor.addToDescription("</ul>");
173
174 }
175
176
177
178
179
180 public void decorateField(
181 GeneratedConformanceContainer genClass,
182 Field field) {
183 genClass.addClassComment(
184 "This represents a constrained "
185 + field.getName()
186 + " field, with the following proerties:");
187 genClass.addClassComment("<table>");
188 addOptionalComment(genClass, "Name", field.getName());
189 addOptionalComment(genClass, "Usage", field.getUsage());
190 addOptionalComment(genClass, "Description", field.getDescription());
191 addOptionalComment(genClass, "Implementation Note", field.getImpNote());
192 addOptionalComment(genClass, "Predicate", field.getPredicate());
193 addOptionalComment(genClass, "Reference", field.getReference());
194 addOptionalComment(
195 genClass,
196 "Minimum Repetitions ",
197 field.getMin() + "");
198 addOptionalComment(
199 genClass,
200 "Maximum Repetitions ",
201 field.getMax() + "");
202 genClass.addClassComment("</table>");
203 }
204
205
206
207
208 public void decorateMaxLength(GeneratedMethod genMethod) {
209 genMethod.addToDescription(
210 "Returns the Maximum allowable length for the Data Type");
211 genMethod.addToComments(
212 "@return the maximum allowable length of the Data Type");
213
214 }
215
216
217
218
219 public void decorateMaxReps(GeneratedMethod genMethod) {
220
221 genMethod.addToDescription("This method returns the maximum allowable");
222 genMethod.addToComments("repetitions of this object.");
223 genMethod.addToComments("@return maximum allowable repetitions");
224
225 }
226
227
228
229
230 public void decorateMinReps(GeneratedMethod genMethod) {
231
232 genMethod.addToDescription("This method returns the minimum allowable");
233 genMethod.addToComments("repetitions of this object.");
234 genMethod.addToComments("@return minimum allowable repetitions");
235
236 }
237
238
239
240
241
242 public void decoratePrimitive(
243 GeneratedPrimitive genClass,
244 AbstractComponent ac) {
245 genClass.addClassComment(
246 "This represents a constrained "
247 + ac.getName()
248 + " field, with the following properties:");
249 genClass.addClassComment("<table>");
250 addOptionalComment(genClass, "Name", ac.getName());
251 addOptionalComment(genClass, "Usage", ac.getUsage());
252 addOptionalComment(genClass, "Data Type", ac.getDatatype());
253 addOptionalComment(genClass, "Constant Value", ac.getConstantValue());
254 addOptionalComment(genClass, "Description", ac.getDescription());
255 addOptionalComment(genClass, "Implementation Note", ac.getImpNote());
256 addOptionalComment(genClass, "Predicate", ac.getPredicate());
257 addOptionalComment(genClass, "Reference", ac.getReference());
258 addOptionalComment(genClass, "Length", ac.getLength() + "");
259 if (ac.getTable() != null && Pattern.matches("[^0]", ac.getTable()))
260 addOptionalComment(genClass, "Table", ac.getTable() + "");
261 genClass.addClassComment("</table>");
262 }
263
264
265
266
267
268 public void decorateProfileStructure(
269 GeneratedConformanceContainer genClass,
270 ProfileStructure ps) {
271 genClass.addClassComment(
272 "This represents a constrained "
273 + ps.getName()
274 + " segment, with the following properties:");
275 genClass.addClassComment("<table>");
276 addOptionalComment(genClass, "Name", ps.getName());
277 addOptionalComment(genClass, "Usage", ps.getUsage());
278 addOptionalComment(genClass, "Description", ps.getDescription());
279 addOptionalComment(genClass, "Implementation Note", ps.getImpNote());
280 addOptionalComment(genClass, "Predicate", ps.getPredicate());
281 addOptionalComment(genClass, "Reference", ps.getReference());
282 addOptionalComment(genClass, "Minimum Repetitions ", ps.getMin() + "");
283 addOptionalComment(genClass, "Maximum Repetitions ", ps.getMax() + "");
284 genClass.addClassComment("</table>");
285 }
286
287
288
289
290
291
292 public void decorateRepGetter(
293 GeneratedRepGetter genMethod,
294 Field field,
295 String repType) {
296
297 genMethod.addToDescription(
298 "This method returns a reference to the "
299 + field.getName()
300 + " field belonging to this segment.");
301 genMethod.addToComments("Min Repetitions " + field.getMin());
302 genMethod.addToComments("Max Repetitions " + field.getMax());
303 if (field.getMax() == -1)
304 genMethod.addToComments("@param rep The desired repetition number");
305 genMethod.addToComments(
306 "@return the child object reference. <b>rep must fall between "
307 + field.getMin()
308 + " and "
309 + field.getMax()
310 + "</b>");
311 genMethod.addToComments(
312 "@throws ca.uhn.hl7v2.conf.classes.exceptions.ConfRepException");
313
314 }
315
316
317
318
319
320
321 public void decorateRepGetter(
322 GeneratedRepGetter genMethod,
323 ProfileStructure profileStructure,
324 String repType) {
325
326 genMethod.addToDescription(
327 "This method returns a reference to the "
328 + profileStructure.getName()
329 + " child.");
330 genMethod.addToComments("Min Repetitions" + profileStructure.getMin());
331 genMethod.addToComments("Max Repetitions" + profileStructure.getMax());
332 if (profileStructure.getMax() == -1)
333 genMethod.addToComments("@param rep The desired repetition number");
334 genMethod.addToComments(
335 "@return the child object reference. <b>rep must fall between "
336 + profileStructure.getMin()
337 + " and "
338 + profileStructure.getMax()
339 + "</b>");
340 genMethod.addToComments(
341 "@throws ca.uhn.hl7v2.conf.classes.exceptions.ConfRepException");
342
343 }
344
345
346
347
348
349 public void decorateSegGroup(
350 GeneratedConformanceContainer genClass,
351 SegGroup segGroup) {
352 this.decorateProfileStructure(genClass, segGroup);
353 }
354
355
356
357
358
359 public void decorateSegment(
360 GeneratedConformanceContainer genClass,
361 Seg seg) {
362 this.decorateProfileStructure(genClass, seg);
363 }
364
365 public void decorateSetValue(GeneratedMethod genMethod, long maxLength) {
366 genMethod.addToDescription(
367 "This method validates the <code>String</code> value passed in to be no greater then the");
368 genMethod.addToDescription(
369 "maximum allowable length for the extending class. If the <code>String</code> value is valid, this");
370 genMethod.addToDescription(
371 "method will set the underlying HAPI class's value. If the data passed in is invalid for the given");
372 genMethod.addToDescription(
373 "data type, a ConformanceException is thrown.");
374 genMethod.addToDescription(
375 "@throws ConfDataException if the data is invalid for the given datatype");
376
377 genMethod.addToDescription("@param value The value to be set.");
378 if (maxLength > 0)
379 genMethod.addToDescription(
380 "Note: The value has a maximum length of " + maxLength);
381 }
382
383
384
385
386 public String getGeneratedClassHeader() {
387 return (
388 "/**\n"
389 + "The following code was automatically genearated by the Conformance Class Generation System\n"
390 + "Contributor(s):The Conformance Class Generation System was developed by\n"
391 + " --------------.:JH6 Solutions:.--------------\n"
392 + " James Agnew - jait214@yahoo.ca\n"
393 + " Paul Brohman - pbrohman@rogers.com\n"
394 + " Mitch Delachevrotiere - hapimgd@hotmail.com\n"
395 + " Shawn Dyck - sdyck613@yahoo.ca\n"
396 + " Cory Metcalf - cory_metcalf@hotmail.com\n"
397 + "\n"
398 + "*/");
399 }
400
401 }