Class PipeParser
- Author:
- Bryan Tripp (bryan_tripp@sourceforge.net)
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringDeprecated.This will be removed in HAPI 3.0 -
Constructor Summary
ConstructorsConstructorDescriptionPipeParser(HapiContext context) PipeParser(ModelClassFactory theFactory) Creates a new PipeParser -
Method Summary
Modifier and TypeMethodDescriptionprotected StringFormats a Message object into an HL7 message string using this parser's default encoding ("VB").protected StringFormats a Message object into an HL7 message string using the given encoding.doEncode(Segment structure, EncodingCharacters encodingCharacters) Encodes a particular segment and returns the encoded structuredoEncode(Type type, EncodingCharacters encodingCharacters) Encodes a particular type and returns the encoded structureprotected MessageParses a message string and returns the corresponding Message object.protected MessagedoParseForSpecificPackage(String message, String version, String packageName) Attempt the parse a message using a specific model packagestatic Stringencode(Group source, EncodingCharacters encodingChars) Returns given group serialized as a pipe-encoded string - this method is called by encode(Message source, String encoding).Formats a Message object into an HL7 message string using this parser's default encoding.static Stringencode(Segment source, EncodingCharacters encodingChars) Returns given segment serialized as a pipe-encoded string.static Stringencode(Type source, EncodingCharacters encodingChars) Encodes the given Type, using the given encoding characters.For response messages, returns the value of MSA-2 (the message ID of the message sent by the sending system).getCriticalResponseData(String message) Returns a minimal amount of data from a message string, including only the data needed to send a response to the remote system.getEncoding(String message) Returns a String representing the encoding of the given message, if the encoding is recognized.static PipeParserConvenience factory method which returns an instance that has a newDefaultHapiContextinitialized with aNoValidation validation context.getMessageStructure(String message) Deprecated.this method should not be publicgetVersion(String message) Returns the version ID (MSH-12) from the given message, without fully parsing the message.booleanDeprecated.This will be removed in HAPI 3.0voidParses a particular message and returns the encoded structurevoidparse(Segment destination, String segment, EncodingCharacters encodingChars) Parses a segment string and populates the given Segment object.voidparse(Segment destination, String segment, EncodingCharacters encodingChars, int theRepetition) Parses a segment string and populates the given Segment object.voidparse(Type destinationField, String data, EncodingCharacters encodingCharacters) Fills a field with values from an unparsed string representing the field.Parses a message string and returns the corresponding Message object.voidsetLegacyMode(boolean legacyMode) Deprecated.This will be removed in HAPI 3.0voidsetValidationContext(ValidationContext context) static String[]Splits the given composite string into an array of components using the given delimiter.static StringRemoves leading whitespace from the given string.Methods inherited from class ca.uhn.hl7v2.parser.Parser
applySuperStructureName, assertVersionExists, encode, getFactory, getMessageStructureForEvent, getParserConfiguration, getValidationContext, instantiateMessage, instantiateMessageInASpecificPackage, makeControlMSH, parseForSpecificPackage, setParserConfiguration, supportsEncoding, validVersionMethods inherited from class ca.uhn.hl7v2.HapiContextSupport
getHapiContext, setHapiContext
-
Field Details
-
DEFAULT_LEGACY_MODE_PROPERTY
Deprecated.This will be removed in HAPI 3.0System property key. If value is "true", legacy mode will default to true- See Also:
-
-
Constructor Details
-
PipeParser
public PipeParser() -
PipeParser
- Parameters:
context- the context containing all configuration items to be used
-
PipeParser
Creates a new PipeParser- Parameters:
theFactory- custom factory to use for model class lookup
-
-
Method Details
-
setValidationContext
- Overrides:
setValidationContextin classParser- Parameters:
context- the set of validation rules to be applied to messages parsed or encoded by this parser (defaults to ValidationContextFactory.DefaultValidation)
-
getEncoding
Returns a String representing the encoding of the given message, if the encoding is recognized. For example if the given message appears to be encoded using HL7 2.x XML rules then "XML" would be returned. If the encoding is not recognized then null is returned. That this method returns a specific encoding does not guarantee that the message is correctly encoded (e.g. well formed XML) - just that it is not encoded using any other encoding than the one returned.- Specified by:
getEncodingin classParser- Parameters:
message- message string- Returns:
- string representing the encoding of the given message, i.e. "XML" or "ER7"
-
getDefaultEncoding
- Specified by:
getDefaultEncodingin classParser- Returns:
- the preferred encoding of this Parser
-
getMessageStructure
Deprecated.this method should not be public- Parameters:
message- HL7 message- Returns:
- message structure
- Throws:
HL7Exception
-
doParse
Parses a message string and returns the corresponding Message object. Unexpected segments added at the end of their group.- Specified by:
doParsein classParser- Parameters:
message- a String that contains an HL7 messageversion- the name of the HL7 version to which the message belongs (eg "2.5")- Returns:
- a HAPI Message object parsed from the given String
- Throws:
HL7Exception- if the message is not correctly formatted.EncodingNotSupportedException- if the message encoded is not supported by this parser.
-
doParseForSpecificPackage
protected Message doParseForSpecificPackage(String message, String version, String packageName) throws HL7Exception Attempt the parse a message using a specific model package- Specified by:
doParseForSpecificPackagein classParser- Throws:
HL7Exception
-
parse
public void parse(Segment destination, String segment, EncodingCharacters encodingChars) throws HL7Exception Parses a segment string and populates the given Segment object. Unexpected fields are added as Varies' at the end of the segment.- Specified by:
parsein classParser- Parameters:
destination- segment to parse the segment string intosegment- encoded segmentencodingChars- encoding characters to be used- Throws:
HL7Exception- if the given string does not contain the given segment or if the string is not encoded properly
-
parse
public void parse(Segment destination, String segment, EncodingCharacters encodingChars, int theRepetition) throws HL7Exception Parses a segment string and populates the given Segment object. Unexpected fields are added as Varies' at the end of the segment.- Parameters:
destination- segment to parse the segment string intosegment- encoded segmentencodingChars- encoding characters to be usedtheRepetition- the repetition number of this segment within its group- Throws:
HL7Exception- if the given string does not contain the given segment or if the string is not encoded properly
-
parse
public void parse(Type destinationField, String data, EncodingCharacters encodingCharacters) throws HL7Exception Fills a field with values from an unparsed string representing the field.- Specified by:
parsein classParser- Parameters:
destinationField- the field Typedata- the field string (including all components and subcomponents; not including field delimiters)encodingCharacters- the encoding characters used in the message- Throws:
HL7Exception- If there is a problem encoding
-
split
Splits the given composite string into an array of components using the given delimiter.- Parameters:
composite- encoded composite stringdelim- delimiter to split upon- Returns:
- split string
-
doEncode
Encodes a particular segment and returns the encoded structure -
doEncode
Encodes a particular type and returns the encoded structure -
encode
Encodes the given Type, using the given encoding characters. It is assumed that the Type represents a complete field rather than a component.- Parameters:
source- type to be encodedencodingChars- encoding characters to be used- Returns:
- encoded type
-
doEncode
Formats a Message object into an HL7 message string using the given encoding.- Specified by:
doEncodein classParser- Parameters:
source- a Message object from which to construct an encoded message stringencoding- the name of the HL7 encoding to use (eg "XML"; most implementations support only one encoding)- Returns:
- the encoded message
- Throws:
HL7Exception- if the data fields in the message do not permit encoding (e.g. required fields are null)EncodingNotSupportedException- if the requested encoding is not supported by this parser.
-
doEncode
Formats a Message object into an HL7 message string using this parser's default encoding ("VB").- Specified by:
doEncodein classParser- Parameters:
source- a Message object from which to construct an encoded message string- Returns:
- the encoded message
- Throws:
HL7Exception- if the data fields in the message do not permit encoding (e.g. required fields are null)
-
encode
Returns given group serialized as a pipe-encoded string - this method is called by encode(Message source, String encoding).- Parameters:
source- group to be encodedencodingChars- encoding characters to be used- Returns:
- encoded group
- Throws:
HL7Exception- if an error occurred while encoding
-
getInstanceWithNoValidation
Convenience factory method which returns an instance that has a newDefaultHapiContextinitialized with aNoValidation validation context.- Returns:
- PipeParser with disabled validation
-
encode
Returns given segment serialized as a pipe-encoded string.- Parameters:
source- segment to be encodedencodingChars- encoding characters to be used- Returns:
- encoded group
-
stripLeadingWhitespace
Removes leading whitespace from the given string. This method was created to deal with frequent problems parsing messages that have been hand-written in windows. The intuitive way to delimit segments is to hitat the end of each segment, but this creates both a carriage return and a line feed, so to the parser, the first character of the next segment is the line feed. - Parameters:
in- input string- Returns:
- string with leading whitespaces removed
-
getCriticalResponseData
Returns a minimal amount of data from a message string, including only the data needed to send a response to the remote system. This includes the following fields:
- field separator
- encoding characters
- processing ID
- message control ID
- Specified by:
getCriticalResponseDatain classParser- Parameters:
message- the message- Returns:
- an MSH segment
- Throws:
HL7Exception- if no MSH segment could be created
-
getAckID
For response messages, returns the value of MSA-2 (the message ID of the message sent by the sending system). This value may be needed prior to main message parsing, so that (particularly in a multi-threaded scenario) the message can be routed to the thread that sent the request. We need this information first so that any parse exceptions are thrown to the correct thread. Returns null if MSA-2 can not be found (e.g. if the message is not a response message). -
setLegacyMode
Deprecated.This will be removed in HAPI 3.0Defaults tofalse- See Also:
-
encode
Formats a Message object into an HL7 message string using this parser's default encoding.- Overrides:
encodein classParser- Parameters:
source- a Message object from which to construct an encoded message string- Returns:
- the encoded message
- Throws:
HL7Exception- if the data fields in the message do not permit encoding (e.g. required fields are null)
-
parse
Parses a message string and returns the corresponding Message object.- Overrides:
parsein classParser- Parameters:
message- a String that contains an HL7 message- Returns:
- a HAPI Message object parsed from the given String
- Throws:
HL7Exception- if the message is not correctly formatted.EncodingNotSupportedException- if the message encoded is not supported by this parser.
-
isLegacyMode
Deprecated.This will be removed in HAPI 3.0Returns
trueif legacy mode is on.Prior to release 1.0, when an unexpected segment was encountered in a message, HAPI would recurse to the deepest nesting in the last group it encountered after the current position in the message, and deposit the segment there. This could lead to unusual behaviour where all segments afterward would not be in an expected spot within the message.
This should normally be set to false, but any code written before the release of HAPI 1.0 which depended on this behaviour might need legacy mode to be set to true.
Defaults to
false. Note that this method only overrides behaviour of theparse(java.lang.String)andencode(ca.uhn.hl7v2.model.Message)methods -
getVersion
Returns the version ID (MSH-12) from the given message, without fully parsing the message. The version is needed prior to parsing in order to determine the message class into which the text of the message should be parsed.- Specified by:
getVersionin classParser- Parameters:
message- the message- Returns:
- the value of MSH-12
- Throws:
HL7Exception- if the version field can not be found.
-
parse
Description copied from class:ParserParses a particular message and returns the encoded structure- Specified by:
parsein classParser- Parameters:
message- The message to encodestring- The string to parse- Throws:
HL7Exception- If there is a problem encoding
-