Skip to content

Commit

Permalink
fix AI/AN mapping on person/applicant in inbound ATP transfer (#4103)
Browse files Browse the repository at this point in the history
* fix AI/AN mapping on person/applicant in inbound ATP transfer

* fix rubocop issues

---------

Signed-off-by: Sai Praveen Gudimetla <[email protected]>
  • Loading branch information
saipraveen18 authored Aug 5, 2024
1 parent 347dbcd commit 80d35e8
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 19 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: 76f664dce913d31767227aa39221aaa0ebee31a2
revision: d3aba9dde2a1efaa66a5aaf8560c64cc4fe0f921
branch: trunk
specs:
aca_entities (0.10.0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,20 +132,26 @@ def find_family(family_hash)
person_params_result = sanitize_person_params(family_hash['family_members'].select { |a| a["is_primary_applicant"] == true}.first)
return person_params_result if person_params_result.failure?
person_params = person_params_result.value!
match_criteria, records = ::Operations::People::Match.new.call({:dob => person_params[:dob],
:last_name => person_params[:last_name],
:first_name => person_params[:first_name],
:ssn => person_params[:ssn]})
return Success(nil) unless records.present?
return Success(nil) unless [:ssn_present, :dob_present].include?(match_criteria)
return Success(nil) if match_criteria == :dob_present && person_params[:ssn].present? && records.first.ssn != person_params[:ssn]

person = records.first
person = fetch_person(person_params)
return Success(nil) if person.blank?

Success(person.primary_family)
rescue StandardError => e
Failure("find family error #{e}")
end

def fetch_person(person_params)
match_criteria, records = ::Operations::People::Match.new.call({:dob => person_params[:dob],
:last_name => person_params[:last_name],
:first_name => person_params[:first_name],
:ssn => person_params[:ssn]})
return unless records.present?
return unless [:ssn_present, :dob_present].include?(match_criteria)
return if match_criteria == :dob_present && person_params[:ssn].present? && records.first.ssn != person_params[:ssn]

records.first
end

def build_family(family_hash)
found_family_result = find_family(family_hash)
return found_family_result unless found_family_result.success?
Expand Down Expand Up @@ -198,7 +204,8 @@ def create_member(family_member_hash)
person_params_result = sanitize_person_params(family_member_hash)
return person_params_result unless person_params_result.success?
person_params = person_params_result.value!
person_result = create_or_update_person(person_params)
updated_person_params = fetch_updated_person_params(person_params)
person_result = create_or_update_person(updated_person_params)
if person_result.success?
@person = person_result.success
fam_result = create_or_update_family_member(@person, @family, family_member_hash)
Expand All @@ -217,6 +224,17 @@ def create_member(family_member_hash)
Failure("create_member: #{e}")
end

def fetch_updated_person_params(person_params)
person = fetch_person(person_params)
return person_params if person.blank?

if person_params[:indian_tribe_member].nil?
attributes_to_exclude = [:tribal_name, :tribal_state, :tribal_id,
:indian_tribe_member]
end
person_params.except(*attributes_to_exclude)
end

def create_or_update_person(person_params)
::Operations::People::CreateOrUpdate.new.call(params: person_params)
rescue StandardError => e
Expand Down Expand Up @@ -435,10 +453,10 @@ def sanitize_applicant_params(iap_hash, primary)
had_prior_insurance: applicant_hash['had_prior_insurance'],
age_of_applicant: applicant_hash['age_of_applicant'],
hours_worked_per_week: applicant_hash['hours_worked_per_week'],
indian_tribe_member: applicant_hash['indian_tribe_member'],
tribal_id: applicant_hash['tribal_id'],
tribal_name: applicant_hash['tribal_name'],
tribal_state: applicant_hash['tribal_state'],
indian_tribe_member: family_member.person.indian_tribe_member,
tribal_id: family_member.person.tribal_id,
tribal_name: family_member.person.tribal_name,
tribal_state: family_member.person.tribal_state,
transfer_referral_reason: applicant_hash['transfer_referral_reason']
}
end
Expand Down Expand Up @@ -480,6 +498,7 @@ def build_person_hash(person_hash, consumer_role_hash)
race: consumer_role_hash['is_applying_coverage'] ? person_hash['race'] : nil,
ethnicity: consumer_role_hash['is_applying_coverage'] ? person_hash['person_demographics']['ethnicity'] : [],
is_incarcerated: consumer_role_hash['is_applying_coverage'] ? person_hash['person_demographics']['is_incarcerated'] : nil,
indian_tribe_member: person_hash['person_demographics']['indian_tribe_member'],
tribal_id: person_hash['person_demographics']['tribal_id'],
tribal_name: person_hash['person_demographics']['tribal_name'],
tribal_state: person_hash['person_demographics']['tribal_state'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,76 @@
end
end

context 'AI/AN status' do
context "when PersonAmericanIndianOrAlaskaNativeIndicator does not exists for any applicant" do
let(:document) do
document = Nokogiri::XML(xml)
document.xpath('//ns4:PersonAmericanIndianOrAlaskaNativeIndicator', 'ns4' => "http://hix.cms.gov/0.1/hix-core").each(&:remove)
document
end

it "should default the person/applicant indian_tribe_member 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.indian_tribe_member).to eq false
expect(Person.all.first.indian_tribe_member).to eq false
end
end

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

it "should default the person/applicant indian_tribe_member 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.indian_tribe_member).to eq false
expect(Person.all.first.indian_tribe_member).to eq false
end
end

context "when person records exits and the payload is missing PersonAmericanIndianOrAlaskaNativeIndicator element" do
let!(:person) do
FactoryBot.create(:person, first_name: "Junior", last_name: "Banfield",
dob: Date.new(2014,1,1), is_incarcerated: true,
tribal_name: "Tribe name", tribal_state: "ME", indian_tribe_member: true)
end

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

it "should not override the existing tribal_name/tribal_state/indian_tribe_member values" do
allow(EnrollRegistry[:indian_alaskan_tribe_details].feature).to receive(:is_enabled).and_return(true)
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.tribal_name).to eq person.tribal_name
expect(matching_person.tribal_state).to eq person.tribal_state
expect(matching_person.indian_tribe_member).to eq person.indian_tribe_member
expect(family_member["person"]["person_demographics"]["tribal_name"]).not_to eq matching_person.tribal_name
expect(family_member["person"]["person_demographics"]["tribal_state"]).not_to eq matching_person.tribal_state
expect(family_member["person"]["person_demographics"]["indian_tribe_member"]).not_to eq matching_person.indian_tribe_member
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
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,10 @@
<ns2:PersonSexText>Female</ns2:PersonSexText>
<ns2:PersonUSCitizenIndicator ns1:metadata="vm2009583325215611506">true</ns2:PersonUSCitizenIndicator>
<ns4:TribalAugmentation>
<ns4:PersonAmericanIndianOrAlaskaNativeIndicator>false</ns4:PersonAmericanIndianOrAlaskaNativeIndicator>
<ns4:PersonRecognizedTribeIndicator>true</ns4:PersonRecognizedTribeIndicator>
<ns4:PersonAmericanIndianOrAlaskaNativeIndicator>true</ns4:PersonAmericanIndianOrAlaskaNativeIndicator>
<ns4:PersonTribeName>Eastern Band of Cherokee Indians of North Carolina</ns4:PersonTribeName>
<ns2:LocationStateUSPostalServiceCode>ME</ns2:LocationStateUSPostalServiceCode>
</ns4:TribalAugmentation>
<ns4:PersonAugmentation>
<ns4:PersonAssociation>
Expand Down Expand Up @@ -463,9 +466,12 @@
<ns2:IdentificationID>218725469</ns2:IdentificationID>
</ns2:PersonSSNIdentification>
<ns2:PersonUSCitizenIndicator ns1:metadata="vm2009583325215611506">true</ns2:PersonUSCitizenIndicator>
<ns4:TribalAugmentation>
<ns4:PersonAmericanIndianOrAlaskaNativeIndicator>false</ns4:PersonAmericanIndianOrAlaskaNativeIndicator>
</ns4:TribalAugmentation>
<ns4:TribalAugmentation>
<ns4:PersonRecognizedTribeIndicator>true</ns4:PersonRecognizedTribeIndicator>
<ns4:PersonAmericanIndianOrAlaskaNativeIndicator>true</ns4:PersonAmericanIndianOrAlaskaNativeIndicator>
<ns4:PersonTribeName>Eastern Band of Cherokee Indians of North Carolina</ns4:PersonTribeName>
<ns2:LocationStateUSPostalServiceCode>ME</ns2:LocationStateUSPostalServiceCode>
</ns4:TribalAugmentation>
<ns4:PersonAugmentation>
<ns4:PersonAssociation>
<ns2:AssociationBeginDate>
Expand Down

0 comments on commit 80d35e8

Please sign in to comment.