Sha256: aa98878ffc5bcdc6a88d2a324df8ff31d37ab8616917f226775ecafae082d9c2

Contents?: true

Size: 1.15 KB

Versions: 18

Compression:

Stored size: 1.15 KB

Contents

# frozen_string_literal: true

require_dependency "renalware/pathology"

module Renalware
  module Pathology
    class NearestObservationsQuery
      pattr_initialize [:patient!, :date!, :code_group!, look_behind_days!: 2]

      # rubocop:disable Metrics/MethodLength
      def call
        pathology_patient
          .observations
          .joins(:description)
          .where(description_id: observation_description_ids)
          .where("observed_at >= ?", (date - look_behind_days.days).beginning_of_day)
          .select(
            :observed_at,
            :result,
            :description_id,
            "pathology_observation_descriptions.code as code"
          )
          .map do |row|
            {
              code: row.code,
              observed_on: row.observed_at.to_date,
              result: row.result
            }
          end
      end
      # rubocop:enable Metrics/MethodLength

      private

      def pathology_patient
        Pathology.cast_patient(patient)
      end

      def observation_description_ids
        @observation_description_ids ||= code_group.memberships.pluck(:observation_description_id)
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

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