<commit_before>class Person
  include Mongoid::Document
  include Mongoid::Timestamps
  include Mongoid::Versioning
  include Mongoid::Paranoia

  extend Mongorder

  attr_accessor :relationship

  field :name_pfx, type: String, default: ""
  field :name_first, type: String
  field :name_middle, type: String, default: ""
  field :name_last, type: String
  field :name_sfx, type: String, default: ""
  field :name_full, type: String
  field :alternate_name, type: String, default: ""
  field :updated_by, type: String, default: "system_service"
  field :job_title, type: String, default: ""
  field :department, type: String, default: ""
  field :is_active, type: Boolean, default: true

  field :authority_member_id, type: String, default: nil
  index({"authority_member_id" => 1})

  before_create :initialize_authority_member
  before_save :initialize_name_full
  before_save :invalidate_find_caches

  validates_presence_of :name_first, :name_last
  index({name_last:  1})
  index({name_first: 1})
  index({name_last:1, name_first: 1})
  index({name_first: 1, name_last:1})
  index({name_first: 1, name_last:1, "members.dob"=> 1})
  index({name_last:1, name_first: 1, "members.dob" => 1})
  index({name_first: 1, name_last:1, "emails.email_address" => 1})
  index({name_last: 1, name_first:1, "emails.email_address" => 1})
  index({"emails.email_address" => 1})

  belongs_to :applicant, class_name: "ApplicationGroup", inverse_of: :applicants
  belongs_to :tax_household_member, class_name: "TaxHousehold", inverse_of: :tax_household_members

  has_many   :primary_applicants, class_name: "ApplicationGroup", inverse_of: :primary_applicant
  has_many   :consenters, class_name: "ApplicationGroup", inverse_of: :consent_applicant

  has_and_belongs_to_many :employers, class_name: "Employer", inverse_of: :employee

  embeds_many :addresses, :inverse_of => :person
  accepts_nested_attributes_for :addresses, reject_if: proc { |attribs| attribs['address_1'].blank? }, allow_destroy: true

  embeds_many :phones, :inverse_of => :person
  accepts_nested_attributes_for :phones, reject_if: proc { |attribs| attribs['phone_number'].blank? }, allow_destroy: true

  embeds_many :emails, :inverse_of => :person
  accepts_nested_attributes_for :emails, reject_if: proc { |attribs| attribs['email_address'].blank? }, allow_destroy: true

  # embeds_many :members, after_add: :generate_hbx_member_id
  embeds_many :members, cascade_callbacks: true
  embeds_many :person_relationships

  embeds_many :responsible_parties
#  accepts_nested_attributes_for :responsible_parties, reject_if: :all_blank, allow_destroy: true

  embeds_many :financial_statements
  accepts_nested_attributes_for :financial_statements, allow_destroy: true

  embeds_many :comments
  accepts_nested_attributes_for :comments, reject_if: proc { |attribs| attribs['content'].blank? }, allow_destroy: true

  index({"members.hbx_member_id" =>1})
  index({"members.ssn" => 1})
  index({"members.dob" => 1})
  accepts_nested_attributes_for :members, reject_if: :all_blank, allow_destroy: true

  scope :all_under_age_twenty_six, ->{ gt(:'members.dob' => (Date.today - 26.years))}
  scope :all_over_age_twenty_six,  ->{lte(:'members.dob' => (Date.today - 26.years))}

  # TODO: Add scope that accepts age range
  # scope :all_between_age_range, ->(range) {}

  scope :all_over_or_equal_age, ->(age) {lte(:'members.dob' => (Date.today - age.years))}
  scope :all_under_or_equal_age, ->(age) {gte(:'members.dob' => (Date.today - age.years))}
  scope :all_with_multiple_members, exists({ :'members.1' => true })
  scope :by_name, order_by(name_last: 1, name_first: 1)

  def update_attributes_with_delta(props = {})<commit_msg>Remove embedded financial_statements.  Fix associations with ApplicationGroup<commit_after>class Person
  include Mongoid::Document
  include Mongoid::Timestamps
  include Mongoid::Versioning
  include Mongoid::Paranoia

  extend Mongorder

  attr_accessor :relationship

  field :name_pfx, type: String, default: ""
  field :name_first, type: String
  field :name_middle, type: String, default: ""
  field :name_last, type: String
  field :name_sfx, type: String, default: ""
  field :name_full, type: String
  field :alternate_name, type: String, default: ""
  field :updated_by, type: String, default: "system_service"
  field :job_title, type: String, default: ""
  field :department, type: String, default: ""
  field :is_active, type: Boolean, default: true

  field :authority_member_id, type: String, default: nil
  index({"authority_member_id" => 1})

  before_create :initialize_authority_member
  before_save :initialize_name_full
  before_save :invalidate_find_caches

  validates_presence_of :name_first, :name_last
  index({name_last:  1})
  index({name_first: 1})
  index({name_last:1, name_first: 1})
  index({name_first: 1, name_last:1})
  index({name_first: 1, name_last:1, "members.dob"=> 1})
  index({name_last:1, name_first: 1, "members.dob" => 1})
  index({name_first: 1, name_last:1, "emails.email_address" => 1})
  index({name_last: 1, name_first:1, "emails.email_address" => 1})
  index({"emails.email_address" => 1})


  belongs_to :applicant, class_name: "ApplicationGroup", inverse_of: :applicants
  belongs_to :primary_applicant, class_name: "ApplicationGroup"
  belongs_to :consent_applicant, class_name: "ApplicationGroup"

  has_and_belongs_to_many :employers, class_name: "Employer", inverse_of: :employee

  embeds_many :addresses, :inverse_of => :person
  accepts_nested_attributes_for :addresses, reject_if: proc { |attribs| attribs['address_1'].blank? }, allow_destroy: true

  embeds_many :phones, :inverse_of => :person
  accepts_nested_attributes_for :phones, reject_if: proc { |attribs| attribs['phone_number'].blank? }, allow_destroy: true

  embeds_many :emails, :inverse_of => :person
  accepts_nested_attributes_for :emails, reject_if: proc { |attribs| attribs['email_address'].blank? }, allow_destroy: true

  # embeds_many :members, after_add: :generate_hbx_member_id
  embeds_many :members, cascade_callbacks: true
  embeds_many :person_relationships

  embeds_many :responsible_parties
#  accepts_nested_attributes_for :responsible_parties, reject_if: :all_blank, allow_destroy: true

  embeds_many :comments
  accepts_nested_attributes_for :comments, reject_if: proc { |attribs| attribs['content'].blank? }, allow_destroy: true

  index({"members.hbx_member_id" =>1})
  index({"members.ssn" => 1})
  index({"members.dob" => 1})
  accepts_nested_attributes_for :members, reject_if: :all_blank, allow_destroy: true

  scope :all_under_age_twenty_six, ->{ gt(:'members.dob' => (Date.today - 26.years))}
  scope :all_over_age_twenty_six,  ->{lte(:'members.dob' => (Date.today - 26.years))}

  # TODO: Add scope that accepts age range
  # scope :all_between_age_range, ->(range) {}

  scope :all_over_or_equal_age, ->(age) {lte(:'members.dob' => (Date.today - age.years))}
  scope :all_under_or_equal_age, ->(age) {gte(:'members.dob' => (Date.today - age.years))}
  scope :all_with_multiple_members, exists({ :'members.1' => true })
  scope :by_name, order_by(name_last: 1, name_first: 1)

  def update_attributes_with_delta(props = {})
{'fraction_non_alphanumeric': 0.1279475373238454, 'fraction_numerical': 0.008650760429747453, 'mean_word_length': 6.225806451612903, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 47, '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': '4398738', 'n_tokens_mistral': 2599, 'n_tokens_neox': 2480, 'n_words': 538}