Skip to content

Commit a962449

Browse files
committed
fix: improve logic.Count for count_min = 0
Do not require a positive number of intervals of type POSITIVE if count_min is 0. Add a test case.
1 parent 6f69a39 commit a962449

File tree

2 files changed

+64
-4
lines changed

2 files changed

+64
-4
lines changed

execution_engine/task/task.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,8 @@ def interval_union_with_count(
383383
count_max = self.expr.count_max
384384
if count_min is None and count_max is None:
385385
raise ValueError("count_min and count_max cannot both be None")
386+
if count_min is None:
387+
count_min = 0
386388

387389
def interval_counts(
388390
start: int, end: int, intervals: List[GeneralizedInterval]
@@ -395,11 +397,12 @@ def interval_counts(
395397
for interval in intervals
396398
)
397399

398-
# The interval type with the highest "union priority"
399-
# determines the result.
400+
# Either the count constraints or the interval type
401+
# with the highest "union priority" determines the
402+
# result.
400403
positive_count = counts[IntervalType.POSITIVE]
401-
if positive_count > 0:
402-
if count_min is None:
404+
if positive_count > 0 or count_min == 0:
405+
if count_min == 0:
403406
if positive_count <= count_max:
404407
return Interval(start, end, IntervalType.POSITIVE)
405408
else:

tests/execution_engine/omop/criterion/combination/test_temporal_combination.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2387,6 +2387,63 @@ def patient_events(self, db_session, visit_occurrence):
23872387
],
23882388
},
23892389
),
2390+
(
2391+
logic.And(c2), # population
2392+
logic.MaxCount(
2393+
bodyweight_measurement_with_forward_fill,
2394+
body_height_measurement_with_forward_fill,
2395+
tidal_volume_measurement_with_forward_fill,
2396+
threshold=2,
2397+
),
2398+
{
2399+
1: [
2400+
(
2401+
IntervalType.NOT_APPLICABLE,
2402+
'nan',
2403+
pendulum.parse("2025-02-18 17:55:00+01:00"),
2404+
pendulum.parse("2025-02-19 07:59:59+01:00"),
2405+
),
2406+
(
2407+
IntervalType.POSITIVE,
2408+
'nan',
2409+
pendulum.parse("2025-02-19 08:00:00+01:00"),
2410+
pendulum.parse("2025-02-20 17:59:59+01:00"),
2411+
),
2412+
(
2413+
IntervalType.NEGATIVE,
2414+
'nan',
2415+
pendulum.parse("2025-02-20 18:00:00+01:00"),
2416+
pendulum.parse("2025-02-21 02:00:00+01:00"),
2417+
),
2418+
(
2419+
IntervalType.NOT_APPLICABLE,
2420+
'nan',
2421+
pendulum.parse("2025-02-21 02:00:01+01:00"),
2422+
pendulum.parse("2025-02-22 05:30:00+01:00"),
2423+
),
2424+
],
2425+
2: [
2426+
(
2427+
IntervalType.NOT_APPLICABLE,
2428+
'nan',
2429+
pendulum.parse("2025-02-18 17:55:00+01:00"),
2430+
pendulum.parse("2025-02-19 07:59:59+01:00"),
2431+
),
2432+
(
2433+
IntervalType.POSITIVE,
2434+
'nan',
2435+
pendulum.parse("2025-02-19 08:00:00+01:00"),
2436+
pendulum.parse("2025-02-21 02:00:00+01:00"),
2437+
),
2438+
(
2439+
IntervalType.NOT_APPLICABLE,
2440+
'nan',
2441+
pendulum.parse("2025-02-21 02:00:01+01:00"),
2442+
pendulum.parse("2025-02-22 05:30:00+01:00"),
2443+
),
2444+
],
2445+
},
2446+
),
23902447
],
23912448
)
23922449
def test_combination_on_database(

0 commit comments

Comments
 (0)