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 p1 #223

Merged
merged 7 commits into from
Nov 30, 2016
4 changes: 2 additions & 2 deletions app/views/documents/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@
%i.glyphicon.glyphicon-equalizer
Project Summary Report
.col-md-3
%button.btn-block.new_report.btn.btn-primary{ data: { type: "incomplete_visit_report" } }
%button.btn-block.new_report.btn.btn-primary{ data: { type: "visit_report" } }
%i.glyphicon.glyphicon-equalizer
Incomplete Visit Report
Visit Report
.row
.col-md-12
= render "documents"
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,23 @@
%button.close{type: 'button', data: {dismiss: 'modal'}}
%span{aria: {hidden:'true'}} ×
%span.sr-only= t(:actions)[:close]
%h4.modal-title.text-center= t(:reports)[:incomplete_visit_report]
%h4.modal-title.text-center= t(:reports)[:visit_report]
.modal-body
#modal_errors
.row
.col-md-12
= hidden_field_tag "report_type", report_type
.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"
=label_tag "title", t(:documents)[:title], class: "col-sm-4 control-label"
.col-sm-8= text_field_tag "title", title, class: "form-control"
.form-group
= label_tag "start_date", t(:reports)[:visit_start_date_from], class: "col-sm-4 control-label"
.col-sm-8
= text_field_tag "start_date", nil, class: "datepicker form-control", readonly: true
.form-group
= label_tag "end_date", t(:reports)[:visit_start_date_to], class: "col-sm-4 control-label"
.col-sm-8
= text_field_tag "end_date", nil, class: "datepicker form-control", readonly: true
.modal-footer
.center-block
%button.btn.btn-default{type: 'button', data: {dismiss: 'modal'}}= t(:actions)[:close]
Expand Down
4 changes: 3 additions & 1 deletion config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ en:
descending: "Descending"
invoice_report: "Invoice Report"
end_date: "End Date"
incomplete_visit_report: "Incomplete Visit Report"
visit_report: "Visit Report"
organization: "Organization(s)*"
page_title: "All Reports"
participant: "Participant"
Expand All @@ -354,6 +354,8 @@ en:
sort_by: "Sort By"
sort_order: "Sort Order"
start_date: "Start Date"
visit_start_date_from: "Visit Start Date From"
visit_start_date_to: "Visit Start Date To"

services:
object: "Service"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@

require 'csv'

class IncompleteVisitReport < Report
class VisitReport < Report
VALIDATES_PRESENCE_OF = [:title].freeze
VALIDATES_NUMERICALITY_OF = [].freeze

# db columns of interest; qualified because of ambiguities
START_DATE = '`appointments`.`start_date`'
END_DATE = '`appointments`.`completed_date`'
#END_DATE = '`appointments`.`completed_date`'
STATUS = '`procedures`.`status`'
PROTOCOL_ID = '`participants`.`protocol_id`'
LAST_NAME = '`participants`.`last_name`'
Expand All @@ -39,10 +39,14 @@ class IncompleteVisitReport < Report
def generate(document)
document.update_attributes(content_type: 'text/csv', original_filename: "#{@params[:title]}.csv")
_24_hours_ago = 24.hours.ago.utc

from_start_date = @params[:start_date].empty? ? Appointment.first.created_at.utc : Time.strptime(@params[:start_date], "%m/%d/%Y").utc
to_start_date = @params[:end_date].empty? ? Appointment.last.created_at.utc : Time.strptime(@params[:end_date], "%m/%d/%Y").tomorrow.utc - 1.second

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").
where("#{START_DATE} < ? AND #{START_DATE} > ? AND #{START_DATE} < ? AND #{STATUS} = ?", _24_hours_ago, from_start_date, to_start_date, "unstarted").
uniq.
pluck(PROTOCOL_ID, LAST_NAME, FIRST_NAME, VISIT_NAME, :start_date, :completed_date, :sparc_core_name)
get_protocol_srids(result_set)
Expand All @@ -57,7 +61,7 @@ def get_protocol_srids(result_set)
protocol_ids = result_set.map(&:first).uniq

# SRID's indexed by protocol id
@srid = Hash[Protocol.includes(:sub_service_request).
@srid = Hash[ Protocol.includes(:sub_service_request).
select(:id, :sparc_id, :sub_service_request_id). # cols necessary for SRID
where(id: protocol_ids).
map { |protocol| [protocol.id, protocol.srid] }]
Expand Down