Skip to content

Commit

Permalink
Validate clinic name present for community clinic-based outcomes this…
Browse files Browse the repository at this point in the history
… cycle
  • Loading branch information
benilovj committed Nov 17, 2024
1 parent 9814652 commit cdb48b1
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 17 deletions.
12 changes: 10 additions & 2 deletions app/models/immunisation_import_row.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,19 @@ class ImmunisationImportRow
inclusion: [CARE_SETTING_SCHOOL, CARE_SETTING_COMMUNITY],
allow_nil: true
validates :care_setting, presence: true, if: :requires_care_setting?
validates :clinic_name,
inclusion: {
if: -> do
outcome_in_this_academic_year? &&
care_setting == CARE_SETTING_COMMUNITY
end,
in: -> { _1.organisation.community_clinics.map(&:name) }
}

validate :performed_by_details_present_where_required

attr_reader :organisation

def initialize(data:, organisation:, programme:)
@data = data
@organisation = organisation
Expand Down Expand Up @@ -334,8 +344,6 @@ def uuid

private

attr_reader :organisation

delegate :ods_code, to: :organisation

def performed_at
Expand Down
3 changes: 3 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ en:
batch_expiry_date: <code>BATCH_EXPIRY_DATE</code>
batch_number: <code>BATCH_NUMBER</code>
care_setting: <code>CARE_SETTING</code>
clinic_name: <code>CLINIC_NAME</code>
date_of_vaccination: <code>DATE_OF_VACCINATION</code>
delivery_site: <code>ANATOMICAL_SITE</code>
dose_sequence: <code>DOSE_SEQUENCE</code>
Expand Down Expand Up @@ -197,6 +198,8 @@ en:
care_setting:
blank: Enter a care setting.
inclusion: Enter a valid care setting.
clinic_name:
inclusion: Enter a clinic name
date_of_vaccination:
blank: Enter a date in the correct format
greater_than_or_equal_to: The vaccination date is outside the programme. Enter a date after the programme started.
Expand Down
35 changes: 22 additions & 13 deletions spec/features/hpv_vaccination_offline_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@
when_i_choose_to_record_offline_from_a_clinic_page
then_i_see_an_excel_spreadsheet_for_recording_offline

when_i_record_vaccination_outcomes_to_the_spreadsheet_and_export_it_to_csv(
clinic_name: "Westfield Shopping Centre"
)
when_i_record_vaccination_outcomes_to_the_spreadsheet_and_export_it_to_csv
and_i_upload_the_modified_csv_file
and_i_navigate_to_the_clinic_page
then_i_see_the_uploaded_vaccination_outcomes_reflected_in_the_session
Expand All @@ -42,13 +40,21 @@ def given_an_hpv_programme_is_underway(clinic: false)
:with_generic_clinic,
programmes: [programme]
)
location = create(:location, :school)
school = create(:location, :school)
previous_date = 1.month.ago

if clinic
[previous_date, Date.current].each do |date|
@organisation.generic_clinic_session.session_dates.create!(value: date)
end

@physical_clinic_location =
create(
:location,
:community_clinic,
name: "Westfield Shopping Centre",
organisation: @organisation
)
end

vaccine = programme.vaccines.active.first
Expand All @@ -60,7 +66,7 @@ def given_an_hpv_programme_is_underway(clinic: false)
:today,
organisation: @organisation,
programme:,
location:
location: school
)

@session.session_dates.create!(value: previous_date)
Expand All @@ -71,16 +77,16 @@ def given_an_hpv_programme_is_underway(clinic: false)
2,
:consent_given_triage_not_needed,
session: clinic ? @organisation.generic_clinic_session : @session,
school: location,
school:,
year_group: 8
)
@previously_vaccinated_patient =
create(
:patient,
:vaccinated,
session: clinic ? @organisation.generic_clinic_session : @session,
school: location,
location_name: clinic ? "Local hospital" : nil,
school:,
location_name: clinic ? @physical_clinic_location.name : nil,
year_group: 8
)
VaccinationRecord.last.update!(
Expand Down Expand Up @@ -125,9 +131,7 @@ def excel_cell_to_csv(value)
end
end

def when_i_record_vaccination_outcomes_to_the_spreadsheet_and_export_it_to_csv(
clinic_name: nil
)
def when_i_record_vaccination_outcomes_to_the_spreadsheet_and_export_it_to_csv
# the steps below roughly approximate SAIS users:
#
# * opening the spreadsheet in Excel
Expand Down Expand Up @@ -164,7 +168,9 @@ def when_i_record_vaccination_outcomes_to_the_spreadsheet_and_export_it_to_csv(
.users
.first
.email
row_for_vaccinated_patient["CLINIC_NAME"] = clinic_name if clinic_name
row_for_vaccinated_patient[
"CLINIC_NAME"
] = @physical_clinic_location.name if @physical_clinic_location

row_for_unvaccinated_patient =
csv_table.find do |row|
Expand All @@ -180,7 +186,10 @@ def when_i_record_vaccination_outcomes_to_the_spreadsheet_and_export_it_to_csv(
row_for_unvaccinated_patient[
"PERFORMING_PROFESSIONAL_EMAIL"
] = @organisation.users.first.email
row_for_unvaccinated_patient["CLINIC_NAME"] = clinic_name if clinic_name
row_for_unvaccinated_patient[
"CLINIC_NAME"
] = @physical_clinic_location.name if @physical_clinic_location

File.write("tmp/modified.csv", csv_table.to_csv)
end

Expand Down
34 changes: 32 additions & 2 deletions spec/models/immunisation_import_row_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
let(:family_name) { "Potter" }
let(:date_of_birth) { "20120101" }
let(:address_postcode) { "SW1A 1AA" }
let(:vaccinator) { create(:user, organisation:) }
let(:valid_common_data) do
{
"ORGANISATION_CODE" => "abc",
Expand Down Expand Up @@ -611,12 +612,41 @@
end
end

context "when home educated and community care setting" do
context "current academic year, home educated and community care setting" do
let(:clinic) do
create(:location, :community_clinic, name: "A Clinic", organisation:)
end
let(:session_date) do
create(
:session_date,
value: "#{Date.current.academic_year}0901",
session: organisation.generic_clinic_session
)
end

let(:data) do
valid_data.merge(
"SCHOOL_URN" => "999999",
"SCHOOL_NAME" => "",
"CARE_SETTING" => "2"
"CARE_SETTING" => "2",
"CLINIC_NAME" => clinic.name,
"DATE_OF_VACCINATION" => session_date.value.strftime("%Y%m%d"),
"PERFORMING_PROFESSIONAL_EMAIL" => vaccinator.email
)
end

it "sets the location to the clinic" do
expect(session.location).to eq(organisation.generic_clinic)
end
end

context "previous academic year, home educated and community care setting" do
let(:data) do
valid_data.merge(
"SCHOOL_URN" => "999999",
"SCHOOL_NAME" => "",
"CARE_SETTING" => "2",
"DATE_OF_VACCINATION" => "20220101"
)
end

Expand Down

0 comments on commit cdb48b1

Please sign in to comment.