Skip to content

Commit 03984a9

Browse files
Controlled BP card (#5776)
Story card: [15132](https://app.shortcut.com/simpledotorg/story/15132/design-controlled-bp-and-statins-cards-to-dm-dashboard) [SIMPLEBACK-35](https://rtsl.atlassian.net/browse/SIMPLEBACK-35?search_id=ff3d2704-f506-4f54-a7da-cf92d9e94904&referrer=quick-find) [SIMPLEBACK-31](https://rtsl.atlassian.net/browse/SIMPLEBACK-31?search_id=a825a931-2a3b-46ae-8b13-769cab3ee674) Because This PR is adding 2 new charts to the Simple DM dashboard: DM patients with controlled BP DM patients >40yr prescribed statins This addresses New DM indicators. Test instructions This feature is behind a flipper flag while adding to production to test before roll-out. Flag: diabetes_cvd_indicators --------- Co-authored-by: Jamie Carter <9541902+jamiecarter7@users.noreply.github.com>
1 parent 688121f commit 03984a9

25 files changed

Lines changed: 1648 additions & 23 deletions

app/assets/javascripts/common/reports.js

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ function dashboardReportsChartJSColors() {
2929
overdueCalledChartFillLightGreen: "rgba(41,181,0,0.2)",
3030
overdueCalledChartFillLightYellow: "rgba(255,241,49,0.25)",
3131
overdueCalledChartFillLightRed: "rgba(255,146,122,0.2)",
32+
lightPink: "rgb(223 78 223 / 0.1)",
33+
mediumPink: "rgb(223 78 223)",
3234
};
3335
}
3436

@@ -190,6 +192,56 @@ DashboardReports = () => {
190192
return withBaseLineConfig(config);
191193
},
192194

195+
dmControlledBPTrend: function (data) {
196+
const config = {
197+
data: {
198+
labels: Object.keys(data.controlledBPRate140),
199+
datasets: [
200+
{
201+
label: "BP controlled <130/80",
202+
data: Object.values(data.controlledBPRate130),
203+
backgroundColor: colors.transparent,
204+
borderColor: colors.darkGreen,
205+
},
206+
{
207+
label: "BP controlled <140/90",
208+
data: Object.values(data.controlledBPRate140),
209+
backgroundColor: colors.transparent,
210+
borderColor: colors.mediumGreen,
211+
},
212+
],
213+
},
214+
// options: {
215+
// scales: {
216+
// x: {
217+
// stacked: true,
218+
// },
219+
// y: {
220+
// stacked: true,
221+
// },
222+
// },
223+
// },
224+
};
225+
return withBaseLineConfig(config);
226+
},
227+
228+
dmPrescribedStatinsTrend: function (data) {
229+
const config = {
230+
data: {
231+
labels: Object.keys(data.prescribedStatinsRate),
232+
datasets: [
233+
{
234+
label: "Patients prescribed statins",
235+
backgroundColor: colors.lightPink,
236+
borderColor: colors.mediumPink,
237+
data: Object.values(data.prescribedStatinsRate),
238+
},
239+
],
240+
},
241+
};
242+
return withBaseLineConfig(config);
243+
},
244+
193245
diabetesMissedVisitsTrend: function (data) {
194246
const config = {
195247
data: {
@@ -1460,7 +1512,7 @@ Reports = function ({
14601512
populateVisitDetailsGraphDefault();
14611513
}
14621514
};
1463-
1515+
14641516
this.initializeTables = () => {
14651517
const tableSortAscending = { descending: false };
14661518
const regionComparisonTable = document.getElementById(

app/assets/stylesheets/application.scss

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -249,9 +249,6 @@ table {
249249
.text-red {
250250
color: $red;
251251
}
252-
.text-green {
253-
color: $green;
254-
}
255252
.text-yellow {
256253
color: $yellow-dark;
257254
}

app/assets/stylesheets/partials/_reports.scss

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
bottom: 8px;
2525
}
2626

27+
.pb-24px {
28+
padding-bottom: 24px;
29+
}
30+
2731
// Pointer events
2832
.pe-none {
2933
pointer-events: none;
@@ -328,6 +332,9 @@
328332
.c-grey-light {
329333
color: $grey-light;
330334
}
335+
.c-green {
336+
color: $green;
337+
}
331338
.c-green-dark {
332339
color: $green-dark;
333340
}
@@ -337,6 +344,9 @@
337344
.c-purple-medium {
338345
color: $purple-mid;
339346
}
347+
.c-pink {
348+
color: $pink;
349+
}
340350
.c-red {
341351
color: $red;
342352
}

app/assets/stylesheets/partials/_variables.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ $orange-dark-new: #DF680F;
4747

4848
$amber: #dfa52f;
4949

50+
$pink: #df4eef;
51+
5052
$purple-light: #eee5fc;
5153
$purple-mid: #a980ef;
5254
$purple: #5300e0;

app/assets/stylesheets/user_analytics.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -903,6 +903,7 @@ footer p {
903903
.c-white { color: $white; }
904904
.c-black { color: $black; }
905905
.c-brown-new { color:$brown-new; }
906+
.c-pink { color: $pink; }
906907
/* BACKGROUND COLORS */
907908
.bgc-grey-lightest { background: $grey-lightest; }
908909
.bgc-grey-light { background: $grey-light; }
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<div id="dm-controlled-bp" class="d-lg-flex min-w-0">
2+
<%= render Dashboard::Card::GraphComponent.new(id: "dmControlledBPTrend", data: graph_data, period: period) do |c| %>
3+
<%= c.title(
4+
title: "DM patients with controlled BP",
5+
subtitle: "Diabetes patients in #{region.name} with controlled BP at their latest visit in the last 3 months (#{bp_control_date_range}).") do |title| %>
6+
<%= title.tooltip({ "Numerator" => "Patients with controlled BP at their latest visit in the last 3 months.",
7+
"Denominator" => t(denominator_copy, region_name: region.name )}
8+
) %>
9+
<%= title.ltfu_toggle(id: 'DMcontrolleBPGraphLtfuToggle', enabled: with_ltfu) %>
10+
<% end %>
11+
<%= c.summary do %>
12+
<div class="ml-4px d-lg-flex align-lg-center">
13+
<p class="c-print-black c-green graph-percent fs-28px" data-key="controlledBPRate140" data-format="percentage"></p>
14+
<div>
15+
<p class="m-0px c-black">
16+
<span data-key="controlledBPNumerator140" data-format="numberWithCommas"></span>
17+
patients with BP &lt;140/90
18+
</p>
19+
</div>
20+
</div>
21+
<div class="ml-4px mb-4px d-lg-flex align-lg-center">
22+
<p class="c-print-black c-green-dark graph-percent fs-28px" data-key="controlledBPRate130" data-format="percentage">
23+
30%</p>
24+
<div>
25+
<p class="m-0px c-black">
26+
<span data-key="controlledBPNumerator130" data-format="numberWithCommas"></span>
27+
patients with BP &lt;130/80
28+
</p>
29+
</div>
30+
</div>
31+
<p class="ml-4px c-grey-dark c-print-black">
32+
of <span data-key="adjustedPatients" data-format="numberWithCommas"></span>
33+
patients registered till
34+
<span data-key="registrationDate"></span>
35+
</p>
36+
<% end %>
37+
<% end %>
38+
</div>
39+
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
class Dashboard::Diabetes::DmBpControlledComponent < ApplicationComponent
2+
attr_reader :data, :region, :period, :with_ltfu
3+
4+
def initialize(data:, region:, period:, use_who_standard:, with_ltfu: false)
5+
@data = data
6+
@region = region
7+
@period = period
8+
@with_ltfu = with_ltfu
9+
@use_who_standard = use_who_standard
10+
end
11+
12+
def graph_data
13+
if with_ltfu
14+
adjusted_patients_data = data[:adjusted_diabetes_patient_counts_with_ltfu]
15+
rates_140 = data[:dm_controlled_bp_140_90_with_ltfu_rates]
16+
rates_130 = data[:dm_controlled_bp_130_80_with_ltfu_rates]
17+
else
18+
adjusted_patients_data = data[:adjusted_diabetes_patient_counts]
19+
rates_140 = data[:dm_controlled_bp_140_90_rates]
20+
rates_130 = data[:dm_controlled_bp_130_80_rates]
21+
end
22+
23+
numerators_140 = data[:dm_patients_with_controlled_bp_140_90]
24+
numerators_130 = data[:dm_patients_with_controlled_bp_130_80]
25+
26+
{
27+
# Rates for BP controlled <140/90 (outer bar)
28+
controlledBPRate140: format_rates(rates_140),
29+
# Rates for BP controlled <130/80 (inner bar, stacked on top)
30+
controlledBPRate130: format_rates(rates_130),
31+
# Patient counts for BP controlled <140/90
32+
controlledBPNumerator140: format_counts(numerators_140),
33+
# Patient counts for BP controlled <130/80
34+
controlledBPNumerator130: format_counts(numerators_130),
35+
# Adjusted patient counts (denominator)
36+
adjustedPatients: format_counts(adjusted_patients_data),
37+
**period_data
38+
}
39+
end
40+
41+
def bp_control_date_range
42+
"#{period.bp_control_range_start_date} to #{period.bp_control_range_end_date}"
43+
end
44+
45+
def denominator_copy
46+
with_ltfu ? "diabetes_bp_controlled_denominator_with_ltfu_copy" : "diabetes_bp_controlled_denominator_copy"
47+
end
48+
49+
private
50+
51+
def period_data
52+
{
53+
startDate: period_info(:bp_control_start_date),
54+
endDate: period_info(:bp_control_end_date),
55+
registrationDate: period_info(:bp_control_registration_date)
56+
}
57+
end
58+
59+
def period_info(key)
60+
data[:period_info].map do |period_obj, period_data_hash|
61+
period_key = period_obj.to_s
62+
date_value = period_data_hash[key]
63+
[period_key, date_value]
64+
end.to_h
65+
end
66+
67+
def format_rates(rates_hash)
68+
rates_hash.transform_keys { |period| period.to_s }
69+
end
70+
71+
def format_counts(counts_hash)
72+
counts_hash.transform_keys { |period| period.to_s }
73+
end
74+
end
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<div id="dm-prescribed-statins" class="d-lg-flex min-w-0">
2+
<%= render Dashboard::Card::GraphComponent.new(id: "dmPrescribedStatinsTrend", data: graph_data, period: period) do |c| %>
3+
<%= c.title(
4+
title: "DM patients &ge;40y prescribed statins".html_safe,
5+
subtitle: "Diabetes patients in #{region.name} ≥40 years old that were prescribed statins at their latest visit in the last 12 months.") do |title| %>
6+
<%= title.tooltip({
7+
"Numerator" => "Patients prescribed statins at their latest visit.",
8+
"Denominator" => t(denominator_copy, region_name: region.name)
9+
}) %>
10+
<%= title.ltfu_toggle(id: 'DMPrescribedStatinsGraphLtfuToggle', enabled: with_ltfu) %>
11+
<% end %>
12+
<%= c.summary do %>
13+
<div class="mb-12px d-lg-flex align-lg-center">
14+
<p class="c-print-black c-pink graph-percent fs-28px" data-key="prescribedStatinsRate" data-format="percentage"></p>
15+
<div>
16+
<p class="m-0px c-black">
17+
<span data-key="prescribedStatinsNumerator" data-format="numberWithCommas"></span>
18+
patients prescribed statins
19+
</p>
20+
<p class="m-0px c-grey-dark c-print-black">
21+
of
22+
<span data-key="cumulativeAssignedPatientsUnderCareOver40yearsOld" data-format="numberWithCommas"></span>
23+
patients ≥40 years old registered till
24+
<span data-key="endDate"></span>
25+
</p>
26+
</div>
27+
</div>
28+
<%end%>
29+
<% end %>
30+
</div>
31+
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
class Dashboard::Diabetes::DmPrescribedStatinsComponent < ApplicationComponent
2+
attr_reader :data, :region, :period, :with_ltfu
3+
4+
def initialize(data:, region:, period:, use_who_standard:, with_ltfu: false)
5+
@data = data
6+
@region = region
7+
@period = period
8+
@with_ltfu = with_ltfu
9+
@use_who_standard = use_who_standard
10+
end
11+
12+
def denominator_copy
13+
with_ltfu ? "dm_prescribed_statins_denominator_with_ltfu_copy" : "dm_prescribed_statins_denominator_copy"
14+
end
15+
16+
def graph_data
17+
if with_ltfu
18+
rates = data[:dm_prescribed_statins_with_ltfu_rates]
19+
denominator = data[:dm_patients_40_and_above_with_ltfu]
20+
else
21+
rates = data[:dm_prescribed_statins_rates]
22+
denominator = data[:dm_patients_40_and_above_under_care]
23+
end
24+
{
25+
prescribedStatinsRate: format_rates(rates),
26+
prescribedStatinsNumerator: format_counts(data[:dm_patients_prescribed_statins]),
27+
cumulativeAssignedPatientsUnderCareOver40yearsOld: format_counts(denominator),
28+
**period_data
29+
}
30+
end
31+
32+
private
33+
34+
def period_data
35+
{
36+
startDate: period_info(:bp_control_start_date),
37+
endDate: period_info(:bp_control_end_date),
38+
registrationDate: period_info(:bp_control_registration_date)
39+
}
40+
end
41+
42+
def period_info(key)
43+
data[:period_info].map do |period_obj, period_data_hash|
44+
period_key = period_obj.to_s
45+
date_value = period_data_hash[key]
46+
[period_key, date_value]
47+
end.to_h
48+
end
49+
50+
def format_rates(rates_hash)
51+
rates_hash.transform_keys { |period| period.to_s }
52+
end
53+
54+
def format_counts(counts_hash)
55+
counts_hash.transform_keys { |period| period.to_s }
56+
end
57+
end

app/models/blood_sugar.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,6 @@ def risk_state
6767
break
6868
end
6969
end
70-
risk_state.to_sym
70+
risk_state&.to_sym
7171
end
7272
end

0 commit comments

Comments
 (0)