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

Jw attachement for service provider #621

Merged
merged 8 commits into from
Aug 16, 2016
Merged
Show file tree
Hide file tree
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
56 changes: 39 additions & 17 deletions app/controllers/service_requests_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -306,14 +306,12 @@ def send_confirmation_notifications to_notify
send_notifications(@service_request, @sub_service_request)
elsif @sub_service_request
if to_notify.include? @sub_service_request.id
xls = render_to_string action: 'show', formats: [:xlsx]
send_ssr_service_provider_notifications(@service_request, @sub_service_request, xls)
send_ssr_service_provider_notifications(@service_request, @sub_service_request)
end
else
xls = render_to_string action: 'show', formats: [:xlsx]
@service_request.sub_service_requests.each do |ssr|
if to_notify.include? ssr.id
send_ssr_service_provider_notifications(@service_request, ssr, xls)
send_ssr_service_provider_notifications(@service_request, ssr)
end
end
end
Expand Down Expand Up @@ -439,8 +437,7 @@ def remove_service
ssr = @service_request.sub_service_requests.find_by_organization_id(org_id)
if !['first_draft', 'draft'].include?(@service_request.status) and !@service_request.submitted_at.nil? and @service_request.submitted_at > ssr.created_at
@protocol = @service_request.protocol
xls = @protocol.nil? ? nil : render_to_string(action: 'show', formats: [:xlsx])
send_ssr_service_provider_notifications(@service_request, ssr, xls, ssr_deleted=true)
send_ssr_service_provider_notifications(@service_request, ssr, ssr_deleted=true)
end
ssr.destroy
end
Expand Down Expand Up @@ -498,21 +495,26 @@ def new_document

# Send notifications to all users.
def send_notifications(service_request, sub_service_request)
xls = render_to_string action: 'show', formats: [:xlsx]
send_user_notifications(service_request, xls)
send_user_notifications(service_request)

if sub_service_request then
sub_service_requests = [ sub_service_request ]
else
sub_service_requests = service_request.sub_service_requests
end
send_admin_notifications(service_request, sub_service_requests, xls)
send_service_provider_notifications(service_request, sub_service_requests, xls)
send_admin_notifications(service_request, sub_service_requests)
send_service_provider_notifications(service_request, sub_service_requests)
end

def send_user_notifications(service_request, xls)
def send_user_notifications(service_request)
# Does an approval need to be created? Check that the user
# submitting has approve rights.
@service_list_false = service_request.service_list(false)
@service_list_true = service_request.service_list(true)
@line_items = @service_request.line_items

xls = render_to_string action: 'show', formats: [:xlsx]

if service_request.protocol.project_roles.detect{|pr| pr.identity_id == current_user.id}.project_rights != "approve"
approval = service_request.approvals.create
else
Expand All @@ -526,26 +528,32 @@ def send_user_notifications(service_request, xls)
end
end

def send_service_provider_notifications(service_request, sub_service_requests, xls) #all sub-service requests on service request
def send_service_provider_notifications(service_request, sub_service_requests) #all sub-service requests on service request
sub_service_requests.each do |sub_service_request|
send_ssr_service_provider_notifications(service_request, sub_service_request, xls)
send_ssr_service_provider_notifications(service_request, sub_service_request)
end
end

def send_admin_notifications(service_request, sub_service_requests, xls)
def send_admin_notifications(service_request, sub_service_requests)
@service_list_false = service_request.service_list(false)
@service_list_true = service_request.service_list(true)
@line_items = @service_request.line_items

xls = render_to_string action: 'show', formats: [:xlsx]

sub_service_requests.each do |sub_service_request|
sub_service_request.organization.submission_emails_lookup.each do |submission_email|
Notifier.notify_admin(service_request, submission_email.email, xls, current_user).deliver
end
end
end

def send_ssr_service_provider_notifications(service_request, sub_service_request, xls, ssr_deleted=false) #single sub-service request
def send_ssr_service_provider_notifications(service_request, sub_service_request, ssr_deleted=false) #single sub-service request
previously_submitted_at = service_request.previous_submitted_at.nil? ? Time.now.utc : service_request.previous_submitted_at.utc
audit_report = sub_service_request.audit_report(current_user, previously_submitted_at, Time.now.utc)

sub_service_request.organization.service_providers.where("(`service_providers`.`hold_emails` != 1 OR `service_providers`.`hold_emails` IS NULL)").each do |service_provider|
send_individual_service_provider_notification(service_request, sub_service_request, service_provider, xls, audit_report, ssr_deleted)
send_individual_service_provider_notification(service_request, sub_service_request, service_provider, audit_report, ssr_deleted)
end
end

Expand All @@ -566,8 +574,22 @@ def service_request_has_changed_ssr?(service_request) #any ssr on sr has changed
return false
end

def send_individual_service_provider_notification(service_request, sub_service_request, service_provider, xls, audit_report=nil, ssr_deleted=false)
def send_individual_service_provider_notification(service_request, sub_service_request, service_provider, audit_report=nil, ssr_deleted=false)
attachments = {}

@service_list_true = @service_request.service_list(true, service_provider)
@service_list_false = @service_request.service_list(false, service_provider)

# Retrieves the valid line items for service provider to calculate total direct cost in the xls
line_items = []
@service_request.sub_service_requests.each do |ssr|
if service_provider.identity.is_service_provider?(ssr)
line_items << SubServiceRequest.find(ssr).line_items
end
end

@line_items = line_items.flatten
xls = render_to_string action: 'show', formats: [:xlsx]
attachments["service_request_#{service_request.id}.xlsx"] = xls

#TODO this is not very multi-institutional
Expand Down
17 changes: 16 additions & 1 deletion app/models/service_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ def set_visit_page page_passed, arm
page
end

def service_list is_one_time_fee=nil
def service_list(is_one_time_fee=nil, service_provider=nil)
items = []
case is_one_time_fee
when nil
Expand All @@ -353,6 +353,10 @@ def service_list is_one_time_fee=nil
items = per_patient_per_visit_line_items
end

if service_provider
items = service_provider_line_items(service_provider, items)
end

groupings = {}
items.each do |line_item|
service = line_item.service
Expand Down Expand Up @@ -390,6 +394,17 @@ def service_list is_one_time_fee=nil
groupings
end

# Returns the line items that a service provider is associated with
def service_provider_line_items(service_provider, items)
service_provider_items = []
items.map(&:sub_service_request_id).each do |ssr|
if service_provider.identity.is_service_provider?(SubServiceRequest.find(ssr))
service_provider_items << SubServiceRequest.find(ssr).line_items
end
end
service_provider_items.flatten.uniq
end

def has_one_time_fee_services?
one_time_fee_line_items.count > 0
end
Expand Down
16 changes: 10 additions & 6 deletions app/views/service_requests/show.xlsx.axlsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ wb.add_worksheet(name: "Review") do |sheet|
sheet.add_row ["Authorized Users"], :style => header_style
proxy_row = ["Name", "Role", "", "Proxy Rights"]

has_per_patient_per_visit_services = @sub_service_request.nil? ? @service_request.has_per_patient_per_visit_services? : @sub_service_request.has_per_patient_per_visit_services?
has_per_patient_per_visit_services = @sub_service_request.nil? ? (!@service_list_false.empty? && @service_request.has_per_patient_per_visit_services?) : (!@service_list_false.empty? && @sub_service_request.has_per_patient_per_visit_services?)

visit_count = 0
if has_per_patient_per_visit_services
Expand Down Expand Up @@ -132,7 +132,7 @@ wb.add_worksheet(name: "Review") do |sheet|

sheet.add_row(r_t_row, :style => centered)

@service_request.service_list(false).each do |key, value|
@service_list_false.each do |key, value|
next unless @sub_service_request.nil? or @sub_service_request.organization.name == value[:process_ssr_organization_name]
services_sub_header_rows << sheet.add_row([value[:name]], :style => sub_header_style)

Expand Down Expand Up @@ -199,23 +199,26 @@ wb.add_worksheet(name: "Review") do |sheet|
service_rows = []
services_sub_header_rows = []
services_sub_header_rows << sheet.add_row(['Other Services'], :style => name_header_style)
@service_request.service_list(true).each do |key, value|
@service_list_true.each do |key, value|
next unless @sub_service_request.nil? or @sub_service_request.organization.name == value[:process_ssr_organization_name]
services_sub_header_rows << sheet.add_row([value[:name]], :style => sub_header_style)

value[:line_items].each do |line_item|
service_row = [line_item.service.name, ""]
line_item_total = display_one_time_fee_direct_cost(line_item)

if @admin_offset
line_item.pricing_scheme = 'effective'
line_item_total = display_one_time_fee_direct_cost(line_item)
service_row << display_your_cost(line_item)
line_item.pricing_scheme = 'displayed'
end

service_row += [display_your_cost(line_item), ""]

if !@service_list_true.empty? && !@service_list_false.empty?
service_row += [display_your_cost(line_item), ""]
else
service_row += [display_your_cost(line_item), "", ""]
end

if has_per_patient_per_visit_services
(visit_count*2 + 1).times do
service_row << ''
Expand All @@ -226,6 +229,7 @@ wb.add_worksheet(name: "Review") do |sheet|
service_rows << sheet.add_row(service_row, :style => default)
end
end

merge_service_rows << service_rows
merge_sub_header_rows << services_sub_header_rows

Expand Down
1 change: 1 addition & 0 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,7 @@
t.integer "changed_by_id", limit: 4
end

add_index "past_statuses", ["changed_by_id"], name: "index_past_statuses_on_changed_by_id", using: :btree
add_index "past_statuses", ["sub_service_request_id"], name: "index_past_statuses_on_sub_service_request_id", using: :btree

create_table "past_subsidies", force: :cascade do |t|
Expand Down