@@ -12,8 +12,8 @@ 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- " getFirstAndLastPurchase" should " return the first and the last purchase of each potential exposure" in {
1615
16+ " delayStart" should " delay the start of events by the given period" in {
1717 val sqlCtx = sqlContext
1818 import sqlCtx .implicits ._
1919
@@ -30,15 +30,51 @@ class LimitedExposurePeriodAdderSuite extends SharedContext {
3030 (" A" , " S" , makeTS(2008 , 2 , 1 ), 1.0 )
3131 ).toDF(PatientID , Value , Start , Weight )
3232
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+
51+ " getFirstAndLastPurchase" should " return the first and the last purchase of each potential exposure" in {
52+
53+ val sqlCtx = sqlContext
54+ import sqlCtx .implicits ._
55+
56+ // Given
57+ val input = Seq (
58+ (" A" , " P" , makeTS(2008 , 1 , 1 ), 2.0 ),
59+ (" A" , " P" , makeTS(2008 , 2 , 1 ), 1.0 ),
60+ (" A" , " P" , makeTS(2008 , 5 , 1 ), 1.0 ),
61+ (" A" , " P" , makeTS(2008 , 6 , 1 ), 1.0 ),
62+ (" A" , " P" , makeTS(2008 , 7 , 1 ), 1.0 ),
63+ (" A" , " P" , makeTS(2009 , 1 , 1 ), 1.0 ),
64+ (" A" , " P" , makeTS(2009 , 7 , 1 ), 1.0 ),
65+ (" A" , " P" , makeTS(2009 , 8 , 1 ), 1.0 ),
66+ (" A" , " S" , makeTS(2008 , 2 , 1 ), 2.0 )
67+ ).toDF(PatientID , Value , Start , Weight )
68+
3369 val expected = Seq (
34- (" A" , " P" , makeTS(2008 , 1 , 1 ), 1 .0 , " first" , makeTS(2008 , 2 , 11 )),
70+ (" A" , " P" , makeTS(2008 , 1 , 1 ), 2 .0 , " first" , makeTS(2008 , 4 , 11 )),
3571 (" A" , " P" , makeTS(2008 , 2 , 1 ), 1.0 , " last" , makeTS(2008 , 3 , 11 )),
3672 (" A" , " P" , makeTS(2008 , 5 , 1 ), 1.0 , " first" , makeTS(2008 , 6 , 11 )),
3773 (" A" , " P" , makeTS(2008 , 7 , 1 ), 1.0 , " last" , makeTS(2008 , 8 , 11 )),
3874 (" A" , " P" , makeTS(2009 , 1 , 1 ), 1.0 , " first" , makeTS(2009 , 2 , 11 )),
3975 (" A" , " P" , makeTS(2009 , 7 , 1 ), 1.0 , " first" , makeTS(2009 , 8 , 11 )),
4076 (" A" , " P" , makeTS(2009 , 8 , 1 ), 1.0 , " last" , makeTS(2009 , 9 , 11 )),
41- (" A" , " S" , makeTS(2008 , 2 , 1 ), 1 .0 , " first" , makeTS(2008 , 3 , 11 ))
77+ (" A" , " S" , makeTS(2008 , 2 , 1 ), 2 .0 , " first" , makeTS(2008 , 5 , 11 ))
4278 ).toDF(PatientID , Value , Start , Weight , " Status" , " purchaseReach" )
4379
4480 val result = mockInstance.getFirstAndLastPurchase(input, 1 .months, 3 .month, 10 .days)
@@ -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