Skip to content

Commit

Permalink
JM - (SPARCRequest & SPARCDashboard) Step 2 Edit Study RMID Bugs [#15…
Browse files Browse the repository at this point in the history
…0810679]
  • Loading branch information
jwiel86 committed Sep 15, 2017
1 parent 01c141a commit 3ba1422
Show file tree
Hide file tree
Showing 37 changed files with 98 additions and 28 deletions.
4 changes: 4 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ def create_calendar_event event
}
end

def rmid_server_status(protocol)
@rmid_server_down = protocol.rmid_server_status
@rmid_server_down ? flash[:alert] = t(:protocols)[:summary][:tooltips][:rmid_server_down] : nil
end

def authorization_error msg, ref
error = msg
Expand Down
5 changes: 5 additions & 0 deletions app/controllers/dashboard/base_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ def clean_errors(errors)

private

def rmid_server_status(protocol)
@rmid_server_down = protocol.rmid_server_status
@rmid_server_down ? flash[:alert] = t(:protocols)[:summary][:tooltips][:rmid_server_down] : nil
end

def protocol_authorizer_view
@authorization = ProtocolAuthorizer.new(@protocol, @user)

Expand Down
5 changes: 5 additions & 0 deletions app/controllers/dashboard/protocols_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ def new
session[:protocol_type] = params[:protocol_type]
gon.rm_id_api_url = RESEARCH_MASTER_API
gon.rm_id_api_token = RMID_API_TOKEN
rmid_server_status(@protocol)
end

def create
Expand Down Expand Up @@ -142,6 +143,8 @@ def edit
@errors = @protocol.errors
@errors.delete(:research_master_id) if @admin

rmid_server_status(@protocol)

respond_to do |format|
format.html
end
Expand Down Expand Up @@ -193,6 +196,8 @@ def update_protocol_type
if @protocol_type == "Study" && @protocol.sponsor_name.nil? && @protocol.selected_for_epic.nil?
flash[:alert] = t(:protocols)[:change_type][:new_study_warning]
end

rmid_server_status(@protocol)
end

def archive
Expand Down
3 changes: 3 additions & 0 deletions app/controllers/dashboard/study_type_answers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,8 @@ def edit
respond_to do |format|
format.js
end

@rmid_server_down = @protocol.rmid_server_status
@rmid_server_down ? flash[:alert] = t(:protocols)[:summary][:tooltips][:rmid_server_down] : nil
end
end
5 changes: 5 additions & 0 deletions app/controllers/protocols_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def new
@protocol.populate_for_edit
gon.rm_id_api_url = RESEARCH_MASTER_API
gon.rm_id_api_token = RMID_API_TOKEN
rmid_server_status(@protocol)
end

def create
Expand Down Expand Up @@ -78,6 +79,9 @@ def edit
@protocol.populate_for_edit
@protocol.valid?
@errors = @protocol.errors

rmid_server_status(@protocol)

gon.rm_id_api_url = RESEARCH_MASTER_API
gon.rm_id_api_token = RMID_API_TOKEN

Expand Down Expand Up @@ -127,6 +131,7 @@ def update_protocol_type
if @protocol_type == "Study" && @protocol.sponsor_name.nil? && @protocol.selected_for_epic.nil?
flash[:alert] = t(:protocols)[:change_type][:new_study_warning]
end
rmid_server_status(@protocol)
end

def show
Expand Down
9 changes: 8 additions & 1 deletion app/models/protocol.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,12 @@ def existing_rm_id
rm_ids = HTTParty.get(RESEARCH_MASTER_API + 'research_masters.json', headers: {'Content-Type' => 'application/json', 'Authorization' => "Token token=\"#{RMID_API_TOKEN}\""})
ids = rm_ids.map{ |rm_id| rm_id['id'] }

unless ids.include?(self.research_master_id)
if research_master_id.present? && !ids.include?(research_master_id)
errors.add(:_, 'The entered Research Master ID does not exist. Please go to the Research Master website to create a new record.')
end

rescue
return "server_down"
end

def unique_rm_id_to_protocol
Expand Down Expand Up @@ -480,6 +483,10 @@ def create_arm(args)
arm
end

def rmid_server_status
existing_rm_id == "server_down" && type == "Study"
end

def should_push_to_epic?
service_requests.any?(&:should_push_to_epic?)
end
Expand Down
2 changes: 1 addition & 1 deletion app/views/dashboard/protocols/edit.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@
= render 'shared/modal_errors', errors: @errors
#protocol
= render 'dashboard/protocols/form/edit_protocol_type', protocol: @protocol, protocol_type: @protocol_type, in_dashboard: @in_dashboard
= render 'dashboard/protocols/form/protocol_form', protocol: @protocol, protocol_type: @protocol_type, admin: @admin, permission_to_edit: @permission_to_edit, action_name: action_name, edit_answers: @edit_answers
= render 'dashboard/protocols/form/protocol_form', protocol: @protocol, protocol_type: @protocol_type, admin: @admin, permission_to_edit: @permission_to_edit, action_name: action_name, edit_answers: @edit_answers, rmid_server_down: @rmid_server_down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
= hidden_field_tag :epic_config, USE_EPIC
.edit-study-view.container-fluid
.row.user-edit-protocol-view
= render partial: 'dashboard/protocols/form/study_fields', locals: { form: form, protocol: protocol, admin: admin, permission_to_edit: permission_to_edit, action_name: action_name, edit_answers: edit_answers }
= render partial: 'dashboard/protocols/form/study_fields', locals: { form: form, protocol: protocol, admin: admin, permission_to_edit: permission_to_edit, action_name: action_name, edit_answers: edit_answers, rmid_server_down: rmid_server_down }

- elsif @protocol.type.capitalize == "Project"
.edit-project-view.container-fluid
Expand Down
2 changes: 1 addition & 1 deletion app/views/dashboard/protocols/form/_study_fields.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
-# 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.
= render 'dashboard/protocols/form/study_form_sections/study_information', protocol: protocol, form: form, admin: admin, permission_to_edit: permission_to_edit, action_name: action_name, edit_answers: edit_answers
= render 'dashboard/protocols/form/study_form_sections/study_information', protocol: protocol, form: form, admin: admin, permission_to_edit: permission_to_edit, action_name: action_name, edit_answers: edit_answers, rmid_server_down: rmid_server_down
= render 'dashboard/protocols/form/study_form_sections/optional_information', protocol: protocol, form: form
= render 'dashboard/protocols/form/study_form_sections/research_involving', protocol: protocol, form: form
= render 'dashboard/protocols/form/study_form_sections/study_type', protocol: protocol, form: form
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@
= form.label :research_master_id, class: 'col-lg-2 control-label rm-id' do
= link_to t(:protocols)[:studies][:information][:research_master_id], RESEARCH_MASTER_LINK, target: '_blank'
.col-lg-3
= form.text_field :research_master_id, class: 'form-control research-master-field', readonly: action_name == "edit" && admin
- if action_name == "edit" && admin
= form.text_field :research_master_id, class: 'form-control research-master-field', readonly: action_name == "edit" && admin, disabled: rmid_server_down
- if action_name == "edit" && admin && !rmid_server_down
.btn.btn-warning.edit-rmid
= t(:actions)[:edit]
- if rmid_server_down
.glyphicon.glyphicon-exclamation-sign.text-danger{ title: t(:protocols)[:summary][:tooltips][:rmid_server_down], data: { toggle: 'tooltip', delay: '{"show":"500"}' } }

.form-group.row
= form.label :short_title,
Expand Down
2 changes: 1 addition & 1 deletion app/views/dashboard/protocols/new.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@
= stylesheet_link_tag 'protocol_form'

#protocol
= render 'dashboard/protocols/form/protocol_form', protocol: @protocol, protocol_type: @protocol_type, admin: @admin, permission_to_edit: @permission_to_edit
= render 'dashboard/protocols/form/protocol_form', protocol: @protocol, protocol_type: @protocol_type, admin: @admin, permission_to_edit: @permission_to_edit, rmid_server_down: @rmid_server_down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# 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.

$("#protocol-form-display").replaceWith("<%= escape_javascript(render( '/dashboard/protocols/form/protocol_form', protocol: @protocol, protocol_type: @protocol_type, admin: @admin, permission_to_edit: @permission_to_edit )) %>")
$("#protocol-form-display").replaceWith("<%= escape_javascript(render( '/dashboard/protocols/form/protocol_form', protocol: @protocol, protocol_type: @protocol_type, admin: @admin, permission_to_edit: @permission_to_edit, rmid_server_down: @rmid_server_down )) %>")
$("#flashes_container").html("<%= escape_javascript(render( 'shared/flash' )) %>")
$(".datetimepicker").datetimepicker(format: 'MM/DD/YYYY', allowInputToggle: true)
$(".selectpicker").selectpicker()
Expand Down
2 changes: 1 addition & 1 deletion app/views/dashboard/study_type_answers/edit.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# 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.

$('#protocol-form-display').replaceWith("<%= j render 'dashboard/protocols/form/protocol_form', protocol: @protocol, protocol_type: @protocol.type, admin: true, permission_to_edit: true, edit_answers: @edit_answers %>")
$('#protocol-form-display').replaceWith("<%= j render 'dashboard/protocols/form/protocol_form', protocol: @protocol, protocol_type: @protocol.type, admin: true, permission_to_edit: true, edit_answers: @edit_answers, rmid_server_down: @rmid_server_down %>")
$(".datetimepicker:not(.time)").datetimepicker(format: 'MM/DD/YYYY', allowInputToggle: true)
$('.datetimepicker.time').datetimepicker(format: 'hh:mm A', allowInputToggle: true)
$(".selectpicker").selectpicker()
Expand Down
2 changes: 1 addition & 1 deletion app/views/protocols/edit.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@
= render 'shared/modal_errors', errors: @errors
#protocol
= render 'protocols/form/edit_protocol_type', protocol: @protocol, protocol_type: @protocol_type, service_request: @service_request, in_dashboard: @in_dashboard
= render 'protocols/form/protocol_form', protocol: @protocol, protocol_type: @protocol_type, service_request: @service_request, sub_service_request_id: @sub_service_request.try(:id)
= render 'protocols/form/protocol_form', protocol: @protocol, protocol_type: @protocol_type, service_request: @service_request, sub_service_request_id: @sub_service_request.try(:id), rmid_server_down: @rmid_server_down
2 changes: 1 addition & 1 deletion app/views/protocols/form/_protocol_form.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
= hidden_field_tag :epic_config, USE_EPIC
.edit-study-view.container-fluid
.row.user-edit-protocol-view
= render 'protocols/form/study_fields', form: form, protocol: protocol
= render 'protocols/form/study_fields', form: form, protocol: protocol, rmid_server_down: rmid_server_down

- elsif protocol.type.capitalize == "Project"
.edit-project-view.container-fluid
Expand Down
2 changes: 1 addition & 1 deletion app/views/protocols/form/_study_fields.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
-# 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.
= render 'protocols/form/study_form_sections/study_information', protocol: protocol, form: form
= render 'protocols/form/study_form_sections/study_information', protocol: protocol, form: form, rmid_server_down: rmid_server_down
= render 'protocols/form/study_form_sections/optional_information', protocol: protocol, form: form
= render 'protocols/form/study_form_sections/research_involving', protocol: protocol, form: form
= render 'protocols/form/study_form_sections/study_type', protocol: protocol, form: form
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@
.form-group.row
= form.label :research_master_id, class: 'col-lg-2 control-label rm-id' do
= link_to t(:protocols)[:studies][:information][:research_master_id], RESEARCH_MASTER_LINK, target: '_blank'
.col-lg-10
= form.text_field :research_master_id, class: 'form-control research-master-field'
.col-lg-3
= form.text_field :research_master_id, class: 'form-control research-master-field', disabled: rmid_server_down
- if rmid_server_down
.glyphicon.glyphicon-exclamation-sign.text-danger{ title: t(:protocols)[:summary][:tooltips][:rmid_server_down], data: { toggle: 'tooltip', delay: '{"show":"500"}' } }

.form-group.row
= form.label :short_title, t(:protocols)[:studies][:information][:short_title],
Expand Down
2 changes: 1 addition & 1 deletion app/views/protocols/new.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@
= stylesheet_link_tag 'protocol_form'

#protocol
= render 'protocols/form/protocol_form', protocol: @protocol, protocol_type: @protocol_type, service_request: @service_request
= render 'protocols/form/protocol_form', protocol: @protocol, protocol_type: @protocol_type, service_request: @service_request, rmid_server_down: @rmid_server_down
2 changes: 1 addition & 1 deletion app/views/protocols/update_protocol_type.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# 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.

$("#protocol-form-display").replaceWith("<%= escape_javascript(render( '/protocols/form/protocol_form', protocol: @protocol, protocol_type: @protocol_type, service_request: @service_request )) %>")
$("#protocol-form-display").replaceWith("<%= escape_javascript(render( '/protocols/form/protocol_form', protocol: @protocol, protocol_type: @protocol_type, service_request: @service_request, rmid_server_down: @rmid_server_down )) %>")
$("#flashes_container").html("<%= escape_javascript(render( 'shared/flash' )) %>")
$(".datetimepicker").datetimepicker(format: 'MM/DD/YYYY', allowInputToggle: true)
$(".selectpicker").selectpicker()
Expand Down
16 changes: 14 additions & 2 deletions app/views/shared/_flash.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
-# 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.~
#flashes_container
- if !content_for?(:error_messages)
- if @rmid_server_down
- flash.each do |type, message|
.alert.alert-dismissable{ class: twitterized_type(type) }
%button.close{:'data-dismiss' => "alert", type: "button"}
Expand All @@ -28,8 +28,20 @@
%p
= message
- flash.clear
- else
= content_for(:error_messages)
- else
- if !content_for?(:error_messages)
- flash.each do |type, message|
.alert.alert-dismissable{ class: twitterized_type(type) }
%button.close{:'data-dismiss' => "alert", type: "button"}
%span{:'aria-hidden' => "true"} &times;
%span.sr-only
= t(:actions)[:close]
%p
= message
- flash.clear
- else
= content_for(:error_messages)

:coffeescript
window.setTimeout (->
Expand Down
1 change: 1 addition & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,7 @@ en:
edit: "Quick access to edit protocol information"
archive_study: "Ability to hide study from all Authorized User dashboards"
unarchive_study: "Click to reveal on all associated Authorized User dashboards"
rmid_server_down: "Research Master ID Server is down. You cannot edit the Research Master ID field at this time."
view_details:
button: "View %{protocol_type} Details"
header: "%{protocol_type} Details: #%{protocol_id}"
Expand Down
8 changes: 7 additions & 1 deletion spec/controllers/dashboard/protocols/get_edit_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@

context "user authorized to edit Protocol" do
context "protocol has inactive study_type_question_group_id" do

build_study_type_question_groups
before(:each) do
@logged_in_user = build_stubbed(:identity)
Expand All @@ -59,12 +58,14 @@
end

allow(@protocol).to receive(:valid?).and_return(true)
allow(@protocol).to receive(:rmid_server_status).and_return(false)
allow(@protocol).to receive(:populate_for_edit)
allow(@protocol).to receive(:update_attribute).and_return(true)

authorize(@logged_in_user, @protocol, can_edit: true)

log_in_dashboard_identity(obj: @logged_in_user)


get :edit, params: { id: @protocol.id }
end
Expand Down Expand Up @@ -96,6 +97,7 @@
end

allow(@protocol).to receive(:valid?).and_return(true)
allow(@protocol).to receive(:rmid_server_status).and_return(false)
allow(@protocol).to receive(:populate_for_edit)
allow(@protocol).to receive(:update_attribute).and_return(true)

Expand Down Expand Up @@ -152,6 +154,8 @@
create(:sub_service_request_without_validations, organization: organization, service_request: service_request, status: 'draft', protocol_id: @protocol.id)
create(:super_user, identity: @logged_in_user, organization: organization)

allow_any_instance_of(Protocol).to receive(:rmid_server_status).and_return(false)

log_in_dashboard_identity(obj: @logged_in_user)

get :edit, params: { id: @protocol.id }
Expand All @@ -173,6 +177,8 @@
create(:sub_service_request_without_validations, organization: organization, service_request: service_request, status: 'draft', protocol_id: @protocol.id)
create(:service_provider, identity: @logged_in_user, organization: organization)

allow_any_instance_of(Protocol).to receive(:rmid_server_status).and_return(false)

log_in_dashboard_identity(obj: @logged_in_user)

get :edit, params: { id: @protocol.id }
Expand Down
2 changes: 2 additions & 0 deletions spec/controllers/dashboard/protocols/get_new_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
context 'params[:protocol_type] == "project"' do
before(:each) do
@current_user = build_stubbed(:identity)
allow_any_instance_of(Protocol).to receive(:rmid_server_status).and_return(false)
log_in_dashboard_identity(obj: @current_user)
get :new, params: { protocol_type: 'project' }
end
Expand All @@ -50,6 +51,7 @@
context 'params[:protocol_type] == "study"' do
before(:each) do
@current_user = build_stubbed(:identity)
allow_any_instance_of(Protocol).to receive(:rmid_server_status).and_return(false)
log_in_dashboard_identity(obj: @current_user)
get :new, params: { protocol_type: 'study' }
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
end
allow(@protocol).to receive(:update_attribute)
allow(@protocol).to receive(:populate_for_edit)
allow(@protocol).to receive(:rmid_server_status).and_return(false)
authorize(@logged_in_user, @protocol, can_edit: true)

put :update_protocol_type, params: { id: @protocol.id, type: "Project"}, xhr: true
Expand Down Expand Up @@ -85,7 +86,7 @@
before :each do
@logged_in_user = create(:identity)
@protocol = create(:protocol_without_validations, type: 'Project')

allow_any_instance_of(Protocol).to receive(:rmid_server_status).and_return(false)
log_in_dashboard_identity(obj: @logged_in_user)

put :update_protocol_type, params: { id: @protocol.id }, xhr: true
Expand All @@ -109,6 +110,8 @@
create(:sub_service_request_without_validations, organization: organization, service_request: service_request, status: 'draft', protocol_id: @protocol.id)
create(:super_user, identity: @logged_in_user, organization: organization)

allow_any_instance_of(Protocol).to receive(:rmid_server_status).and_return(false)

log_in_dashboard_identity(obj: @logged_in_user)

put :update_protocol_type, params: { id: @protocol.id }, xhr: true
Expand All @@ -130,6 +133,8 @@
service_request = create(:service_request_without_validations, protocol: @protocol)
create(:sub_service_request_without_validations, organization: organization, service_request: service_request, status: 'draft', protocol_id: @protocol.id)
create(:service_provider, identity: @logged_in_user, organization: organization)

allow_any_instance_of(Protocol).to receive(:rmid_server_status).and_return(false)

log_in_dashboard_identity(obj: @logged_in_user)

Expand Down
2 changes: 1 addition & 1 deletion spec/factories/protocol.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
start_date { '2015-10-15' }
end_date { '2015-10-15' }
selected_for_epic false

trait :without_validations do
to_create { |instance| instance.save(validate: false) }
end
Expand Down

0 comments on commit 3ba1422

Please sign in to comment.