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

Updated discovery for new FHIR resources #300

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 83 additions & 0 deletions cumulus_library/studies/discovery/code_definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,31 @@
from cumulus_library.template_sql import sql_utils

code_list = [
# AllergyIntolerance
{
"table_name": "allergyintolerance",
"column_hierarchy": [("clinicalstatus", dict), ("coding", list)],
},
{
"table_name": "allergyintolerance",
"column_hierarchy": [("verificationtstatus", dict), ("coding", list)],
},
{
"table_name": "allergyintolerance",
"column_hierarchy": [("code", dict), ("coding", list)],
},
{
"table_name": "allergyintolerance",
"column_hierarchy": [("reaction", list), ("substance", dict), ("coding", list)],
},
{
"table_name": "allergyintolerance",
"column_hierarchy": [("reaction", list), ("manifestation", list), ("coding", list)],
},
{
"table_name": "allergyintolerance",
"column_hierarchy": [("reaction", list), ("exposureroute", dict), ("coding", list)],
},
# Condition
{
"table_name": "condition",
Expand All @@ -12,6 +37,19 @@
"table_name": "condition",
"column_hierarchy": [("code", dict), ("coding", list)],
},
# DiagnosticReport
{
"table_name": "diagnosticreport",
"column_hierarchy": [("category", list), ("coding", list)],
},
{
"table_name": "diagnosticreport",
"column_hierarchy": [("code", dict), ("coding", list)],
},
{
"table_name": "diagnosticreport",
"column_hierarchy": [("conclusioncode", list), ("coding", list)],
},
# DocumentReference
{
"table_name": "documentreference",
Expand Down Expand Up @@ -92,4 +130,49 @@
"table_name": "patient",
"column_hierarchy": [("maritalstatus", dict), ("coding", list)],
},
# Procedure
{
"table_name": "procedure",
"column_hierarchy": [("statusreason", dict), ("coding", list)],
},
{
"table_name": "procedure",
"column_hierarchy": [("category", dict), ("coding", list)],
},
{
"table_name": "procedure",
"column_hierarchy": [("code", dict), ("coding", list)],
},
{
"table_name": "procedure",
"column_hierarchy": [("performer", list), ("function", dict), ("coding", list)],
},
{
"table_name": "procedure",
"column_hierarchy": [("reasoncode", list), ("coding", list)],
},
{
"table_name": "procedure",
"column_hierarchy": [("bodysite", list), ("coding", list)],
},
{
"table_name": "procedure",
"column_hierarchy": [("outcome", dict), ("coding", list)],
},
{
"table_name": "procedure",
"column_hierarchy": [("complication", list), ("coding", list)],
},
{
"table_name": "procedure",
"column_hierarchy": [("followup", list), ("coding", list)],
},
{
"table_name": "procedure",
"column_hierarchy": [("focalDevice", list), ("action", dict), ("coding", list)],
},
{
"table_name": "procedure",
"column_hierarchy": [("usedcode", list), ("coding", list)],
},
]
266 changes: 266 additions & 0 deletions cumulus_library/studies/discovery/reference_sql/code_detection.sql
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,84 @@
-- ###########################################################

CREATE TABLE discovery__code_sources AS
SELECT DISTINCT
'allergyintolerance' AS table_name,
'clinicalstatus' AS column_name,
table_1.col_1.code,
table_1.col_1.display,
table_1.col_1.system
FROM allergyintolerance,
UNNEST(clinicalstatus.coding) AS table_1 (col_1)

UNION

SELECT *
FROM (
VALUES (
'allergyintolerance',
'verificationtstatus',
'',
'',
''
)
)
AS t (table_name, column_name, code, display, system)

UNION

SELECT DISTINCT
'allergyintolerance' AS table_name,
'code' AS column_name,
table_1.col_1.code,
table_1.col_1.display,
table_1.col_1.system
FROM allergyintolerance,
UNNEST(code.coding) AS table_1 (col_1)

UNION

SELECT *
FROM (
VALUES (
'allergyintolerance',
'reaction.substance',
'',
'',
''
)
)
AS t (table_name, column_name, code, display, system)

UNION

SELECT *
FROM (
VALUES (
'allergyintolerance',
'reaction.manifestation',
'',
'',
''
)
)
AS t (table_name, column_name, code, display, system)

UNION

SELECT *
FROM (
VALUES (
'allergyintolerance',
'reaction.exposureroute',
'',
'',
''
)
)
AS t (table_name, column_name, code, display, system)

UNION

SELECT DISTINCT
'condition' AS table_name,
'category' AS column_name,
Expand All @@ -30,6 +108,43 @@ UNNEST(code.coding) AS table_1 (col_1)

UNION

SELECT DISTINCT
'diagnosticreport' AS table_name,
'category' AS column_name,
table_2.col_2.code,
table_2.col_2.display,
table_2.col_2.system
FROM diagnosticreport,
UNNEST(category) AS table_1 (col_1),
UNNEST(col_1.coding) as table_2 (col_2)

UNION

SELECT DISTINCT
'diagnosticreport' AS table_name,
'code' AS column_name,
table_1.col_1.code,
table_1.col_1.display,
table_1.col_1.system
FROM diagnosticreport,
UNNEST(code.coding) AS table_1 (col_1)

UNION

SELECT *
FROM (
VALUES (
'diagnosticreport',
'conclusioncode',
'',
'',
''
)
)
AS t (table_name, column_name, code, display, system)

UNION

SELECT DISTINCT
'documentreference' AS table_name,
'type' AS column_name,
Expand Down Expand Up @@ -236,5 +351,156 @@ SELECT DISTINCT
FROM patient,
UNNEST(maritalstatus.coding) AS table_1 (col_1)

UNION

SELECT *
FROM (
VALUES (
'procedure',
'statusreason',
'',
'',
''
)
)
AS t (table_name, column_name, code, display, system)

UNION

SELECT *
FROM (
VALUES (
'procedure',
'category',
'',
'',
''
)
)
AS t (table_name, column_name, code, display, system)

UNION

SELECT DISTINCT
'procedure' AS table_name,
'code' AS column_name,
table_1.col_1.code,
table_1.col_1.display,
table_1.col_1.system
FROM procedure,
UNNEST(code.coding) AS table_1 (col_1)

UNION

SELECT *
FROM (
VALUES (
'procedure',
'performer.function',
'',
'',
''
)
)
AS t (table_name, column_name, code, display, system)

UNION

SELECT *
FROM (
VALUES (
'procedure',
'reasoncode',
'',
'',
''
)
)
AS t (table_name, column_name, code, display, system)

UNION

SELECT *
FROM (
VALUES (
'procedure',
'bodysite',
'',
'',
''
)
)
AS t (table_name, column_name, code, display, system)

UNION

SELECT *
FROM (
VALUES (
'procedure',
'outcome',
'',
'',
''
)
)
AS t (table_name, column_name, code, display, system)

UNION

SELECT *
FROM (
VALUES (
'procedure',
'complication',
'',
'',
''
)
)
AS t (table_name, column_name, code, display, system)

UNION

SELECT *
FROM (
VALUES (
'procedure',
'followup',
'',
'',
''
)
)
AS t (table_name, column_name, code, display, system)

UNION

SELECT *
FROM (
VALUES (
'procedure',
'focalDevice.action',
'',
'',
''
)
)
AS t (table_name, column_name, code, display, system)

UNION

SELECT *
FROM (
VALUES (
'procedure',
'usedcode',
'',
'',
''
)
)
AS t (table_name, column_name, code, display, system)



Loading
Loading