-
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
Add core__procedure table #329
Open
mikix
wants to merge
1
commit into
main
Choose a base branch
from
mikix/procedure
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import cumulus_library | ||
from cumulus_library.studies.core.core_templates import core_templates | ||
from cumulus_library.template_sql import sql_utils | ||
|
||
expected_table_cols = { | ||
"procedure": { | ||
"id": [], | ||
"status": [], | ||
"subject": sql_utils.REFERENCE, | ||
"encounter": sql_utils.REFERENCE, | ||
"performedDateTime": [], | ||
"performedPeriod": ["start", "end"], | ||
} | ||
} | ||
|
||
|
||
class CoreProcedureBuilder(cumulus_library.BaseTableBuilder): | ||
display_text = "Creating Procedure tables..." | ||
|
||
def prepare_queries(self, *args, config: cumulus_library.StudyConfig, **kwargs): | ||
code_sources = [ | ||
sql_utils.CodeableConceptConfig( | ||
source_table="procedure", | ||
column_hierarchy=[("category", dict)], | ||
target_table="core__procedure_dn_category", | ||
), | ||
sql_utils.CodeableConceptConfig( | ||
source_table="procedure", | ||
column_hierarchy=[("code", dict)], | ||
target_table="core__procedure_dn_code", | ||
), | ||
] | ||
self.queries += sql_utils.denormalize_complex_objects(config.db, code_sources) | ||
validated_schema = sql_utils.validate_schema(config.db, expected_table_cols) | ||
self.queries.append(core_templates.get_core_template("procedure", validated_schema)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
cumulus_library/studies/core/core_templates/procedure.sql.jinja
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
{% import 'core_utils.jinja' as utils %} | ||
|
||
-- This table includes all fields of interest to the US Core Procedure profile. | ||
-- EXCEPT FOR: | ||
-- * the 'performedAge' and 'performedRange' fields, simply because they are annoying to | ||
-- represent and not frequently used. They aren't even marked as Must Support by the profile | ||
-- (heck, neither is performedPeriod, but we include that since EHRs often like to use periods) | ||
-- | ||
-- AND ADDING: | ||
-- * the `category` field, because it's helpful for classification | ||
-- * the `encounter` field, because come on, why is it left out of the US Core profile | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you've got to be kidding me |
||
-- | ||
-- There are lots of interesting possible fields to support from the base FHIR spec that aren't | ||
-- in the US Core profile, like reasonCode, bodySite, and outcome. But EHR support seems low since | ||
-- they aren't in the profile, so they have been left out so far. | ||
-- | ||
-- US Core profile for reference: | ||
-- * http://hl7.org/fhir/us/core/STU4/StructureDefinition-us-core-procedure.html | ||
|
||
CREATE TABLE core__procedure AS | ||
WITH temp_procedure AS ( | ||
SELECT | ||
{{- utils.basic_cols('procedure', 'src', ['id']) }}, | ||
{{- | ||
utils.nullable_cols( | ||
'procedure', | ||
'src', | ||
[ | ||
'status', | ||
('subject', 'reference', 'subject_ref'), | ||
('encounter', 'reference', 'encounter_ref'), | ||
], | ||
schema | ||
) | ||
}}, | ||
{{- | ||
utils.truncate_date_cols( | ||
'procedure', | ||
'src', | ||
[ | ||
('performedDateTime', 'day'), | ||
('performedDateTime', 'week'), | ||
('performedDateTime', 'month'), | ||
('performedDateTime', 'year'), | ||
('performedPeriod', 'start', 'performedPeriod_start_day', 'day'), | ||
('performedPeriod', 'start', 'performedPeriod_start_week', 'week'), | ||
('performedPeriod', 'start', 'performedPeriod_start_month', 'month'), | ||
('performedPeriod', 'start', 'performedPeriod_start_year', 'year'), | ||
('performedPeriod', 'end', 'performedPeriod_end_day', 'day'), | ||
('performedPeriod', 'end', 'performedPeriod_end_week', 'week'), | ||
('performedPeriod', 'end', 'performedPeriod_end_month', 'month'), | ||
('performedPeriod', 'end', 'performedPeriod_end_year', 'year'), | ||
], | ||
schema | ||
) | ||
}} | ||
FROM "procedure" AS src | ||
) | ||
|
||
SELECT | ||
tp.id, | ||
tp.status, | ||
|
||
dn_category.code AS category_code, | ||
dn_category.system AS category_system, | ||
dn_category.display AS category_display, | ||
|
||
dn_code.code AS code_code, | ||
dn_code.system AS code_system, | ||
dn_code.display AS code_display, | ||
|
||
tp.performedDateTime_day, | ||
tp.performedDateTime_week, | ||
tp.performedDateTime_month, | ||
tp.performedDateTime_year, | ||
|
||
tp.performedPeriod_start_day, | ||
tp.performedPeriod_start_week, | ||
tp.performedPeriod_start_month, | ||
tp.performedPeriod_start_year, | ||
|
||
tp.performedPeriod_end_day, | ||
tp.performedPeriod_end_week, | ||
tp.performedPeriod_end_month, | ||
tp.performedPeriod_end_year, | ||
|
||
concat('Procedure/', tp.id) AS procedure_ref, | ||
tp.subject_ref, | ||
tp.encounter_ref | ||
|
||
FROM temp_procedure AS tp | ||
LEFT JOIN core__procedure_dn_code AS dn_code ON tp.id = dn_code.id | ||
LEFT JOIN core__procedure_dn_category AS dn_category ON tp.id = dn_category.id; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 I think this deserves a tiny callout.
For context, the way completion works is that we ignore any encounters for which all the listed associated tables have not been loaded by the ETL yet.
So adding a new resource like this to the list of "required resources" means:
core
, all encounters will disappear.core
requires more and more resources (like procedures) to be exported and ETL'd before it can function as expectedHowever... This pain is also... the point of completion tracking?
Would we want to draw a line between "resources we really care about" and "resources we kind of care about"? If we didn't add Procedure to the encounter-completion check, but your study used
core__procedure
, you would now be subject to the reasons we added the completion table - engineers ETL'ing data behind the scenes can cause inconsistent/incomplete results when querying.This "ignore encounters" trick was so that studies didn't have to know about the whole completion table feature. They just would
inner join
on encounters at some point and incomplete data would be ignored. But another approach is maybe we have a list of 2nd-tier resources for which studies are expected to manually check the completion tables? (the logic isn't necessarily fun, but we could write some docs with examples)Or we just accept the pain points listed above as we add resources.
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 of two minds about this:
I kinda want to have a discussion at the product level about what's best here and then circle back on the implementation side of things? We can take this as is for now and then backsolve later if we want.