Skip to content

Commit

Permalink
Merge pull request #97 from sparc-request/sj_billing_report_cleanup
Browse files Browse the repository at this point in the history
billing report cleanup, removing lines for empty protocols
  • Loading branch information
Stuart-Johnson committed Oct 26, 2015
2 parents eee4399 + 357474b commit d1cc654
Showing 1 changed file with 61 additions and 57 deletions.
118 changes: 61 additions & 57 deletions lib/reports/billing_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,74 +24,78 @@ def generate(document)
protocols.each do |protocol|
total = 0

csv << ["Study Level Charges:"]
csv << [
"Protocol ID",
"Primary PI",
"Fulfillment Date",
"Service(s) Completed",
"Quantity Completed",
"",
"",
"",
"Research Rate",
"Total Cost"
]
csv << [""]

protocol.fulfillments.fulfilled_in_date_range(@start_date, @end_date).each do |fulfillment|
if protocol.fulfillments.fulfilled_in_date_range(@start_date, @end_date).any?
csv << ["Study Level Charges:"]
csv << [
protocol.sparc_id,
protocol.pi ? protocol.pi.full_name : nil,
format_date(fulfillment.fulfilled_at),
fulfillment.service_name,
fulfillment.quantity,
"Protocol ID",
"Primary PI",
"Fulfillment Date",
"Service(s) Completed",
"Quantity Completed",
"",
"",
"",
display_cost(fulfillment.service_cost),
display_cost(fulfillment.total_cost)
"Research Rate",
"Total Cost"
]
csv << [""]

total += fulfillment.total_cost
protocol.fulfillments.fulfilled_in_date_range(@start_date, @end_date).each do |fulfillment|
csv << [
protocol.sparc_id,
protocol.pi ? protocol.pi.full_name : nil,
format_date(fulfillment.fulfilled_at),
fulfillment.service_name,
fulfillment.quantity,
"",
"",
"",
display_cost(fulfillment.service_cost),
display_cost(fulfillment.total_cost)
]

total += fulfillment.total_cost
end
end

csv << [""]
csv << [""]
if protocol.procedures.completed_r_in_date_range(@start_date, @end_date).any?
csv << [""]
csv << [""]

csv << ["Procedures/Per-Patient-Per-Visit:"]
csv << [
"Protocol ID",
"Primary PI",
"Patient Name",
"Patient ID",
"Visit Name",
"Visit Date",
"Service(s) Completed",
"Quantity Completed",
"Research Rate",
"Total Cost"
]
csv << [""]
protocol.procedures.completed_r_in_date_range(@start_date, @end_date).group_by(&:appointment).each do |appointment, appointment_procedures|
participant = appointment.participant
csv << ["Procedures/Per-Patient-Per-Visit:"]
csv << [
"Protocol ID",
"Primary PI",
"Patient Name",
"Patient ID",
"Visit Name",
"Visit Date",
"Service(s) Completed",
"Quantity Completed",
"Research Rate",
"Total Cost"
]
csv << [""]
protocol.procedures.completed_r_in_date_range(@start_date, @end_date).group_by(&:appointment).each do |appointment, appointment_procedures|
participant = appointment.participant

appointment_procedures.group_by(&:service_name).each do |service_name, service_procedures|
procedure = service_procedures.first
appointment_procedures.group_by(&:service_name).each do |service_name, service_procedures|
procedure = service_procedures.first

csv << [
protocol.sparc_id,
protocol.pi ? protocol.pi.full_name : nil,
participant.full_name,
participant.label,
appointment.name,
format_date(appointment.start_date),
procedure.service_name,
service_procedures.size,
display_cost(procedure.service_cost),
display_cost(service_procedures.size * procedure.service_cost.to_f)
]
total += service_procedures.size * procedure.service_cost.to_f
csv << [
protocol.sparc_id,
protocol.pi ? protocol.pi.full_name : nil,
participant.full_name,
participant.label,
appointment.name,
format_date(appointment.start_date),
procedure.service_name,
service_procedures.size,
display_cost(procedure.service_cost),
display_cost(service_procedures.size * procedure.service_cost.to_f)
]
total += service_procedures.size * procedure.service_cost.to_f
end
end
end
if total > 0
Expand Down

0 comments on commit d1cc654

Please sign in to comment.