From 203d243d87a1cb078bd9b8c4ad3023b8c9a438f9 Mon Sep 17 00:00:00 2001 From: Jay Reddy Date: Tue, 13 Aug 2024 10:45:13 -0400 Subject: [PATCH] 187603029 pivotal (#213) * Fixed Start Date Bug on Glue * Fixed Start Date Bug on Glue * latest updates * latest updates * latest updates --- .../handlers/enrollment_event_xml_helper.rb | 10 ++ app/models/enrollment_action/dependent_add.rb | 27 ++- .../enrollment_event_xml_helper_spec.rb | 21 +++ .../enrollment_action/dependent_add_spec.rb | 159 +++++++++++++++++- 4 files changed, 207 insertions(+), 10 deletions(-) diff --git a/app/business_processes/handlers/enrollment_event_xml_helper.rb b/app/business_processes/handlers/enrollment_event_xml_helper.rb index 07d61fdb6..8cb2c4104 100644 --- a/app/business_processes/handlers/enrollment_event_xml_helper.rb +++ b/app/business_processes/handlers/enrollment_event_xml_helper.rb @@ -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? diff --git a/app/models/enrollment_action/dependent_add.rb b/app/models/enrollment_action/dependent_add.rb index d3159550b..76fe1ad7b 100644 --- a/app/models/enrollment_action/dependent_add.rb +++ b/app/models/enrollment_action/dependent_add.rb @@ -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) diff --git a/spec/business_processes/handlers/enrollment_event_xml_helper_spec.rb b/spec/business_processes/handlers/enrollment_event_xml_helper_spec.rb index f2b8a6bb7..14c924137 100644 --- a/spec/business_processes/handlers/enrollment_event_xml_helper_spec.rb +++ b/spec/business_processes/handlers/enrollment_event_xml_helper_spec.rb @@ -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 diff --git a/spec/models/enrollment_action/dependent_add_spec.rb b/spec/models/enrollment_action/dependent_add_spec.rb index 80e83c2a3..669d390c9 100644 --- a/spec/models/enrollment_action/dependent_add_spec.rb +++ b/spec/models/enrollment_action/dependent_add_spec.rb @@ -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) } @@ -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 \ No newline at end of file