app/models/forms/family_member.rb
def verify_unique_dependent
      # Only run on create
      return if self.persisted?
      return if family.blank? || family.family_members.blank?
      new_dependent = self
      # Don't use SSN in case there is no SSN
      potential_duplicate_present = family.family_members.active.any? do |family_member|
        family_member&.first_name == new_dependent.first_name &&
          family_member&.last_name == new_dependent.last_name &&
          family_member&.dob == new_dependent.dob
      end
      # Disabling rubocop because it seems like a guard clause changes behavior
      # rubocop:disable Style/GuardClause
      if potential_duplicate_present
        # Manage Family Page Redirect
        duplicate_message = l10n(
          'insured.family_members.duplicate_error_message',
          action: "add",
          contact_center_phone_number: EnrollRegistry[:enroll_app].settings(:contact_center_short_number).item
        )
        self.errors.add(:base, duplicate_message)
      end
      # rubocop:enable Style/GuardClause
    end
# TODO: This may have to also be in the family member model someday. Or applicant model,
# in the financial assistance engine. Who knows.
This may have to also be in the family member model someday. Or applicant model,
in the financial assistance engine. Who knows.
This may have to also be in the family member model someday . Or applicant model in the financial assistance engine . Who knows .
def verify_unique_dependent
      return if self.persisted?
      return if family.blank? || family.family_members.blank?
      new_dependent = self
      potential_duplicate_present = family.family_members.active.any? do |family_member|
        family_member&.first_name == new_dependent.first_name &&
          family_member&.last_name == new_dependent.last_name &&
          family_member&.dob == new_dependent.dob
      end
      if potential_duplicate_present
        duplicate_message = l10n(
          'insured.family_members.duplicate_error_message',
          action: "add",
          contact_center_phone_number: EnrollRegistry[:enroll_app].settings(:contact_center_short_number).item
        )
        self.errors.add(:base, duplicate_message)
      end
    end
def verify_unique_dependent return if self . persisted? return if family . blank? || family . family_members . blank? new_dependent = self potential_duplicate_present = family . family_members . active . any? do | family_member | family_member &. first_name == new_dependent . first_name && family_member &. last_name == new_dependent . last_name && family_member &. dob == new_dependent . dob end if potential_duplicate_present duplicate_message = l10n ( 'insured.family_members.duplicate_error_message' , action : "add" , contact_center_phone_number : EnrollRegistry [ :enroll_app ] . settings ( :contact_center_short_number ) . item ) self . errors . add ( :base , duplicate_message ) end end
TODO: This may have to also be in the family member model someday.
TODO : This may have to also be in the family member model someday .
# Only run on create # Don't use SSN in case there is no SSN # Disabling rubocop because it seems like a guard clause changes behavior # rubocop:disable Style/GuardClause # Manage Family Page Redirect # rubocop:enable Style/GuardClause