Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions apps/bfd-pipeline-idr/model/base_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -850,18 +850,22 @@ def stale_phase_1_claims_query(
cutoff_date: datetime,
) -> tuple[str, tuple[datetime, datetime]]:
return (
f"""
f"""
WITH claims AS (
SELECT clm.clm_uniq_id
FROM {header_table} clm
WHERE clm.clm_type_cd BETWEEN {PHASE_1_SS_MIN} AND {PHASE_1_SS_MAX}
AND clm.clm_src_id IN ('{FISS_CLM_SOURCE}', '{MCS_CLM_SOURCE}', '{VMS_CLM_SOURCE}')
AND clm.bfd_updated_ts < %s
ORDER BY clm.bfd_updated_ts, clm.clm_uniq_id
)
SELECT clm.clm_uniq_id
FROM {header_table} clm
WHERE clm.clm_type_cd BETWEEN {PHASE_1_SS_MIN} AND {PHASE_1_SS_MAX}
AND clm.clm_src_id IN ('{FISS_CLM_SOURCE}', '{MCS_CLM_SOURCE}', '{VMS_CLM_SOURCE}')
AND clm.bfd_updated_ts < %s
AND NOT EXISTS (
FROM claims clm
WHERE NOT EXISTS (
SELECT 1 FROM {item_table} item
WHERE clm.clm_uniq_id = item.clm_uniq_id
AND item.bfd_updated_ts >= %s
)
ORDER BY clm.clm_uniq_id
LIMIT {PHASE_1_PRUNE_BATCH_LIMIT}
""",
(cutoff_date, cutoff_date),
Expand Down
Loading