<commit_before># Keeps track of the history of objects (mostly patients and pregnancies).
class AuditTrail
  include Mongoid::History::Tracker
  include Mongoid::Userstamp
  mongoid_userstamp user_model: 'User'

  # convenience methods for clean view display
  def date_of_change
    created_at.display_date
  end

  def changed_fields
    relevant_fields = modified.map do |key, value|
      key unless irrelevant_fields.include? key
    end

    relevant_fields.compact.map(&:humanize)
  end

  def changed_from
    relevant_fields = original.map do |key, value|
      value unless irrelevant_fields.include? key
    end

    relevant_fields.compact
  end

  def changed_to
    relevant_fields = modified.map do |key, value|
      value unless irrelevant_fields.include? key
    end

    relevant_fields.compact
  end

  def changed_by_user
    nil # until I figure it out
    # User.find(created_by).name
  end

  def irrelevant_fields
    ['user_ids', 'updated_by']
  end

  def marked_urgent?
    modified.include?('urgent_flag') && modified['urgent_flag'] == true
  end
end<commit_msg>get user to properly render<commit_after># Keeps track of the history of objects (mostly patients and pregnancies).
class AuditTrail
  include Mongoid::History::Tracker
  include Mongoid::Userstamp
  mongoid_userstamp user_model: 'User'

  # convenience methods for clean view display
  def date_of_change
    created_at.display_date
  end

  def changed_fields
    relevant_fields = modified.map do |key, value|
      key unless irrelevant_fields.include? key
    end

    relevant_fields.compact.map(&:humanize)
  end

  def changed_from
    relevant_fields = original.map do |key, value|
      value unless irrelevant_fields.include? key
    end

    relevant_fields.compact
  end

  def changed_to
    relevant_fields = modified.map do |key, value|
      value unless irrelevant_fields.include? key
    end

    relevant_fields.compact
  end

  def changed_by_user
    created_by ? created_by.name : 'System'
  end

  def irrelevant_fields
    %w(user_ids updated_by)
  end

  def marked_urgent?
    modified.include?('urgent_flag') && modified['urgent_flag'] == true
  end
end
{'fraction_non_alphanumeric': 0.06675874769797421, 'fraction_numerical': 0.0, 'mean_word_length': 3.623404255319149, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2067321', 'n_tokens_mistral': 671, 'n_tokens_neox': 640, 'n_words': 189}