Using SNOMED dictionaries and codelists

Using SNOMED dictionaries and codelists

This package is designed to make it easier to use SNOMED CT in R, including searching the SNOMED CT dictionary and relations, and creating and manipulating SNOMED CT codelists.

Basic introduction to SNOMED CT

SNOMED CT is a clinical terminology system which contains thousands of concepts, each of which has a distinct meaning. Each concept has a unique concept ID, and one or more descriptions (synonyms). It also contains a knowledge model (ontology), specifying which concepts are subtypes of another concept or associated in other ways.

The SNOMED dictionaries are contained within four key tables:

  • CONCEPT - one row per concept, with key metadata about the concepts
  • DESCRIPTION - one row per description
  • STATEDRELATIONSHIP - directly stated relationships
  • RELATIONSHIP - relationships between terms inferred from other relationships

The following additional tables are also included: - SIMPLEMAP - Maps to Clinical Terms Version 3 and some other terms (e.g. COVID-19 terms) - EXTENDEDMAP - Maps to ICD-10 and OPCS4 - REFSET - Sets of SNOMED CT concepts used for specific clinical / operational purposes

Each SNOMED CT concept may have any number of synonyms, but there are the following special types:

  • Fully Specified Name - this is the most precise description of the concept, but is too verbose for general use.
  • Preferred - these is the synonym that is preferred for clinical display in a particular language, and is recorded in the language-specific reference set

Each concept also has a semantic tag, which denotes what type of concept it is (e.g. ‘disorder’ or ‘organism’). This is currently recorded in parentheses at the end of the Fully Specified Name, and can be extracted using the semanticType function in this package.

Loading the SNOMED CT dictionaries

This package contains functions to import a set of SNOMED CT release files which should be obtained from NHS Digital TRUD (https://isd.digital.nhs.uk/trud/user/guest/group/0/home). The International and UK release files are provided in two separate downloads, and need to be combined to create the whole dictionary. This can be done using the loadSNOMED() function and specifying a vector of folder paths to load.

The SNOMED CT UK drug extension is available as a separate file and can (in theory) be added to the SNOMED environment, but this has not yet been tested.

For most users the ‘Snapshot’ files, containing the current versions of the entries, will be the most useful, and these are loaded by loadSNOMED() function. The sample dictionaries in this package are also based on the Snapshot file format. The ‘Delta’ files contain changes since the previous version, and the ‘Full’ files contain a history of the changes to each entry.

When the NHS Digital SNOMED CT files are extracted, they will be in a folder such as ‘SnomedCT_InternationalRF2_PRODUCTION_20200731T120000Z’, and the relevant tables will be in the subfolder ‘Snapshot/Terminology’ (main SNOMED CT tables) and ‘Snapshot/Refset’ (mappings and refsets). Code such as the following can be used to load the tables into R (the file paths should be changed to the actual file paths on your system).

Note that the UK SNOMED CT release needs to be loaded together with the corresponding international release. The UK release cannot be used in isolation because it is incomplete.

# Load package
require(Rdiagnosislist)

# Load UK and International SNOMED CT release files into an
# R environment called 'SNOMED'
SNOMED <- loadSNOMED(c(
  'SnomedCT_InternationalRF2_PRODUCTION_20200731T120000Z/',
  'SnomedCT_UKClinicalRF2_PRODUCTION_20210317T000001Z/'))

# Save the 'SNOMED' environment to a file on disk
saveRDS(SNOMED, file = 'mySNOMED.RDS')

# Reload the 'SNOMED' environment from file
SNOMED <- readRDS('mySNOMED.RDS')

Using R environments

The SNOMED CT dictionary files are loaded into an R ‘environment’, which is an object that can contain other objects. This is a convenient way in R to store a group of objects without cluttering up the global environment with too many individual objects. It also allows different versions of SNOMED CT dictionaries to be used side by side, by loading them into different environments. For ease of use, many of the functions in the package will search for the dictionaries in an environment named ‘SNOMED’ by default, but for programming use it is recommended to specify the environment explicitly in function calls to avoid unexpected errors.

For the purpose of this vignette, we will create a sample set of SNOMED CT files from the sample dictionaries included with the package.

# The sampleSNOMED() function returns an environment containing
# the sample dictionaries
require(Rdiagnosislist)
## Loading required package: Rdiagnosislist
## Loading required package: readxl
## 
## Attaching package: 'Rdiagnosislist'
## The following object is masked from 'package:stats':
## 
##     decompose
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, union
TEST <- sampleSNOMED()

# TEST is now an environment containing the sample SNOMED CT dictionary.
# Objects within the environment can be retrieved using the $ operator
# or the 'get' function. We will export the sample dictionaries to a
# temporary folder to show how to reload them using loadSNOMED()
exportSNOMEDenvir(TEST, tempdir())
## NULL
dir(tempdir())
## [1] "HistorySubstitutionTable_Concepts.txt"
## [2] "Refset_ExtendedMapSnapshot.txt"       
## [3] "Refset_SimpleMapSnapshot.txt"         
## [4] "Refset_SimpleSnapshot.txt"            
## [5] "SNOMEDQueryTable.txt"                 
## [6] "_Concept_Snapshot.txt"                
## [7] "_Description_Snapshot.txt"            
## [8] "_Relationship_Snapshot.txt"           
## [9] "_StatedRelationship_Snapshot.txt"
# loadSNOMED searches for files containing '_Concept_', '_Description_',
# '_StatedRelationship_', '_Relationship_', 'Refset_SimpleMap',
# 'Refset_ExtendedMap' or 'Refset_Simple', as in the actual SNOMED CT
# release files.

# Import using the loadSNOMED function
SNOMED <- loadSNOMED(tempdir(), active_only = FALSE)
## Attempting to load from /tmp/RtmpwK8ULj
## Attempting to load /_Concept_Snapshot.txt
##   Loaded 509 rows.
##   Converted effectiveTime to IDate.
##   Naming as CONCEPT
## Attempting to load /_Description_Snapshot.txt
##   Loaded 1596 rows.
##   Converted effectiveTime to IDate.
##   Naming as DESCRIPTION
## Attempting to load /_StatedRelationship_Snapshot.txt
##   Loaded 329 rows.
##   Converted effectiveTime to IDate.
##   Converting typeId to integer64.
##   Naming as STATEDRELATIONSHIP
## Attempting to load /_Relationship_Snapshot.txt
##   Loaded 1915 rows.
##   Converted effectiveTime to IDate.
##   Converting typeId to integer64.
##   Naming as RELATIONSHIP
## Attempting to load /Refset_SimpleMapSnapshot.txt
##   Loaded 124 rows.
##   Converted effectiveTime to IDate.
##   Naming as SIMPLEMAP
## Attempting to load /Refset_ExtendedMapSnapshot.txt
##   Loaded 915 rows.
##   Converted effectiveTime to IDate.
##   Converting mapCategoryId to integer64.
##   Naming as EXTENDEDMAP
## Attempting to load /Refset_SimpleSnapshot.txt
##   Loaded 428 rows.
##   Converted effectiveTime to IDate.
##   Naming as REFSET
## Attempting to load /SNOMEDQueryTable.txt
##   Loaded 1767 rows.
##   Converting supertypeId to integer64.
##   Naming as QUERY
## Attempting to load /HistorySubstitutionTable_Concepts.txt
##   Loaded 199 rows.
##   Naming as HISTORY
## 
## SNOMED CT tables loaded into environment:
##                  NAME NROW NCOL MB
## 1:            CONCEPT  509    5  0
## 2:        DESCRIPTION 1596    9  0
## 3:        EXTENDEDMAP  915   12  0
## 4:            HISTORY  199   14  0
## 5:              QUERY 1767    3  0
## 6:             REFSET  428    5  0
## 7:       RELATIONSHIP 1915   10  0
## 8:          SIMPLEMAP  124    6  0
## 9: STATEDRELATIONSHIP  329   10  0
##                                                                                COLS
## 1:                              id,effectiveTime,active,moduleId,definitionStatusId
## 2:                      id,effectiveTime,active,moduleId,conceptId,languageCode,...
## 3:        effectiveTime,active,moduleId,refsetId,referencedComponentId,mapGroup,...
## 4: OLDCONCEPTID,OLDCONCEPTSTATUS,NEWCONCEPTID,NEWCONCEPTSTATUS,PATH,ISAMBIGUOUS,...
## 5:                                                 supertypeId,subtypeId,provenance
## 6:                     effectiveTime,active,moduleId,refsetId,referencedComponentId
## 7:                      id,effectiveTime,active,moduleId,sourceId,destinationId,...
## 8:           effectiveTime,active,moduleId,refsetId,referencedComponentId,mapTarget
## 9:                      id,effectiveTime,active,moduleId,sourceId,destinationId,...
##                                                         KEY
## 1:                                                       id
## 2:                                                       id
## 3: mapPriority,mapCategoryId,refsetId,referencedComponentId
## 4:                                NEWCONCEPTID,OLDCONCEPTID
## 5:                                    supertypeId,subtypeId
## 6:                           refsetId,referencedComponentId
## 7:                                   sourceId,typeId,active
## 8:                 refsetId,mapTarget,referencedComponentId
## 9:                                   sourceId,typeId,active
## Total: 0MB using type_size

SNOMED CT concepts IDs in R

SNOMED CT concept IDs are long integers which need to be represented using the integer64 data type in R. This is not available in base R but is provided in the bit64 package which is automatically loaded with this package. They must not be stored as short integer or numeric values because they cannot be stored precisely and may be incorrect.

This package makes it easier to use SNOMED CT concept IDs because they can be supplied as character vectors and converted to ‘SNOMEDconcept’ vectors. The SNOMEDconcept class is a 64-bit integer class which can faithfully store SNOMED CT concept IDs, and is more memory-efficient than storing them as character vectors. If the SNOMED dictionary is available in the R environment, the concepts are displayed with their description in the default print method.

The function ‘as.SNOMEDconcept’ can be used to retrieve the SNOMED concept ID matching a description. This function also converts SNOMED CT concept IDs in other formats (numeric, 64-bit integer or character) into SNOMEDconcept objects.

# Make sure the SNOMED environment is available and contains the SNOMED dictionary
SNOMEDconcept('Heart failure', SNOMED = SNOMED)
## [1] "84114007 | Heart failure (disorder)"
# To use the sample SNOMED dictionary for testing
SNOMEDconcept('Heart failure', SNOMED = sampleSNOMED())
## [1] "84114007 | Heart failure (disorder)"
# If an object named SNOMED containing the SNOMED dictionary is available
# in the current environment, it does not need to be stated in the
# function call
SNOMED <- sampleSNOMED()
SNOMEDconcept('Heart failure')
## [1] "84114007 | Heart failure (disorder)"
# The argument 'exact' can be used to specify whether a regular expression
# search should be done, e.g.
SNOMEDconcept('Heart f', exact = FALSE)
##  [1] "5053004 | Cardiac insufficiency due to prosthesis (disorder)"             
##  [2] "60856006 | Cardiac insufficiency following cardiac surgery (disorder)"    
##  [3] "84114007 | Heart failure (disorder)"                                      
##  [4] "89819002 | Cardiac insufficiency during AND/OR resulting from a proced..."
##  [5] "233924009 | Heart failure as a complication of care (disorder)"           
##  [6] "309634009 | History of heart failure in last year (situation)"            
##  [7] "390868005 | Heart failure screen (procedure)"                             
##  [8] "394927007 | Heart failure excluded (situation)"                           
##  [9] "395105005 | Heart failure confirmed (situation)"                          
## [10] "423475008 | Heart failure education (procedure)"                          
## [11] "446221000 | Heart failure with normal ejection fraction (disorder)"       
## [12] "471880001 | Heart failure due to end stage congenital heart disease (d..."
## [13] "703276005 | Heart failure with reduced ejection fraction due to heart ..."
## [14] "703275009 | Heart failure with reduced ejection fraction due to cardio..."
## [15] "703273002 | Heart failure with reduced ejection fraction due to corona..."
## [16] "703272007 | Heart failure with reduced ejection fraction (disorder)"      
## [17] "703274008 | Heart failure with reduced ejection fraction due to myocar..."
## [18] "788950000 | Heart failure with mid range ejection fraction (disorder)"
# The 'description' function can be used to return the descriptions of
# the concepts found. It returns a data.table with the fully specified 
# name for each term.
description(SNOMEDconcept('Heart f', exact = FALSE))
##             id       conceptId
##          <i64> <SNOMEDconcept>
##  1:  788329019         5053004
##  2:  799854016        60856006
##  3:  825890014        84114007
##  4:  832792011        89819002
##  5:  622176015       233924009
##  6: 2987039012       309634009
##  7: 1465046015       390868005
##  8: 2612836016       394927007
##  9: 2612834018       395105005
## 10: 2641521019       423475008
## 11: 2881211010       446221000
## 12: 2950980013       471880001
## 13: 3008127011       703276005
## 14: 3008129014       703275009
## 15: 3008172015       703273002
## 16: 3008153015       703272007
## 17: 3008310010       703274008
## 18: 3786233013       788950000
##                                                                                       term
##                                                                                     <char>
##  1:                                     Cardiac insufficiency due to prosthesis (disorder)
##  2:                             Cardiac insufficiency following cardiac surgery (disorder)
##  3:                                                               Heart failure (disorder)
##  4:              Cardiac insufficiency during AND/OR resulting from a procedure (disorder)
##  5:                                     Heart failure as a complication of care (disorder)
##  6:                                      History of heart failure in last year (situation)
##  7:                                                       Heart failure screen (procedure)
##  8:                                                     Heart failure excluded (situation)
##  9:                                                    Heart failure confirmed (situation)
## 10:                                                    Heart failure education (procedure)
## 11:                                 Heart failure with normal ejection fraction (disorder)
## 12:                     Heart failure due to end stage congenital heart disease (disorder)
## 13:     Heart failure with reduced ejection fraction due to heart valve disease (disorder)
## 14:          Heart failure with reduced ejection fraction due to cardiomyopathy (disorder)
## 15: Heart failure with reduced ejection fraction due to coronary artery disease (disorder)
## 16:                                Heart failure with reduced ejection fraction (disorder)
## 17:             Heart failure with reduced ejection fraction due to myocarditis (disorder)
## 18:                              Heart failure with mid range ejection fraction (disorder)
# The 'semantic type' function returns the semantic type of the concept
# from the Fully Specified Name
semanticType(SNOMEDconcept('Heart failure'))
## [1] "disorder"
# Functions which expect a SNOMEDconcept object, such as semanticType,
# will automatically convert their argument to SNOMEDconcept using the
# function as.SNOMEDconcept
semanticType('Heart failure')
## [1] "disorder"

Set operations using SNOMEDconcept

This package provides versions of the set functions ‘setdiff’, ‘intersect’ and ‘union’ which work with SNOMEDconcept objects.

# A list of concepts with a description containing the term 'heart'
# (not that all synonyms are searched, not just the Fully Specified Names)
heart <- SNOMEDconcept('Heart|heart', exact = FALSE, SNOMED = sampleSNOMED())

# A list of concepts containing the term 'fail'
fail <- SNOMEDconcept('Fail|fail', exact = FALSE, SNOMED = sampleSNOMED())

# Concepts with heart and fail
intersect(heart, fail)
##  [1] "364006 | Acute left-sided heart failure (disorder)"                       
##  [2] "5053004 | Cardiac insufficiency due to prosthesis (disorder)"             
##  [3] "5148006 | Hypertensive heart disease with congestive heart failure (di..."
##  [4] "5375005 | Chronic left-sided congestive heart failure (disorder)"         
##  [5] "10091002 | High output heart failure (disorder)"                          
##  [6] "10335000 | Chronic right-sided heart failure (disorder)"                  
##  [7] "10633002 | Acute congestive heart failure (disorder)"                     
##  [8] "25544003 | Low output heart failure (disorder)"                           
##  [9] "42343007 | Congestive heart failure (disorder)"                           
## [10] "44313006 | Right heart failure secondary to left heart failure (disorder)"
## [11] "46113002 | Hypertensive heart failure (disorder)"                         
## [12] "48447003 | Chronic heart failure (disorder)"                              
## [13] "56675007 | Acute heart failure (disorder)"                                
## [14] "60856006 | Cardiac insufficiency following cardiac surgery (disorder)"    
## [15] "66989003 | Chronic right-sided congestive heart failure (disorder)"       
## [16] "74960003 | Acute left-sided congestive heart failure (disorder)"          
## [17] "80479009 | Acute right-sided congestive heart failure (disorder)"         
## [18] "82523003 | Congestive rheumatic heart failure (disorder)"                 
## [19] "83105008 | Malignant hypertensive heart disease with congestive heart ..."
## [20] "84114007 | Heart failure (disorder)"                                      
## [21] "85232009 | Left heart failure (disorder)"                                 
## [22] "88805009 | Chronic congestive heart failure (disorder)"                   
## [23] "89819002 | Cardiac insufficiency during AND/OR resulting from a proced..."
## [24] "90727007 | Pleural effusion due to congestive heart failure (disorder)"   
## [25] "92506005 | Biventricular congestive heart failure (disorder)"             
## [26] "111283005 | Chronic left-sided heart failure (disorder)"                  
## [27] "161505003 | History of heart failure (situation)"                         
## [28] "194767001 | Benign hypertensive heart disease with congestive cardiac ..."
## [29] "194779001 | Hypertensive heart and renal disease with (congestive) hea..."
## [30] "194781004 | Hypertensive heart and renal disease with both (congestive..."
## [31] "233924009 | Heart failure as a complication of care (disorder)"           
## [32] "309634009 | History of heart failure in last year (situation)"            
## [33] "314206003 | Refractory heart failure (disorder)"                          
## [34] "359617009 | Acute right-sided heart failure (disorder)"                   
## [35] "390868005 | Heart failure screen (procedure)"                             
## [36] "394887005 | Suspected heart failure (situation)"                          
## [37] "394927007 | Heart failure excluded (situation)"                           
## [38] "395105005 | Heart failure confirmed (situation)"                          
## [39] "418304008 | Diastolic heart failure (disorder)"                           
## [40] "417996009 | Systolic heart failure (disorder)"                            
## [41] "424404003 | Decompensated chronic heart failure (disorder)"               
## [42] "423475008 | Heart failure education (procedure)"                          
## [43] "426611007 | Congestive heart failure due to valvular disease (disorder)"  
## [44] "426263006 | Congestive heart failure due to left ventricular systolic ..."
## [45] "426012001 | Right heart failure due to pulmonary hypertension (disorder)" 
## [46] "429959009 | Family history of heart failure (situation)"                  
## [47] "433305001 | Family history of congestive heart failure (situation)"       
## [48] "441481004 | Chronic systolic heart failure (disorder)"                    
## [49] "441530006 | Chronic diastolic heart failure (disorder)"                   
## [50] "443253003 | Acute on chronic systolic heart failure (disorder)"           
## [51] "443254009 | Acute systolic heart failure (disorder)"                      
## [52] "443343001 | Acute diastolic heart failure (disorder)"                     
## [53] "443344007 | Acute on chronic diastolic heart failure (disorder)"          
## [54] "446221000 | Heart failure with normal ejection fraction (disorder)"       
## [55] "96311000119109 | Exacerbation of congestive heart failure (disorder)"     
## [56] "120851000119104 | Systolic heart failure stage D (disorder)"              
## [57] "120861000119102 | Systolic heart failure stage C (disorder)"              
## [58] "120891000119109 | Diastolic heart failure stage C (disorder)"             
## [59] "120881000119106 | Diastolic heart failure stage D (disorder)"             
## [60] "67431000119105 | Congestive heart failure stage D (disorder)"             
## [61] "67441000119101 | Congestive heart failure stage C (disorder)"             
## [62] "462175008 | Fetal heart failure with redistribution of cardiac output ..."
## [63] "462174007 | Fetal heart failure with myocardial hypertrophy (disorder)"   
## [64] "462172006 | Fetal heart failure (disorder)"                               
## [65] "471880001 | Heart failure due to end stage congenital heart disease (d..."
## [66] "83291003 | Cor pulmonale (disorder)"                                      
## [67] "153931000119109 | Acute combined systolic and diastolic heart failure ..."
## [68] "101281000119107 | Congestive heart failure due to cardiomyopathy (diso..."
## [69] "698296002 | Acute exacerbation of chronic congestive heart failure (di..."
## [70] "698594003 | Symptomatic congestive heart failure (disorder)"              
## [71] "153951000119103 | Acute on chronic combined systolic and diastolic hea..."
## [72] "23341000119109 | Congestive heart failure with right heart failure (di..."
## [73] "153941000119100 | Chronic combined systolic and diastolic heart failur..."
## [74] "72481000119103 | Congestive heart failure as early postoperative compl..."
## [75] "15781000119107 | Hypertensive heart AND chronic kidney disease with co..."
## [76] "703276005 | Heart failure with reduced ejection fraction due to heart ..."
## [77] "703275009 | Heart failure with reduced ejection fraction due to cardio..."
## [78] "703273002 | Heart failure with reduced ejection fraction due to corona..."
## [79] "703272007 | Heart failure with reduced ejection fraction (disorder)"      
## [80] "703274008 | Heart failure with reduced ejection fraction due to myocar..."
## [81] "704242009 | Fetal heart failure due to extracardiac disease (disorder)"   
## [82] "15629741000119102 | Systolic heart failure stage C due to ischemic car..."
## [83] "718287008 | Provision of written information about heart failure (proc..."
## [84] "15629591000119103 | Congestive heart failure stage B due to ischemic c..."
## [85] "15629541000119106 | Congestive heart failure stage C due to ischemic c..."
## [86] "717840005 | Congestive heart failure stage B (disorder)"                  
## [87] "788950000 | Heart failure with mid range ejection fraction (disorder)"    
## [88] "16838951000119100 | Acute on chronic right-sided congestive heart fail..."
## [89] "367363000 | Right ventricular failure (disorder)"                         
## [90] "871617000 | Low output heart failure due to and following Fontan opera..."
## [91] "813991000000101 | Education about deteriorating heart failure (procedure)"
# Concepts with heart and not fail
setdiff(heart, fail)
##  [1] "127337006 | Acute heart disease (disorder)"                               
##  [2] "368009 | Heart valve disorder (disorder)"                                 
##  [3] "13213009 | Congenital heart disease (disorder)"                           
##  [4] "23685000 | Rheumatic heart disease (disorder)"                            
##  [5] "36221001 | Benign hypertensive heart disease (disorder)"                  
##  [6] "54225002 | Malignant hypertensive heart disease (disorder)"               
##  [7] "56265001 | Heart disease (disorder)"                                      
##  [8] "64715009 | Hypertensive heart disease (disorder)"                         
##  [9] "64915003 | Operation on heart (procedure)"                                
## [10] "66816004 | Implantation of cardiac temporary transvenous pacemaker sys..."
## [11] "67189007 | Acute pulmonary heart disease (disorder)"                      
## [12] "79561009 | Structure of right side of heart (body structure)"             
## [13] "80891009 | Heart structure (body structure)"                              
## [14] "86234004 | Hypertensive heart AND renal disease (disorder)"               
## [15] "87837008 | Chronic pulmonary heart disease (disorder)"                    
## [16] "118797008 | Procedure on heart (procedure)"                               
## [17] "119202000 | Heart part (body structure)"                                  
## [18] "128238001 | Chronic heart disease (disorder)"                             
## [19] "128599005 | Structural disorder of heart (disorder)"                      
## [20] "301095005 | Cardiac finding (finding)"                                    
## [21] "57809008 | Myocardial disease (disorder)"                                 
## [22] "409708007 | Heart and/or pericardium structure (body structure)"          
## [23] "307280005 | Implantation of cardiac pacemaker (procedure)"                
## [24] "430901004 | Fetal heart disorder (disorder)"                              
## [25] "473383000 | Abnormality of fetal heart (disorder)"                        
## [26] "87878005 | Left cardiac ventricular structure (body structure)"           
## [27] "53085002 | Right cardiac ventricular structure (body structure)"          
## [28] "82327001 | Cardiac fluoroscopy (procedure)"
# Concepts with heart or fail
union(heart, fail)
##   [1] "127337006 | Acute heart disease (disorder)"                               
##   [2] "364006 | Acute left-sided heart failure (disorder)"                       
##   [3] "368009 | Heart valve disorder (disorder)"                                 
##   [4] "5053004 | Cardiac insufficiency due to prosthesis (disorder)"             
##   [5] "5148006 | Hypertensive heart disease with congestive heart failure (di..."
##   [6] "5375005 | Chronic left-sided congestive heart failure (disorder)"         
##   [7] "10091002 | High output heart failure (disorder)"                          
##   [8] "10335000 | Chronic right-sided heart failure (disorder)"                  
##   [9] "10633002 | Acute congestive heart failure (disorder)"                     
##  [10] "13213009 | Congenital heart disease (disorder)"                           
##  [11] "23685000 | Rheumatic heart disease (disorder)"                            
##  [12] "25544003 | Low output heart failure (disorder)"                           
##  [13] "36221001 | Benign hypertensive heart disease (disorder)"                  
##  [14] "42343007 | Congestive heart failure (disorder)"                           
##  [15] "44313006 | Right heart failure secondary to left heart failure (disorder)"
##  [16] "46113002 | Hypertensive heart failure (disorder)"                         
##  [17] "48447003 | Chronic heart failure (disorder)"                              
##  [18] "54225002 | Malignant hypertensive heart disease (disorder)"               
##  [19] "56265001 | Heart disease (disorder)"                                      
##  [20] "56675007 | Acute heart failure (disorder)"                                
##  [21] "60856006 | Cardiac insufficiency following cardiac surgery (disorder)"    
##  [22] "64715009 | Hypertensive heart disease (disorder)"                         
##  [23] "64915003 | Operation on heart (procedure)"                                
##  [24] "66816004 | Implantation of cardiac temporary transvenous pacemaker sys..."
##  [25] "66989003 | Chronic right-sided congestive heart failure (disorder)"       
##  [26] "67189007 | Acute pulmonary heart disease (disorder)"                      
##  [27] "74960003 | Acute left-sided congestive heart failure (disorder)"          
##  [28] "79561009 | Structure of right side of heart (body structure)"             
##  [29] "80479009 | Acute right-sided congestive heart failure (disorder)"         
##  [30] "80891009 | Heart structure (body structure)"                              
##  [31] "82523003 | Congestive rheumatic heart failure (disorder)"                 
##  [32] "83105008 | Malignant hypertensive heart disease with congestive heart ..."
##  [33] "84114007 | Heart failure (disorder)"                                      
##  [34] "85232009 | Left heart failure (disorder)"                                 
##  [35] "86234004 | Hypertensive heart AND renal disease (disorder)"               
##  [36] "87837008 | Chronic pulmonary heart disease (disorder)"                    
##  [37] "88805009 | Chronic congestive heart failure (disorder)"                   
##  [38] "89819002 | Cardiac insufficiency during AND/OR resulting from a proced..."
##  [39] "90727007 | Pleural effusion due to congestive heart failure (disorder)"   
##  [40] "92506005 | Biventricular congestive heart failure (disorder)"             
##  [41] "111283005 | Chronic left-sided heart failure (disorder)"                  
##  [42] "118797008 | Procedure on heart (procedure)"                               
##  [43] "119202000 | Heart part (body structure)"                                  
##  [44] "128238001 | Chronic heart disease (disorder)"                             
##  [45] "128599005 | Structural disorder of heart (disorder)"                      
##  [46] "161505003 | History of heart failure (situation)"                         
##  [47] "194767001 | Benign hypertensive heart disease with congestive cardiac ..."
##  [48] "194779001 | Hypertensive heart and renal disease with (congestive) hea..."
##  [49] "194781004 | Hypertensive heart and renal disease with both (congestive..."
##  [50] "233924009 | Heart failure as a complication of care (disorder)"           
##  [51] "301095005 | Cardiac finding (finding)"                                    
##  [52] "309634009 | History of heart failure in last year (situation)"            
##  [53] "314206003 | Refractory heart failure (disorder)"                          
##  [54] "359617009 | Acute right-sided heart failure (disorder)"                   
##  [55] "57809008 | Myocardial disease (disorder)"                                 
##  [56] "390868005 | Heart failure screen (procedure)"                             
##  [57] "394887005 | Suspected heart failure (situation)"                          
##  [58] "394927007 | Heart failure excluded (situation)"                           
##  [59] "395105005 | Heart failure confirmed (situation)"                          
##  [60] "409708007 | Heart and/or pericardium structure (body structure)"          
##  [61] "307280005 | Implantation of cardiac pacemaker (procedure)"                
##  [62] "418304008 | Diastolic heart failure (disorder)"                           
##  [63] "417996009 | Systolic heart failure (disorder)"                            
##  [64] "424404003 | Decompensated chronic heart failure (disorder)"               
##  [65] "423475008 | Heart failure education (procedure)"                          
##  [66] "426611007 | Congestive heart failure due to valvular disease (disorder)"  
##  [67] "426263006 | Congestive heart failure due to left ventricular systolic ..."
##  [68] "426012001 | Right heart failure due to pulmonary hypertension (disorder)" 
##  [69] "429959009 | Family history of heart failure (situation)"                  
##  [70] "433305001 | Family history of congestive heart failure (situation)"       
##  [71] "430901004 | Fetal heart disorder (disorder)"                              
##  [72] "441481004 | Chronic systolic heart failure (disorder)"                    
##  [73] "441530006 | Chronic diastolic heart failure (disorder)"                   
##  [74] "443253003 | Acute on chronic systolic heart failure (disorder)"           
##  [75] "443254009 | Acute systolic heart failure (disorder)"                      
##  [76] "443343001 | Acute diastolic heart failure (disorder)"                     
##  [77] "443344007 | Acute on chronic diastolic heart failure (disorder)"          
##  [78] "446221000 | Heart failure with normal ejection fraction (disorder)"       
##  [79] "96311000119109 | Exacerbation of congestive heart failure (disorder)"     
##  [80] "120851000119104 | Systolic heart failure stage D (disorder)"              
##  [81] "120861000119102 | Systolic heart failure stage C (disorder)"              
##  [82] "120891000119109 | Diastolic heart failure stage C (disorder)"             
##  [83] "120881000119106 | Diastolic heart failure stage D (disorder)"             
##  [84] "67431000119105 | Congestive heart failure stage D (disorder)"             
##  [85] "67441000119101 | Congestive heart failure stage C (disorder)"             
##  [86] "462175008 | Fetal heart failure with redistribution of cardiac output ..."
##  [87] "462174007 | Fetal heart failure with myocardial hypertrophy (disorder)"   
##  [88] "462172006 | Fetal heart failure (disorder)"                               
##  [89] "471880001 | Heart failure due to end stage congenital heart disease (d..."
##  [90] "83291003 | Cor pulmonale (disorder)"                                      
##  [91] "473383000 | Abnormality of fetal heart (disorder)"                        
##  [92] "153931000119109 | Acute combined systolic and diastolic heart failure ..."
##  [93] "101281000119107 | Congestive heart failure due to cardiomyopathy (diso..."
##  [94] "698296002 | Acute exacerbation of chronic congestive heart failure (di..."
##  [95] "698594003 | Symptomatic congestive heart failure (disorder)"              
##  [96] "153951000119103 | Acute on chronic combined systolic and diastolic hea..."
##  [97] "23341000119109 | Congestive heart failure with right heart failure (di..."
##  [98] "153941000119100 | Chronic combined systolic and diastolic heart failur..."
##  [99] "72481000119103 | Congestive heart failure as early postoperative compl..."
## [100] "15781000119107 | Hypertensive heart AND chronic kidney disease with co..."
## [101] "703276005 | Heart failure with reduced ejection fraction due to heart ..."
## [102] "703275009 | Heart failure with reduced ejection fraction due to cardio..."
## [103] "703273002 | Heart failure with reduced ejection fraction due to corona..."
## [104] "703272007 | Heart failure with reduced ejection fraction (disorder)"      
## [105] "703274008 | Heart failure with reduced ejection fraction due to myocar..."
## [106] "704242009 | Fetal heart failure due to extracardiac disease (disorder)"   
## [107] "15629741000119102 | Systolic heart failure stage C due to ischemic car..."
## [108] "718287008 | Provision of written information about heart failure (proc..."
## [109] "15629591000119103 | Congestive heart failure stage B due to ischemic c..."
## [110] "15629541000119106 | Congestive heart failure stage C due to ischemic c..."
## [111] "717840005 | Congestive heart failure stage B (disorder)"                  
## [112] "87878005 | Left cardiac ventricular structure (body structure)"           
## [113] "53085002 | Right cardiac ventricular structure (body structure)"          
## [114] "788950000 | Heart failure with mid range ejection fraction (disorder)"    
## [115] "16838951000119100 | Acute on chronic right-sided congestive heart fail..."
## [116] "367363000 | Right ventricular failure (disorder)"                         
## [117] "871617000 | Low output heart failure due to and following Fontan opera..."
## [118] "82327001 | Cardiac fluoroscopy (procedure)"                               
## [119] "813991000000101 | Education about deteriorating heart failure (procedure)"
## [120] "13839000 | Bernheim's syndrome (disorder)"                                
## [121] "14669001 | Acute renal failure syndrome (disorder)"                       
## [122] "42399005 | Renal failure syndrome (disorder)"                             
## [123] "43736008 | Rheumatic left ventricular failure (disorder)"                 
## [124] "49220004 | Hypertensive renal failure (disorder)"                         
## [125] "55565007 | Cardiac failure after obstetrical surgery AND/OR other proc..."
## [126] "195111005 | Decompensated cardiac failure (disorder)"                     
## [127] "195112003 | Compensated cardiac failure (disorder)"                       
## [128] "195114002 | Acute left ventricular failure (disorder)"                    
## [129] "206586007 | Congenital cardiac failure (disorder)"                        
## [130] "276514007 | Neonatal cardiac failure (disorder)"                          
## [131] "277638005 | Sepsis-associated left ventricular failure (disorder)"        
## [132] "277639002 | Sepsis-associated right ventricular failure (disorder)"       
## [133] "313389004 | No cardiac failure (situation)"                               
## [134] "409622000 | Respiratory failure (disorder)"                               
## [135] "410431009 | Cardiorespiratory failure (disorder)"                         
## [136] "609460008 | Induced termination of pregnancy complicated by cardiac ar..."
## [137] "609507007 | Induced termination of pregnancy complicated by cardiac fa..."
## [138] "722095005 | Acute kidney injury due to circulatory failure (disorder)"    
## [139] "722919003 | Neonatal cardiac failure due to decreased left ventricular..."
## [140] "724550005 | Neonatal cardiac failure due to pulmonary overperfusion (d..."

These set operations can be used to create lists of SNOMED CT concepts of interest, similar to the way researchers use Read codes. However, SNOMED CT also allows the use of hierarchies and relationships to locate concepts by their meaning.

Using relationships between SNOMED CT concepts

The most important relationship is the ‘Is a’ relationship, also known as parent and child. This makes it easy to find all specific concepts that are a subtype of a more general concept. The relationship functions (parents, ancestors, children and descendants) all take a SNOMEDconcept object as input, or attempt to convert their argument to SNOMEDconcept.

SNOMED <- sampleSNOMED()

# Parents (immediate ancestors)
parents('Acute heart failure')
## [1] "84114007 | Heart failure (disorder)"       
## [2] "127337006 | Acute heart disease (disorder)"
# Ancestors
ancestors('Acute heart failure')
##  [1] "49483002 | Disorder of mediastinum (disorder)"               
##  [2] "49601007 | Disorder of cardiovascular system (disorder)"     
##  [3] "56265001 | Heart disease (disorder)"                         
##  [4] "64572001 | Disease (disorder)"                               
##  [5] "84114007 | Heart failure (disorder)"                         
##  [6] "105981003 | Disorder of cardiac function (disorder)"         
##  [7] "106063007 | Cardiovascular finding (finding)"                
##  [8] "118228005 | Functional finding (finding)"                    
##  [9] "118946009 | Disorder of thorax (disorder)"                   
## [10] "127337006 | Acute heart disease (disorder)"                  
## [11] "128121009 | Disorder of trunk (disorder)"                    
## [12] "298705000 | Finding of region of thorax (finding)"           
## [13] "301095005 | Cardiac finding (finding)"                       
## [14] "301296002 | Mediastinal finding (finding)"                   
## [15] "302292003 | Finding of trunk structure (finding)"            
## [16] "362965005 | Disorder of body system (disorder)"              
## [17] "404684003 | Clinical finding (finding)"                      
## [18] "406123005 | Viscus structure finding (finding)"              
## [19] "609622007 | Disorder of thoracic segment of trunk (disorder)"
## [20] "609623002 | Finding of upper trunk (finding)"
# Children (immediate descendants)
children('Acute heart failure')
## [1] "364006 | Acute left-sided heart failure (disorder)"                   
## [2] "10633002 | Acute congestive heart failure (disorder)"                 
## [3] "49584005 | Acute cor pulmonale (disorder)"                            
## [4] "359617009 | Acute right-sided heart failure (disorder)"               
## [5] "443254009 | Acute systolic heart failure (disorder)"                  
## [6] "443343001 | Acute diastolic heart failure (disorder)"                 
## [7] "722095005 | Acute kidney injury due to circulatory failure (disorder)"
# Descendants
descendants('Acute heart failure')
##  [1] "364006 | Acute left-sided heart failure (disorder)"                       
##  [2] "10633002 | Acute congestive heart failure (disorder)"                     
##  [3] "49584005 | Acute cor pulmonale (disorder)"                                
##  [4] "74960003 | Acute left-sided congestive heart failure (disorder)"          
##  [5] "80479009 | Acute right-sided congestive heart failure (disorder)"         
##  [6] "359617009 | Acute right-sided heart failure (disorder)"                   
##  [7] "443253003 | Acute on chronic systolic heart failure (disorder)"           
##  [8] "443254009 | Acute systolic heart failure (disorder)"                      
##  [9] "443343001 | Acute diastolic heart failure (disorder)"                     
## [10] "443344007 | Acute on chronic diastolic heart failure (disorder)"          
## [11] "698296002 | Acute exacerbation of chronic congestive heart failure (di..."
## [12] "722095005 | Acute kidney injury due to circulatory failure (disorder)"    
## [13] "153931000119109 | Acute combined systolic and diastolic heart failure ..."
## [14] "153951000119103 | Acute on chronic combined systolic and diastolic hea..."
## [15] "15964701000119109 | Acute cor pulmonale co-occurrent and due to saddle..."
## [16] "16838951000119100 | Acute on chronic right-sided congestive heart fail..."

Attributes of SNOMED CT concepts

The ‘hasAttributes’ function can be used to find terms with particular attributes. For example, to find all disorders with a finding site of the heart, we can use the relatedConcepts function, which retrieves relationships from the RELATIONSHIP and STATEDRELATIONSHIP tables.

In order to find the finding site of a disorder, we use the ‘forward’ relationship. In order to find disorders with a particular finding site, we use the relationship in the ‘reverse’ direction.

require(Rdiagnosislist)
SNOMED <- sampleSNOMED()

# List all the attributes of a concept
print(attrConcept('Heart failure'))
##            sourceId destinationId    typeId relationshipGroup active
##     <SNOMEDconcept>         <i64>     <i64>             <int> <lgcl>
##  1:        84114007     105981003 116680003                 0   TRUE
##  2:        84114007      80891009 363698007                 1   TRUE
##  3:        84114007     260379002 363713009                 2   TRUE
##  4:        10091002      84114007 116680003                 0   TRUE
##  5:        25544003      84114007 116680003                 0   TRUE
##  6:        42343007      84114007 116680003                 0   TRUE
##  7:        46113002      84114007 116680003                 0   TRUE
##  8:        48447003      84114007 116680003                 0   TRUE
##  9:        55565007      84114007 116680003                 0   TRUE
## 10:        56675007      84114007 116680003                 0   TRUE
## 11:        85232009      84114007 116680003                 0   TRUE
## 12:        89819002      84114007 116680003                 0   TRUE
## 13:       161505003      84114007 246090004                 1   TRUE
## 14:       195111005      84114007 116680003                 0   TRUE
## 15:       195112003      84114007 116680003                 0   TRUE
## 16:       206586007      84114007 116680003                 0   TRUE
## 17:       233924009      84114007 116680003                 0   TRUE
## 18:       236003008      84114007  42752001                 2   TRUE
## 19:       276514007      84114007 116680003                 0   TRUE
## 20:       309634009      84114007 246090004                 1   TRUE
## 21:       313389004      84114007 246090004                 1   TRUE
## 22:       314206003      84114007 116680003                 0   TRUE
## 23:       367363000      84114007 116680003                 0   TRUE
## 24:       390868005      84114007 363702006                 2   TRUE
## 25:       394887005      84114007 246090004                 1   TRUE
## 26:       394927007      84114007 246090004                 1   TRUE
## 27:       395105005      84114007 246090004                 1   TRUE
## 28:       410431009      84114007 116680003                 0   TRUE
## 29:       417996009      84114007 116680003                 0   TRUE
## 30:       418304008      84114007 116680003                 0   TRUE
## 31:       423475008      84114007 363702006                 2   TRUE
## 32:       429959009      84114007 246090004                 1   TRUE
## 33:       445236007      84114007 116680003                 0   TRUE
## 34:       446221000      84114007 116680003                 0   TRUE
## 35:       462172006      84114007 116680003                 0   TRUE
## 36:       471880001      84114007 116680003                 0   TRUE
## 37:       609507007      84114007 116680003                 0   TRUE
## 38:       703272007      84114007 116680003                 0   TRUE
## 39:       718287008      84114007 363702006                 2   TRUE
## 40:       722095005      84114007  42752001                 3   TRUE
## 41:       788950000      84114007 116680003                 0   TRUE
## 42: 813991000000101      84114007 363702006                 2   TRUE
##            sourceId destinationId    typeId relationshipGroup active
##                                                                                         sourceDesc
##                                                                                             <char>
##  1:                                                                       Heart failure (disorder)
##  2:                                                                       Heart failure (disorder)
##  3:                                                                       Heart failure (disorder)
##  4:                                                           High output heart failure (disorder)
##  5:                                                            Low output heart failure (disorder)
##  6:                                                            Congestive heart failure (disorder)
##  7:                                                          Hypertensive heart failure (disorder)
##  8:                                                               Chronic heart failure (disorder)
##  9: Cardiac failure after obstetrical surgery AND/OR other procedure including delivery (disorder)
## 10:                                                                 Acute heart failure (disorder)
## 11:                                                                  Left heart failure (disorder)
## 12:                      Cardiac insufficiency during AND/OR resulting from a procedure (disorder)
## 13:                                                           History of heart failure (situation)
## 14:                                                       Decompensated cardiac failure (disorder)
## 15:                                                         Compensated cardiac failure (disorder)
## 16:                                                          Congenital cardiac failure (disorder)
## 17:                                             Heart failure as a complication of care (disorder)
## 18:                                                                     Cardiac ascites (disorder)
## 19:                                                            Neonatal cardiac failure (disorder)
## 20:                                              History of heart failure in last year (situation)
## 21:                                                                 No cardiac failure (situation)
## 22:                                                            Refractory heart failure (disorder)
## 23:                                                           Right ventricular failure (disorder)
## 24:                                                               Heart failure screen (procedure)
## 25:                                                            Suspected heart failure (situation)
## 26:                                                             Heart failure excluded (situation)
## 27:                                                            Heart failure confirmed (situation)
## 28:                                                           Cardiorespiratory failure (disorder)
## 29:                                                              Systolic heart failure (disorder)
## 30:                                                             Diastolic heart failure (disorder)
## 31:                                                            Heart failure education (procedure)
## 32:                                                    Family history of heart failure (situation)
## 33:                                                                Cardiorenal syndrome (disorder)
## 34:                                         Heart failure with normal ejection fraction (disorder)
## 35:                                                                 Fetal heart failure (disorder)
## 36:                             Heart failure due to end stage congenital heart disease (disorder)
## 37:                     Induced termination of pregnancy complicated by cardiac failure (disorder)
## 38:                                        Heart failure with reduced ejection fraction (disorder)
## 39:                               Provision of written information about heart failure (procedure)
## 40:                                      Acute kidney injury due to circulatory failure (disorder)
## 41:                                      Heart failure with mid range ejection fraction (disorder)
## 42:                                        Education about deteriorating heart failure (procedure)
##                                                                                         sourceDesc
##                             destinationDesc                       typeDesc
##                                      <char>                         <char>
##  1: Disorder of cardiac function (disorder)               Is a (attribute)
##  2:        Heart structure (body structure)       Finding site (attribute)
##  3:              Impaired (qualifier value) Has interpretation (attribute)
##  4:                Heart failure (disorder)               Is a (attribute)
##  5:                Heart failure (disorder)               Is a (attribute)
##  6:                Heart failure (disorder)               Is a (attribute)
##  7:                Heart failure (disorder)               Is a (attribute)
##  8:                Heart failure (disorder)               Is a (attribute)
##  9:                Heart failure (disorder)               Is a (attribute)
## 10:                Heart failure (disorder)               Is a (attribute)
## 11:                Heart failure (disorder)               Is a (attribute)
## 12:                Heart failure (disorder)               Is a (attribute)
## 13:                Heart failure (disorder) Associated finding (attribute)
## 14:                Heart failure (disorder)               Is a (attribute)
## 15:                Heart failure (disorder)               Is a (attribute)
## 16:                Heart failure (disorder)               Is a (attribute)
## 17:                Heart failure (disorder)               Is a (attribute)
## 18:                Heart failure (disorder)             Due to (attribute)
## 19:                Heart failure (disorder)               Is a (attribute)
## 20:                Heart failure (disorder) Associated finding (attribute)
## 21:                Heart failure (disorder) Associated finding (attribute)
## 22:                Heart failure (disorder)               Is a (attribute)
## 23:                Heart failure (disorder)               Is a (attribute)
## 24:                Heart failure (disorder)          Has focus (attribute)
## 25:                Heart failure (disorder) Associated finding (attribute)
## 26:                Heart failure (disorder) Associated finding (attribute)
## 27:                Heart failure (disorder) Associated finding (attribute)
## 28:                Heart failure (disorder)               Is a (attribute)
## 29:                Heart failure (disorder)               Is a (attribute)
## 30:                Heart failure (disorder)               Is a (attribute)
## 31:                Heart failure (disorder)          Has focus (attribute)
## 32:                Heart failure (disorder) Associated finding (attribute)
## 33:                Heart failure (disorder)               Is a (attribute)
## 34:                Heart failure (disorder)               Is a (attribute)
## 35:                Heart failure (disorder)               Is a (attribute)
## 36:                Heart failure (disorder)               Is a (attribute)
## 37:                Heart failure (disorder)               Is a (attribute)
## 38:                Heart failure (disorder)               Is a (attribute)
## 39:                Heart failure (disorder)          Has focus (attribute)
## 40:                Heart failure (disorder)             Due to (attribute)
## 41:                Heart failure (disorder)               Is a (attribute)
## 42:                Heart failure (disorder)          Has focus (attribute)
##                             destinationDesc                       typeDesc
# 'Finding site' of a particular disorder
relatedConcepts('Heart failure', 'Finding site')
## [1] "80891009 | Heart structure (body structure)"
# Disorders with a 'Finding site' of 'Heart'
relatedConcepts('Heart', 'Finding site', reverse = TRUE)
##  [1] "5053004 | Cardiac insufficiency due to prosthesis (disorder)"             
##  [2] "10091002 | High output heart failure (disorder)"                          
##  [3] "13213009 | Congenital heart disease (disorder)"                           
##  [4] "25544003 | Low output heart failure (disorder)"                           
##  [5] "33644002 | Postvalvulotomy syndrome (disorder)"                           
##  [6] "36221001 | Benign hypertensive heart disease (disorder)"                  
##  [7] "40172005 | Cardiac complication (disorder)"                               
##  [8] "44088000 | Low cardiac output syndrome (disorder)"                        
##  [9] "46113002 | Hypertensive heart failure (disorder)"                         
## [10] "48447003 | Chronic heart failure (disorder)"                              
## [11] "54225002 | Malignant hypertensive heart disease (disorder)"               
## [12] "55565007 | Cardiac failure after obstetrical surgery AND/OR other proc..."
## [13] "56265001 | Heart disease (disorder)"                                      
## [14] "56675007 | Acute heart failure (disorder)"                                
## [15] "60856006 | Cardiac insufficiency following cardiac surgery (disorder)"    
## [16] "64715009 | Hypertensive heart disease (disorder)"                         
## [17] "68583001 | Auricular dilatation (disorder)"                               
## [18] "78643003 | Postcardiotomy syndrome (disorder)"                            
## [19] "84114007 | Heart failure (disorder)"                                      
## [20] "86234004 | Hypertensive heart AND renal disease (disorder)"               
## [21] "89819002 | Cardiac insufficiency during AND/OR resulting from a proced..."
## [22] "105981003 | Disorder of cardiac function (disorder)"                      
## [23] "127337006 | Acute heart disease (disorder)"                               
## [24] "128238001 | Chronic heart disease (disorder)"                             
## [25] "128599005 | Structural disorder of heart (disorder)"                      
## [26] "195111005 | Decompensated cardiac failure (disorder)"                     
## [27] "195112003 | Compensated cardiac failure (disorder)"                       
## [28] "195130005 | Post cardiac operation functional disturbance (disorder)"     
## [29] "206586007 | Congenital cardiac failure (disorder)"                        
## [30] "233924009 | Heart failure as a complication of care (disorder)"           
## [31] "276514007 | Neonatal cardiac failure (disorder)"                          
## [32] "301095005 | Cardiac finding (finding)"                                    
## [33] "314206003 | Refractory heart failure (disorder)"                          
## [34] "362999008 | Cardiac complication of procedure (disorder)"                 
## [35] "410431009 | Cardiorespiratory failure (disorder)"                         
## [36] "417996009 | Systolic heart failure (disorder)"                            
## [37] "418304008 | Diastolic heart failure (disorder)"                           
## [38] "424404003 | Decompensated chronic heart failure (disorder)"               
## [39] "430901004 | Fetal heart disorder (disorder)"                              
## [40] "441481004 | Chronic systolic heart failure (disorder)"                    
## [41] "441530006 | Chronic diastolic heart failure (disorder)"                   
## [42] "443253003 | Acute on chronic systolic heart failure (disorder)"           
## [43] "443254009 | Acute systolic heart failure (disorder)"                      
## [44] "443343001 | Acute diastolic heart failure (disorder)"                     
## [45] "443344007 | Acute on chronic diastolic heart failure (disorder)"          
## [46] "445236007 | Cardiorenal syndrome (disorder)"                              
## [47] "446221000 | Heart failure with normal ejection fraction (disorder)"       
## [48] "462172006 | Fetal heart failure (disorder)"                               
## [49] "462175008 | Fetal heart failure with redistribution of cardiac output ..."
## [50] "471880001 | Heart failure due to end stage congenital heart disease (d..."
## [51] "473383000 | Abnormality of fetal heart (disorder)"                        
## [52] "609507007 | Induced termination of pregnancy complicated by cardiac fa..."
## [53] "703272007 | Heart failure with reduced ejection fraction (disorder)"      
## [54] "703273002 | Heart failure with reduced ejection fraction due to corona..."
## [55] "703274008 | Heart failure with reduced ejection fraction due to myocar..."
## [56] "703275009 | Heart failure with reduced ejection fraction due to cardio..."
## [57] "703276005 | Heart failure with reduced ejection fraction due to heart ..."
## [58] "704242009 | Fetal heart failure due to extracardiac disease (disorder)"   
## [59] "722095005 | Acute kidney injury due to circulatory failure (disorder)"    
## [60] "722919003 | Neonatal cardiac failure due to decreased left ventricular..."
## [61] "724550005 | Neonatal cardiac failure due to pulmonary overperfusion (d..."
## [62] "788950000 | Heart failure with mid range ejection fraction (disorder)"    
## [63] "871617000 | Low output heart failure due to and following Fontan opera..."
## [64] "120851000119104 | Systolic heart failure stage D (disorder)"              
## [65] "120861000119102 | Systolic heart failure stage C (disorder)"              
## [66] "120881000119106 | Diastolic heart failure stage D (disorder)"             
## [67] "120891000119109 | Diastolic heart failure stage C (disorder)"             
## [68] "153931000119109 | Acute combined systolic and diastolic heart failure ..."
## [69] "153941000119100 | Chronic combined systolic and diastolic heart failur..."
## [70] "153951000119103 | Acute on chronic combined systolic and diastolic hea..."
## [71] "15629741000119102 | Systolic heart failure stage C due to ischemic car..."

SNOMED CT codelists

The SNOMED CT codelist data type allows a list of SNOMED CT concepts to be curated. It allows codelists to be expressed in three formats:

  • simple – a simple list of concepts, one row per concept. It contains at least 2 columns: ‘conceptId’ and ‘term’
  • tree – a hierarchical list, in which each concept may be a single concept or include its descendants. It contains at least 4 columns: ‘conceptId’, ‘term’, ‘include_desc’ (whether descendants of the term are included) and ‘included’ (TRUE means it is an inclusion concept, FALSE means it is excluded)
  • exptree – tree format codelists in which the descendants are also enumerated, and have a missing (NA) entry in the ‘include_desc’ column

Tree format codelists may be more concise and easier to understand, but generally need to be converted to the ‘simple’ format (either using this package or equivalent functionality in a SNOMED CT server) in order to be used in practice, e.g. to run queries in a database. The result of the conversion may vary depending on the version of SNOMED CT used.

SNOMEDcodelist objects can be constructed using the function SNOMEDcodelist. The function ‘is.SNOMEDcodelist’ checks if an object is a SNOMEDcodelist (and optionally whether it is of the specified type), and ‘as.SNOMEDcodelist’ converts an object to a SNOMEDcodelist if it is not already.

The following items of metadata can be stored as part of a SNOMEDcodelist object:

  • codelist_name
  • author
  • version
  • date
  • sct_version (SNOMED CT version taken from the SNOMED environment that was used to create the codelist)
  • timestamp (automatically created)
  • format (‘simple’, ‘tree’ or ‘exptree’)
SNOMED <- sampleSNOMED()

# Create a codelist containing all the descendants of
# the concept 'Heart failure'
my_heart_failure_codelist <- SNOMEDcodelist(
  SNOMEDconcept('Heart failure'), include_desc = TRUE,
  format = 'simple', codelist_name = 'Heart failure')
## Converting 1 concept(s) to a codelist
# Original codelist
print(my_heart_failure_codelist)
## SNOMED CT codelist: 
## codelist_name: Heart failure
## version: 
## author: 
## date: 
## timestamp: 2024-11-28 06:54:01.542656
## sct_version: Sample
## format: simple 
## Key: <conceptId>
##              conceptId                                                     term
##        <SNOMEDconcept>                                                   <char>
##   1:            364006                Acute left-sided heart failure (disorder)
##   2:           5053004       Cardiac insufficiency due to prosthesis (disorder)
##   3:           5148006 Hypertensive heart disease with congestive heart fail...
##   4:           5375005   Chronic left-sided congestive heart failure (disorder)
##   5:          10091002                     High output heart failure (disorder)
##  ---                                                                           
##  98: 15629541000119106 Congestive heart failure stage C due to ischemic card...
##  99: 15629591000119103 Congestive heart failure stage B due to ischemic card...
## 100: 15629741000119102 Systolic heart failure stage C due to ischemic cardio...
## 101: 15964701000119109 Acute cor pulmonale co-occurrent and due to saddle em...
## 102: 16838951000119100 Acute on chronic right-sided congestive heart failure...
# Convert to tree format
tree <- SNOMEDcodelist(my_heart_failure_codelist, format = 'tree')
print(tree)
## SNOMED CT codelist: 
## codelist_name: Heart failure
## version: 
## author: 
## date: 
## timestamp: 2024-11-28 06:54:01.761657
## sct_version: Sample
## format: tree 
## Key: <conceptId>
##          conceptId  inc_d  inclu                     term
##    <SNOMEDconcept> <lgcl> <lgcl>                   <char>
## 1:        84114007   TRUE   TRUE Heart failure (disorder)
# Write out codelist to file
# Metadata are stored in a column named 'metadata'
# export(tree, file = paste0(tempdir(), '/hf_codes.csv'))

# Reload codelist from file (including metadata)
# reloaded_codelist <- as.SNOMEDcodelist(
#  data.table::fread(paste0(tempdir(), '/hf_codes.csv')))
# print(reloaded_codelist)

‘History of’ SNOMED CT concepts

Some SNOMED CT concepts state ‘History of’ a disorder or procedure, such as ‘History of heart failure’. These concepts may be important to include in a search for patients with a past history of a condition, which may be recorded using either the disorder concept or a history concept.

‘History of’ concepts are of the semantic type ‘Situation’ with attributes:

  • Temporal context = In the past
  • Associated finding = concept ID of the historic condition
  • Finding context = Known present
  • Subject relationship context = Subject of record

‘Suspected’ concepts are also of the semantic type ‘Situation’ and have the following attributes:

  • Temporal context = Current or specified time
  • Associated finding = concept ID of the condition that is suspected
  • Finding context = Suspected
  • Subject relationship context = Subject of record

The sample SNOMED dictionary included in this package does not include all these attributes, so the following examples require a full SNOMED CT dictionary to be loaded.

find_historic <- function(x, SNOMED){
  # returns a vector of concepts which are historic versions of
  # the supplied concepts
  # Arguments: x = a SNOMEDconcept vector
  #            SNOMED = a SNOMED environment

  R <- unique(relatedConcepts(x,
    type = SNOMEDconcept('Associated finding'), reverse = TRUE))
  Rpast = hasAttributes(R,
    typeIds = SNOMEDconcept('Temporal context'),
    destinationIds = SNOMEDconcept('In the past'), SNOMED = SNOMED)
  Rknown = hasAttributes(R,
    typeIds = SNOMEDconcept('Finding context'),
    destinationIds = SNOMEDconcept('Known present'), SNOMED = SNOMED)
  Rsubj = hasAttributes(R,
    typeIds = SNOMEDconcept('Subject relationship context'),
    destinationIds = SNOMEDconcept('Subject of record'), SNOMED = SNOMED)
  
  R[Rpast & Rknown & Rsubj]
}

find_suspected <- function(x, SNOMED){
  # returns a vector of concepts which are suspected versions of
  # the supplied concepts
  # Arguments: x = a SNOMEDconcept vector
  #            SNOMED = a SNOMED environment

  R <- unique(relatedConcepts(x,
    type = SNOMEDconcept('Associated finding'), reverse = TRUE))
  Rcurrent = hasAttributes(R,
    typeIds = SNOMEDconcept('Temporal context'),
    destinationIds = SNOMEDconcept('Current or specified time'),
    SNOMED = SNOMED)
  Rsuspected = hasAttributes(R,
    typeIds = SNOMEDconcept('Finding context'),
    destinationIds = SNOMEDconcept('Suspected'), SNOMED = SNOMED)
  Rsubj = hasAttributes(R,
    typeIds = SNOMEDconcept('Subject relationship context'),
    destinationIds = SNOMEDconcept('Subject of record'), SNOMED = SNOMED)
  
  R[Rcurrent & Rsuspected & Rsubj]
}

# Example (using full SNOMED CT dictionary):
#
# > find_historic(SNOMEDconcept('Heart failure'), SNOMED)
# [1] "309634009 | History of heart failure in last year (situation)"
# [2] "161505003 | History of heart failure (situation)"
#             
# > find_suspected(SNOMEDconcept('Heart failure'), SNOMED)
# [1] "394887005 | Suspected heart failure (situation)" 

SNOMED CT simple refsets

Refsets are sets of SNOMED CT terms (like codelists) that are supplied as part of the SNOMED CT distribution and are used for operational purposes. They are included in the REFSET table in the SNOMED dictionary. The getRefset function retrieves a particular refset. Each refset has a name which is a SNOMED CT concept of semantic type ‘foundation metadata concept’.

SNOMED = sampleSNOMED()

# Obtain a list of available refsets with descriptions and counts
merge(SNOMED$REFSET[, .N, by = list(conceptId = refsetId)],
  SNOMED$DESCRIPTION[, list(conceptId, term)], by = 'conceptId')
## Key: <conceptId>
##              conceptId     N
##                  <i64> <int>
##  1:    991381000000107     4
##  2:    991381000000107     4
##  3:    991401000000107     1
##  4:    991401000000107     1
##  5:    991411000000109     2
##  6:    991411000000109     2
##  7:   1127581000000103   102
##  8:   1127581000000103   102
##  9:   1127601000000107   101
## 10:   1127601000000107   101
## 11:   1127821000000102     1
## 12:   1127821000000102     1
## 13: 999000061000000101    26
## 14: 999000061000000101    26
## 15: 999000711000000101    99
## 16: 999000711000000101    99
## 17: 999001061000000106     4
## 18: 999001061000000106     4
## 19: 999001111000000105     3
## 20: 999001111000000105     3
## 21: 999002321000000107    82
## 22: 999002321000000107    82
## 23: 999002571000000104     1
## 24: 999002571000000104     1
## 25: 999004331000000102     1
## 26: 999004331000000102     1
## 27: 999004361000000107     1
## 28: 999004361000000107     1
##              conceptId     N
##                                                                                                                                term
##                                                                                                                              <char>
##  1:                                                                          Comorbid conditions for selection simple reference set
##  2:                                            Comorbid conditions for selection simple reference set (foundation metadata concept)
##  3:                                                             Emergency care presenting complaints or issues simple reference set
##  4:                               Emergency care presenting complaints or issues simple reference set (foundation metadata concept)
##  5:                                                                                   Emergency care diagnosis simple reference set
##  6:                                                     Emergency care diagnosis simple reference set (foundation metadata concept)
##  7:                                                                                              Health issues simple reference set
##  8:                                                                Health issues simple reference set (foundation metadata concept)
##  9:                                                           Healthcare matters simple reference set (foundation metadata concept)
## 10:                                                                                         Healthcare matters simple reference set
## 11:                                                                               Acute kidney injury findings simple reference set
## 12:                                                 Acute kidney injury findings simple reference set (foundation metadata concept)
## 13:                                                     Care planning activities simple reference set (foundation metadata concept)
## 14:                                                                                   Care planning activities simple reference set
## 15:                                                                    Diagnosis simple reference set (foundation metadata concept)
## 16:                                                                                                  Diagnosis simple reference set
## 17:                                                       Renal clinical finding simple reference set (foundation metadata concept)
## 18:                                                                                     Renal clinical finding simple reference set
## 19:                                  United Kingdom diagnostic imaging procedure simple reference set (foundation metadata concept)
## 20:                                                                United Kingdom diagnostic imaging procedure simple reference set
## 21:                                                                          Comorbid conditions comprehensive simple reference set
## 22:                                            Comorbid conditions comprehensive simple reference set (foundation metadata concept)
## 23:                                                                                   Default exclusion filter simple reference set
## 24:                                                     Default exclusion filter simple reference set (foundation metadata concept)
## 25:                                                                              Summary Care Record inclusion simple reference set
## 26:                                                Summary Care Record inclusion simple reference set (foundation metadata concept)
## 27:                               General practice summary data sharing exclusion for termination of pregnancy simple reference set
## 28: General practice summary data sharing exclusion for termination of pregnancy simple reference set (foundation metadata concept)
##                                                                                                                                term
# Obtain a refset as a SNOMEDconcept vector
renal_ref <- getRefset('Renal clinical finding simple reference set')

# Find out whether a concept is included in a refset
SNOMEDconcept('Renal failure') %in% renal_ref
## [1] FALSE

Mapping between SNOMED CT and ICD-10 and OPCS4

Mapping tables are provided in the international and UK SNOMED CT distributions for ICD-10. The UK distribution also includes mappings to CTV3, ICD Oncology (ICD-O) for body locations and OPCS4.

These mappings are designed to enable clinical data entered using SNOMED CT to be converted to ICD-10 or OPCS4 in a semi-automated manner. This package includes functions to use the mappings to convert codelists from one format to another. Beware that these code systems are not equivalent, so it is necessary to check the output codelist to ensure that the mapping makes sense. For ICD-10 maps, only maps with mapCategoryId = ‘Map source concept is properly classified’ are retrieved.

The table SIMPLEMAPS contains maps to CTV3 and ICD-O, whereas EXTENDEDMAPS contains mappings to ICD-10 and OPCS4. The EXTENDEDMAPS tables contains additional columns to define the type of mapping, but they are not used by the functions in this package.

The getMaps function can be used to conveniently return the ICD-10 or OPCS4 codes associated with a SNOMED CT concept. Note that in the output data.table, the icd10_code or opcs4_code column is a list (because there may be multiple entries per SNOMED CT concept). To return each map on a separate row, use getMaps with the option single_row_per_concept = FALSE.

# Example: creating an ICD-10 heart failure codelist using SNOMED CT
SNOMED <- sampleSNOMED()

my_heart_failure_codelist <- SNOMEDcodelist(
  SNOMEDconcept('Heart failure'), include_desc = FALSE)
## Converting 1 concept(s) to a codelist
getMaps(my_heart_failure_codelist, to = c('icd10'))

my_pacemaker_codelist <- SNOMEDcodelist(
  SNOMEDconcept('Implantation of cardiac pacemaker'),
  include_desc = FALSE)
## Converting 1 concept(s) to a codelist
getMaps(my_pacemaker_codelist, to = c('opcs4'))

Mapping between SNOMED CT and Read Clinical Terminology

Prior to the introduction of SNOMED CT, the Read Clinical Terminology (version 2 or 3) were used to record clinical information in UK general practice. SNOMED CT terms are partly derived from Read, so all Read terms have a ‘forward’ mapping to an appropriate SNOMED CT term. NHS Digital provides a set of mappings to enable these conversions in clinical systems that are moving to SNOMED CT. These tables are available from the Technology Reference data Update Distribution .

This package provides the ‘loadMAPS’ function for loading the NHS Digital files into an R data.table, the ‘MAPS’ sample dataset and the ‘getMaps’ function for retrieving Read Clinical Terms Version 2 (Read 2) and Clinical Terms Version 3 (CTV3) that map to a set of SNOMED CT concepts.

These maps can be used for converting SNOMED CT codelists into Read 2 or CTV3 format for running queries, such as to characterise patient phenotypes or identify patient populations for research. They cannot be used in the reverse direction (to map a Read 2/CTV3 codelist to SNOMED CT) because some of the SNOMED CT terms will be missed out, and the list will be incomplete.

Use the ‘unlist’ function, followed by deduplication, to create a table of concepts in another coding system mapped from SNOMED CT, as in the example below.

# Example: creating a Read heart failure codelist using SNOMED CT
SNOMED <- sampleSNOMED()
data(READMAPS)

# Start off with a SNOMED CT codelist containing the descendants of
# the concept 'Heart failure'
my_heart_failure_codelist <- SNOMEDcodelist(
  SNOMEDconcept('Heart failure'), include_desc = TRUE)
## Converting 1 concept(s) to a codelist
single_row_maps <- getMaps(my_heart_failure_codelist,
  mappingtable = READMAPS, to = c('read2', 'ctv3'),
  single_row_per_concept = TRUE)

# Display the maps - one row per concept (long terms truncated)
print(single_row_maps[, list(term = substr(term, 1, 10), read2_code,
  ctv3_concept)])
## SNOMED CT codelist: 
## codelist_name: 
## version: 
## author: 
## date: 
## timestamp: 
## sct_version: 
## format:  
##            term read2_code ctv3_concept
##          <char>     <list>       <list>
##   1: Acute left                        
##   2: Cardiac in                        
##   3: Hypertensi                        
##   4: Chronic le                        
##   5: High outpu                        
##  ---                                   
##  98: Congestive                        
##  99: Congestive                        
## 100: Systolic h                        
## 101: Acute cor                         
## 102: Acute on c
multi_row_maps <- getMaps(my_heart_failure_codelist,
  mappingtable = READMAPS, to = 'read2',
  single_row_per_concept = FALSE)

# Display the maps - multiple rows per concept (long terms truncated)
print(multi_row_maps[, list(term = substr(term, 1, 10), read2_code,
  read2_term = substr(read2_term, 1, 30))])
##           term read2_code                     read2_term
##         <char>     <char>                         <char>
##  1: Acute cong    G580000 Acute congestive heart failure
##  2: Congestive    G580.00       Congestive heart failure
##  3: Congestive    G580.11     Congestive cardiac failure
##  4: Rheumatic     G1yz100 Rheumatic left ventricular fai
##  5: Acute cor     G400.00            Acute cor pulmonale
##  6: Acute hear    G582.00            Acute heart failure
##  7: Cardiac as    G581.11               Asthma - cardiac
##  8: Chronic co    G41z.11          Chronic cor pulmonale
##  9: Malignant     G210100 Malignant hypertensive heart d
## 10: Heart fail    G58..00                  Heart failure
## 11: Heart fail    G58z.00              Heart failure NOS
## 12: Heart fail    G58z.11                     Weak heart
## 13: Heart fail    G58z.12            Cardiac failure NOS
## 14: Heart fail    G58..11                Cardiac failure
## 15: Left heart    G581.00       Left ventricular failure
## 16: Chronic co    G580100 Chronic congestive heart failu
## 17: Biventricu    G580.14          Biventricular failure
## 18: Benign hyp    G211100 Benign hypertensive heart dise
## 19: Hypertensi    G232.00 Hypertensive heart and renal d
## 20: Hypertensi    G234.00 Hypertensive heart and renal d
## 21: Decompensa    G580200  Decompensated cardiac failure
## 22: Compensate    G580300    Compensated cardiac failure
## 23: Acute left    G581000 Acute left ventricular failure
## 24: Congenital    Q48y100     Congenital cardiac failure
## 25: Heart fail    SP11111 Heart failure as a complicatio
## 26: Neonatal c    Q490.00       Neonatal cardiac failure
## 27: Right vent    G580.13      Right ventricular failure
## 28: Right vent    G584.00      Right ventricular failure
## 29: Cardioresp    R2y1000   [D]Cardiorespiratory failure
## 30: Congestive    G580400 Congestive heart failure due t
## 31: Heart fail    G583.12 Heart failure with preserved e
## 32: Heart fail    G583.11 HFNEF - heart failure with nor
## 33: Heart fail    G583.00 Heart failure with normal ejec
## 34: Induced te    L09y200 Cardiac failure following abor
##           term read2_code                     read2_term
# Create a standalone Read2 codelist
read_codelist <- data.table::data.table(
  code = unlist(single_row_maps$read2_code),
  term = unlist(single_row_maps$read2_term))
print(read_codelist[!duplicated(read_codelist)][order(code)])
##        code
##      <char>
##  1: G1yz100
##  2: G210100
##  3: G211100
##  4: G232.00
##  5: G234.00
##  6: G400.00
##  7: G41z.11
##  8: G58..00
##  9: G58..11
## 10: G580.00
## 11: G580.11
## 12: G580.13
## 13: G580.14
## 14: G580000
## 15: G580100
## 16: G580200
## 17: G580300
## 18: G580400
## 19: G581.00
## 20: G581.11
## 21: G581000
## 22: G582.00
## 23: G583.00
## 24: G583.11
## 25: G583.12
## 26: G584.00
## 27: G58z.00
## 28: G58z.11
## 29: G58z.12
## 30: L09y200
## 31: Q48y100
## 32: Q490.00
## 33: R2y1000
## 34: SP11111
##        code
##                                                                                            term
##                                                                                          <char>
##  1:                                                          Rheumatic left ventricular failure
##  2:                        Malignant hypertensive heart disease with congestive cardiac failure
##  3:                           Benign hypertensive heart disease with congestive cardiac failure
##  4:                        Hypertensive heart and renal disease with (congestive) heart failure
##  5: Hypertensive heart and renal disease with both (congestive) heart failure and renal failure
##  6:                                                                         Acute cor pulmonale
##  7:                                                                       Chronic cor pulmonale
##  8:                                                                               Heart failure
##  9:                                                                             Cardiac failure
## 10:                                                                    Congestive heart failure
## 11:                                                                  Congestive cardiac failure
## 12:                                                                   Right ventricular failure
## 13:                                                                       Biventricular failure
## 14:                                                              Acute congestive heart failure
## 15:                                                            Chronic congestive heart failure
## 16:                                                               Decompensated cardiac failure
## 17:                                                                 Compensated cardiac failure
## 18:                                            Congestive heart failure due to valvular disease
## 19:                                                                    Left ventricular failure
## 20:                                                                            Asthma - cardiac
## 21:                                                              Acute left ventricular failure
## 22:                                                                         Acute heart failure
## 23:                                                 Heart failure with normal ejection fraction
## 24:                                         HFNEF - heart failure with normal ejection fraction
## 25:                                              Heart failure with preserved ejection fraction
## 26:                                                                   Right ventricular failure
## 27:                                                                           Heart failure NOS
## 28:                                                                                  Weak heart
## 29:                                                                         Cardiac failure NOS
## 30:                                                Cardiac failure following abortive pregnancy
## 31:                                                                  Congenital cardiac failure
## 32:                                                                    Neonatal cardiac failure
## 33:                                                                [D]Cardiorespiratory failure
## 34:                                                     Heart failure as a complication of care
##                                                                                            term

More information

For more information about SNOMED CT, visit the SNOMED CT international website: https://www.snomed.org/

SNOMED CT (UK edition) can be downloaded from the NHS Digital site: https://isd.digital.nhs.uk/trud/user/guest/group/0/home

The NHS Digital terminology browser can be used to search for terms interactively: https://termbrowser.nhs.uk/