Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter subscribers list and subscriber Coverage information based on options provided #79

Draft
wants to merge 3 commits into
base: me_carrier_boarding
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 11 additions & 20 deletions app/controllers/api/event_source/enrolled_subjects_controller.rb
Original file line number Diff line number Diff line change
@@ -1,40 +1,31 @@
module Api
module EventSource
class EnrolledSubjectsController < ApplicationController
# skip_before_filter :authenticate_user_from_token!
# skip_before_filter :authenticate_me!
# skip_before_filter :verify_authenticity_token

def index
year_param = params[:year]
hios_param = params[:hios_id]
if year_param.blank? || hios_param.blank?
render :status => 422, :nothing => true
else
render :status => 200, :json => SubscriberInventory.subscriber_ids_for(hios_param, year_param.to_i)
end
render :status => 200, :json => SubscriberInventory.subscriber_ids_for(read_filter_params)
end

def show
member_id = params[:id]
member_id = params[:enrolled_subject].present? ? params[:enrolled_subject][:id] : params[:id]
person = Person.find_for_member_id(member_id)
if person.blank?
render :status => 404, :nothing => true
else
render :status => 200, :json => SubscriberInventory.coverage_inventory_for(person, read_show_filter_params)
render :status => 200, :json => SubscriberInventory.coverage_inventory_for(person, read_filter_params)
end
end

def read_show_filter_params
def read_filter_params
filter_parameters = Hash.new
year_param = params[:year]
hios_param = params[:hios_id]
if !year_param.blank?
filter_parameters[:year] = year_param.to_i
end
if !hios_param.blank?
filter_parameters[:hios_id] = hios_param
end
year_param = params[:year]
start_time = params[:start_time]
end_time = params[:end_time]
filter_parameters.merge!(hios_id: hios_param) if hios_param.present?
filter_parameters.merge!(year: year_param.to_i) if year_param.present?
filter_parameters.merge!(start_time: start_time) if start_time.present?
filter_parameters.merge!(end_time: end_time) if end_time.present?
filter_parameters
end
end
Expand Down
12 changes: 6 additions & 6 deletions app/models/subscriber_inventory.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
class SubscriberInventory
def self.subscriber_ids_for(carrier_hios, year)
plans = plans_for(carrier_hios, year)
aggregate_query_for_subscribers_under_plans(plans)
def self.subscriber_ids_for(filters)
plan_ids = select_filtered_plan_ids(filters)
aggregate_query_for_subscribers_under_plans(plan_ids)
end

def self.aggregate_query_for_subscribers_under_plans(plans)
def self.aggregate_query_for_subscribers_under_plans(plan_ids)
Policy.collection.raw_aggregate([
{"$match" => {"plan_id" => {"$in" => plans.map(&:_id)}}},
{"$match" => {"plan_id" => {"$in" => plan_ids}}},
{"$unwind" => "$enrollees"},
{"$match" => {"enrollees.rel_code" => "self"}},
{"$group" => {"_id" => "$enrollees.m_id"}}
Expand Down Expand Up @@ -37,7 +37,7 @@ def self.select_filtered_plan_ids(filters = {})
if filters.has_key?(:year)
filter_criteria[:year] = filters[:year]
end
return nil if filter_criteria.empty?
return [] if filter_criteria.empty?

Rails.cache.fetch("plan-ids-#{filter_criteria[:hios_plan_id]}-#{filter_criteria[:year]}", expires_in: 24.hour) do
plans = Plan.where(filter_criteria)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,20 @@
end

describe "given no parameters" do
it "returns 422" do
it "returns 200" do
get :index, {user_token: user_token}
expect(response).to have_http_status(422)
expect(response).to have_http_status(200)
end
end

describe "given a valid hios_id and year, but no results" do
let(:the_hios_id) { "A VALID HIOS ID" }
let(:the_year) { "2015" }
let(:filters) { {hios_id: "A VALID HIOS ID", year: 2015} }

before :each do
allow(SubscriberInventory).to receive(:subscriber_ids_for).with(
the_hios_id,
the_year.to_i
filters
).and_return([])
end

Expand All @@ -51,11 +51,11 @@
let(:the_hios_id) { "A VALID HIOS ID" }
let(:the_year) { "2015" }
let(:matching_subscriber_id) { "A SUBSCRIBER ID" }
let(:filters) { {hios_id: the_hios_id, year: the_year.to_i} }

before :each do
allow(SubscriberInventory).to receive(:subscriber_ids_for).with(
the_hios_id,
the_year.to_i
filters
).and_return([matching_subscriber_id])
end

Expand Down
9 changes: 6 additions & 3 deletions spec/models/subscriber_inventory_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
)
end

let(:filters) { { hios_id: plan.hios_plan_id, year: 2015 }}

it "has no results for #subscriber_ids_for" do
expect(SubscriberInventory.subscriber_ids_for(plan.hios_plan_id, 2015).to_a).to eq []
expect(SubscriberInventory.subscriber_ids_for(filters).to_a).to eq []
end
end

Expand All @@ -33,10 +35,11 @@
:eg_id => "some eg id"
})
end
let(:filters) { { hios_id: plan.hios_plan_id[0..2], year: plan.year }}

it "returns the subscriber" do
policy
expect(SubscriberInventory.subscriber_ids_for(plan.hios_plan_id[0..2], plan.year).to_a).to eq ["subscriber_id"]
expect(SubscriberInventory.subscriber_ids_for(filters).to_a).to eq ["subscriber_id"]
end
end

Expand Down Expand Up @@ -76,7 +79,7 @@
it "returns the coverage history in the format ACA Entities expects" do
expect(Generators::CoverageInformationSerializer).to receive(
:new
).with(person, nil).and_return(coverage_information_serializer)
).with(person, []).and_return(coverage_information_serializer)
expect(SubscriberInventory.coverage_inventory_for(person)).to eq({})
end
end
Expand Down