<commit_before>require_dependency "renalware/pathology/requests"

module Renalware
  module Pathology
    module Requests
      module ParamType
        class ObservationResult < Base
          def initialize(patient, param_id, param_comparison_operator, param_comparison_value)
            unless ["==", ">", "<", ">=", "<="].include?(param_comparison_operator)
              raise ArgumentError
            end

            super(patient, param_id, param_comparison_operator, param_comparison_value)
          end

          def required?
            return true if observation_result.nil?
            observation_result.send(@param_comparison_operator.to_sym, @param_comparison_value)
          end

          def to_s
            "#{find_observation_description.code} #{@param_comparison_operator} #{@param_comparison_value}"
          end

          private

          def observation_result
            @observation_result ||= begin

              observation =
                ::Renalware::Pathology::ObservationForPatientObservationDescriptionQuery
                  .new(@patient, observation_description).call

              observation.result.to_i if observation.present?
            end
          end

          def observation_description
            @observation_description ||=
              Renalware::Pathology::ObservationDescription.new(id: @param_id)
          end

          def find_observation_description
            Renalware::Pathology::ObservationDescription.find(@param_id)
          end
        end<commit_msg>coerce comparison value to integer in ObservationResult<commit_after>require_dependency "renalware/pathology/requests"

module Renalware
  module Pathology
    module Requests
      module ParamType
        class ObservationResult < Base
          def initialize(patient, param_id, param_comparison_operator, param_comparison_value)
            unless ["==", ">", "<", ">=", "<="].include?(param_comparison_operator)
              raise ArgumentError
            end

            super(patient, param_id, param_comparison_operator, param_comparison_value)
          end

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

          def to_s
            "#{find_observation_description.code} #{@param_comparison_operator} #{@param_comparison_value}"
          end

          private

          def observation_result
            @observation_result ||= begin

              observation =
                ::Renalware::Pathology::ObservationForPatientObservationDescriptionQuery
                  .new(@patient, observation_description).call

              observation.result.to_i if observation.present?
            end
          end

          def observation_description
            @observation_description ||=
              Renalware::Pathology::ObservationDescription.new(id: @param_id)
          end

          def find_observation_description
            Renalware::Pathology::ObservationDescription.find(@param_id)
          end
        end
{'fraction_non_alphanumeric': 0.072, 'fraction_numerical': 0.0, 'mean_word_length': 2.3184713375796178, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2894323', 'n_tokens_mistral': 779, 'n_tokens_neox': 743, 'n_words': 141}