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

billing report cleanup, removing lines for empty protocols #97

Merged
merged 1 commit into from
Oct 26, 2015
Merged
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
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