public class PipeParser extends Parser
for configuration options which may affect parser encoding and decoding behaviour
Modifier and Type | Field and Description |
---|---|
static String |
DEFAULT_LEGACY_MODE_PROPERTY
Deprecated.
This will be removed in HAPI 3.0
|
Constructor and Description |
---|
PipeParser() |
PipeParser(HapiContext context) |
PipeParser(ModelClassFactory theFactory)
Creates a new PipeParser
|
Modifier and Type | Method and Description |
---|---|
protected String |
doEncode(Message source)
Formats a Message object into an HL7 message string using this parser's
default encoding ("VB").
|
protected String |
doEncode(Message source,
String encoding)
Formats a Message object into an HL7 message string using the given
encoding.
|
String |
doEncode(Segment structure,
EncodingCharacters encodingCharacters)
Encodes a particular segment and returns the encoded structure
|
String |
doEncode(Type type,
EncodingCharacters encodingCharacters)
Encodes a particular type and returns the encoded structure
|
protected Message |
doParse(String message,
String version)
Parses a message string and returns the corresponding Message object.
|
protected Message |
doParseForSpecificPackage(String message,
String version,
String packageName)
Attempt the parse a message using a specific model package
|
static String |
encode(Group source,
EncodingCharacters encodingChars)
Returns given group serialized as a pipe-encoded string - this method is
called by encode(Message source, String encoding).
|
String |
encode(Message source)
Formats a Message object into an HL7 message string using this parser's default encoding.
|
static String |
encode(Segment source,
EncodingCharacters encodingChars)
Returns given segment serialized as a pipe-encoded string.
|
static String |
encode(Type source,
EncodingCharacters encodingChars)
Encodes the given Type, using the given encoding characters.
|
String |
getAckID(String message)
For response messages, returns the value of MSA-2 (the message ID of the
message sent by the sending system).
|
Segment |
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.
|
String |
getDefaultEncoding() |
String |
getEncoding(String message)
Returns a String representing the encoding of the given message, if the
encoding is recognized.
|
static PipeParser |
getInstanceWithNoValidation()
Convenience factory method which returns an instance that has a new
DefaultHapiContext initialized with a NoValidation validation context . |
String |
getMessageStructure(String message)
Deprecated.
this method should not be public
|
String |
getVersion(String message)
Returns the version ID (MSH-12) from the given message, without fully
parsing the message.
|
boolean |
isLegacyMode()
Deprecated.
This will be removed in HAPI 3.0
|
void |
parse(Message message,
String string)
Parses a particular message and returns the encoded structure
|
void |
parse(Segment destination,
String segment,
EncodingCharacters encodingChars)
Parses a segment string and populates the given Segment object.
|
void |
parse(Segment destination,
String segment,
EncodingCharacters encodingChars,
int theRepetition)
Parses a segment string and populates the given Segment object.
|
Message |
parse(String message)
Parses a message string and returns the corresponding Message object.
|
void |
parse(Type destinationField,
String data,
EncodingCharacters encodingCharacters)
Fills a field with values from an unparsed string representing the field.
|
void |
setLegacyMode(boolean legacyMode)
Deprecated.
This will be removed in HAPI 3.0
|
void |
setValidationContext(ValidationContext context) |
static String[] |
split(String composite,
String delim)
Splits the given composite string into an array of components using the
given delimiter.
|
static String |
stripLeadingWhitespace(String in)
Removes leading whitespace from the given string.
|
applySuperStructureName, assertVersionExists, encode, getFactory, getMessageStructureForEvent, getParserConfiguration, getValidationContext, instantiateMessage, instantiateMessageInASpecificPackage, makeControlMSH, parseForSpecificPackage, setParserConfiguration, supportsEncoding, validVersion
getHapiContext, setHapiContext
public static final String DEFAULT_LEGACY_MODE_PROPERTY
isLegacyMode()
,
Constant Field Valuespublic PipeParser()
public PipeParser(HapiContext context)
context
- the context containing all configuration items to be usedpublic PipeParser(ModelClassFactory theFactory)
theFactory
- custom factory to use for model class lookuppublic void setValidationContext(ValidationContext context)
setValidationContext
in class Parser
context
- the set of validation rules to be applied to messages parsed or encoded by
this parser (defaults to ValidationContextFactory.DefaultValidation)public String getEncoding(String message)
getEncoding
in class Parser
message
- message stringpublic String getDefaultEncoding()
getDefaultEncoding
in class Parser
public String getMessageStructure(String message) throws HL7Exception
message
- HL7 messageHL7Exception
protected Message doParse(String message, String version) throws HL7Exception
doParse
in class Parser
message
- a String that contains an HL7 messageversion
- the name of the HL7 version to which the message belongs (eg "2.5")HL7Exception
- if the message is not correctly formatted.EncodingNotSupportedException
- if the message encoded is not supported by this parser.protected Message doParseForSpecificPackage(String message, String version, String packageName) throws HL7Exception
doParseForSpecificPackage
in class Parser
HL7Exception
public void parse(Segment destination, String segment, EncodingCharacters encodingChars) throws HL7Exception
parse
in class Parser
destination
- segment to parse the segment string intosegment
- encoded segmentencodingChars
- encoding characters to be usedHL7Exception
- if the given string does not contain the given segment or if
the string is not encoded properlypublic void parse(Segment destination, String segment, EncodingCharacters encodingChars, int theRepetition) throws HL7Exception
destination
- segment to parse the segment string intosegment
- encoded segmentencodingChars
- encoding characters to be usedtheRepetition
- the repetition number of this segment within its groupHL7Exception
- if the given string does not contain the given segment or if
the string is not encoded properlypublic void parse(Type destinationField, String data, EncodingCharacters encodingCharacters) throws HL7Exception
parse
in class Parser
destinationField
- the field Typedata
- the field string (including all components and subcomponents;
not including field delimiters)encodingCharacters
- the encoding characters used in the messageHL7Exception
- If there is a problem encodingpublic static String[] split(String composite, String delim)
composite
- encoded composite stringdelim
- delimiter to split uponpublic String doEncode(Segment structure, EncodingCharacters encodingCharacters) throws HL7Exception
doEncode
in class Parser
structure
- The structure to encodeencodingCharacters
- The encoding charactersHL7Exception
- If there is a problem encodingpublic String doEncode(Type type, EncodingCharacters encodingCharacters) throws HL7Exception
doEncode
in class Parser
type
- The type to encodeencodingCharacters
- The encoding charactersHL7Exception
- If there is a problem encodingpublic static String encode(Type source, EncodingCharacters encodingChars)
source
- type to be encodedencodingChars
- encoding characters to be usedprotected String doEncode(Message source, String encoding) throws HL7Exception
doEncode
in class Parser
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)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.protected String doEncode(Message source) throws HL7Exception
doEncode
in class Parser
source
- a Message object from which to construct an encoded message stringHL7Exception
- if the data fields in the message do not permit encoding
(e.g. required fields are null)public static String encode(Group source, EncodingCharacters encodingChars) throws HL7Exception
source
- group to be encodedencodingChars
- encoding characters to be usedHL7Exception
- if an error occurred while encodingpublic static PipeParser getInstanceWithNoValidation()
DefaultHapiContext
initialized with a NoValidation validation context
.public static String encode(Segment source, EncodingCharacters encodingChars)
source
- segment to be encodedencodingChars
- encoding characters to be usedpublic static String stripLeadingWhitespace(String in)
in
- input stringpublic Segment getCriticalResponseData(String message) throws HL7Exception
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:
getCriticalResponseData
in class Parser
message
- the messageHL7Exception
- if no MSH segment could be createdpublic String getAckID(String message)
public void setLegacyMode(boolean legacyMode)
false
isLegacyMode()
public String encode(Message source) throws HL7Exception
encode
in class Parser
source
- a Message object from which to construct an encoded message stringHL7Exception
- if the data fields in the message do not permit encoding (e.g. required
fields are null)public Message parse(String message) throws HL7Exception
parse
in class Parser
message
- a String that contains an HL7 messageHL7Exception
- if the message is not correctly formatted.EncodingNotSupportedException
- if the message encoded is not supported by this parser.public boolean isLegacyMode()
Returns true
if 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 the parse(java.lang.String)
and
encode(ca.uhn.hl7v2.model.Message)
methods
public String getVersion(String message) throws HL7Exception
getVersion
in class Parser
message
- the messageHL7Exception
- if the version field can not be found.public void parse(Message message, String string) throws HL7Exception
Parser
parse
in class Parser
message
- The message to encodestring
- The string to parseHL7Exception
- If there is a problem encodingCopyright © 2001–2017 University Health Network. All rights reserved.