Skip to content

Instantly share code, notes, and snippets.

@rafbm
Created April 15, 2018 13:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rafbm/a6c331ceb79fcfc2cd58b83fc1778b3f to your computer and use it in GitHub Desktop.
Save rafbm/a6c331ceb79fcfc2cd58b83fc1778b3f to your computer and use it in GitHub Desktop.
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment