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

Better type resolution #46

Merged
merged 15 commits into from
Feb 15, 2024
Merged
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
66 changes: 33 additions & 33 deletions docs/src/examples/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -655,45 +655,45 @@ query.
("concept_1"."vocabulary_id" = 'SNOMED') AND
("concept_1"."concept_code" = '22298006')
UNION ALL
SELECT "concept_3"."concept_id"
FROM "base_1" AS "concept_2"
SELECT "concept_2"."concept_id"
FROM "base_1" AS "base_2"
JOIN (
SELECT
"concept_relationship_1"."concept_id_1",
"concept_relationship_1"."concept_id_2"
FROM "concept_relationship" AS "concept_relationship_1"
WHERE ("concept_relationship_1"."relationship_id" = 'Is a')
) AS "concept_relationship_2" ON ("concept_2"."concept_id" = "concept_relationship_2"."concept_id_2")
JOIN "concept" AS "concept_3" ON ("concept_relationship_2"."concept_id_1" = "concept_3"."concept_id")
) AS "concept_relationship_2" ON ("base_2"."concept_id" = "concept_relationship_2"."concept_id_2")
JOIN "concept" AS "concept_2" ON ("concept_relationship_2"."concept_id_1" = "concept_2"."concept_id")
),
"base_3" ("concept_id") AS (
SELECT "concept_4"."concept_id"
FROM "concept" AS "concept_4"
"base_4" ("concept_id") AS (
SELECT "concept_3"."concept_id"
FROM "concept" AS "concept_3"
WHERE
("concept_4"."vocabulary_id" = 'SNOMED') AND
("concept_4"."concept_code" = '70422006')
("concept_3"."vocabulary_id" = 'SNOMED') AND
("concept_3"."concept_code" = '70422006')
UNION ALL
SELECT "concept_6"."concept_id"
FROM "base_3" AS "concept_5"
SELECT "concept_4"."concept_id"
FROM "base_4" AS "base_5"
JOIN (
SELECT
"concept_relationship_3"."concept_id_1",
"concept_relationship_3"."concept_id_2"
FROM "concept_relationship" AS "concept_relationship_3"
WHERE ("concept_relationship_3"."relationship_id" = 'Is a')
) AS "concept_relationship_4" ON ("concept_5"."concept_id" = "concept_relationship_4"."concept_id_2")
JOIN "concept" AS "concept_6" ON ("concept_relationship_4"."concept_id_1" = "concept_6"."concept_id")
) AS "concept_relationship_4" ON ("base_5"."concept_id" = "concept_relationship_4"."concept_id_2")
JOIN "concept" AS "concept_4" ON ("concept_relationship_4"."concept_id_1" = "concept_4"."concept_id")
)
SELECT
"condition_occurrence_1"."person_id",
"condition_occurrence_1"."condition_start_date"
FROM "condition_occurrence" AS "condition_occurrence_1"
JOIN (
SELECT "base_2"."concept_id"
FROM "base_1" AS "base_2"
LEFT JOIN "base_3" AS "base_4" ON ("base_2"."concept_id" = "base_4"."concept_id")
WHERE ("base_4"."concept_id" IS NULL)
) AS "concept_7" ON ("condition_occurrence_1"."condition_concept_id" = "concept_7"."concept_id")
SELECT "base_3"."concept_id"
FROM "base_1" AS "base_3"
LEFT JOIN "base_4" AS "base_6" ON ("base_3"."concept_id" = "base_6"."concept_id")
WHERE ("base_6"."concept_id" IS NULL)
) AS "base_7" ON ("condition_occurrence_1"."condition_concept_id" = "base_7"."concept_id")
ORDER BY "condition_occurrence_1"."condition_occurrence_id"
=#

Expand Down Expand Up @@ -920,34 +920,34 @@ Now we have all the components to construct the final query:
("concept_1"."vocabulary_id" = 'SNOMED') AND
("concept_1"."concept_code" = '22298006')
UNION ALL
SELECT "concept_3"."concept_id"
FROM "base_1" AS "concept_2"
SELECT "concept_2"."concept_id"
FROM "base_1" AS "base_2"
JOIN (
SELECT
"concept_relationship_1"."concept_id_1",
"concept_relationship_1"."concept_id_2"
FROM "concept_relationship" AS "concept_relationship_1"
WHERE ("concept_relationship_1"."relationship_id" = 'Is a')
) AS "concept_relationship_2" ON ("concept_2"."concept_id" = "concept_relationship_2"."concept_id_2")
JOIN "concept" AS "concept_3" ON ("concept_relationship_2"."concept_id_1" = "concept_3"."concept_id")
) AS "concept_relationship_2" ON ("base_2"."concept_id" = "concept_relationship_2"."concept_id_2")
JOIN "concept" AS "concept_2" ON ("concept_relationship_2"."concept_id_1" = "concept_2"."concept_id")
),
"base_3" ("concept_id") AS (
SELECT "concept_4"."concept_id"
FROM "concept" AS "concept_4"
"base_4" ("concept_id") AS (
SELECT "concept_3"."concept_id"
FROM "concept" AS "concept_3"
WHERE
("concept_4"."vocabulary_id" = 'Visit') AND
("concept_4"."concept_code" = 'IP')
("concept_3"."vocabulary_id" = 'Visit') AND
("concept_3"."concept_code" = 'IP')
UNION ALL
SELECT "concept_6"."concept_id"
FROM "base_3" AS "concept_5"
SELECT "concept_4"."concept_id"
FROM "base_4" AS "base_5"
JOIN (
SELECT
"concept_relationship_3"."concept_id_1",
"concept_relationship_3"."concept_id_2"
FROM "concept_relationship" AS "concept_relationship_3"
WHERE ("concept_relationship_3"."relationship_id" = 'Is a')
) AS "concept_relationship_4" ON ("concept_5"."concept_id" = "concept_relationship_4"."concept_id_2")
JOIN "concept" AS "concept_6" ON ("concept_relationship_4"."concept_id_1" = "concept_6"."concept_id")
) AS "concept_relationship_4" ON ("base_5"."concept_id" = "concept_relationship_4"."concept_id_2")
JOIN "concept" AS "concept_4" ON ("concept_relationship_4"."concept_id_1" = "concept_4"."concept_id")
)
SELECT
"condition_occurrence_3"."person_id",
Expand All @@ -962,13 +962,13 @@ Now we have all the components to construct the final query:
"condition_occurrence_1"."person_id",
"condition_occurrence_1"."condition_start_date"
FROM "condition_occurrence" AS "condition_occurrence_1"
JOIN "base_1" AS "base_2" ON ("condition_occurrence_1"."condition_concept_id" = "base_2"."concept_id")
JOIN "base_1" AS "base_3" ON ("condition_occurrence_1"."condition_concept_id" = "base_3"."concept_id")
ORDER BY "condition_occurrence_1"."condition_occurrence_id"
) AS "condition_occurrence_2"
WHERE (EXISTS (
SELECT NULL AS "_"
FROM "visit_occurrence" AS "visit_occurrence_1"
JOIN "base_3" AS "base_4" ON ("visit_occurrence_1"."visit_concept_id" = "base_4"."concept_id")
JOIN "base_4" AS "base_6" ON ("visit_occurrence_1"."visit_concept_id" = "base_6"."concept_id")
WHERE
("visit_occurrence_1"."person_id" = "condition_occurrence_2"."person_id") AND
("condition_occurrence_2"."condition_start_date" BETWEEN "visit_occurrence_1"."visit_start_date" AND "visit_occurrence_1"."visit_end_date")
Expand Down
60 changes: 36 additions & 24 deletions docs/src/guide/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -1283,13 +1283,13 @@ immediate subtypes as the function:

DBInterface.execute(conn, q) |> DataFrame
#=>
7 DataFrame
10 DataFrame
Row │ concept_id concept_name domain_id vocabulary_id conc ⋯
│ Int64 String String String Stri ⋯
─────┼──────────────────────────────────────────────────────────────────────────
1 │ 4329847 Myocardial infarction Condition SNOMED Clin ⋯
2 │ 312327 Acute myocardial infarction Condition SNOMED Clin
3 columns omitted
6 columns omitted
=#

But how can we fetch not just immediate, but all of the subtypes of a concept?
Expand Down Expand Up @@ -1317,50 +1317,62 @@ This is exactly the action of the [`Iterate`](@ref) node.

render(conn, q) |> print
#=>
WITH RECURSIVE "concept_2" ("concept_id", "concept_name", "domain_id", "vocabulary_id", "concept_class_id", "standard_concept", "concept_code") AS (
WITH RECURSIVE "__1" ("concept_id", "concept_name", "domain_id", "vocabulary_id", "concept_class_id", "standard_concept", "concept_code", "valid_start_date", "valid_end_date", "invalid_reason") AS (
SELECT
"concept_1"."concept_id",
"concept_1"."concept_name",
"concept_1"."domain_id",
"concept_1"."vocabulary_id",
"concept_1"."concept_class_id",
"concept_1"."standard_concept",
"concept_1"."concept_code"
"concept_1"."concept_code",
"concept_1"."valid_start_date",
"concept_1"."valid_end_date",
"concept_1"."invalid_reason"
FROM "concept" AS "concept_1"
WHERE ("concept_1"."concept_name" = 'Myocardial infarction')
UNION ALL
SELECT
"concept_3"."concept_id",
"concept_3"."concept_name",
"concept_3"."domain_id",
"concept_3"."vocabulary_id",
"concept_3"."concept_class_id",
"concept_3"."standard_concept",
"concept_3"."concept_code"
FROM "concept" AS "concept_3"
"concept_2"."concept_id",
"concept_2"."concept_name",
"concept_2"."domain_id",
"concept_2"."vocabulary_id",
"concept_2"."concept_class_id",
"concept_2"."standard_concept",
"concept_2"."concept_code",
"concept_relationship_2"."valid_start_date",
"concept_relationship_2"."valid_end_date",
"concept_relationship_2"."invalid_reason"
FROM "concept" AS "concept_2"
JOIN (
SELECT
"concept_relationship_1"."valid_start_date",
"concept_relationship_1"."valid_end_date",
"concept_relationship_1"."invalid_reason",
"concept_relationship_1"."concept_id_2",
"concept_relationship_1"."concept_id_1"
FROM "concept_relationship" AS "concept_relationship_1"
WHERE ("concept_relationship_1"."relationship_id" = 'Is a')
) AS "concept_relationship_2" ON ("concept_3"."concept_id" = "concept_relationship_2"."concept_id_1")
JOIN "concept_2" AS "concept_4" ON ("concept_relationship_2"."concept_id_2" = "concept_4"."concept_id")
) AS "concept_relationship_2" ON ("concept_2"."concept_id" = "concept_relationship_2"."concept_id_1")
JOIN "__1" AS "__2" ON ("concept_relationship_2"."concept_id_2" = "__2"."concept_id")
)
SELECT
"concept_5"."concept_id",
"concept_5"."concept_name",
"concept_5"."domain_id",
"concept_5"."vocabulary_id",
"concept_5"."concept_class_id",
"concept_5"."standard_concept",
"concept_5"."concept_code"
FROM "concept_2" AS "concept_5"
"concept_3"."concept_id",
"concept_3"."concept_name",
"concept_3"."domain_id",
"concept_3"."vocabulary_id",
"concept_3"."concept_class_id",
"concept_3"."standard_concept",
"concept_3"."concept_code",
"concept_3"."valid_start_date",
"concept_3"."valid_end_date",
"concept_3"."invalid_reason"
FROM "__1" AS "concept_3"
=#

DBInterface.execute(conn, q) |> DataFrame
#=>
7 DataFrame
10 DataFrame
Row │ concept_id concept_name domain_id vocabulary_id ⋯
│ Int64 String String String ⋯
─────┼──────────────────────────────────────────────────────────────────────────
Expand All @@ -1370,6 +1382,6 @@ This is exactly the action of the [`Iterate`](@ref) node.
4 │ 438170 Acute myocardial infarction of i… Condition SNOMED
5 │ 438438 Acute myocardial infarction of a… Condition SNOMED ⋯
6 │ 444406 Acute subendocardial infarction Condition SNOMED
3 columns omitted
6 columns omitted
=#

Loading
Loading