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 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
3 changes: 0 additions & 3 deletions app/assets/javascripts/associated_users.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@
# 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.
$(document).ready ->
getSRId = () ->
$('input[name="service_request_id"]').val()

$(document).on 'click', '#new-associated-user-button', ->
$.ajax
type: 'get'
Expand Down
3 changes: 0 additions & 3 deletions app/assets/javascripts/catalog.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@
#= require cart

$(document).ready ->
getSRId = () ->
$('input[name="service_request_id"]').val()

### ACCORDION LOGIC ###
$(document).on 'click', '.institution-header, .provider-header, .program-link:not(.locked-program)', ->
if $(this).hasClass('institution-header')
Expand Down
1 change: 1 addition & 0 deletions app/assets/javascripts/dashboard/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
//= require_tree .

//= require ../service_calendar
//= require ../global
//= require global
//= require associated_users_form
//= require study_schedule_tabs
Expand Down
3 changes: 0 additions & 3 deletions app/assets/javascripts/dashboard/documents.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@
# 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.

$ ->
getSRId = ->
$("input[name='service_request_id']").val()

# DOCUMENTS LISTENERS BEGIN

$(document).on 'click', '#document-new', ->
Expand Down
3 changes: 0 additions & 3 deletions app/assets/javascripts/dashboard/protocols.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@
$(document).ready ->
Sparc.protocol =
ready: ->
getSRId = () ->
$('input[name="service_request_id"]').val()

# Protocol Index Begin
$(document).on 'click', '.protocols_index_row > .id, .protocols_index_row > .title, .protocols_index_row > .pis', ->
#if you click on the row, it opens the protocol show
Expand Down
3 changes: 0 additions & 3 deletions app/assets/javascripts/document_management.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@
#= require cart

$(document).ready ->
getSRId = ->
$("input[name='service_request_id']").val()

$(document).on 'click', '#document-new', ->
data =
protocol_id: $(this).data('protocol-id')
Expand Down
6 changes: 6 additions & 0 deletions app/assets/javascripts/global.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ $ ->
$(document).ajaxComplete ->
$('[data-toggle="tooltip"]').tooltip()

(exports ? this).getSRId = ->
$("input[name='service_request_id']").val()

(exports ? this).getSSRId = ->
$("input[name='sub_service_request_id']").val()

(exports ? this).formatMoney = (n, t=',', d='.', c='$') ->
s = if n < 0 then "-#{c}" else c
i = Math.abs(n).toFixed(2)
Expand Down
64 changes: 17 additions & 47 deletions app/assets/javascripts/service_calendar.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,6 @@
#= require navigation

$(document).ready ->

getSRId = ->
$("input[name='service_request_id']").val()

getSSRId = ->
$("input[name='sub_service_request_id']").val()

freezeHeader = (arm_container) ->
$(arm_container).each ->
$(this).find('table').addClass('scrolling-table')
Expand Down Expand Up @@ -241,9 +234,6 @@ $(document).ready ->
data: data
# NOTES LISTENERS END

getSRId = ->
$("input[name='service_request_id']").val()

(exports ? this).setup_xeditable_fields = (scroll) ->
reload_calendar = (arm_id, scroll) ->
# E.g. "billing-strategy-tab" -> "billing_strategy"
Expand Down Expand Up @@ -271,40 +261,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 @@ -325,10 +281,24 @@ getSRId = ->
line_items_visit:
subject_count: params.value
service_request_id: getSRId()
sub_service_request_id: getSSRId()
}
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'])

if data['ssr_header']
# Replace Admin Dashboard SSR header
$('#sub_service_request_header').html(data['ssr_header'])
$('.selectpicker').selectpicker()

$('.edit-qty').editable
params: (params) ->
Expand Down
3 changes: 0 additions & 3 deletions app/assets/javascripts/service_details.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@
#= require cart

$(document).ready ->
getSRId = ->
$("input[name='service_request_id']").val()

$(document).on 'click', '#new-arm-button', ->
$.ajax
type: 'get'
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.

85 changes: 85 additions & 0 deletions app/controllers/line_items_visits_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# 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]
portal = params[:portal] == 'true'
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 portal
line_items_visit.sub_service_request.update_attribute(:status, 'draft')
@service_request.update_attribute(:status, 'draft')
end

data = {
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
}

data[:ssr_header] = render_to_string(partial: 'dashboard/sub_service_requests/header', locals: { sub_service_request: @sub_service_request }) if portal

render json: data
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
end