ConceptSetManifest R6 Class
ConceptSetManifest R6 Class
Details
An R6 class that manages a collection of ConceptSetDef objects and maintains metadata in a SQLite database.
The ConceptSetManifest class manages multiple concept set definitions and stores their metadata in a SQLite database located at inputs/conceptSets/conceptSetManifest.sqlite. Each ConceptSetDef is assigned a sequential ID based on its position in the manifest.
Vocabulary Suggestion by Domain: The function automatically suggests appropriate vocabularies based on concept set domains:
condition_occurrence: ICD10CM, ICD9CMprocedure: HCPCS, CPT4measurement: LOINCdrug_exposure: NDCobservation: All vocabularies (ICD9CM, ICD10CM, HCPCS, CPT4, LOINC, NDC)device_exposure: NDCvisit_occurrence: ICD10CM, ICD9CM, HCPCS, CPT4
Note: These suggestions are based on OMOP CDM conventions. You can override with any valid vocabulary combination.
Processing Workflow:
Verifies ExecutionSettings is configured with database connection
Detects domains of all concept sets in the manifest
Displays suggested vocabularies based on detected domains
Prompts user to accept or override suggested vocabularies
Creates a new xlsx workbook
For each concept set in the manifest:
Reads the CIRCE JSON definition
Builds a concept query selecting standard concepts (using CirceR)
Performs SQL join: concepts -> concept_relationship (Maps to) -> source concepts
Finds matching source codes in the specified vocabularies
Adds results as a new sheet in the xlsx workbook with formatted header
Provides status messages for each concept set
Exports combined results to
{outputFolder}/SourceCodeWorkbook.xlsxEach sheet contains columns: vocabulary_id, concept_code, concept_name
Sheet headers are styled with blue background and white bold text
Column widths are auto-fitted for readability
SQL Query Pattern: For each concept set, the following logic is executed:
CTE selects all standard concepts in the concept set
Joins to concept_relationship table with relationship_id = 'Maps to'
Maps relationship finds what source codes map TO standard concepts
Filters to valid, non-invalid source codes in specified vocabularies
Results ordered by vocabulary_id and concept_code
Requirements:
ExecutionSettings must be initialized with a valid database connection
Vocabulary schema must be accessible from ExecutionSettings
openxlsx2 package must be installed
User must have READ permissions on vocabulary tables
Error Handling:
Displays warnings if any concept set processing fails but continues with others
Provides clear error messages if database connection is unavailable
Validates source vocabularies against known vocabulary IDs
This function identifies which standard concepts are included in each concept set by finding the reverse mapping relationship. For each concept set:
Reads the CIRCE JSON definition
Builds a concept query using CirceR
Joins with concept_relationship via reverse "Maps to" relationship (finds what maps TO the concept set concepts)
Filters for standard concepts (standard_concept = 'S')
Adds results to a new sheet in the xlsx workbook
Exports all results to
{outputFolder}/IncludedCodes.xlsxEach sheet contains: concept_id, concept_name, vocabulary_id
Requirements:
ExecutionSettings must be initialized with a valid connection
Vocabulary schema must be accessible from ExecutionSettings
openxlsx2 package must be installed
Methods
Method new()
Initialize a new ConceptSetManifest
Usage
ConceptSetManifest$new(
conceptSetEntries,
executionSettings = NULL,
dbPath = "inputs/conceptSets/conceptSetManifest.sqlite"
)Arguments
conceptSetEntriesList. A list of ConceptSetDef objects.
executionSettingsObject. (Optional) Execution settings for accessing the vocabulary database. Can be any object type containing configuration for vocabulary queries. Defaults to NULL. Only required for operations like extractSourceCodes().
dbPathCharacter. Path to the SQLite database. Defaults to "inputs/conceptSets/conceptSetManifest.sqlite" Get the manifest as a data frame
Method getConceptSetsByLabel()
Usage
ConceptSetManifest$getConceptSetsByLabel(
label,
matchType = c("exact", "pattern")
)Method grabConceptSetsByLabel()
Usage
ConceptSetManifest$grabConceptSetsByLabel(
label,
matchType = c("exact", "pattern")
)Method hardRemoveConceptSet()
Hard delete a concept set (removes the record from database, irreversible)
Method cleanupMissing()
Clean up missing concept sets from manifest
Method extractSourceCodes()
Finds source codes from specified vocabularies that map to each concept set's standard concepts. Results are exported to a single xlsx file with one sheet per concept set, saved in the inputs/conceptSets folder. The function provides interactive vocabulary suggestions based on detected concept set domains.
Arguments
sourceVocabsCharacter vector. Source vocabulary IDs to search for. Valid options: "ICD9CM", "ICD10CM", "HCPCS", "CPT4", "LOINC", "NDC". Defaults to c("ICD10CM"). The function will suggest appropriate vocabularies based on the domains of your concept sets and prompt you to use them.
outputFolderCharacter. Path where the xlsx file will be saved. Defaults to "inputs/conceptSets".
Returns
Invisibly returns NULL. Saves xlsx file to outputFolder and prints status messages via cli package. Output file is ready to open in Excel or other spreadsheet software.
Extract Included Standard Concepts for Concept Sets
Finds standard concepts that are included in (map TO) each concept set's included concepts. Results are exported to a single xlsx file with one sheet per concept set, saved in the inputs/conceptSets folder.
Method extractIncludedCodes()
Usage
ConceptSetManifest$extractIncludedCodes(
outputFolder = here::here("inputs/conceptSets")
)