@@ -223,7 +223,14 @@ def handle_mbis(self, patient, num_mbis, custom_first_mbi=None):
223223 previous_mbi = patient ["BENE_MBI_ID" ]
224224 patient ["BENE_MBI_ID" ] = current_mbi
225225
226- def generate_coverages (self , patient , coverage_parts = ['A' , 'B' ], include_tpl = True , expired = False , future = False ):
226+ def generate_coverages (self , patient ):
227+ parts = random .choices ([['A' ], ['B' ], ['A' , 'B' ], []], weights = [0.2 , 0.2 , 0.5 , 0.1 ])[0 ]
228+ include_tp = random .random () > 0.2
229+ expired = random .random () < 0.2
230+ future = random .random () < 0.2
231+ self ._generate_coverages (patient , coverage_parts = parts , include_tp = include_tp , expired = expired , future = future )
232+
233+ def _generate_coverages (self , patient , coverage_parts , include_tp , expired , future ):
227234 now = datetime .date .today ()
228235 if expired :
229236 medicare_start_date = now - datetime .timedelta (days = 730 )
@@ -266,7 +273,6 @@ def generate_coverages(self, patient, coverage_parts=['A', 'B'], include_tpl=Tru
266273 self .mdcr_rsn .append (rsn_row )
267274
268275 for coverage_type in coverage_parts :
269-
270276 #ENTLMT
271277 entlmt_row = {"BENE_SK" :patient ['BENE_SK' ],
272278 'IDR_LTST_TRANS_FLG' :'Y' ,
@@ -282,7 +288,7 @@ def generate_coverages(self, patient, coverage_parts=['A', 'B'], include_tpl=Tru
282288 }
283289 self .mdcr_entlmt .append (entlmt_row )
284290 #TP
285- if include_tpl :
291+ if include_tp :
286292 tp_row = {"BENE_SK" :patient ['BENE_SK' ],
287293 'IDR_LTST_TRANS_FLG' :'Y' ,
288294 'BENE_TP_TYPE_CD' : coverage_type ,
@@ -496,45 +502,3 @@ def save_output_files(self):
496502 df = pd .json_normalize (self .bene_mapd_enrlmt )
497503 if (df .size > 0 ):
498504 df .to_csv ("out/SYNTHETIC_BENE_MAPD_ENRLMT.csv" , index = False )
499-
500- # === ADDITION START: Main execution block to generate specific cases ===
501- if __name__ == "__main__" :
502- util = GeneratorUtil ()
503-
504- scenarios = {
505- "part_a_only" : {"coverage_parts" : ['A' ], "include_tpl" : True },
506- "part_b_only" : {"coverage_parts" : ['B' ], "include_tpl" : True },
507- "expired_coverage" : {"coverage_parts" : ['A' , 'B' ], "include_tpl" : True , "expired" : True },
508- "future_coverage" : {"coverage_parts" : ['A' , 'B' ], "include_tpl" : True , "future" : True },
509- "no_third_party_data" : {"coverage_parts" : ['A' , 'B' ], "include_tpl" : False }
510- }
511-
512- # Generate one patient for each scenario
513- for patient_type , params in scenarios .items ():
514- print (f"Generating patient: { patient_type } ..." )
515-
516- patient = util .create_base_patient ()
517-
518- patient ["BENE_SK" ] = util .gen_bene_sk ()
519- patient ["BENE_XREF_EFCTV_SK" ] = 0
520- name = util .fake .name ().split ()
521- patient ["BENE_1ST_NAME" ] = name [0 ]
522- patient ["BENE_LAST_NAME" ] = name [1 ]
523- patient ["BENE_MIDL_NAME" ] = util .fake .random_uppercase_letter ()
524- patient ["BENE_BRTH_DT" ] = util .fake .date_of_birth (minimum_age = 65 , maximum_age = 90 ).strftime ('%Y-%m-%d' )
525- patient ["BENE_DEATH_DT" ] = "9999-12-31"
526- patient ["BENE_VRFY_DEATH_DAY_SW" ] = "N"
527- patient ["BENE_SEX_CD" ] = random .choice (["1" , "2" ])
528- patient ["BENE_RACE_CD" ] = random .choice (util .code_systems .get ('BENE_RACE_CD' , ['1' ]))
529-
530- util .handle_mbis (patient , num_mbis = 1 )
531-
532- util .bene_hstry_table .append (patient )
533-
534- util .generate_coverages (patient , ** params )
535-
536- print ("Saving all data to output files in 'out/' directory..." )
537- util .save_output_files ()
538- print ("Done." )
539-
540-
0 commit comments