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 - Fix RMID API IRB Synchronization & Synchronization Errors When RMID Server Down #2370

Merged
merged 2 commits into from
May 22, 2020
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
2 changes: 1 addition & 1 deletion app/models/protocol.rb
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ def remotely_notifiable_attributes_to_watch_for_change
def validate_existing_rmid
rmid = Protocol.get_rmid(self.research_master_id)

if self.research_master_id.present? && rmid['status'] == 404 && self.errors[:research_master_id].empty?
if self.research_master_id.present? && rmid.present? && rmid['status'] == 404 && self.errors[:research_master_id].empty?
self.errors.add(:base, I18n.t('protocols.rmid.errors.not_found', rmid: self.research_master_id, rmid_link: Setting.get_value('research_master_link')))
end
end
Expand Down
5 changes: 2 additions & 3 deletions app/views/irb_records/_irb_record.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +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.

- primary = primary == 'true'

.list-group-item.d-flex.border.flex-column.collapsed.mb-3.irb-record{ class: primary ? 'list-group-item-success primary-irb' : 'list-group-item-info', id: "irb#{index}", data: { toggle: 'collapse', target: "#irb#{index}Collapse" } }
= hidden_field_tag "protocol[human_subjects_info_attributes][irb_records_attributes][#{index}][pro_number]", irb_record.pro_number
= hidden_field_tag "protocol[human_subjects_info_attributes][irb_records_attributes][#{index}][irb_of_record]", irb_record.irb_of_record
Expand All @@ -39,7 +37,8 @@
.d-flex.align-items-center
= link_to edit_irb_records_path(id: irb_record.id, index: index, primary: primary.to_s, irb_record: params[:irb_record].present? ? params[:irb_record].permit! : {}), remote: true, class: 'text-warning mr-2 edit-irb', title: t('irb_records.tooltips.edit'), data: { toggle: 'tooltip' } do
= icon('fas', 'edit fa-lg')
= link_to irb_records_path(id: irb_record.id, index: index), remote: true, method: :delete, class: 'text-danger delete-irb', title: t('irb_records.tooltips.delete'), data: { toggle: 'tooltip' } do
- disable_delete = @irb_count && @irb_count > 1 && primary
= link_to irb_records_path(id: irb_record.id, index: index), remote: true, method: :delete, class: ['delete-irb', disable_delete ? 'text-muted' : 'text-danger'], title: disable_delete ? t('irb_records.tooltips.cant_delete_primary') : t('irb_records.tooltips.delete'), disabled: disable_delete, data: { toggle: 'tooltip' } do
= icon('fas', 'trash-alt fa-lg')
.collapse{ id: "irb#{index}Collapse" }
.w-100.pt-3
Expand Down
4 changes: 2 additions & 2 deletions app/views/irb_records/create.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ $("[name='irb_record[<%= attr.to_s %>]']").parents('.form-group').removeClass('i
<% end %>
<% end %>
<% else %>
$('#irbRecords').append("<%= j render 'irb_records/irb_record', protocol: @protocol, irb_record: @irb_record, index: params[:index], primary: params[:primary] %>")
$('#newIrbRecord').replaceWith("<%= j render 'irb_records/new_irb_record', protocol: @protocol, index: params[:index].to_i + 1, primary: 'false' %>")
$('#irbRecords').append("<%= j render 'irb_records/irb_record', protocol: @protocol, irb_record: @irb_record, index: params[:index], primary: params[:primary] == 'true' %>")
$('#newIrbRecord').replaceWith("<%= j render 'irb_records/new_irb_record', protocol: @protocol, index: params[:index].to_i + 1, primary: false %>")

<% if params[:primary] == 'false' %>
$('.primary-irb .delete-irb').addClass('text-muted').removeClass('text-danger').
Expand Down
11 changes: 9 additions & 2 deletions app/views/irb_records/update.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ $("[name='irb_record[<%= attr.to_s %>]']").parents('.form-group').removeClass('i
<% end %>
<% end %>
<% else %>
$("#irb<%= params[:index] %>").replaceWith("<%= j render 'irb_records/irb_record', protocol: @protocol, irb_record: @irb_record, index: params[:index], primary: params[:primary] %>")
$("#modalContainer").modal('hide')
$("#irb<%= params[:index] %>").replaceWith("<%= j render 'irb_records/irb_record', protocol: @protocol, irb_record: @irb_record, index: params[:index], primary: params[:primary] == 'true' %>")

if $('.irb-record:not(.d-none)').length > 1
$('.primary-irb .delete-irb').addClass('text-muted').removeClass('text-danger').
attr('disabled', true).
attr('data-original-title', I18n.t('irb_records.tooltips.cant_delete_primary'))

if $('#modalContainer').hasClass('show')
$("#modalContainer").modal('hide')
<% end %>
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
%h5
= HumanSubjectsInfo.human_attribute_name(:irb_records)
.w-100#irbRecords
- index = ff_hsi.object.irb_records.length
- @irb_count = ff_hsi.object.irb_records.length
= ff_hsi.fields_for :irb_records do |ff_irb|
= render 'irb_records/irb_record', protocol: protocol, irb_record: ff_irb.object, index: ff_irb.index, primary: (ff_irb.index == 0).to_s
= render 'irb_records/new_irb_record', protocol: protocol, index: index, primary: index == 0
= render 'irb_records/irb_record', protocol: protocol, irb_record: ff_irb.object, index: ff_irb.index, primary: ff_irb.index == 0
= render 'irb_records/new_irb_record', protocol: protocol, index: @irb_count, primary: @irb_count == 0
24 changes: 15 additions & 9 deletions app/views/protocols/validate_rmid.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,15 @@
<% if @errors.any? %>
$('#protocol_research_master_id').parents('.form-group').addClass('is-invalid')

<% if @protocol.rmid_server_down %>
$('#protocol_research_master_id').val('').prop('disabled', true)
$('#rmidContainer').append("<%= j render 'protocols/form/rmid_server_down' %>")
<% else %>
AlertSwal.fire(
type: 'error'
title: "<%= Protocol.human_attribute_name(:research_master_id) %>"
html: "<%= @errors.join('<br>').html_safe %>"
)
<% end %>

<% elsif @protocol.rmid_server_down %>
$('#protocol_research_master_id').val('').prop('disabled', true)
$('#rmidContainer').append("<%= j render 'protocols/form/rmid_server_down' %>")
<% else %>
$('#protocol_research_master_id').parents('.form-group').addClass('is-valid')

Expand All @@ -41,9 +40,16 @@ $('#protocol_title').val("<%= @rmid_record['long_title'] %>").prop('readonly', t
if !$('#protocol_research_types_info_attributes_human_subjects').prop('checked')
$('#protocol_research_types_info_attributes_human_subjects').click()
$('#protocol_research_master_id').click()
$.ajax
method: 'POST'
dataType: 'script'
url: "<%= irb_records_path(irb_record: { pro_number: @rmid_record['eirb_pro_number'], initial_irb_approval_date: @rmid_record['date_initially_approved'], irb_approval_date: @rmid_record['date_approved'], irb_expiration_date: @rmid_record['date_expiration'] }, primary: 'true', index: 0) %>"

if $('.primary-irb').length
$.ajax
method: 'PUT'
dataType: 'script'
url: "<%= irb_records_path(irb_record: { id: @protocol.irb_records.first, pro_number: @rmid_record['eirb_pro_number'], initial_irb_approval_date: @rmid_record['date_initially_approved'], irb_approval_date: @rmid_record['date_approved'], irb_expiration_date: @rmid_record['date_expiration'] }, primary: 'true', index: 0) %>"
else
$.ajax
method: 'POST'
dataType: 'script'
url: "<%= irb_records_path(irb_record: { pro_number: @rmid_record['eirb_pro_number'], initial_irb_approval_date: @rmid_record['date_initially_approved'], irb_approval_date: @rmid_record['date_approved'], irb_expiration_date: @rmid_record['date_expiration'] }, primary: 'true', index: 0) %>"
<% end %>
<% end %>
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,12 @@
click_button I18n.t('actions.save')
wait_for_javascript_to_finish

expect(IrbRecord.count).to eq(1)
irb = IrbRecord.first
expect(irb.pro_number).to eq('1111111111')
expect(irb.irb_of_record).to eq('My IRB Board')
Timeout.timeout(Capybara.default_max_wait_time) do
loop until IrbRecord.count == 1
expect(IrbRecord.count).to eq(1)
irb = IrbRecord.first
expect(irb.pro_number).to eq('1111111111')
expect(irb.irb_of_record).to eq('My IRB Board')
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@
click_button I18n.t('actions.save')
wait_for_javascript_to_finish

expect(Project.count).to eq(1)
expect(page).to have_current_path(dashboard_protocol_path(Protocol.last))
Timeout.timeout(Capybara.default_max_wait_time) do
loop until Project.count == 1
expect(Project.count).to eq(1)
expect(page).to have_current_path(dashboard_protocol_path(Protocol.last))
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@
click_button I18n.t('actions.save')
wait_for_javascript_to_finish

expect(Study.count).to eq(1)
expect(page).to have_current_path(dashboard_protocol_path(Protocol.last))
Timeout.timeout(Capybara.default_max_wait_time) do
loop until Study.count == 1
expect(Study.count).to eq(1)
expect(page).to have_current_path(dashboard_protocol_path(Protocol.last))
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,11 @@
click_button I18n.t('actions.save')
wait_for_javascript_to_finish

expect(Project.count).to eq(1)
expect(@sr.reload.protocol.becomes(Project)).to eq(Project.last)
expect(page).to have_current_path(protocol_service_request_path(srid: @sr.id))
Timeout.timeout(Capybara.default_max_wait_time) do
loop until Project.count == 1
expect(Project.count).to eq(1)
expect(@sr.reload.protocol.becomes(Project)).to eq(Project.last)
expect(page).to have_current_path(protocol_service_request_path(srid: @sr.id))
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,11 @@
click_button I18n.t('actions.save')
wait_for_javascript_to_finish

expect(Study.count).to eq(1)
expect(@sr.reload.protocol.becomes(Study)).to eq(Study.last)
expect(page).to have_current_path(protocol_service_request_path(srid: @sr.id))
Timeout.timeout(Capybara.default_max_wait_time) do
loop until Study.count == 1
expect(Study.count).to eq(1)
expect(@sr.reload.protocol.becomes(Study)).to eq(Study.last)
expect(page).to have_current_path(protocol_service_request_path(srid: @sr.id))
end
end
end
6 changes: 3 additions & 3 deletions spec/views/irb_records/_irb_record.html.haml_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,22 @@
let!(:irb) { build(:irb_record) }

it 'should render hidden fields with the given record index' do
render 'irb_records/irb_record', irb_record: irb, primary: 'true', index: 0
render 'irb_records/irb_record', irb_record: irb, primary: true, index: 0

expect(response).to have_selector('#protocol_human_subjects_info_attributes_irb_records_attributes_0_pro_number', visible: false)
end

context 'primary IRB' do
it 'should have the success contextual class' do
render 'irb_records/irb_record', irb_record: irb, primary: 'true', index: 0
render 'irb_records/irb_record', irb_record: irb, primary: true, index: 0

expect(response).to have_selector('.irb-record.list-group-item-success.primary-irb')
end
end

context 'secondary IRB' do
it 'should have the info contextual class' do
render 'irb_records/irb_record', irb_record: irb, primary: 'false', index: 0
render 'irb_records/irb_record', irb_record: irb, primary: false, index: 0

expect(response).to have_selector('.irb-record.list-group-item-info:not(.primary-irb)')
end
Expand Down