Skip to content

Commit

Permalink
Merge pull request #133 from sparc-request/kg-report_date_time_zone
Browse files Browse the repository at this point in the history
KG - Report Date Time Zone Incomplete Visit Report
  • Loading branch information
amcates committed Feb 11, 2016
2 parents e4a62ed + a2a7b5d commit 9460f31
Show file tree
Hide file tree
Showing 14 changed files with 27 additions and 29 deletions.
1 change: 0 additions & 1 deletion app/controllers/reports_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ class ReportsController < ApplicationController

def new
@title = @report_type.titleize
@time_zone = current_identity.time_zone
end

def create
Expand Down
6 changes: 3 additions & 3 deletions app/models/fulfillment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ class Fulfillment < ActiveRecord::Base
after_create :update_line_item_name

scope :fulfilled_in_date_range, ->(start_date, end_date) {
where("fulfilled_at is not NULL AND DATE(fulfilled_at) between ? AND ?", start_date.to_date, end_date.to_date)}
where("fulfilled_at is not NULL AND fulfilled_at between ? AND ?", start_date, end_date)}

def fulfilled_at=(date)
write_attribute(:fulfilled_at, Time.strptime(date, "%m-%d-%Y")) if date.present?
def fulfilled_at=(date_time)
write_attribute(:fulfilled_at, Time.strptime(date_time, "%m-%d-%Y")) if date_time.present?
end

def total_cost
Expand Down
2 changes: 1 addition & 1 deletion app/models/procedure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class Procedure < ActiveRecord::Base
# select Procedures that belong to an Appointment without a start date
scope :belonging_to_unbegun_appt, -> { joins(:appointment).where('appointments.start_date IS NULL') }
scope :completed_r_in_date_range, ->(start_date, end_date) {
where("procedures.completed_date is not NULL AND DATE(procedures.completed_date) between ? AND ? AND billing_type = ?", start_date.to_date, end_date.to_date, "research_billing_qty")}
where("procedures.completed_date is not NULL AND procedures.completed_date between ? AND ? AND billing_type = ?", start_date, end_date, "research_billing_qty")}

def self.billing_display
[["R", "research_billing_qty"],
Expand Down
4 changes: 2 additions & 2 deletions app/views/documents/_documents.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
= t(:actions)[:edit]
%th{data: {class: 'title', align: 'center', sortable: "true", field: 'title'}}
= t(:documents)[:title]
%th{data: {class: 'created_at', align: 'center', sortable: "true", field: 'created_at'}}
%th{data: {class: 'created_at', align: 'center', sortable: "true", sorter: "dateSorter", field: 'created_at'}}
= t(:documents)[:date_created]
%th{data: {class: 'viewed_at', align: 'center', sortable: "true", field: 'viewed_at'}}
%th{data: {class: 'viewed_at', align: 'center', sortable: "true", sorter: "dateSorter", field: 'viewed_at'}}
= t(:documents)[:viewed_at]
%th{data: {class: 'state', align: 'center', field: 'state'}}
= t(:documents)[:state]
Expand Down
1 change: 0 additions & 1 deletion app/views/reports/_auditing_report.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
.row
.col-md-12
= hidden_field_tag "report_type", report_type
= hidden_field_tag "time_zone", time_zone
.form-group
=label_tag "title", t(:documents)[:title], class: "col-sm-3 control-label"
.col-sm-9= text_field_tag "title", title, class: "form-control"
Expand Down
1 change: 0 additions & 1 deletion app/views/reports/_invoice_report.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
.row
.col-md-12
= hidden_field_tag "report_type", report_type
= hidden_field_tag "time_zone", time_zone
.form-group
= label_tag "title", t(:documents)[:title], class: "col-sm-3 control-label"
.col-sm-9
Expand Down
1 change: 0 additions & 1 deletion app/views/reports/_project_summary_report.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
.row
.col-md-12
= hidden_field_tag "report_type", report_type
= hidden_field_tag "time_zone", time_zone
.form-group
=label_tag "title", t(:documents)[:title], class: "col-sm-3 control-label"
.col-sm-9= text_field_tag "title", title, class: "form-control"
Expand Down
2 changes: 1 addition & 1 deletion app/views/reports/new.js.coffee
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
$("#modal_area").html("<%= escape_javascript(render(partial: @report_type, locals: { title: @title, report_type: @report_type, time_zone: @time_zone })) %>")
$("#modal_area").html("<%= escape_javascript(render(partial: @report_type, locals: { title: @title, report_type: @report_type })) %>")
$("#modal_place").modal('show')
$('#start_date').datetimepicker(format: 'MM-DD-YYYY')
$('#end_date').datetimepicker(format: 'MM-DD-YYYY')
Expand Down
1 change: 1 addition & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class Application < Rails::Application
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
# config.i18n.default_locale = :de
config.time_zone = ENV['APPLICATION_TIME_ZONE']

config.paths.add File.join('app', 'jobs'), glob: File.join('**', '*.rb')
config.autoload_paths += Dir[Rails.root.join('app', 'jobs', '*')]
Expand Down
1 change: 1 addition & 0 deletions dotenv.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ SPARC_API_HOST=localhost:5000
SPARC_API_VERSION=v1
SPARC_API_USERNAME=iyqu2bm3T4rDWWpnwYfEl2i6o2Sphpuq_TKvFnIOTA0
SPARC_API_PASSWORD=qL1oZmdMi7OU7G1f0q6aCTVR6HrmoNmpZVNc8DfHqek
APPLICATION_TIME_ZONE=Eastern Time (US & Canada)
FAYE_REFRESH_INTERVAL=25
FAYE_TOKEN=3bd16424a2154769a1fb4adc081b10747bdbfdbd93682032
CWF_FAYE_HOST=localhost:9292
Expand Down
12 changes: 6 additions & 6 deletions lib/reports/auditing_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ def generate(document)
#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
#then convert to UTC to match database times
@end_date = Time.strptime(@params[:end_date], "%m-%d-%Y").tomorrow.utc - 1.second

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

Expand Down Expand Up @@ -55,9 +55,9 @@ def generate(document)
participant.label,
procedure.appointment.arm.name,
procedure.appointment.name,
format_date(procedure.completed_date.nil? ? nil : 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),
format_date(procedure.completed_date.nil? ? nil : procedure.completed_date),
format_date(procedure.incompleted_date.nil? ? nil : procedure.incompleted_date),
format_date(procedure.follow_up? ? procedure.handled_date : nil),
added_formatter(procedure),
procedure.service.organization.name,
procedure.service_name,
Expand Down Expand Up @@ -90,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.in_time_zone(@params[:time_zone]))} | Comment: #{procedure.task.body}"
"Due Date: #{format_date(procedure.follow_up_date)} | Comment: #{procedure.task.body}"
end
end
end
6 changes: 1 addition & 5 deletions lib/reports/incomplete_visit_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class IncompleteVisitReport < Report

def generate(document)
document.update_attributes(content_type: 'text/csv', original_filename: "#{@params[:title]}.csv")
_24_hours_ago = DateTime.now.ago(24*60*60)
_24_hours_ago = 24.hours.ago.utc

CSV.open(document.path, "wb") do |csv|
csv << REPORT_COLUMNS
Expand Down Expand Up @@ -46,10 +46,6 @@ def get_protocol_srids(result_set)
map { |protocol| [protocol.id, protocol.srid] }]
end

def format_date(dt)
dt.strftime('%m/%d/%Y')
end

def core_list(y)
y.map(&:last).join(', ')
end
Expand Down
10 changes: 5 additions & 5 deletions lib/reports/invoice_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ def generate(document)
#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
#then convert to UTC to match database times
@end_date = Time.strptime(@params[:end_date], "%m-%d-%Y").tomorrow.utc - 1.second

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

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

def generate(document)
@start_date = Time.strptime(@params[:start_date], "%m-%d-%Y")
@end_date = Time.strptime(@params[:end_date], "%m-%d-%Y")
#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 database times
@end_date = Time.strptime(@params[:end_date], "%m-%d-%Y").tomorrow.utc - 1.second

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

Expand Down

0 comments on commit 9460f31

Please sign in to comment.