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

JM - Make Participant Name All Caps #521

Merged
merged 2 commits into from
Aug 5, 2019
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
7 changes: 7 additions & 0 deletions app/controllers/participants_controller.rb
Expand Up @@ -26,6 +26,7 @@ class ParticipantsController < ApplicationController
before_action :note_old_protocols_participant_attributes, only: [:update_status, :update_arm]
before_action :authorize_protocol, only: [:show]
before_action :authorize_patient_registrar, only: [:index]
before_action :format_participant_name, only: [:create]

def index
@page = params[:page]
Expand All @@ -42,6 +43,12 @@ def index
end
end

def format_participant_name
params[:participant][:first_name] = params[:participant][:first_name].upcase.squish
params[:participant][:last_name] = params[:participant][:last_name].upcase.squish
params[:participant][:middle_initial] = params[:participant][:middle_initial].upcase.squish
end

def find_participants(action_name)
if action_name == "protocols_participants_in_protocol"
@participants = Participant.by_protocol_id(@protocol.id)
Expand Down
40 changes: 40 additions & 0 deletions lib/tasks/fix_participant_names.rake
@@ -0,0 +1,40 @@
# Copyright © 2011-2019 MUSC Foundation for Research Development~
# All rights reserved.~

# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:~

# 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.~

# 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following~
# disclaimer in the documentation and/or other materials provided with the distribution.~

# 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products~
# derived from this software without specific prior written permission.~

# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,~
# BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT~
# SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL~
# 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.~

namespace :data do
desc "Fix participant names"
task fix_participant_names: :environment do

participants = Participant.all
bar = ProgressBar.new(participants.count)

participants.find_each do |participant|

first_name = participant.first_name.nil? ? nil : participant.first_name.upcase.squish
last_name = participant.last_name.nil? ? nil : participant.last_name.upcase.squish
middle_initial = participant.middle_initial.nil? ? nil : participant.middle_initial.upcase.squish

participant.update_attributes(first_name: first_name,
last_name: last_name,
middle_initial: middle_initial)
bar.increment! rescue nil
end
end
end