Sha256: ba9cec634f4aaeae604d1e6c402b954211aa9ea99385a0167f8b09a5a9f8365e

Contents?: true

Size: 1.19 KB

Versions: 20

Compression:

Stored size: 1.19 KB

Contents

require_dependency "renalware/hd"

module Renalware
  module HD
    class PatientsWithUnmetPreferencesQuery
      def initialize(query = {})
        @query = query
      end

      def call
        search.result
      end

      def search
        HD::Patient
          .extend(Scopes)
          .includes(hd_profile: :hospital_unit)
          .includes(hd_preference_set: :hospital_unit)
          .eager_load(:hd_profile)
          .eager_load(:hd_preference_set)
          .having_an_unmet_preference
          .ransack(query)
      end

      private

      attr_reader :query

      module Scopes
        def having_an_unmet_preference
          sql = <<-SQL.squish
            (hd_preference_sets.hospital_unit_id > 0 AND
              hd_profiles.hospital_unit_id != hd_preference_sets.hospital_unit_id) OR
            (coalesce(hd_preference_sets.schedule_definition_id, 0) != 0 AND
              hd_profiles.schedule_definition_id != hd_preference_sets.schedule_definition_id) OR
            (coalesce(hd_preference_sets.other_schedule, '') != '' AND
              hd_profiles.other_schedule != hd_preference_sets.other_schedule)
          SQL
          where(sql)
        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/patients_with_unmet_preferences_query.rb
renalware-core-2.0.7 app/models/renalware/hd/patients_with_unmet_preferences_query.rb
renalware-core-2.0.5 app/models/renalware/hd/patients_with_unmet_preferences_query.rb
renalware-core-2.0.4 app/models/renalware/hd/patients_with_unmet_preferences_query.rb
renalware-core-2.0.3 app/models/renalware/hd/patients_with_unmet_preferences_query.rb
renalware-core-2.0.2 app/models/renalware/hd/patients_with_unmet_preferences_query.rb
renalware-core-2.0.1 app/models/renalware/hd/patients_with_unmet_preferences_query.rb
renalware-core-2.0.0 app/models/renalware/hd/patients_with_unmet_preferences_query.rb
renalware-core-2.0.0.pre.rc13 app/models/renalware/hd/patients_with_unmet_preferences_query.rb
renalware-core-2.0.0.pre.rc11 app/models/renalware/hd/patients_with_unmet_preferences_query.rb
renalware-core-2.0.0.pre.rc10 app/models/renalware/hd/patients_with_unmet_preferences_query.rb
renalware-core-2.0.0.pre.rc9 app/models/renalware/hd/patients_with_unmet_preferences_query.rb
renalware-core-2.0.0.pre.rc8 app/models/renalware/hd/patients_with_unmet_preferences_query.rb
renalware-core-2.0.0.pre.rc7 app/models/renalware/hd/patients_with_unmet_preferences_query.rb
renalware-core-2.0.0.pre.rc6 app/models/renalware/hd/patients_with_unmet_preferences_query.rb
renalware-core-2.0.0.pre.rc5 app/models/renalware/hd/patients_with_unmet_preferences_query.rb
renalware-core-2.0.0.pre.rc4 app/models/renalware/hd/patients_with_unmet_preferences_query.rb
renalware-core-2.0.0.pre.rc3 app/models/renalware/hd/patients_with_unmet_preferences_query.rb
renalware-core-2.0.0.pre.rc1 app/models/renalware/hd/patients_with_unmet_preferences_query.rb
renalware-core-2.0.0.pre.beta12 app/models/renalware/hd/patients_with_unmet_preferences_query.rb