Sha256: 01680a354c484376888b5660315e67850b7a666a7d03392971ad0b48c3d858f8

Contents?: true

Size: 831 Bytes

Versions: 114

Compression:

Stored size: 831 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

114 entries across 114 versions & 1 rubygems

Version Path
renalware-core-2.1.1 app/validators/renalware/patients/blood_pressure_validator.rb
renalware-core-2.1.0 app/validators/renalware/patients/blood_pressure_validator.rb
renalware-core-2.0.167 app/validators/renalware/patients/blood_pressure_validator.rb
renalware-core-2.0.166 app/validators/renalware/patients/blood_pressure_validator.rb
renalware-core-2.0.165 app/validators/renalware/patients/blood_pressure_validator.rb
renalware-core-2.0.164 app/validators/renalware/patients/blood_pressure_validator.rb
renalware-core-2.0.163 app/validators/renalware/patients/blood_pressure_validator.rb
renalware-core-2.0.162 app/validators/renalware/patients/blood_pressure_validator.rb
renalware-core-2.0.161 app/validators/renalware/patients/blood_pressure_validator.rb
renalware-core-2.0.160 app/validators/renalware/patients/blood_pressure_validator.rb
renalware-core-2.0.159 app/validators/renalware/patients/blood_pressure_validator.rb
renalware-core-2.0.158 app/validators/renalware/patients/blood_pressure_validator.rb
renalware-core-2.0.157 app/validators/renalware/patients/blood_pressure_validator.rb
renalware-core-2.0.156 app/validators/renalware/patients/blood_pressure_validator.rb
renalware-core-2.0.155 app/validators/renalware/patients/blood_pressure_validator.rb
renalware-core-2.0.153 app/validators/renalware/patients/blood_pressure_validator.rb
renalware-core-2.0.152 app/validators/renalware/patients/blood_pressure_validator.rb
renalware-core-2.0.151 app/validators/renalware/patients/blood_pressure_validator.rb
renalware-core-2.0.149 app/validators/renalware/patients/blood_pressure_validator.rb
renalware-core-2.0.148 app/validators/renalware/patients/blood_pressure_validator.rb