-
-
Save saturday/64daae33bd3050885b7c45a03fc410b4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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