2019-07-25 18:09:55 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-07-25 20:46:35 -04:00
|
|
|
class ImportPerson # rubocop:disable Metrics/ClassLength
|
2019-07-25 18:09:55 -04:00
|
|
|
include Interactor
|
|
|
|
|
2019-07-25 20:46:35 -04:00
|
|
|
def call # rubocop:disable Metrics/MethodLength
|
2019-07-25 18:09:55 -04:00
|
|
|
ActiveRecord::Base.transaction do
|
|
|
|
create_person
|
2019-07-25 20:46:35 -04:00
|
|
|
create_passport
|
2019-07-25 18:18:10 -04:00
|
|
|
create_general_comments_person_comment
|
2019-07-25 18:30:17 -04:00
|
|
|
create_first_contact_date_person_comment
|
2019-07-25 18:42:25 -04:00
|
|
|
create_latest_contact_date_person_comment
|
2019-07-25 20:08:48 -04:00
|
|
|
create_human_readable_id_person_comment
|
2019-07-25 20:15:41 -04:00
|
|
|
create_past_experience_person_comment
|
2019-07-25 20:18:18 -04:00
|
|
|
create_aid_at_2014_elections_person_comment
|
2019-07-25 20:19:19 -04:00
|
|
|
create_aid_at_2015_elections_person_comment
|
2019-07-25 18:09:55 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def create_person
|
2019-07-25 18:35:33 -04:00
|
|
|
context.person = Person.where(id: person_id).lock(true).first_or_create!(
|
|
|
|
person_attributes.reverse_merge(
|
2019-07-29 01:36:39 -04:00
|
|
|
contact_list: ContactList.new,
|
2019-07-25 18:35:33 -04:00
|
|
|
),
|
|
|
|
)
|
2019-07-25 18:09:55 -04:00
|
|
|
end
|
|
|
|
|
2019-07-25 18:40:04 -04:00
|
|
|
# rubocop:disable Metrics/AbcSize
|
|
|
|
|
2019-07-25 21:24:30 -04:00
|
|
|
def create_passport # rubocop:disable Metrics/MethodLength
|
|
|
|
return if passport_attributes[:number].blank?
|
|
|
|
|
2019-07-25 20:46:35 -04:00
|
|
|
context.passport =
|
|
|
|
Passport
|
|
|
|
.where(person_id: context.person.id).lock(true).first_or_initialize
|
|
|
|
|
|
|
|
context.passport.federal_subject = FederalSubject.find_by id: region_id
|
|
|
|
|
|
|
|
passport_attributes.each do |(key, value)|
|
|
|
|
context.passport.public_send "#{key}=", value
|
|
|
|
end
|
|
|
|
|
|
|
|
context.passport.save!
|
|
|
|
rescue
|
|
|
|
context.passport = nil
|
|
|
|
end
|
|
|
|
|
2019-07-25 18:18:10 -04:00
|
|
|
def create_general_comments_person_comment
|
2019-07-25 18:35:33 -04:00
|
|
|
return if general_comments.blank?
|
2019-07-25 18:18:10 -04:00
|
|
|
|
|
|
|
context.general_comments_person_comment =
|
2019-07-25 18:43:58 -04:00
|
|
|
context
|
|
|
|
.person.person_comments.where(origin: :general_comments).lock(true)
|
|
|
|
.first_or_initialize
|
2019-07-25 18:18:10 -04:00
|
|
|
|
2019-07-25 18:35:33 -04:00
|
|
|
context.general_comments_person_comment.text = general_comments
|
2019-07-25 18:18:10 -04:00
|
|
|
|
|
|
|
context.general_comments_person_comment.save!
|
|
|
|
end
|
|
|
|
|
2019-07-25 18:30:17 -04:00
|
|
|
def create_first_contact_date_person_comment
|
2019-07-25 18:35:33 -04:00
|
|
|
return if first_contact_date.blank?
|
2019-07-25 18:30:17 -04:00
|
|
|
|
|
|
|
context.first_contact_date_person_comment =
|
2019-07-25 18:43:58 -04:00
|
|
|
context
|
|
|
|
.person.person_comments.where(origin: :first_contact_date).lock(true)
|
|
|
|
.first_or_initialize
|
2019-07-25 18:30:17 -04:00
|
|
|
|
2019-07-25 18:35:33 -04:00
|
|
|
context.first_contact_date_person_comment.text = first_contact_date
|
2019-07-25 18:30:17 -04:00
|
|
|
|
|
|
|
context.first_contact_date_person_comment.save!
|
|
|
|
end
|
|
|
|
|
2019-07-25 18:42:25 -04:00
|
|
|
def create_latest_contact_date_person_comment
|
|
|
|
return if latest_contact_date.blank?
|
|
|
|
|
|
|
|
context.latest_contact_date_person_comment =
|
2019-07-25 18:43:58 -04:00
|
|
|
context
|
|
|
|
.person.person_comments.where(origin: :latest_contact_date).lock(true)
|
|
|
|
.first_or_initialize
|
2019-07-25 18:42:25 -04:00
|
|
|
|
|
|
|
context.latest_contact_date_person_comment.text = latest_contact_date
|
|
|
|
|
|
|
|
context.latest_contact_date_person_comment.save!
|
|
|
|
end
|
|
|
|
|
2019-07-25 20:08:48 -04:00
|
|
|
def create_human_readable_id_person_comment
|
|
|
|
return if human_readable_id.blank?
|
|
|
|
|
|
|
|
context.human_readable_id_person_comment =
|
|
|
|
context
|
|
|
|
.person.person_comments.where(origin: :human_readable_id).lock(true)
|
|
|
|
.first_or_initialize
|
|
|
|
|
|
|
|
context.human_readable_id_person_comment.text = human_readable_id
|
|
|
|
|
|
|
|
context.human_readable_id_person_comment.save!
|
|
|
|
end
|
|
|
|
|
2019-07-25 20:15:41 -04:00
|
|
|
def create_past_experience_person_comment
|
|
|
|
return if past_experience.blank?
|
|
|
|
|
|
|
|
context.past_experience_person_comment =
|
|
|
|
context
|
|
|
|
.person.person_comments.where(origin: :past_experience).lock(true)
|
|
|
|
.first_or_initialize
|
|
|
|
|
|
|
|
context.past_experience_person_comment.text = past_experience
|
|
|
|
|
|
|
|
context.past_experience_person_comment.save!
|
|
|
|
end
|
|
|
|
|
2019-07-25 20:18:18 -04:00
|
|
|
def create_aid_at_2014_elections_person_comment
|
|
|
|
return if aid_at_2014_elections.blank?
|
|
|
|
|
|
|
|
context.aid_at_2014_elections_person_comment =
|
|
|
|
context
|
2019-07-25 20:49:05 -04:00
|
|
|
.person.person_comments.where(origin: :aid_at_2014_elections).lock(true)
|
2019-07-25 20:18:18 -04:00
|
|
|
.first_or_initialize
|
|
|
|
|
2019-07-25 20:49:05 -04:00
|
|
|
context.aid_at_2014_elections_person_comment.text = aid_at_2014_elections
|
2019-07-25 20:18:18 -04:00
|
|
|
|
|
|
|
context.aid_at_2014_elections_person_comment.save!
|
|
|
|
end
|
|
|
|
|
2019-07-25 20:19:19 -04:00
|
|
|
def create_aid_at_2015_elections_person_comment
|
|
|
|
return if aid_at_2015_elections.blank?
|
|
|
|
|
|
|
|
context.aid_at_2015_elections_person_comment =
|
|
|
|
context
|
2019-07-25 20:49:05 -04:00
|
|
|
.person.person_comments.where(origin: :aid_at_2015_elections).lock(true)
|
2019-07-25 20:19:19 -04:00
|
|
|
.first_or_initialize
|
|
|
|
|
2019-07-25 20:49:05 -04:00
|
|
|
context.aid_at_2015_elections_person_comment.text = aid_at_2015_elections
|
2019-07-25 20:19:19 -04:00
|
|
|
|
|
|
|
context.aid_at_2015_elections_person_comment.save!
|
|
|
|
end
|
|
|
|
|
2019-07-25 18:35:33 -04:00
|
|
|
def person_id
|
2019-07-25 21:24:30 -04:00
|
|
|
context.row[0].presence
|
2019-07-25 18:35:33 -04:00
|
|
|
end
|
|
|
|
|
2019-07-25 20:46:35 -04:00
|
|
|
def region_id
|
2019-07-25 21:24:30 -04:00
|
|
|
context.row[14].presence
|
2019-07-25 20:46:35 -04:00
|
|
|
end
|
|
|
|
|
2019-07-25 18:09:55 -04:00
|
|
|
def person_attributes
|
|
|
|
{
|
2019-07-25 21:24:30 -04:00
|
|
|
last_name: context.row[2].presence,
|
|
|
|
first_name: context.row[1].presence,
|
|
|
|
middle_name: context.row[3].presence,
|
2019-07-25 18:35:33 -04:00
|
|
|
sex: nil,
|
2019-07-25 21:24:30 -04:00
|
|
|
date_of_birth: context.row[8].presence,
|
|
|
|
place_of_birth: context.row[9].presence,
|
2019-07-25 18:09:55 -04:00
|
|
|
}
|
|
|
|
end
|
2019-07-25 18:35:33 -04:00
|
|
|
|
2019-07-25 20:46:35 -04:00
|
|
|
def passport_attributes # rubocop:disable Metrics/MethodLength
|
|
|
|
{
|
2019-07-25 21:24:30 -04:00
|
|
|
last_name: context.row[2].presence,
|
|
|
|
first_name: context.row[1].presence,
|
|
|
|
middle_name: context.row[3].presence,
|
2019-07-25 20:46:35 -04:00
|
|
|
sex: :male,
|
2019-07-25 21:24:30 -04:00
|
|
|
date_of_birth: context.row[8].presence,
|
|
|
|
place_of_birth: context.row[9].presence,
|
|
|
|
|
|
|
|
series: context.row[38].presence,
|
|
|
|
number: context.row[10].presence,
|
|
|
|
issued_by: context.row[11].presence,
|
|
|
|
unit_code: context.row[12].presence,
|
|
|
|
date_of_issue: context.row[13].presence,
|
|
|
|
zip_code: context.row[15].presence,
|
|
|
|
|
|
|
|
town_type: context.row[20].presence,
|
|
|
|
town_name: context.row[21].presence,
|
|
|
|
settlement_type: context.row[22].presence,
|
|
|
|
settlement_name: context.row[23].presence,
|
|
|
|
district_type: context.row[18].presence,
|
|
|
|
district_name: context.row[19].presence,
|
|
|
|
street_type: context.row[16].presence,
|
|
|
|
street_name: context.row[17].presence,
|
|
|
|
residence_type: context.row[24].presence,
|
|
|
|
residence_name: context.row[25].presence,
|
|
|
|
building_type: context.row[26].presence,
|
|
|
|
building_name: context.row[27].presence,
|
|
|
|
apartment_type: context.row[28].presence,
|
|
|
|
apartment_name: context.row[29].presence,
|
2019-07-25 20:46:35 -04:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
# rubocop:enable Metrics/AbcSize
|
|
|
|
|
2019-07-25 18:35:33 -04:00
|
|
|
def general_comments
|
2019-07-25 21:24:30 -04:00
|
|
|
context.row[5].presence
|
2019-07-25 18:35:33 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def first_contact_date
|
2019-07-25 21:24:30 -04:00
|
|
|
context.row[6].presence
|
2019-07-25 18:35:33 -04:00
|
|
|
end
|
2019-07-25 18:42:25 -04:00
|
|
|
|
|
|
|
def latest_contact_date
|
2019-07-25 21:24:30 -04:00
|
|
|
context.row[7].presence
|
2019-07-25 18:42:25 -04:00
|
|
|
end
|
2019-07-25 20:08:48 -04:00
|
|
|
|
|
|
|
def human_readable_id
|
2019-07-25 21:24:30 -04:00
|
|
|
context.row[34].presence
|
2019-07-25 20:08:48 -04:00
|
|
|
end
|
2019-07-25 20:15:41 -04:00
|
|
|
|
|
|
|
def past_experience
|
2019-07-25 21:24:30 -04:00
|
|
|
context.row[35].presence
|
2019-07-25 20:15:41 -04:00
|
|
|
end
|
2019-07-25 20:18:18 -04:00
|
|
|
|
2019-07-25 20:49:05 -04:00
|
|
|
def aid_at_2014_elections
|
2019-07-25 21:24:30 -04:00
|
|
|
context.row[36].presence
|
2019-07-25 20:18:18 -04:00
|
|
|
end
|
2019-07-25 20:19:19 -04:00
|
|
|
|
2019-07-25 20:49:05 -04:00
|
|
|
def aid_at_2015_elections
|
2019-07-25 21:24:30 -04:00
|
|
|
context.row[37].presence
|
2019-07-25 20:19:19 -04:00
|
|
|
end
|
2019-07-25 18:09:55 -04:00
|
|
|
end
|