Skip to content

Instantly share code, notes, and snippets.

@saturday

saturday/meh.rb Secret

Created May 17, 2016 00:57
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 saturday/64daae33bd3050885b7c45a03fc410b4 to your computer and use it in GitHub Desktop.
Save saturday/64daae33bd3050885b7c45a03fc410b4 to your computer and use it in GitHub Desktop.
def self.get_apps_with_patient_plots(patient_id)
patient_id = ActiveRecord::Base.connection.quote(patient_id)
application_results = {}
applications = OauthApplication.find_by_sql("select oauth_applications.* from oauth_applications
inner join tasks on tasks.application_id = oauth_applications.id and assignee = #{patient_id} and completion_date IS NOT NULL
inner join oauth_applications_plots on oauth_applications.id = oauth_applications_plots.oauth_application_id
inner join plots on oauth_applications_plots.plot_id = plots.id
inner join plot_types on plots.plot_type_id = plot_types.id and plot_types.name = 'Patient'
group by oauth_applications.id;")
applications.each do |app|
application_results["#{app.name}"] ||= []
application_results["#{app.name}"] << Result.where("patient = ? and app_id = ?", patient_id, app.id).order(created_at: :asc)
end
application_results
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment