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

wth - (SPARCFulfillment) Add Funding Source Column to Fulfillment/Pro… #328

Merged
merged 8 commits into from Aug 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/controllers/fulfillments_controller.rb
Expand Up @@ -44,7 +44,7 @@ def create
@line_item = LineItem.find(fulfillment_params[:line_item_id])
service = @line_item.service
funding_source = @line_item.protocol.sparc_funding_source
@fulfillment = Fulfillment.new(fulfillment_params.merge!({ creator: current_identity, service: service, service_name: service.name, service_cost: @line_item.cost(funding_source) }))
@fulfillment = Fulfillment.new(fulfillment_params.merge!({ creator: current_identity, service: service, service_name: service.name, service_cost: @line_item.cost(funding_source), funding_source: funding_source }))
if @fulfillment.valid?
@fulfillment.save
update_components_and_create_notes('create')
Expand Down
4 changes: 3 additions & 1 deletion app/controllers/procedures_controller.rb
Expand Up @@ -30,6 +30,7 @@ def create
service = Service.find params[:service_id]
performer_id = params[:performer_id]
@procedures = []
funding_source = @appointment.protocol.sparc_funding_source

qty.times do
@procedures << Procedure.create(appointment: @appointment,
Expand All @@ -38,7 +39,8 @@ def create
performer_id: performer_id,
billing_type: 'research_billing_qty',
sparc_core_id: service.sparc_core_id,
sparc_core_name: service.sparc_core_name)
sparc_core_name: service.sparc_core_name,
funding_source: funding_source)
end
end

Expand Down
2 changes: 1 addition & 1 deletion app/models/fulfillment.rb
Expand Up @@ -60,7 +60,7 @@ def total_cost

def cost_available
date = fulfilled_at ? fulfilled_at : Date.today
cost = line_item.try(:cost, line_item.protocol.sparc_funding_source, date) rescue nil
cost = line_item.try(:cost, funding_source, date) rescue nil
if cost.nil?
errors[:base] << "No cost found, ensure that a valid pricing map exists for that date."
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/procedure.rb
Expand Up @@ -187,7 +187,7 @@ def service_name
end
end

def cost(funding_source = protocol.sparc_funding_source, date = Time.current)
def cost(date = Time.current)
if service_cost
service_cost.to_i
else
Expand Down
@@ -0,0 +1,5 @@
class AddFundingSourceToFulfillments < ActiveRecord::Migration[5.0]
def change
add_column :fulfillments, :funding_source, :string, after: :quantity
end
end
5 changes: 5 additions & 0 deletions db/migrate/20180613165940_add_funding_source_to_procedures.rb
@@ -0,0 +1,5 @@
class AddFundingSourceToProcedures < ActiveRecord::Migration[5.0]
def change
add_column :procedures, :funding_source, :string
end
end
6 changes: 4 additions & 2 deletions db/schema.rb
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20180322134942) do
ActiveRecord::Schema.define(version: 20180613165940) do

create_table "appointment_statuses", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin" do |t|
t.string "status"
Expand Down Expand Up @@ -101,7 +101,8 @@
t.integer "sparc_id"
t.integer "line_item_id"
t.datetime "fulfilled_at"
t.decimal "quantity", precision: 10, scale: 2
t.decimal "quantity", precision: 10, scale: 2
t.string "funding_source"
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "deleted_at"
Expand Down Expand Up @@ -237,6 +238,7 @@
t.integer "performer_id"
t.datetime "incompleted_date"
t.boolean "invoiced"
t.string "funding_source"
t.index ["appointment_id"], name: "index_procedures_on_appointment_id", using: :btree
t.index ["completed_date"], name: "index_procedures_on_completed_date", using: :btree
t.index ["service_id"], name: "index_procedures_on_service_id", using: :btree
Expand Down
4 changes: 4 additions & 0 deletions lib/reports/invoice_report.rb
Expand Up @@ -78,6 +78,7 @@ def generate(document)
header << "Request ID"
header << "RMID" if ENV.fetch('RMID_URL'){nil}
header << "Short Title"
header << "Funding Source"
header << "Status"
header << "Primary PI"
header << "Primary PI Affiliation"
Expand All @@ -103,6 +104,7 @@ def generate(document)
data << protocol.sub_service_request.ssr_id
data << protocol.research_master_id if ENV.fetch('RMID_URL'){nil}
data << protocol.sparc_protocol.short_title
data << fulfillment.funding_source
data << formatted_status(protocol)
data << (protocol.pi ? protocol.pi.full_name : nil)
data << (protocol.pi ? [protocol.pi.professional_org_lookup("institution"), protocol.pi.professional_org_lookup("college"),
Expand Down Expand Up @@ -139,6 +141,7 @@ def generate(document)
header << "Request ID"
header << "RMID" if ENV.fetch('RMID_URL'){nil}
header << "Short Title"
header << "Funding Source"
header << "Status"
header << "Primary PI"
header << "Primary PI Affiliation"
Expand Down Expand Up @@ -173,6 +176,7 @@ def generate(document)
data << protocol.sub_service_request.ssr_id
data << protocol.research_master_id if ENV.fetch('RMID_URL'){nil}
data << protocol.sparc_protocol.short_title
data << procedure.funding_source
data << formatted_status(protocol)
data << (protocol.pi ? protocol.pi.full_name : nil)
data << (protocol.pi ? [protocol.pi.professional_org_lookup("institution"), protocol.pi.professional_org_lookup("college"),
Expand Down
16 changes: 16 additions & 0 deletions lib/tasks/find_historical_funding_sources.rake
@@ -0,0 +1,16 @@
namespace :data do
task find_historical_funding_sources: :environment do
Protocol.all.each do |p|
begin
funding_source = p.sparc_funding_source

p.procedures.update_all(funding_source: funding_source)
p.fulfillments.update_all(funding_source: funding_source)
rescue
puts "Protocol ID: #{p.id}, SPARC Protocol ID: #{p.sparc_id} is invalid"
next
end
end
end
end