@@ -56,11 +56,11 @@ def fetch_applications(type)
5656
5757 if %w[ individual_market both ] . include? ( type )
5858 individual_market_applications = ::IndividualMarket ::Application . all . only (
59- :hbx_id , :relationships , :id , :family_id , :aasm_state , :assistance_year , :transfer_id
59+ :hbx_id , :relationships , :id , :family_id , :current_state , :assistance_year
6060 ) . where (
6161 :relationships => {
6262 '$elemMatch' => {
63- :kind => { '$nin' => AcaEntities ::MagiMedicaid ::Types ::RelationshipKind . values } ,
63+ :kind => { '$nin' => AcaEntities ::IndividualMarket ::Types ::RelationshipKind . values } ,
6464 :_id => { '$exists' => true }
6565 }
6666 }
@@ -102,21 +102,21 @@ def generate_report_or_fix_data(action_type, applications)
102102 end
103103 end
104104
105- # Method to generate a report of invalid FA applicant relationships
105+ # Method to generate a report of invalid applicant relationships
106106 #
107107 # @param [Array] applications
108108 #
109109 # @return [void]
110110 def generate_report ( applications )
111- @csv_file = "invalid_fa_applicant_relationship_kinds_report_ #{ TimeKeeper . date_of_record . strftime ( '%Y_%m_%d' ) } .csv"
111+ @csv_file = "invalid_applicant_relationship_kinds_report_ #{ TimeKeeper . date_of_record . strftime ( '%Y_%m_%d' ) } .csv"
112112 CSV . open ( @csv_file , 'w' , force_quotes : true ) do |csv |
113113 csv << [
114114 'Primary Person Hbx ID' ,
115- 'FA Application Hbx ID' ,
116- 'FA Application Type' ,
117- 'FA Application Assistance Year' ,
118- 'FA Application AASM State' ,
119- 'FA Application Transfer ID' ,
115+ 'Application Hbx ID' ,
116+ 'Application Type' ,
117+ 'Application Assistance Year' ,
118+ 'Application State' ,
119+ 'Application Transfer ID' ,
120120 'Applicant/Source ID' ,
121121 'Relative ID' ,
122122 'Invalid Relationship Kind'
@@ -130,13 +130,19 @@ def generate_report(applications)
130130 # Handle both IndividualMarket::Relationship (source_id) and FinancialAssistance::Relationship (applicant_id)
131131 applicant_or_source_id = relationship . respond_to? ( :applicant_id ) ? relationship . applicant_id : relationship . source_id
132132
133+ # Determine application type and handle different field names
134+ is_individual_market = application . is_a? ( ::IndividualMarket ::Application )
135+ app_type = is_individual_market ? 'IndividualMarket::Application' : 'FinancialAssistance::Application'
136+ app_state = is_individual_market ? application . current_state : application . aasm_state
137+ transfer_id = is_individual_market ? nil : application . transfer_id
138+
133139 csv << [
134140 primary_person . hbx_id ,
135141 application . hbx_id ,
136- application . class . name ,
142+ app_type ,
137143 application . assistance_year ,
138- application . aasm_state ,
139- application . transfer_id ,
144+ app_state ,
145+ transfer_id ,
140146 applicant_or_source_id ,
141147 relationship . relative_id ,
142148 relationship . kind
@@ -146,25 +152,25 @@ def generate_report(applications)
146152 end
147153 end
148154
149- # Method to fix invalid FA applicant relationship kinds
155+ # Method to fix invalid applicant relationship kinds
150156 # If the relationship kind is 'self', the relationship is destroyed.
151157 # Otherwise, the relationship kind is updated to 'unrelated'.
152158 #
153159 # @param [Array] applications
154160 #
155161 # @return [void]
156162 def fix_invalid_relationship_kinds ( applications )
157- @csv_file = "invalid_fa_applicant_relationship_kinds_data_fix_ #{ TimeKeeper . date_of_record . strftime ( '%Y_%m_%d' ) } .csv"
163+ @csv_file = "invalid_applicant_relationship_kinds_data_fix_ #{ TimeKeeper . date_of_record . strftime ( '%Y_%m_%d' ) } .csv"
158164 CSV . open (
159165 @csv_file , 'w' , force_quotes : true
160166 ) do |csv |
161167 csv << [
162168 'Primary Person Hbx ID' ,
163- 'FA Application Hbx ID' ,
164- 'FA Application Type' ,
165- 'FA Application Assistance Year' ,
166- 'FA Application AASM State' ,
167- 'FA Application Transfer ID' ,
169+ 'Application Hbx ID' ,
170+ 'Application Type' ,
171+ 'Application Assistance Year' ,
172+ 'Application State' ,
173+ 'Application Transfer ID' ,
168174 'Applicant/Source ID' ,
169175 'Relative ID' ,
170176 'Invalid Relationship Kind' ,
@@ -179,6 +185,12 @@ def fix_invalid_relationship_kinds(applications)
179185 # Handle both IndividualMarket::Relationship (source_id) and FinancialAssistance::Relationship (applicant_id)
180186 applicant_or_source_id = relationship . respond_to? ( :applicant_id ) ? relationship . applicant_id : relationship . source_id
181187
188+ # Determine application type and handle different field names
189+ is_individual_market = application . is_a? ( ::IndividualMarket ::Application )
190+ app_type = is_individual_market ? 'IndividualMarket::Application' : 'FinancialAssistance::Application'
191+ app_state = is_individual_market ? application . current_state : application . aasm_state
192+ transfer_id = is_individual_market ? nil : application . transfer_id
193+
182194 old_kind = relationship . kind
183195
184196 if relationship . kind == 'self'
@@ -192,10 +204,10 @@ def fix_invalid_relationship_kinds(applications)
192204 csv << [
193205 primary_person . hbx_id ,
194206 application . hbx_id ,
195- application . class . name ,
207+ app_type ,
196208 application . assistance_year ,
197- application . aasm_state ,
198- application . transfer_id ,
209+ app_state ,
210+ transfer_id ,
199211 applicant_or_source_id ,
200212 relationship . relative_id ,
201213 old_kind ,
0 commit comments