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

Jw change protocol type madness #762

Merged
merged 11 commits into from
Nov 30, 2016
4 changes: 2 additions & 2 deletions app/assets/stylesheets/dashboard/protocol.scss
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@
padding-top: 11px;
}

.red_note {
color: red;
.gray_note {
color: gray;
}

.investigational_products .col-lg-10,
Expand Down
4 changes: 2 additions & 2 deletions app/assets/stylesheets/protocol_form.sass
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,5 @@ textarea
.inv-device-number-field
margin-top: 3px

.red_note
color: red
.gray_note
color: gray
13 changes: 10 additions & 3 deletions app/controllers/dashboard/protocols_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,14 @@ def edit
end

def update
if params[:updated_protocol_type] == 'true' && params[:protocol][:type] == 'Study'
@protocol.update_attribute(:type, params[:protocol][:type])
@protocol.activate
@protocol = Protocol.find(params[:id]) #Protocol reload
end

attrs = fix_date_params
permission_to_edit = @authorization.present? ? @authorization.can_edit? : false

# admin is not able to activate study_type_question_group
if @protocol.update_attributes(attrs)
flash[:success] = I18n.t('protocols.updated', protocol_type: @protocol.type)
Expand All @@ -157,12 +162,14 @@ def update
end

def update_protocol_type
# Using update_attribute here is intentional, type is a protected attribute
protocol_role = @protocol.project_roles.find_by(identity_id: @user.id)
@permission_to_edit = protocol_role.nil? ? false : protocol_role.can_edit?

# Setting type and study_type_question_group, not actually saving
@protocol.type = params[:type]
@protocol.study_type_question_group_id = StudyTypeQuestionGroup.active_id

@protocol_type = params[:type]

@protocol.populate_for_edit
flash[:success] = t(:protocols)[:change_type][:updated]
if @protocol_type == "Study" && @protocol.sponsor_name.nil? && @protocol.selected_for_epic.nil?
Expand Down
14 changes: 12 additions & 2 deletions app/controllers/protocols_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,13 @@ def edit
end

def update

if params[:updated_protocol_type] == 'true' && params[:protocol][:type] == 'Study'
@protocol.update_attribute(:type, params[:protocol][:type])
@protocol.activate
@protocol = Protocol.find(params[:id]) #Protocol reload
end

attrs = fix_date_params
@service_request = ServiceRequest.find(params[:srid])

Expand All @@ -96,10 +103,13 @@ def update

def update_protocol_type
@protocol = Protocol.find(params[:id])
@protocol_type = params[:type]

# Setting type and study_type_question_group, not actually saving
@protocol.type = params[:type]
@protocol.populate_for_edit
@protocol.study_type_question_group_id = StudyTypeQuestionGroup.active_id

@protocol_type = params[:type]
@protocol.populate_for_edit
flash[:success] = t(:protocols)[:change_type][:updated]
if @protocol_type == "Study" && @protocol.sponsor_name.nil? && @protocol.selected_for_epic.nil?
flash[:alert] = t(:protocols)[:change_type][:new_study_warning]
Expand Down
7 changes: 7 additions & 0 deletions app/models/protocol.rb
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,13 @@ def populate_for_edit
end
end

def setup_study_type_answers
StudyTypeQuestion.find_each do |stq|
study_type_answer = study_type_answers.detect{|obj| obj.study_type_question_id == stq.id}
study_type_answer = study_type_answers.build(study_type_question_id: stq.id) unless study_type_answer
end
end

def create_arm(args)
arm = self.arms.new(args)
if arm.valid?
Expand Down
9 changes: 1 addition & 8 deletions app/models/study.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
class Study < Protocol
validates :sponsor_name, presence: true
validates :selected_for_epic, inclusion: [true, false], :if => [:is_epic?]
validate :validate_study_type_answers, if: [:selected_for_epic?, "StudyTypeQuestionGroup.active.pluck(:id).first == changed_attributes()['study_type_question_group_id'] || StudyTypeQuestionGroup.active.pluck(:id).first == study_type_question_group_id"]
validate :validate_study_type_answers, if: [:selected_for_epic?, "StudyTypeQuestionGroup.active.pluck(:id).first == study_type_question_group_id"]


def classes
Expand Down Expand Up @@ -89,13 +89,6 @@ def setup_affiliations
affiliations.sort_by(&:position)
end

def setup_study_type_answers
StudyTypeQuestion.find_each do |stq|
study_type_answer = study_type_answers.detect{|obj| obj.study_type_question_id == stq.id}
study_type_answer = study_type_answers.build(study_type_question_id: stq.id) unless study_type_answer
end
end

def setup_project_roles
project_roles.build(role: "primary-pi", project_rights: "approve") unless project_roles.primary_pis.any?
end
Expand Down
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.
.row.container-fluid
.row.container-fluid{ display_if(!protocol.selected_for_epic) }
.panel.panel-default
.panel-heading
%h4.panel-title
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@
= form.radio_button :selected_for_epic, 'false', id: "study_selected_for_epic_false", class: 'hidden'
= t(:constants)[:no_select]
.form-group.row.selected_for_epic_dependent{ display_if(protocol.selected_for_epic) }
= hidden_field_tag :updated_protocol_type, updated_protocol_type
= form.label :study_type_questions, t(:protocols)[:studies][:information][:study_type_questions], class: 'col-lg-2 control-label required'
.col-lg-10
- updated_protocol_type ? protocol.setup_study_type_answers : ''
= form.fields_for :study_type_answers, protocol.study_type_answers do |answer_form|
- if answer_form.object.study_type_question.study_type_question_group.active
.form-group.row{ id: "study_type_answer_#{answer_form.object.study_type_question.friendly_id}", style: "#{answer_form.object.answer != nil ? 'display:block' : 'display:none;'}" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,12 @@

/ Display epic questions as readonly for administrators who aren't an authorized user
/ with edit abilities
- updated_protocol_type = action_name == 'update_protocol_type' ? true : false
- if USE_EPIC
- if action_name == 'new'
= render partial: 'dashboard/protocols/form/study_form_sections/interactive_form', locals: { protocol: protocol, form: form }
- if action_name == 'new' || updated_protocol_type
= render partial: 'dashboard/protocols/form/study_form_sections/interactive_form', locals: { protocol: protocol, form: form, updated_protocol_type: updated_protocol_type }
- else
= render partial: 'dashboard/protocols/form/study_form_sections/readonly_form', locals: { protocol: protocol, form: form }
= render partial: 'dashboard/protocols/form/study_form_sections/red_note', locals: { protocol: protocol, form: form }
= render partial: 'dashboard/protocols/form/study_form_sections/study_type_note', locals: { protocol: protocol, form: form }


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.

#study_type_note.red_note
#study_type_note.gray_note
- if protocol.active? && action_name != 'update_protocol_type'
- note = protocol.determine_study_type_note
- if note.present?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ $("#flashes_container").html("<%= escape_javascript(render( 'shared/flash' )) %>
$(".datetimepicker").datetimepicker(format: 'MM/DD/YYYY', allowInputToggle: true)
$(".selectpicker").selectpicker()

if $("input[name='protocol[selected_for_epic]']").val()
if $("input[name='protocol[selected_for_epic]',val='true']").prop('checked')
$('.selected_for_epic_dependent').show()
$('#study_type_answer_certificate_of_conf_answer').show_elt()

Expand Down
2 changes: 1 addition & 1 deletion app/views/protocols/form/_edit_protocol_type.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.
.row.container-fluid
.row.container-fluid{ display_if(!protocol.selected_for_epic) }
.panel.panel-default
.panel-heading
%h4.panel-title
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
.form-group.row.selected_for_epic_dependent{ display_if(protocol.selected_for_epic) }
= form.label :study_type_questions, t(:protocols)[:studies][:information][:study_type_questions], class: 'col-lg-2 control-label required'
.col-lg-10
- action_name == 'update_protocol_type' ? protocol.setup_study_type_answers : ''
= form.fields_for :study_type_answers, protocol.study_type_answers do |answer_form|
- if answer_form.object.study_type_question.study_type_question_group.active
.form-group.row{ id: "study_type_answer_#{answer_form.object.study_type_question.friendly_id}", style: "#{answer_form.object.answer != nil ? 'display:block' : 'display:none;'}" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,4 @@
= form.text_field :sponsor_name, class: 'form-control'
- if USE_EPIC
= render partial: 'protocols/form/study_form_sections/interactive_form', locals: { protocol: protocol, form: form }
= render partial: 'protocols/form/study_form_sections/red_note', locals: { protocol: protocol, form: form }
= render partial: 'protocols/form/study_form_sections/study_type_note', locals: { protocol: protocol, form: form }
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.

#study_type_note.red_note
#study_type_note.gray_note
- if protocol.active? && action_name != 'update_protocol_type'
- note = protocol.determine_study_type_note
- if note.present?
Expand 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 @@ -23,6 +23,6 @@ $("#flashes_container").html("<%= escape_javascript(render( 'shared/flash' )) %>
$(".datetimepicker").datetimepicker(format: 'MM/DD/YYYY', allowInputToggle: true)
$(".selectpicker").selectpicker()

if $("input[name='protocol[selected_for_epic]']").val()
if $("input[name='protocol[selected_for_epic]',val='true']").prop('checked')
$('.selected_for_epic_dependent').show()
$('#study_type_answer_certificate_of_conf_answer').show_elt()