Validation helpers¶
A place for generic validation functions.
In some places the variable name date_time has been used to avoid conflict with the imported datetime class.
-
class
validate.NhClinicalValidationUtils(pool, cr)[source]¶ -
_module= 'validate'¶
-
_name= 'nh.clinical.validation_utils'¶
-
fields_in_min_max_range(record, field_names_to_validate=None)[source]¶ This method has a very specific use case. A model may be used for something like configuration and may have fields like temperature, temperature_minimum, and temperature_maximum. The method will take a record with all its fields populated and validate that each ‘normal’ field is within the range specified by its corresponding minimum and maximum fields.
Any model that has fields that follow the naming convention demonstrated above can use this method for validation.
Parameters: - record –
- field_names_to_validate (list) –
Returns:
-
-
validate._convert_string_to_datetime(date_time)[source]¶ Converts a supplied string into a datetime or just passes through a supplied datetime.
Parameters: date_time – String or datetime object. Returns: Naive datetime object if converted from string Return type: datetime.datetime
-
validate.in_min_max_range(min_value, max_value, value)[source]¶ Validates that a value is within a range given by the passed minimum and maximum values. The value is allowed to be equal to the minimum and maximum but not less than or greater than.
Parameters: - min_value – Minimal value the value cannot be lesser than.
- max_value – Maximum value the value cannot be greater than.
- value – Value to ensure is the minimum and maximum values.
Raises: ValidationError
-
validate.not_in_the_future(date_time)[source]¶ Validate that supplied date_time string is not after the current server time.
Parameters: date_time – String or datetime. NOTE: This needs to be in UTC as datetime.now() will return a naive date.
-
validate.not_in_the_future_multiple_args(*args)[source]¶ Validates multiple datetime/strings representing datetimes
Parameters: args – iterable of datetime/string representing datetime
-
validate.start_datetime_not_after_end_datetime(start_datetime, end_datetime)[source]¶ Validate that start_datetime is not after end_datetime.
Datetimes if not instances of datetime.datetime will be converted into naive datetimes. So there will be issues comparing a timezone aware and naive datetime.
Parameters: - start_datetime – String or datetime
- end_datetime – String or datetime