Allows users to identify relevant clinical codes and automate the construction of clinical code lists for primary care database studies. This package is analogous to the Stata command pcdsearch.
Identifies relevant clinical codes and automates the construction of clinical code lists
David A. Springate, Evangelos Kontopantelis, Ivan Olier.
Development of this package has been frozen. This package has been merged with the rEHR package. See the rEHR codelists vignette for details and see the Introduction to rEHR vignette for more details on this package. Further updates will be made there.
Clinical code search and build methodology will be published in a forthcoming paper.
rpcdsearch is not on CRAN but you can install from github using devtools:
Definition lists can be defined for:
Building definition lists is a two stage process:
MedicalDefinition, containing the terms to be searched for in the lookup tables
definition_searchis performed on the
MedicalDefinitionobject and the relevant lookup tables to return a list of matching dataframes
MedicalDefinition object can be either made using terms defined within
R or with terms imported from an external csv file
MedicalDefinition constructor function to generate search definitions. This takes the following arguments:
termsa list of character vectors representing clinical search terms or NULL
codeslist of character vectors representing clinical code terms or NULL
testslist of character vectors representing test search terms or NULL
drugslist of character vectors representing drug search terms or NULL
drugcodeslist of character vectors representing drug product code terms or NULL
vectors of length > 1 are searched for together (AND), in any order. Different vectors in the same list are searched for seperately (OR). Placing a "-" character at the start of a character vector element excludes that terms from the search.
# vectors of length > 1 are combined as a single AND expression# "-" excludes that term from the searchdef <- MedicalDefinition(terms = list("peripheral vascular disease", "peripheral gangrene", "-wrong answer","intermittent claudication", "thromboangiitis obliterans","thromboangiitis obliterans", "diabetic peripheral angiopathy",c("diabetes", "peripheral angiopathy"), # combined as a single AND expressionc("diabetes", "peripheral angiopathy"),c("buerger", "disease presenile_gangrene"),"thromboangiitis obliterans","-rubbish", # exclusionc("percutaneous_transluminal_angioplasty", "artery"),c("bypass", "iliac_artery"),c("bypass", "femoral_artery"),c("femoral_artery" , "occlusion"),c("popliteal_artery", "occlusion"),"dissecting_aortic_aneurysm", "peripheral_angiopathic_disease","acrocyanosis", "acroparaesthesia", "erythrocyanosis","erythromelalgia", "ABPI",c("ankle", "brachial"),c("ankle", "pressure"),c("left", "brachial"),c("left", "pressure"),c("right", "brachial"),c("right", "pressure")),codes = list("G73"),tests = NULL,drugs = list("insulin", "diabet", "aspirin"))
When searching for codes, a range of clinical codes can be searched for by providing two codes seperated by a hyphen. e.g.
Searches can be imported from a csv file in this format
The first column in every row determines the list that the term applies to and the second column determines whether the term should be included or excluded. Note that the csv does not have to be a valid format for conversion to a dataframe. Extra columns can be used to include terms to be combined as an AND expression with the other terms on that row. The title row can also be ommitted. You can use standard regex escape patterns in the term definitions.
The data is called into
R in the following way:
## Using the example search definition provided with the packagedef2 <- import_definitions(system.file("extdata", "example_search.csv", package = "rpcdsearch"))
Once a search has been defined, the relevant lookup tables should be called in. Note that these lookup tables are not provided with the package and will be specific to the users EHR database. These examples are using CPRD lookups and EHR definitions (See the ehr_system code for details of how the interface with CPRD is implemented).
## Use fileEncoding="latin1" to avoid any issues with non-ascii charactersmedical_table <- read.delim("Lookups//medical.txt", fileEncoding="latin1", stringsAsFactors = FALSE)drug_table <- read.delim("Lookups/product.txt", fileEncoding="latin1", stringsAsFactors = FALSE)
And the search can be run:
draft_lists <- build_definition_lists(def, medical_table = medical_table,drug_table = drug_table)
This returns a list of dataframes for each of the provided search lists. If
codes are provided in the definition, it also contains a
combined_terms_codes data frame which is a combination of
codes with duplicate rows removed.
The code lists produced by
build_definition_lists will often want to be reviewed by clinicians or non-technical researchers. To facilitate this, there is an
export_definition_search function to export the code lists as an Excel file, with each list occupying a tab in the file. To export a code list:
out_file <- "def_searches.xlsx"export_definition_search(draft_lists, out_file)