Skip to content

Commit

Permalink
Ensure programmes are valid for session (#3116)
Browse files Browse the repository at this point in the history
When importing vaccination records for a particular session we need to
make sure that the programmes are valid for that session.
  • Loading branch information
thomasleese authored Feb 28, 2025
2 parents a7b8798 + 8dc1d39 commit ec6c743
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
4 changes: 2 additions & 2 deletions app/models/immunisation_import_row.rb
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ def session
organisation
.sessions
.for_current_academic_year
.includes(:location, :session_dates)
.includes(:location, :programmes, :session_dates)
.find_by(id: session_id)
end
end
Expand Down Expand Up @@ -472,7 +472,7 @@ def organisation_ods_code

def programmes_by_name
@programmes_by_name ||=
organisation
(session || organisation)
.programmes
.each_with_object({}) do |programme, hash|
programme.import_names.each { |name| hash[name] = programme }
Expand Down
3 changes: 3 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,9 @@ en:
performed_ods_code:
blank: Enter an organisation code.
equal_to: Enter an organisation code that matches the current organisation.
programme_name:
blank: Enter a programme
inclusion: Enter a programme administered by this organisation
reason:
blank: Enter a valid reason
school_name:
Expand Down
22 changes: 21 additions & 1 deletion spec/models/immunisation_import_row_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
/You need to record whether the child was vaccinated or not/
)
expect(immunisation_import_row.errors[:programme_name]).to include(
"is not included in the list"
"Enter a programme administered by this organisation"
)
end
end
Expand Down Expand Up @@ -336,6 +336,26 @@
end
end

context "vaccination in a session and invalid programme" do
let(:data) do
{ "SESSION_ID" => session.id.to_s, "PROGRAMME" => "MenACWY" }
end

let(:programmes) do
[create(:programme, :hpv), create(:programme, :menacwy)]
end
let(:session) do
create(:session, organisation:, programmes: [programmes.first])
end

it "has errors" do
expect(immunisation_import_row).to be_invalid
expect(immunisation_import_row.errors[:programme_name]).to eq(
["Enter a programme administered by this organisation"]
)
end
end

context "vaccination in a session, no vaccinator details provided" do
let(:data) do
valid_data.except(
Expand Down

0 comments on commit ec6c743

Please sign in to comment.