Sha256: 8e61a5aade3ddc232d51da7b7300d510112ce8122371774314b7ff4dce3f381a

Contents?: true

Size: 1.92 KB

Versions: 43

Compression:

Stored size: 1.92 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.eager_load(:required_observation_description).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

43 entries across 43 versions & 1 rubygems

Version Path
renalware-core-2.1.1 app/models/renalware/pathology/requests/global_rule/request_result.rb
renalware-core-2.1.0 app/models/renalware/pathology/requests/global_rule/request_result.rb
renalware-core-2.0.167 app/models/renalware/pathology/requests/global_rule/request_result.rb
renalware-core-2.0.166 app/models/renalware/pathology/requests/global_rule/request_result.rb
renalware-core-2.0.165 app/models/renalware/pathology/requests/global_rule/request_result.rb
renalware-core-2.0.164 app/models/renalware/pathology/requests/global_rule/request_result.rb
renalware-core-2.0.163 app/models/renalware/pathology/requests/global_rule/request_result.rb
renalware-core-2.0.162 app/models/renalware/pathology/requests/global_rule/request_result.rb
renalware-core-2.0.161 app/models/renalware/pathology/requests/global_rule/request_result.rb
renalware-core-2.0.160 app/models/renalware/pathology/requests/global_rule/request_result.rb
renalware-core-2.0.159 app/models/renalware/pathology/requests/global_rule/request_result.rb
renalware-core-2.0.158 app/models/renalware/pathology/requests/global_rule/request_result.rb
renalware-core-2.0.157 app/models/renalware/pathology/requests/global_rule/request_result.rb
renalware-core-2.0.156 app/models/renalware/pathology/requests/global_rule/request_result.rb
renalware-core-2.0.155 app/models/renalware/pathology/requests/global_rule/request_result.rb
renalware-core-2.0.153 app/models/renalware/pathology/requests/global_rule/request_result.rb
renalware-core-2.0.152 app/models/renalware/pathology/requests/global_rule/request_result.rb
renalware-core-2.0.151 app/models/renalware/pathology/requests/global_rule/request_result.rb
renalware-core-2.0.149 app/models/renalware/pathology/requests/global_rule/request_result.rb
renalware-core-2.0.148 app/models/renalware/pathology/requests/global_rule/request_result.rb