---
title: "Creating synthetic vocabulary Tables with omock"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{a03_Creating_a_synthetic_vocabulary}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

```{r, include = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
```

The `omock` R package provides functions to build and populate mock or user's bespoke vocabulary tables for their mock cdm.In this vignette, we'll show how to use the `mockVocabularyTables()` function to initialize standard OMOP vocabulary tables within a mock CDM reference.

First, let's load packages required for this vignette.

```{r, message=FALSE, warning=FALSE}
library(omock)
library(dplyr)
```

Then we start off with creating an `cdm` object.

```{r}
cdm <- emptyCdmReference(cdmName = "synthetic cdm") |>
  mockPerson(nPerson = 10, birthRange = as.Date(c("1960-01-01", "1980-12-31"))) |>
  mockObservationPeriod()
```

To populate this cdm object with synthetic vocabulary table, we simply use the `mockVocabularyTables()` function. The `omock` package comes with two set mock vocabulary tables at the moment. "mock" and "Eunomia", the "mock" vocabulary set contain a very small subset of vocabularies from the CPRD database and "Eunomia" is the vocabulary set from the eunomia test database. https://ohdsi.github.io/Eunomia/.
```{r}
cdm <- mockVocabularyTables(cdm, vocabularySet = "mock")
cdm$vocabulary |> print()
```

set vocabularySet to eunomia to create the cdm with eunomia vocabulary table.
```{r}
cdm <- mockVocabularyTables(cdm, vocabularySet = "eunomia")
cdm$vocabulary |> print()
```

You can also edit any vocabulary table with your own bespoke vocabulary, for example if you want to insert your own bespoke concept table. you can do below.
```{r}
myConceptTable <- data.frame(
  concept_id = 1:3,
  concept_name = c("Condition A", "Condition B", "Drug C"),
  domain_id = c("Condition", "Condition", "Drug"),
  vocabulary_id = c("SNOMED", "SNOMED", "RxNorm"),
  concept_class_id = c("Clinical Finding", "Clinical Finding", "Ingredient"),
  standard_concept = c("S", "S", "S"),
  concept_code = c("111", "222", "333"),
  valid_start_date = as.Date("1970-01-01"),
  valid_end_date = as.Date("2099-12-31"),
  invalid_reason = NA
)

cdm <- mockVocabularyTables(cdm, 
                            vocabularySet = "eunomia",
                            concept = myConceptTable) 

cdm$concept |> print()
```

As you can see mockVocabularyTables() allows you to populate a mock CDM with custom vocabulary tables, it provided two different vocabulary set for you to choose from and also give you the flexibility to modify it with your own custom vocabulary tables. 
