diff --git a/app/controllers/surgeons_controller.rb b/app/controllers/surgeons_controller.rb index 5f957bea..53ee4b2e 100644 --- a/app/controllers/surgeons_controller.rb +++ b/app/controllers/surgeons_controller.rb @@ -1,7 +1,11 @@ class SurgeonsController < ApplicationController def index @surgeons = Surgeon.all.order(:last_name) - @pins_per_surgeon = Surgeon.joins(:pins).group("pins.surgeon_id").count + @pin_counts_per_surgeon = Surgeon.joins(:pins).group("pins.surgeon_id").count + @pins_per_surgeon = Hash[*Pin.select(:surgeon_id, 'array_agg(id)').group(:surgeon_id).pluck(:surgeon_id, 'array_agg(id)').flatten(1)] + @pins_by_complications = ActsAsTaggableOn::Tagging.includes(:tag). + where(context: 'complications'). + pluck(:taggable_id, :name).group_by {|id, name| id } end def show diff --git a/app/views/surgeons/_surgeon_row.html.erb b/app/views/surgeons/_surgeon_row.html.erb index 22ecfb8b..22c192c9 100644 --- a/app/views/surgeons/_surgeon_row.html.erb +++ b/app/views/surgeons/_surgeon_row.html.erb @@ -2,6 +2,8 @@
A warning about "Complication Rate": complications are loosely structured tags on the site. This means one single procedure on a patient might have been submitted several times, and the submitter may have duplicated the tags on their submissions. This means the complication rate may be higher than reality. This complication rate can not be used as medical advice.
Name | Submissions | +Complications | +Complication Rate | <% @surgeons.each do |surgeon| %> - <%= render partial: 'surgeons/surgeon_row', locals: { surgeon: surgeon, pin_count: @pins_per_surgeon[surgeon.id] } %> + <%= render partial: 'surgeons/surgeon_row', locals: { surgeon: surgeon, pin_count: @pin_counts_per_surgeon[surgeon.id], complication_count: @pins_by_complications.values_at(*@pins_per_surgeon[surgeon.id]).compact.count } %> <% end %>
---|