Skip to content

Commit

Permalink
Merge pull request #55 from ideacrew/180365353-fix-missing-terms (#187)
Browse files Browse the repository at this point in the history
Correct missing terminations and incorrect interpretation of events.

Co-authored-by: Trey <[email protected]>
Co-authored-by: Raghu Ram <[email protected]>
  • Loading branch information
3 people authored Mar 27, 2024
1 parent 430eef4 commit 995083f
Show file tree
Hide file tree
Showing 3 changed files with 146 additions and 14 deletions.
19 changes: 13 additions & 6 deletions app/models/external_events/enrollment_event_notification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ class EnrollmentEventNotification

include Handlers::EnrollmentEventXmlHelper

COVERAGE_START_EVENTS = [
"urn:openhbx:terms:v1:enrollment#initial",
"urn:openhbx:terms:v1:enrollment#auto_renew",
"urn:openhbx:terms:v1:enrollment#active_renew"
]

def initialize(e_responder, m_tag, t_stamp, e_xml, headers)
@business_process_history = Array.new
@errors = ActiveModel::Errors.new(self)
Expand Down Expand Up @@ -62,7 +68,7 @@ def drop_if_term_with_no_end!
def drop_if_already_processed!
found_event = ::EnrollmentAction::EnrollmentActionIssue.where(
:hbx_enrollment_id => hbx_enrollment_id,
:enrollment_action_uri => enrollment_action
:enrollment_action_uri => {"$in" => event_search_uri}
)
if found_event.any?
if is_reterm_with_earlier_date?
Expand All @@ -77,6 +83,11 @@ def drop_if_already_processed!
end
end

def event_search_uri
return COVERAGE_START_EVENTS if is_coverage_starter?
["urn:openhbx:terms:v1:enrollment#terminate_enrollment"]
end

def drop_if_bogus_term!
return false unless @bogus_termination
response_with_publisher do |result_publisher|
Expand Down Expand Up @@ -203,11 +214,7 @@ def duplicates?(other)
end

def is_coverage_starter?
[
"urn:openhbx:terms:v1:enrollment#initial",
"urn:openhbx:terms:v1:enrollment#auto_renew",
"urn:openhbx:terms:v1:enrollment#active_renew"
].include?(enrollment_action)
COVERAGE_START_EVENTS.include?(enrollment_action)
end

def edge_for(graph, other)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,31 @@ class RemoveSameActionsAndSelectSilent
def filter(full_event_list)
full_event_list.inject([]) do |acc, event|
duplicate_found = acc.detect do |item|
[event.hbx_enrollment_id, event.enrollment_action] == [item.hbx_enrollment_id, item.enrollment_action]
[event.hbx_enrollment_id, event_comparison_action(event.enrollment_action)] == [item.hbx_enrollment_id, event_comparison_action(item.enrollment_action)]
end
if duplicate_found
# Favor the event marked as silent
# Favor the event marked as silent in the case of terminations
if duplicate_found && event.is_termination?
if (!duplicate_found.is_publishable?)
event.drop_payload_duplicate!
acc
elsif (!event.is_publishable?)
filtered_accs = acc.reject do |item|
[event.hbx_enrollment_id, event.enrollment_action] == [item.hbx_enrollment_id, item.enrollment_action]
[event.hbx_enrollment_id, event_comparison_action(event.enrollment_action)] == [item.hbx_enrollment_id, event_comparison_action(item.enrollment_action)]
end
duplicate_found.drop_payload_duplicate!
filtered_accs + [event]
else
event.drop_payload_duplicate!
acc
end
# In the case of initials, favor the event marked as auto_renewal if it exists
elsif duplicate_found && event.is_coverage_starter?
if (duplicate_found.is_passive_renewal?)
event.drop_payload_duplicate!
acc
elsif (event.is_passive_renewal?)
filtered_accs = acc.reject do |item|
[event.hbx_enrollment_id, event_comparison_action(event.enrollment_action)] == [item.hbx_enrollment_id, event_comparison_action(item.enrollment_action)]
end
duplicate_found.drop_payload_duplicate!
filtered_accs + [event]
Expand All @@ -26,6 +41,12 @@ def filter(full_event_list)
end
end
end

def event_comparison_action(event_action)
events_counting_as_coverage_selected = ExternalEvents::EnrollmentEventNotification::COVERAGE_START_EVENTS
return "urn:openhbx:terms:v1:enrollment#initial" if events_counting_as_coverage_selected.include?(event_action)
event_action
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
::ExternalEvents::EnrollmentEventNotification,
:hbx_enrollment_id => "A",
:enrollment_action => "terminate",
:is_publishable? => true
:is_publishable? => true,
:is_termination? => true
)
end

Expand All @@ -19,7 +20,8 @@
::ExternalEvents::EnrollmentEventNotification,
:hbx_enrollment_id => "A",
:enrollment_action => "terminate",
:is_publishable? => false
:is_publishable? => false,
:is_termination? => true
)
end

Expand Down Expand Up @@ -54,7 +56,8 @@
::ExternalEvents::EnrollmentEventNotification,
:hbx_enrollment_id => "A",
:enrollment_action => "terminate",
:is_publishable? => true
:is_publishable? => true,
:is_termination? => true
)
end

Expand All @@ -63,7 +66,8 @@
::ExternalEvents::EnrollmentEventNotification,
:hbx_enrollment_id => "A",
:enrollment_action => "terminate",
:is_publishable? => false
:is_publishable? => false,
:is_termination? => true
)
end

Expand All @@ -87,3 +91,103 @@
end

end

describe ::ExternalEvents::EnrollmentEventNotificationFilters::RemoveSameActionsAndSelectSilent, "given, in order:
- a coverage_selected for enrollment 'A'
- an auto_renew for enrollment 'A'
" do

let(:event_1) do
instance_double(
::ExternalEvents::EnrollmentEventNotification,
:hbx_enrollment_id => "A",
:enrollment_action => "urn:openhbx:terms:v1:enrollment#initial",
:is_publishable? => true,
:is_termination? => false,
:is_coverage_starter? => true,
:is_passive_renewal? => false
)
end

let(:event_2) do
instance_double(
::ExternalEvents::EnrollmentEventNotification,
:hbx_enrollment_id => "A",
:enrollment_action => "urn:openhbx:terms:v1:enrollment#auto_renew",
:is_publishable? => false,
:is_termination? => false,
:is_coverage_starter? => true,
:is_passive_renewal? => true
)
end

let(:events) { [event_1, event_2] }

before :each do
allow(event_1).to receive(:drop_payload_duplicate!)
end

it "filters the coverage_selected event" do
expect(subject.filter(events)).not_to include(event_1)
end

it "includes the auto_renewal event" do
expect(subject.filter(events)).to include(event_2)
end

it "drops the coverage_selected event as a duplicate" do
expect(event_1).to receive(:drop_payload_duplicate!)
subject.filter(events)
end

end

describe ::ExternalEvents::EnrollmentEventNotificationFilters::RemoveSameActionsAndSelectSilent, "given, in order:
- an auto_renewal for enrollment 'A'
- a coverage_selected for enrollment 'A'
" do

let(:event_1) do
instance_double(
::ExternalEvents::EnrollmentEventNotification,
:hbx_enrollment_id => "A",
:enrollment_action => "urn:openhbx:terms:v1:enrollment#auto_renew",
:is_publishable? => true,
:is_termination? => false,
:is_coverage_starter? => true,
:is_passive_renewal? => true
)
end

let(:event_2) do
instance_double(
::ExternalEvents::EnrollmentEventNotification,
:hbx_enrollment_id => "A",
:enrollment_action => "urn:openhbx:terms:v1:enrollment#initial",
:is_publishable? => false,
:is_termination? => false,
:is_coverage_starter? => true,
:is_passive_renewal? => false
)
end

let(:events) { [event_1, event_2] }

before :each do
allow(event_2).to receive(:drop_payload_duplicate!)
end

it "filters the coverage_selected event" do
expect(subject.filter(events)).not_to include(event_2)
end

it "includes the auto_renewal event" do
expect(subject.filter(events)).to include(event_1)
end

it "drops the coverage_selected event as a duplicate" do
expect(event_2).to receive(:drop_payload_duplicate!)
subject.filter(events)
end

end

0 comments on commit 995083f

Please sign in to comment.