Skip to content

Instantly share code, notes, and snippets.

@rafbm
Created April 15, 2018 13:36
Show Gist options
  • Save rafbm/a6c331ceb79fcfc2cd58b83fc1778b3f to your computer and use it in GitHub Desktop.
Save rafbm/a6c331ceb79fcfc2cd58b83fc1778b3f to your computer and use it in GitHub Desktop.

Revisions

  1. rafbm created this gist Apr 15, 2018.
    20 changes: 20 additions & 0 deletions query_object.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    def call
    scope = base_relation.joins(:care_periods)

    if params.care_provider_id.present?
    scope = scope
    .where(care_periods: { care_provider_id: params.care_provider_id })
    end

    if params.hospital_id.present?
    scope = scope
    .where(care_periods: { hospital_id: params.hospital_id })
    end

    if params.discharge_period.present?
    scope = scope.joins(:hospital_visit)
    .where(hospital_visits: { end_on: params.discharge_period }
    end

    scope
    end