Skip to content

Commit e852a8d

Browse files
authored
Change default TIME_OF_VACCINATION to midnight (#3213)
If a `TIME_OF_VACCINATION` is not specified, the default is set to midday (`12:00`). This causes a problem if the file is uploaded in the morning for sessions that happened that day (which could occur for an offline recording), as the `performed_at` date/time ends up being in the future which fails the validation on the `VaccinationRecord`. Setting the time to midnight ensures that this will always pass those validation checks. Preferrably, I think we should treat the date and time separately, and allow for the scenario where the time of the vaccination is unknown and present that to the user rather than needing to pick a default. However, this would require changes to the data model. Alternatively, my first implementation was to use the current time, which passes the validation checks, but introduces a new issue related to our duplicate checker. If the same file (without time of vaccinations) is uploaded twice, because the time has now changed, the records don't end up being flagged as duplicates, which runs the risk of duplicate vaccination records being imported. Again, I think if we treated the date separate to the time, we could improve this situation. https://good-machine.sentry.io/issues/6339922906/
2 parents 13ac932 + 3a384ae commit e852a8d

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

app/models/immunisation_import_row.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ def performed_at
426426
date_of_vaccination.year,
427427
date_of_vaccination.month,
428428
date_of_vaccination.day,
429-
time_of_vaccination&.hour || 12,
429+
time_of_vaccination&.hour || 0,
430430
time_of_vaccination&.min || 0,
431431
time_of_vaccination&.sec || 0
432432
)

spec/features/import_vaccination_records_with_duplicates_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def and_an_existing_patient_record_exists
109109
create(
110110
:vaccination_record,
111111
programme: @programme,
112-
performed_at: @session.dates.min.in_time_zone + 12.hours,
112+
performed_at: @session.dates.min.in_time_zone,
113113
notes: "Foo",
114114
created_at: Time.zone.yesterday,
115115
batch: @batch,
@@ -125,7 +125,7 @@ def and_an_existing_patient_record_exists
125125
create(
126126
:vaccination_record,
127127
programme: @programme,
128-
performed_at: @session.dates.min.in_time_zone + 12.hours,
128+
performed_at: @session.dates.min.in_time_zone,
129129
notes: "Bar",
130130
created_at: Time.zone.yesterday,
131131
batch: @other_batch,
@@ -211,7 +211,7 @@ def and_the_first_patient_should_not_be_updated_but_have_a_vaccination_record
211211
expect(@existing_patient.vaccination_records.count).to eq(1)
212212
vaccs_record = @existing_patient.vaccination_records.first
213213
expect(vaccs_record.performed_at).to eq(
214-
Time.new(2024, 5, 14, 12, 0, 0, "+01:00")
214+
Time.new(2024, 5, 14, 0, 0, 0, "+01:00")
215215
)
216216
expect(vaccs_record.delivery_method).to eq("intramuscular")
217217
expect(vaccs_record.delivery_site).to eq("left_buttock")

spec/models/immunisation_import_row_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1556,7 +1556,7 @@
15561556

15571557
it "sets the administered at time" do
15581558
expect(vaccination_record.performed_at).to eq(
1559-
Time.new(2024, 1, 1, 12, 0, 0, "+00:00")
1559+
Time.new(2024, 1, 1, 0, 0, 0, "+00:00")
15601560
)
15611561
end
15621562

@@ -1565,7 +1565,7 @@
15651565

15661566
it "sets the administered at time" do
15671567
expect(vaccination_record.performed_at).to eq(
1568-
Time.new(2023, 9, 1, 12, 0, 0, "+01:00")
1568+
Time.new(2023, 9, 1, 0, 0, 0, "+01:00")
15691569
)
15701570
end
15711571
end
@@ -1575,7 +1575,7 @@
15751575

15761576
it "parses the date and sets the administered at time" do
15771577
expect(vaccination_record.performed_at).to eq(
1578-
Time.new(2023, 9, 1, 12, 0, 0, "+01:00")
1578+
Time.new(2023, 9, 1, 0, 0, 0, "+01:00")
15791579
)
15801580
end
15811581
end
@@ -1585,7 +1585,7 @@
15851585

15861586
it "parses the date and sets the administered at time" do
15871587
expect(vaccination_record.performed_at).to eq(
1588-
Time.new(2023, 9, 1, 12, 0, 0, "+01:00")
1588+
Time.new(2023, 9, 1, 0, 0, 0, "+01:00")
15891589
)
15901590
end
15911591
end

0 commit comments

Comments
 (0)