Esempio n. 1
0
def validate_renal_imaging(errors, obj):
    patient = obj.patient

    run_validators(errors, 'date', obj.date, [required, after_date_of_birth(patient), not_in_future])
    run_validators(errors, 'imaging_type', obj.imaging_type, [required])
    run_validators(errors, 'right_present', obj.right_present, [required])
    run_validators(errors, 'left_present', obj.left_present, [required])

    if obj.right_present:
        run_validators(errors, 'right_type', obj.right_type, [required, in_(['transplant', 'natural'])])
        run_validators(errors, 'right_length', obj.right_length, [required, range_(0, 100)])  # TODO range
        run_validators(errors, 'right_cysts', obj.right_cysts, [required])
        run_validators(errors, 'right_calcification', obj.right_calcification, [required])

        if obj.right_calcification:
            run_validators(errors, 'right_nephrocalcinosis', obj.right_nephrocalcinosis, [required])
            run_validators(errors, 'right_nephrolithiasis', obj.right_nephrolithiasis, [required])
        else:
            obj.right_nephrocalcinosis = None
            obj.right_nephrolithiasis = None
    else:
        obj.right_type = None
        obj.right_length = None
        obj.right_cysts = None
        obj.right_calcification = None
        obj.right_nephrocalcinosis = None
        obj.right_nephrolithiasis = None

    if obj.left_present:
        run_validators(errors, 'left_type', obj.left_type, [required, in_(['transplant', 'natural'])])
        run_validators(errors, 'left_length', obj.left_length, [required, range_(0, 100)])  # TODO range
        run_validators(errors, 'left_cysts', obj.left_cysts, [required])
        run_validators(errors, 'left_calcification', obj.left_calcification, [required])

        if obj.left_calcification:
            run_validators(errors, 'left_nephrocalcinosis', obj.left_nephrocalcinosis, [required])
            run_validators(errors, 'left_nephrolithiasis', obj.left_nephrolithiasis, [required])
        else:
            obj.left_nephrocalcinosis = None
            obj.left_nephrolithiasis = None
    else:
        obj.left_type = None
        obj.left_length = None
        obj.left_cysts = None
        obj.left_calcification = None
        obj.left_nephrocalcinosis = None
        obj.left_nephrolithiasis = None
Esempio n. 2
0
def validate_patient_demographics(errors, obj):
    run_validators(errors, 'first_name', obj.first_name, [not_empty, max_length(30)])
    run_validators(errors, 'last_name', obj.last_name, [not_empty, max_length(30)])
    run_validators(errors, 'date_of_birth', obj.date_of_birth, [required, not_in_future])
    run_validators(errors, 'date_of_death', obj.date_of_death, [optional, not_in_future])
    run_validators(errors, 'gender', obj.gender, [required, in_(['M', 'F'])])
    run_validators(errors, 'ethnicity_code', obj.ethnicity_code, [required])
    run_validators(errors, 'email_address', obj.email_address, [optional, email_address])
    run_validators(errors, 'nhs_no', obj.nhs_no, [optional, nhs_no])
    run_validators(errors, 'chi_no', obj.chi_no, [optional, chi_no])

    if not errors.is_valid():
        return

    if obj.date_of_death is not None and obj.date_of_death < obj.date_of_birth:
        errors.add_error('date_of_death', "Can't be before the patient's date of birth.")
Esempio n. 3
0
def test_in_not_in_list():
    with pytest.raises(ValidationError):
        in_([1, 2, 3])(4)
Esempio n. 4
0
def test_in_in_list():
    in_([1, 2, 3])(1)