From 851cf44358ecb59a75dfbc902b81433699f8977b Mon Sep 17 00:00:00 2001 From: pbugni Date: Tue, 12 Mar 2024 08:32:51 -0700 Subject: [PATCH] bug found in qb_timeline overlap check (#4368) between protocol v3 and v5, additional months were added, i.e. month 33. if v3 month 36 didn't have any committed work and it's time to change protocols for the user, v5 month 33 should follow v3 month 30. the code looking for this case had an extra check which prevented the above from functioning, in the rare case where v3 month 30 ended before v5 month 33 starts. this was discovered with the new withdrawal handling in adherence data, as the insertion of the withdrawal row could not predictably insert before the time point just after withdrawal, when the timeline was found to have such an overlap. --- portal/models/qb_timeline.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/portal/models/qb_timeline.py b/portal/models/qb_timeline.py index aee9822af..c263fb381 100644 --- a/portal/models/qb_timeline.py +++ b/portal/models/qb_timeline.py @@ -812,7 +812,11 @@ def int_or_none(value): for row in qbt_rows: # Confirm expected order if last_at: - assert row.at >= last_at + if last_at > row.at: + raise ValueError( + f"patient {row.user_id} has overlapping qb_timeline rows" + f" {last_at} and {row.at}" + ) key = f"{row.qb_id}:{row.qb_iteration}" if previous_key and previous_key != key: @@ -975,11 +979,9 @@ def attempt_update(user_id, research_study_id, invalidate_existing): if ( pending_qbts[j].qb_id != remove_qb_id or pending_qbts[j].qb_iteration != remove_iteration): - # To qualify for this special case, - # having worked back to previous QB, if - # at > start, take action - if pending_qbts[j].at > start: - unwanted_count = len(pending_qbts)-j-1 + # unwanted_count represents all rows from + # overlapped, unwanted visit + unwanted_count = len(pending_qbts)-j-1 break # keep a lookout for work done in old RP