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

KG - Step 2B: Calendar Query and Rendering Need Improvement Part 4 - Subject Count #966

Merged
merged 7 commits into from
Jul 13, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
48 changes: 11 additions & 37 deletions app/assets/javascripts/service_calendar.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -231,40 +231,6 @@ getSRId = ->
error_msgs.push(humanize_string(attr)+err)
return error_msgs.join("\n")

$('.window-before').editable
params: (params) ->
{
visit_group:
window_before: params.value
service_request_id: getSRId()
}

$('.day').editable
params: (params) ->
{
visit_group:
day: params.value
service_request_id: getSRId()
}
emptytext: '(?)'

$('.window-after').editable
params: (params) ->
{
visit_group:
window_after: params.value
service_request_id: getSRId()
}

$('.visit-group-name').editable
params: (params) ->
{
visit_group:
name: params.value
service_request_id: getSRId()
}
emptytext: '(?)'

$('.edit-your-cost').editable
display: (value) ->
# display field as currency, edit as quantity
Expand All @@ -286,9 +252,17 @@ getSRId = ->
subject_count: params.value
service_request_id: getSRId()
}
success: () ->
scroll = $(this).parents('.scrolling-div').length > 0
reload_calendar($(this).data('armId'), scroll)
success: (data) ->
arm_id = $(this).data('arm-id')

# Replace Per Patient / Study Totals
$(this).parent().siblings('.pppv-per-patient-line-item-total').replaceWith(data['total_per_patient'])
$(this).parent().siblings('.pppv-per-study-line-item-total').replaceWith(data['total_per_study'])

# Replace Totals
$(".arm-#{arm_id}.maximum-total-direct-cost-per-patient").replaceWith(data['max_total_direct'])
$(".arm-#{arm_id}.maximum-total-per-patient").replaceWith(data['max_total_per_patient'])
$(".arm-#{arm_id}.total-per-patient-per-visit-cost-per-study").replaceWith(data['total_costs'])

$('.edit-qty').editable
params: (params) ->
Expand Down
37 changes: 37 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,43 @@ def authorize_site_admin
end
end

def in_dashboard?
(params[:portal] && params[:portal] == 'true') || (params[:admin] && params[:admin] == 'true')
end

def authorize_dashboard_access
if params[:sub_service_request_id]
authorize_admin
else
if params[:service_request_id]
@service_request = ServiceRequest.find(params[:service_request_id])
end
authorize_protocol
end
end

def authorize_protocol
@protocol = @service_request ? @service_request.protocol : Protocol.find(params[:protocol_id])
permission_to_view = current_user.can_view_protocol?(@protocol)

unless permission_to_view || Protocol.for_admin(current_user.id).include?(@protocol)
@protocol = nil

render partial: 'service_requests/authorization_error', locals: { error: 'You are not allowed to access this Sub Service Request.' }
end
end

def authorize_admin
@sub_service_request = SubServiceRequest.find(params[:sub_service_request_id])
@service_request = @sub_service_request.service_request

unless (current_user.authorized_admin_organizations & @sub_service_request.org_tree).any?
@sub_service_request = nil
@service_request = nil
render partial: 'service_requests/authorization_error', locals: { error: 'You are not allowed to access this Sub Service Request.' }
end
end

def find_locked_org_ids
@locked_org_ids = []
if @service_request.protocol.present?
Expand Down
68 changes: 0 additions & 68 deletions app/controllers/dashboard/line_items_visits_controller.rb

This file was deleted.

118 changes: 118 additions & 0 deletions app/controllers/line_items_visits_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
# Copyright © 2011-2016 MUSC Foundation for Research Development
# All rights reserved.

# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

# 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

# 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
# disclaimer in the documentation and/or other materials provided with the distribution.

# 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products
# derived from this software without specific prior written permission.

# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
# BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
# SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

class LineItemsVisitsController < ApplicationController
respond_to :json, :js, :html

before_action :initialize_service_request, unless: :in_dashboard?
before_action :authorize_identity, unless: :in_dashboard?
before_action :authorize_dashboard_access, if: :in_dashboard?

# Used for x-editable update and validations
def update
page = params[:page]
tab = params[:tab]
line_items_visit = LineItemsVisit.find(params[:id])
arm = line_items_visit.arm
line_items_visits = arm.line_items_visits.eager_load(line_item: [:admin_rates, service: [:pricing_maps, organization: [:pricing_setups, parent: [:pricing_setups, parent: [:pricing_setups, parent: :pricing_setups]]]], service_request: :protocol])
visit_groups = arm.visit_groups.paginate(page: page.to_i, per_page: VisitGroup.per_page).eager_load(visits: { line_items_visit: { line_item: [:admin_rates, service: [:pricing_maps, organization: [:pricing_setups, parent: [:pricing_setups, parent: [:pricing_setups, parent: :pricing_setups]]]], service_request: :protocol] } })

if line_items_visit.update_attributes(line_items_visit_params)
unless params[:portal] == 'true'
line_items_visit.sub_service_request.update_attribute(:status, 'draft')
@service_request.update_attribute(:status, 'draft')
end
render json: {
total_per_patient: render_to_string(partial: 'service_calendars/master_calendar/pppv/total_per_patient', locals: { liv: line_items_visit }),
total_per_study: render_to_string(partial: 'service_calendars/master_calendar/pppv/total_per_study', locals: { liv: line_items_visit }),
max_total_direct: render_to_string(partial: 'service_calendars/master_calendar/pppv/totals/max_total_direct_per_patient', locals: { arm: arm, visit_groups: visit_groups, line_items_visits: line_items_visits, tab: tab, page: page }),
max_total_per_patient: render_to_string(partial: 'service_calendars/master_calendar/pppv/totals/max_total_per_patient', locals: { arm: arm, visit_groups: visit_groups, line_items_visits: line_items_visits, tab: tab, page: page }),
total_costs: render_to_string(partial: 'service_calendars/master_calendar/pppv/totals/total_cost_per_study', locals: { arm: arm, line_items_visits: line_items_visits, tab: tab }),
success: true
}
else
render json: line_items_visit.errors, status: :unprocessable_entity
end

end

def destroy
@line_items_visit = LineItemsVisit.find(params[:id])
@sub_service_request = @line_items_visit.line_item.sub_service_request
@service_request = @sub_service_request.service_request
@selected_arm = @service_request.arms.first
line_item = @line_items_visit.line_item
@line_items = @sub_service_request.line_items

ActiveRecord::Base.transaction do
if @line_items_visit.destroy
line_item.destroy unless line_item.line_items_visits.count > 0
# Have to reload the service request to get the correct direct cost total for the subsidy
@service_request = @sub_service_request.service_request
render 'dashboard/sub_service_requests/add_line_item'
end
end
end

private

def line_items_visit_params
params.require(:line_items_visit).permit(:subject_count)
end

private

def in_dashboard?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You already have these methods in ApplicationController. They should be available since you are inheriting from that controller.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wtholt Good catch. I meant to remove these.

(params[:portal] && params[:portal] == 'true') || (params[:admin] && params[:admin] == 'true')
end

def authorize_dashboard_access
if params[:sub_service_request_id]
authorize_admin
else
if params[:service_request_id]
@service_request = ServiceRequest.find(params[:service_request_id])
end
authorize_protocol
end
end

def authorize_protocol
@protocol = @service_request ? @service_request.protocol : Protocol.find(params[:protocol_id])
permission_to_view = current_user.can_view_protocol?(@protocol)

unless permission_to_view || Protocol.for_admin(current_user.id).include?(@protocol)
@protocol = nil

render partial: 'service_requests/authorization_error', locals: { error: 'You are not allowed to access this Sub Service Request.' }
end
end

def authorize_admin
@sub_service_request = SubServiceRequest.find(params[:sub_service_request_id])
@service_request = @sub_service_request.service_request

unless (current_user.authorized_admin_organizations & @sub_service_request.org_tree).any?
@sub_service_request = nil
@service_request = nil
render partial: 'service_requests/authorization_error', locals: { error: 'You are not allowed to access this Sub Service Request.' }
end
end
end
37 changes: 0 additions & 37 deletions app/controllers/service_calendars_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -209,43 +209,6 @@ def toggle_calendar_column

private

def in_dashboard?
(params[:portal] && params[:portal] == 'true') || (params[:admin] && params[:admin] == 'true')
end

def authorize_dashboard_access
if params[:sub_service_request_id]
authorize_admin
else
if params[:service_request_id]
@service_request = ServiceRequest.find(params[:service_request_id])
end
authorize_protocol
end
end

def authorize_protocol
@protocol = @service_request ? @service_request.protocol : Protocol.find(params[:protocol_id])
permission_to_view = current_user.can_view_protocol?(@protocol)

unless permission_to_view || Protocol.for_admin(current_user.id).include?(@protocol)
@protocol = nil

render partial: 'service_requests/authorization_error', locals: { error: 'You are not allowed to access this Sub Service Request.' }
end
end

def authorize_admin
@sub_service_request = SubServiceRequest.find(params[:sub_service_request_id])
@service_request = @sub_service_request.service_request

unless (current_user.authorized_admin_organizations & @sub_service_request.org_tree).any?
@sub_service_request = nil
@service_request = nil
render partial: 'service_requests/authorization_error', locals: { error: 'You are not allowed to access this Sub Service Request.' }
end
end

def setup_calendar_pages
@pages = {}
page = params[:page] if params[:page]
Expand Down
17 changes: 3 additions & 14 deletions app/controllers/visits_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
class VisitsController < ApplicationController
respond_to :json, :js, :html

before_action :initialize_service_request, if: Proc.new{ params[:admin] != 'true' }
before_action :authorize_identity, if: Proc.new { params[:admin] != 'true' }
before_action :authorize_admin, if: Proc.new { params[:admin] == 'true' }
before_action :initialize_service_request, unless: :in_dashboard?
before_action :authorize_identity, unless: :in_dashboard?
before_action :authorize_admin, if: :in_dashboard?

def edit
@visit = Visit.find(params[:id])
Expand Down Expand Up @@ -89,15 +89,4 @@ def visit_params
:insurance_billing_qty,
:effort_billing_qty)
end

def authorize_admin
@sub_service_request = SubServiceRequest.find(params[:sub_service_request_id])
@service_request = @sub_service_request.service_request

unless (current_user.authorized_admin_organizations & @sub_service_request.org_tree).any?
@sub_service_request = nil
@service_request = nil
render partial: 'service_requests/authorization_error', locals: { error: 'You are not allowed to access this Sub Service Request.' }
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
-# Copyright © 2011 MUSC Foundation for Research Development
-# All rights reserved.

-# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

-# 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

-# 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
-# disclaimer in the documentation and/or other materials provided with the distribution.

-# 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products
-# derived from this software without specific prior written permission.

-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
-# BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
-# SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
-# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
%td.subject-count.text-center.xs-col-width
- if locked
= liv.subject_count
- else
%a.edit-subject-count{ href: 'javascript:void(0)', data: { arm_id: arm.id, name: 'subject_count', title: t(:calendars)[:pppv][:editable_fields][:subject_count], value: liv.subject_count, url: line_items_visit_path(liv, page: page.to_s, tab: tab, portal: portal) } }