Skip to content

Commit

Permalink
187603029 pivotal (#213)
Browse files Browse the repository at this point in the history
* Fixed Start Date Bug on Glue

* Fixed Start Date Bug on Glue

* latest updates

* latest updates

* latest updates
  • Loading branch information
jayreddy519 authored Aug 13, 2024
1 parent 6cc97b5 commit 203d243
Show file tree
Hide file tree
Showing 4 changed files with 207 additions and 10 deletions.
10 changes: 10 additions & 0 deletions app/business_processes/handlers/enrollment_event_xml_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ def extract_carrier_id(policy_cv)
Maybe.new(carrier).id.strip.split("#").last.value
end

def enrollee_start_for_member_id(policy_cv, member_id)
enrollee_list = Maybe.new(policy_cv).enrollees.value

enrollee_list ||= []
enrollee = enrollee_list.detect{|enrollee| extract_member_id(enrollee) == member_id}

return nil if enrollee.blank?
extract_enrollee_start(enrollee)
end

def extract_enrollee_end(enrollee)
val = Maybe.new(enrollee).benefit.end_date.strip.value
return nil if val.blank?
Expand Down
27 changes: 19 additions & 8 deletions app/models/enrollment_action/dependent_add.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,21 +56,32 @@ def publish
policy_to_change = termination.existing_policy
change_publish_helper = EnrollmentAction::ActionPublishHelper.new(action.event_xml)
enrollees = policy_to_change.try(:enrollees)
if enrollees.present?
enrollees.each do |en|
if en.c_id.present? || en.cp_id.present?
change_publish_helper.set_carrier_assigned_ids(en)
end
end
end
if @dep_adding_to_renewal
change_publish_helper.set_event_action("urn:openhbx:terms:v1:enrollment#auto_renew")
change_publish_helper.keep_member_ends([])
publish_edi(amqp_connection, change_publish_helper.to_xml, action.hbx_enrollment_id, action.employer_hbx_id)
else
member_date_map = {}
# pick policy members

policy_to_change.enrollees.each do |en|
member_date_map[en.m_id] = en.coverage_start
if en.coverage_end.blank?
member_date_map[en.m_id] = en.coverage_start
else
##en.coverage_end on the member
## start date of the members(from the XML)
## CHECK FOR DATE EXISTS?
member_start_from_xml = action.enrollee_start_for_member_id(action.policy_cv, en.m_id)
# coverage end of enrollee
# if that date is 1 day
# if member_start_from_xml nil?

next if member_start_from_xml.blank?

if en.coverage_end + 1.day >= member_start_from_xml
member_date_map[en.m_id] = en.coverage_start
end
end
end
change_publish_helper.set_policy_id(policy_to_change.eg_id)
change_publish_helper.set_member_starts(member_date_map)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,27 @@
end
end

describe "#enrollee_start_for_member_id" do
let(:member_id) { "54" }
let(:member) { instance_double(::Openhbx::Cv2::EnrolleeMember, id: "ABC##{member_id}") }
let(:benefit) { instance_double(::Openhbx::Cv2::EnrolleeBenefit, begin_date: "20170101") }
let(:enrollee) { instance_double(::Openhbx::Cv2::Enrollee, member: member, benefit: benefit) }
let(:other_enrollee) { instance_double(::Openhbx::Cv2::Enrollee, member: instance_double(::Openhbx::Cv2::EnrolleeMember, id: "DEF#99")) }
let(:policy_cv) { instance_double(::Openhbx::Cv2::Policy, enrollees: [other_enrollee, enrollee]) }

it "returns the start date for the given member id" do
expect(subject.enrollee_start_for_member_id(policy_cv, member_id)).to eq(Date.new(2017, 1, 1))
end

context "when the member id is not found" do
let(:policy_cv) { instance_double(::Openhbx::Cv2::Policy, enrollees: [other_enrollee]) }

it "returns nil" do
expect(subject.enrollee_start_for_member_id(policy_cv, member_id)).to be_nil
end
end
end

describe "#extract_enrollment_group_id" do
let(:policy_cv) { double(:id => "SOMEGRP#1234") }
it "returns the parsed id" do
Expand Down
159 changes: 157 additions & 2 deletions spec/models/enrollment_action/dependent_add_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@
let(:amqp_connection) { double }
let(:event_xml) { double }
let(:event_responder) { instance_double(::ExternalEvents::EventResponder, :connection => amqp_connection) }
let(:enrollee_primary) { double(:m_id => 1, :coverage_start => :one_month_ago, :c_id => nil, :cp_id => nil) }
let(:enrollee_new) { double(:m_id => 2, :coverage_start => :one_month_ago, :c_id => nil, :cp_id => nil) }
let(:enrollee_primary) { double(:m_id => 1, :coverage_start => :one_month_ago, :coverage_end => nil) }
let(:enrollee_new) { double(:m_id => 2, :coverage_start => :one_month_ago, :coverage_end => nil) }

let(:plan) { instance_double(Plan, :id => 1) }
let(:carrier) { instance_double(Carrier, :renewal_dependent_add_transmitted_as_renewal => true) }
Expand Down Expand Up @@ -695,4 +695,159 @@
subject.publish
end
end
end

describe EnrollmentAction::DependentAdd, "given overlapping coverage" do
let(:amqp_connection) { double }
let(:event_xml) { double }
let(:event_responder) { instance_double(::ExternalEvents::EventResponder, :connection => amqp_connection) }
let(:enrollee_primary) { double(:m_id => 1, :coverage_start => :one_month_ago, :coverage_end => nil) }
let(:enrollee_new) { double(:m_id => 2, :coverage_start => :one_month_ago, :coverage_end => enrollee_new_original_end) }

let(:enrollee_new_original_end) { Date.new(2024,5,29) }
let(:enrollee_new_xml_start) { Date.new(2024,5,29) }

let(:plan) { instance_double(Plan, :id => 1) }
let(:carrier) { instance_double(Carrier, :renewal_dependent_add_transmitted_as_renewal => true) }
let(:policy) { instance_double(Policy, :enrollees => [enrollee_primary, enrollee_new], :eg_id => 1, carrier: carrier) }
let(:policy_cv) { instance_double(::Openhbx::Cv2::Policy, enrollees: [enrollee_primary, enrollee_new]) }

let(:dependent_add_event) { instance_double(
::ExternalEvents::EnrollmentEventNotification,
:event_xml => event_xml,
:all_member_ids => [1,2],
:hbx_enrollment_id => 2,
employer_hbx_id: 1,
:policy_cv => policy_cv
) }
let(:termination_event) { instance_double(
::ExternalEvents::EnrollmentEventNotification,
:existing_policy => policy,
:all_member_ids => [1],
:event_responder => event_responder,
:hbx_enrollment_id => 1,
:employer_hbx_id => 1
) }
let(:action_helper_result_xml) { double }

let(:action_publish_helper) { instance_double(
EnrollmentAction::ActionPublishHelper,
:to_xml => action_helper_result_xml
) }

before :each do
allow(EnrollmentAction::ActionPublishHelper).to receive(:new).with(event_xml).and_return(action_publish_helper)
allow(action_publish_helper).to receive(:set_policy_id).with(1).and_return(true)
allow(action_publish_helper).to receive(:filter_affected_members).with([2]).and_return(true)
allow(action_publish_helper).to receive(:set_event_action).with("urn:openhbx:terms:v1:enrollment#change_member_add")
allow(action_publish_helper).to receive(:set_member_starts).with({ 1 => :one_month_ago, 2 => :one_month_ago })
allow(action_publish_helper).to receive(:keep_member_ends).with([])
allow(subject).to receive(:publish_edi).with(amqp_connection, action_helper_result_xml, termination_event.hbx_enrollment_id, termination_event.employer_hbx_id)
allow(subject).to receive(:same_carrier_renewal_candidates).with(dependent_add_event).and_return([])
allow(dependent_add_event).to receive(:enrollee_start_for_member_id).with(policy, 2).and_return(enrollee_new_xml_start)
allow(dependent_add_event).to receive(:policy_cv).and_return(policy)
end

subject do
EnrollmentAction::DependentAdd.new(termination_event, dependent_add_event)
end

it "publishes an event of type add dependents" do
expect(action_publish_helper).to receive(:set_event_action).with("urn:openhbx:terms:v1:enrollment#change_member_add")
subject.publish
end

it "sets member start dates" do
expect(action_publish_helper).to receive(:set_member_starts).with({ 1 => :one_month_ago, 2 => :one_month_ago })
subject.publish
end

it "clears all member end dates before publishing" do
expect(action_publish_helper).to receive(:keep_member_ends).with([])
subject.publish
end

it "publishes resulting xml to edi" do
expect(subject).to receive(:publish_edi).with(amqp_connection, action_helper_result_xml, termination_event.hbx_enrollment_id, termination_event.employer_hbx_id)
subject.publish
end

it "publishes an auto renew event when adding dependent to renewal" do
subject.dep_adding_to_renewal = true
allow(subject).to receive(:publish_edi).with(amqp_connection, action_helper_result_xml, dependent_add_event.hbx_enrollment_id, dependent_add_event.employer_hbx_id)
allow(EnrollmentAction::ActionPublishHelper).to receive(:new).with(dependent_add_event).and_return(action_publish_helper)
expect(action_publish_helper).to receive(:set_event_action).with("urn:openhbx:terms:v1:enrollment#auto_renew")
subject.publish
end
end

describe EnrollmentAction::DependentAdd, "given non overlapping coverage" do
let(:amqp_connection) { double }
let(:event_xml) { double }
let(:event_responder) { instance_double(::ExternalEvents::EventResponder, :connection => amqp_connection) }
let(:enrollee_primary) { double(:m_id => 1, :coverage_start => :one_month_ago, :coverage_end => nil) }
let(:enrollee_new) { double(:m_id => 2, :coverage_start => :one_month_ago, :coverage_end => enrollee_new_original_end) }

let(:enrollee_new_original_end) { Date.new(2024,5,25) }
let(:enrollee_new_xml_start) { Date.new(2024,5,29) }

let(:plan) { instance_double(Plan, :id => 1) }
let(:carrier) { instance_double(Carrier, :renewal_dependent_add_transmitted_as_renewal => true) }
let(:policy) { instance_double(Policy, :enrollees => [enrollee_primary, enrollee_new], :eg_id => 1, carrier: carrier) }
let(:policy_cv) { instance_double(::Openhbx::Cv2::Policy, enrollees: [enrollee_primary, enrollee_new]) }

let(:dependent_add_event) { instance_double(
::ExternalEvents::EnrollmentEventNotification,
:event_xml => event_xml,
:all_member_ids => [1,2],
:hbx_enrollment_id => 2,
employer_hbx_id: 1,
:policy_cv => policy_cv
) }
let(:termination_event) { instance_double(
::ExternalEvents::EnrollmentEventNotification,
:existing_policy => policy,
:all_member_ids => [1],
:event_responder => event_responder,
:hbx_enrollment_id => 1,
:employer_hbx_id => 1
) }
let(:action_helper_result_xml) { double }

let(:action_publish_helper) { instance_double(
EnrollmentAction::ActionPublishHelper,
:to_xml => action_helper_result_xml
) }

before :each do
allow(EnrollmentAction::ActionPublishHelper).to receive(:new).with(event_xml).and_return(action_publish_helper)
allow(action_publish_helper).to receive(:set_policy_id).with(1).and_return(true)
allow(action_publish_helper).to receive(:filter_affected_members).with([2]).and_return(true)
allow(action_publish_helper).to receive(:set_event_action).with("urn:openhbx:terms:v1:enrollment#change_member_add")
allow(action_publish_helper).to receive(:set_member_starts).with({ 1 => :one_month_ago }).and_return(true)
allow(action_publish_helper).to receive(:keep_member_ends).with([])
allow(subject).to receive(:publish_edi).with(amqp_connection, action_helper_result_xml, termination_event.hbx_enrollment_id, termination_event.employer_hbx_id)
allow(subject).to receive(:same_carrier_renewal_candidates).with(dependent_add_event).and_return([])
allow(dependent_add_event).to receive(:enrollee_start_for_member_id).with(policy, 2).and_return(enrollee_new_xml_start)
allow(dependent_add_event).to receive(:policy_cv).and_return(policy)
end

subject do
EnrollmentAction::DependentAdd.new(termination_event, dependent_add_event)
end

it "publishes an event of type add dependents" do
expect(action_publish_helper).to receive(:set_event_action).with("urn:openhbx:terms:v1:enrollment#change_member_add")
subject.publish
end

it "sets member start dates" do
expect(action_publish_helper).to receive(:set_member_starts).with({ 1 => :one_month_ago })
subject.publish
end

it "clears all member end dates before publishing" do
expect(action_publish_helper).to receive(:keep_member_ends).with([])
subject.publish
end
end

0 comments on commit 203d243

Please sign in to comment.