Skip to content

Commit 5b821a9

Browse files
committed
Do not process patients that have skipped school move
These records should be skipped entirely from the import so no changes to the base patient are made from data that is very likely to be outdated (why we're skipping the school moves in the first place)
1 parent 3fe28fc commit 5b821a9

3 files changed

Lines changed: 26 additions & 5 deletions

File tree

app/jobs/commit_import_job.rb

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,19 @@ def perform(import_global_id)
3939
changesets
4040
.from_file
4141
.includes(:school)
42-
.find_in_batches(batch_size: 100) do |changesets|
43-
increment_column_counts!(import, counts, changesets)
42+
.find_in_batches(batch_size: 100) do |batch|
43+
to_skip = batch.select(&:school_move_to_unknown_from_another_team?)
44+
to_process = batch - to_skip
4445

45-
import_patients_and_parents(changesets, import)
46-
import_school_moves(changesets, import)
47-
import_pds_search_results(changesets, import)
46+
if to_process.any?
47+
increment_column_counts!(import, counts, to_process)
48+
49+
import_patients_and_parents(to_process, import)
50+
import_school_moves(to_process, import)
51+
import_pds_search_results(to_process, import)
52+
end
53+
54+
to_skip.each(&:processed!)
4855
end
4956

5057
PatientTeamUpdater.call(patient_scope: import.patients)

app/jobs/commit_patient_changesets_job.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ def perform(patient_changeset_ids)
3131
changesets.update_all(patient_id: nil)
3232

3333
to_process = changesets.select { review_consistent?(it) }
34+
to_skip = changesets.select(&:skipped_school_move?)
35+
to_process -= to_skip
3436

3537
if to_process.any?
3638
increment_column_counts!(import, counts, to_process)
@@ -40,6 +42,8 @@ def perform(patient_changeset_ids)
4042
to_process.each(&:processed!)
4143
end
4244

45+
to_skip.each(&:processed!)
46+
4347
PatientTeamUpdater.call(patient_scope: import.patients)
4448
end
4549

spec/features/import_child_records_review_spec.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
and_i_should_see_the_skipped_school_moves_summary
2121
and_the_patient_should_remain_at_their_current_school
2222
and_the_patient_should_not_be_linked_to_my_team
23+
and_the_patient_should_not_be_linked_to_the_import
24+
and_the_import_changes_should_not_be_processed
2325
end
2426

2527
def given_i_am_signed_in
@@ -117,4 +119,12 @@ def and_the_patient_should_not_be_linked_to_my_team
117119
expect(@patient.teams).not_to include(@team)
118120
expect(@patient.teams).to contain_exactly(@other_team)
119121
end
122+
123+
def and_the_patient_should_not_be_linked_to_the_import
124+
expect(@patient.cohort_imports).to be_empty
125+
end
126+
127+
def and_the_import_changes_should_not_be_processed
128+
expect(@patient.parents).to be_empty
129+
end
120130
end

0 commit comments

Comments
 (0)