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.81 app/models/renalware/pathology/requests/global_rule/request_result.rb
renalware-core-2.0.80 app/models/renalware/pathology/requests/global_rule/request_result.rb
renalware-core-2.0.79 app/models/renalware/pathology/requests/global_rule/request_result.rb
renalware-core-2.0.78 app/models/renalware/pathology/requests/global_rule/request_result.rb
renalware-core-2.0.77 app/models/renalware/pathology/requests/global_rule/request_result.rb
renalware-core-2.0.76 app/models/renalware/pathology/requests/global_rule/request_result.rb
renalware-core-2.0.75 app/models/renalware/pathology/requests/global_rule/request_result.rb
renalware-core-2.0.74 app/models/renalware/pathology/requests/global_rule/request_result.rb
renalware-core-2.0.73 app/models/renalware/pathology/requests/global_rule/request_result.rb
renalware-core-2.0.72 app/models/renalware/pathology/requests/global_rule/request_result.rb
renalware-core-2.0.71 app/models/renalware/pathology/requests/global_rule/request_result.rb
renalware-core-2.0.70 app/models/renalware/pathology/requests/global_rule/request_result.rb
renalware-core-2.0.69 app/models/renalware/pathology/requests/global_rule/request_result.rb
renalware-core-2.0.68 app/models/renalware/pathology/requests/global_rule/request_result.rb
renalware-core-2.0.67 app/models/renalware/pathology/requests/global_rule/request_result.rb
renalware-core-2.0.64 app/models/renalware/pathology/requests/global_rule/request_result.rb
renalware-core-2.0.63 app/models/renalware/pathology/requests/global_rule/request_result.rb
renalware-core-2.0.62 app/models/renalware/pathology/requests/global_rule/request_result.rb
renalware-core-2.0.61 app/models/renalware/pathology/requests/global_rule/request_result.rb
renalware-core-2.0.60 app/models/renalware/pathology/requests/global_rule/request_result.rb