Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

basic stat for complications on surgeons index #103

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion app/controllers/surgeons_controller.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 2 additions & 0 deletions app/views/surgeons/_surgeon_row.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<td><%= link_to "#{surgeon.last_name}, #{surgeon.first_name}", surgeon_path(surgeon.id) %></td>
<% if user_signed_in? %>
<td><%= link_to pin_count || 0, pins_path(surgeon: surgeon.id) %></td>
<td><%= complication_count || 0 %></td>
<td><%= (complication_count * 100 / pin_count if pin_count.present? && pin_count > 0) || 0 %>%</td>
<% else %>
<td><%= link_to "Register to see more", register_path %></td>
<% end %>
Expand Down
5 changes: 4 additions & 1 deletion app/views/surgeons/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
<%= render partial: 'ads/test1' %>
<% title "Surgeons" %>
<div id="surgeons" style="background-color:#ffffff">
<p>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.</p>
<table class="table table-hover table-bordered" bgcolor="#ffffcc">
<th>Name</th>
<th>Submissions</th>
<th>Complications</th>
<th>Complication Rate</th>
<% @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 %>
</table>
</div>