public abstract class AbstractMessage extends AbstractGroup implements Message
log
Constructor and Description |
---|
AbstractMessage(ModelClassFactory theFactory) |
Modifier and Type | Method and Description |
---|---|
boolean |
accept(MessageVisitor visitor,
Location location)
Iterates over the contained structures and calls the visitor for each
of them.
|
String |
encode()
Encodes this message using the parser returned by
Message.getParser() |
Message |
fillResponseHeader(Message out,
AcknowledgmentCode code)
Populates certain required fields in a response message header, using
information from the corresponding inbound message.
|
Message |
generateACK()
Generates and returns an ACK message which would be used to acknowledge this message
successfully, with an MSA-1 code of "AA".
|
Message |
generateACK(AcknowledgmentCode theAcknowledgementCode,
HL7Exception theException)
Generates and returns an ACK message which would be used to acknowledge this message
successfully.
|
Message |
generateACK(String theAcknowledgementCode,
HL7Exception theException)
Deprecated.
|
String |
getEncodingCharactersValue()
Convenience method which retrieves the encoding characters value from the second field of the
first segment.
|
Character |
getFieldSeparatorValue()
Convenience method which retrieves the field separator value from the first field of the
first segment.
|
Message |
getMessage()
Returns this Message object.
|
Group |
getParent()
Returns the parent group within which this structure exists (may be root
message group).
|
Parser |
getParser()
Returns the parser to be used when parse/encode methods are called on this
Message, as well as its children.
|
ValidationContext |
getValidationContext()
Returns the set of validation rules that applied to this message.
|
String |
getVersion()
Returns the version number.
|
void |
initQuickstart(String messageCode,
String messageTriggerEvent,
String processingId)
Quickly initializes this message with common values in the first (MSH) segment.
|
void |
parse(String string)
Parses the string into this message using the parser returned by
Message.getParser() |
String |
printStructure()
Prints a summary of the contents and structure of this message.
|
String |
printStructure(boolean includeEmptyElements)
Prints the message structure in a similar way to
printStructure() but
optionally excludes elements with no contents. |
void |
setParser(Parser parser)
Sets the parser to be used when parse/encode methods are called on this
Message, as well as its children.
|
String |
toString()
Provides an overview of the type and structure of this message
|
add, add, add, addNonstandardSegment, addNonstandardSegment, clear, currentReps, get, get, getAll, getAllAsList, getClass, getFieldNumForName, getModelClassFactory, getName, getNames, getNonStandardNames, getReps, getTyped, getTyped, insert, insert, insertRepetition, insertRepetition, isChoiceElement, isEmpty, isGroup, isRepeating, isRequired, provideLocation, removeRepetition, tryToInstantiateStructure, visitNestedStructures
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
addNonstandardSegment, addNonstandardSegment, get, get, getAll, getClass, getNames, isChoiceElement, isGroup, isRepeating, isRequired
isEmpty, provideLocation
public AbstractMessage(ModelClassFactory theFactory)
theFactory
- factory for model classes (e.g. group, segment) for this messagepublic Message getMessage()
getMessage
in interface Structure
getMessage
in class AbstractStructure
public Group getParent()
Structure
getParent
in interface Structure
getParent
in class AbstractStructure
public String getVersion()
getVersion
in interface Message
Message.getVersion()
public ValidationContext getValidationContext()
public Character getFieldSeparatorValue() throws HL7Exception
getFieldSeparatorValue
in interface Message
HL7Exception
- If an error occurspublic String getEncodingCharactersValue() throws HL7Exception
getEncodingCharactersValue
in interface Message
HL7Exception
- If an error occurspublic void setParser(Parser parser)
Sets the parser to be used when parse/encode methods are called on this Message, as well as its children. It is recommended that if these methods are going to be called, a parser be supplied with the validation context wanted. Where possible, the parser should be reused for best performance, unless thread safety is an issue.
Note that not all parsers can be used. As of version 1.0, only PipeParser
supports this functionality
Serialization note: The message parser is marked as transient, so it will not survive serialization.
public Parser getParser()
Returns the parser to be used when parse/encode methods are called on this
Message, as well as its children. The default value is a new PipeParser
.
Serialization note: The message parser is marked as transient, so it will not survive serialization.
public void parse(String string) throws HL7Exception
Message.getParser()
parse
in interface Message
string
- the message to be parsedHL7Exception
- if errors occurred during parsingpublic String encode() throws HL7Exception
Message.getParser()
encode
in interface Message
HL7Exception
- if error occurred during encodingpublic Message generateACK() throws HL7Exception, IOException
Generates and returns an ACK message which would be used to acknowledge this message successfully, with an MSA-1 code of "AA". The ACK generated will be of the same version as the value of MSH-12 in this message (as opposed to the version of the message class instance, if they are different)
Note that this method will fail if it is not possible to generate an ACK for any reason, such as
generateACK
in interface Message
HL7Exception
- If the message can not be constructedIOException
- If a failure occurs in generating a control ID for the messagepublic Message generateACK(String theAcknowledgementCode, HL7Exception theException) throws HL7Exception, IOException
Generates and returns an ACK message which would be used to acknowledge this message successfully. The ACK generated will be of the same version as the value of MSH-12 in this message (as opposed to the version of the message class instance, if they are different)
Note that this method will fail if it is not possible to generate an ACK for any reason, such as
generateACK
in interface Message
theAcknowledgementCode
- The acknowledement code (MSA-1) to supply. If null, defaults to
"AA". To generate a typical NAK, use "AE"theException
- The exceptions used to populate the ERR segment (if any)HL7Exception
- If the message can not be constructedIOException
- If a failure occurs in generating a control ID for the messagepublic Message generateACK(AcknowledgmentCode theAcknowledgementCode, HL7Exception theException) throws HL7Exception, IOException
Generates and returns an ACK message which would be used to acknowledge this message successfully. The ACK generated will be of the same version as the value of MSH-12 in this message (as opposed to the version of the message class instance, if they are different)
Note that this method will fail if it is not possible to generate an ACK for any reason, such as
generateACK
in interface Message
theAcknowledgementCode
- If null, defaults to
AcknowledgmentCode.AA. To generate a typical NAK, use AcknowledgmentCode.AEtheException
- The exceptions used to populate the ERR segment (if any)HL7Exception
- If the message can not be constructedIOException
- If a failure occurs in generating a control ID for the messagepublic Message fillResponseHeader(Message out, AcknowledgmentCode code) throws HL7Exception, IOException
MessageIDGenerator
is
used to create a unique message ID. Version and message type fields are
not populated.out
- outgoing message to be populatedcode
- acknowledgment codeHL7Exception
- if header cannot be filledIOException
- if message ID could not be generatedpublic String printStructure() throws HL7Exception
Prints a summary of the contents and structure of this message. This is useful for debugging purposes, if you want to figure out where in the structure of a message a given segment has been placed.
For instance, the following message (containing a few quirks for demonstration purposes):
...produces the following output: MSH|^~\\&|^QueryServices||||20021011161756.297-0500||ADT^A01|1|D|2.4\r
EVN|R01
EVN|R02
PID|1
IN1|1
IN1|2
PID|2
ADT_A01 (start)
MSH - MSH|^~\&|^QueryServices||||20021011161756.297-0500||ADT^A01|1|D|2.4
EVN - EVN|R01
[ { EVN2 } ] (non-standard) - EVN|R02
PID - PID|1
[ PD1 ] - Not populated
[ { ROL } ] - Not populated
[ { NK1 } ] - Not populated
PV1 - Not populated
[ PV2 ] - Not populated
[ { ROL2 } ] - Not populated
[ { DB1 } ] - Not populated
[ { OBX } ] - Not populated
[ { AL1 } ] - Not populated
[ { DG1 } ] - Not populated
[ DRG ] - Not populated
PROCEDURE (start)
[{
PR1 - Not populated
[ { ROL } ] - Not populated
}]
PROCEDURE (end)
[ { GT1 } ] - Not populated
INSURANCE (start)
[{
IN1 - IN1|1
[ IN2 ] - Not populated
[ { IN3 } ] - Not populated
[ { ROL } ] - Not populated
}]
[{
IN1 - IN1|2
[ { PID } ] (non-standard) - PID|2
[ IN2 ] - Not populated
[ { IN3 } ] - Not populated
[ { ROL } ] - Not populated
}]
INSURANCE (end)
[ ACC ] - Not populated
[ UB1 ] - Not populated
[ UB2 ] - Not populated
[ PDA ] - Not populated
ADT_A01 (end)
printStructure
in interface Message
HL7Exception
- If any problems occur encoding the structurepublic String printStructure(boolean includeEmptyElements) throws HL7Exception
printStructure()
but
optionally excludes elements with no contents.HL7Exception
public void initQuickstart(String messageCode, String messageTriggerEvent, String processingId) throws HL7Exception, IOException
Settings include:
IDGenerator
messageCode
- The message code (aka message type) to insert into MSH-9-1. Example: "ADT"messageTriggerEvent
- The message trigger event to insert into MSG-9-2. Example: "A01"processingId
- The message processing ID to insert into MSH-11. Examples: "T" (for TEST) or "P" for (PRODUCTION)IOException
- If the message ID generation fails for some reasonHL7Exception
- If the message rejects any of the values which are generated to settingpublic boolean accept(MessageVisitor visitor, Location location) throws HL7Exception
AbstractGroup
accept
in interface Visitable
accept
in class AbstractGroup
visitor
- MessageVisitor instance to be called back.location
- location of the groupHL7Exception
- if a problem occurred during visitingCopyright © 2001–2017 University Health Network. All rights reserved.