File tree Expand file tree Collapse file tree
apps/bfd-pipeline-idr/model Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -850,18 +850,22 @@ def stale_phase_1_claims_query(
850850 cutoff_date : datetime ,
851851) -> tuple [str , tuple [datetime , datetime ]]:
852852 return (
853- f"""
853+ f"""
854+ WITH claims AS (
855+ SELECT clm.clm_uniq_id
856+ FROM { header_table } clm
857+ WHERE clm.clm_type_cd BETWEEN { PHASE_1_SS_MIN } AND { PHASE_1_SS_MAX }
858+ AND clm.clm_src_id IN ('{ FISS_CLM_SOURCE } ', '{ MCS_CLM_SOURCE } ', '{ VMS_CLM_SOURCE } ')
859+ AND clm.bfd_updated_ts < %s
860+ ORDER BY clm.bfd_updated_ts, clm.clm_uniq_id
861+ )
854862 SELECT clm.clm_uniq_id
855- FROM { header_table } clm
856- WHERE clm.clm_type_cd BETWEEN { PHASE_1_SS_MIN } AND { PHASE_1_SS_MAX }
857- AND clm.clm_src_id IN ('{ FISS_CLM_SOURCE } ', '{ MCS_CLM_SOURCE } ', '{ VMS_CLM_SOURCE } ')
858- AND clm.bfd_updated_ts < %s
859- AND NOT EXISTS (
863+ FROM claims clm
864+ WHERE NOT EXISTS (
860865 SELECT 1 FROM { item_table } item
861866 WHERE clm.clm_uniq_id = item.clm_uniq_id
862867 AND item.bfd_updated_ts >= %s
863868 )
864- ORDER BY clm.clm_uniq_id
865869 LIMIT { PHASE_1_PRUNE_BATCH_LIMIT }
866870 """ ,
867871 (cutoff_date , cutoff_date ),
You can’t perform that action at this time.
0 commit comments