Skip to content

Commit af3a8c3

Browse files
sc-14920 added functionality with spec (#5539)
**Story card:** [sc-14920](https://app.shortcut.com/simpledotorg/story/14920/quick-links-at-district-level-reports) Because At district level, quick links will open the corresponding metabase report for that district This Addresses Will open the quick links for the respective district Test Instructions Enable the flipper "quick_link_for_metabase"
1 parent 519298f commit af3a8c3

File tree

4 files changed

+66
-16
lines changed

4 files changed

+66
-16
lines changed

.env.BD

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@ HELP_SCREEN_SUPPORT_GROUP_ICON = "icon_whatsapp_icon.svg"
44
DRUG_STOCK_REPORT_URL = "/my_facilities/drug_stocks?facility_group="
55
METABASE_TITRATION_URL = "https://metabase.bd.simple.org/question/109-facility-titration-trend?months=past9months&facility_name="
66
METABASE_BP_FUDGING_URL = "https://metabase.bd.simple.org/question/954-bp-fudging-02-facility-trend-line?assigned_facility_slug="
7+
DISTRICT_FACILITY_TREND_REPORT_URL = "https://api.bd.simple.org/my_facilities/bp_controlled?facility_group="
8+
DISTRICT_DRUG_STOCK_REPORT_URL = "https://api.bd.simple.org/my_facilities/drug_stocks?facility_group="
9+
DISTRICT_METABASE_TITRATION_URL = "https://metabase.bd.simple.org/question/997-district-titration-trend?months=past9months&district_name="

.env.test

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,6 @@ USER_OTP_VALID_UNTIL_DELTA_IN_MINUTES=10
6666
DRUG_STOCK_REPORT_URL="https://api.example.com/my_facilities/drug_stocks?facility_group="
6767
METABASE_BP_FUDGING_URL= 'https://metabase.example.com/bp_fudging?region='
6868
METABASE_TITRATION_URL= 'https://metabase.example.com/titration?region='
69+
DISTRICT_DRUG_STOCK_REPORT_URL = "https://api.example.com/my_facilities/drug_stocks?facility_group="
70+
DISTRICT_FACILITY_TREND_REPORT_URL = "https://api.example.com/my_facilities/bp_controlled?facility_group="
71+
DISTRICT_METABASE_TITRATION_URL = "https://metabase.example.com/titration?district_name="

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

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,40 @@
11
<% content_for :title do %>
22
<%= @region.name %> | Hypertension
33
<% end %>
4-
5-
<% if @is_desktop && @region.facility_region? && Flipper.enabled?(:quick_link_for_metabase, current_admin) %>
4+
<% if @is_desktop && Flipper.enabled?(:quick_link_for_metabase, current_admin) %>
5+
<% last_month = Date.today.last_month.strftime("%b-%Y") %>
66
<div class="float-right desktop">
77
<h4 class="mb-0px">Quick links</h4>
8-
<% district = @region.source.facility_group.slug %>
9-
<% size = @region.source.facility_size.present? ? @region.source.facility_size : '' %>
10-
<% zone = @region.source.zone %>
11-
<% last_month = Date.today.last_month.strftime("%b-%Y") %>
12-
<div><a href="<%= ENV.fetch('DRUG_STOCK_REPORT_URL', '') %><%= district %>&zone=<%= zone %>&for_end_of_month=<%= last_month %>&size=<%= size %> " target="_blank">
13-
Drug stock report
14-
</a></div>
15-
<div><a href="<%= ENV.fetch('METABASE_TITRATION_URL', '') %><%= @region.name %>" target="_blank">
16-
Metabase: Titration report
17-
</a></div>
18-
<div><a href="<%= ENV.fetch('METABASE_BP_FUDGING_URL', '') %><%= @region.name %>" target="_blank">
19-
Metabase: BP fudging report
20-
</a></div>
8+
9+
<% if @region.facility_region? %>
10+
<% district = @region.source.facility_group.slug %>
11+
<% size = @region.source.facility_size.presence || '' %>
12+
<% zone = @region.source.zone %>
13+
14+
<div><a href="<%= ENV.fetch('DRUG_STOCK_REPORT_URL', '') %><%= district %>&zone=<%= zone %>&for_end_of_month=<%= last_month %>&size=<%= size %> " target="_blank">
15+
Drug stock report
16+
</a></div>
17+
<div><a href="<%= ENV.fetch('METABASE_TITRATION_URL', '') %><%= @region.name %>" target="_blank">
18+
Metabase: Titration report
19+
</a></div>
20+
<div><a href="<%= ENV.fetch('METABASE_BP_FUDGING_URL', '') %><%= @region.name %>" target="_blank">
21+
Metabase: BP fudging report
22+
</a></div>
23+
<% elsif @region.district_region? %>
24+
<div><a href="<%= ENV.fetch('DISTRICT_FACILITY_TREND_REPORT_URL', '') %><%= @region.slug %>&for_end_of_month=" target="_blank">
25+
District facility trend report
26+
</a></div>
27+
<div><a href="<%= ENV.fetch('DISTRICT_DRUG_STOCK_REPORT_URL', '') %><%= @region.slug %>&for_end_of_month=<%= last_month %>" target="_blank">
28+
District Drug stock report
29+
</a></div>
30+
<div><a href="<%= ENV.fetch('DISTRICT_METABASE_TITRATION_URL', '') %><%= @region.name %>" target="_blank">
31+
Metabase: Titration report
32+
</a></div>
33+
<% end %>
2134
</div>
2235
<% end %>
2336

2437

25-
2638
<%= render "header" %>
2739

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

spec/controllers/reports/regions_controller_spec.rb

100644100755
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,38 @@
7575
end
7676
end
7777

78+
context "when the region is a facility region" do
79+
let(:facility_group) { create(:facility_group, organization: organization) }
80+
let(:district) { create(:facility, facility_group: facility_group) }
81+
let(:region) { district.region }
82+
before do
83+
allow(region).to receive(:district_region?).and_return(true)
84+
allow(DeviceDetector).to receive(:new).and_return(double(device_type: "desktop"))
85+
end
86+
context "and the feature flag is enabled" do
87+
before { Flipper.enable(:quick_link_for_metabase, cvho) }
88+
it "displays the quick links section with the correct URLs" do
89+
sign_in(cvho.email_authentication)
90+
get :show, params: {id: facility_group.slug, report_scope: "district"}
91+
expect(response.body).to include("District facility trend report")
92+
expect(response.body).to include("District Drug stock report")
93+
expect(response.body).to include("Metabase: Titration report")
94+
expect(response.body).to include("https://api.example.com/my_facilities/drug_stocks?facility_group=")
95+
expect(response.body).to include("https://api.example.com/my_facilities/bp_controlled?facility_group=")
96+
expect(response.body).to include("https://metabase.example.com/titration?district_name=")
97+
end
98+
end
99+
context "and the feature flag is disabled" do
100+
it "does not display the quick links section" do
101+
sign_in(cvho.email_authentication)
102+
get :show, params: {id: facility_group.slug, report_scope: "district"}
103+
expect(response.body).to_not include("District facility trend report")
104+
expect(response.body).to_not include("District Drug sto_notck report")
105+
expect(response.body).to_not include("Metabase: Titration report")
106+
end
107+
end
108+
end
109+
78110
it "redirects if matching region slug not found" do
79111
sign_in(cvho.email_authentication)
80112
get :show, params: {id: "String-unknown", report_scope: "bad-report_scope"}

0 commit comments

Comments
 (0)