Skip to content

Commit 0e8216c

Browse files
author
Youcef Sebiat
committed
CNAM-410: Add new tests.
1 parent c2d754d commit 0e8216c

File tree

2 files changed

+30
-25
lines changed

2 files changed

+30
-25
lines changed

src/main/scala/fr/polytechnique/cmap/cnam/etl/transformers/exposures/LimitedExposurePeriodAdder.scala

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,26 @@ private class LimitedExposurePeriodAdder(data: DataFrame) extends ExposurePeriod
1515
private val orderedWindow = window.orderBy(col(Start))
1616

1717
/** *
18-
* This strategy works as the following:
19-
* 1. Each DrugPurchase will have a corresponding Exposure.
20-
* 2. Each Exposure has one or multiple DrugPurchases.
21-
* 3. An Exposure is defined recursively as follows:
22-
* A. The first DrugPurchase defines a new Exposure.
23-
* B. If there is a DrugPurchase within the defined window of the first DrugPurchase, then expand the current
24-
* Exposure with the DrugPurchase.
25-
* C. Else, close and set the end of the Exposure as the reach of the latest Drug Purchase and create a new
26-
* Exposure with the next DrugPurchase as the new Exposure.
27-
* This strategy is suited for short term effects.
28-
* !!! WARNING: THIS ONLY RETURNS EXPOSURES.
29-
*
30-
* @param minPurchases : Not used.
31-
* @param startDelay : period to be added to the start of each DrugPurchase.
32-
* @param purchasesWindow : Not used.
33-
* @param endThresholdGc : the period that defines the reach for Grand Condtionnement.
34-
* @param endThresholdNgc : the period that defines the reach for Non Grand Condtionnement.
35-
* @param endDelay : period added to the end of an exposure.
36-
* @return: A DataFrame of Exposures.
37-
*/
18+
* This strategy works as the following:
19+
* 1. Each DrugPurchase will have a corresponding Exposure.
20+
* 2. Each Exposure has one or multiple DrugPurchases.
21+
* 3. An Exposure is defined recursively as follows:
22+
* A. The first DrugPurchase defines a new Exposure.
23+
* B. If there is a DrugPurchase within the defined window of the first DrugPurchase, then expand the current
24+
* Exposure with the DrugPurchase.
25+
* C. Else, close and set the end of the Exposure as the reach of the latest Drug Purchase and create a new
26+
* Exposure with the next DrugPurchase as the new Exposure.
27+
* This strategy is suited for short term effects.
28+
* !!! WARNING: THIS ONLY RETURNS EXPOSURES.
29+
*
30+
* @param minPurchases : Not used.
31+
* @param startDelay : period to be added to delay the start of each DrugPurchase.
32+
* @param purchasesWindow : Not used.
33+
* @param endThresholdGc : the period that defines the reach for Grand Conditionnement.
34+
* @param endThresholdNgc : the period that defines the reach for Non Grand Conditionnement.
35+
* @param endDelay : period added to the end of an exposure.
36+
* @return: A DataFrame of Exposures.
37+
*/
3838
def withStartEnd(
3939
minPurchases: Int = 2,
4040
startDelay: Period = 5.days,
@@ -48,7 +48,12 @@ private class LimitedExposurePeriodAdder(data: DataFrame) extends ExposurePeriod
4848

4949
val delayedDrugPurchases = delayStart(data, startDelay)
5050

51-
val firstLastPurchase = getFirstAndLastPurchase(delayedDrugPurchases, endThresholdGc.get, endThresholdNgc.get, endDelay.get)
51+
val firstLastPurchase = getFirstAndLastPurchase(
52+
delayedDrugPurchases,
53+
endThresholdGc.get,
54+
endThresholdNgc.get,
55+
endDelay.get
56+
)
5257

5358
toExposure(firstLastPurchase).select(outputColumns: _*)
5459
}

src/test/scala/fr/polytechnique/cmap/cnam/etl/transformers/exposures/LimitedExposurePeriodAdderSuite.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,26 +55,26 @@ class LimitedExposurePeriodAdderSuite extends SharedContext {
5555

5656
// Given
5757
val input = Seq(
58-
("A", "P", makeTS(2008, 1, 1), 1.0),
58+
("A", "P", makeTS(2008, 1, 1), 2.0),
5959
("A", "P", makeTS(2008, 2, 1), 1.0),
6060
("A", "P", makeTS(2008, 5, 1), 1.0),
6161
("A", "P", makeTS(2008, 6, 1), 1.0),
6262
("A", "P", makeTS(2008, 7, 1), 1.0),
6363
("A", "P", makeTS(2009, 1, 1), 1.0),
6464
("A", "P", makeTS(2009, 7, 1), 1.0),
6565
("A", "P", makeTS(2009, 8, 1), 1.0),
66-
("A", "S", makeTS(2008, 2, 1), 1.0)
66+
("A", "S", makeTS(2008, 2, 1), 2.0)
6767
).toDF(PatientID, Value, Start, Weight)
6868

6969
val expected = Seq(
70-
("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)),
7171
("A", "P", makeTS(2008, 2, 1), 1.0, "last", makeTS(2008, 3, 11)),
7272
("A", "P", makeTS(2008, 5, 1), 1.0, "first", makeTS(2008, 6, 11)),
7373
("A", "P", makeTS(2008, 7, 1), 1.0, "last", makeTS(2008, 8, 11)),
7474
("A", "P", makeTS(2009, 1, 1), 1.0, "first", makeTS(2009, 2, 11)),
7575
("A", "P", makeTS(2009, 7, 1), 1.0, "first", makeTS(2009, 8, 11)),
7676
("A", "P", makeTS(2009, 8, 1), 1.0, "last", makeTS(2009, 9, 11)),
77-
("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))
7878
).toDF(PatientID, Value, Start, Weight, "Status", "purchaseReach")
7979

8080
val result = mockInstance.getFirstAndLastPurchase(input, 1.months, 3.month, 10.days)

0 commit comments

Comments
 (0)