Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

is_homeless indicator should use ApplicantFixedAddress tag #466

Draft
wants to merge 2 commits into
base: trunk
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/aca_entities/atp/functions/relationship_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,14 @@ def call(cache)
private

def person_hash
dob_value = @memoized_data.find(Regexp.new("person.person_demographics.dob.#{@primary_applicant_id}"))&.first&.item
dob = dob_value ? Date.parse(dob_value) : nil

{ hbx_id: '1234', # default value
first_name: @memoized_data.find(Regexp.new("person_name.first_name.#{@primary_applicant_id}"))&.first&.item&.capitalize,
last_name: @memoized_data.find(Regexp.new("person_name.last_name.#{@primary_applicant_id}"))&.first&.item&.capitalize,
gender: @memoized_data.find(Regexp.new("person.person_demographics.gender.#{@primary_applicant_id}"))&.first&.item&.capitalize,
dob: @memoized_data.find(Regexp.new("person.person_demographics.dob.#{@primary_applicant_id}"))&.first&.item&.to_date,
dob: dob,
ssn: encrypt_ssn(@memoized_data.find(Regexp.new("person.person_demographics.ssn.#{@primary_applicant_id}"))&.first&.item) }
end

Expand Down
11 changes: 9 additions & 2 deletions lib/aca_entities/atp/transformers/cv/family.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,15 @@ class Family < ::AcaEntities::Operations::Transforms::Transform
add_key 'person.addresses', memoize_record: true, function: AcaEntities::Atp::Functions::AddressBuilder.new
add_key 'person.is_homeless', function: lambda { |v|
member_id = v.find(/record.people.(\w+)$/).map(&:item).last
contacts_information = v.find(Regexp.new("record.people.#{member_id}.augementation")).map(&:item).last[:contacts]
contacts_information.select { |co| co[:category_code].downcase == "home" && co[:contact][:mailing_address].present? }.empty?
applicants = v.resolve(:'insurance_application.insurance_applicants').item
fixed_address_indicator = applicants.dig(member_id.to_sym, :fixed_address_indicator)

if fixed_address_indicator.nil?
contacts_information = v.find(Regexp.new("record.people.#{member_id}.augementation")).map(&:item).last[:contacts]
contacts_information.select { |co| co[:category_code].downcase == "home" && co[:contact][:mailing_address].present? }.empty?
else
!fixed_address_indicator
end
}
add_key 'person.emails', function: lambda {|v|
# revisit if condition for emails and phone for dependents
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,12 @@ def to_hash(identifier: false) # rubocop:disable Metrics/CyclomaticComplexity, M
record: identifier ? { people: people.map(&:to_hash).group_by {|h| h[:id]}.transform_keys(&:to_s).transform_values(&:first) } : nil,
people: identifier ? nil : people.map(&:to_hash),
physical_households: physical_households&.map(&:to_hash),
assister: assister&.map(&:to_hash)
assister: assister&.to_hash
}
end
end
end
end
end
end
end
end
67 changes: 67 additions & 0 deletions spec/aca_entities/atp/transformers/cv/family_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# frozen_string_literal: true

require 'spec_helper'
require 'aca_entities/medicaid/atp'
require 'aca_entities/serializers/xml/medicaid/atp'
require 'aca_entities/atp/transformers/cv/family'

RSpec.describe AcaEntities::Atp::Transformers::Cv::Family do
let(:payload) { File.read(Pathname.pwd.join("spec/support/atp/sample_payloads/sample.xml")) }

let(:document) do
Nokogiri::XML(payload)
end

let(:account_transfer_request) do
::AcaEntities::Serializers::Xml::Medicaid::Atp::AccountTransferRequest.parse(document.root.canonicalize, :single => true)
end

describe 'When fixed address indicator passed as true' do

it 'should set homeless indicator false' do
transformed = ::AcaEntities::Atp::Transformers::Cv::Family.transform(account_transfer_request.to_hash(identifier: true))

transformed.dig(:family, :family_members).each do |family_member|
expect(family_member.dig(:person, :is_homeless)).to be_falsey
end
end
end

describe 'When fixed address indicator not passed in xml' do
let(:document) do
document = Nokogiri::XML(payload)
document.xpath('//ns5:InsuranceApplicantFixedAddressIndicator', 'ns5' => 'http://hix.cms.gov/0.1/hix-ee').each do |node|
node.remove
end
document
end

it 'should set homeless indicator based on addresses' do
transformed = ::AcaEntities::Atp::Transformers::Cv::Family.transform(account_transfer_request.to_hash(identifier: true))

transformed.dig(:family, :family_members).each do |family_member|
expect(family_member.dig(:person, :is_homeless)).to be_falsey
end
end
end

describe 'When fixed address indicator passed as false' do
let(:document) do
document = Nokogiri::XML(payload)
document.xpath('//ns5:InsuranceApplicantFixedAddressIndicator', 'ns5' => 'http://hix.cms.gov/0.1/hix-ee').each do |node|
node.content = 'false'
end
document
end

let(:expected_homeless_indicators) { [true, true, false] }

it 'should set homeless indicator true' do
transformed = ::AcaEntities::Atp::Transformers::Cv::Family.transform(account_transfer_request.to_hash(identifier: true))

transformed.dig(:family, :family_members).each_with_index do |family_member, index|
expect(family_member.dig(:person, :is_homeless)).to eq(expected_homeless_indicators[index])
end
end
end
end
Loading