Skip to contents

combine two omop cdm (Common Data Model) instances initially works on lists NOTE these omop_cdm* functions are for omop extracts rather than the concepts and may be best moved to another package TODO could be modified relatively easily to work on >2 extracts up to 9 :-) TODO get it to work on folder names by calling omop_cdm_read()

Usage

omop_cdm_combine(
  cdm1,
  cdm2,
  make_care_site_id_unique = TRUE,
  make_ids_unique = TRUE,
  add_care_site_name_to_person_id_tables = TRUE
)

Arguments

cdm1

list containing cdm tables

cdm2

list containing cdm tables

make_care_site_id_unique

whether to set care_site_id to 1 & 2 for each instance, default TRUE

make_ids_unique

whether to uniqueify all other IDs (multiply by 10 & add extractnum), default TRUE

add_care_site_name_to_person_id_tables

whether to add column to all tables with person_id

Value

a list containing merged omop tables

Examples

#test creation of new ids when overlap
pids1 <- 1:3
pids2 <- 1:2
cdm1 <- list(person=data.frame(person_id=pids1,age=21:23,care_site_id=1L),
             measurement=data.frame(person_id=pids1,meas=5:7),
             care_site=data.frame(care_site_id=1L, care_site_name="hospital1"))
cdm2 <- list(person=data.frame(person_id=pids2,age=91:92,care_site_id=2L),
            measurement=data.frame(person_id=pids2,meas=15:16),
            care_site=data.frame(care_site_id=1L, care_site_name="hospital2"),
            death=data.frame(person_id=pids2,d=c(0,1)))
cdm3 <- omop_cdm_combine(cdm1, cdm2)
#> uniquefied columns :  person$person_id measurement$person_id
#> uniquefied columns :  person$person_id measurement$person_id death$person_id
#an example testing coping with different column classes
#it shouldn't really happen due to omop spec
#but does sometimes e.g. when csvs have been read in wrong
cdmint <- list(measurement=data.frame(person_id=pids1,meas=5:7))
cdmtime <- list(measurement=data.frame(person_id=pids1,meas=strptime("12:30:00", "%H:%M:%S")))
cdmna <- list(measurement=data.frame(person_id=pids1,meas=NA))
cdmchar <- list(measurement=data.frame(person_id=pids1,meas="A"))
#TODO this causes an error because I couldn't work an easy way to fix
#cd3 <- omop_cdm_combine(cdmtime,cdmchar)