-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
28 changed files
with
15,388 additions
and
14 deletions.
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 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.