Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wire new dashboard reports with real data #1039

Merged
merged 128 commits into from
Jun 22, 2020
Merged

Conversation

rsanheim
Copy link
Contributor

@rsanheim rsanheim commented Jun 4, 2020

This wires up the new district dashboard views with live queries.

I decided to not go with the rollup summaries right now, because I want to get these reports live in production so that folks w/ access can review them to see how they look and feel with real data. I've been finding hard to test these with sandbox / seed data, because those datasets vary quite a bit from production data.

NOTE: I realize the code here isn't super great, but I think its a fair trade off since none of will be publicly available yet. The URLs are all hidden and will only be distributed to select users for early-access testing.

Definitions Doc: https://docs.google.com/document/d/1MFRYAuy7pgXFZSH_p0YMLAIyGUldXB0KFYZg2jt8KiY/
Story card: https://www.pivotaltracker.com/story/show/171110822

Because

We want great reports for CVHOs

This addresses

Wiring up a district level report for metrics and benchmarks for CVHOSs

claudiovallejo and others added 30 commits May 22, 2020 12:59
… registration', and 'Controlled patients trend' graphs
They need to be conditional so they only insert where the new record is
greater than the existing recorded_at for the period
@rsanheim rsanheim temporarily deployed to simple-review-pr-1039 June 18, 2020 19:11 Inactive
app/assets/stylesheets/reports.scss Outdated Show resolved Hide resolved
@@ -5,22 +5,43 @@ class Dashboard::DistrictsController < AdminController

EXAMPLE_DATA_FILE = "db/data/example_dashboard_data.json"

def index
authorize :dashboard, :view_my_facilities?
@districts = FacilityGroup.all.order(:name)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should use some sort of policy scope to only show what a user has access to

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I cargo culted a scope from another controller, I think its good for this first PR. I'll need to work with someone w/ more experience w/ Pundit to make sure we have this nailed down later.

app/helpers/application_helper.rb Show resolved Hide resolved
(1..number).inject([self]) do |quarters, number|
quarters << quarters.last.next_quarter
end
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LOVE this

app/services/district_report_service.rb Outdated Show resolved Hide resolved
app/services/district_report_service.rb Show resolved Hide resolved
* estimated population
* last updated date
* the state breadcrumb
@rsanheim rsanheim temporarily deployed to simple-review-pr-1039 June 18, 2020 21:07 Inactive
Copy link
Contributor

@kitallis kitallis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm late to the party, but this overall looks good to me. I've just left some non-blocking comments.

app/views/my_facilities/blood_pressure_control.html.erb Outdated Show resolved Hide resolved
@@ -0,0 +1,2 @@
Time::DATE_FORMATS[:month_year] = "%b %Y"
Copy link
Contributor

@kitallis kitallis Jun 19, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this break other dashboards?
I assume only if they are not explicitly applying strftime.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This adds a new format we can use for to_s with time / date via time.to_s(:month_year). It doesn't change the default to_s behavior. Its a handy Rails thing for custom formats, check out https://github.com/rails/rails/blob/master/activesupport/lib/active_support/core_ext/time/conversions.rb.

def compile_control_and_registration_data
beginning_of_period = selected_date.advance(months: -11)
previous_registrations = 0
registrations.each do |(period, count)|
Copy link
Contributor

@kitallis kitallis Jun 19, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This a bit complicated to understand, from what I gather from the logic, could this be simply achieved by the following?

previous_registrations =
  PatientRegistrationsPerDayPerFacility
    .where(facility: @facilities)
    .group(:year, :month)
    .where('year < ?', beginning_of_period.year)
    .or(PatientRegistrationsPerDayPerFacility
          .where('month <= ?', beginning_of_period.month))
    .sum(:registration_count)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah this was bad. I'm going to replace it with a query directly on the patients table that Tim suggested elsewhere.

Btw, we couldn't do that sort of query you suggested, because our year and months are stored as TEXT in the views. We could cast it I suppose and then do the comparison, but then we are doing conversion logic in our SQL, which kinda defeats the purpose of the views.

Copy link
Contributor Author

@rsanheim rsanheim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some notes and responses

app/services/district_report_service.rb Outdated Show resolved Hide resolved
def compile_control_and_registration_data
beginning_of_period = selected_date.advance(months: -11)
previous_registrations = 0
registrations.each do |(period, count)|
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah this was bad. I'm going to replace it with a query directly on the patients table that Tim suggested elsewhere.

Btw, we couldn't do that sort of query you suggested, because our year and months are stored as TEXT in the views. We could cast it I suppose and then do the comparison, but then we are doing conversion logic in our SQL, which kinda defeats the purpose of the views.

app/services/district_report_service.rb Show resolved Hide resolved
app/views/my_facilities/blood_pressure_control.html.erb Outdated Show resolved Hide resolved
@@ -0,0 +1,2 @@
Time::DATE_FORMATS[:month_year] = "%b %Y"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This adds a new format we can use for to_s with time / date via time.to_s(:month_year). It doesn't change the default to_s behavior. Its a handy Rails thing for custom formats, check out https://github.com/rails/rails/blob/master/activesupport/lib/active_support/core_ext/time/conversions.rb.

@rsanheim rsanheim temporarily deployed to simple-review-pr-1039 June 19, 2020 14:15 Inactive
@rsanheim rsanheim temporarily deployed to simple-review-pr-1039 June 19, 2020 14:17 Inactive
@rsanheim rsanheim temporarily deployed to simple-review-pr-1039 June 22, 2020 17:41 Inactive
@rsanheim rsanheim temporarily deployed to simple-review-pr-1039 June 22, 2020 18:33 Inactive
@rsanheim rsanheim temporarily deployed to simple-review-pr-1039 June 22, 2020 19:08 Inactive
@rsanheim rsanheim temporarily deployed to simple-review-pr-1039 June 22, 2020 19:19 Inactive
@rsanheim rsanheim temporarily deployed to simple-review-pr-1039 June 22, 2020 19:39 Inactive
@rsanheim rsanheim dismissed stale reviews from harimohanraj89 and prabhanshuguptagit June 22, 2020 19:54

done

@rsanheim rsanheim merged commit 0f73bb0 into master Jun 22, 2020
@rsanheim rsanheim deleted the dashboard-reports-with-data branch June 22, 2020 19:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants