Skip to content

Commit

Permalink
Add ability to censor tobacco change notifications.
Browse files Browse the repository at this point in the history
  • Loading branch information
TreyE committed Sep 9, 2024
1 parent 203d243 commit e53668a
Show file tree
Hide file tree
Showing 7 changed files with 147 additions and 9 deletions.
1 change: 1 addition & 0 deletions app/models/carrier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down
4 changes: 4 additions & 0 deletions app/models/external_events/enrollment_event_notification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions script/set_maine_tobacco_censorship.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Carrier.all.each do |carrier|
carrier.update_attributes(
censor_tobacco_change: true
)
end
10 changes: 9 additions & 1 deletion spec/models/enrollment_action/carefirst_termination_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
127 changes: 119 additions & 8 deletions spec/models/enrollment_action/tobacco_or_rating_area_change_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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] }
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) }
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit e53668a

Please sign in to comment.