Skip to content

Commit

Permalink
Restricted notes: Clarify that admin can also mark notes as restricted
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinrobinson committed Jan 25, 2019
1 parent 104ebb0 commit ac3bb74
Show file tree
Hide file tree
Showing 2 changed files with 115 additions and 1 deletion.
Expand Up @@ -42,6 +42,9 @@ export default class RestrictedNotePresence extends React.Component {

renderRedaction() {
const {studentFirstName, educatorName, urlForRestrictedNoteContent} = this.props;
const educatorNameOrAdministrator = (educatorName)
? `${educatorName} or an administrator`
: 'an administrator';
const studentFirstNameOrTheir = (studentFirstName)
? `${studentFirstName}'s`
: 'their';
Expand All @@ -50,7 +53,7 @@ export default class RestrictedNotePresence extends React.Component {
<div>
<NoteText
style={styles.restrictedNoteRedaction}
text={`To respect ${studentFirstNameOrTheir} privacy, ${educatorName || 'the author'} marked this note as restricted.`}
text={`To respect ${studentFirstNameOrTheir} privacy, ${educatorNameOrAdministrator} marked this note as restricted.`}
/>
{urlForRestrictedNoteContent &&
<a
Expand Down
111 changes: 111 additions & 0 deletions app/importers/mtss_referral/student_voice_mid_year_importer.rb
@@ -0,0 +1,111 @@
# Usage:
# file_text = <<EOD
# ...
# EOD
# importer = StudentVoiceMidYearImporter.new
# rows = importer.process(file_text);nil
# event_notes = rows.map {|row| EventNote.create!(row) };nil
class StudentVoiceMidYearImporter
def initialize(options = {})
@log = options.fetch(:log, Rails.env.test? ? LogHelper::Redirect.instance.file : STDOUT)
@strptime_format = options.fetch(:strptime_format, ImportMatcher::GOOGLE_FORM_EXPORTED_TO_GOOGLE_SHEETS_TIMESTAMP_FORMAT)

@matcher = ImportMatcher.new
@fuzzy_student_matcher = FuzzyStudentMatcher.new
reset_counters!
end

def process(file_text)
reset_counters!

event_note_hashes = []
create_streaming_csv(file_text).each_with_index do |row, index|
maybe_row_attrs = process_row_or_nil(row)
next if maybe_row_attrs.nil?
event_note_hashes << maybe_row_attrs
@valid_hashes_count += 1
end

event_note_hashes
end

private
def create_streaming_csv(file_text)
csv_transformer = StreamingCsvTransformer.new(@log, {
csv_options: { header_converters: nil }
})
csv_transformer.transform(file_text)
end

# Map `row` into `EventNote` attributes, adding in `note_title` to each note
# and otherwise just flattening the row into flat text.
def process_row_or_nil(row)
# match student by id first, fall back to name
exact_match = @matcher.find_student_id(row['Student ID Number'])
fuzzy_match = @fuzzy_student_matcher.match_from_full_name(row['Student Name (eg, Sofia Alonso Martinez)'])
if fuzzy_match.nil?
@invalid_student_name_count += 1
@invalid_student_names_list << student_name
return nil
end
student_id = fuzzy_match[:student_id]

# match educator
educator_id = @matcher.find_educator_id(row['Email Address'])

# timestamp
recorded_at = DateTime.strptime(row['Timestamp'], @strptime_format)

# flatten the rest of the fields
{
student_id: student_id,
educator_id: educator_id,
recorded_at: recorded_at,
is_restricted: false,
event_note_type_id: 304,
text: flattened_note_text(row)
}
end

def flattened_note_text(row)
note_title = 'MTSS Referral Form'
text_from_fields = flat_text_from_fields(row, [
'Timestamp',
'Email Address',
'Student Name (eg, Sofia Alonso Martinez)',
'Referring Staff Member'
])
"#{note_title}\n\n#{text_from_fields}"
end

def flat_text_from_fields(raw_row, exclude_fields)
bits = []
row = raw_row.to_h
(row.keys - exclude_fields).each do |key|
next if row[key].nil? || row[key].empty? || row[key] == ''
bits << "#{key}\n#{row[key]}"
end
bits.join("\n\n")
end

def stats
{
valid_hashes_count: @valid_hashes_count,
invalid_row_columns_count: @invalid_row_columns_count,
invalid_student_name_count: @invalid_student_name_count,
invalid_student_names_list: @invalid_student_names_list
}
end

def reset_counters!
@valid_hashes_count = 0
@invalid_row_columns_count = 0
@invalid_student_name_count = 0
@invalid_student_names_list = []
end

def log(msg)
text = if msg.class == String then msg else JSON.pretty_generate(msg) end
@log.puts "StudentVoiceMidYearImporter: #{text}"
end
end

0 comments on commit ac3bb74

Please sign in to comment.