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

Jtm visit report change #210

Merged
merged 3 commits into from
Sep 19, 2016
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
11 changes: 4 additions & 7 deletions lib/reports/incomplete_visit_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,28 @@ class IncompleteVisitReport < Report

# db columns of interest; qualified because of ambiguities
START_DATE = '`appointments`.`start_date`'
END_DATE = '`appointments`.`completed_date`'
STATUS = '`procedures`.`status`'
PROTOCOL_ID = '`participants`.`protocol_id`'
LAST_NAME = '`participants`.`last_name`'
FIRST_NAME = '`participants`.`first_name`'
VISIT_NAME = :name

# report columns
REPORT_COLUMNS = ["Protocol ID (SRID)", "Patient Last Name", "Patient First Name", "Visit Name", "Start Date", "List of Cores which have incomplete visits"]
REPORT_COLUMNS = ["Protocol ID (SRID)", "Patient Last Name", "Patient First Name", "Visit Name", "Start Date", "End Date", "List of Cores which have incomplete visits"]

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

CSV.open(document.path, "wb") do |csv|
csv << REPORT_COLUMNS

result_set = Appointment.all.joins(:procedures).joins(:participant).joins(:visit_group).
where("#{START_DATE} < ? AND #{STATUS} = ?", _24_hours_ago, "unstarted").
uniq.
pluck(PROTOCOL_ID, LAST_NAME, FIRST_NAME, VISIT_NAME, :start_date, :sparc_core_name)

pluck(PROTOCOL_ID, LAST_NAME, FIRST_NAME, VISIT_NAME, :start_date, :completed_date, :sparc_core_name)
get_protocol_srids(result_set)

result_set.group_by { |x| x[0..3] }.
map { |x, y| [ @srid[x[0]] ] + x[1..3] << format_date(y[0][4]) << core_list(y) }.
map { |x, y| [ @srid[x[0]] ] + x[1..3] << format_date(y[0][4]) << (y[0][5].nil? ? "N/A" : format_date(y[0][5])) << core_list(y) }.
sort { |x, y| x <=> y || 1 }. # by default, sort won't handle nils
each { |x| csv << x }
end
Expand Down