Sha256: b9fb0ed3b72befbe37c0c8c5db4c9fe610ec9e2e87c717c0c2916534b247ceea

Contents?: true

Size: 1.87 KB

Versions: 71

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

71 entries across 71 versions & 1 rubygems

Version Path
renalware-core-2.0.124 app/models/renalware/pathology/requests/global_rule/request_result.rb
renalware-core-2.0.123 app/models/renalware/pathology/requests/global_rule/request_result.rb
renalware-core-2.0.121 app/models/renalware/pathology/requests/global_rule/request_result.rb
renalware-core-2.0.120 app/models/renalware/pathology/requests/global_rule/request_result.rb
renalware-core-2.0.119 app/models/renalware/pathology/requests/global_rule/request_result.rb
renalware-core-2.0.118 app/models/renalware/pathology/requests/global_rule/request_result.rb
renalware-core-2.0.117 app/models/renalware/pathology/requests/global_rule/request_result.rb
renalware-core-2.0.116 app/models/renalware/pathology/requests/global_rule/request_result.rb
renalware-core-2.0.115 app/models/renalware/pathology/requests/global_rule/request_result.rb
renalware-core-2.0.113 app/models/renalware/pathology/requests/global_rule/request_result.rb
renalware-core-2.0.112 app/models/renalware/pathology/requests/global_rule/request_result.rb
renalware-core-2.0.111 app/models/renalware/pathology/requests/global_rule/request_result.rb
renalware-core-2.0.110 app/models/renalware/pathology/requests/global_rule/request_result.rb
renalware-core-2.0.109 app/models/renalware/pathology/requests/global_rule/request_result.rb
renalware-core-2.0.108 app/models/renalware/pathology/requests/global_rule/request_result.rb
renalware-core-2.0.106 app/models/renalware/pathology/requests/global_rule/request_result.rb
renalware-core-2.0.105 app/models/renalware/pathology/requests/global_rule/request_result.rb
renalware-core-2.0.104 app/models/renalware/pathology/requests/global_rule/request_result.rb
renalware-core-2.0.103 app/models/renalware/pathology/requests/global_rule/request_result.rb
renalware-core-2.0.102 app/models/renalware/pathology/requests/global_rule/request_result.rb