@@ -12,6 +12,42 @@ class LimitedExposurePeriodAdderSuite extends SharedContext {
1212 // instance created from a mock DataFrame, to allow testing the InnerImplicits implicit class
1313 private val mockInstance = new LimitedExposurePeriodAdder (mock(classOf [DataFrame ]))
1414
15+
16+ " delayStart" should " delay the start of events by the given period" in {
17+ val sqlCtx = sqlContext
18+ import sqlCtx .implicits ._
19+
20+ // Given
21+ val input = Seq (
22+ (" A" , " P" , makeTS(2008 , 1 , 1 ), 1.0 ),
23+ (" A" , " P" , makeTS(2008 , 2 , 1 ), 1.0 ),
24+ (" A" , " P" , makeTS(2008 , 5 , 1 ), 1.0 ),
25+ (" A" , " P" , makeTS(2008 , 6 , 1 ), 1.0 ),
26+ (" A" , " P" , makeTS(2008 , 7 , 1 ), 1.0 ),
27+ (" A" , " P" , makeTS(2009 , 1 , 1 ), 1.0 ),
28+ (" A" , " P" , makeTS(2009 , 7 , 1 ), 1.0 ),
29+ (" A" , " P" , makeTS(2009 , 8 , 1 ), 1.0 ),
30+ (" A" , " S" , makeTS(2008 , 2 , 1 ), 1.0 )
31+ ).toDF(PatientID , Value , Start , Weight )
32+
33+
34+ val expected = Seq (
35+ (" A" , " P" , makeTS(2008 , 1 , 11 ), 1.0 ),
36+ (" A" , " P" , makeTS(2008 , 2 , 11 ), 1.0 ),
37+ (" A" , " P" , makeTS(2008 , 5 , 11 ), 1.0 ),
38+ (" A" , " P" , makeTS(2008 , 6 , 11 ), 1.0 ),
39+ (" A" , " P" , makeTS(2008 , 7 , 11 ), 1.0 ),
40+ (" A" , " P" , makeTS(2009 , 1 , 11 ), 1.0 ),
41+ (" A" , " P" , makeTS(2009 , 7 , 11 ), 1.0 ),
42+ (" A" , " P" , makeTS(2009 , 8 , 11 ), 1.0 ),
43+ (" A" , " S" , makeTS(2008 , 2 , 11 ), 1.0 )
44+ ).toDF(PatientID , Value , Start , Weight ).select(PatientID , Value , Weight , Start )
45+
46+ val result = mockInstance.delayStart(input, 10 .days)
47+
48+ assertDFs(expected, result)
49+ }
50+
1551 " getFirstAndLastPurchase" should " return the first and the last purchase of each potential exposure" in {
1652
1753 val sqlCtx = sqlContext
@@ -93,15 +129,15 @@ class LimitedExposurePeriodAdderSuite extends SharedContext {
93129 ).toDF(PatientID , Value , Start , Weight )
94130
95131 val expected = Seq (
96- (" A" , " P" , makeTS(2008 , 1 , 1 ), 1.0 , makeTS(2008 , 1 , 1 ), makeTS(2008 , 3 , 11 )),
97- (" A" , " P" , makeTS(2008 , 5 , 1 ), 1.0 , makeTS(2008 , 5 , 1 ), makeTS(2008 , 8 , 11 )),
98- (" A" , " P" , makeTS(2009 , 1 , 1 ), 1.0 , makeTS(2009 , 1 , 1 ), makeTS(2009 , 2 , 11 )),
99- (" A" , " P" , makeTS(2009 , 7 , 1 ), 1.0 , makeTS(2009 , 7 , 1 ), makeTS(2009 , 9 , 11 )),
100- (" A" , " S" , makeTS(2008 , 2 , 1 ), 1.0 , makeTS(2008 , 2 , 1 ), makeTS(2008 , 3 , 11 ))
132+ (" A" , " P" , makeTS(2008 , 1 , 6 ), 1.0 , makeTS(2008 , 1 , 6 ), makeTS(2008 , 3 , 16 )),
133+ (" A" , " P" , makeTS(2008 , 5 , 6 ), 1.0 , makeTS(2008 , 5 , 6 ), makeTS(2008 , 8 , 16 )),
134+ (" A" , " P" , makeTS(2009 , 1 , 6 ), 1.0 , makeTS(2009 , 1 , 6 ), makeTS(2009 , 2 , 16 )),
135+ (" A" , " P" , makeTS(2009 , 7 , 6 ), 1.0 , makeTS(2009 , 7 , 6 ), makeTS(2009 , 9 , 16 )),
136+ (" A" , " S" , makeTS(2008 , 2 , 6 ), 1.0 , makeTS(2008 , 2 , 6 ), makeTS(2008 , 3 , 16 ))
101137 ).toDF(PatientID , Value , Start , Weight , ExposureStart , ExposureEnd )
102138
103139 val result = new LimitedExposurePeriodAdder (input)
104- .withStartEnd(0 , 0 .months , 0 .months, Some (1 .months), Some (3 .months), Some (10 .days))
140+ .withStartEnd(0 , 5 .days , 0 .months, Some (1 .months), Some (3 .months), Some (10 .days))
105141
106142 assertDFs(expected, result)
107143 }
0 commit comments