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

Better registration query using groupdate #1124

Closed
wants to merge 29 commits into from

Conversation

rsanheim
Copy link
Contributor

@rsanheim rsanheim commented Jun 30, 2020

This gets rid of a pretty complicated SQL query where we also have to
worry about handling time zone conversion ourselves. It uses groupdate to get the counts, and then does the running total with plain ruby.

The ruby here is pretty straightforward and will be easier to maintain
long term.

This also changes the interface to take the district instead of a list
of facilities, which is really the object we care about.

rsanheim and others added 25 commits June 26, 2020 14:23
This works well in my test and gets all the counts, but fails in the
browser due to some time zone issues going on.

I tried to use the date_to_period_sql but was struggling, as that still
didn't seem to solve things.

I may need to dig into
https://phili.pe/posts/timestamps-and-time-zones-in-postgresql/ to
understand how timezones are working with PostgreSQL here.
We can use a regular ruby module and extend it where we need it as a
class method, and include it where we want it as an instance method.
This gets rid of a pretty complicated SQL query where we also have to
worry about handling time zone conversion ourselves.

The ruby here is pretty straightforward and will be easier to maintain
long term.

This also changes the interface to take the district instead of a list
of facilities, which is really the object we care about.
@rsanheim rsanheim requested a review from timcheadle June 30, 2020 19:22
@harimohanraj89 harimohanraj89 temporarily deployed to simple-review-pr-1124 June 30, 2020 19:23 Inactive
@rsanheim rsanheim temporarily deployed to simple-review-pr-1124 June 30, 2020 19:27 Inactive
Base automatically changed from benchmarks to master June 30, 2020 20:25
@rsanheim rsanheim temporarily deployed to simple-review-pr-1124 June 30, 2020 20:38 Inactive
@rsanheim rsanheim temporarily deployed to simple-review-pr-1124 June 30, 2020 22:44 Inactive
@rsanheim rsanheim requested a review from kitallis June 30, 2020 22:45
Copy link
Contributor

@harimohanraj89 harimohanraj89 left a comment

Choose a reason for hiding this comment

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

Looks good.

@@ -19,7 +17,7 @@ def show
else
Date.current.advance(months: -1)
end
@data = DistrictReportService.new(facilities: @district.facilities, selected_date: @selected_date).call
@data = DistrictReportService.new(district: @district, selected_date: @selected_date).call
Copy link
Contributor

Choose a reason for hiding this comment

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

Non-blocking: I like the idea of letting this service class continue accepting a relation of facilities. Perhaps we can rename it? Seems like better setup to support state/block reports in the future, or whatever arbitrary division of facilities.

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 actually wanted to allow either, but for this iteration it needs to take a district because we use

district.patients.with_hypertension

to get registration counts. I imagine we could find a way to go from the set of facilities to get registration counts, but it would be more indirect I think.

@@ -35,6 +33,9 @@ def district_params
def set_time_zone
time_zone = Rails.application.config.country[:time_zone] || DEFAULT_ANALYTICS_TIME_ZONE

Groupdate.time_zone = time_zone
Copy link
Contributor

Choose a reason for hiding this comment

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

YESSSS

Copy link
Contributor Author

@rsanheim rsanheim Jul 1, 2020

Choose a reason for hiding this comment

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

Is there a reason we can't put this at the ApplicationController level?

Copy link
Contributor

Choose a reason for hiding this comment

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

The rest of our application code likely assumes that Groupdate operates in UTC, so I'd be wary of applying this change globally. Step-by-step seems to be the way to go.

@rsanheim rsanheim temporarily deployed to simple-review-pr-1124 July 1, 2020 14:40 Inactive
@rsanheim
Copy link
Contributor Author

rsanheim commented Jul 6, 2020

Closing this in favor of the more comprehensive PR #1131.

@rsanheim rsanheim closed this Jul 6, 2020
@rsanheim rsanheim deleted the better-registration-query branch July 6, 2020 22:21
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.

None yet

4 participants