-
Notifications
You must be signed in to change notification settings - Fork 26
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
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
2824f79
optimize lineitemsvisitscontroller#update
3b27867
remove duplicate methods [#148344231]
bcc8c91
refresh ssr header / globalize getSRId/SSRId methods [#148344231]
38504b3
Merge branch 'master' into kg-calendar_optimization_pt_4
3dba51b
merge conflicts
54cf706
fix condition to render ssr header [#148344231]
987e5b9
added controller specs [#148344231]
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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? | ||
(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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
app/views/service_calendars/master_calendar/pppv/_subject_count.html.haml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) } } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.