Skip to content

Commit

Permalink
Map incarceration status of applicant in ATP inbound process (#4063)
Browse files Browse the repository at this point in the history
* Map incarceration status of applicant in ATP inbound process

* fix rubocop issues

* update aca entities reference
  • Loading branch information
saipraveen18 authored Jul 29, 2024
1 parent d8094b6 commit 7eabf4b
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ GIT

GIT
remote: https://github.com/ideacrew/aca_entities.git
revision: 11a86c60092ba59f512cf117dc330614e66f8815
revision: 76f664dce913d31767227aa39221aaa0ebee31a2
branch: trunk
specs:
aca_entities (0.10.0)
Expand Down
42 changes: 30 additions & 12 deletions app/domain/operations/people/create_or_update.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,22 +44,40 @@ def create_entity(values)
def match_or_update_or_create_person(person_entity)
person = find_existing_person(person_entity.to_h)
#create new person
if person.blank?
person = Person.new(person_entity.to_h) #if person_valid_params.success?
person.save!
else
return Success(person) if no_infomation_changed?(params: { attributes_hash: person_entity, person: person })
person.assign_attributes(person_entity.except(:addresses, :phones, :emails, :hbx_id))
person.save!
create_or_update_associations(person, person_entity.to_h, :addresses)
create_or_update_associations(person, person_entity.to_h, :emails)
create_or_update_associations(person, person_entity.to_h, :phones)
end
Success(person)
person_record = if person.blank?
create_new_person(person_entity)
else
return Success(person) if no_infomation_changed?(params: { attributes_hash: person_entity, person: person })
update_existing_person(person, person_entity)
end
Success(person_record)
rescue StandardError => e
Failure(person.errors.messages)
end

def create_new_person(person_entity)
person_params = person_entity.to_h
person_params[:is_incarcerated] = person_params[:is_incarcerated].nil? ? false : person_params[:is_incarcerated]

person = Person.new(person_params)
person.save!

person
end

def update_existing_person(person, person_entity)
attributes_to_exclude = %i[addresses phones emails hbx_id]
attributes_to_exclude << :is_incarcerated if person_entity.to_h[:is_incarcerated].nil?
person.assign_attributes(person_entity.except(*attributes_to_exclude))
person.save!

%i[addresses emails phones].each do |association|
create_or_update_associations(person, person_entity.to_h, association)
end

person
end

def create_or_update_associations(person, applicant_params, assoc)
records = applicant_params[assoc.to_sym]
return if records.empty?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ def sanitize_applicant_params(iap_hash, primary)
is_veteran_or_active_military: applicant_hash['demographic']['is_veteran_or_active_military'],
is_vets_spouse_or_child: applicant_hash['demographic']['is_vets_spouse_or_child'],
same_with_primary: address_result.value!,
is_incarcerated: applicant_hash["is_incarcerated"],
is_incarcerated: family_member.person.is_incarcerated,
is_physically_disabled: applicant_hash['attestation']['is_self_attested_disabled'],
is_self_attested_disabled: applicant_hash['attestation']['is_self_attested_disabled'],
is_self_attested_blind: applicant_hash['attestation']['is_self_attested_blind'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,70 @@
end
end

context 'Incarceration status' do
context "when incarceration indicator does not exists for any applicant" do
let(:document) do
document = Nokogiri::XML(xml)
document.xpath('//hix-ee:InsuranceApplicantIncarceration', 'hix-ee' => "http://hix.cms.gov/0.1/hix-ee").each(&:remove)
document
end

it "should default the person/applicant incarceration status to false" do
record = serializer.parse(document.root.canonicalize, :single => true)
@transformed = transformer.transform(record.to_hash(identifier: true))
@result = subject.call(@transformed)
app = FinancialAssistance::Application.find(@result.value!)
expect(app.applicants.first.is_incarcerated).to eq false
expect(Person.all.first.is_incarcerated).to eq false
end
end

context "when incarceration indicator is set to true for all applicants" do
let(:document) do
document = Nokogiri::XML(xml)
document.xpath('//ns4:IncarcerationIndicator', 'ns4' => "http://hix.cms.gov/0.1/hix-core").each do |node|
node.content = 'true'
end
document
end

it "should default the person/applicant incarceration status to false" do
record = serializer.parse(document.root.canonicalize, :single => true)
@transformed = transformer.transform(record.to_hash(identifier: true))
@result = subject.call(@transformed)
app = FinancialAssistance::Application.find(@result.value!)
expect(app.applicants.first.is_incarcerated).to eq true
expect(Person.all.first.is_incarcerated).to eq true
end
end

context "when person records exits and the payload has incarceration set to nil in the payload" do
let!(:person) do
FactoryBot.create(:person, first_name: "Junior", last_name: "Banfield",
dob: Date.new(2014,1,1), is_incarcerated: true)
end

let(:document) do
document = Nokogiri::XML(xml)
document.xpath('//ns4:IncarcerationIndicator', 'ns4' => "http://hix.cms.gov/0.1/hix-core")[1].remove
document
end

it "should default the incarceration status to existing person value" do
record = serializer.parse(document.root.canonicalize, :single => true)
@transformed = transformer.transform(record.to_hash(identifier: true))
@result = subject.call(@transformed)
family_member = @transformed["family"]["family_members"].detect do |member|
member if member["person"]["person_name"]["first_name"] == person.first_name
end
matching_person = Person.all.where(first_name: "Junior").first
expect(matching_person).to be_present
expect(matching_person.is_incarcerated).to eq true
expect(family_member["person"]["person_demographics"]["is_incarcerated"]).not_to eq matching_person.is_incarcerated
end
end
end

context 'failure' do
context 'load_county_on_inbound_transfer feature is enabled' do
context 'with no counties loaded in database' do
Expand Down
12 changes: 12 additions & 0 deletions spec/domain/operations/people/create_or_update_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,18 @@
expect(@result).to be_a(Dry::Monads::Result::Success)
end
end

context 'nil incarceration status' do
before do
person_params.merge!({is_incarcerated: nil})
@result = subject.call(params: person_params)
end

it 'should return success' do
expect(@result).to be_a(Dry::Monads::Result::Success)
expect(@result.value!.is_incarcerated).to eq false
end
end
end

context 'for failed case' do
Expand Down

0 comments on commit 7eabf4b

Please sign in to comment.