# frozen_string_literal: true

class HL7::Message::Segment::PID < HL7::Message::Segment
  weight 1
  has_children %i[NK1 NTE PV1 PV2]
  add_field :set_id
  add_field :patient_id
  add_field :patient_id_list
  add_field :alt_patient_id
  add_field :patient_name
  add_field :mother_maiden_name
  add_field :patient_dob do |value|
    convert_to_ts(value)
  end
  add_field :admin_sex do |sex|
    sanitize_admin_sex!(sex)
  end
  add_field :patient_alias
  add_field :race
  add_field :address
  add_field :county_code
  add_field :phone_home
  add_field :phone_business
  add_field :primary_language
  add_field :marital_status
  add_field :religion
  add_field :account_number
  add_field :social_security_num
  add_field :driver_license_num
  add_field :mothers_id
  add_field :ethnic_group
  add_field :birthplace
  add_field :multi_birth
  add_field :birth_order
  add_field :citizenship
  add_field :vet_status
  add_field :nationality
  add_field :death_date do |value|
    convert_to_ts(value)
  end
  add_field :death_indicator
  add_field :id_unknown_indicator
  add_field :id_reliability_code
  add_field :last_update_date do |value|
    convert_to_ts(value)
  end
  add_field :last_update_facility
  add_field :species_code
  add_field :breed_code
  add_field :strain
  add_field :production_class_code
  add_field :tribal_citizenship

  def country_code
    warn "DEPRECATION WARNING: PID-12 is defined as 'county_code'; " \
         "the 'country_code' alias is retained for backwards compatibility only."
    county_code
  end

  def country_code=(country_code)
    warn "DEPRECATION WARNING: PID-12 is defined as 'county_code'; " \
         "the 'country_code' alias is retained for backwards compatibility only."
    self.county_code = country_code
  end

  def id_readability_code
    warn "DEPRECATION WARNING: PID-32 is defined as 'id_reliability_code'; " \
         "the 'id_readability_code' alias is retained for backwards compatibility only."
    id_reliability_code
  end

  def id_readability_code=(code)
    warn "DEPRECATION WARNING: PID-32 is defined as 'id_reliability_code'; " \
         "the 'id_readability_code' alias is retained for backwards compatibility only."
    self.id_reliability_code = code
  end
end