File tree Expand file tree Collapse file tree 1 file changed +24
-17
lines changed Expand file tree Collapse file tree 1 file changed +24
-17
lines changed Original file line number Diff line number Diff line change 2
2
3
3
desc "Migrate patients who were moved out of cohorts to ensure they're archived."
4
4
task archive_moved_out_of_cohort_patients : :environment do
5
- Team . find_each do |team |
6
- user = OpenStruct . new ( selected_team : team )
5
+ Team
6
+ . includes ( :organisation )
7
+ . find_each do |team |
8
+ user =
9
+ OpenStruct . new (
10
+ selected_team : team ,
11
+ selected_organisation : team . organisation
12
+ )
7
13
8
- patients_in_cohort = team . patients
9
- patients_associated_with_team =
10
- PatientPolicy ::Scope . new ( user , Patient ) . resolve
14
+ patients_in_cohort = team . patients
15
+ patients_associated_with_team =
16
+ PatientPolicy ::Scope . new ( user , Patient ) . resolve
11
17
12
- patients_not_in_cohort = patients_associated_with_team - patients_in_cohort
18
+ patients_not_in_cohort =
19
+ patients_associated_with_team - patients_in_cohort
13
20
14
- archive_reasons =
15
- patients_not_in_cohort . map do |patient |
16
- ArchiveReason . new (
17
- patient :,
18
- team :,
19
- type : "other" ,
20
- other_details : "Unknown: before reasons added"
21
- )
22
- end
21
+ archive_reasons =
22
+ patients_not_in_cohort . map do |patient |
23
+ ArchiveReason . new (
24
+ patient :,
25
+ team :,
26
+ type : "other" ,
27
+ other_details : "Unknown: before reasons added"
28
+ )
29
+ end
23
30
24
- ArchiveReason . import! ( archive_reasons , on_duplicate_key_ignore : true )
25
- end
31
+ ArchiveReason . import! ( archive_reasons , on_duplicate_key_ignore : true )
32
+ end
26
33
end
You can’t perform that action at this time.
0 commit comments