Constructs eras (continuous periods of exposure or disease).

constructEras(
connectionDetails,
sourceDatabaseSchema,
sourceTable = "drug_exposure",
targetDatabaseSchema = sourceDatabaseSchema,
targetTable = "drug_era",
createTargetTable = FALSE,
cdmDatabaseSchema = sourceDatabaseSchema,
gracePeriod = 30,
rollUp = TRUE,
rollUpConceptClassId = "Ingredient",
rollUpVocabularyId = "RxNorm",
cdmVersion = "5"
)

## Arguments

connectionDetails An R object of type connectionDetails created using the function createConnectionDetails in the DatabaseConnector package. The name of the database schema that contains the source table. Requires read permissions to this database. On SQL Server, this should specifiy both the database and the schema, so for example 'cdm_instance.dbo'. The name of the source table. The name of the database schema that contains the target table. Requires write permissions to this database. On SQL Server, this should specifiy both the database and the schema, so for example 'cdm_instance.dbo'. The name of the target table. Should the target table be created? If not, the data is inserted in an existing table. Only needed when rolling up concepts to ancestors: The name of the database schema that contains the vocabulary files. Requires read permissions to this database. On SQL Server, this should specifiy both the database and the schema, so for example 'cdm_instance.dbo'. The number of days allowed between periods for them to still be considered part of the same era. Should concepts be rolled up to their ancestors? The identifier of the concept class to which concepts should be rolled up. The identifier of the vocabulary to which concepts should be rolled up. The verion of the CDM that is being used.

## Details

This function creates eras from source data. For example, one could use this function to create drug eras based on drug exposures. The function allows drugs to be rolled up to ingredients, and prescriptions to the same ingredient that overlap in time are merged into a single ingredient. Note that stockpiling is not assumed to take place (ie. overlap is discarded), but a grace period can be specified allowing for a small gap between prescriptions when merging. The user can specify the source and target table. These tables are assumed to have the same structure as the cohort table in the Common Data Model (CDM), except when the table names are 'drug_exposure' or 'condition_occurrence' for the source table, or 'drug_era' or 'condition_era' for the target table, in which case the tables are assumed to have the structure defined for those tables in the CDM. If both the source and target table specify a field for type_concept_id, the era construction will partition by the type_concept_id, in other words periods with different type_concept_ids will be treated independently.

## Examples

if (FALSE) {
# Constructing drug eras in CDM v4:
constructEras(connectionDetails,
sourceDatabaseSchema = cdmDatabaseSchema,
sourceTable = "drug_exposure",
targetTable = "drug_era",
createTargetTable = FALSE,
gracePeriod = 30,
rollUpVocabularyId = 8,
rollUpConceptClassId = "Ingredient",
cdmVersion = "4")

# Constructing drug eras in CDM v5:
constructEras(connectionDetails,
sourceDatabaseSchema = cdmDatabaseSchema,
sourceTable = "drug_exposure",
targetTable = "drug_era",
createTargetTable = FALSE,
gracePeriod = 30,
rollUpVocabularyId = "RxNorm",
rollUpConceptClassId = "Ingredient",
cdmVersion = "5")

}