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 package ca.uhn.hl7v2.sourcegen;
30
31 import java.util.ArrayList;
32 import java.util.List;
33
34 import org.codehaus.plexus.util.StringUtils;
35
36 import edu.emory.mathcs.backport.java.util.Collections;
37
38
39
40
41
42
43
44
45 public class SegmentDef implements StructureDef {
46
47 private final String name;
48 private final String groupName;
49 private final String description;
50 private final boolean required;
51 private final boolean repeating;
52 private String myIndexName;
53 private final List<DatatypeDef> myFieldDefs = new ArrayList<>();
54 private final boolean choice;
55 private List<String> associatedStructures;
56
57
58 public SegmentDef(String name, String groupName, boolean required, boolean repeating, boolean choice, String description) {
59 this.name = name;
60 this.groupName = groupName;
61 this.required = required;
62 this.repeating = repeating;
63 this.description = StringUtils.defaultString(description);
64 this.choice = choice;
65 }
66
67
68
69
70 public boolean isChoice() {
71 return choice;
72 }
73
74 public void addFieldDef(DatatypeDef theFieldDef) {
75 myFieldDefs.add(theFieldDef);
76 }
77
78 public List<DatatypeDef> getFieldDefs() {
79 return myFieldDefs;
80 }
81
82
83
84
85 public String getName() {
86 String result = this.name;
87 if (result != null && result.equals("?")) {
88 result = "GenericSegment";
89 }
90 return result;
91 }
92
93
94
95
96 public String getGroupName() {
97 return this.groupName;
98 }
99
100
101
102
103 public boolean isRequired() {
104 return this.required;
105 }
106
107
108
109
110 public boolean isRepeating() {
111 return this.repeating;
112 }
113
114
115
116
117 public String getDescription() {
118 return this.description;
119 }
120
121
122
123
124
125
126
127
128 public String[] getChildSegments() {
129 return new String[]{getName()};
130 }
131
132
133
134
135 public String toString() {
136 return "SegmentDef[name=" + name + ", groupName=" + groupName + ", description=" + description + "]";
137 }
138
139 public boolean isGroup() {
140 return false;
141 }
142
143
144
145
146 public String getUnqualifiedName() {
147 return getName();
148 }
149
150
151
152
153 public String getIndexName() {
154 return myIndexName;
155 }
156
157
158
159
160 public void setIndexName(String theIndexName) {
161 myIndexName = theIndexName;
162 }
163
164
165
166
167 public boolean isSegment() {
168 return true;
169 }
170
171
172
173
174 public List<String> getAssociatedStructures() {
175 if (associatedStructures == null) {
176 associatedStructures = new ArrayList<>();
177 }
178 return associatedStructures;
179 }
180
181
182
183
184 public void addAssociatedStructure(String theAssociatedStructure) {
185 if (getAssociatedStructures().contains(theAssociatedStructure)) {
186 return;
187 }
188 getAssociatedStructures().add(theAssociatedStructure);
189 Collections.sort(getAssociatedStructures());
190 }
191
192
193 }