Sha256: 79b83c3acf9f93b547234090ff28a4c547b26f068e6eaf4591417e0982a74d2d

Contents?: true

Size: 1.84 KB

Versions: 28

Compression:

Stored size: 1.84 KB

Contents

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

28 entries across 28 versions & 1 rubygems

Version Path
renalware-core-2.0.0.pre.beta11 app/models/renalware/pathology/requests/global_rule/request_result.rb
renalware-core-2.0.0.pre.beta10 app/models/renalware/pathology/requests/global_rule/request_result.rb
renalware-core-2.0.0.pre.beta9 app/models/renalware/pathology/requests/global_rule/request_result.rb
renalware-core-2.0.0.pre.beta8 app/models/renalware/pathology/requests/global_rule/request_result.rb
renalware-core-2.0.0.pre.beta7 app/models/renalware/pathology/requests/global_rule/request_result.rb
renalware-core-2.0.0.pre.beta6 app/models/renalware/pathology/requests/global_rule/request_result.rb
renalware-core-2.0.0.pre.beta5 app/models/renalware/pathology/requests/global_rule/request_result.rb
renalware-core-2.0.0.pre.beta4 app/models/renalware/pathology/requests/global_rule/request_result.rb