This is the HL7 Null value. It means that a field is present and blank.
Returns a instance of the hl7.Message that allows indexed access to the data elements.
A custom hl7.Factory subclass can be passed in to be used when constructing the message and it’s components.
Note
HL7 usually contains only ASCII, but can use other character sets (HL7 Standards Document, Section 1.7.1), however as of v2.8, UTF-8 is the preferred character set [1].
python-hl7 works on Python unicode strings. hl7.parse() will accept unicode string or will attempt to convert bytestrings into unicode strings using the optional encoding parameter. encoding defaults to UTF-8, so no work is needed for bytestrings in UTF-8, but for other character sets like ‘cp1252’ or ‘latin1’, encoding must be set appropriately.
>>> h = hl7.parse(message)
To decode a non-UTF-8 byte string:
hl7.parse(message, encoding='latin1')
Return type: | hl7.Message |
---|
[1] | http://wiki.hl7.org/index.php?title=Character_Set_used_in_v2_messages |
Determines whether a line looks like an HL7 message. This method only does a cursory check and does not fully validate the message.
Return type: | bool |
---|
Files are wrapped in FHS / FTS FHS = file header segment FTS = file trailer segment
Given a file, split out the messages. Does not do any validation on the message. Throws away batch and file segments.
Generate a unique 20 character message id.
See http://www.hl7resources.com/Public/index.html?a55433.htm
Parse hl7 DTM string value datetime.datetime.
value is of the format YYYY[MM[DD[HH[MM[SS[.S[S[S[S]]]]]]]]][+/-HHMM] or a ValueError will be raised.
Return type: | :py:;class:datetime.datetime |
---|
Base class for sequences that can be indexed using 1-based index
Support list access using HL7 compatible 1-based indices. Can be used to get and set values.
>>> s = hl7.Sequence([1, 2, 3, 4])
>>> s(1) == s[0]
True
>>> s(2, "new")
>>> s
[1, 'new', 3, 4]
Abstract root class for the parts of the HL7 message.
Join a the child containers into a single string, separated by the self.separator. This method acts recursively, calling the children’s __unicode__ method. Thus unicode() is the approriate method for turning the python-hl7 representation of HL7 into a standard string.
>>> unicode(h) == message
True
Note
For Python 2.x use unicode(), but for Python 3.x, use str()
Create a new instance of Accessor for segment. Index numbers start from 1.
Return a new OrderedDict which maps field names to their values
Make a new Accessor object from a sequence or iterable
Return a new Accessor object replacing specified fields with new values
Alias for field number 4
Alias for field number 2
Return the string accessor key that represents this instance
Create an Accessor by parsing an accessor key.
The key is defined as:
SEG[n]-Fn-Rn-Cn-SnF FieldR RepeatC ComponentS Sub-ComponentIndexing is from 1 for compatibility with HL7 spec numbering.
Example:
PID.F1.R1.C2.S2 or PID.1.1.2.2PID (default to first PID segment, counting from 1)F1 (first after segment id, HL7 Spec numbering)R1 (repeat counting from 1)C2 (component 2 counting from 1)S2 (component 2 counting from 1)
Alias for field number 3
Alias for field number 0
Alias for field number 1
Alias for field number 5
Representation of an HL7 message. It contains a list of hl7.Segment instances.
Index, segment-based or accessor lookup.
If key is an integer, __getitem__ acts list a list, returning the hl7.Segment held at that index:
>>> h[1]
[[u'PID'], ...]
If the key is a string of length 3, __getitem__ acts like a dictionary, returning all segments whose segment_id is key (alias of hl7.Message.segments()).
>>> h['OBX']
[[[u'OBX'], [u'1'], ...]]
If the key is a string of length greater than 3, the key is parsed into an hl7.Accessor and passed to hl7.Message.extract_field().
If the key is an hl7.Accessor, it is passed to hl7.Message.extract_field().
Index or accessor assignment.
If key is an integer, __setitem__ acts list a list, setting the hl7.Segment held at that index:
>>> h[1] = hl7.Segment("|", [hl7.Field("^", [u'PID'], [u''])])
If the key is a string of length greater than 3, the key is parsed into an hl7.Accessor and passed to hl7.Message.assign_field().
>>> h["PID.2"] = "NEW"
If the key is an hl7.Accessor, it is passed to hl7.Message.assign_field().
Assign a value into a message using the tree based assignment notation. The segment must exist.
Extract a field using a future proofed approach, based on rules in: http://wiki.medical-objects.com.au/index.php/Hl7v2_parsing
Create an hl7 ACK response hl7.Message, per spec 2.9.2, for this message.
See http://www.hl7standards.com/blog/2007/02/01/ack-message-original-mode-acknowledgement/
ack_code options are one of AA (accept), AR (reject), AE (error) (see HL7 Table 0008 - Acknowledgment Code) message_id control message ID for ACK, defaults to unique generated ID application name of sending application, defaults to receiving application of message facility name of sending facility, defaults to receiving facility of message
Create a new hl7.Component compatible with this message
Create a new hl7.Message compatible with this message
Create a new hl7.Repetition compatible with this message
Create a new hl7.Segment compatible with this message
See: http://www.hl7standards.com/blog/2006/11/02/hl7-escape-sequences/
To process this correctly, the full set of separators (MSH.1/MSH.2) needs to be known.
Pass through the message. Replace recognised characters with their escaped version. Return an ascii encoded string.
Functionality:
Incomplete:
Extract a field using a future proofed approach, based on rules in: http://wiki.medical-objects.com.au/index.php/Hl7v2_parsing
‘PID|Field1|Component1^Component2|Component1^Sub-Component1&Sub-Component2^Component3|Repeat1~Repeat2’,
PID.F3.R1.C2.S2 = ‘Sub-Component2’PID.F4.R2.C1 = ‘Repeat1’
Compatibility Rules:
If the parse tree is deeper than the specified path continue following the first child branch until a leaf of the tree is encountered and return that value (which could be blank).
Example:
PID.F3.R1.C2 = ‘Sub-Component1’ (assume .SC1)If the parse tree terminates before the full path is satisfied check each of the subsequent paths and if every one is specified at position 1 then the leaf value reached can be returned as the result.
PID.F4.R1.C1.SC1 = ‘Repeat1’ (ignore .SC1)
Gets the first segment with the segment_id from the parsed message.
>>> h.segment('PID')
[[u'PID'], ...]
Return type: | hl7.Segment |
---|
Returns the requested segments from the parsed message that are identified by the segment_id (e.g. OBR, MSH, ORC, OBX).
>>> h.segments('OBX')
[[[u'OBX'], [u'1'], ...]]
Return type: | list of hl7.Segment |
---|
See: http://www.hl7standards.com/blog/2006/11/02/hl7-escape-sequences/
To process this correctly, the full set of separators (MSH.1/MSH.2) needs to be known.
This will convert the identifiable sequences. If the application provides mapping, these are also used. Items which cannot be mapped are removed
For example, the App Map count provide N, H, Zxxx values
Chapter 2: Section 2.10
At the moment, this functionality can:
It cannot:
Second level of an HL7 message, which represents an HL7 Segment. Traditionally this is a line of a message that ends with a carriage return and is separated by pipes. It contains a list of hl7.Field instances.
Third level of an HL7 message, that traditionally is surrounded by pipes and separated by carets. It contains a list of strings or hl7.Repetition instances.
Fourth level of an HL7 message. A field can repeat. It contains a list of strings or hl7.Component instances.
Fifth level of an HL7 message. A component is a composite datatypes. It contains a list of string sub-components.
Factory used to create each type of Container.
A subclass can be used to create specialized subclasses of each container.
Create an instance of hl7.Component
alias of Component
Create an instance of hl7.Message
alias of Message
Create an instance of hl7.Repetition
alias of Repetition
Create an instance of hl7.Segment
alias of Segment
A basic, blocking, HL7 MLLP client based upon socket.
MLLPClient implements two methods for sending data to the server.
Can be used by the with statement to ensure MLLPClient.close() is called:
with MLLPClient(host, port) as client:
client.send_message('MSH|...')
MLLPClient takes an optional encoding parameter, defaults to UTF-8, for encoding unicode messages [2].
[2] | http://wiki.hl7.org/index.php?title=Character_Set_used_in_v2_messages |
Release the socket connection
Low-level, direct access to the socket.send (data must be already wrapped in an MLLP container). Blocks until the server returns.
Wraps a byte string, unicode string, or hl7.Message in a MLLP container and send the message to the server
If message is a byte string, we assume it is already encoded properly. If message is unicode or hl7.Message, it will be encoded according to hl7.client.MLLPClient.encoding