@@ -149,6 +149,7 @@ def create_base_patient(self):
149149 patient = {}
150150 self .set_timestamps (patient , datetime .date (year = 2017 , month = 5 , day = 20 ))
151151 patient ["CNTCT_LANG_CD" ] = random .choice (["~" , "ENG" , "SPA" ])
152+ patient ["IDR_LTST_TRANS_FLG" ] = "Y"
152153 address = self .gen_address ()
153154 for component in address :
154155 patient [component ] = address [component ]
@@ -196,12 +197,15 @@ def handle_mbis(self, patient, num_mbis, custom_first_mbi=None):
196197 )
197198 mbi_obj ["BENE_MBI_OBSLT_DT" ] = obslt_dt .strftime ("%Y-%m-%d" )
198199
199- # Create historical entry for the OLD MBI (not the new one)
200- historical_patient = copy .deepcopy (patient )
201- historical_patient ["BENE_MBI_ID" ] = previous_mbi if previous_mbi else patient ["BENE_MBI_ID" ]
202- # Set the obsolescence timestamp for the historical entry
203- self .set_timestamps (historical_patient , obslt_dt )
204- self .bene_hstry_table .append (historical_patient )
200+ if previous_mbi and previous_mbi != current_mbi :
201+ historical_patient = copy .deepcopy (patient )
202+ historical_patient ["BENE_MBI_ID" ] = previous_mbi
203+ historical_patient ["IDR_LTST_TRANS_FLG" ] = "N"
204+
205+ self .set_timestamps (historical_patient , obslt_dt )
206+ historical_patient ["IDR_TRANS_OBSLT_TS" ] = str (obslt_dt ) + "T00:00:00.000000+0000"
207+ self .bene_hstry_table .append (historical_patient )
208+
205209
206210 previous_obslt_dt = obslt_dt # Store for next iteration
207211 else :
@@ -308,6 +312,7 @@ def save_output_files(self):
308312 "GEO_ZIP5_CD" ,
309313 "GEO_USPS_STATE_CD" ,
310314 "CNTCT_LANG_CD" ,
315+ "IDR_LTST_TRANS_FLG" ,
311316 "IDR_TRANS_EFCTV_TS" ,
312317 "IDR_INSRT_TS" ,
313318 "IDR_UPDT_TS" ,
0 commit comments