Class AbstractMessage
- All Implemented Interfaces:
Group,Message,Structure,Visitable,Serializable
- Direct Known Subclasses:
AbstractSuperMessage,GenericMessage
- Author:
- Bryan Tripp (bryan_tripp@sourceforge.net)
- See Also:
-
Field Summary
Fields inherited from class ca.uhn.hl7v2.model.AbstractStructure
log -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanaccept(MessageVisitor visitor, Location location) Iterates over the contained structures and calls the visitor for each of them.copy()encode()Encodes this message using the parser returned byMessage.getParser()fillResponseHeader(Message out, AcknowledgmentCode code) Populates certain required fields in a response message header, using information from the corresponding inbound message.Generates and returns an ACK message which would be used to acknowledge this message successfully, with an MSA-1 code of "AA".generateACK(AcknowledgmentCode theAcknowledgementCode, HL7Exception theException) Generates and returns an ACK message which would be used to acknowledge this message successfully.generateACK(String theAcknowledgementCode, HL7Exception theException) Deprecated.Convenience method which retrieves the encoding characters value from the second field of the first segment.Convenience method which retrieves the field separator value from the first field of the first segment.Returns this Message object.Returns the parent group within which this structure exists (may be root message group).Returns the parser to be used when parse/encode methods are called on this Message, as well as its children.Returns the set of validation rules that applied to this message.Returns the version number.voidinitQuickstart(String messageCode, String messageTriggerEvent, String processingId) Quickly initializes this message with common values in the first (MSH) segment.voidParses the string into this message using the parser returned byMessage.getParser()Prints a summary of the contents and structure of this message.printStructure(boolean includeEmptyElements) Prints the message structure in a similar way toprintStructure()but optionally excludes elements with no contents.voidSets the parser to be used when parse/encode methods are called on this Message, as well as its children.toString()Provides an overview of the type and structure of this messageMethods inherited from class ca.uhn.hl7v2.model.AbstractGroup
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, visitNestedStructuresMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface ca.uhn.hl7v2.model.Group
addNonstandardSegment, addNonstandardSegment, get, get, getAll, getClass, getNames, isChoiceElement, isGroup, isRepeating, isRequiredMethods inherited from interface ca.uhn.hl7v2.model.Visitable
isEmpty, provideLocation
-
Constructor Details
-
AbstractMessage
- Parameters:
theFactory- factory for model classes (e.g. group, segment) for this message
-
-
Method Details
-
getMessage
Returns this Message object.- Specified by:
getMessagein interfaceStructure- Overrides:
getMessagein classAbstractStructure- Returns:
- message the root message this structure is part of
-
getParent
Description copied from interface:StructureReturns the parent group within which this structure exists (may be root message group).- Specified by:
getParentin interfaceStructure- Overrides:
getParentin classAbstractStructure- Returns:
- parent group of this structure
-
getVersion
Returns the version number. This default implementation inspects this.getClass().getName(). This should be overridden if you are putting a custom message definition in your own package, or it will default.- Specified by:
getVersionin interfaceMessage- Returns:
- lowest available version if not obvious from package name
- See Also:
-
getValidationContext
Returns the set of validation rules that applied to this message. If the parser was set to "not-validating", this method returns null- Returns:
- the set of validation rules that applied to this message
-
getFieldSeparatorValue
Convenience method which retrieves the field separator value from the first field of the first segment. Typically, the first segment is MSH, so this method will retrieve the value of MSH-1.- Specified by:
getFieldSeparatorValuein interfaceMessage- Returns:
- The field separator
- Throws:
HL7Exception- If an error occurs
-
getEncodingCharactersValue
Convenience method which retrieves the encoding characters value from the second field of the first segment. Typically, the first segment is MSH, so this method will retrieve the value of MSH-2.- Specified by:
getEncodingCharactersValuein interfaceMessage- Returns:
- The encoding characters
- Throws:
HL7Exception- If an error occurs
-
setParser
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
PipeParsersupports this functionalitySerialization note: The message parser is marked as transient, so it will not survive serialization.
-
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.
-
parse
Parses the string into this message using the parser returned byMessage.getParser()- Specified by:
parsein interfaceMessage- Parameters:
string- the message to be parsed- Throws:
HL7Exception- if errors occurred during parsing
-
encode
Encodes this message using the parser returned byMessage.getParser()- Specified by:
encodein interfaceMessage- Returns:
- the string-encoded message
- Throws:
HL7Exception- if error occurred during encoding
-
generateACK
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
- Message version is invalid
- First segment is not an MSH
- Specified by:
generateACKin interfaceMessage- Returns:
- the acknowledgment message
- Throws:
HL7Exception- If the message can not be constructedIOException- If a failure occurs in generating a control ID for the message
-
generateACK
public Message generateACK(String theAcknowledgementCode, HL7Exception theException) throws HL7Exception, IOException Deprecated.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
- Message version is invalid
- First segment is not an MSH
- Specified by:
generateACKin interfaceMessage- Parameters:
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)- Throws:
HL7Exception- If the message can not be constructedIOException- If a failure occurs in generating a control ID for the message
-
generateACK
public 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
- Message version is invalid
- First segment is not an MSH
- Specified by:
generateACKin interfaceMessage- Parameters:
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)- Returns:
- the acknoeldgement message
- Throws:
HL7Exception- If the message can not be constructedIOException- If a failure occurs in generating a control ID for the message
-
fillResponseHeader
public Message fillResponseHeader(Message out, AcknowledgmentCode code) throws HL7Exception, IOException Populates certain required fields in a response message header, using information from the corresponding inbound message. The current time is used for the message time field, andMessageIDGeneratoris used to create a unique message ID. Version and message type fields are not populated.- Parameters:
out- outgoing message to be populatedcode- acknowledgment code- Returns:
- outgoing message
- Throws:
HL7Exception- if header cannot be filledIOException- if message ID could not be generated
-
toString
Provides an overview of the type and structure of this message -
printStructure
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)- Specified by:
printStructurein interfaceMessage- Returns:
- A summary of the structure
- Throws:
HL7Exception- If any problems occur encoding the structure
-
printStructure
Prints the message structure in a similar way toprintStructure()but optionally excludes elements with no contents.- Throws:
HL7Exception
-
initQuickstart
public void initQuickstart(String messageCode, String messageTriggerEvent, String processingId) throws HL7Exception, IOException Quickly initializes this message with common values in the first (MSH) segment.Settings include:
- MSH-1 (Field Separator) is set to "|"
- MSH-2 (Encoding Characters) is set to "^~\&"
- MSH-7 (Date/Time of Message) is set to current time
- MSH-10 (Control ID) is populated using next value generated by a
IDGenerator
- Parameters:
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)- Throws:
IOException- If the message ID generation fails for some reasonHL7Exception- If the message rejects any of the values which are generated to setting
-
accept
Description copied from class:AbstractGroupIterates over the contained structures and calls the visitor for each of them.- Specified by:
acceptin interfaceVisitable- Overrides:
acceptin classAbstractGroup- Parameters:
visitor- MessageVisitor instance to be called back.location- location of the group- Returns:
- true if visiting shall continue, false if not
- Throws:
HL7Exception- if a problem occurred during visiting
-
copy
Creates a copy ofthisAbstractMessageby recursively looping over eachStructure(i.e.AbstractGrouporAbstractSegment). When anAbstractSegmentis found, its contents are encoded and parsed into the copiedAbstractMessage- Returns:
- A copy of
thisAbstractMessage - Throws:
HL7Exception- If an error occurs while the message is being copied
-