|
22 | 22 | # invalidated_at :datetime |
23 | 23 | # local_authority_mhclg_code :string |
24 | 24 | # nhs_number :string |
| 25 | +# nhs_number_first_added_at :datetime |
25 | 26 | # pending_changes :jsonb not null |
26 | 27 | # preferred_family_name :string |
27 | 28 | # preferred_given_name :string |
|
47 | 48 | # index_patients_on_names_family_first (family_name,given_name) |
48 | 49 | # index_patients_on_names_given_first (given_name,family_name) |
49 | 50 | # index_patients_on_nhs_number (nhs_number) UNIQUE |
| 51 | +# index_patients_on_nhs_number_first_added_at (nhs_number_first_added_at) |
50 | 52 | # index_patients_on_pending_changes_not_empty (id) WHERE (pending_changes <> '{}'::jsonb) |
51 | 53 | # index_patients_on_school_id (school_id) |
52 | 54 | # |
|
1307 | 1309 | end |
1308 | 1310 | end |
1309 | 1311 |
|
| 1312 | + describe "NHS number first added timestamp" do |
| 1313 | + it "sets nhs_number_first_added_at when an NHS number is first added" do |
| 1314 | + patient = |
| 1315 | + create(:patient, nhs_number: nil, nhs_number_first_added_at: nil) |
| 1316 | + |
| 1317 | + freeze_time do |
| 1318 | + expect { patient.update!(nhs_number: "9449310475") }.to change { |
| 1319 | + patient.reload.nhs_number_first_added_at |
| 1320 | + }.from(nil).to(Time.current) |
| 1321 | + end |
| 1322 | + end |
| 1323 | + |
| 1324 | + it "does not clear nhs_number_first_added_at when an NHS number is removed" do |
| 1325 | + patient = create(:patient) |
| 1326 | + |
| 1327 | + expect { patient.update!(nhs_number: nil) }.not_to( |
| 1328 | + change { patient.reload.nhs_number_first_added_at } |
| 1329 | + ) |
| 1330 | + end |
| 1331 | + |
| 1332 | + it "does not overwrite nhs_number_first_added_at when an NHS number is re-added" do |
| 1333 | + patient = create(:patient) |
| 1334 | + first_added_at = patient.nhs_number_first_added_at |
| 1335 | + |
| 1336 | + patient.update!(nhs_number: nil) |
| 1337 | + |
| 1338 | + expect { patient.update!(nhs_number: "9449310475") }.not_to change { |
| 1339 | + patient.reload.nhs_number_first_added_at |
| 1340 | + }.from(first_added_at) |
| 1341 | + end |
| 1342 | + end |
| 1343 | + |
1310 | 1344 | describe "#should_search_vaccinations_from_nhs_immunisations_api?" do |
1311 | 1345 | subject(:should_search_vaccinations_from_nhs_immunisations_api?) do |
1312 | 1346 | patient.send(:should_search_vaccinations_from_nhs_immunisations_api?) |
|
0 commit comments