Skip to content

Commit 19092b2

Browse files
misakathomasleese
authored andcommitted
Remove CSVImportable#process!
The intention is to make the import processing simpler to understand. Since nearly all the processing happens in the sub-classes we just call that directly from the ProcessImportJob. Jira-Issue: MAV-6063
1 parent 5b2c54d commit 19092b2

3 files changed

Lines changed: 35 additions & 33 deletions

File tree

app/models/concerns/csv_importable.rb

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -145,12 +145,6 @@ def processed?
145145
processed_at != nil
146146
end
147147

148-
def process!
149-
process_import!
150-
151-
TeamCachedCounts.new(team).reset_import_issues!
152-
end
153-
154148
def remove!
155149
return if csv_removed?
156150
update!(csv_data: nil, csv_removed_at: Time.zone.now)

app/models/immunisation_import.rb

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,36 @@ def records_count
6464
end
6565
end
6666

67+
def process!
68+
raise "'rows' are empty. Call parse_rows! before processing." if rows.nil?
69+
70+
counts = count_columns.index_with(0)
71+
72+
@vaccination_records_batch = Set.new
73+
@patients_batch = Set.new
74+
@patient_locations_batch = Set.new
75+
@archive_reasons_batch = Set.new
76+
77+
ActiveRecord::Base.transaction do
78+
rows.each do |row|
79+
count_column_to_increment = process_row(row)
80+
counts[count_column_to_increment] += 1
81+
bulk_import(rows: 100)
82+
end
83+
84+
bulk_import(rows: :all)
85+
86+
postprocess_rows!
87+
88+
update_columns(processed_at: Time.zone.now, status: :processed, **counts)
89+
end
90+
91+
post_commit!
92+
UpdatePatientsFromPDS.call(patients, queue: :imports)
93+
94+
TeamCachedCounts.new(team).reset_import_issues!
95+
end
96+
6797
private
6898

6999
# TODO: This is called by the `rows_are_valid` validation. Move it to it's own validation.
@@ -125,32 +155,6 @@ def process_row(row)
125155
count_column_to_increment
126156
end
127157

128-
def process_import!
129-
counts = count_columns.index_with(0)
130-
131-
@vaccination_records_batch = Set.new
132-
@patients_batch = Set.new
133-
@patient_locations_batch = Set.new
134-
@archive_reasons_batch = Set.new
135-
136-
ActiveRecord::Base.transaction do
137-
rows.each do |row|
138-
count_column_to_increment = process_row(row)
139-
counts[count_column_to_increment] += 1
140-
bulk_import(rows: 100)
141-
end
142-
143-
bulk_import(rows: :all)
144-
145-
postprocess_rows!
146-
147-
update_columns(processed_at: Time.zone.now, status: :processed, **counts)
148-
end
149-
150-
post_commit!
151-
UpdatePatientsFromPDS.call(patients, queue: :imports)
152-
end
153-
154158
def bulk_import(rows: 100)
155159
return if rows != :all && @vaccination_records_batch.size < rows
156160

app/models/patient_import.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ def records_count
3434
changesets.from_file.count
3535
end
3636

37-
def process_import!
37+
def process!
38+
raise "'rows' are empty. Call parse_rows! before processing." if rows.nil?
39+
3840
changesets =
3941
rows.each_with_index.map do |row, row_number|
4042
PatientChangeset.from_import_row(row:, import: self, row_number:)
@@ -54,6 +56,8 @@ def process_import!
5456
return if changesets_are_invalid?
5557

5658
enqueue_review_jobs(self.changesets)
59+
60+
TeamCachedCounts.new(team).reset_import_issues!
5761
end
5862

5963
def validate_pds_match_rate!

0 commit comments

Comments
 (0)