Sha256: 59b61cc47b2edb9a60b13301d706ac0e62b8f4c0a7a5f75432bf0f6287cd3813

Contents?: true

Size: 1.01 KB

Versions: 149

Compression:

Stored size: 1.01 KB

Contents

# frozen_string_literal: true

module Renalware
  module HD
    module Sessions
      class LatestPatientSessionsQuery
        def initialize(patient:)
          @patient = patient
        end

        def call(starting_on: 4.weeks.ago, ending_on: Time.zone.today, max_sessions: 12)
          Session.all
            .extending(Scopes)
            .for_patient(patient)
            .not_ongoing
            .ordered
            .within_period(starting_on, ending_on)
            .limit(max_sessions)
        end

        private

        attr_reader :patient

        module Scopes
          def for_patient(patient)
            where(patient: patient)
          end

          def within_period(starting_on, ending_on)
            where("performed_on >= ? and performed_on <= ?",
                  starting_on.beginning_of_day,
                  ending_on.end_of_day)
          end

          def not_ongoing
            where(type: [Session::Closed.sti_name, Session::DNA.sti_name])
          end
        end
      end
    end
  end
end

Version data entries

149 entries across 149 versions & 1 rubygems

Version Path
renalware-core-2.0.62 app/models/renalware/hd/sessions/latest_patient_sessions_query.rb
renalware-core-2.0.61 app/models/renalware/hd/sessions/latest_patient_sessions_query.rb
renalware-core-2.0.60 app/models/renalware/hd/sessions/latest_patient_sessions_query.rb
renalware-core-2.0.58 app/models/renalware/hd/sessions/latest_patient_sessions_query.rb
renalware-core-2.0.57 app/models/renalware/hd/sessions/latest_patient_sessions_query.rb
renalware-core-2.0.56 app/models/renalware/hd/sessions/latest_patient_sessions_query.rb
renalware-core-2.0.55 app/models/renalware/hd/sessions/latest_patient_sessions_query.rb
renalware-core-2.0.54 app/models/renalware/hd/sessions/latest_patient_sessions_query.rb
renalware-core-2.0.53 app/models/renalware/hd/sessions/latest_patient_sessions_query.rb
renalware-core-2.0.52 app/models/renalware/hd/sessions/latest_patient_sessions_query.rb
renalware-core-2.0.51 app/models/renalware/hd/sessions/latest_patient_sessions_query.rb
renalware-core-2.0.50 app/models/renalware/hd/sessions/latest_patient_sessions_query.rb
renalware-core-2.0.48 app/models/renalware/hd/sessions/latest_patient_sessions_query.rb
renalware-core-2.0.47 app/models/renalware/hd/sessions/latest_patient_sessions_query.rb
renalware-core-2.0.46 app/models/renalware/hd/sessions/latest_patient_sessions_query.rb
renalware-core-2.0.45 app/models/renalware/hd/sessions/latest_patient_sessions_query.rb
renalware-core-2.0.44 app/models/renalware/hd/sessions/latest_patient_sessions_query.rb
renalware-core-2.0.43 app/models/renalware/hd/sessions/latest_patient_sessions_query.rb
renalware-core-2.0.42 app/models/renalware/hd/sessions/latest_patient_sessions_query.rb
renalware-core-2.0.41 app/models/renalware/hd/sessions/latest_patient_sessions_query.rb