Validation module

class hl7apy.validation.Validator(level)

Class that handles validation. It defines validation levels and validate an element using VALIDATION.STRICT validation level

static is_quiet(level)

Equal to is_tolerant. Kept for backward compatibility :param level: :rtype: bool :return: True if validation level is tolerant

static is_strict(level)

Check if the given validation level is strict

Parameters:level (int) – validation level (see VALIDATION_LEVEL)
Return type:bool
Returns:True if validation level is strict
static is_tolerant(level)

Check if the given validation level is tolerant

Parameters:level (int) – validation level (see VALIDATION_LEVEL)
Return type:bool
Returns:True if validation level is tolerant
static validate(element, reference=None, report_file=None)

Checks if the Element is a valid HL7 message according to the reference specified. If the reference is not specified, it will be used the official HL7 structures for the elements. In particular it checks:

  • the maximum and minimum number of occurrences for every child
  • that children are all allowed
  • the datatype of fields, components and subcomponents
  • the values, in particular the length and the adherence with the HL7 table, if one is specified

It raises the first exception that it finds.

If report_file is specified, it will create a file with all the errors that occur.

Parameters:
  • elementElement: The element to validate
  • reference – the reference to use. Usually is None or a message profile object
  • report_file – the name of the report file to create
Returns:

The True if everything is ok

Raises:

ValidationError: when errors occur

Raises:

ValidationWarning: errors concerning the values