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

Sj empty protocol admin view #145

Merged
merged 11 commits into from Mar 13, 2017
Expand Up @@ -133,7 +133,7 @@ def refresh_service_calendar

def push_to_epic
begin
@sub_service_request.service_request.protocol.push_to_epic(EPIC_INTERFACE, "admin_push", current_user.id)
@sub_service_request.protocol.push_to_epic(EPIC_INTERFACE, "admin_push", current_user.id)
flash[:success] = 'Request Pushed to Epic!'
rescue
flash[:alert] = $!.message
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/reports_controller.rb
Expand Up @@ -121,7 +121,7 @@ def cwf_audit
end
@audit_trail += @ssr.reports.map{|x| x.audit_trail start_date, end_date}

@ssr.service_request.protocol.arms.each do |arm|
@ssr.protocol.arms.each do |arm|
@audit_trail += arm.audit_trail start_date, end_date
@audit_trail += arm.line_items_visits.includes(:line_item => :service).where("services.organization_id IN (?)", included_cores).map{|x| x.audit_trail start_date, end_date}
@audit_trail += arm.subjects.map{|x| x.audit_trail start_date, end_date}
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/service_requests_controller.rb
Expand Up @@ -497,7 +497,7 @@ def authorize_protocol_edit_request
@service_request.status == 'first_draft' || current_user.can_edit_service_request?(@service_request)
end

protocol = @sub_service_request ? @sub_service_request.service_request.protocol : @service_request.protocol
protocol = @sub_service_request ? @sub_service_request.protocol : @service_request.protocol

unless authorized || protocol.project_roles.find_by(identity: current_user).present?
@service_request = nil
Expand Down
6 changes: 3 additions & 3 deletions app/controllers/study_tracker/cover_letters_controller.rb
Expand Up @@ -25,8 +25,8 @@ class StudyTracker::CoverLettersController < StudyTracker::BaseController
def new
@cover_letter = @sub_service_request.cover_letters.build

@srid = "#{@sub_service_request.service_request.protocol.id}-#{@sub_service_request.ssr_id}"
@short_title = @sub_service_request.service_request.protocol.short_title
@srid = "#{@sub_service_request.protocol.id}-#{@sub_service_request.ssr_id}"
@short_title = @sub_service_request.protocol.short_title
end

def create
Expand Down Expand Up @@ -64,4 +64,4 @@ def load_sub_service_request
def sanitize_content
params[:cover_letter][:content] = CoverLetterSanitizer.new.sanitize(params[:cover_letter][:content].to_s)
end
end
end
2 changes: 1 addition & 1 deletion app/helpers/dashboard/sub_service_requests_helper.rb
Expand Up @@ -34,7 +34,7 @@ def ssr_statuses
end

def full_ssr_id(ssr)
protocol = ssr.service_request.protocol
protocol = ssr.protocol
if protocol
"#{protocol.id}-#{ssr.ssr_id}"
else
Expand Down
4 changes: 2 additions & 2 deletions app/helpers/service_requests_helper.rb
Expand Up @@ -21,8 +21,8 @@
module ServiceRequestsHelper

def protocol_id_display(sub_service_request, service_request)
if sub_service_request && sub_service_request.service_request.protocol.present?
" SRID: #{sub_service_request.service_request.protocol.id}"
if sub_service_request && sub_service_request.protocol.present?
" SRID: #{sub_service_request.protocol.id}"
elsif service_request && service_request.protocol.present?
" SRID: #{service_request.protocol.id}"
else
Expand Down
6 changes: 3 additions & 3 deletions app/mailers/notifier.rb
Expand Up @@ -83,7 +83,7 @@ def notify_admin(submission_email_address, xls, user_current, ssr, audit_report=
@role = 'none'
@full_name = submission_email_address

@protocol = ssr.service_request.protocol
@protocol = ssr.protocol
@service_request = ssr.service_request
@service_requester_id = @service_request.sub_service_requests.first.service_requester_id
@ssrs_to_be_displayed = [ssr]
Expand Down Expand Up @@ -170,14 +170,14 @@ def provide_feedback feedback
end

def sub_service_request_deleted identity, sub_service_request, user_current
@ssr_id = "#{sub_service_request.service_request.protocol.id}-#{sub_service_request.ssr_id}"
@ssr_id = "#{sub_service_request.protocol.id}-#{sub_service_request.ssr_id}"

@triggered_by = user_current.id
@service_request = sub_service_request.service_request
@ssr = sub_service_request

email_to = identity.email
subject = "#{sub_service_request.service_request.protocol.id} - #{t(:mailer)[:application_title]} - service request deleted"
subject = "#{sub_service_request.protocol.id} - #{t(:mailer)[:application_title]} - service request deleted"

mail(:to => email_to, :from => NO_REPLY_FROM, :subject => subject)
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/identity.rb
Expand Up @@ -242,7 +242,7 @@ def can_edit_sub_service_request? ssr
end

def has_correct_project_role? request
protocol = request.class == ServiceRequest ? request.protocol : request.service_request.protocol
protocol = request.protocol

protocol.project_roles.where(identity_id: self.id, project_rights: ['approve', 'request']).any?
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/protocol.rb
Expand Up @@ -35,7 +35,7 @@ class Protocol < ActiveRecord::Base
has_many :identities, through: :project_roles
has_many :service_requests
has_many :services, through: :service_requests
has_many :sub_service_requests, through: :service_requests
has_many :sub_service_requests
has_many :line_items, through: :service_requests
has_many :organizations, through: :sub_service_requests
has_many :affiliations, dependent: :destroy
Expand Down
9 changes: 9 additions & 0 deletions app/models/service_request.rb
Expand Up @@ -38,6 +38,7 @@ class ServiceRequest < ActiveRecord::Base
has_many :notes, as: :notable, dependent: :destroy

after_save :set_original_submitted_date
after_save :set_ssr_protocol_id

validation_group :catalog do
validate :validate_line_items
Expand Down Expand Up @@ -543,4 +544,12 @@ def set_original_submitted_date
self.save(validate: false)
end
end

def set_ssr_protocol_id
if protocol_id_changed?
sub_service_requests.each do |ssr|
ssr.update_attributes(protocol_id: protocol_id)
end
end
end
end
14 changes: 10 additions & 4 deletions app/models/sub_service_request.rb
Expand Up @@ -24,13 +24,15 @@ class SubServiceRequest < ActiveRecord::Base

audited

before_create :set_protocol_id
after_save :update_org_tree
after_save :update_past_status

belongs_to :service_requester, class_name: "Identity", foreign_key: "service_requester_id"
belongs_to :owner, :class_name => 'Identity', :foreign_key => "owner_id"
belongs_to :service_request
belongs_to :organization
belongs_to :protocol
has_many :past_statuses, :dependent => :destroy
has_many :line_items, :dependent => :destroy
has_many :line_items_visits, through: :line_items
Expand All @@ -44,12 +46,12 @@ class SubServiceRequest < ActiveRecord::Base
has_many :subsidies
has_one :approved_subsidy, :dependent => :destroy
has_one :pending_subsidy, :dependent => :destroy
has_one :protocol, through: :service_request

delegate :percent_subsidy, to: :approved_subsidy, allow_nil: true

# service_request_id & ssr_id together form a unique id for the sub service request
attr_accessible :service_request_id
attr_accessible :protocol_id
attr_accessible :ssr_id
attr_accessible :organization_id
attr_accessible :owner_id
Expand Down Expand Up @@ -134,7 +136,7 @@ def unset_effective_date_for_cost_calculations
end

def display_id
return "#{service_request.try(:protocol).try(:id)}-#{ssr_id || 'DRAFT'}"
return "#{protocol.try(:id)}-#{ssr_id || 'DRAFT'}"
end

def has_subsidy?
Expand Down Expand Up @@ -280,7 +282,7 @@ def update_line_item line_item, args

def eligible_for_subsidy?
# This defines when subsidies show up for SubServiceRequests across the app.
if organization.eligible_for_subsidy? and not organization.funding_source_excluded_from_subsidy?(self.service_request.protocol.try(:funding_source_based_on_status))
if organization.eligible_for_subsidy? and not organization.funding_source_excluded_from_subsidy?(self.protocol.try(:funding_source_based_on_status))
true
else
false
Expand Down Expand Up @@ -464,7 +466,7 @@ def generate_approvals current_user, params
##########################
# Distributes all available surveys to primary pi and ssr requester
def distribute_surveys
primary_pi = service_request.protocol.primary_principal_investigator
primary_pi = protocol.primary_principal_investigator
# send all available surveys at once
available_surveys = line_items.map{|li| li.service.available_surveys}.flatten.compact.uniq
# do nothing if we don't have any available surveys
Expand Down Expand Up @@ -514,6 +516,10 @@ def audit_report(identity, start_date, end_date=Time.now.utc)

private

def set_protocol_id
self.protocol_id = service_request.try(:protocol_id)
end

def notify_remote_around_update?
true
end
Expand Down
4 changes: 2 additions & 2 deletions app/views/dashboard/notifications/_dropdown.html.haml
Expand Up @@ -19,8 +19,8 @@
-# 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.
%select.selectpicker.new-notification{ title: t(:dashboard)[:notifications][:table][:send], data: { style: "btn-success new_notification_button", live_search: 'true', sub_service_request_id: sub_service_request.ssr_id } }
%optgroup{ label: t(:dashboard)[:notifications][:table][:authorized_users]}
- sub_service_request.service_request.protocol.project_roles.each do |pr|
%option{ data: { identity_id: pr.identity_id, sub_service_request_id: sub_service_request.id, is_service_provider: 'false', current_user_id: user.id, content: display_authorized_user(pr, sub_service_request.service_requester_id) } }
- sub_service_request.protocol.project_roles.each do |pr|
%option{ data: { identity_id: pr.identity_id, sub_service_request_id: sub_service_request.id, is_service_provider: 'false', current_user_id: user.id, content: display_authorized_user(pr, sub_service_request.service_requester_id) } }
%optgroup{ label: t(:dashboard)[:notifications][:table][:service_providers]}
- sub_service_request.organization.service_providers.includes(:identity).sort_by { |sp| sp.identity.last_name }.each do |sp|
%option{ data: { identity_id: sp.identity.id, sub_service_request_id: sub_service_request.id, is_service_provider: 'true', current_user_id: user.id, content: display_service_provider(sp, sub_service_request.owner_id) } }
Expand Up @@ -29,14 +29,14 @@
%tr
%th
= t(:study_tracker)[:visit_calendar][:header1]
= @sub_service_request.service_request.protocol.id
= @sub_service_request.protocol_id
%th
= t(:study_tracker)[:visit_calendar][:header2]
= @subject.external_subject_id
%tr
%th
= t(:study_tracker)[:visit_calendar][:header3]
= @sub_service_request.service_request.protocol.billing_managers.try(:first).try(:full_name)
= @sub_service_request.protocol.billing_managers.try(:first).try(:full_name)
%th
= t(:study_tracker)[:visit_calendar][:header4]
= f.select :status, options_for_select(["Active", "Completed", "Early Term", "Screen Fail"], f.try(:object).try(:status)), :include_blank => "--Choose a Status--"
Expand Down Expand Up @@ -72,4 +72,4 @@
core_id = $(ui.newTab).data("core_id")
$.cookie('current_core', core_id, {path: '/', expires: 1})
)

Expand Up @@ -28,7 +28,7 @@
for Visit
= "#{@procedure.appointment.display_name}"
on your study
= "#{@sub_service_request.display_id} - #{@sub_service_request.service_request.protocol.short_title}"
= "#{@sub_service_request.display_id} - #{@sub_service_request.protocol.short_title}"
by SCTR Research Nexus Staff. To inquire about the changes, please contact the Research Nexus as appropriate below:

%ul
Expand Down
@@ -0,0 +1,20 @@
class AddProtocolIdToSubServiceRequests < ActiveRecord::Migration
def change
add_column :sub_service_requests, :protocol_id, :integer
add_index :sub_service_requests, :protocol_id

SubServiceRequest.find_each do |ssr|
if ssr.service_request
if ssr.service_request.protocol_id
ssr.protocol_id = ssr.service_request.protocol_id
ssr.save
else
puts "Sub Service Request: #{ssr.id} has a Service Request with no protocol_id"
end
else
puts "Sub Service Request: #{ssr.id} has no Service Request"
end
end

end
end
4 changes: 3 additions & 1 deletion db/schema.rb
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20170217134129) do
ActiveRecord::Schema.define(version: 20170303171239) do

create_table "admin_rates", force: :cascade do |t|
t.integer "line_item_id", limit: 4
Expand Down Expand Up @@ -1026,10 +1026,12 @@
t.text "org_tree_display", limit: 65535
t.integer "service_requester_id", limit: 4
t.datetime "submitted_at"
t.integer "protocol_id", limit: 4
end

add_index "sub_service_requests", ["organization_id"], name: "index_sub_service_requests_on_organization_id", using: :btree
add_index "sub_service_requests", ["owner_id"], name: "index_sub_service_requests_on_owner_id", using: :btree
add_index "sub_service_requests", ["protocol_id"], name: "index_sub_service_requests_on_protocol_id", using: :btree
add_index "sub_service_requests", ["service_request_id"], name: "index_sub_service_requests_on_service_request_id", using: :btree
add_index "sub_service_requests", ["service_requester_id"], name: "index_sub_service_requests_on_service_requester_id", using: :btree
add_index "sub_service_requests", ["ssr_id"], name: "index_sub_service_requests_on_ssr_id", using: :btree
Expand Down
6 changes: 3 additions & 3 deletions lib/reports/apr_report.rb
Expand Up @@ -73,15 +73,15 @@ def service_and_ssr_counts
Organization.all.each do |organization|
ssrs = SubServiceRequest.find_all_by_organization_id(organization.id)
ssrs_with_sr = ssrs.select {|x| x.service_request}
ssrs_with_protocol = ssrs_with_sr.select {|x| x.service_request.protocol}
ssrs_with_protocol = ssrs_with_sr.select {|x| x.protocol}
ssrs_with_status = ssrs_with_protocol.select {|x| ['submitted', 'in process', 'complete'].include?(x.status)}
within_dates = ssrs_with_status.select {|x| relevant_date(x) < Date.parse('2013-01-01') && relevant_date(x) > Date.parse('2012-03-01')}
line_items = within_dates.map {|x| x.line_items.count}.inject(:+)

lis = LineItem.all.select {|x| x.service.organization_id == organization.id}
lis_with_ssr = lis.select {|x| x.sub_service_request}
lis_with_sr = lis_with_ssr.select {|x| x.sub_service_request.service_request}
lis_with_protocol = lis_with_sr.select {|x| x.sub_service_request.service_request.protocol}
lis_with_protocol = lis_with_sr.select {|x| x.sub_service_request.protocol}
lis_with_status = lis_with_protocol.select {|x| ['submitted', 'in process', 'complete'].include?(x.sub_service_request.status)}
lis_within_dates = lis_with_status.select {|x| relevant_date(x.sub_service_request) < Date.parse('2013-01-01') && relevant_date(x.sub_service_request) > Date.parse('2012-03-01')}

Expand Down Expand Up @@ -165,7 +165,7 @@ def run
row << protocol.title
row << protocol.funding_status.try(:humanize)
row << (protocol.funding_status == 'funded' ? protocol.funding_source : '').try(:humanize)

row << (protocol.funding_source == 'federal' ? protocol.federal_grant_code_id : '')
row << (protocol.funding_source == 'federal' ? protocol.federal_phs_sponsor : '')
row << (protocol.funding_source == 'federal' ? protocol.federal_non_phs_sponsor : '')
Expand Down
10 changes: 5 additions & 5 deletions lib/reports/ctrc_subsidy_report.rb
Expand Up @@ -58,12 +58,12 @@ def run
#unless ["draft", "first_draft"].include? ssr.status
if ["in_process", "ctrc_review", "ctrc_approved"].include? ssr.status # per request by Lane we only want this report to include these statuses
if ssr.service_request
if ssr.service_request.protocol
if ssr.protocol
row = []
puts '#'*100
puts "#{ssr.service_request.protocol.id}-#{ssr.ssr_id}"
row << "#{ssr.service_request.protocol.id}-#{ssr.ssr_id}"
row << "#{ssr.service_request.protocol.primary_principal_investigator.full_name}"
puts ssr.display_id
row << ssr.display_id
row << "#{ssr.protocol.primary_principal_investigator.full_name}"
row << CtrcSubsidyReport.currency_converter(ssr.direct_cost_total)
puts CtrcSubsidyReport.currency_converter(ssr.direct_cost_total)
if ssr.subsidy
Expand All @@ -75,7 +75,7 @@ def run
row << ""
row << ""
end
row << ssr.service_request.protocol.display_funding_source_value
row << ssr.protocol.display_funding_source_value

csv << row
end
Expand Down
6 changes: 2 additions & 4 deletions lib/tasks/admin_turnaround_times_report.rake
Expand Up @@ -45,9 +45,7 @@ namespace :data do
end

def full_ssr_id(ssr)
protocol = ssr.service_request.protocol

"#{protocol.id}-#{ssr.ssr_id}"
ssr.display_id
end

def extract_status_dates ssr
Expand Down Expand Up @@ -90,4 +88,4 @@ namespace :data do
puts "No provider id specified."
end
end
end
end
2 changes: 1 addition & 1 deletion lib/tasks/jit_report.rake
Expand Up @@ -27,7 +27,7 @@ task :jit_report => :environment do

ssrs.each do |ssr|
first_submit = ssr.past_statuses.where(:status => 'submitted').first.date
protocol = ssr.service_request.protocol
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,
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)]
Expand Down