-
Notifications
You must be signed in to change notification settings - Fork 36
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
Conversation
…nd' card with dummy data
… 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
@@ -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) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
(1..number).inject([self]) do |quarters, number| | ||
quarters << quarters.last.next_quarter | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LOVE this
* estimated population * last updated date * the state breadcrumb
There was a problem hiding this 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.
@@ -0,0 +1,2 @@ | |||
Time::DATE_FORMATS[:month_year] = "%b %Y" |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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)| |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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.
There was a problem hiding this 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
def compile_control_and_registration_data | ||
beginning_of_period = selected_date.advance(months: -11) | ||
previous_registrations = 0 | ||
registrations.each do |(period, count)| |
There was a problem hiding this comment.
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.
@@ -0,0 +1,2 @@ | |||
Time::DATE_FORMATS[:month_year] = "%b %Y" |
There was a problem hiding this comment.
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.
done
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