Sha256: bb45bc2ae9d637982b4b15ed888b36382b23f1221525f70dae42a4ef16d6c554

Contents?: true

Size: 1.21 KB

Versions: 22

Compression:

Stored size: 1.21 KB

Contents

require_dependency "renalware/hd"

# Find for example HD Patients who according to their HD Profile dialyse on Monday PM
# Example usage in that instance:
#   PatientsDialysingByDayAndPeriodQuery.new(1, "am").call
module Renalware
  module HD
    class PatientsDialysingByDayAndPeriodQuery
      attr_reader :hospital_unit_id, :day_of_week, :period_code

      def initialize(hospital_unit_id, day_of_week, period_code)
        @hospital_unit_id = hospital_unit_id
        @day_of_week = day_of_week
        @period_code = period_code
      end

      def call
        PatientsDialysingByScheduleQuery.new(
          hospital_unit_id,
          schedule_definition_ids
        ).call
      end

      private

      # Find the first schedule having day_of_week in the pg days[] array (e.g. [2,4,6] if
      # day_of_week is 2 (Tuesday) AND matching the period_code ie having the correct diurnal
      # period code e.g. AM.
      # Note
      def schedule_definition_ids
        HD::ScheduleDefinition
          .eager_load(:diurnal_period)
          .merge(Renalware::HD::DiurnalPeriodCode.for(period_code))
          .merge(Renalware::HD::ScheduleDefinition.for_day_of_week(day_of_week))
          .pluck(:id)
      end
    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

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