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 @@ <%= link_to "#{surgeon.last_name}, #{surgeon.first_name}", surgeon_path(surgeon.id) %> <% if user_signed_in? %> <%= link_to pin_count || 0, pins_path(surgeon: surgeon.id) %> + <%= complication_count || 0 %> + <%= (complication_count * 100 / pin_count if pin_count.present? && pin_count > 0) || 0 %>% <% else %> <%= link_to "Register to see more", register_path %> <% end %> diff --git a/app/views/surgeons/index.html.erb b/app/views/surgeons/index.html.erb index 778daa28..49cb461c 100644 --- a/app/views/surgeons/index.html.erb +++ b/app/views/surgeons/index.html.erb @@ -1,11 +1,14 @@ <%= render partial: 'ads/test1' %> <% title "Surgeons" %>
+

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.

+ + <% @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 %>
Name SubmissionsComplicationsComplication Rate