OHDSI / omock

https://ohdsi.github.io/omock/
Apache License 2.0
2 stars 1 forks source link

write test for mockPerson #10

Closed ilovemane closed 6 months ago

nmercadeb commented 6 months ago

at the moment the following code returns the person table specified in the first mockPerson function (n = 1000). @ilovemane @edward-burn @catalamarti is this what you would expect? maybe it could throw a warning ?

cdm <- emptyCdmReference(cdmName = "test") |> mockPerson(nPerson = 1000, birthRange = as.Date(c("1990-01-01", "2000-01-01"))) |> mockPerson(nPerson = 10, birthRange = as.Date(c("1990-01-01", "2000-01-01")))

edward-burn commented 6 months ago

excellent test :) I think the second call should overwrite the first

ilovemane commented 6 months ago

but if we have an observation period table already in the CDM, we overwrite the person table. Then these two tables won't match. How should we handle this? I don't think omopgenerics will stop us from doing this.


> cdm <- omock::emptyCdmReference(cdmName = "mock") |> omock::mockPerson(nPerson = 100) |> omock::mockObservationPeriod()
> cdm <- cdm |> omock::mockPerson(nPerson = 10)
> cdm$person
# A tibble: 10 x 7
   person_id gender_concept_id year_of_birth month_of_birth day_of_birth race_concept_id ethnicity_concept_id
 *     <int>             <dbl> <chr>         <chr>          <chr>        <lgl>           <lgl>               
 1         1              8532 1997          8              22           NA              NA                  
 2         2              8532 1963          1              27           NA              NA                  
 3         3              8532 1986          3              10           NA              NA                  
 4         4              8532 1978          11             8            NA              NA                  
 5         5              8507 1973          3              2            NA              NA                  
 6         6              8507 1961          2              1            NA              NA                  
 7         7              8507 1986          12             16           NA              NA                  
 8         8              8507 1981          9              5            NA              NA                  
 9         9              8507 1983          7              23           NA              NA                  
10        10              8507 1998          6              2            NA              NA                  
> cdm$observation_period
# A tibble: 100 x 5
   observation_period_id person_id observation_period_start_date observation_period_end_date period_type_concept_id
 *                 <int>     <int> <date>                        <date>                      <lgl>                 
 1                     1         1 2001-05-12                    2006-05-07                  NA                    
 2                     2         2 1967-12-21                    1976-07-29                  NA                    
 3                     3         3 2011-01-23                    2012-09-03                  NA                    
 4                     4         4 2006-08-20                    2007-12-06                  NA                    
 5                     5         5 2012-11-15                    2019-11-07                  NA                    
 6                     6         6 1984-08-31                    1998-06-26                  NA                    
 7                     7         7 1988-03-14                    2005-12-29                  NA                    
 8                     8         8 2003-01-05                    2012-01-23                  NA                    
 9                     9         9 2015-09-20                    2018-11-07                  NA                    
10                    10        10 2015-06-09                    2019-09-18                  NA                    
# i 90 more rows
# i Use `print(n = ...)` to see more rows
``
edward-burn commented 6 months ago

Oh very true, maybe better to throw an error if the cdm contains a person table with records.