Skip to content

Commit

Permalink
Block reports fixes (#1929)
Browse files Browse the repository at this point in the history
**Story card:** [ch2175](https://app.clubhouse.io/simpledotorg/story/2175/block-reports-user-wise-data-missing)

User-wise data tables in the Details section of facility reports were missing.

The underlying cause is: The Details section wasn't handling the distinction between facilities and non-facility regions correctly. Comments are inline for reviewers.

**Recommend reviewing with whitespace ignored**
  • Loading branch information
harimohanraj89 authored Dec 30, 2020
1 parent 969854e commit 3713840
Show file tree
Hide file tree
Showing 4 changed files with 266 additions and 200 deletions.
11 changes: 7 additions & 4 deletions app/controllers/reports/regions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ def details
prev_periods: 6,
include_current_period: true)

if @region.respond_to?(:recent_blood_pressures)
@recent_blood_pressures = paginate(@region.recent_blood_pressures)
if region_source.respond_to?(:recent_blood_pressures)
@recent_blood_pressures = paginate(region_source.recent_blood_pressures)
end
end

Expand Down Expand Up @@ -153,8 +153,8 @@ def set_force_cache
RequestStore.store[:force_cache] = true if force_cache?
end

def find_region
region_source = authorize {
def region_source
@region_source ||= authorize {
case region_class
when "FacilityDistrict"
scope = current_admin.accessible_facilities(:view_reports)
Expand All @@ -174,6 +174,9 @@ def find_region
raise ActiveRecord::RecordNotFound, "unknown region_class #{region_class}"
end
}
end

def find_region
@region = if current_admin.feature_enabled?(:region_reports)
region_source.region
else
Expand Down
6 changes: 5 additions & 1 deletion app/models/region.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,11 @@ def cohort_analytics(period:, prev_periods:)
end

def dashboard_analytics(period:, prev_periods:, include_current_period: true)
DistrictAnalyticsQuery.new(self, period, prev_periods, include_current_period: include_current_period).call
if facility_region?
FacilityAnalyticsQuery.new(self, period, prev_periods, include_current_period: include_current_period).call
else
DistrictAnalyticsQuery.new(self, period, prev_periods, include_current_period: include_current_period).call
end
end

def syncable_patients
Expand Down
Loading

0 comments on commit 3713840

Please sign in to comment.