Skip to content

Commit

Permalink
Merge pull request #131 from sparc-request/kg-report_date_time_zone
Browse files Browse the repository at this point in the history
KG - Report Date Filtering Fixes
  • Loading branch information
amcates committed Feb 5, 2016
2 parents bed8284 + 6e970e4 commit a27c790
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 13 deletions.
1 change: 1 addition & 0 deletions app/controllers/reports_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def reports_params
:title,
:start_date,
:end_date,
:time_zone,
:protocol_id,
:participant_id,
:documentable_id,
Expand Down
16 changes: 10 additions & 6 deletions lib/reports/auditing_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@ class AuditingReport < Report
require 'csv'

def generate(document)
@start_date = Time.strptime(@params[:start_date], "%m-%d-%Y").in_time_zone(@params[:time_zone])
@end_date = Time.strptime(@params[:end_date], "%m-%d-%Y").in_time_zone(@params[:time_zone])
#We want to filter from 00:00:00 in the local time zone,
#then convert to UTC to match database times
@start_date = Time.strptime(@params[:start_date], "%m-%d-%Y").utc
#We want to filter from 11:59:59 in the local time zone,
#then convert to UTC to match databsae times
@end_date = (Time.strptime(@params[:end_date], "%m-%d-%Y") + 86399).utc

document.update_attributes(content_type: 'text/csv', original_filename: "#{@params[:title]}.csv")

Expand Down Expand Up @@ -51,9 +55,9 @@ def generate(document)
participant.label,
procedure.appointment.arm.name,
procedure.appointment.name,
format_date(procedure.completed_date),
format_date(procedure.incompleted_date),
format_date(procedure.follow_up? ? procedure.handled_date : nil),
format_date(procedure.completed_date.in_time_zone(@params[:time_zone])),
format_date(procedure.incompleted_date.nil? ? nil : procedure.incompleted_date.in_time_zone(@params[:time_zone])),
format_date(procedure.follow_up? ? procedure.handled_date.in_time_zone(@params[:time_zone]) : nil),
added_formatter(procedure),
procedure.service.organization.name,
procedure.service_name,
Expand Down Expand Up @@ -86,7 +90,7 @@ def reason_formatter(procedure)

def follow_up_formatter(procedure)
if procedure.follow_up_date
"Due Date: #{format_date(procedure.follow_up_date)} | Comment: #{procedure.task.body}"
"Due Date: #{format_date(procedure.follow_up_date.in_time_zone(@params[:time_zone]))} | Comment: #{procedure.task.body}"
end
end
end
14 changes: 9 additions & 5 deletions lib/reports/invoice_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@ class InvoiceReport < Report
require 'csv'

def generate(document)
@start_date = Time.strptime(@params[:start_date], "%m-%d-%Y").in_time_zone(@params[:time_zone])
@end_date = Time.strptime(@params[:end_date], "%m-%d-%Y").in_time_zone(@params[:time_zone])
#We want to filter from 00:00:00 in the local time zone,
#then convert to UTC to match database times
@start_date = Time.strptime(@params[:start_date], "%m-%d-%Y").utc
#We want to filter from 11:59:59 in the local time zone,
#then convert to UTC to match databsae times
@end_date = (Time.strptime(@params[:end_date], "%m-%d-%Y") + 86399).utc

document.update_attributes(content_type: 'text/csv', original_filename: "#{@params[:title]}.csv")

Expand Down Expand Up @@ -46,7 +50,7 @@ def generate(document)
protocol.sparc_id,
protocol.sparc_protocol.short_title,
protocol.pi ? protocol.pi.full_name : nil,
format_date(fulfillment.fulfilled_at),
format_date(fulfillment.fulfilled_at.in_time_zone(@params[:time_zone])),
fulfillment.service_name,
fulfillment.quantity,
fulfillment.line_item.account_number,
Expand Down Expand Up @@ -93,9 +97,9 @@ def generate(document)
participant.full_name,
participant.label,
appointment.name,
format_date(appointment.start_date),
format_date(appointment.start_date.in_time_zone(@params[:time_zone])),
procedure.service_name,
format_date(procedure.completed_date),
format_date(procedure.completed_date.in_time_zone(@params[:time_zone])),
service_procedures.size,
display_cost(procedure.service_cost),
display_cost(service_procedures.size * procedure.service_cost.to_f)
Expand Down
4 changes: 2 additions & 2 deletions lib/reports/project_summary_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ class ProjectSummaryReport < Report
require 'csv'

def generate(document)
@start_date = Time.strptime(@params[:start_date], "%m-%d-%Y").in_time_zone(@params[:time_zone])
@end_date = Time.strptime(@params[:end_date], "%m-%d-%Y").in_time_zone(@params[:time_zone])
@start_date = Time.strptime(@params[:start_date], "%m-%d-%Y")
@end_date = Time.strptime(@params[:end_date], "%m-%d-%Y")

document.update_attributes(content_type: 'text/csv', original_filename: "#{@params[:title]}.csv")

Expand Down

0 comments on commit a27c790

Please sign in to comment.