Skip to content

Commit

Permalink
Merge pull request #2336 from sparc-request/sj-incomplete_form_bug
Browse files Browse the repository at this point in the history
SJ - Fixing query for incomplete responses
  • Loading branch information
Stuart-Johnson committed May 12, 2020
2 parents 93dd20e + 1025709 commit 14f6863
Show file tree
Hide file tree
Showing 20 changed files with 62 additions and 74 deletions.
2 changes: 1 addition & 1 deletion app/controllers/funding/services_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def to_csv(documents)
documents.each do |d|
ssr = d.sub_service_requests.where(organization_id: Setting.get_value("funding_org_ids")).first
p = ssr.protocol
csv << [ssr.display_id, p.primary_principal_investigator.last_name_first, p.primary_principal_investigator.try(:professional_org_lookup, 'institution'), p.short_title, d.document_file_name.humanize, d.document_updated_at.strftime('%D %l:%M %p'), PermissibleValue.get_value('status', ssr.status)]
csv << [ssr.display_id, p.primary_pi.last_name_first, p.primary_pi.try(:professional_org_lookup, 'institution'), p.short_title, d.document_file_name.humanize, d.document_updated_at.strftime('%D %l:%M %p'), PermissibleValue.get_value('status', ssr.status)]
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/protocols_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def push_to_epic
epic_queue = EpicQueue.find params[:eq_id]
epic_queue.update_attribute(:attempted_push, true)
# removed 12/23/13 per request by Lane
#if current_user != @protocol.primary_principal_investigator then
#if current_user != @protocol.primary_pi then
# raise ArgumentError, "User is not primary PI"
#end

Expand Down
31 changes: 18 additions & 13 deletions app/controllers/surveyor/responses_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -195,33 +195,38 @@ def load_responses
existing_responses
else
incomplete_responses = get_incomplete_form_responses
existing_responses + incomplete_responses
Response.includes(:survey).where(id: (incomplete_responses + existing_responses))
end
end
preload_responses
end

def preload_responses
preloader = ActiveRecord::Associations::Preloader.new
preloader.preload(@responses.select { |r| r.respondable_type == SubServiceRequest.name }, { respondable: { protocol: { primary_pi_role: :identity } } })
preloader.preload(@responses.select { |r| r.respondable_type == ServiceRequest.name }, { respondable: { protocol: { primary_pi_role: :identity } } })
preloader.preload(@responses.select { |r| r.respondable_type == SubServiceRequest.name }, [:question_responses, :identity, respondable: { protocol: :primary_pi } ])
preloader.preload(@responses.select { |r| r.respondable_type == ServiceRequest.name }, [:question_responses, :identity, respondable: { protocol: :primary_pi } ])
end

def get_incomplete_form_responses
@filterrific.with_state.reject!(&:blank?) if @filterrific.with_state
@filterrific.with_survey.reject!(&:blank?) if @filterrific.with_survey

state_selected = @filterrific.with_state.try(&:any?)
survey_selected = @filterrific.with_survey.try(&:any?)

responses = []
Protocol.eager_load(sub_service_requests: [:responses, :service_forms, :organization_forms]).distinct.each do |p|
# It should only shows those admin have access to
p.sub_service_requests.where(organization_id: @admin_org_ids).each do |ssr|
ssr.forms_to_complete.values.flatten.select do |f|
# Apply the State, Survey/Form, and Start/End Date filters manually
(@filterrific.with_state.try(&:empty?) || (@filterrific.with_state.try(&:any?) && @filterrific.with_state.include?(f.active ? 1 : 0))) &&
(@filterrific.with_survey.try(&:empty?) || (@filterrific.with_survey.try(&:any?) && @filterrific.with_survey.include?(f.id)))
end.each do |f|
responses << Response.new(survey: f,respondable: ssr)
end
ssrs = SubServiceRequest.eager_load(:responses, :service_forms, :organization_forms).where(organization_id: @admin_org_ids) # It should only shows those admin have access to
preloader = ActiveRecord::Associations::Preloader.new
preloader.preload(ssrs, service_forms: :surveyable)
preloader.preload(ssrs, organization_forms: :surveyable)

ssrs.each do |ssr|
ssr.forms_to_complete.values.flatten.select do |f|
# Apply the State, Survey/Form, and Start/End Date filters manually
(!state_selected || (state_selected && @filterrific.with_state.include?(f.active ? 1 : 0))) &&
(!survey_selected || (@filterrific.with_survey.try(&:any?) && @filterrific.with_survey.include?(f.id)))
end.each do |f|
responses << Response.new(survey: f,respondable: ssr)
end
end

Expand Down
4 changes: 2 additions & 2 deletions app/helpers/funding/documents_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
module Funding::DocumentsHelper

def display_pi(ssr)
ssr.protocol.primary_principal_investigator.last_name_first
ssr.protocol.primary_pi.last_name_first
end

def display_pi_institution(ssr)
ssr.protocol.primary_principal_investigator.try(:professional_org_lookup, 'institution')
ssr.protocol.primary_pi.try(:professional_org_lookup, 'institution')
end

def display_actions(ssr)
Expand Down
16 changes: 8 additions & 8 deletions app/lib/reports/protocols.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ def column_attrs
attrs["IRB of Record"] = "service_request.try(:protocol).try(:human_subjects_info).try(:irb_of_record)"
attrs["IRB Expiration Date"] = "service_request.try(:protocol).try(:human_subjects_info).try(:irb_expiration_date)"

attrs["Primary PI Last Name"] = "service_request.try(:protocol).try(:primary_principal_investigator).try(:last_name)"
attrs["Primary PI First Name"] = "service_request.try(:protocol).try(:primary_principal_investigator).try(:first_name)"
attrs["Primary PI Email"] = "service_request.try(:protocol).try(:primary_principal_investigator).try(:email)"
attrs["Primary PI Institution"] = "service_request.try(:protocol).try(:primary_principal_investigator).try(:professional_org_lookup, 'institution')"
attrs["Primary PI College"] = "service_request.try(:protocol).try(:primary_principal_investigator).try(:professional_org_lookup, 'college')"
attrs["Primary PI Department"] = "service_request.try(:protocol).try(:primary_principal_investigator).try(:professional_org_lookup, 'department')"
attrs["Primary PI Division"] = "service_request.try(:protocol).try(:primary_principal_investigator).try(:professional_org_lookup, 'division')"
attrs["Primary PI Last Name"] = "service_request.try(:protocol).try(:primary_pi).try(:last_name)"
attrs["Primary PI First Name"] = "service_request.try(:protocol).try(:primary_pi).try(:first_name)"
attrs["Primary PI Email"] = "service_request.try(:protocol).try(:primary_pi).try(:email)"
attrs["Primary PI Institution"] = "service_request.try(:protocol).try(:primary_pi).try(:professional_org_lookup, 'institution')"
attrs["Primary PI College"] = "service_request.try(:protocol).try(:primary_pi).try(:professional_org_lookup, 'college')"
attrs["Primary PI Department"] = "service_request.try(:protocol).try(:primary_pi).try(:professional_org_lookup, 'department')"
attrs["Primary PI Division"] = "service_request.try(:protocol).try(:primary_pi).try(:professional_org_lookup, 'division')"

attrs["Primary Coordinator(s)"] = "service_request.try(:protocol).try(:coordinators).try(:map, &:full_name).try(:join, ', ')"
attrs["Primary Coordinator Email(s)"] = "service_request.try(:protocol).try(:coordinator_emails)"
Expand Down Expand Up @@ -106,7 +106,7 @@ def table

# Other tables to include
def includes
[:organization, { service_request: { protocol: [:project_roles, :study_phases, :human_subjects_info, :investigational_products_info, primary_pi_role: { identity: { professional_organization: { parent: { parent: :parent } } } }] } }, { line_items: :service }]
[:organization, { service_request: { protocol: [:project_roles, :study_phases, :human_subjects_info, :investigational_products_info, primary_pi: { professional_organization: { parent: { parent: :parent } } }] } }, { line_items: :service }]
end

# Conditions
Expand Down
14 changes: 7 additions & 7 deletions app/lib/reports/service_requests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@ def column_attrs
attrs["Core"] = "org_tree.select{|org| org.type == 'Core'}.first.try(:abbreviation)"
end

attrs["Primary PI Last Name"] = "service_request.try(:protocol).try(:primary_principal_investigator).try(:last_name)"
attrs["Primary PI First Name"] = "service_request.try(:protocol).try(:primary_principal_investigator).try(:first_name)"
attrs["Primary PI Institution"] = "service_request.try(:protocol).try(:primary_principal_investigator).try(:professional_org_lookup, 'institution')"
attrs["Primary PI College"] = "service_request.try(:protocol).try(:primary_principal_investigator).try(:professional_org_lookup, 'college')"
attrs["Primary PI Department"] = "service_request.try(:protocol).try(:primary_principal_investigator).try(:professional_org_lookup, 'department')"
attrs["Primary PI Division"] = "service_request.try(:protocol).try(:primary_principal_investigator).try(:professional_org_lookup, 'division')"
attrs["Primary PI Last Name"] = "service_request.try(:protocol).try(:primary_pi).try(:last_name)"
attrs["Primary PI First Name"] = "service_request.try(:protocol).try(:primary_pi).try(:first_name)"
attrs["Primary PI Institution"] = "service_request.try(:protocol).try(:primary_pi).try(:professional_org_lookup, 'institution')"
attrs["Primary PI College"] = "service_request.try(:protocol).try(:primary_pi).try(:professional_org_lookup, 'college')"
attrs["Primary PI Department"] = "service_request.try(:protocol).try(:primary_pi).try(:professional_org_lookup, 'department')"
attrs["Primary PI Division"] = "service_request.try(:protocol).try(:primary_pi).try(:professional_org_lookup, 'division')"
attrs["Primary Coordinator(s)"] = "service_request.try(:protocol).try(:coordinators).try(:map, &:full_name).try(:join, ', ')"
attrs["Primary Coordinator Email(s)"] = "service_request.try(:protocol).try(:coordinator_emails)"

Expand Down Expand Up @@ -129,7 +129,7 @@ def table

# Other tables to include
def includes
return :organization, :service_request => {:line_items => :service}
return :organization, service_request: { protocol: { primary_pi: { professional_organization: { parent: { parent: :parent } } } }, line_items: :service }
end

# Conditions
Expand Down
6 changes: 3 additions & 3 deletions app/mailers/notifier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def sub_service_request_deleted identity, sub_service_request, user_current

def notify_for_epic_user_approval protocol
@protocol = protocol
@primary_pi = @protocol.primary_principal_investigator
@primary_pi = @protocol.primary_pi

subject = "#{@protocol.id} - Epic Rights Approval"

Expand All @@ -200,7 +200,7 @@ def notify_for_epic_user_approval protocol

def notify_primary_pi_for_epic_user_final_review protocol
@protocol = protocol
@primary_pi = @protocol.primary_principal_investigator
@primary_pi = @protocol.primary_pi

email_to = @primary_pi.email
subject = "#{@protocol.id} - Epic Rights User Approval"
Expand All @@ -210,7 +210,7 @@ def notify_primary_pi_for_epic_user_final_review protocol

def notify_primary_pi_for_epic_user_removal(protocol, project_roles)
@protocol = protocol
@primary_pi = @protocol.primary_principal_investigator
@primary_pi = @protocol.primary_pi
@project_roles = project_roles

subject = "#{@protocol.id} - Epic User Removal"
Expand Down
4 changes: 0 additions & 4 deletions app/models/protocol.rb
Original file line number Diff line number Diff line change
Expand Up @@ -424,10 +424,6 @@ def email_about_change_in_authorized_user(modified_roles, action)
end
end

def primary_principal_investigator
primary_pi_role.try(:identity)
end

def billing_business_manager_email
billing_business_manager_static_email.blank? ? billing_managers.map(&:email).try(:join, ', ') : billing_business_manager_static_email
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/sub_service_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ def all_forms_completed?
##########################
# Distributes all available surveys to primary pi and ssr requester
def distribute_surveys
primary_pi = protocol.primary_principal_investigator
primary_pi = protocol.primary_pi
# do nothing if we don't have any available surveys
unless available_surveys.empty?
SurveyNotification.service_survey(available_surveys, primary_pi, self).deliver
Expand Down
4 changes: 2 additions & 2 deletions app/views/dashboard/protocols/show.xlsx.axlsx
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ end
sheet.add_row ["SPARC #{@protocol.class.to_s} ID:",@protocol.id], style: [bold_default, default]
sheet.add_row ["RMID:", @protocol.research_master_id], style: [bold_default, default]
sheet.add_row ["Short Title:",@protocol.short_title], style: [bold_default, default]
sheet.add_row ["Primary PI Name:", @protocol.primary_principal_investigator.full_name], style: [bold_default, default]
sheet.add_row ["Primary PI Name:", @protocol.primary_pi.full_name], style: [bold_default, default]
sheet.add_row ["Indirect Cost Rate:", "=Summary!B10"], style: [bold_default, percent]

indirect_cost_ref = sheet.rows.last.cells.last.r
Expand Down Expand Up @@ -364,7 +364,7 @@ wb.insert_worksheet(0, name: "Summary") do |sheet|
sheet.add_row ["Short Title:", @protocol.short_title], :style => [bold_default, default]
sheet.add_row ["Protocol Title:", @protocol.title], :style => [bold_default, default]
sheet.add_row ["Sponsor:", @protocol.sponsor_name], :style => [bold_default, default]
sheet.add_row ["Primary PI Name:", @protocol.primary_principal_investigator.full_name], :style => [bold_default, default]
sheet.add_row ["Primary PI Name:", @protocol.primary_pi.full_name], :style => [bold_default, default]
sheet.add_row ["Business Manager:", @protocol.billing_managers.map(&:full_name).try(:join, ', ')], :style => [bold_default, default]
sheet.add_row ["Funding Source:", @protocol.display_funding_source_value], :style => [bold_default, default]
sheet.add_row ["Indirect Cost Rate:", @protocol.indirect_cost_rate.try(:/, 100.0) || 0.0], style: [bold_default, percent]
Expand Down
2 changes: 1 addition & 1 deletion app/views/survey_notification/_info_table.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@

%tr{:style => 'border: 1px solid black;'}
%th{:style => 'border: 1px solid black; width:200px; text-align:left;'}= t(:surveyor)[:responses][:table][:headers][:primary_pi]
%td{:style => 'border: 1px solid black;'}= @protocol.primary_principal_investigator.full_name
%td{:style => 'border: 1px solid black;'}= @protocol.primary_pi.full_name

%tr{:style => 'border: 1px solid black;'}
%th{:style => 'border: 1px solid black; width:200px; text-align:left;'}= t(:surveyor)[:responses][:table][:headers][:request_owner]
Expand Down
2 changes: 1 addition & 1 deletion app/views/surveyor/responses/index.json.jbuilder
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ json.(@responses) do |response|

json.srid srid == 'N/A' ? 'N/A' : link_to(srid, dashboard_protocol_path(srid.to_s.split('-').first), target: :_blank)
json.short_title response.try(:respondable).try(:protocol).try(:short_title) || 'N/A'
json.primary_pi response.try(:respondable).try(:protocol).try(:primary_principal_investigator).try(:full_name) || 'N/A'
json.primary_pi response.try(:respondable).try(:protocol).try(:primary_pi).try(:full_name) || 'N/A'
json.title response.survey.full_title
json.by response.identity.try(:full_name) || 'N/A'
json.complete complete_display(response)
Expand Down
14 changes: 10 additions & 4 deletions config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,27 @@
config.consider_all_requests_local = true
config.action_controller.perform_caching = false

# Don't care if the mailer can't send
config.action_mailer.raise_delivery_errors = false

# Print deprecation notices to the Rails logger
config.active_support.deprecation = :log

# Expands the lines which load the assets
config.assets.compile = true
config.assets.debug = true

# Don't care if the mailer can't send
config.action_mailer.raise_delivery_errors = false
config.action_mailer.default_url_options = { host: ENV.fetch('ROOT_URL') }
config.action_mailer.delivery_method = :letter_opener
config.action_mailer.perform_deliveries = true

config.log_level = :debug
# Print deprecation notices to the Rails logger.
config.active_support.deprecation = :log

# Raise an error on page load if there are pending migrations.
config.active_record.migration_error = :page_load

# Highlight code that triggered database queries in logs.
config.active_record.verbose_query_logs = true

# Stuff to do on each request
config.to_prepare do
Expand Down
21 changes: 1 addition & 20 deletions db/schema.rb
Original file line number Diff line number Diff line change
@@ -1,23 +1,3 @@
# Copyright © 2011-2020 MUSC Foundation for Research Development~
# All rights reserved.~

# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:~

# 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.~

# 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following~
# disclaimer in the documentation and/or other materials provided with the distribution.~

# 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products~
# derived from this software without specific prior written permission.~

# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,~
# BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT~
# SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL~
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS~
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR~
# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.~

# This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
Expand Down Expand Up @@ -983,6 +963,7 @@
t.boolean "access_empty_protocols", default: false
t.boolean "billing_manager"
t.boolean "allow_credit"
t.boolean "hold_emails", default: true
t.index ["identity_id"], name: "index_super_users_on_identity_id"
t.index ["organization_id"], name: "index_super_users_on_organization_id"
end
Expand Down
2 changes: 1 addition & 1 deletion lib/tasks/admin_turnaround_times_report.rake
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ namespace :data do
if ssr.service_request.protocol && (ssr.organization_id == core.id) && (ssr.created_at.to_date > 2012-03-01)
past_statuses = ssr.past_status_lookup
dates = extract_status_dates(ssr)
pi = ssr.service_request.protocol.try(:primary_principal_investigator).try(:full_name)
pi = ssr.service_request.protocol.try(:primary_pi).try(:full_name)
owner = ssr.owner_id ? Identity.find(ssr.owner_id).full_name : ""

row = [ssr.service_request.protocol.id, full_ssr_id(ssr), ssr.service_request.protocol.short_title, pi, provider.abbreviation, program.abbreviation, core.abbreviation, owner, dates[0], dates[1]]
Expand Down
2 changes: 1 addition & 1 deletion lib/tasks/billing_only_report.rake
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ namespace :reports do
research_rate = procedure.cost
cost = research_rate * r_qty

csv << [protocol.id, protocol.try(:primary_principal_investigator).try(:full_name), subject.name, subject.label, visit_name, visit_date, procedure.display_service_name, r_qty, research_rate, cost]
csv << [protocol.id, protocol.try(:primary_pi).try(:full_name), subject.name, subject.label, visit_name, visit_date, procedure.display_service_name, r_qty, research_rate, cost]
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/tasks/jit_report.rake
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ task :jit_report => :environment do
first_submit = ssr.past_statuses.where(:status => 'submitted').first.date
protocol = ssr.protocol
human_subjects_info = protocol.human_subjects_info
csv << [first_submit.strftime('%m/%d/%y'), ssr.display_id, ssr.organization.name, protocol.primary_principal_investigator.display_name,
csv << [first_submit.strftime('%m/%d/%y'), ssr.display_id, ssr.organization.name, protocol.primary_pi.display_name,
protocol.title, human_subjects_info.irb_of_record, human_subjects_info.irb_and_pro_numbers, (human_subjects_info.irb_approval_date.strftime('%m/%d/%y') rescue nil)]
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/tasks/one_time_fee_report.rake
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ namespace :data do
status = PermissibleValue.get_value('status', ssr.status)
protocol_id = ssr.protocol_id
short_title = ssr.protocol.short_title
pi = ssr.protocol.try(:primary_principal_investigator).try(:full_name)
pi = ssr.protocol.try(:primary_pi).try(:full_name)
owner = ssr.owner_id ? Identity.find(ssr.owner_id).full_name : ""

ssr.line_items.each do |li|
Expand Down

0 comments on commit 14f6863

Please sign in to comment.