Exceptions¶
-
class
hl7apy.exceptions.
HL7apyException
¶ Base exception class for hl7apy
-
class
hl7apy.exceptions.
ParserError
¶ Error during parsing
>>> from hl7apy.parser import parse_message >>> m = parse_message('NOTHL7') # doctest: +IGNORE_EXCEPTION_DETAIL Traceback (most recent call last): ... ParserError: Invalid message
-
class
hl7apy.exceptions.
UnsupportedVersion
(version)¶ Given version is not supported
>>> from hl7apy import set_default_version >>> set_default_version("2.0") # doctest: +IGNORE_EXCEPTION_DETAIL Traceback (most recent call last): ... UnsupportedVersion: The version 2.0 is not supported
-
class
hl7apy.exceptions.
ChildNotFound
(name)¶ Raised when a child element is not found in the HL7 reference structures for the given version
>>> from hl7apy.core import Segment, Field >>> s = Segment('MSH') >>> s.unknown = Field() # doctest: +IGNORE_EXCEPTION_DETAIL Traceback (most recent call last): ... ChildNotFound: No child named UNKNOWN
-
class
hl7apy.exceptions.
ChildNotValid
(child, parent)¶ Raised when you try to assign an unexpected child to an
Element
>>> from hl7apy.core import Segment, Field >>> s = Segment('PID', validation_level=1) >>> s.pid_1 = Field('PID_34') # doctest: +IGNORE_EXCEPTION_DETAIL Traceback (most recent call last): ... ChildNotValid: <Field PID_34 (LAST_UPDATE_FACILITY) of type HD> is not a valid child for PID_1
-
class
hl7apy.exceptions.
UnknownValidationLevel
¶ Raised when the validation_level specified is not valid
It should be one of those defined in
VALIDATION_LEVEL
.>>> from hl7apy import set_default_validation_level >>> set_default_validation_level(3) # doctest: +IGNORE_EXCEPTION_DETAIL Traceback (most recent call last): ... UnknownValidationLevel
-
class
hl7apy.exceptions.
OperationNotAllowed
¶ Generic exception raised when something is not allowed
>>> from hl7apy.core import Segment >>> s = Segment() # doctest: +IGNORE_EXCEPTION_DETAIL Traceback (most recent call last): ... OperationNotAllowed: Cannot instantiate an unknown Segment
-
class
hl7apy.exceptions.
MaxChildLimitReached
(parent, child, limit)¶ Raised when a child cannot be added to an instance of
Element
since theElement
has already reached the maximum number of children allowed for the given child type (e.g. aMessage
should have at most 1 MSH segment)>>> from hl7apy.core import Message, Segment >>> m = Message("OML_O33", validation_level=1) >>> m.add(Segment('MSH')) # doctest: +IGNORE_EXCEPTION_DETAIL Traceback (most recent call last): ... MaxChildLimitReached: Cannot add <Segment MSH>: max limit (1) reached for <Message OML_O33>
-
class
hl7apy.exceptions.
MaxLengthReached
(value, limit)¶ Value length exceeds its datatype
max_length
.>>> from hl7apy.v2_5 import get_base_datatypes >>> from hl7apy.consts import VALIDATION_LEVEL >>> SI = get_base_datatypes()['SI'] >>> st = SI(value=11111, validation_level=VALIDATION_LEVEL.STRICT) # doctest: +IGNORE_EXCEPTION_DETAIL Traceback (most recent call last): ... MaxLengthReached: The value 11111 exceed the max length: 4
-
class
hl7apy.exceptions.
InvalidName
(cls, name)¶ Raised if the reference for the given class/name has not been found
>>> from hl7apy.core import Message >>> Message('Unknown') # doctest: +IGNORE_EXCEPTION_DETAIL Traceback (most recent call last): ... InvalidName: Invalid name for Message: UNKNOWN
-
class
hl7apy.exceptions.
InvalidDataType
(datatype)¶ Raised when the currently used HL7 version does not support the given datatype
>>> from hl7apy.factories import datatype_factory >>> datatype_factory('TN', '11 123456', version="2.4") #doctest: +ELLIPSIS <hl7apy.base_datatypes.TN object at 0x...> >>> datatype_factory('GTS', '11 123456', version="2.4") # doctest: +IGNORE_EXCEPTION_DETAIL Traceback (most recent call last): ... InvalidDataType: The datatype GTS is not available for the given HL7 version
-
class
hl7apy.exceptions.
InvalidHighlightRange
(lower_bound, upper_bound)¶ Raised when the specified highlight range is not valid
For a description of highlight range see
hl7apy.base_datatypes.TextualDataType
>>> from hl7apy.v2_5 import ST >>> s = ST(value='some useful information', highlights=((5, 3),)) >>> s.to_er7() # doctest: +IGNORE_EXCEPTION_DETAIL Traceback (most recent call last): ... InvalidHighlightRange: Invalid highlight range: 5 - 3
-
class
hl7apy.exceptions.
InvalidDateFormat
(out_format)¶ Raised when the output format for a
hl7apy.base_datatypes.DateTimeDataType
is not valid>>> from hl7apy.v2_5 import DTM >>> DTM(value='10102013', out_format="%d%m%Y") # doctest: +IGNORE_EXCEPTION_DETAIL Traceback (most recent call last): ... InvalidDateFormat: Invalid date format: %d%m%Y
-
class
hl7apy.exceptions.
InvalidDateOffset
(offset)¶ Raised when the offset for a
TM
orhl7apy.base_datatypes.DTM
is not valid>>> from hl7apy.v2_5 import DTM >>> DTM(value='20131010', out_format="%Y%m%d", offset='+1300') # doctest: +IGNORE_EXCEPTION_DETAIL Traceback (most recent call last): ... InvalidDateOffset: Invalid date offset: +1300
-
class
hl7apy.exceptions.
InvalidEncodingChars
¶ Raised when the encoding chars specified is not a correct set of HL7 encoding chars
>>> from hl7apy.core import Message >>> encoding_chars = {'GROUP': '\r', 'SEGMENT': '\r', 'COMPONENT': '^', 'SUBCOMPONENT': '&', 'REPETITION': '~', 'ESCAPE': '\\'} >>> m = Message('ADT_A01', encoding_chars=encoding_chars) # doctest: +IGNORE_EXCEPTION_DETAIL Traceback (most recent call last): ... InvalidEncodingChars: Missing required encoding chars