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.')
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.')
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.')
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.')
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])
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
def test_after_date_of_birth_greater_than(patient): after_date_of_birth(patient)(date(2000, 1, 2))
def test_after_date_of_birth_equal(patient): after_date_of_birth(patient)(date(2000, 1, 1))
def test_after_date_of_birth_less_than(patient): with pytest.raises(ValidationError): after_date_of_birth(patient)(date(1999, 12, 31))
def test_after_date_of_birth_no_date_of_birth(): patient = Patient() after_date_of_birth(patient)(date(1999, 1, 1))