Sha256: f68d0bb46d3bd3b964c1b5d11eef347bdf2e3403b0b2b032eca2278dec5075b4

Contents?: true

Size: 1.87 KB

Versions: 35

Compression:

Stored size: 1.87 KB

Contents

# frozen_string_literal: true

require_dependency "renalware/pathology/requests"

module Renalware
  module Pathology
    module Requests
      class GlobalRule
        class RequestResult < GlobalRule
          validates :param_comparison_operator, inclusion:
            { in: PARAM_COMPARISON_OPERATORS, allow_nil: false }
          validates :param_comparison_value, presence: true
          validate :request_description_present
          validate :required_observation_description_for_request_description_present

          def observation_required_for_patient?(patient, _date)
            observation =
              ObservationForPatientObservationDescriptionQuery.new(
                patient, observation_description
              ).call
            observation_result = observation.result.to_i if observation.present?

            return true if observation_result.nil?
            observation_result.send(param_comparison_operator.to_sym, param_comparison_value.to_i)
          end

          def to_s
            "last result is #{param_comparison_operator} #{param_comparison_value}"
          end

          private

          def observation_description
            request_description.required_observation_description
          end

          def request_description
            RequestDescription.find_by(id: param_id)
          end

          def request_description_present
            return if request_description.present?
            errors.add(:param_id, "param_id must be the id of an RequestDescription")
          end

          def required_observation_description_for_request_description_present
            return if request_description.present? &&
                      request_description.required_observation_description.present?
            errors.add(:request_description, "required observation description can't be blank")
          end
        end
      end
    end
  end
end

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
renalware-core-2.0.46 app/models/renalware/pathology/requests/global_rule/request_result.rb
renalware-core-2.0.45 app/models/renalware/pathology/requests/global_rule/request_result.rb
renalware-core-2.0.44 app/models/renalware/pathology/requests/global_rule/request_result.rb
renalware-core-2.0.43 app/models/renalware/pathology/requests/global_rule/request_result.rb
renalware-core-2.0.42 app/models/renalware/pathology/requests/global_rule/request_result.rb
renalware-core-2.0.41 app/models/renalware/pathology/requests/global_rule/request_result.rb
renalware-core-2.0.40 app/models/renalware/pathology/requests/global_rule/request_result.rb
renalware-core-2.0.39 app/models/renalware/pathology/requests/global_rule/request_result.rb
renalware-core-2.0.38 app/models/renalware/pathology/requests/global_rule/request_result.rb
renalware-core-2.0.37 app/models/renalware/pathology/requests/global_rule/request_result.rb
renalware-core-2.0.36 app/models/renalware/pathology/requests/global_rule/request_result.rb
renalware-core-2.0.35 app/models/renalware/pathology/requests/global_rule/request_result.rb
renalware-core-2.0.34 app/models/renalware/pathology/requests/global_rule/request_result.rb
renalware-core-2.0.33 app/models/renalware/pathology/requests/global_rule/request_result.rb
renalware-core-2.0.32 app/models/renalware/pathology/requests/global_rule/request_result.rb
renalware-core-2.0.31 app/models/renalware/pathology/requests/global_rule/request_result.rb
renalware-core-2.0.30 app/models/renalware/pathology/requests/global_rule/request_result.rb
renalware-core-2.0.28 app/models/renalware/pathology/requests/global_rule/request_result.rb
renalware-core-2.0.27 app/models/renalware/pathology/requests/global_rule/request_result.rb
renalware-core-2.0.26 app/models/renalware/pathology/requests/global_rule/request_result.rb