@@ -300,6 +300,91 @@ test_that("combine_supp() does not create an IDVARVAL column (#78)", {
300300 expect_false(" IDVARVAL" %in% names(noidvarval ))
301301})
302302
303+ test_that(" make_supp_qual handles deprecated dataset_name parameter" , {
304+ load(metacore :: metacore_example(" pilot_SDTM.rda" ))
305+ ae <- combine_supp(safetyData :: sdtm_ae , safetyData :: sdtm_suppae )
306+
307+ # Test that dataset_name is deprecated and shows guidance
308+ suppressWarnings({
309+ result <- make_supp_qual(ae , metacore , dataset_name = " AE" )
310+ })
311+
312+ expect_s3_class(result , " data.frame" )
313+ })
314+
315+ test_that(" combine_supp handles QNAM not in dataset columns" , {
316+ simple_ae <- safetyData :: sdtm_ae [1 : 5 , ]
317+ simple_suppae <- safetyData :: sdtm_suppae [1 , ]
318+ simple_suppae $ QNAM <- " NEWCOL" # A new column to add
319+
320+ # Should successfully add the new column
321+ result <- combine_supp(simple_ae , simple_suppae )
322+ expect_true(" NEWCOL" %in% names(result ))
323+ })
324+
325+ test_that(" combine_supp errors when QNAM already exists in dataset" , {
326+ simple_ae <- safetyData :: sdtm_ae [1 : 5 , ]
327+ simple_ae $ AETRTEM <- " existing" # Add column that matches QNAM
328+ simple_suppae <- safetyData :: sdtm_suppae [1 , ]
329+
330+ expect_error(
331+ combine_supp(simple_ae , simple_suppae ),
332+ " already in the original dataset"
333+ )
334+ })
335+
336+ test_that(" combine_supp handles IDVAR not in dataset" , {
337+ simple_ae <- safetyData :: sdtm_ae [1 : 5 , ]
338+ simple_suppae <- safetyData :: sdtm_suppae [1 , ]
339+ simple_suppae $ IDVAR <- " FAKEIDVAR" # IDVAR that doesn't exist
340+
341+ expect_error(
342+ combine_supp(simple_ae , simple_suppae ),
343+ " replacement has 0 rows"
344+ )
345+ })
346+
347+ test_that(" combine_supp_by_idvar detects conflicting replacements across IDVARs" , {
348+ simple_ae <- safetyData :: sdtm_ae %> %
349+ filter(USUBJID %in% c(" 01-701-1015" , " 01-701-1023" )) %> %
350+ mutate(NEWID = dplyr :: row_number())
351+
352+ # Create supp with same QNAM but different IDVARs that would cause conflicts
353+ suppae_conflict <- bind_rows(
354+ data.frame (
355+ STUDYID = " CDISCPILOT01" ,
356+ RDOMAIN = " AE" ,
357+ USUBJID = " 01-701-1015" ,
358+ IDVAR = " AESEQ" ,
359+ IDVARVAL = " 1" ,
360+ QNAM = " TESTVAR" ,
361+ QLABEL = " Test Variable" ,
362+ QVAL = " ValueA" ,
363+ QORIG = " CRF" ,
364+ QEVAL = " " ,
365+ stringsAsFactors = FALSE
366+ ),
367+ data.frame (
368+ STUDYID = " CDISCPILOT01" ,
369+ RDOMAIN = " AE" ,
370+ USUBJID = " 01-701-1015" ,
371+ IDVAR = " NEWID" ,
372+ IDVARVAL = " 1" ,
373+ QNAM = " TESTVAR" ,
374+ QLABEL = " Test Variable" ,
375+ QVAL = " ValueB" , # Different value for same subject/QNAM
376+ QORIG = " CRF" ,
377+ QEVAL = " " ,
378+ stringsAsFactors = FALSE
379+ )
380+ )
381+
382+ expect_error(
383+ combine_supp(simple_ae , suppae_conflict ),
384+ " unexpected number of rows"
385+ )
386+ })
387+
303388test_that(" combine_supp: all SUPP rows merge cleanly (#98)" , {
304389 pc <- tibble :: tibble(
305390 STUDYID = " STUDY123" ,
0 commit comments