@@ -92,36 +92,19 @@ test_that("CHADS2-VASc quartiles are calculated within each cohort", {
9292test_that(" Charlson applies hierarchy and includes zero-score people in standard deviation" , {
9393 skip_if_not(dbms == " sqlite" && exists(" eunomiaConnection" ))
9494
95- anyMalignancyConcept <- DatabaseConnector :: querySql(
96- connection = eunomiaConnection ,
97- sql = "
98- SELECT descendant_concept_id
99- FROM main.concept_ancestor
100- WHERE ancestor_concept_id = 443392
101- LIMIT 1" ,
102- snakeCaseToCamelCase = TRUE
103- )
104- metastaticTumorConcept <- DatabaseConnector :: querySql(
105- connection = eunomiaConnection ,
106- sql = "
107- SELECT descendant_concept_id
108- FROM main.concept_ancestor
109- WHERE ancestor_concept_id = 432851
110- LIMIT 1" ,
111- snakeCaseToCamelCase = TRUE
112- )
113- skip_if(nrow(anyMalignancyConcept ) == 0 || nrow(metastaticTumorConcept ) == 0 ,
114- " Eunomia does not contain the required Charlson concepts"
115- )
116-
11795 syntheticPersonIds <- c(- 334003L , - 334004L )
11896 syntheticConditionEraIds <- c(- 334003L , - 334004L )
97+ syntheticConditionConceptIds <- c(- 334003L , - 334004L )
11998 DatabaseConnector :: executeSql(
12099 connection = eunomiaConnection ,
121100 sql = paste0(
122101 " DELETE FROM " , eunomiaCdmDatabaseSchema ,
123102 " .condition_era WHERE person_id IN (" , paste(syntheticPersonIds , collapse = " , " ), " ); " ,
124103 " DELETE FROM " , eunomiaCdmDatabaseSchema ,
104+ " .concept_ancestor WHERE descendant_concept_id IN (" , paste(syntheticConditionConceptIds , collapse = " , " ), " ); " ,
105+ " DELETE FROM " , eunomiaCdmDatabaseSchema ,
106+ " .concept WHERE concept_id IN (" , paste(syntheticConditionConceptIds , collapse = " , " ), " ); " ,
107+ " DELETE FROM " , eunomiaCdmDatabaseSchema ,
125108 " .person WHERE person_id IN (" , paste(syntheticPersonIds , collapse = " , " ), " )"
126109 )
127110 )
@@ -132,6 +115,10 @@ test_that("Charlson applies hierarchy and includes zero-score people in standard
132115 " DELETE FROM " , eunomiaCdmDatabaseSchema ,
133116 " .condition_era WHERE person_id IN (" , paste(syntheticPersonIds , collapse = " , " ), " ); " ,
134117 " DELETE FROM " , eunomiaCdmDatabaseSchema ,
118+ " .concept_ancestor WHERE descendant_concept_id IN (" , paste(syntheticConditionConceptIds , collapse = " , " ), " ); " ,
119+ " DELETE FROM " , eunomiaCdmDatabaseSchema ,
120+ " .concept WHERE concept_id IN (" , paste(syntheticConditionConceptIds , collapse = " , " ), " ); " ,
121+ " DELETE FROM " , eunomiaCdmDatabaseSchema ,
135122 " .person WHERE person_id IN (" , paste(syntheticPersonIds , collapse = " , " ), " )"
136123 )
137124 )
@@ -153,17 +140,52 @@ test_that("Charlson applies hierarchy and includes zero-score people in standard
153140 progressBar = FALSE ,
154141 camelCaseToSnakeCase = TRUE
155142 )
143+ DatabaseConnector :: insertTable(
144+ connection = eunomiaConnection ,
145+ tableName = " concept" ,
146+ databaseSchema = eunomiaCdmDatabaseSchema ,
147+ data = data.frame (
148+ conceptId = syntheticConditionConceptIds ,
149+ conceptName = c(" Test any malignancy" , " Test metastatic solid tumor" ),
150+ domainId = c(" Condition" , " Condition" ),
151+ vocabularyId = c(" SNOMED" , " SNOMED" ),
152+ conceptClassId = c(" Clinical Finding" , " Clinical Finding" ),
153+ standardConcept = c(" S" , " S" ),
154+ conceptCode = c(" TEST_ANY_MALIGNANCY" , " TEST_METASTATIC_TUMOR" ),
155+ validStartDate = as.Date(c(" 1970-01-01" , " 1970-01-01" )),
156+ validEndDate = as.Date(c(" 2099-12-31" , " 2099-12-31" )),
157+ invalidReason = c(NA_character_ , NA_character_ )
158+ ),
159+ dropTableIfExists = FALSE ,
160+ tempTable = FALSE ,
161+ createTable = FALSE ,
162+ progressBar = FALSE ,
163+ camelCaseToSnakeCase = TRUE
164+ )
165+ DatabaseConnector :: insertTable(
166+ connection = eunomiaConnection ,
167+ tableName = " concept_ancestor" ,
168+ databaseSchema = eunomiaCdmDatabaseSchema ,
169+ data = data.frame (
170+ ancestorConceptId = c(443392L , 432851L ),
171+ descendantConceptId = syntheticConditionConceptIds ,
172+ minLevelsOfSeparation = c(1L , 1L ),
173+ maxLevelsOfSeparation = c(1L , 1L )
174+ ),
175+ dropTableIfExists = FALSE ,
176+ tempTable = FALSE ,
177+ createTable = FALSE ,
178+ progressBar = FALSE ,
179+ camelCaseToSnakeCase = TRUE
180+ )
156181 DatabaseConnector :: insertTable(
157182 connection = eunomiaConnection ,
158183 tableName = " condition_era" ,
159184 databaseSchema = eunomiaCdmDatabaseSchema ,
160185 data = data.frame (
161186 conditionEraId = syntheticConditionEraIds ,
162187 personId = rep(syntheticPersonIds [1 ], 2 ),
163- conditionConceptId = c(
164- anyMalignancyConcept $ descendantConceptId [1 ],
165- metastaticTumorConcept $ descendantConceptId [1 ]
166- ),
188+ conditionConceptId = syntheticConditionConceptIds ,
167189 conditionEraStartDate = as.Date(c(" 2019-01-01" , " 2019-01-01" )),
168190 conditionEraEndDate = as.Date(c(" 2019-01-01" , " 2019-01-01" )),
169191 conditionOccurrenceCount = c(1L , 1L )
0 commit comments