public final class Message
extends java.lang.Object
Segment
S
(with entries in the list being the repetitions of segments in the message).Constructor and Description |
---|
Message()
Construct an empty message.
|
Modifier and Type | Method and Description |
---|---|
boolean |
containsSegment(java.lang.String id)
Return true if a segment with the given ID is in the message.
|
static Message |
copyOf(Message m)
Create and return a new Message that is a deep copy of the given message.
|
java.lang.String |
getField(java.lang.String spec)
Returns the string value of a segment field given a path-like spec string as input.
|
java.lang.String |
getMessageType()
Returns the message type found in
MSH.9 , if present, or null otherwise. |
Segment |
getSegment(java.lang.String id)
Return the first segment (among any repetitions) with the given ID, or
null if no such segment is in the Message.
|
Segment |
getSegment(java.lang.String id,
int repetition)
Return a given reptition of segments with the given ID, or
null if no such segment is in the Message.
|
java.util.Set<java.lang.String> |
getSegmentIds()
Return a set of all the segment IDs in the message.
|
java.util.List<Segment> |
getSegments(java.lang.String id)
Return a list of repetitions for a given segment ID, or null if no segment with
that ID is in the message.
|
void |
putSegment(Segment s)
Put a segment into the message.
|
void |
removeSegment(Segment s)
Remove a segment from the message.
|
java.util.Collection<java.util.List<Segment>> |
segments()
Return a collection of all the repetitions of segments in the message.
|
void |
setField(java.lang.String spec,
java.lang.String value)
Sets a field of a segment in the message.
|
java.lang.String |
toString() |
public java.util.Set<java.lang.String> getSegmentIds()
public boolean containsSegment(java.lang.String id)
public java.util.Collection<java.util.List<Segment>> segments()
Note that the iteration order of the returned collection is the order in which the segment lists were added to the message, so to get a well-formed HL7 message, you'll either need to:
getSegment(String)
or getSegment(String, int)
and encode them individuallypublic java.util.List<Segment> getSegments(java.lang.String id)
public Segment getSegment(java.lang.String id, int repetition)
public Segment getSegment(java.lang.String id)
public void putSegment(Segment s)
public void removeSegment(Segment s)
public java.lang.String getMessageType()
MSH.9
, if present, or null otherwise.
Example: "QRY^A19"public java.lang.String getField(java.lang.String spec)
Examples:
"MSH.9.1" - Message TypeLikewise, for segments that can repeat in a message, the SID can be written SID(R) to get the Rth repetition. Ex: "NK1(2).2.1" for the Family Name of the second instance of the NK1 segment.
"PID.3(2).1 - The ID portion (i.e. PID.3.1) of the 2nd repetition in the PID.3 field.
If the repetition number is not specified for segment IDs or fields, it defaults to 1.
To be partially compatible with the syntax for HAPI's Terser class, you can use a dash "-" in place of the periods "." in the above format. Also, if the spec string starts with a slash "/", it will be silently discarded.
spec
- spec string, as abovepublic void setField(java.lang.String spec, java.lang.String value)
spec
- spec string as described in the docs for getField(java.lang.String)
value
- scalar value to assign to the fieldpublic static Message copyOf(Message m)
public java.lang.String toString()
toString
in class java.lang.Object