-
Notifications
You must be signed in to change notification settings - Fork 0
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
Refactored remaining core tables #166
Conversation
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.
Not done yet, but I'm going to break for lunch and wanted to dump these on ya first 😄
cumulus_library/studies/core/core_templates/documentreference.sql.jinja
Outdated
Show resolved
Hide resolved
cumulus_library/studies/core/core_templates/documentreference.sql.jinja
Outdated
Show resolved
Hide resolved
cumulus_library/studies/core/core_templates/encounter.sql.jinja
Outdated
Show resolved
Hide resolved
e.priority_code_system, | ||
e.reasoncode_code, | ||
e.reasoncode_code_system, | ||
date_diff('year', date(p.birthdate), e.period_start_day) AS age_at_visit, |
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 is probs fine since the ETL always gives you year-only birthDates. But if we ever want to handle cases where the day might actually fall anywhere in the year, this is the logic I used in quality
(works in both athena and duckdb, unlike date_diff
):
year(targetDateTime)
- year(birthDate)
- (
CASE WHEN
extract(doy FROM birthDate) > extract(doy FROM targetDateTime)
THEN 1
ELSE 0
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.
frankly i just copied this over verbatim from the raw sql without thinking about it.
but - can we talk about this? i assume there's a reason, which is why i didn't touch this, but that feels like an odd behavior.
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.
date_diff
works like you want I believe, in Athena. (i.e. it takes day of year into account, is my memory)
But not duckdb - in duckdb, it is naive and just does year-minus-year.
So I used the logic above to get both to work the same. I'm guessing the author of that sql just didn't have duckdb in their brains because why would they. But you might hid oddities during unit testing if you ever feed this a non -01-01
date.
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.
so the bit I actually wanted to talk about was truncating the birthdates at the ETL - just wanted to understand more of why that's happening.
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.
Oh that was because of reducing PHI vibes - we keep most datetimes in place, for clinical reasons. But I guess they (Andy & Jamie) felt like birthdates were more sensitive and we should keep truncating them.
For reference, that happens at the MS-deid-tool layer and we could change the config to not do that.
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.
OK - I created #169 - we're using that now in a way that's slightly inaccurate and i want to, at some point, just discuss the implications once more.
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.
Dropping another group of comments, before I dig into the tests
cumulus_library/studies/core/core_templates/observation.sql.jinja
Outdated
Show resolved
Hide resolved
cumulus_library/studies/core/core_templates/observation.sql.jinja
Outdated
Show resolved
Hide resolved
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.
OK finished looking at this 😮💨 and looks good! Thanks for all this refactoring.
Comments can be resolved as you see fit, but nothing deal breaking.
This PR makes the following changes:
Checklist
docs/
) needs to be updated