-
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.
core: add core__diagnosticreport table
- Loading branch information
Showing
21 changed files
with
10,231 additions
and
5 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
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,37 @@ | ||
import cumulus_library | ||
from cumulus_library.studies.core.core_templates import core_templates | ||
from cumulus_library.template_sql import sql_utils | ||
|
||
expected_table_cols = { | ||
"diagnosticreport": { | ||
"id": [], | ||
"status": [], | ||
"subject": sql_utils.REFERENCE, | ||
"encounter": sql_utils.REFERENCE, | ||
"effectiveDateTime": [], | ||
"effectivePeriod": ["start", "end"], | ||
"issued": [], | ||
"result": sql_utils.REFERENCE, | ||
} | ||
} | ||
|
||
|
||
class CoreDiagnosticReportBuilder(cumulus_library.BaseTableBuilder): | ||
display_text = "Creating DiagnosticReport tables..." | ||
|
||
def prepare_queries(self, *args, config: cumulus_library.StudyConfig, **kwargs): | ||
code_sources = [ | ||
sql_utils.CodeableConceptConfig( | ||
source_table="diagnosticreport", | ||
column_hierarchy=[("category", list)], | ||
target_table="core__diagnosticreport_dn_category", | ||
), | ||
sql_utils.CodeableConceptConfig( | ||
source_table="diagnosticreport", | ||
column_hierarchy=[("code", dict)], | ||
target_table="core__diagnosticreport_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("diagnosticreport", 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
102 changes: 102 additions & 0 deletions
102
cumulus_library/studies/core/core_templates/diagnosticreport.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,102 @@ | ||
{% import 'core_utils.jinja' as utils %} | ||
{% import 'unnest_utils.jinja' as unnest_utils %} | ||
|
||
-- This table includes all fields of interest to the US Core DiagnosticReport profiles. | ||
-- EXCEPT FOR: | ||
-- * the 'presentedForm' field, which is an attachment array that is stripped out by the ETL. | ||
-- * the `reporter` field, simply due to it not likely being interesting to consumers | ||
-- and being an array field, which would require a lot of row duplication. | ||
-- | ||
-- US Core profiles for reference: | ||
-- * https://hl7.org/fhir/us/core/STU4/StructureDefinition-us-core-diagnosticreport-lab.html | ||
-- * https://hl7.org/fhir/us/core/STU4/StructureDefinition-us-core-diagnosticreport-note.html | ||
|
||
CREATE TABLE core__diagnosticreport AS | ||
WITH temp_diagnosticreport AS ( | ||
SELECT | ||
{{- utils.basic_cols('diagnosticreport', 'd', ['id']) }}, | ||
{{- | ||
utils.nullable_cols( | ||
'diagnosticreport', | ||
'd', | ||
[ | ||
'status', | ||
('subject', 'reference', 'subject_ref'), | ||
('encounter', 'reference', 'encounter_ref'), | ||
], | ||
schema | ||
) | ||
}}, | ||
{{- | ||
utils.truncate_date_cols( | ||
'diagnosticreport', | ||
'd', | ||
[ | ||
('effectiveDateTime', 'day'), | ||
('effectiveDateTime', 'week'), | ||
('effectiveDateTime', 'month'), | ||
('effectiveDateTime', 'year'), | ||
('effectivePeriod', 'start', 'effectivePeriod_start_day', 'day'), | ||
('effectivePeriod', 'start', 'effectivePeriod_start_week', 'week'), | ||
('effectivePeriod', 'start', 'effectivePeriod_start_month', 'month'), | ||
('effectivePeriod', 'start', 'effectivePeriod_start_year', 'year'), | ||
('effectivePeriod', 'end', 'effectivePeriod_end_day', 'day'), | ||
('effectivePeriod', 'end', 'effectivePeriod_end_week', 'week'), | ||
('effectivePeriod', 'end', 'effectivePeriod_end_month', 'month'), | ||
('effectivePeriod', 'end', 'effectivePeriod_end_year', 'year'), | ||
('issued', 'day'), | ||
('issued', 'week'), | ||
('issued', 'month'), | ||
('issued', 'year'), | ||
], | ||
schema | ||
) | ||
}} | ||
FROM diagnosticreport AS d | ||
), | ||
|
||
temp_result AS ( | ||
{{ unnest_utils.flatten('diagnosticreport', 'reference', parent_field='result') }} | ||
) | ||
|
||
SELECT | ||
td.id, | ||
td.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, | ||
|
||
td.effectiveDateTime_day, | ||
td.effectiveDateTime_week, | ||
td.effectiveDateTime_month, | ||
td.effectiveDateTime_year, | ||
|
||
td.effectivePeriod_start_day, | ||
td.effectivePeriod_start_week, | ||
td.effectivePeriod_start_month, | ||
td.effectivePeriod_start_year, | ||
|
||
td.effectivePeriod_end_day, | ||
td.effectivePeriod_end_week, | ||
td.effectivePeriod_end_month, | ||
td.effectivePeriod_end_year, | ||
|
||
td.issued_day, | ||
td.issued_week, | ||
td.issued_month, | ||
td.issued_year, | ||
|
||
concat('DiagnosticReport/', td.id) AS diagnosticreport_ref, | ||
td.subject_ref, | ||
td.encounter_ref, | ||
tr.reference AS result_ref | ||
|
||
FROM temp_diagnosticreport AS td | ||
LEFT JOIN core__diagnosticreport_dn_code AS dn_code ON td.id = dn_code.id | ||
LEFT JOIN core__diagnosticreport_dn_category AS dn_category ON td.id = dn_category.id | ||
LEFT JOIN temp_result AS tr ON td.id = tr.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
Oops, something went wrong.