Example #1
0
def validate_transplant(errors, obj):
    patient = obj.patient

    run_validators(
        errors, "transplant_date", obj.transplant_date, [required, after_date_of_birth(patient), not_in_future]
    )
    run_validators(errors, "transplant_type", obj.transplant_type, [required])
Example #2
0
def validate_hospitalisation(errors, obj):
    patient = obj.patient

    run_validators(errors, 'date_of_admission', obj.date_of_admission, [required, after_date_of_birth(patient), not_in_future])
    run_validators(errors, 'date_of_discharge', obj.date_of_discharge, [optional, after_date_of_birth(patient), not_in_future])

    if not errors.is_valid():
        return

    if obj.date_of_discharge is not None and obj.date_of_admission > obj.date_of_discharge:
        errors.add_error('date_of_discharge', 'Date of discharge must be on or after date of admission.')
Example #3
0
def validate_plasmapheresis(errors, obj):
    patient = obj.patient

    run_validators(errors, 'from_date', obj.from_date, [required, after_date_of_birth(patient), not_in_future])
    run_validators(errors, 'to_date', obj.to_date, [optional, after_date_of_birth(patient), not_in_future])
    run_validators(errors, 'no_of_exchanges', obj.no_of_exchanges, [required, min_(0)])
    run_validators(errors, 'response', obj.response, [required])

    if not errors.is_valid():
        return

    if obj.to_date is not None and obj.from_date > obj.to_date:
        errors.add_error('to_date', 'Must be after from date.')
Example #4
0
def validate_dialysis(errors, obj):
    patient = obj.patient

    run_validators(errors, 'from_date', obj.from_date, [required, after_date_of_birth(patient), not_in_future])
    run_validators(errors, 'to_date', obj.to_date, [optional, after_date_of_birth(patient), not_in_future])
    run_validators(errors, 'dialysis_type', obj.dialysis_type, [required])

    if not errors.is_valid():
        return

    if obj.to_date is not None:
        run_validators(errors, 'to_date', obj.to_date, [not_in_future])

        if obj.from_date > obj.to_date:
            errors.add_error('to_date', 'Must be after from date.')
Example #5
0
def validate_genetics(errors, obj):
    run_validators(errors, 'sample_sent', obj.sample_sent, [required, not_in_future])

    if obj.sample_sent is not None:
        run_validators(errors, 'sample_sent_date', obj.sample_sent_date, [required, not_in_future])
Example #6
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
Example #7
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.")
Example #8
0
def validate_medication(errors, obj):
    patient = obj.patient

    run_validators(errors, 'from_date', obj.from_date, [required, after_date_of_birth(patient), not_in_future])
    run_validators(errors, 'to_date', obj.to_date, [optional, after_date_of_birth(patient), not_in_future])
    run_validators(errors, 'name', obj.name, [not_empty])
    run_validators(errors, 'dose_quantity', obj.dose_quantity, [required, min_(0)])
    run_validators(errors, 'dose_unit', obj.dose_unit, [required])
    run_validators(errors, 'frequency', obj.frequency, [required])
    run_validators(errors, 'route', obj.route, [required])

    if not errors.is_valid():
        return

    if obj.to_date is not None and obj.from_date > obj.to_date:
        errors.add_error('to_date', 'Must be after from date.')