Closed meerapatelmd closed 3 years ago
#' @title #' Get OMOP Metadata #' #' @description #' Get metadata for the OMOP CDM Tables, the OMOP Vocabulary Tables, or Both. All functions return built-in values with the exception of \code{\link{get.field_names}}, which returns the field names in real-time. #' #' @name get NULL #' @title #' Get Fields #' #' @importFrom pg13 lsFields #' @export #' @rdname get.field_names #' @family get functions get.field_names <- function(omop_table, omop_schema, verbose = TRUE) { conn <- connectOMOP(verbose = verbose) on.exit(dcOMOP(conn = conn, verbose = verbose)) pg13::lsFields(conn = conn, tableName = omop_table, schema = omop_schema) } #' @title #' Get CDM Tables #' #' @return #' Vector of names of CDM Tables #' #' @export #' @rdname get.cdm_tables #' @family get functions get.cdm_tables <- function() { c('ATTRIBUTE_DEFINITION', 'CARE_SITE', 'CDM_SOURCE', 'COHORT', 'COHORT_ATTRIBUTE', 'COHORT_DEFINITION', 'CONDITION_ERA', 'CONDITION_OCCURRENCE', 'COST', 'DEATH', 'DEVICE_EXPOSURE', 'DOSE_ERA', 'DRUG_ERA', 'DRUG_EXPOSURE', 'EPISODE', 'EPISODE_EVENT', 'FACT_RELATIONSHIP', 'LK_PERSON_KEYS', 'LOCATION', 'MEASUREMENT', 'METADATA', 'NOTE', 'NOTE_NLP', 'OBSERVATION', 'OBSERVATION_PERIOD', 'PAYER_PLAN_PERIOD', 'PERSON', 'PROCEDURE_OCCURRENCE', 'PROVIDER', 'REGIMEN', 'SOURCE_TO_CONCEPT_MAP', 'SPECIMEN', 'VISIT_DETAIL', 'VISIT_OCCURRENCE') } #' @title #' Get OMOP Table Abbreviations #' #' @return #' Named vector of abbreviations for all OMOP Tables generated by \code{\link[base]{abbreviate}}. #' #' @export #' @rdname get.omop_table_abbr #' @family get functions get.omop_table_abbr <- function() { allTables <- c(get.cdm_tables(), get.vocab_tables()) allTableNames <- stringr::str_replace_all( allTables, pattern = "[_]{1}", replacement = " " ) tolower(abbreviate(allTableNames, minlength = 1L)) %>% as.list() %>% purrr::set_names(allTables) } #' @title #' Get Vocabulary Tables #' #' @return #' Vector of names of Vocabulary Tables #' #' @export #' @rdname get.vocab_tables #' @family get functions get.vocab_tables <- function() { c('CONCEPT', 'CONCEPT_ANCESTOR', 'CONCEPT_CLASS', 'CONCEPT_RELATIONSHIP', 'CONCEPT_SYNONYM', 'DOMAIN', 'DRUG_STRENGTH', 'RELATIONSHIP', 'VOCABULARY') } #' @title #' Get CDM Table Concept Id Fields #' #' @return #' Tibble of the concept id fields for each CDM Table #' #' @importFrom tibble tribble #' @export #' @rdname get.concept_id_fields #' @family get functions get.concept_id_fields <- function() { tibble::tribble( ~CDM_TABLE,~CONCEPT_ID_FIELDS, 'ATTRIBUTE_DEFINITION', 'c("attribute_type_concept_id")', 'CARE_SITE', 'c("place_of_service_concept_id")', 'COHORT', 'c("drug_concept_id")', 'COHORT_ATTRIBUTE', 'c("value_as_concept_id")', 'COHORT_DEFINITION', 'c("definition_type_concept_id", "subject_concept_id")', 'CONDITION_ERA', 'c("condition_concept_id")', 'CONDITION_OCCURRENCE', 'c("condition_concept_id", "condition_type_concept_id", "condition_source_concept_id", "condition_status_concept_id")', 'COST', 'c("cost_type_concept_id", "currency_concept_id", "revenue_code_concept_id", "drg_concept_id")', 'DEATH', 'c("death_type_concept_id", "cause_concept_id", "cause_source_concept_id")', 'DEVICE_EXPOSURE', 'c("device_concept_id", "device_type_concept_id", "device_source_concept_id")', 'DOSE_ERA', 'c("drug_concept_id", "unit_concept_id")', 'DRUG_ERA', 'c("drug_concept_id")', 'DRUG_EXPOSURE', 'c("drug_concept_id", "drug_type_concept_id", "route_concept_id", "drug_source_concept_id")', 'EPISODE', 'c("episode_concept_id", "episode_object_concept_id", "episode_type_concept_id", "episode_source_concept_id")', 'EPISODE_EVENT', 'c("episode_event_field_concept_id")', 'FACT_RELATIONSHIP', 'c("domain_concept_id_1", "domain_concept_id_2", "relationship_concept_id")', 'MEASUREMENT', 'c("measurement_concept_id", "measurement_type_concept_id", "operator_concept_id", "value_as_concept_id", "unit_concept_id", "measurement_source_concept_id", "modifier_of_field_concept_id")', 'METADATA', 'c("metadata_concept_id", "metadata_type_concept_id", "value_as_concept_id")', 'NOTE', 'c("note_type_concept_id", "note_class_concept_id", "encoding_concept_id", "language_concept_id")', 'NOTE_NLP', 'c("section_concept_id", "note_nlp_concept_id", "note_nlp_source_concept_id")', 'OBSERVATION', 'c("observation_concept_id", "observation_type_concept_id", "value_as_concept_id", "qualifier_concept_id", "unit_concept_id", "observation_source_concept_id")', 'OBSERVATION_PERIOD', 'c("period_type_concept_id")', 'PAYER_PLAN_PERIOD', 'c("payer_concept_id", "payer_source_concept_id", "plan_concept_id", "plan_source_concept_id", "sponsor_concept_id", "sponsor_source_concept_id", "stop_reason_concept_id", "stop_reason_source_concept_id")', 'PERSON', 'c("gender_concept_id", "race_concept_id", "ethnicity_concept_id", "gender_source_concept_id", "race_source_concept_id", "ethnicity_source_concept_id")', 'PROCEDURE_OCCURRENCE', 'c("procedure_concept_id", "procedure_type_concept_id", "modifier_concept_id", "procedure_source_concept_id")', 'PROVIDER', 'c("specialty_concept_id", "gender_concept_id", "specialty_source_concept_id", "gender_source_concept_id")', 'REGIMEN', 'c("drug_concept_id")', 'SOURCE_TO_CONCEPT_MAP', 'c("source_concept_id", "target_concept_id")', 'SPECIMEN', 'c("specimen_concept_id", "specimen_type_concept_id", "unit_concept_id", "anatomic_site_concept_id", "disease_status_concept_id")', 'VISIT_DETAIL', 'c("visit_detail_concept_id", "visit_detail_type_concept_id", "admitting_source_concept_id", "discharge_to_concept_id", "visit_detail_source_concept_id")', 'VISIT_OCCURRENCE', 'c("visit_concept_id", "visit_type_concept_id", "visit_source_concept_id", "admitting_source_concept_id", "discharge_to_concept_id")' ) }