---
title: "**OMOP CDM v5.4**"
output:
  html_document:
    toc: yes
    toc_depth: 5
    toc_float: yes
---

```{r setup, include=FALSE, eval=TRUE}

#todo figure out how to get the document dynamically without specifying the name
library(rmarkdown)
library(knitr)
library(kableExtra)
library(magrittr)
library(dplyr)
library(stringr)

```

This is the specification document for the OMOP Common Data Model, v5.4. **This is the latest version of the OMOP CDM.**  Each table is represented with a high-level description and ETL conventions that should be followed. This is continued with a discussion of each field in each table, any conventions related to the field, and constraints that should be followed (like primary key, foreign key, etc). Fields that are not required should exist in the CDM table but do not need to be populated. Should you have questions please feel free to visit the [forums](https://forums.ohdsi.org/) or the [github issue](https://github.com/ohdsi/CommonDataModel/issues) page.

### Current Support for CDM v5.4

The table below details which OHDSI tools support CDM v5.4. There are two levels of support: legacy support means that the tool supports all tables and fields that were present in CDM v5.3 and feature support indicates that the tool supports any new tables and fields in CDM v5.4 that were not present in CDM v5.3. A green check `r emo::ji("white heavy check mark")` indicates that the support level for the listed tool is in place, has been tested, and released. A warning sign `r emo::ji("warning")` indicates that the support level for the listed tool has been initiated but has not yet been tested and released. 
<br>


|**Tool**|**Description**|**Legacy Support**|**Feature Support**|
|--|--|--|--|
|**CDM R package**|This package can be downloaded from [https://github.com/OHDSI/CommonDataModel/](https://github.com/OHDSI/CommonDataModel/). It functions to dynamically create the OMOP CDM documentation and DDL scripts to instantiate the CDM tables. |`r emo::ji("white heavy check mark")`|`r emo::ji("white heavy check mark")`
|**Data Quality Dashboard**|This package can be downloaded from [https://github.com/OHDSI/DataQualityDashboard](https://github.com/OHDSI/DataQualityDashboard). It runs a set of > 3500 data quality checks against an OMOP CDM instance and is required to be run on all databases prior to participating in an OHDSI network research study.|`r emo::ji("white heavy check mark")`| `r emo::ji("warning")`
|**Achilles**|This package can be downloaded from [https://github.com/OHDSI/Achilles](https://github.com/OHDSI/Achilles), performing a set of broad database characterizations agains an OMOP CDM instance. |`r emo::ji("white heavy check mark")`|`r emo::ji("warning")`
|**ARES**|This package can be downloaded from [https://github.com/OHDSI/Ares](https://github.com/OHDSI/Ares) and is designed to display the results from both the ACHILLES and DataQualityDashboard packages to support data quality and characterization research.|`r emo::ji("white heavy check mark")`|`r emo::ji("warning")`
|**ATLAS**|ATLAS is an open source software tool for researchers to conduct scientific analyses on standardized observational data. [Demo](http://atlas-demo.ohdsi.org/) |`r emo::ji("white heavy check mark")`|`r emo::ji("warning")`
|**Rabbit-In-A-Hat**|This package can be downloaded from [https://github.com/OHDSI/WhiteRabbit](https://github.com/OHDSI/WhiteRabbit) and is an application for interactive design of an ETL to the OMOP Common Data Model with the help of the the scan report generated by White Rabbit.|`r emo::ji("white heavy check mark")`|`r emo::ji("white heavy check mark")`
|**Feature Extraction**|This package can be downloaded from [https://github.com/OHDSI/FeatureExtraction](https://github.com/OHDSI/FeatureExtraction). It is designed to generate features (covariates) for a cohort generated using the OMOP CDM. |`r emo::ji("white heavy check mark")`|`r emo::ji("white heavy check mark")`*
|**Cohort Diagnostics**|This package can be downloaded from [https://github.com/OHDSI/CohortDiagnostics](https://github.com/OHDSI/CohortDiagnostics) and is used to critically evaluate cohort phenotypes. |`r emo::ji("white heavy check mark")`|`r emo::ji("warning")`
<br>
\* The **Feature Extraction** package supports all relevant new features in CDM v5.4. For example, it was decided that, from a methodological perspective, the EPISODE and EPISODE_EVENT tables should not be included to define cohort covariates because the events that make up episodes are already pulled in as potential covariates.

<br>

Looking to send us a pull request for a bug fix? Please see the [readme](https://github.com/OHDSI/CommonDataModel#readme) on the main github page.

```{r docLoop54, echo=FALSE, results='asis'}
tableSpecs <- read.csv("../inst/csv/OMOP_CDMv5.4_Table_Level.csv", stringsAsFactors = FALSE)
cdmSpecs <- read.csv("../inst/csv/OMOP_CDMv5.4_Field_Level.csv", stringsAsFactors = FALSE)

tables <- tableSpecs$cdmTableName

cdmSpecsClean <- cdmSpecs %>%
  dplyr::select(`CDM Table` = cdmTableName,
                `CDM Field` = cdmFieldName,
                `User Guide` = userGuidance,
                `ETL Conventions` = etlConventions,
                `Datatype` = cdmDatatype,
                `Required` = isRequired,
                `Primary Key` = isPrimaryKey,
                `Foreign Key` = isForeignKey,
                `FK Table` = fkTableName,
                `FK Domain` = fkDomain
                )

cdmSpecsClean[is.na(cdmSpecsClean)] <- ""

for(tb in tables) {
  
  if(tb == 'PERSON'){
    cat("## **Clinical Data Tables**\n\n")
  }
  
  if(tb == 'LOCATION'){
    cat("## **Health System Data Tables**\n\n")
  }
  
  if(tb == 'PAYER_PLAN_PERIOD'){
    cat("## **Health Economics Data Tables**\n\n")
  }
  
  if(tb == 'DRUG_ERA'){
    cat("## **Standardized Derived Elements**\n\n")
  }
  
  if(tb == 'METADATA'){
    cat("## **Metadata Tables**\n\n")
  }
  if(tb == 'CONCEPT'){
    cat("## **Vocabulary Tables**\n\n")
  }
  
  cat("###", tb, "{.tabset .tabset-pills} \n\n")
  
  tableInfo <- subset(tableSpecs, cdmTableName == tb)
  cat("**Table Description**\n\n",tableInfo[,"tableDescription"], "\n\n")
  
  if(!isTRUE(tableInfo[,"userGuidance"]=="")){
    cat("**User Guide**\n\n",tableInfo[,"userGuidance"],"\n\n")
  }
  
  if(!isTRUE(tableInfo[,"etlConventions"]=="")){
    cat("**ETL Conventions**\n\n",tableInfo[,"etlConventions"],"\n\n")
  }
  
  loopTable <- subset(cdmSpecsClean, `CDM Table` == tb)
  loopTable <- subset(loopTable, select = -c(1))
 
  print(knitr::kable(x = loopTable, align = "l", row.names = FALSE, format = "html", escape = FALSE) %>%
           column_spec(1, bold = T) %>%
           # column_spec(2, width = "3in", include_thead = T) %>%
           # column_spec(3, width = "4in", include_thead = T) %>%
           # column_spec(4:9, width = "1in", include_thead = T) %>%
           kable_styling(c("condensed","hover"), position = "center", full_width = T, font_size = 13))
         
  
  }



```
