Sha256: 9b74939446e5a8019cfa5c287893ad9f1d7f00add6c4749d280922c2ad6dc09f

Contents?: true

Size: 1008 Bytes

Versions: 20

Compression:

Stored size: 1008 Bytes

Contents

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

20 entries across 20 versions & 1 rubygems

Version Path
renalware-core-2.0.8 app/models/renalware/hd/sessions/latest_patient_sessions_query.rb
renalware-core-2.0.7 app/models/renalware/hd/sessions/latest_patient_sessions_query.rb
renalware-core-2.0.5 app/models/renalware/hd/sessions/latest_patient_sessions_query.rb
renalware-core-2.0.4 app/models/renalware/hd/sessions/latest_patient_sessions_query.rb
renalware-core-2.0.3 app/models/renalware/hd/sessions/latest_patient_sessions_query.rb
renalware-core-2.0.2 app/models/renalware/hd/sessions/latest_patient_sessions_query.rb
renalware-core-2.0.1 app/models/renalware/hd/sessions/latest_patient_sessions_query.rb
renalware-core-2.0.0 app/models/renalware/hd/sessions/latest_patient_sessions_query.rb
renalware-core-2.0.0.pre.rc13 app/models/renalware/hd/sessions/latest_patient_sessions_query.rb
renalware-core-2.0.0.pre.rc11 app/models/renalware/hd/sessions/latest_patient_sessions_query.rb
renalware-core-2.0.0.pre.rc10 app/models/renalware/hd/sessions/latest_patient_sessions_query.rb
renalware-core-2.0.0.pre.rc9 app/models/renalware/hd/sessions/latest_patient_sessions_query.rb
renalware-core-2.0.0.pre.rc8 app/models/renalware/hd/sessions/latest_patient_sessions_query.rb
renalware-core-2.0.0.pre.rc7 app/models/renalware/hd/sessions/latest_patient_sessions_query.rb
renalware-core-2.0.0.pre.rc6 app/models/renalware/hd/sessions/latest_patient_sessions_query.rb
renalware-core-2.0.0.pre.rc5 app/models/renalware/hd/sessions/latest_patient_sessions_query.rb
renalware-core-2.0.0.pre.rc4 app/models/renalware/hd/sessions/latest_patient_sessions_query.rb
renalware-core-2.0.0.pre.rc3 app/models/renalware/hd/sessions/latest_patient_sessions_query.rb
renalware-core-2.0.0.pre.rc1 app/models/renalware/hd/sessions/latest_patient_sessions_query.rb
renalware-core-2.0.0.pre.beta12 app/models/renalware/hd/sessions/latest_patient_sessions_query.rb