Skip to content

Commit cabcd87

Browse files
committed
Message#setField(): create segment if necessary
1 parent 6f53982 commit cabcd87

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/com/illcode/hl7/Message.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,8 @@ public String getField(String spec) {
160160
}
161161

162162
/**
163-
* Sets a field of a segment in the message.
163+
* Sets a field of a segment in the message. If no segment with the specified ID
164+
* exists in the message, it will be created and added.
164165
* @param spec spec string as described in the docs for {@link #getField}
165166
* @param value scalar value to assign to the field
166167
*/
@@ -169,8 +170,10 @@ public void setField(String spec, String value) {
169170
if (path == null)
170171
return;
171172
Segment seg = getSegment(path.segmentId, path.segmentRep);
172-
if (seg == null)
173-
return;
173+
if (seg == null) {
174+
seg = new Segment("path.segmentId");
175+
putSegment(seg);
176+
}
174177
seg.setFieldValue(path.field, path.fieldRep, path.component, path.subcomponent, value);
175178
}
176179

0 commit comments

Comments
 (0)