How to use the hl7apy.exceptions.HL7apyException function in hl7apy

To help you get started, we’ve selected a few hl7apy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github crs4 / hl7apy / hl7apy / exceptions.py View on Github external
>>> 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
    """
    def __init__(self, lower_bound, upper_bound):
        self.lower_bound = lower_bound
        self.upper_bound = upper_bound

    def __str__(self):
        return 'Invalid highlight range: {0} - {1}'.format(self.lower_bound, self.upper_bound)


class InvalidDateFormat(HL7apyException):
    """
    Raised when the output format for a :class:`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
    """
    def __init__(self, out_format):
        self.format = out_format

    def __str__(self):
        return 'Invalid date format: {0}'.format(self.format)

github crs4 / hl7apy / hl7apy / exceptions.py View on Github external
"""
    Raised when the microseconds precision of a TM or DTM oject is not between 1 and 4

    >>> from hl7apy.v2_5 import get_base_datatypes
    >>> DTM = get_base_datatypes()['DTM']
    >>> DTM(value='20131010', microsec_precision=5)  # doctest: +IGNORE_EXCEPTION_DETAIL
    Traceback (most recent call last):
    ...
    InvalidMicrosecondsPrecision: Invalid microseconds precision. It must be between 1 and 4
    """

    def __str__(self):
        return 'Invalid microseconds precision. It must be between 1 and 4'


class InvalidEncodingChars(HL7apyException):
    """
    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
    """
    def __str__(self):
        return self.message if self.message else 'Invalid encoding chars'


class MessageProfileNotFound(HL7apyException):
github crs4 / hl7apy / hl7apy / exceptions.py View on Github external
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
    """
    def __init__(self, version):
        self.version = version

    def __str__(self):
        return 'The version {0} is not supported'.format(self.version)


class ChildNotFound(HL7apyException):
    """
    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
    """
    def __init__(self, name):
        self.name = name

    def __str__(self):
        return 'No child named {0}'.format(self.name)
github crs4 / hl7apy / hl7apy / exceptions.py View on Github external
>>> m = Message("OML_O33", validation_level=1)
    >>> m.add(Segment('MSH'))  # doctest: +IGNORE_EXCEPTION_DETAIL
    Traceback (most recent call last):
    ...
    MaxChildLimitReached: Cannot add : max limit (1) reached for 
    """
    def __init__(self, parent, child, limit):
        self.parent = parent
        self.child = child
        self.limit = limit

    def __str__(self):
        return 'Cannot add {0}: max limit ({1}) reached for {2}'.format(self.child, self.limit, self.parent)


class MaxLengthReached(HL7apyException):
    """
    Value length exceeds its datatype :attr:`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
    """
    def __init__(self, value, limit):
        self.value = value
        self.limit = limit

    def __str__(self):
github crs4 / hl7apy / hl7apy / exceptions.py View on Github external
"""


class OperationNotAllowed(HL7apyException):
    """
    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 MaxChildLimitReached(HL7apyException):
    """
    Raised when a child cannot be added to an instance of :class:`Element `
    since the :class:`Element ` has already reached the maximum number
    of children allowed for the given child type (e.g. a :class:`Message ` 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 : max limit (1) reached for 
    """
    def __init__(self, parent, child, limit):
        self.parent = parent
        self.child = child
github crs4 / hl7apy / hl7apy / exceptions.py View on Github external
>>> from hl7apy.factories import datatype_factory
    >>> datatype_factory('TN', '11 123456', version="2.4") #doctest: +ELLIPSIS
    
    >>> 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
    """
    def __init__(self, datatype):
        self.datatype = datatype

    def __str__(self):
        return "The datatype {0} is not available for the given HL7 version".format(self.datatype)


class InvalidHighlightRange(HL7apyException):
    """
    Raised when the specified highlight range is not valid

    For a description of highlight range see :class:`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
    """
    def __init__(self, lower_bound, upper_bound):
        self.lower_bound = lower_bound
        self.upper_bound = upper_bound
github crs4 / hl7apy / hl7apy / mllp.py View on Github external
from __future__ import absolute_import
from __future__ import unicode_literals

import re
import socket
try:
    from SocketServer import StreamRequestHandler, ThreadingTCPServer
except ImportError:
    from socketserver import StreamRequestHandler, ThreadingTCPServer

from hl7apy.parser import get_message_type
from hl7apy.exceptions import HL7apyException, ParserError


class UnsupportedMessageType(HL7apyException):
    """
    Error that occurs when the :class:`MLLPServer` receives a message without an associated handler
    """
    def __init__(self, msg_type):
        self.msg_type = msg_type

    def __str__(self):
        return 'Unsupported message type %s' % self.msg_type


class InvalidHL7Message(HL7apyException):
    """
    Error that occurs when the :class:`MLLPServer` receives a string which doesn't represent an ER7-encoded HL7 message
    """
    def __str__(self):
        return 'The string received is not a valid HL7 message'
github crs4 / hl7apy / hl7apy / exceptions.py View on Github external
Raised when the output format for a :class:`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
    """
    def __init__(self, out_format):
        self.format = out_format

    def __str__(self):
        return 'Invalid date format: {0}'.format(self.format)


class InvalidDateOffset(HL7apyException):
    """
    Raised when the offset for a :class:`TM` or :class:`hl7apy.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
    """
    def __init__(self, offset):
        self.offset = offset

    def __str__(self):
        return 'Invalid date offset: {0}'.format(self.offset)

github crs4 / hl7apy / hl7apy / exceptions.py View on Github external
"""


class ParserError(HL7apyException):
    """
    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 ValidationError(HL7apyException):
    """
    Error during validation

    >>> from hl7apy.parser import parse_message
    >>> from hl7apy.validation import VALIDATION_LEVEL
    >>> msh = 'MSH|^~\&|SENDING APP|SENDING FAC|REC APP|REC FAC|20080115153000||ADT^A01^ADT_A01|' \
    '0123456789|P|2.5||||AL\\r'
    >>> evn = 'EVN||20080115153000||AAA|AAA|20080114003000\\r'
    >>> pid = 'PID|1||123-456-789^^^HOSPITAL^MR||SURNAME^NAME^A|||M|||1111 SOMEWHERE STREET^^SOMEWHERE^^^USA||' \
    '555-555-2004~444-333-222|||M\\r'
    >>> message = msh + evn + pid
    >>> parse_message(message, validation_level=VALIDATION_LEVEL.STRICT, force_validation=True)  # doctest: +IGNORE_EXCEPTION_DETAIL
    Traceback (most recent call last):
    ...
    ValidationError: Missing required child ADT_A01.PV1
    """
github crs4 / hl7apy / hl7apy / exceptions.py View on Github external
>>> 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:  is not a valid child for PID_1
    """
    def __init__(self, child, parent):
        self.child = child
        self.parent = parent

    def __str__(self):
        return '{0} is not a valid child for {1}'.format(self.child, self.parent)


class UnknownValidationLevel(HL7apyException):
    """
    Raised when the validation_level specified is not valid

    It should be one of those defined in :class:`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 OperationNotAllowed(HL7apyException):
    """
    Generic exception raised when something is not allowed