From e53668a624c2121dfd5f9648bf4e15bd762d1f2f Mon Sep 17 00:00:00 2001 From: Trey Evans Date: Mon, 9 Sep 2024 10:56:53 -0400 Subject: [PATCH] Add ability to censor tobacco change notifications. --- app/models/carrier.rb | 1 + .../tobacco_or_rating_area_change.rb | 1 + .../enrollment_event_notification.rb | 4 + script/set_maine_tobacco_censorship.rb | 5 + .../carefirst_termination_spec.rb | 10 +- .../concurrent_policy_cancel_and_term_spec.rb | 8 ++ .../tobacco_or_rating_area_change_spec.rb | 127 ++++++++++++++++-- 7 files changed, 147 insertions(+), 9 deletions(-) create mode 100644 script/set_maine_tobacco_censorship.rb diff --git a/app/models/carrier.rb b/app/models/carrier.rb index 1ac03f0fa..e3f0b84b7 100644 --- a/app/models/carrier.rb +++ b/app/models/carrier.rb @@ -25,6 +25,7 @@ class Carrier field :plan_change_renewal_dependent_drop_transmitted_as_renewal, type: Boolean, default: false field :retro_renewal_transmitted_as_renewal, type: Boolean, default: false field :renewal_dependent_drop_transmitted_as_renewal, type: Boolean, default: false + field :censor_tobacco_change, type: Boolean, default: false has_many :plans has_many :policies diff --git a/app/models/enrollment_action/tobacco_or_rating_area_change.rb b/app/models/enrollment_action/tobacco_or_rating_area_change.rb index f03973cda..b42498c87 100644 --- a/app/models/enrollment_action/tobacco_or_rating_area_change.rb +++ b/app/models/enrollment_action/tobacco_or_rating_area_change.rb @@ -14,6 +14,7 @@ def self.qualifies?(chunk) def self.tobacco_change?(chunk) termination = chunk.detect { |c| c.is_termination? } action = chunk.detect { |c| !c.is_termination? } + return false if action.carrier && action.carrier.censor_tobacco_change t_tu_hash = termination.tobacco_usage_hash a_tu_hash = action.tobacco_usage_hash t_tu_hash.each_pair do |k,v| diff --git a/app/models/external_events/enrollment_event_notification.rb b/app/models/external_events/enrollment_event_notification.rb index 56986bd70..64eb394f5 100644 --- a/app/models/external_events/enrollment_event_notification.rb +++ b/app/models/external_events/enrollment_event_notification.rb @@ -428,6 +428,10 @@ def existing_plan @existing_plan ||= extract_plan(policy_cv) end + def carrier + @carrier ||= existing_plan && existing_plan.carrier + end + def is_publishable? Maybe.new(enrollment_event_xml).event.body.publishable?.value end diff --git a/script/set_maine_tobacco_censorship.rb b/script/set_maine_tobacco_censorship.rb new file mode 100644 index 000000000..7e0daa424 --- /dev/null +++ b/script/set_maine_tobacco_censorship.rb @@ -0,0 +1,5 @@ +Carrier.all.each do |carrier| + carrier.update_attributes( + censor_tobacco_change: true + ) +end \ No newline at end of file diff --git a/spec/models/enrollment_action/carefirst_termination_spec.rb b/spec/models/enrollment_action/carefirst_termination_spec.rb index 728de7386..1d8a92ef6 100644 --- a/spec/models/enrollment_action/carefirst_termination_spec.rb +++ b/spec/models/enrollment_action/carefirst_termination_spec.rb @@ -63,7 +63,7 @@ let(:enrollee) { instance_double(::Openhbx::Cv2::Enrollee, member: member) } let(:terminated_policy_cv) { instance_double(Openhbx::Cv2::Policy, enrollees: [enrollee])} let(:carrier) { Carrier.create } - let(:policy) { FactoryGirl.create(:policy, hbx_enrollment_ids: [1], carrier: carrier) } + let(:policy) { FactoryGirl.create(:policy, eg_id: 1, hbx_enrollment_ids: [1], carrier: carrier) } let(:start_date) { Date.new(Date.today.year) } let(:term_date) { start_date + 1.month} let(:termination_event) { instance_double( @@ -75,6 +75,10 @@ all_member_ids: [1,2] ) } + after :each do + Policy.where({}).delete + end + before :each do policy.enrollees.update_all(coverage_start: start_date, coverage_end: nil) allow(policy).to receive(:term_for_np).and_return(true, false) @@ -132,6 +136,10 @@ coverage_end: Date.new(2019,3,31)) end + after :each do + Policy.where({}).delete + end + before :each do person.update_attributes!(:authority_member_id => person.members.first.hbx_member_id) allow(termination_event.existing_policy).to receive(:terminate_as_of).and_return(true) diff --git a/spec/models/enrollment_action/concurrent_policy_cancel_and_term_spec.rb b/spec/models/enrollment_action/concurrent_policy_cancel_and_term_spec.rb index e2610b59c..f5f238801 100644 --- a/spec/models/enrollment_action/concurrent_policy_cancel_and_term_spec.rb +++ b/spec/models/enrollment_action/concurrent_policy_cancel_and_term_spec.rb @@ -13,6 +13,10 @@ subject { EnrollmentAction::ConcurrentPolicyCancelAndTerm } + after :each do + Policy.where({}).delete + end + it "qualifies" do expect(subject.qualifies?([event_1])).to be_truthy end @@ -383,6 +387,10 @@ EnrollmentAction::ConcurrentPolicyCancelAndTerm.new(termination_event, nil) end + after :each do + Policy.where({}).delete + end + it "should terminate policy with correct date and delete future APTC credits" do expect(active_policy.aasm_state).to eq "submitted" expect(active_policy.aptc_credits.where(start_on: aptc_one_start, end_on: aptc_one_end).count).to eq 1 diff --git a/spec/models/enrollment_action/tobacco_or_rating_area_change_spec.rb b/spec/models/enrollment_action/tobacco_or_rating_area_change_spec.rb index 2687a53a3..61cb8507a 100644 --- a/spec/models/enrollment_action/tobacco_or_rating_area_change_spec.rb +++ b/spec/models/enrollment_action/tobacco_or_rating_area_change_spec.rb @@ -66,7 +66,8 @@ -- has two events -- has the same plan -- has same carrier --- tobacco and rating are unchanged" do +-- tobacco and rating are unchanged +-- carrier censor_tobacco_change is FALSE" do let(:tobacco_use_hash) do { @@ -79,7 +80,7 @@ { } end - let(:carrier) { instance_double(Carrier, :id => 1, :require_term_drop? => true) } + let(:carrier) { instance_double(Carrier, :id => 1, :require_term_drop? => true, :censor_tobacco_change => false) } let(:plan) { instance_double(Plan, :id => 1, carrier_id: 1) } let(:policy_cv1) do @@ -114,7 +115,8 @@ :is_termination? => false, :policy_cv => policy_cv2, :is_cobra? => false, - :tobacco_usage_hash => tobacco_use_hash + :tobacco_usage_hash => tobacco_use_hash, + :carrier => carrier ) end @@ -159,9 +161,10 @@ -- has the same plan -- has same carrier -- rating area is unchanged --- tobacco is changed" do +-- tobacco is changed +-- carrier censor_tobacco_change is FALSE" do - let(:carrier) { instance_double(Carrier, :id => 1, :require_term_drop? => true) } + let(:carrier) { instance_double(Carrier, :id => 1, :require_term_drop? => true, :censor_tobacco_change => false) } let(:plan) { instance_double(Plan, :id => 1, carrier_id: 1) } let(:policy_cv1) do @@ -184,7 +187,8 @@ :is_termination? => true, :policy_cv => policy_cv1, :is_cobra? => false, - :tobacco_usage_hash => tobacco_use_hash_1 + :tobacco_usage_hash => tobacco_use_hash_1, + :carrier => carrier ) end @@ -196,7 +200,8 @@ :is_termination? => false, :policy_cv => policy_cv2, :is_cobra? => false, - :tobacco_usage_hash => tobacco_use_hash_2 + :tobacco_usage_hash => tobacco_use_hash_2, + :carrier => carrier ) end let(:event_set) { [event_1, event_2] } @@ -253,6 +258,108 @@ end end +describe EnrollmentAction::TobaccoOrRatingAreaChange, "given an enrollment event set that: +-- has two events +-- has the same plan +-- has same carrier +-- rating area is unchanged +-- tobacco is changed +-- carrier censor_tobacco_change is TRUE" do + + let(:carrier) { instance_double(Carrier, :id => 1, :require_term_drop? => true, :censor_tobacco_change => true) } + let(:plan) { instance_double(Plan, :id => 1, carrier_id: 1) } + + let(:policy_cv1) do + instance_double( + Openhbx::Cv2::Policy + ) + end + + let(:policy_cv2) do + instance_double( + Openhbx::Cv2::Policy + ) + end + + let(:event_1) do + instance_double( + ExternalEvents::EnrollmentEventNotification, + :existing_plan => plan, + :all_member_ids => [1,2], + :is_termination? => true, + :policy_cv => policy_cv1, + :is_cobra? => false, + :tobacco_usage_hash => tobacco_use_hash_1, + :carrier => carrier + ) + end + + let(:event_2) do + instance_double( + ExternalEvents::EnrollmentEventNotification, + :existing_plan => plan, + :all_member_ids => [1,2], + :is_termination? => false, + :policy_cv => policy_cv2, + :is_cobra? => false, + :tobacco_usage_hash => tobacco_use_hash_2, + :carrier => carrier + ) + end + let(:event_set) { [event_1, event_2] } + + let(:external_policy_1) do + instance_double( + ExternalEvents::ExternalPolicy, + extract_rating_details: rating_details + ) + end + let(:external_policy_2) do + instance_double( + ExternalEvents::ExternalPolicy, + extract_rating_details: rating_details + ) + end + + let(:tobacco_use_hash_1) do + { + "1" => "Y", + "2" => "Y" + } + end + + let(:tobacco_use_hash_2) do + { + "1" => "Y", + "2" => "N" + } + end + + let(:rating_details) do + { } + end + + subject { EnrollmentAction::TobaccoOrRatingAreaChange } + + before do + allow(plan).to receive(:carrier).and_return(carrier) + allow(ExternalEvents::ExternalPolicy).to receive(:new).with( + policy_cv1, + plan, + false + ).and_return(external_policy_1) + allow(ExternalEvents::ExternalPolicy).to receive(:new).with( + policy_cv2, + plan, + false + ).and_return(external_policy_2) + end + + it "does not qualify" do + expect(subject.qualifies?(event_set)).to be_falsey + end +end + describe EnrollmentAction::TobaccoOrRatingAreaChange, "given an enrollment event set that: -- has two events @@ -425,7 +532,7 @@ let(:new_policy_cv) { instance_double(Openhbx::Cv2::Policy, :enrollees => [enrollee_primary, enrollee_secondary, enrollee_new]) } let(:plan) { instance_double(Plan, :id => 1) } let(:carrier) { Carrier.create } - let(:policy) { FactoryGirl.create(:policy, hbx_enrollment_ids: [1], carrier: carrier) } + let(:policy) { FactoryGirl.create(:policy, eg_id: 1, hbx_enrollment_ids: [1], carrier: carrier) } let(:start_date) { Date.new(Date.today.year) } let(:term_date) { start_date + 1.month} let(:primary_db_record) { instance_double(ExternalEvents::ExternalMember, :persist => true) } @@ -454,6 +561,10 @@ EnrollmentAction::TobaccoOrRatingAreaChange.new(termination_event, action_event) end + after :each do + Policy.where({}).delete + end + before :each do policy.enrollees.update_all(coverage_start: start_date, coverage_end: nil) allow(ExternalEvents::ExternalMember).to receive(:new).with(member_primary).and_return(primary_db_record)