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 - More OS Settings Configurations Updates #1041

8 changes: 4 additions & 4 deletions app/controllers/dashboard/protocols_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ def new
@protocol.requester_id = current_user.id
@protocol.populate_for_edit
session[:protocol_type] = params[:protocol_type]
gon.rm_id_api_url = Setting.find_by_key("research_master_api").value
gon.rm_id_api_token = Setting.find_by_key("rmid_api_token").value
gon.rm_id_api_url = Setting.find_by_key("research_master_api_url").value
gon.rm_id_api_token = Setting.find_by_key("research_master_api_token").value
end

def create
Expand Down Expand Up @@ -131,8 +131,8 @@ def edit
@permission_to_edit = @authorization.nil? ? false : @authorization.can_edit?
@in_dashboard = true
@protocol.populate_for_edit
gon.rm_id_api_url = Setting.find_by_key("research_master_api").value
gon.rm_id_api_token = Setting.find_by_key("rmid_api_token").value
gon.rm_id_api_url = Setting.find_by_key("research_master_api_url").value
gon.rm_id_api_token = Setting.find_by_key("research_master_api_token").value

session[:breadcrumbs].
clear.
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 @@ -34,8 +34,8 @@ def new
@protocol.requester_id = current_user.id
@service_request = ServiceRequest.find(params[:srid])
@protocol.populate_for_edit
gon.rm_id_api_url = Setting.find_by_key("research_master_api").value
gon.rm_id_api_token = Setting.find_by_key("rmid_api_token").value
gon.rm_id_api_url = Setting.find_by_key("research_master_api_url").value
gon.rm_id_api_token = Setting.find_by_key("research_master_api_token").value
end

def create
Expand Down Expand Up @@ -78,8 +78,8 @@ def edit
@protocol.populate_for_edit
@protocol.valid?
@errors = @protocol.errors
gon.rm_id_api_url = Setting.find_by_key("research_master_api").value
gon.rm_id_api_token = Setting.find_by_key("rmid_api_token").value
gon.rm_id_api_url = Setting.find_by_key("research_master_api_url").value
gon.rm_id_api_token = Setting.find_by_key("research_master_api_token").value

respond_to do |format|
format.html
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/protocols_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
module ProtocolsHelper
def display_study_type_question?(protocol, study_type_answer)
to_display =
if !USE_EPIC || protocol.selected_for_epic == false
if !Setting.find_by_key("use_epic").value || protocol.selected_for_epic == false
['certificate_of_conf_no_epic', 'higher_level_of_privacy_no_epic'].include?(study_type_answer.study_type_question.friendly_id) && study_type_answer.answer != nil
else
!['certificate_of_conf_no_epic', 'higher_level_of_privacy_no_epic'].include?(study_type_answer.study_type_question.friendly_id) && study_type_answer.answer != nil
Expand Down
2 changes: 1 addition & 1 deletion app/lib/add_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def initialize(service_request, service_id, current_user)
end

def existing_service_ids
@service_request.line_items.reject{ |line_item| FINISHED_STATUSES.include?(line_item.status) }.map(&:service_id)
@service_request.line_items.reject{ |line_item| Setting.find_by_key("finished_statuses").value.include?(line_item.status) }.map(&:service_id)
end

def generate_new_service_request
Expand Down
8 changes: 4 additions & 4 deletions app/lib/redcap_survey_emitter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ def send_form
data = [record].to_json

fields = {
:token => Setting.find_by_key("redcap_token").value,
:token => Setting.find_by_key("redcap_api_token").value,
:content => 'record',
:format => 'json',
:type => 'flat',
:data => data,
}

ch = Curl::Easy.http_post(
Setting.find_by_key("redcap_api").value,
Setting.find_by_key("redcap_api_url").value,
fields.collect{|k, v| Curl::PostField.content(k.to_s, v)}
)

Expand All @@ -58,14 +58,14 @@ def send_form

def latest_letter_id
fields = {
:token => Setting.find_by_key("redcap_token").value,
:token => Setting.find_by_key("redcap_api_token").value,
:content => 'record',
:format => 'json',
:type => 'flat'
}

ch = Curl::Easy.http_post(
Setting.find_by_key("redcap_api").value,
Setting.find_by_key("redcap_api_url").value,
fields.collect{|k, v| Curl::PostField.content(k.to_s, v)}
)

Expand Down
5 changes: 3 additions & 2 deletions app/mailers/notifier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def notify_user(project_role, service_request, ssr, approval, user_current, audi

@service_requester_id = @service_request.sub_service_requests.first.service_requester_id

#
@portal_link = Setting.find_by_key("dashboard_link").value + "/protocols/#{@protocol.id}"
@ssrs_to_be_displayed = individual_ssr ? [ssr] : @service_request.sub_service_requests

Expand Down Expand Up @@ -178,7 +179,7 @@ def account_status_change identity, approved
@approved = approved

##REVIEW: Why do we care what the from is?
email_from = Rails.env == 'production' ? Setting.find_by_key("admin_mail_to").value : DEFAULT_MAIL_TO
email_from = Rails.env == 'production' ? Setting.find_by_key("admin_mail_to").value : Setting.find_by_key("default_mail_to").value
email_to = identity.email
subject = "#{t(:mailer)[:application_title]} account request - status change"

Expand All @@ -193,7 +194,7 @@ def provide_feedback feedback
@feedback = feedback

email_to = Setting.find_by_key("feedback_mail_to").value
email_from = @feedback.email.blank? ? DEFAULT_MAIL_TO : @feedback.email
email_from = @feedback.email.blank? ? Setting.find_by_key("default_mail_to") : @feedback.email

mail(:to => email_to, :from => email_from, :subject => "Feedback")
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/audit_recovery.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@

class AuditRecovery < ApplicationRecord
self.table_name = 'audits'
establish_connection("audit_#{Rails.env}") if USE_SEPARATE_AUDIT_DATABASE
establish_connection("audit_#{Rails.env}") if Setting.find_by_key("use_separate_audit_database").value
serialize :audited_changes
end
2 changes: 1 addition & 1 deletion app/models/protocol.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def self.to_csv(protocols)
end

def existing_rm_id
rm_ids = HTTParty.get(Setting.find_by_key("research_master_api").value + 'research_masters.json', headers: {'Content-Type' => 'application/json', 'Authorization' => "Token token=\"#{Setting.find_by_key("rmid_api_token").value}\""})
rm_ids = HTTParty.get(Setting.find_by_key("research_master_api_url").value + 'research_masters.json', headers: {'Content-Type' => 'application/json', 'Authorization' => "Token token=\"#{Setting.find_by_key("research_master_api_token").value}\""})
ids = rm_ids.map{ |rm_id| rm_id['id'] }

unless ids.include?(self.research_master_id)
Expand Down
26 changes: 24 additions & 2 deletions app/models/setting.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,22 @@ class Setting < ApplicationRecord

audited

belongs_to :parent, -> { find_by_key(self.parent_key) }, class_name: 'Setting'

validates_uniqueness_of :key

validates :data_type, inclusion: { in: %w(boolean string json email url path) }, presence: true
validates :parent_key, inclusion: { in: Setting.all.pluck(:key) }, allow_blank: true

validate :value_matches_type, if: Proc.new{ self.value.present? }
validate :parent_value_matches_parent_type, if: Proc.new{ self.parent_key.present? }

def value
case data_type
when 'boolean'
read_attribute(:value) == 'true'
when 'json'
JSON.parse(read_attribute(:value))
JSON.parse(read_attribute(:value).gsub("=>", ": "))
else
read_attribute(:value)
end
Expand All @@ -43,7 +47,7 @@ def value
private

def value_matches_type
errors.add(:value, 'invalid type') unless
errors.add(:value, 'does not match the provided data type') unless
case data_type
when 'boolean'
is_boolean?(value)
Expand All @@ -59,4 +63,22 @@ def value_matches_type
true
end
end

def parent_value_matches_parent_type
errors.add(:parent_value, 'does not match the parent\'s data type') unless
case data_type
when 'boolean'
is_boolean?(self.parent.value)
when 'json'
is_json?(self.parent.value)
when 'email'
is_email?(self.parent.value)
when 'url'
is_url?(self.parent.value)
when 'path'
is_path?(self.parent.value)
else # Default type = string, no validation needed
true
end
end
end
2 changes: 1 addition & 1 deletion app/models/study.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def setup_project_roles
FRIENDLY_IDS = ["certificate_of_conf", "higher_level_of_privacy", "epic_inbasket", "research_active", "restrict_sending"]

def validate_study_type_answers
if USE_EPIC && self.selected_for_epic && StudyTypeQuestionGroup.active.ids.first == self.study_type_question_group_id
if Setting.find_by_key("use_epic").value && self.selected_for_epic && StudyTypeQuestionGroup.active.ids.first == self.study_type_question_group_id
answers = {}
FRIENDLY_IDS.each do |fid|
q = StudyTypeQuestion.active.find_by_friendly_id(fid)
Expand Down
4 changes: 2 additions & 2 deletions app/views/catalogs/_about_section.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@

.col-sm-12.about-section
.col-sm-3
%a.text-center{ href: t(:proper)[:footer][:about_url] }
= image_tag 'about.jpg', alt: 'About Sparc Request', height: 30
%a.text-center{ Setting.find_by_key("about_sparc_url") }
= image_tag 'about.jpg', alt: t(:proper)[:footer][:about_alt], height: 30
.col-sm-6
.col-sm-3
-# Insert custom link here if requested
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
= form.hidden_field :requester_id
= form.hidden_field :type
- if @protocol.type.capitalize == "Study"
= hidden_field_tag :epic_config, USE_EPIC
= hidden_field_tag :epic_config, Setting.find_by_key("use_epic").value
.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 }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@


.form-group.row
- if USE_EPIC
- if Setting.find_by_key("USE_EPIC").value
= form.label :selected_for_epic,
t(:protocols)[:studies][:information][:push_to_epic],
class: 'col-lg-2 control-label required',
Expand All @@ -31,14 +31,14 @@
%label.radio-inline.btn.btn-default#study_selected_for_epic_true_button{ class: protocol.selected_for_epic? ? 'active' : ''}
= form.radio_button :selected_for_epic, 'true', id: "study_selected_for_epic_true", class: 'hidden'
= t(:constants)[:yes_select]
%label.radio-inline.btn.btn-default#study_selected_for_epic_false_button{ class: protocol.selected_for_epic == false || !USE_EPIC ? 'active': '' }
%label.radio-inline.btn.btn-default#study_selected_for_epic_false_button{ class: protocol.selected_for_epic == false || !Setting.find_by_key("USE_EPIC").value ? 'active': '' }
= 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 question-label #{USE_EPIC && protocol.selected_for_epic ? 'required' : ''}",
class: "col-lg-2 control-label question-label #{Setting.find_by_key("USE_EPIC").value && protocol.selected_for_epic ? 'required' : ''}",
data: { toggle: 'tooltip', placement: 'right', delay: '{"show":"500"}' },
title: t(:protocols)[:tooltips][:study_type_questions]
.col-lg-10
Expand 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.
.form-group.row
- if USE_EPIC
- if Setting.find_by_key("use_epic").value
= form.label :selected_for_epic, t(:protocols)[:studies][:information][:push_to_epic], class: "col-lg-2 control-label required"
.col-lg-10
%span.epic_selected.display_epic_answers
Expand All @@ -29,7 +29,7 @@
= form.hidden_field :selected_for_epic, value: false
.form-group.row.selected_for_epic_dependent#readonly
- if protocol.display_answers.any?{ |as| display_study_type_question?(protocol, as) }
= form.label :study_type_questions, t(:protocols)[:studies][:information][:study_type_questions], class: "col-lg-2 control-label #{USE_EPIC && protocol.selected_for_epic ? 'required' : ''}"
= form.label :study_type_questions, t(:protocols)[:studies][:information][:study_type_questions], class: "col-lg-2 control-label #{Setting.find_by_key("use_epic").value && protocol.selected_for_epic ? 'required' : ''}"
.col-lg-10
= form.fields_for :study_type_answers, protocol.display_answers do |answer|
= render partial: 'dashboard/protocols/form/study_form_sections/readonly_answer_field', locals: { answer: answer, protocol: protocol }
2 changes: 1 addition & 1 deletion app/views/dashboard/shared/_authorization_error.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
%head
%title
= t(:dashboard)[:header]
= stylesheet_link_tag "#{Setting.find_by_key("custom_asset_path").value}dashboard/application"
= stylesheet_link_tag "dashboard/application"
= javascript_include_tag 'dashboard/application'
/[if IE]
= stylesheet_link_tag 'ie'
Expand Down
5 changes: 3 additions & 2 deletions app/views/devise/sessions/new.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@
= link_to t(:devise)[:sessions][:institution_users], identity_shibboleth_omniauth_authorize_path(service_request_id: @service_request.try(:id)), class: 'btn btn-primary omniauth-login-button'
%a.btn.btn-primary.standard-login-button
= t(:devise)[:sessions][:other_users]
.form-group.sign-up-button
= link_to t(:devise)[:sessions][:sign_up], new_identity_registration_path(service_request_id: @service_request.try(:id))
- if devise_mapping.registerable?
.form-group.sign-up-button
= link_to t(:devise)[:sessions][:sign_up], new_identity_registration_path(service_request_id: @service_request.try(:id))
.form-group.return-button
%a.btn.btn-primary{ href: root_path }
= t(:devise)[:sessions][:return]
Expand Down
2 changes: 1 addition & 1 deletion app/views/identities/approve_account.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,4 @@
.col-sm-9
= text_area_tag :reason, params[:reason], class: 'form-control', disabled: true
%hr
= link_to t(:proper)[:confirmation][:to_dashboard], DASHBOARD_LINK, class: 'btn btn-lg btn-success'
= link_to t(:proper)[:confirmation][:to_dashboard], Setting.find_by_key("dashboard_link").value, class: 'btn btn-lg btn-success'
2 changes: 1 addition & 1 deletion app/views/identities/disapprove_account.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,4 @@
.col-sm-9
= text_area_tag :reason, params[:reason], class: 'form-control', disabled: true
%hr
= link_to t(:proper)[:confirmation][:to_dashboard], DASHBOARD_LINK, class: 'btn btn-lg btn-success'
= link_to t(:proper)[:confirmation][:to_dashboard], Setting.find_by_key("dashboard_link").value, class: 'btn btn-lg btn-success'
2 changes: 1 addition & 1 deletion app/views/layouts/_footer.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@
%li
= link_to t(:proper)[:footer][:sctr], t(:proper)[:footer][:sctr_url], target: :blank
%li
= link_to t(:proper)[:footer][:about], t(:proper)[:footer][:about_url], target: :blank
= link_to t(:proper)[:footer][:about], Setting.find_by_key("about_sparc_url"), target: :blank
2 changes: 1 addition & 1 deletion app/views/layouts/dashboard/application.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
%head
%title
= t(:dashboard)[:header]
= stylesheet_link_tag "#{Setting.find_by_key("custom_asset_path").value}dashboard/application"
= stylesheet_link_tag "dashboard/application"
= javascript_include_tag 'dashboard/application'
/[if IE]
= stylesheet_link_tag 'ie'
Expand 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 @@ -29,7 +29,7 @@
= form.hidden_field :requester_id
= form.hidden_field :type
- if protocol.type.capitalize == "Study"
= hidden_field_tag :epic_config, USE_EPIC
= hidden_field_tag :epic_config, Setting.find_by_key("use_epic").value
.edit-study-view.container-fluid
.row.user-edit-protocol-view
= render 'protocols/form/study_fields', form: form, protocol: protocol
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@


.form-group.row
- if USE_EPIC
- if Setting.find_by_key("use_epic").value
= form.label :selected_for_epic,
t(:protocols)[:studies][:information][:push_to_epic],
class: 'col-lg-2 control-label required',
Expand All @@ -31,11 +31,11 @@
%label.radio-inline.btn.btn-default#study_selected_for_epic_true_button{ class: protocol.selected_for_epic? ? 'active' : ''}
= form.radio_button :selected_for_epic, 'true', id: "study_selected_for_epic_true", class: 'hidden'
= t(:constants)[:yes_select]
%label.radio-inline.btn.btn-default#study_selected_for_epic_false_button{ class: protocol.selected_for_epic == false || !USE_EPIC ? 'active': ''}
%label.radio-inline.btn.btn-default#study_selected_for_epic_false_button{ class: protocol.selected_for_epic == false || !Setting.find_by_key("use_epic").value ? 'active': ''}
= 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) }
= form.label :study_type_questions, t(:protocols)[:studies][:information][:study_type_questions], class: "col-lg-2 control-label question-label #{USE_EPIC && protocol.selected_for_epic ? 'required' : ''}", data: { toggle: 'tooltip', placement: 'right', delay: '{"show":"500"}' }, title: t(:protocols)[:tooltips][:study_type_questions]
= form.label :study_type_questions, t(:protocols)[:studies][:information][:study_type_questions], class: "col-lg-2 control-label question-label #{Setting.find_by_key("use_epic").value && protocol.selected_for_epic ? 'required' : ''}", data: { toggle: 'tooltip', placement: 'right', delay: '{"show":"500"}' }, title: t(:protocols)[:tooltips][:study_type_questions]
.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|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
- visit_groups.each do |vg|
%td.text-center.visit-width{ class: "max-total-per-patient visit-#{vg.id}" }
%strong
- if USE_INDIRECT_COST
- if Setting.find_by_key("use_indirect_cost").value
= currency_converter(vg.per_patient_subtotals * (1 + (arm.protocol.indirect_cost_rate.nil? ? 0 : (arm.protocol.indirect_cost_rate / 100))))
- else
= currency_converter(vg.per_patient_subtotals)
Expand Down