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

Sj epic queue changes #737

Merged
merged 4 commits into from
Nov 21, 2016
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 2 additions & 2 deletions app/controllers/dashboard/sub_service_requests_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def show
cookies['admin-tab'] = 'details-tab' unless cookies['admin-tab']
session[:service_calendar_pages] = params[:pages] if params[:pages]
session[:breadcrumbs].add_crumbs(protocol_id: @sub_service_request.protocol.id, sub_service_request_id: @sub_service_request.id).clear(:notifications)

@service_request = @sub_service_request.service_request
@protocol = @sub_service_request.protocol

Expand Down Expand Up @@ -132,7 +132,7 @@ def refresh_service_calendar

def push_to_epic
begin
@sub_service_request.service_request.protocol.push_to_epic(EPIC_INTERFACE)
@sub_service_request.service_request.protocol.push_to_epic(EPIC_INTERFACE, "admin_push", current_user.id)
flash[:success] = 'Request Pushed to Epic!'
rescue
flash[:alert] = $!.message
Expand Down
10 changes: 5 additions & 5 deletions app/controllers/portal/sub_service_requests_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Portal::SubServiceRequestsController < Portal::BaseController
respond_to :json, :js, :html

before_filter :protocol_authorizer, :only => [:update_from_project_study_information]

def show
@sub_service_request = SubServiceRequest.find(params[:id])
@admin = true
Expand Down Expand Up @@ -99,11 +99,11 @@ def update_from_project_study_information
unless @protocol.errors.messages[:sponsor_name].nil?
@protocol.errors.messages[:sponsor_name].uniq!
end

render action: 'show'

end
end
end

def add_note
@sub_service_request = SubServiceRequest.find(params[:id])
Expand Down Expand Up @@ -177,7 +177,7 @@ def add_otf_line_item

@study_tracker = params[:study_tracker] == "true"
@line_items = @sub_service_request.line_items

if @sub_service_request.create_line_item(
service_id: params[:new_service_id],
sub_service_request_id: params[:sub_service_request_id])
Expand Down Expand Up @@ -282,7 +282,7 @@ def destroy
def push_to_epic
sub_service_request = SubServiceRequest.find(params[:id])
begin
sub_service_request.service_request.protocol.push_to_epic(EPIC_INTERFACE)
sub_service_request.service_request.protocol.push_to_epic(EPIC_INTERFACE, "portal_push", current_user.id)

respond_to do |format|
format.json {
Expand Down
8 changes: 4 additions & 4 deletions app/controllers/protocols_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
# 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 ProtocolsController < ApplicationController

respond_to :html, :js, :json

before_filter :initialize_service_request, unless: :from_portal?, except: [:approve_epic_rights, :push_to_epic, :push_to_epic_status]
Expand Down Expand Up @@ -207,7 +207,7 @@ def push_protocol_to_epic protocol
# Thread.new do
begin
# Do the actual push. This might take a while...
protocol.push_to_epic(EPIC_INTERFACE)
protocol.push_to_epic(EPIC_INTERFACE, "pi_email_approval", current_user.id)
errors = EPIC_INTERFACE.errors
session[:errors] = errors unless errors.empty?
@epic_errors = true unless errors.empty?
Expand All @@ -224,15 +224,15 @@ def push_protocol_to_epic protocol
end
# end
end

def convert_date_for_save(attrs, date_field)
if attrs[date_field] && attrs[date_field].present?
attrs[date_field] = Time.strptime(attrs[date_field], "%m/%d/%Y")
end

attrs
end

def fix_date_params
attrs = params[:protocol]

Expand Down
14 changes: 7 additions & 7 deletions app/controllers/service_requests_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def navigate
when 'service_calendar'
@service_request.group_valid?(:service_calendar)
end

@errors = @service_request.errors

if @errors.any?
Expand Down Expand Up @@ -152,7 +152,7 @@ def document_management
@has_subsidy = @service_request.sub_service_requests.map(&:has_subsidy?).any?
@eligible_for_subsidy = @service_request.sub_service_requests.map(&:eligible_for_subsidy?).any?

unless @has_subsidy || @eligible_for_subsidy
unless @has_subsidy || @eligible_for_subsidy
@back = 'service_calendar'
end
end
Expand Down Expand Up @@ -206,7 +206,7 @@ def confirmation
@sub_service_request.update_past_status(current_user)
else
to_notify = update_service_request_status(@service_request, 'submitted')

@service_request.update_arm_minimum_counts
@service_request.sub_service_requests.update_all(nursing_nutrition_approved: false, lab_approved: false, imaging_approved: false, committee_approved: false)
end
Expand All @@ -219,7 +219,7 @@ def confirmation
# approve_epic_rights.
@protocol.ensure_epic_user
if QUEUE_EPIC
EpicQueue.create(protocol_id: @protocol.id) unless EpicQueue.where(protocol_id: @protocol.id).size == 1
EpicQueue.create(protocol_id: @protocol.id, identity_id: current_user.id) unless EpicQueue.where(protocol_id: @protocol.id).size == 1
else
@protocol.awaiting_approval_for_epic_push
send_epic_notification_for_user_approval(@protocol)
Expand Down Expand Up @@ -515,10 +515,10 @@ def send_admin_notifications(service_request, sub_service_requests)
# Passes the correct SSR to display in the attachment and email.
sub_service_requests.each do |sub_service_request|
sub_service_request.organization.submission_emails_lookup.each do |submission_email|

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

@line_items = sub_service_request.line_items
xls = render_to_string action: 'show', formats: [:xlsx]
Notifier.notify_admin(service_request, submission_email.email, xls, current_user, sub_service_request).deliver
Expand Down Expand Up @@ -598,7 +598,7 @@ def send_epic_notification_for_user_approval(protocol)
end

def update_service_request_status(service_request, status, validate=true)
sub_service_requests = service_request.sub_service_requests.where(status: UPDATABLE_STATUSES)
sub_service_requests = service_request.sub_service_requests.where(status: UPDATABLE_STATUSES)
if (status == 'submitted')
service_request.previous_submitted_at = @service_request.submitted_at
service_request.update_attribute(:submitted_at, Time.now)
Expand Down
2 changes: 1 addition & 1 deletion app/models/epic_queue.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class EpicQueue < ActiveRecord::Base
audited

# attr_accessible :title, :body
attr_accessible :protocol_id
attr_accessible :protocol_id, :identity_id
belongs_to :protocol

after_create :update_protocol
Expand Down
2 changes: 1 addition & 1 deletion app/models/epic_queue_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@
class EpicQueueRecord < ActiveRecord::Base
audited

attr_accessible :protocol_id, :status
attr_accessible :protocol_id, :status, :origin, :identity_id
end
6 changes: 3 additions & 3 deletions app/models/protocol.rb
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ def funding_source_based_on_status
# Note: this method is called inside a child thread by the service
# requests controller. Be careful adding code here that might not be
# thread-safe.
def push_to_epic(epic_interface)
def push_to_epic(epic_interface, origin, identity_id=nil)
begin
self.last_epic_push_time = Time.now
self.last_epic_push_status = 'started'
Expand All @@ -382,13 +382,13 @@ def push_to_epic(epic_interface)
self.last_epic_push_status = 'complete'
save(validate: false)

EpicQueueRecord.create(protocol_id: self.id, status: self.last_epic_push_status)
EpicQueueRecord.create(protocol_id: self.id, status: self.last_epic_push_status, origin: origin, identity_id: identity_id)
rescue Exception => e
Rails.logger.info("Push to Epic failed.")

self.last_epic_push_status = 'failed'
save(validate: false)
EpicQueueRecord.create(protocol_id: self.id, status: self.last_epic_push_status)
EpicQueueRecord.create(protocol_id: self.id, status: self.last_epic_push_status, origin: origin, identity_id: identity_id)
raise e
end
end
Expand Down
6 changes: 6 additions & 0 deletions db/migrate/20161109162634_add_origin_to_epic_queue_record.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class AddOriginToEpicQueueRecord < ActiveRecord::Migration
def change
add_column :epic_queue_records, :origin, :string
add_column :epic_queue_records, :identity_id, :integer
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Meh, as far as I can tell, the actual end result is identical in this instance, but I'll change it just for consistency.

end
end
5 changes: 5 additions & 0 deletions db/migrate/20161115153644_add_identity_id_to_epic_queue.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddIdentityIdToEpicQueue < ActiveRecord::Migration
def change
add_column :epic_queues, :identity_id, :integer
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

See above.

end
end
5 changes: 4 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20160930185037) do
ActiveRecord::Schema.define(version: 20161115153644) do

create_table "admin_rates", force: :cascade do |t|
t.integer "line_item_id", limit: 4
Expand Down Expand Up @@ -284,12 +284,15 @@
t.string "status", limit: 255
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "origin", limit: 255
t.integer "identity_id", limit: 4
end

create_table "epic_queues", force: :cascade do |t|
t.integer "protocol_id", limit: 4
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "identity_id", limit: 4
end

create_table "epic_rights", force: :cascade do |t|
Expand Down
10 changes: 7 additions & 3 deletions lib/tasks/batch_loading_to_epic.rake
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,13 @@ namespace :epic do
protocol_ids.each do |id|
begin
p = Protocol.find id
q = EpicQueue.find_by_protocol_id(p.id) rescue false

p.push_to_epic(EPIC_INTERFACE)
if q
p.push_to_epic(EPIC_INTERFACE, "submission", q.identity_id)
else
p.push_to_epic(EPIC_INTERFACE, "command_line")
end

# loop until the push is either complete or fails
while not ['complete', 'failed'].include? p.last_epic_push_status
Expand All @@ -93,7 +98,6 @@ namespace :epic do
else
puts "#{p.short_title} (#{p.id}) sent to Epic"
sent << p.id
q = EpicQueue.find_by_protocol_id(p.id) rescue false
q.destroy if q
end
rescue Exception => e
Expand All @@ -107,7 +111,7 @@ namespace :epic do
end
puts "Sent => #{sent.inspect.to_s}"
puts "Failed => #{failed.inspect.to_s}"

Notifier.epic_queue_complete(sent, failed).deliver
else
puts "Batch load aborted"
Expand Down
4 changes: 2 additions & 2 deletions spec/models/protocol/push_to_epic_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
describe "push to epic" do
it "should create a record of the protocols push" do
study.update_attribute(:selected_for_epic, true)
expect{ study.push_to_epic(EPIC_INTERFACE) }.to change(EpicQueueRecord, :count).by(1)
expect{ study.push_to_epic(EPIC_INTERFACE, "test") }.to change(EpicQueueRecord, :count).by(1)
end
end
end
end
2 changes: 1 addition & 1 deletion spec/models/protocol_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@
describe "push to epic" do
it "should create a record of the protocols push" do
study.update_attribute(:selected_for_epic, true)
expect{ study.push_to_epic(EPIC_INTERFACE) }.to change(EpicQueueRecord, :count).by(1)
expect{ study.push_to_epic(EPIC_INTERFACE, "test") }.to change(EpicQueueRecord, :count).by(1)
end
end
end