Skip to content

Commit 11ddf80

Browse files
authored
fix(Dr. Rai Reports): Respect 'non-contactable' switch (#5687)
**Story card:** [sc-16697](https://app.shortcut.com/simpledotorg/story/16697/fix-contactoverduepatientindicator-denominator) ## Because We're using the `overdue_patients` regardless of the dashboard only considering `contactable_overdue_patients` ## This addresses Using the right numerator and denominator keys depending on if non-contactable patients are included in the dashboard calculations. ## Test instructions suite tests
1 parent 3cf9a7e commit 11ddf80

File tree

12 files changed

+73
-40
lines changed

12 files changed

+73
-40
lines changed

app/components/dashboard/dr_rai_report.rb

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,16 @@ class Dashboard::DrRaiReport < ApplicationComponent
33
attr_reader :periods, :region
44
attr_accessor :selected_period
55

6-
def initialize(periods, region_slug, selected_quarter = nil, lite = false)
6+
def initialize(periods, region_slug, options, lite = false)
77
@lite = lite
88
@periods = periods
99
@region = Region.find_by(slug: region_slug)
10-
@selected_period = if selected_quarter.nil?
10+
@selected_period = if options[:selected_quarter].nil?
1111
Period.new(type: :quarter, value: current_period.value.to_s)
1212
else
13-
Period.new(type: :quarter, value: selected_quarter)
13+
Period.new(type: :quarter, value: options[:selected_quarter])
1414
end
15+
@with_non_contactable = options[:with_non_contactable].present?
1516
end
1617

1718
def indicators
@@ -40,11 +41,11 @@ def custom_indicators
4041
end
4142

4243
def indicator_numerator(indicator, period = selected_period)
43-
indicator.numerator(region, period)
44+
indicator.numerator(region, period, with_non_contactable: @with_non_contactable)
4445
end
4546

4647
def indicator_denominator(indicator, period = selected_period)
47-
indicator.denominator(region, period)
48+
indicator.denominator(region, period, with_non_contactable: @with_non_contactable)
4849
end
4950

5051
def current_period

app/controllers/reports/progress_controller.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ class Reports::ProgressController < AdminController
55
before_action :require_feature_flag
66
before_action :set_period
77
before_action :find_region
8+
before_action :set_dr_rai_vars, only: [:show]
89
around_action :set_reporting_time_zone
910

1011
def show
@@ -66,4 +67,11 @@ def set_period
6667
period_params = report_params[:period].presence || Reports.default_period.attributes
6768
@period = Period.new(period_params)
6869
end
70+
71+
def set_dr_rai_vars
72+
@dr_rai_periods = Period.quarters_between(10.months.ago, 2.months.from_now)
73+
74+
option_keys = %i[selected_quarter with_non_contactable]
75+
@dr_rai_options = params.select { |k, _| option_keys.include?(k) }
76+
end
6977
end

app/controllers/reports/regions_controller.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ class Reports::RegionsController < AdminController
44
include RegionSearch
55

66
before_action :set_period, except: [:index, :fastindex]
7-
before_action :set_dr_rai_periods, only: [:show, :diabetes]
7+
before_action :set_dr_rai_vars, only: [:show, :diabetes]
88
before_action :set_page, only: [:show, :details, :diabetes]
99
before_action :set_per_page, only: [:show, :details, :diabetes]
1010
before_action :find_region, except: [:index, :fastindex]
@@ -469,7 +469,10 @@ def percentage(numerator, denominator)
469469
((numerator.to_f / denominator) * 100).round(2)
470470
end
471471

472-
def set_dr_rai_periods
472+
def set_dr_rai_vars
473473
@dr_rai_periods = Period.quarters_between(10.months.ago, 2.months.from_now)
474+
475+
option_keys = %i[selected_quarter with_non_contactable]
476+
@dr_rai_options = params.select { |k, _| option_keys.include?(k) }
474477
end
475478
end

app/models/dr_rai/contact_overdue_patients_indicator.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,16 @@ def target_type_frontend
1212
"percent"
1313
end
1414

15-
def numerator_key
15+
def numerator_key all: nil
16+
return "patients_called" if all
17+
1618
"contactable_patients_called"
1719
end
1820

19-
def denominator_key
20-
"overdue_patients"
21+
def denominator_key all: nil
22+
return "overdue_patients" if all
23+
24+
"contactable_overdue_patients"
2125
end
2226

2327
def unit

app/models/dr_rai/indicator.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,27 +51,27 @@ def target_type
5151
DrRai::Target::TYPES[target_type_frontend]
5252
end
5353

54-
def numerator(region, the_period = period)
54+
def numerator(region, the_period = period, with_non_contactable: nil)
5555
0 unless is_supported?(region)
56-
numerators(region)[the_period]
56+
numerators(region, all: with_non_contactable)[the_period]
5757
end
5858

59-
def denominator(region, the_period = period)
59+
def denominator(region, the_period = period, with_non_contactable: nil)
6060
0 unless is_supported?(region)
61-
denominators(region)[the_period]
61+
denominators(region, all: with_non_contactable)[the_period]
6262
end
6363

64-
def numerators(region)
64+
def numerators(region, all: nil)
6565
[] unless is_supported?(region)
6666
datasource(region).map do |t, data|
67-
[t, data[numerator_key]]
67+
[t, data[numerator_key(all: all)]]
6868
end.to_h
6969
end
7070

71-
def denominators(region)
71+
def denominators(region, all: nil)
7272
[] unless is_supported?(region)
7373
datasource(region).map do |t, data|
74-
[t, data[denominator_key]]
74+
[t, data[denominator_key(all: all)]]
7575
end.to_h
7676
end
7777

app/models/dr_rai/statins_indicator.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ def target_type_frontend
2020
"percent"
2121
end
2222

23-
def numerator_key
23+
def numerator_key all: nil
2424
:patients_prescribed_statins
2525
end
2626

27-
def denominator_key
27+
def denominator_key all: nil
2828
:eligible_patients
2929
end
3030

app/models/dr_rai/titration_indicator.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ def target_type_frontend
1616
"percent"
1717
end
1818

19-
def numerator_key
19+
def numerator_key all: nil
2020
:titrated_count
2121
end
2222

23-
def denominator_key
23+
def denominator_key all: nil
2424
:follow_up_count
2525
end
2626

app/views/api/v3/analytics/user_analytics/show.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<body>
2121
<div id="home-page">
2222
<% if Flipper.enabled?(:dr_rai_reports) && Flipper.enabled?(:dr_rai_progress) && @region.facility_region? %>
23-
<% dr_rai_component = Dashboard::DrRaiReport.new(nil, @region.slug, params[:selected_quarter], true) %>
23+
<% dr_rai_component = Dashboard::DrRaiReport.new(nil, @region.slug, @dr_rai_options, true) %>
2424
<% unless dr_rai_component.action_plans.empty? %>
2525
<div class="mb-8px p-16px bgc-white bs-card">
2626
<h1 class="m-0px mb-16px fw-bold fs-24px c-black">

app/views/reports/regions/diabetes.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<%= render "header" %>
66

77
<% if Flipper.enabled?(:dr_rai_reports, current_admin) && @region.facility_region? %>
8-
<%= render Dashboard::DrRaiReport.new(@dr_rai_periods, @region.slug, params[:selected_quarter]) %>
8+
<%= render Dashboard::DrRaiReport.new(@dr_rai_periods, @region.slug, @dr_rai_options) %>
99
<% end %>
1010

1111
<h4 class="mt-5 mb-32px"></h4>

app/views/reports/regions/show.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@
9696
<%= render "header" %>
9797

9898
<% if Flipper.enabled?(:dr_rai_reports, current_admin) && @region.facility_region? %>
99-
<%= render Dashboard::DrRaiReport.new(@dr_rai_periods, @region.slug, params[:selected_quarter]) %>
99+
<%= render Dashboard::DrRaiReport.new(@dr_rai_periods, @region.slug, @dr_rai_options) %>
100100
<% end %>
101101

102102
<% control_graph_denominator_copy = @with_ltfu ? "denominator_with_ltfu_copy" : "denominator_copy" %>

0 commit comments

Comments
 (0)