Skip to content

Commit

Permalink
Add systm_one file format to vaccination reports
Browse files Browse the repository at this point in the history
Currently behind a feature flag, although this will likely need to be
enabled/disabled on a team-per-team basis. We'll sort out how we want to
do that in the future.
  • Loading branch information
misaka committed Jan 21, 2025
1 parent 58431f9 commit e0d5757
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 6 deletions.
16 changes: 12 additions & 4 deletions app/models/vaccination_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@ class VaccinationReport
include RequestSessionPersistable
include WizardStepConcern

FILE_FORMATS = %w[careplus mavis].freeze

def self.request_session_key
"vaccination_report"
end

def self.file_formats
%w[careplus mavis].tap do
it << "systm_one" if Flipper.enabled?(:systm_one_exporter)
end
end

attribute :date_from, :date
attribute :date_to, :date
attribute :file_format, :string
Expand All @@ -20,7 +24,10 @@ def wizard_steps
end

on_wizard_step :file_format, exact: true do
validates :file_format, inclusion: { in: FILE_FORMATS }
validates :file_format,
inclusion: {
in: -> { VaccinationReport.file_formats }
}
end

def programme
Expand Down Expand Up @@ -57,7 +64,8 @@ def csv_filename
def exporter_class
{
careplus: Reports::CareplusExporter,
mavis: Reports::ProgrammeVaccinationsExporter
mavis: Reports::ProgrammeVaccinationsExporter,
systm_one: Reports::SystmOneExporter
}.fetch(file_format.to_sym)
end

Expand Down
2 changes: 1 addition & 1 deletion app/views/vaccination_reports/file_format.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<%= form_with model: @vaccination_report, url: wizard_path, method: :put do |f| %>
<%= f.govuk_error_summary %>

<%= f.govuk_collection_radio_buttons :file_format, VaccinationReport::FILE_FORMATS, :itself, legend: { text: title, size: "l", tag: "h1" }, caption: { text: @programme.name } %>
<%= f.govuk_collection_radio_buttons :file_format, VaccinationReport.file_formats, :itself, legend: { text: title, size: "l", tag: "h1" }, caption: { text: @programme.name } %>

<%= f.govuk_submit %>
<% end %>
1 change: 1 addition & 0 deletions config/locales/helpers.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ en:
file_format_options:
careplus: CarePlus
mavis: CSV
systm_one: SystmOne
2 changes: 1 addition & 1 deletion db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
Faker::Config.locale = "en-GB"

def set_feature_flags
%i[dev_tools mesh_jobs cis2].each do |feature_flag|
%i[dev_tools mesh_jobs cis2 systm_one_export].each do |feature_flag|
Flipper.add(feature_flag) unless Flipper.exist?(feature_flag)
end
end
Expand Down
51 changes: 51 additions & 0 deletions spec/features/download_vaccination_reports_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,36 @@
then_i_download_a_mavis_file
end

scenario "Download in SystmOne format" do
given_an_hpv_programme_is_underway
and_an_administered_vaccination_record_exists
and_systm_one_export_is_enabled

when_i_go_to_the_programme
and_i_click_on_download_vaccination_report
then_i_see_the_dates_page

when_i_enter_some_dates
then_i_see_the_file_format_page

when_i_choose_systm_one
then_i_download_a_systm_one_file
end

scenario "SystmOne disabled" do
given_an_hpv_programme_is_underway
and_an_administered_vaccination_record_exists
# and_systm_one_export_is_enabled

when_i_go_to_the_programme
and_i_click_on_download_vaccination_report
then_i_see_the_dates_page

when_i_enter_some_dates
then_i_see_the_file_format_page
and_systm_one_export_is_disabled
end

def given_an_hpv_programme_is_underway
@organisation = create(:organisation, :with_one_nurse)
@programme = create(:programme, :hpv, organisations: [@organisation])
Expand Down Expand Up @@ -65,6 +95,10 @@ def and_an_administered_vaccination_record_exists
)
end

def and_systm_one_export_is_enabled
Flipper.enable(:systm_one_exporter)
end

def when_i_go_to_the_programme
sign_in @organisation.users.first
visit programme_path(@programme)
Expand Down Expand Up @@ -108,6 +142,11 @@ def when_i_choose_mavis
click_on "Continue"
end

def when_i_choose_systm_one
choose "SystmOne"
click_on "Continue"
end

def then_i_download_a_careplus_file
expect(page.status_code).to eq(200)

Expand All @@ -123,4 +162,16 @@ def then_i_download_a_mavis_file
"ORGANISATION_CODE,SCHOOL_URN,SCHOOL_NAME,CARE_SETTING,CLINIC_NAME,PERSON_FORENAME,PERSON_SURNAME"
)
end

def then_i_download_a_systm_one_file
expect(page.status_code).to eq(200)

expect(page).to have_content(
"Practice code,NHS number,Surname,Middle name,Forename,Gender,Date of Birth,House name,House number and road,Town"
)
end

def and_systm_one_export_is_disabled
expect(page).not_to have_selector("SystmOne")
end
end
17 changes: 17 additions & 0 deletions spec/models/vaccination_report_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# frozen_string_literal: true

describe VaccinationReport do
describe "file_formats" do
it "returns the default file formats" do
expect(described_class.file_formats).to eq(%w[careplus mavis])
end

context "when systm_one exporter is enabled" do
before { Flipper.enable(:systm_one_exporter) }

it "returns the systm_one file format" do
expect(described_class.file_formats).to eq(%w[careplus mavis systm_one])
end
end
end
end

0 comments on commit e0d5757

Please sign in to comment.