Skip to contents

This function simulates condition occurrences for individuals within a specified cohort. It helps create a realistic dataset by generating condition records for each person, based on the number of records specified per person.The generated data are aligned with the existing observation periods to ensure that all conditions are recorded within valid observation windows.

Usage

mockProcedureOccurrence(cdm, recordPerson = 1, seed = NULL)

Arguments

cdm

A `cdm_reference` object that should already include 'person', 'observation_period', and 'concept' tables.This object is the base CDM structure where the procedure occurrence data will be added. It is essential that these tables are not empty as they provide the necessary context for generating condition data.

recordPerson

An integer specifying the expected number of condition records to generate per person.This parameter allows the simulation of varying frequencies of condition occurrences among individuals in the cohort, reflecting the variability seen in real-world medical data.

seed

An optional integer used to set the seed for random number generation, ensuring reproducibility of the generated data.If provided, it allows the function to produce the same results each time it is run with the same inputs.If 'NULL', the seed is not set, resulting in different outputs on each run.

Value

Returns the modified `cdm` object with the new 'condition_occurrence' table added. This table includes the simulated condition data for each person, ensuring that each record is within the valid observation periods and linked to the correct individuals in the 'person' table.

Examples

# \donttest{
library(omock)

# Create a mock CDM reference and add condition occurrences
cdm <- mockCdmReference() |>
  mockPerson() |>
  mockObservationPeriod() |>
  mockProcedureOccurrence(recordPerson = 2)

# View the generated condition occurrence data
print(cdm$procedure_occurrence)
#> # A tibble: 20 × 15
#>    procedure_concept_id person_id procedure_date procedure_end_date
#>  *                <int>     <int> <date>         <date>            
#>  1              4012925         7 2015-02-06     2015-11-07        
#>  2              4012925         3 1981-06-06     1981-12-27        
#>  3              4012925         4 2017-11-27     2018-08-11        
#>  4              4012925         2 1970-01-31     1984-08-16        
#>  5              4012925         3 1981-07-16     1982-01-30        
#>  6              4012925         6 2000-01-23     2012-06-23        
#>  7              4012925         2 1975-05-03     1985-07-08        
#>  8              4012925         5 1991-10-14     1997-02-14        
#>  9              4012925         5 1989-06-16     1997-04-08        
#> 10              4012925        10 1973-05-24     1986-10-04        
#> 11              4012925        10 1977-05-17     1979-11-30        
#> 12              4012925         5 1989-08-31     1994-10-13        
#> 13              4012925         1 2003-06-29     2004-03-03        
#> 14              4012925         7 2015-02-01     2016-02-28        
#> 15              4012925         8 1982-09-04     2000-02-22        
#> 16              4012925         9 1992-04-16     2001-05-16        
#> 17              4012925         1 2003-07-27     2004-06-30        
#> 18              4012925         9 1993-11-15     2002-11-11        
#> 19              4012925         8 1987-01-08     2005-05-12        
#> 20              4012925         6 2004-04-19     2011-12-06        
#> # ℹ 11 more variables: procedure_occurrence_id <int>,
#> #   procedure_type_concept_id <int>, procedure_datetime <dttm>,
#> #   modifier_concept_id <int>, quantity <int>, provider_id <int>,
#> #   visit_occurrence_id <int>, visit_detail_id <int>,
#> #   procedure_source_value <chr>, procedure_source_concept_id <int>,
#> #   modifier_source_value <chr>
# }