How to use the hl7apy.exceptions.OperationNotAllowed 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 / core.py View on Github external
def parse_children(self, text, **kwargs):
        segment_name = text[:3].upper()
        if segment_name != self.name:
            raise OperationNotAllowed('Cannot assign a segment with a different name')
        text = text[4:] if segment_name != 'MSH' else text[3:]
        kwargs = {'name_prefix': self.name,
                  'references': self.structure_by_name,
                  'force_varies': self.allow_infinite_children}
        return super(Segment, self).parse_children(text, **kwargs)
github crs4 / hl7apy / hl7apy / core.py View on Github external
def __init__(self, name=None, parent=None, reference=None, version=None,
                 validation_level=None, traversal_parent=None):

        if name is None:
            raise OperationNotAllowed("Cannot instantiate an unknown Segment")

        if _valid_z_segment_name(name):
            if reference is None:
                reference = ('sequence', ())

            super(Segment, self).__init__(name, parent, reference, version,
                                          validation_level, traversal_parent)
            self.allow_infinite_children = True
            self._last_allowed_child_index = 0
            self._last_child_index = 0
        else:
            super(Segment, self).__init__(name, parent, reference, version,
                                          validation_level, traversal_parent)

            last_field = self.ordered_children[-1]
            last_field_structure = self.structure_by_name[last_field]
github crs4 / hl7apy / hl7apy / core.py View on Github external
def _can_add_child(self, child):
        if self.element._is_valid_child(child):
            if child.parent != self.element and child.traversal_parent != self.element:  # avoid infinite recursion
                child.parent = self.element
            else:
                # if validation is strict, check the child cardinality
                if Validator.is_strict(self.element.validation_level):
                    min_rep, max_rep = self.element.repetitions.get(child.name, (0, -1))
                    if len(self.indexes.get(child.name, [])) + 1 > int(max_rep) and max_rep > -1:
                        raise MaxChildLimitReached(self.element, child, max_rep)
                if self.element.validation_level != child.validation_level:
                    raise OperationNotAllowed('Cannot add a child with a different validation_level')
                if self.element.version != child.version:
                    raise OperationNotAllowed('Cannot add a child with a different HL7 version')
                return True
        else:
            raise ChildNotValid(child, self.element)
        return False
github crs4 / hl7apy / hl7apy / core.py View on Github external
def __init__(self):

        if self.__class__ == SupportComplexDataType:
            raise OperationNotAllowed("Cannot instantiate a SupportComplexDataType")

        self._datatype = None
github crs4 / hl7apy / hl7apy / core.py View on Github external
datatype = datatype or 'ST'
                if is_base_datatype(datatype, version):
                    reference = ('leaf', None, datatype, None, None, -1)
                else:
                    if version is None:
                        version = get_default_version()
                    dt_struct = load_reference(datatype, "Datatypes_Structs", version)
                    reference = ('sequence', dt_struct, datatype, None, None, -1)
                Element.__init__(self, name, parent, reference, version,
                                 validation_level, traversal_parent)
            else:
                raise

        if datatype is not None and Validator.is_strict(validation_level) and \
                datatype != 'varies' and datatype != self.datatype:
            raise OperationNotAllowed("Cannot assign a different datatype with strict validation")

        if datatype is not None:  # force the datatype to be the one chosen by the user
            self.datatype = datatype
        elif self.name is None:  # if it is unknown and no datatype has been given
            self.datatype = None
github crs4 / hl7apy / hl7apy / core.py View on Github external
def parse_children(self, text, find_groups=True, **kwargs):
        from hl7apy.parser import get_message_info

        encoding_chars, message_structure, version = get_message_info(text)

        if not self.is_unknown() and self.name != message_structure:
            raise OperationNotAllowed('Cannot assign a message with a different name')
        elif self.is_unknown():  # the message become a known message
            self.name = message_structure
            self._find_structure()
        if self.version != version:
            raise OperationNotAllowed('Cannot assign a message with a different version')
        elif self.encoding_chars != encoding_chars:
            raise OperationNotAllowed('Cannot assign a message with different encoding chars')

        super(Message, self).parse_children(text, find_groups, **kwargs)
github crs4 / hl7apy / hl7apy / core.py View on Github external
def __init__(self, name=None, datatype=None, parent=None, reference=None,
                 version=None, validation_level=None, traversal_parent=None):

        if self.__class__ == CanBeVaries:
            raise OperationNotAllowed("Cannot instantiate a CanBeVaries")

        if datatype == 'varies' and reference is None:
            reference = ('leaf', None, 'varies', None, None, -1)

        if not Validator.is_strict(validation_level) and datatype not in (None, 'varies') \
                and not is_base_datatype(datatype, version):
            version = version or get_default_version()
            children_refs = load_reference(datatype, 'Datatypes_Structs', version)
            if name is not None:
                # first we get the original reference for the long_name, table etc
                orig_ref = load_reference(name, 'Component', version)
                reference = ('sequence', children_refs, datatype, orig_ref[3], orig_ref[4], orig_ref[5])
            else:
                reference = ('sequence', children_refs, datatype, None, None, -1)

        if name is not None and _valid_child_name(name, 'VARIES'):
github crs4 / hl7apy / hl7apy / core.py View on Github external
def _can_add_child(self, child):
        if self.element._is_valid_child(child):
            if child.parent != self.element and child.traversal_parent != self.element:  # avoid infinite recursion
                child.parent = self.element
            else:
                # if validation is strict, check the child cardinality
                if Validator.is_strict(self.element.validation_level):
                    min_rep, max_rep = self.element.repetitions.get(child.name, (0, -1))
                    if len(self.indexes.get(child.name, [])) + 1 > int(max_rep) and max_rep > -1:
                        raise MaxChildLimitReached(self.element, child, max_rep)
                if self.element.validation_level != child.validation_level:
                    raise OperationNotAllowed('Cannot add a child with a different validation_level')
                if self.element.version != child.version:
                    raise OperationNotAllowed('Cannot add a child with a different HL7 version')
                return True
        else:
            raise ChildNotValid(child, self.element)
        return False
github crs4 / hl7apy / hl7apy / core.py View on Github external
def parse_children(self, text, find_groups=True, **kwargs):
        from hl7apy.parser import get_message_info

        encoding_chars, message_structure, version = get_message_info(text)

        if not self.is_unknown() and self.name != message_structure:
            raise OperationNotAllowed('Cannot assign a message with a different name')
        elif self.is_unknown():  # the message become a known message
            self.name = message_structure
            self._find_structure()
        if self.version != version:
            raise OperationNotAllowed('Cannot assign a message with a different version')
        elif self.encoding_chars != encoding_chars:
            raise OperationNotAllowed('Cannot assign a message with different encoding chars')

        super(Message, self).parse_children(text, find_groups, **kwargs)
github crs4 / hl7apy / hl7apy / core.py View on Github external
def __init__(self, name=None, datatype=None, parent=None, reference=None,
                 version=None, validation_level=None, traversal_parent=None):

        SupportComplexDataType.__init__(self)

        # if datatype == 'varies' and reference is None:
        #     reference = ('leaf', None, 'varies', None, None, -1)

        CanBeVaries.__init__(self, name, datatype, parent, reference,
                             version, validation_level, traversal_parent)

        if self.is_unknown() and Validator.is_strict(validation_level) and \
                not is_base_datatype(self.datatype, self.version) and self.datatype != 'varies':
            raise OperationNotAllowed("Cannot instantiate an unknown Element with strict validation")