Skip to content

Commit 33620e3

Browse files
authored
Merge pull request #6049 from nhsuk/next
v6.20.0
2 parents c4199a9 + ce76186 commit 33620e3

66 files changed

Lines changed: 1363 additions & 588 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/create_dockerized_db.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ jobs:
6363
run: |
6464
bin/rails db:setup
6565
bin/rails feature_flags:enable_for_development
66-
bin/mavis gias import
66+
bin/mavis gias import --input-file=spec/fixtures/dfe-schools.zip
6767
- name: Configure AWS Credentials
6868
uses: aws-actions/configure-aws-credentials@v6
6969
with:
@@ -81,4 +81,4 @@ jobs:
8181
run: |
8282
docker commit database "${{ steps.login-ecr.outputs.registry }}/mavis/development/postgres_db:${{ steps.github-ref.outputs.ref }}"
8383
- name: Push image
84-
run: docker push "${{ steps.login-ecr.outputs.registry }}/mavis/development/postgres_db:${{ steps.github-ref.outputs.ref }}"
84+
run: docker push "${{ steps.login-ecr.outputs.registry }}/mavis/development/postgres_db:${{ steps.github-ref.outputs.ref }}"

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,8 @@ public/ref
8585

8686
# Redis
8787
dump.rdb
88+
89+
90+
# Data that gets downloaded by CLI tools
91+
db/data/dfe-schools.zip
92+
db/data/nhs-gp-practices.zip

Gemfile.lock

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -134,19 +134,19 @@ GEM
134134
ast (2.4.3)
135135
attr_required (1.0.2)
136136
aws-eventstream (1.4.0)
137-
aws-partitions (1.1210.0)
137+
aws-partitions (1.1213.0)
138138
aws-sdk-accessanalyzer (1.85.0)
139139
aws-sdk-core (~> 3, >= 3.241.4)
140140
aws-sigv4 (~> 1.5)
141-
aws-sdk-core (3.241.4)
141+
aws-sdk-core (3.242.0)
142142
aws-eventstream (~> 1, >= 1.3.0)
143143
aws-partitions (~> 1, >= 1.992.0)
144144
aws-sigv4 (~> 1.9)
145145
base64
146146
bigdecimal
147147
jmespath (~> 1, >= 1.6.1)
148148
logger
149-
aws-sdk-ec2 (1.597.0)
149+
aws-sdk-ec2 (1.598.0)
150150
aws-sdk-core (~> 3, >= 3.241.4)
151151
aws-sigv4 (~> 1.5)
152152
aws-sdk-ecr (1.119.0)
@@ -158,7 +158,7 @@ GEM
158158
aws-sdk-kms (1.121.0)
159159
aws-sdk-core (~> 3, >= 3.241.4)
160160
aws-sigv4 (~> 1.5)
161-
aws-sdk-rds (1.306.0)
161+
aws-sdk-rds (1.307.0)
162162
aws-sdk-core (~> 3, >= 3.241.4)
163163
aws-sigv4 (~> 1.5)
164164
aws-sdk-s3 (1.213.0)
@@ -258,7 +258,7 @@ GEM
258258
railties (>= 6.1.0)
259259
faker (3.6.0)
260260
i18n (>= 1.8.11, < 2)
261-
faraday (2.14.0)
261+
faraday (2.14.1)
262262
faraday-net_http (>= 2.0, < 3.5)
263263
json
264264
logger
@@ -334,7 +334,7 @@ GEM
334334
jmespath (1.6.2)
335335
jsbundling-rails (1.3.1)
336336
railties (>= 6.0.0)
337-
json (2.18.0)
337+
json (2.18.1)
338338
json-jwt (1.17.0)
339339
activesupport (>= 4.2)
340340
aes_key_wrap
@@ -451,7 +451,7 @@ GEM
451451
pagy (9.4.0)
452452
paint (2.3.0)
453453
parallel (1.27.0)
454-
parallel_tests (5.5.0)
454+
parallel_tests (5.6.0)
455455
parallel
456456
parser (3.3.10.1)
457457
ast (~> 2.4.1)

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ This runs tests in the `end_to_end` rails environment which will not interfere w
226226
```shell
227227
RAILS_ENV=end_to_end bin/rails db:setup
228228
RAILS_ENV=end_to_end bin/rails feature_flags:enable_for_development
229-
RAILS_ENV=end_to_end bin/mavis gias import
229+
RAILS_ENV=end_to_end bin/mavis gias import --input-file=spec/fixtures/dfe-schools.zip
230230
RAILS_ENV=end_to_end bin/rails assets:precompile
231231
```
232232

app/components/app_activity_log_component.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ def initialize(team:, patient:, session: nil)
6969
session ? scope.where(location: session.location) : scope
7070
end
7171

72+
@patient_merge_log_entries =
73+
@patient.patient_merge_log_entries.includes(:user)
74+
7275
@patient_specific_directions =
7376
@patient
7477
.patient_specific_directions
@@ -105,6 +108,7 @@ def initialize(team:, patient:, session: nil)
105108
:notify_log_entries,
106109
:patient,
107110
:patient_locations,
111+
:patient_merge_log_entries,
108112
:patient_specific_directions,
109113
:pre_screenings,
110114
:attendance_records,
@@ -124,6 +128,7 @@ def all_events
124128
gillick_assessment_events,
125129
note_events,
126130
notify_events,
131+
patient_merge_events,
127132
patient_specific_direction_events,
128133
pre_screening_events,
129134
session_events,
@@ -309,6 +314,21 @@ def notify_events
309314
end
310315
end
311316

317+
def patient_merge_events
318+
patient_merge_log_entries.map do |patient_merge_log_entry|
319+
{
320+
title: "Child record merged",
321+
body:
322+
"The record for #{patient_merge_log_entry.merged_patient_name} (date of birth " \
323+
"#{patient_merge_log_entry.merged_patient_dob.to_fs(:long)}) was merged with the record for " \
324+
"#{patient.full_name} (date of birth #{patient.date_of_birth.to_fs(:long)}) because they have the same " \
325+
"NHS number (#{patient_merge_log_entry.merged_patient_nhs_number}).",
326+
at: patient_merge_log_entry.created_at,
327+
by: patient_merge_log_entry.user
328+
}
329+
end
330+
end
331+
312332
def patient_specific_direction_events
313333
patient_specific_directions.flat_map do |patient_specific_direction|
314334
events = []

app/components/app_import_statistics_component.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
class AppImportStatisticsComponent < ViewComponent::Base
44
erb_template <<-ERB
5-
<p><strong>Out of <%= pluralize(@import.records_count, "record") %> found in the file:</strong></p>
5+
<p><strong><%= pluralize(@import.records_count, "record") %> found in the file:</strong></p>
66
<ul>
77
<li><%= pluralize(@import.new_record_count, "new record") %> imported</li>
88
<li><%= pluralize(@import.exact_duplicate_record_count, "duplicate") %> not imported</li>
9-
<li><%= pluralize(@import.ignored_record_count, "'not vaccinated' record") %> not imported</li>
9+
<li><%= pluralize(@import.ignored_record_count, "not vaccinated record") %> not imported</li>
1010
</ul>
1111
ERB
1212

app/components/app_patient_summary_component.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@ def initialize(patient)
2727
to: :helpers
2828

2929
def rows
30-
[nhs_number_row, date_of_birth_row, address_row]
30+
[
31+
nhs_number_row,
32+
date_of_birth_row,
33+
(address_row unless patient.restricted?)
34+
].compact
3135
end
3236

3337
def classes

app/components/app_vaccination_record_summary_component.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@ def initialize(
55
vaccination_record,
66
current_user:,
77
change_links: {},
8-
show_notes: true
8+
show_notes: true,
9+
comparing: false
910
)
1011
@vaccination_record = vaccination_record
1112
@current_user = current_user
1213
@change_links = change_links
1314
@show_notes = show_notes
15+
@comparing = comparing
1416

1517
@identity_check = vaccination_record.identity_check
1618
@patient = vaccination_record.patient
@@ -316,7 +318,8 @@ def call
316318
end && Flipper.enabled?(:imms_api_integration)
317319
if @vaccination_record.respond_to?(:sync_status) &&
318320
correct_feature_flags_enabled &&
319-
@vaccination_record.correct_source_for_nhs_immunisations_api?
321+
@vaccination_record.correct_source_for_nhs_immunisations_api? &&
322+
!@comparing
320323
summary_list.with_row do |row|
321324
row.with_key { "Synced with NHS England?" }
322325
row.with_value do

app/forms/concerns/patient_merge_form_concern.rb

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,29 @@ def nhs_number=(value)
1515
end
1616

1717
def existing_patient
18+
return if nhs_number.blank?
19+
1820
@existing_patient ||=
19-
if nhs_number.present?
20-
patient_policy_scope.includes(:vaccination_records).find_by(
21-
nhs_number:
22-
) ||
23-
Patient
24-
.where
25-
.missing(:patient_locations)
26-
.includes(:vaccination_records)
27-
.find_by(nhs_number:)
28-
end
21+
find_existing(patient_policy_scope) ||
22+
find_existing(Patient.where.missing(:patient_locations))
23+
end
24+
25+
def find_existing(scope)
26+
scope
27+
.where.not(id: patient.id)
28+
.includes(:vaccination_records)
29+
.find_by(nhs_number: nhs_number)
2930
end
3031

3132
def save
3233
return false if invalid?
3334

3435
if existing_patient
35-
PatientMerger.call(to_keep: existing_patient, to_destroy: patient)
36+
PatientMerger.call(
37+
to_keep: existing_patient,
38+
to_destroy: patient,
39+
user: current_user
40+
)
3641
end
3742

3843
true

app/forms/import_duplicate_form.rb

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,54 @@ def apply_pending_changes!
5858
end
5959

6060
def discard_pending_changes!
61+
remove_imported_parent_relationships_if_needed!
62+
6163
object.patient.discard_pending_changes! if object.respond_to?(:patient)
6264

6365
object.discard_pending_changes!
6466
end
6567

6668
def keep_both_changes!
67-
object.apply_pending_changes_to_new_record! if can_keep_both? && can_apply?
69+
return unless can_keep_both?
70+
return unless can_apply?
71+
72+
object.apply_pending_changes_to_new_record!(
73+
changeset: changeset_for_keep_both
74+
)
75+
end
76+
77+
def changeset_for_keep_both
78+
scope = object.changesets.includes(:import).order(:created_at)
79+
80+
return scope.last unless Flipper.enabled?(:import_review_screen)
81+
82+
completed_import_statuses = %w[
83+
processed
84+
partially_processed
85+
removing_parent_relationships
86+
]
87+
88+
scope
89+
.processed
90+
.select { completed_import_statuses.include?(it.import&.status) }
91+
.last
6892
end
6993

7094
def reset_count!
7195
TeamCachedCounts.new(current_team).reset_import_issues!
7296
end
97+
98+
def remove_imported_parent_relationships_if_needed!
99+
return unless object.is_a?(Patient)
100+
101+
changeset = object.changesets.includes(:import).order(:created_at).last
102+
return if changeset.nil?
103+
104+
changeset
105+
.import
106+
.parent_relationships
107+
.includes(:patient)
108+
.where(patient: object)
109+
.find_each(&:destroy!)
110+
end
73111
end

0 commit comments

Comments
 (0)