Skip to content

Warning

Consider limiting how many UDFs you utilise in your rules as they can cause significant performance degredation when used on large datasets.

dve.core_engine.functions.implementations

Function implementations to be registered as UDFs.

check_correct_numeric_signage(val, expected_sign='+/-')

Check the expected sign of a numeric type.

Source code in src/dve/core_engine/functions/implementations.py
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
def check_correct_numeric_signage(
    val: Union[float, int, Decimal], expected_sign: str = "+/-"
) -> Optional[bool]:
    """Check the expected sign of a numeric type."""
    if val is None:
        return None
    if expected_sign not in ("+/-", "+", "-"):
        return None

    if expected_sign == "+/-":
        return True
    if expected_sign == "+":
        return val >= 0
    if expected_sign == "-":
        return val <= 0
    return None

date_in_current_financial_year(test_date)

Checks the date is in the current financial year

Source code in src/dve/core_engine/functions/implementations.py
39
40
41
42
def date_in_current_financial_year(test_date: datetime.date) -> bool:
    """Checks the date is in the current financial year"""
    current_fiscal_year_start: datetime.date = datetime.date(datetime.date.today().year, 4, 1)
    return test_date >= current_fiscal_year_start

nhsno_mod11_check(nhs_no)

Check that a given nhs number passes mod11 checks.

Source code in src/dve/core_engine/functions/implementations.py
88
89
90
def nhsno_mod11_check(nhs_no: str) -> bool:
    """Check that a given nhs number passes mod11 checks."""
    return NHSNumber.check_validates(nhs_no)

number_matches_within_percentage(comparator, number, percentage)

Check that number matches comparator to within a percentage of the value of comparator.

tolerance should be a decimal representaion of the percentage (e.g. 0.01 for 1%).

Source code in src/dve/core_engine/functions/implementations.py
73
74
75
76
77
78
79
80
81
82
83
84
85
def number_matches_within_percentage(
    comparator: Decimal, number: Decimal, percentage: Decimal
) -> Optional[bool]:
    """Check that `number` matches `comparator` to within a percentage of the value of `comparator`.

    `tolerance` should be a decimal representaion of the percentage (e.g. 0.01 for 1%).

    """
    if percentage is None or comparator is None:
        return None

    tolerance = comparator * percentage
    return number_matches_within_tolerance(comparator, number, tolerance)

number_matches_within_tolerance(comparator, number, tolerance)

Check that number matches comparator to within a fixed tolerance.

Source code in src/dve/core_engine/functions/implementations.py
63
64
65
66
67
68
69
70
def number_matches_within_tolerance(
    comparator: Decimal, number: Decimal, tolerance: Decimal
) -> Optional[bool]:
    """Check that `number` matches `comparator` to within a fixed tolerance."""
    if comparator is None or number is None or tolerance is None:
        return None

    return abs(number - comparator) <= abs(tolerance)