Skip to content

Commit

Permalink
sc-13986 Enabled diabetes option in progress tab with assigned patien…
Browse files Browse the repository at this point in the history
…ts (#5481)

**Story card:**
[sc-13986](https://app.shortcut.com/simpledotorg/story/13986/enable-diabetes-option-in-progress-tab)

## Because
Enabled the diabetes option with the assigned patients section

## This addresses
Enabled the assigned patients section with values as given in the below
screenshots.

## Test instructions
Enable this flipper flag :diabetes_progress_report_tab to check the
functionality.

---------

Co-authored-by: Dany Sam <[email protected]>
  • Loading branch information
Gyan-Gupta-Rtsl and danySam authored Nov 15, 2024
1 parent f7b647c commit 75c756a
Show file tree
Hide file tree
Showing 10 changed files with 150 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<div id="diabetes-report" class="d-none">
<div class="mb-8px pt-16px pb-16px bgc-white bs-card">
<a
class="d-inline-flex ai-center h-24px mb-24px pl-16px tt-uppercase"
href="#"
onclick="goToPage(id='diabetes-report', 'home-page'); return false;"
>
<%= inline_file("chevron-left.svg") %>
back
</a>
</div>
<%= render(Reports::ProgressAssignedPatientsComponent.new(
assigned_patients: diabetes_reports_data[:assigned_patients],
region: diabetes_reports_data[:region],
diagnosis: "diabetes"
)) %>
</div>
12 changes: 12 additions & 0 deletions app/components/progress_tab/diabetes/diagnosis_report_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

class ProgressTab::Diabetes::DiagnosisReportComponent < ApplicationComponent
include AssetsHelper
include ApplicationHelper

attr_reader :diabetes_reports_data

def initialize(diabetes_reports_data:)
@diabetes_reports_data = diabetes_reports_data
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
</p>
</div>
<p class="m-0px p-0px ta-left fw-normal fs-16px lh-150 c-grey-dark">
<%= t("progress_tab.diagnosis_report.assigned_patients_card.subtitle", facility_name: @region.name, diagnosis: "hypertension") %>
<%= t("progress_tab.diagnosis_report.assigned_patients_card.subtitle", facility_name: @region.name, diagnosis: @diagnosis) %>
</p>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ class Reports::ProgressAssignedPatientsComponent < ViewComponent::Base
include AssetsHelper
include ActionView::Helpers::NumberHelper

attr_reader :assigned_patients, :region
attr_reader :assigned_patients, :region, :diagnosis

def initialize(assigned_patients:, region:)
def initialize(assigned_patients:, region:, diagnosis: nil)
@assigned_patients = assigned_patients
@region = region
@diagnosis = diagnosis || "hypertension"
end
end
7 changes: 7 additions & 0 deletions app/services/reports/facility_progress_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,13 @@ def hypertension_reports_data
}
end

def diabetes_reports_data
{
assigned_patients: repository.cumulative_assigned_diabetic_patients[@region.slug][@period],
region: @region
}
end

memoize def daily_total_follow_ups
total_follow_ups_per_period(period_type: "daily", facility_data: @daily_facility_data)
end
Expand Down
48 changes: 34 additions & 14 deletions app/views/api/v3/analytics/user_analytics/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -72,20 +72,35 @@
<%= t("progress_tab.hypertension_report_title") %>
</p>
</a>
<a
class="p-relative f-1 d-flex fd-column ai-center jc-center h-96px ml-8px p-12px td-none bgc-grey-light-new br-8px"
href="#"
>
<div class="d-flex ai-center jc-center w-32px h-32px mb-8px bgc-white br-8px">
<%= inline_file("graph-grey.svg") %>
</div>
<p class="m-0px p-0px ta-left fw-medium fs-16px c-grey-dark">
<%= t("progress_tab.diabetes_report_title") %>
</p>
<p class="p-absolute b-0 l-0 w-100 fw-regular fs-12px c-grey ta-center bs-border-box">
<%= t("progress_tab.coming_soon") %>
</p>
</a>
<% if Flipper.enabled?(:diabetes_progress_report_tab)%>
<a
class=" f-1 d-flex fd-column ai-center jc-center h-96px ml-8px p-12px td-none bgc-purple-light bs-purple-light-button br-8px"
href="#"
onclick="goToPage('home-page', 'diabetes-report'); return false;"
>
<div class="d-flex ai-center jc-center w-32px h-32px mb-8px bgc-white br-8px">
<%= inline_file("graph-purple.svg") %>
</div>
<p class="m-0px p-0px ta-left fw-medium fs-16px c-purple">
<%= t("progress_tab.diabetes_report_title") %>
</p>
</a>
<% else %>
<a
class="p-relative f-1 d-flex fd-column ai-center jc-center h-96px ml-8px p-12px td-none bgc-grey-light-new br-8px"
href="#"
>
<div class="d-flex ai-center jc-center w-32px h-32px mb-8px bgc-white br-8px">
<%= inline_file("graph-grey.svg") %>
</div>
<p class="m-0px p-0px ta-left fw-medium fs-16px c-grey-dark">
<%= t("progress_tab.diabetes_report_title") %>
</p>
<p class="p-absolute b-0 l-0 w-100 fw-regular fs-12px c-grey ta-center bs-border-box">
<%= t("progress_tab.coming_soon") %>
</p>
</a>
<% end %>
</div>
</div>
<% if current_facility_group.region.feature_enabled?(:drug_stocks) && controller_name == "user_analytics" %>
Expand Down Expand Up @@ -215,6 +230,11 @@
last_updated_at: @user_analytics.last_updated_at
))
%>

<%= render(ProgressTab::Diabetes::DiagnosisReportComponent.new(
diabetes_reports_data: @service.diabetes_reports_data
))
%>
<!-- TODO: The partial "api/v3/analytics/user_analytics/diagnosis_report" need to be removed once the Diabetes reports are released -->
</body>
<%= inline_js("standalone/progress_tab.js") %>
Expand Down
3 changes: 2 additions & 1 deletion doc/wiki/feature-flags.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,5 @@ to facility the launch of a new feature, and may reference the Simple team's int
| ethiopia_dhis2_export | Yes | When enabled, exports data to DHIS2 facilities in ethiopia |
| patients_protected | Yes | To selectively launch the [patients protected](https://app.shortcut.com/simpledotorg/epic/11405) section on the HTN dashboard.
| patients_protected_htn_cascade | Yes | To selectively launch the HTN cascade subsection of the [patients protected](https://app.shortcut.com/simpledotorg/epic/11405) feature on the HTN dashboard.
| diabetes_who_standard_indicator | Yes | When enabled, only FBS and HBA1c measurements are considered for calculating diabetes controlled and uncontrolled rate
| diabetes_who_standard_indicator | Yes | When enabled, only FBS and HBA1c measurements are considered for calculating diabetes controlled and uncontrolled rate
| diabetes_progress_report_tab | Yes | When the progress tab is activated, the diabetes section will be displayed as enabled, followed by a comprehensive listing of all associated key indicators.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
require "rails_helper"

RSpec.describe ProgressTab::Diabetes::DiagnosisReportComponent, type: :component do
let(:diabetes_reports_data) do
{
assigned_patients: 100,
region: double("Region", name: "Region 1"),
diagnosis: "diabetes"
}
end
subject { render_inline(described_class.new(diabetes_reports_data: diabetes_reports_data)) }

it "renders the diabetes report section" do
expect(subject).to have_css("div#diabetes-report")
end

it "renders the back link with correct text and onclick behavior" do
expect(subject).to have_css('a[onclick="goToPage(id=\'diabetes-report\', \'home-page\'); return false;"]', text: "back")
end

it "renders the Reports::ProgressAssignedPatientsComponent with correct data" do
expect(subject.text).to include("Region 1")
expect(subject.text).to include(diabetes_reports_data[:assigned_patients].to_s)
expect(subject.text).to include("diabetes")
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
require "rails_helper"

RSpec.describe Reports::ProgressAssignedPatientsComponent, type: :component do
let(:region) { double("Region", name: "Region 1") }
let(:assigned_patients) { 100 }
let(:diagnosis) { "hypertension" }

subject { render_inline(described_class.new(assigned_patients: assigned_patients, region: region, diagnosis: diagnosis)) }

it "renders the correct title for the assigned patients card" do
expect(subject).to have_css("h2", text: I18n.t("progress_tab.diagnosis_report.assigned_patients_card.title"))
end

it "displays the assigned patients count" do
expect(subject).to have_css("p", text: assigned_patients.to_s)
end

it "displays the correct subtitle with region and diagnosis" do
expect(subject).to have_css("p", text: I18n.t("progress_tab.diagnosis_report.assigned_patients_card.subtitle", facility_name: region.name, diagnosis: diagnosis))
end

context "when diagnosis is not provided" do
let(:diagnosis) { nil }

subject { render_inline(described_class.new(assigned_patients: assigned_patients, region: region)) }

it "uses the default diagnosis value (hypertension)" do
expect(subject).to have_css("p", text: I18n.t("progress_tab.diagnosis_report.assigned_patients_card.subtitle", facility_name: region.name, diagnosis: "hypertension"))
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,22 @@
expect(response.body).to include("Enter drug stock")
end

it "does not render drug stock form if feature flag is disabled" do
Flipper.disable(:diabetes_progress_report_tab)
get :show, format: :html
expect(response.body).to include(I18n.t("progress_tab.coming_soon"))
expect(response.body).to include(I18n.t("progress_tab.diabetes_report_title"))
expect(response.body).to_not include("goToPage('home-page', 'diabetes-report')")
end

it "renders drug stock form if feature flag is enabled" do
Flipper.enable(:diabetes_progress_report_tab)
get :show, format: :html
expect(response.body).to include("goToPage('home-page', 'diabetes-report')")
expect(response.body).to include(I18n.t("progress_tab.diabetes_report_title"))
expect(response.body).to_not include(I18n.t("progress_tab.coming_soon"))
end

it "renders successfully for follow_ups_v2 with no data" do
Flipper.enable(:follow_ups_v2_progress_tab)
patients = create_list(:patient, 2, registration_facility: request_facility, registration_user: request_user, recorded_at: 3.months.ago)
Expand Down

0 comments on commit 75c756a

Please sign in to comment.