@@ -8,19 +8,31 @@ def initialize(location, academic_year:, sync_patient_teams_now: false)
88 end
99
1010 def call
11- ActiveRecord ::Base . transaction do
12- if location . generic_clinic?
13- find_or_create_session! ( programmes : location . programmes )
14- else
15- ProgrammeGrouper
16- . call ( location . programmes )
17- . values
18- . reject { |programmes | catch_up_only? ( programmes :) }
19- . reject { |programmes | already_exists? ( programmes :) }
20- . map { |programmes | create_session! ( programmes :) }
21- end
11+ imported_patient_location_ids =
12+ ActiveRecord ::Base . transaction do
13+ if location . generic_clinic?
14+ find_or_create_session! ( programmes : location . programmes )
15+ else
16+ ProgrammeGrouper
17+ . call ( location . programmes )
18+ . values
19+ . reject { |programmes | catch_up_only? ( programmes :) }
20+ . reject { |programmes | already_exists? ( programmes :) }
21+ . map { |programmes | create_session! ( programmes :) }
22+ end
2223
23- add_patients!
24+ add_patients!
25+ end
26+ if sync_patient_teams_now
27+ SyncPatientTeamJob . perform_now (
28+ PatientLocation ,
29+ imported_patient_location_ids
30+ )
31+ else
32+ SyncPatientTeamJob . perform_later (
33+ PatientLocation ,
34+ imported_patient_location_ids
35+ )
2436 end
2537 end
2638
@@ -61,17 +73,11 @@ def find_or_create_session!(programmes:)
6173 end
6274
6375 def add_patients!
64- imported_ids =
65- PatientLocation . import! (
66- %i[ patient_id location_id academic_year ] ,
67- patient_ids . map { [ it , location . id , academic_year ] } ,
68- on_duplicate_key_ignore : true
69- ) . ids
70- if sync_patient_teams_now
71- SyncPatientTeamJob . perform_now ( PatientLocation , imported_ids )
72- else
73- SyncPatientTeamJob . perform_later ( PatientLocation , imported_ids )
74- end
76+ PatientLocation . import! (
77+ %i[ patient_id location_id academic_year ] ,
78+ patient_ids . map { [ it , location . id , academic_year ] } ,
79+ on_duplicate_key_ignore : true
80+ ) . ids
7581 end
7682
7783 def patient_ids
0 commit comments