Skip to content

Commit

Permalink
Merge pull request #1020 from sparc-request/os#147708807-status
Browse files Browse the repository at this point in the history
SAW - changed available/default statuses constant call to query
  • Loading branch information
Stuart-Johnson committed Jul 26, 2017
2 parents d1de86a + a19c379 commit 40eb927
Show file tree
Hide file tree
Showing 41 changed files with 138 additions and 42 deletions.
2 changes: 1 addition & 1 deletion app/controllers/dashboard/protocols_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def index
initialize_filterrific(Protocol, params[:filterrific] && filterrific_params,
default_filter_params: @default_filter_params,
select_options: {
with_status: AVAILABLE_STATUSES.invert,
with_status: PermissibleValue.get_inverted_hash('status'),
with_organization: Dashboard::GroupedOrganizations.new(@organizations).collect_grouped_options,
with_owner: build_with_owner_params
},
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/dashboard/service_requests_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def protocol_panel_header_line service_request
if service_request.status == "submitted"
"Service Request: #{service_request.id} - Submitted - #{format_date(service_request.submitted_at)}"
else
"Service Request: #{service_request.id} - #{AVAILABLE_STATUSES[service_request.status]} - #{format_date(service_request.updated_at)}"
"Service Request: #{service_request.id} - #{PermissibleValue.get_value('status', service_request.status)} - #{format_date(service_request.updated_at)}"
end
end

Expand Down
2 changes: 1 addition & 1 deletion app/lib/reports/all_service_requests_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def run
'Primary Investigator Department'
]

statuses = AVAILABLE_STATUSES
statuses = PermissibleValue.get_hash('status')

idx = 1

Expand Down
2 changes: 1 addition & 1 deletion app/lib/reports/redcap_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def run
'Service Provider'
]

statuses = AVAILABLE_STATUSES
statuses = PermissibleValue.get_hash('status')

idx = 1

Expand Down
2 changes: 1 addition & 1 deletion app/lib/reports/success_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def run
'Status'
]

statuses = AVAILABLE_STATUSES
statuses = PermissibleValue.get_hash('status')

orgs = Program.find(47).cores.map(&:id)

Expand Down
2 changes: 1 addition & 1 deletion app/models/available_status.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ class AvailableStatus < ApplicationRecord
attr_accessor :new
attr_accessor :position

TYPES = AVAILABLE_STATUSES
TYPES = PermissibleValue.get_hash('status')
end
8 changes: 4 additions & 4 deletions app/models/organization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ def all_super_users

def setup_available_statuses
position = 1
obj_names = AvailableStatus::TYPES.map{ |k,v| k }
obj_names = PermissibleValue.get_hash('status').map{ |k,v| k }
obj_names.each do |obj_name|
available_status = available_statuses.detect { |obj| obj.status == obj_name }
available_status ||= available_statuses.build(status: obj_name, new: true)
Expand All @@ -362,15 +362,15 @@ def get_available_statuses
if tmp_available_statuses.empty?
self.parents.each do |parent|
if !parent.available_statuses.empty?
statuses = AVAILABLE_STATUSES.select{|k,v| parent.available_statuses.map(&:status).include? k}
statuses = PermissibleValue.get_hash('status').select{|k,v| parent.available_statuses.map(&:status).include? k}
return statuses
end
end
else
statuses = AVAILABLE_STATUSES.select{|k,v| tmp_available_statuses.map(&:status).include? k}
statuses = PermissibleValue.get_hash('status').select{|k,v| tmp_available_statuses.map(&:status).include? k}
end
if statuses.empty?
statuses = AVAILABLE_STATUSES.select{|k,v| DEFAULT_STATUSES.include? k}
statuses = PermissibleValue.get_hash('status').select{|k,v| PermissibleValue.get_key_list('status', true).include? k}
end
statuses
end
Expand Down
9 changes: 9 additions & 0 deletions app/models/permissible_value.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ def self.get_value_list(category)
PermissibleValue.where(category: category).pluck(:value)
end

# Get an array of PermissibleValue keys with the given category
def self.get_key_list(category, default=nil)
unless default.nil?
PermissibleValue.where(category: category, default: default).pluck(:key)
else
PermissibleValue.where(category: category).pluck(:key)
end
end

# Get a hash of PermissibleValue keys as they keys and values as values
def self.get_hash(category)
Hash[PermissibleValue.where(category: category).pluck(:key, :value)]
Expand Down
9 changes: 5 additions & 4 deletions app/models/sub_service_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,11 @@ def previously_submitted?
end

def formatted_status
if AVAILABLE_STATUSES.has_key? status
AVAILABLE_STATUSES[status]
else
formatted_status = PermissibleValue.get_value('status', self.status)
if formatted_status.nil?
"STATUS MAPPING NOT PRESENT"
else
formatted_status
end
end

Expand Down Expand Up @@ -261,7 +262,7 @@ def ready_for_fulfillment?
def update_status_and_notify(new_status)
to_notify = []
if can_be_edited?
available = AVAILABLE_STATUSES.keys
available = PermissibleValue.get_key_list('status')
editable = EDITABLE_STATUSES[organization_id] || available
changeable = available & editable
if changeable.include?(new_status)
Expand Down
4 changes: 2 additions & 2 deletions app/reports/admin_time_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def default_options
Program => {:field_type => :select_tag, :dependency => '#provider_id', :dependency_id => 'parent_id', :required => true},
Core => {:field_type => :select_tag, :dependency => '#program_id', :dependency_id => 'parent_id'},
Service => {:field_type => :select_tag, :dependency => '#program_id, #core_id', :dependency_id => 'organization_id', :required => true},
"Current Status" => {:field_type => :check_box_tag, :for => 'status', :multiple => AVAILABLE_STATUSES}
"Current Status" => {:field_type => :check_box_tag, :for => 'status', :multiple => PermissibleValue.get_hash('status')}
}
end

Expand Down Expand Up @@ -136,7 +136,7 @@ def where args={}

# submitted_at ||= self.default_options["Date Range"][:from]..self.default_options["Date Range"][:to]
submitted_at = "2012-03-01".to_date..Date.today
statuses = args[:status] || AVAILABLE_STATUSES.keys # use all if none are selected
statuses = args[:status] || PermissibleValue.get_key_list('status') # use all if none are selected

return :sub_service_requests => {:organization_id => ssr_organization_ids, :status => statuses}, :service_requests => {:submitted_at => submitted_at}, :services => {:id => args[:service_id]}
end
Expand Down
2 changes: 1 addition & 1 deletion app/reports/protocols.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def where args={}
ssr_organization_ids = Organization.all.map(&:id) if ssr_organization_ids.compact.empty? # use all if none are selected

submitted_at ||= self.default_options["Date Range"][:from]..self.default_options["Date Range"][:to]
statuses = args[:status] || AVAILABLE_STATUSES.keys # use all if none are selected
statuses = args[:status] || PermissibleValue.get_key_list('status') # use all if none are selected

return :sub_service_requests => {:organization_id => ssr_organization_ids, :status => statuses}, :service_requests => {:submitted_at => submitted_at}, :services => {:organization_id => service_organization_ids}
end
Expand Down
4 changes: 2 additions & 2 deletions app/reports/service_requests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def default_options
Program => {:field_type => :select_tag, :dependency => '#provider_id', :dependency_id => 'parent_id'},
Core => {:field_type => :select_tag, :dependency => '#program_id', :dependency_id => 'parent_id'},
"Tags" => {:field_type => :text_field_tag},
"Current Status" => {:field_type => :check_box_tag, :for => 'status', :multiple => AVAILABLE_STATUSES},
"Current Status" => {:field_type => :check_box_tag, :for => 'status', :multiple => PermissibleValue.get_hash('status')},
"Show APR Data" => {:field_type => :check_box_tag, :for => 'apr_data', :multiple => {"irb" => "IRB", "iacuc" => "IACUC"}},
"Show SPARCFulfillment Information" => {:field_type => :check_box_tag, :for => 'fulfillment_info', :field_label => 'Show SPARCFulfillment Information' }
}
Expand Down Expand Up @@ -173,7 +173,7 @@ def where args={}
ssr_organization_ids = Organization.all.map(&:id) if ssr_organization_ids.compact.empty? # use all if none are selected

submitted_at ||= self.default_options["Submission Date Range"][:from]..self.default_options["Submission Date Range"][:to]
statuses = args[:status] || AVAILABLE_STATUSES.keys # use all if none are selected
statuses = args[:status] || PermissibleValue.get_key_list('status') # use all if none are selected

return :sub_service_requests => {:organization_id => ssr_organization_ids, :status => statuses, :submitted_at => submitted_at}, :services => {:organization_id => service_organization_ids}
end
Expand Down
4 changes: 2 additions & 2 deletions app/reports/test_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def default_options
Provider => {:field_type => :select_tag, :dependency => '#institution_id', :dependency_id => 'parent_id'},
Program => {:field_type => :select_tag, :dependency => '#provider_id', :dependency_id => 'parent_id'},
Core => {:field_type => :select_tag, :dependency => '#program_id', :dependency_id => 'parent_id'},
"Current Status" => {:field_type => :check_box_tag, :for => 'status', :multiple => AVAILABLE_STATUSES},
"Current Status" => {:field_type => :check_box_tag, :for => 'status', :multiple => PermissibleValue.get_hash('status')},
"One Date" => {:field_type => :date_field, :for => "service_requests_submitted_at"}
}
end
Expand Down Expand Up @@ -141,7 +141,7 @@ def where args={}
service_organization_ids = Organization.all.map(&:id) if service_organization_ids.compact.empty? # use all if none are selected
ssr_organization_ids = Organization.all.map(&:id) if ssr_organization_ids.compact.empty? # use all if none are selected
submitted_at ||= self.default_options["Date Range"][:from]..self.default_options["Date Range"][:to]
statuses = args[:status] || AVAILABLE_STATUSES.keys # use all if none are selected
statuses = args[:status] || PermissibleValue.get_key_list('status') # use all if none are selected

return :sub_service_requests => {:organization_id => ssr_organization_ids, :status => statuses}, :project_roles => {:role => ['pi', 'primary-pi']}, :service_requests => {:submitted_at => submitted_at}, :services => {:organization_id => service_organization_ids}
end
Expand Down
10 changes: 5 additions & 5 deletions app/views/catalog_manager/shared/_available_statuses.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,19 @@
%td
%legend= t(:organization_form)[:available_statuses]
%table
= f.fields_for :available_statuses, @organization.available_statuses.sort{|x, y| AVAILABLE_STATUSES[x.status] <=> AVAILABLE_STATUSES[y.status]} do |as|
= f.fields_for :available_statuses, @organization.available_statuses.sort{|x, y| PermissibleValue.get_value('status', x.status) <=> PermissibleValue.get_value('status', y.status)} do |as|
%tr
%th= as.label :status, "#{AvailableStatus::TYPES[as.object.status].gsub('CTRC', 'Nexus')}:"
%td= as.check_box "_destroy", {:checked => !as.object.new_record? || DEFAULT_STATUSES.include?(as.object.status), :disabled => ["Draft", "Get a Cost Estimate", "Submitted"].include?(AVAILABLE_STATUSES[as.object.status])}, false, true
%th= as.label :status, "#{PermissibleValue.get_value('status', as.object.status).gsub('CTRC', 'Nexus')}:"
%td= as.check_box "_destroy", {:checked => !as.object.new_record? || PermissibleValue.get_key_list('status', true).include?(as.object.status), :disabled => ["Draft", "Get a Cost Estimate", "Submitted"].include?(PermissibleValue.get_value('status', as.object.status))}, false, true
= as.hidden_field :status, :value => as.object.status
%td
%legend= t(:organization_form)[:selected_statuses]
%table
%tr
%tr
%tr
- @organization.available_statuses.sort{|x, y| AVAILABLE_STATUSES[x.status] <=> AVAILABLE_STATUSES[y.status]}.each do |as|
- @organization.available_statuses.sort{|x, y| PermissibleValue.get_value('status', x.status) <=> PermissibleValue.get_value('status', y.status)}.each do |as|
-if !as.id.nil?
%tr
%th= AVAILABLE_STATUSES[as.status]
%th= PermissibleValue.get_value('status', as.status)

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ json.(@sub_service_requests) do |ssr|
json.srid ssr.display_id
json.organization ssr.org_tree_display
json.owner display_owner(ssr)
json.status AVAILABLE_STATUSES[ssr.status]
json.status PermissibleValue.get_value('status', ssr.status)
json.notifications ssr_notifications_display(ssr, @user)
json.actions ssr_actions_display(ssr, @user, @permission_to_edit, @admin_orgs, @show_view_ssr_back)
json.surveys display_ssr_submissions(ssr)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
json.(@past_statuses) do |status|
json.created_at format_datetime(status.date)
json.changed_from AVAILABLE_STATUSES[status.status]
json.changed_to AVAILABLE_STATUSES[status.changed_to]
json.changed_from PermissibleValue.get_value('status', status.status)
json.changed_to PermissibleValue.get_value('status', status.changed_to)
json.changed_by status.changer.try(:full_name)
end
2 changes: 1 addition & 1 deletion app/views/notifier/_srid_information.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@
- else
%td.skinny-black-border.center= ssr.display_id
%td.skinny-black-border.center= ssr.org_tree_display
%td.skinny-black-border.center= AVAILABLE_STATUSES[ssr.reload.status]
%td.skinny-black-border.center= PermissibleValue.get_value('status', ssr.reload.status)
%br
%br
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
%td.notes.text-center
= display_li_notes(line_item, @portal)
%td.status.text-center
= AVAILABLE_STATUSES[ssr.status]
= PermissibleValue.get_value('status', ssr.status)
%td.service-rate.text-center
= display_service_rate(line_item)
%td.your-cost.text-center
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
%td.notes.text-center.notes-width
= display_liv_notes(liv, @portal)
%td.status.text-center.status-width
= AVAILABLE_STATUSES[ssr.status]
= PermissibleValue.get_value('status', ssr.status)
%td.service-rate.text-center.sm-col-width
= display_service_rate(liv.line_item)
%td.your-cost.text-center.sm-col-width
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
%td.notes.text-center.notes-width
= display_liv_notes(liv, @portal)
%td.status.text-center.status-width
= AVAILABLE_STATUSES[ssr.status]
= PermissibleValue.get_value('status', ssr.status)
%td.service-rate.text-center.sm-col-width
= display_service_rate(liv.line_item)
%td.your-cost.text-center.sm-col-width
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
%td.notes.text-center.notes-width
= display_liv_notes(liv, @portal)
%td.status.text-center.status-width
= AVAILABLE_STATUSES[ssr.status]
= PermissibleValue.get_value('status', ssr.status)
%td.service-rate.text-center.sm-col-width
= display_service_rate(liv.line_item)
%td.your-cost.text-center.sm-col-width
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,33 @@
# 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.

class UpdateObtainResearchPricingAvailableStatuses < ActiveRecord::Migration

class AvailableStatus < ApplicationRecord
audited

belongs_to :organization

attr_accessor :new
attr_accessor :position

TYPES = { 'ctrc_approved': 'Active',
'administrative_review': 'Administrative Review',
'approved': 'Approved',
'awaiting_pi_approval': 'Awaiting Requester Response',
'complete': 'Complete',
'declined': 'Declined',
'draft': 'Draft',
'get_a_cost_estimate': 'Get a Cost Estimate',
'invoiced': 'Invoiced',
'ctrc_review': 'In Admin Review',
'committee_review': 'In Committee Review',
'fulfillment_queue': 'In Fulfillment Queue',
'in_process': 'In Process',
'on_hold': 'On Hold',
'submitted': 'Submitted',
'withdrawn': 'Withdrawn' }
end

def up
AvailableStatus.where(:status => 'obtain_research_pricing').each do |as|
as.update_attributes({:status => 'get_a_cost_estimate'})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,31 +19,58 @@
# 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.~

class ChangeServiceRequestQuoteStatusToGetCostEstimate < ActiveRecord::Migration

class AvailableStatus < ApplicationRecord
audited

belongs_to :organization

attr_accessor :new
attr_accessor :position

TYPES = { 'ctrc_approved': 'Active',
'administrative_review': 'Administrative Review',
'approved': 'Approved',
'awaiting_pi_approval': 'Awaiting Requester Response',
'complete': 'Complete',
'declined': 'Declined',
'draft': 'Draft',
'get_a_cost_estimate': 'Get a Cost Estimate',
'invoiced': 'Invoiced',
'ctrc_review': 'In Admin Review',
'committee_review': 'In Committee Review',
'fulfillment_queue': 'In Fulfillment Queue',
'in_process': 'In Process',
'on_hold': 'On Hold',
'submitted': 'Submitted',
'withdrawn': 'Withdrawn' }
end

def up
[
'ServiceRequest',
'SubServiceRequest',
'AvailableStatus',
'PastStatus'
].each do |model|
model.
constantize.
where(status: 'get_a_quote').
update_all status: 'get_a_cost_estimate'
end
AvailableStatus.where(status: 'get_a_quote').update_all(status: 'get_a_cost_estimate')
end

def down
[
'ServiceRequest',
'SubServiceRequest',
'AvailableStatus',
'PastStatus'
].each do |model|
model.
constantize.
where(status: 'get_a_cost_estimate').
update_all status: 'get_a_quote'
end
AvailableStatus.where(status: 'get_a_quote').update_all(status: 'get_a_cost_estimate')
end
end
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 @@ -74,7 +74,7 @@ namespace :data do
def build_one_time_fee_report csv, ssr, provider, program, core
if ssr.protocol
service_request_id = full_ssr_id(ssr)
status = AVAILABLE_STATUSES[ssr.status]
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)
Expand Down
1 change: 1 addition & 0 deletions spec/controllers/service_requests/get_confirmation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
stub_controller
let!(:before_filters) { find_before_filters }
let!(:logged_in_user) { create(:identity) }
build_statuses

describe '#confirmation' do
it 'should call before_filter #initialize_service_request' do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
stub_controller
let!(:before_filters) { find_before_filters }
let!(:logged_in_user) { create(:identity) }
build_statuses

describe '#obtain_research_pricing' do
it 'should call before_filter #initialize_service_request' do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
stub_controller
let!(:before_filters) { find_before_filters }
let!(:logged_in_user) { create(:identity) }
build_statuses

describe '#obtain_research_pricing' do
it 'should call before_filter #initialize_service_request' do
Expand Down

0 comments on commit 40eb927

Please sign in to comment.