Sha256: c54648f0885f48fd49289be270403b310ee6e432d63ac0ed211719189dfc7b45

Contents?: true

Size: 830 Bytes

Versions: 19

Compression:

Stored size: 830 Bytes

Contents

# frozen_string_literal: true

module Renalware
  module Patients
    class BloodPressureValidator < ActiveModel::Validator
      include NumericRangeValidations
      MIN_VALUE = 20
      MAX_VALUE = 300

      def validate(bp)
        apply_validations(bp) if bp.present?
      end

      private

      def apply_validations(bp)
        validate_number_is_in_range(bp, :systolic, bp.systolic, MIN_VALUE, MAX_VALUE)
        validate_number_is_in_range(bp, :diastolic, bp.diastolic, MIN_VALUE, MAX_VALUE)
        validate_diastolic_less_than_systolic(bp)
      end

      def validate_diastolic_less_than_systolic(bp)
        errors = bp.errors
        return if errors.any?
        unless bp.diastolic.to_f < bp.systolic.to_f
          errors.add(:diastolic, :must_be_less_than_systolic)
        end
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
renalware-core-2.0.46 app/validators/renalware/patients/blood_pressure_validator.rb
renalware-core-2.0.45 app/validators/renalware/patients/blood_pressure_validator.rb
renalware-core-2.0.44 app/validators/renalware/patients/blood_pressure_validator.rb
renalware-core-2.0.43 app/validators/renalware/patients/blood_pressure_validator.rb
renalware-core-2.0.42 app/validators/renalware/patients/blood_pressure_validator.rb
renalware-core-2.0.41 app/validators/renalware/patients/blood_pressure_validator.rb
renalware-core-2.0.40 app/validators/renalware/patients/blood_pressure_validator.rb
renalware-core-2.0.39 app/validators/renalware/patients/blood_pressure_validator.rb
renalware-core-2.0.38 app/validators/renalware/patients/blood_pressure_validator.rb
renalware-core-2.0.37 app/validators/renalware/patients/blood_pressure_validator.rb
renalware-core-2.0.36 app/validators/renalware/patients/blood_pressure_validator.rb
renalware-core-2.0.35 app/validators/renalware/patients/blood_pressure_validator.rb
renalware-core-2.0.34 app/validators/renalware/patients/blood_pressure_validator.rb
renalware-core-2.0.33 app/validators/renalware/patients/blood_pressure_validator.rb
renalware-core-2.0.32 app/validators/renalware/patients/blood_pressure_validator.rb
renalware-core-2.0.31 app/validators/renalware/patients/blood_pressure_validator.rb
renalware-core-2.0.30 app/validators/renalware/patients/blood_pressure_validator.rb
renalware-core-2.0.28 app/validators/renalware/patients/blood_pressure_validator.rb
renalware-core-2.0.27 app/validators/renalware/patients/blood_pressure_validator.rb