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

ML- (SPARCDashboard) Fee Agreement Report Filtering [#181500559] #2851

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 12 additions & 1 deletion app/lib/fee_agreement.rb
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,8 @@ class Report
# columns.
def initialize(service_request, filters = {}, max_visit_columns_per_table = 5)
@service_request = service_request
@filters = filters
@filters = init_filters(filters)

@visit_columns = max_visit_columns_per_table

@clinical_service_tables = init_clinical_service_tables()
Expand All @@ -239,6 +240,16 @@ def non_clinical_services_displayed?
!@non_clinical_service_table.rows.empty?
end

# Initialize filters from the provided options. Ensures that downstream filtering includes
# child organizations (Cores).
def init_filters(options = {})
filters = options
filters[:program] ||= []
child_orgs = filters[:program].map {|program| Organization.where(parent: program).map(&:id)}
filters[:program] = filters[:program] + child_orgs.flatten
filters
end

# @returns Hash of options to use for filtering data.
def filter_options
unless @filter_options
Expand Down
16 changes: 11 additions & 5 deletions spec/lib/fee_agreement/report_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@
@program_outpatient_clinic = create(:program, parent: @provider_ctrc, process_ssrs: true)
@program_nursing = create(:program, parent: @provider_ctrc, process_ssrs: true)
@program_admin = create(:program, parent: @provider_ctrc, process_ssrs: true)
@core_outpatient_clinic = create(:core, parent: @program_outpatient_clinic, process_ssrs: true)

# SubServiceRequests
@ssr_outpatient = create(:sub_service_request, service_request: @sr, organization: @program_outpatient_clinic, status: 'awaiting_pi_approval')
@ssr_admin = create(:sub_service_request, service_request: @sr, organization: @program_admin, status: 'awaiting_pi_approval')
@ssr_nursing = create(:sub_service_request, service_request: @sr, organization: @program_nursing, status: 'awaiting_pi_approval')
@ssr_core_outpatient = create(:sub_service_request, service_request: @sr, organization: @core_outpatient_clinic, status: 'awaiting_pi_approval')

# Services
@service_outpatient_room = create(:service, :with_pricing_map, name: "Outpatient room", organization: @program_outpatient_clinic, one_time_fee: false)
Expand All @@ -44,6 +46,7 @@
@service_nursing_admin_fee = create(:service, :with_pricing_map, name: "Nursing admin fee", organization: @program_admin, one_time_fee: true)
@service_rn = create(:service, :with_pricing_map, name: "RN", organization: @program_nursing, one_time_fee: false)
@service_iv = create(:service, :with_pricing_map, name: "IV", organization: @program_nursing, one_time_fee: false)
@service_core = create(:service, :with_pricing_map, name: "Core service", organization: @core_outpatient_clinic, one_time_fee: true)

# LineItems
@li_outpatient_rm = create(:line_item, :without_validations, service: @service_outpatient_room, service_request: @sr, sub_service_request: @ssr_outpatient)
Expand All @@ -53,6 +56,7 @@
@li_nursing_admin = create(:line_item, :without_validations, service: @service_nursing_admin_fee, service_request: @sr, sub_service_request: @ssr_admin)
@li_rn = create(:line_item, :without_validations, service: @service_rn, service_request: @sr, sub_service_request: @ssr_nursing)
@li_iv = create(:line_item, :without_validations, service: @service_iv, service_request: @sr, sub_service_request: @ssr_nursing)
@li_core = create(:line_item, :without_validations, service: @service_core, service_request: @sr, sub_service_request: @ssr_core_outpatient)

# Arms
# NOTE: The after_create callback ensures the creation of the following records:
Expand Down Expand Up @@ -117,6 +121,7 @@
@inst.destroy
@provider_ctrc.destroy
@program_outpatient_clinic.destroy
@core_outpatient_clinic.destroy
@program_nursing.destroy
@program_admin.destroy
end
Expand All @@ -129,7 +134,7 @@
expect(report.non_clinical_services_displayed?).to be(true)
end
it 'should create a row in the non-clinical service table for every active otf line item' do
expect(report.non_clinical_service_table.rows.count).to eq(2)
expect(report.non_clinical_service_table.rows.count).to eq(3)
end
it 'should create a clinical service table for each arm' do
expect(report.clinical_service_tables.size).to eq(2)
Expand Down Expand Up @@ -198,11 +203,11 @@
context 'with program filter' do
let (:report) { FeeAgreement::Report.new(@sr, filters = { :program => [@program_outpatient_clinic.id] }) }

it 'should only display line items provided by the given program' do
expect(report.non_clinical_service_table.rows.count).to eq(0)
it 'should only display line items provided by the given program and its cores' do
expect(report.non_clinical_service_table.rows.count).to eq(1)
expect(report.clinical_service_tables[0].rows.count).to eq(0)
expect(report.clinical_service_tables[1].rows.count).to eq(1)
expect(report.non_clinical_services_displayed?).to be(false)
expect(report.non_clinical_services_displayed?).to be(true)
expect(report.clinical_services_displayed?).to be(true)
end

Expand All @@ -211,8 +216,9 @@
per_person = @visit_quantities.select { |row| row[li] == @li_outpatient_rm }
.map { |row| row[li].applicable_rate * row[qty] }
.sum
expected_non_clinical_total = Service.cents_to_dollars(@li_core.applicable_rate * @li_core.quantity)
expected = Service.cents_to_dollars(@arm2.subject_count * per_person)
expect(report.non_clinical_service_table.total).to eq(0)
expect(report.non_clinical_service_table.total).to eq(expected_non_clinical_total)
expect(report.clinical_service_tables[0].total).to eq(0)
expect(report.clinical_service_tables[1].total).to eq(expected)
end
Expand Down