Closed catalamarti closed 1 year ago
select distinct concept_id, concept_name -- and whatever else you want to output from concept_ancestor a1 join concept_relationship on descendant_concept_id=concept_id_1 and relationship_id in ('Due to of', 'Occurs before') join concept_ancestor a2 on a2.ancestor_concept_id=concept_id_2 join concept on concept_id=a2.descendant_concept_id and standard_concept='S' where a1.ancestor_concept_id=201820 -- this is where you put the concept_id in for which you want to find the sequelae and vocabulary_id='SNOMED'
This will find concepts like "Kimmelstiel-Wilson syndrome", which you would probably think of in the weeks before and after final exam in Med School.
This is now possible as below:
library(CodelistGenerator)
library(dplyr)
#> Warning: package 'dplyr' was built under R version 4.2.3
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
db <- DBI::dbConnect(RPostgres::Postgres(),
dbname = Sys.getenv("DB_SERVER_cdmgold202007_dbi"),
port = Sys.getenv("DB_PORT"),
host = Sys.getenv("DB_HOST"),
user = Sys.getenv("DB_USER"),
password = Sys.getenv("DB_PASSWORD")
)
cdm <- CDMConnector::cdm_from_con(
con = db,
cdm_schema = "public"
)
# Occurs before relationship
codes1 <- getCandidateCodes(cdm=cdm,
keywords=c("Acute chest syndrome"),
domains = "Condition",
includeDescendants=FALSE)
codes2 <- getCandidateCodes(cdm=cdm,
keywords=c("Acute chest syndrome"),
domains = "Condition",
includeDescendants=FALSE,
includeSequela = TRUE)
compareCodelists(codes1, codes2)
#> # A tibble: 4 × 3
#> concept_id concept_name codelist
#> <int> <chr> <chr>
#> 1 254062 Acute chest syndrome Both
#> 2 765385 Acute chest syndrome due to sickle cell-hemoglobin C dise… Both
#> 3 22281 Sickle cell-hemoglobin SS disease Only co…
#> 4 443721 Sickle cell-hemoglobin C disease with crisis Only co…
# Due to of relationship
codes1 <- getCandidateCodes(cdm=cdm,
keywords=c("sickle cell-hemoglobin C disease"),
domains = "Condition",
exactMatch = TRUE,
includeDescendants=FALSE)
codes2 <- getCandidateCodes(cdm=cdm,
keywords=c("sickle cell-hemoglobin C disease"),
domains = "Condition",
exactMatch = TRUE,
includeDescendants=FALSE,
includeSequela = TRUE)
compareCodelists(codes1, codes2)
#> # A tibble: 2 × 3
#> concept_id concept_name codelist
#> <int> <chr> <chr>
#> 1 24006 Sickle cell-hemoglobin C disease Both
#> 2 4334887 Sickle cell-hemoglobin C retinopathy Only codelist 2
Created on 2023-03-29 with reprex v2.0.2
@cgreich @catalamarti I'll close this because I think this is now implemented, but please comment/ reopen this issue if this isn't what you were after
Instead of using a exclude by exclude = "due to" and so. It would be nice to have an option that is: includeSequelae = FALSE. According to @cgreich if we ask SNOMED we will have a relation between the concepts and if they are or not sequelae