Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 2 additions & 15 deletions app/components/app_patient_page_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,21 +56,8 @@ def vaccination_records
end

def default_vaccinate_form
today_pre_screenings =
patient_session
.pre_screenings
.joins(:session_date)
.merge(SessionDate.today)
.order(created_at: :desc)

feeling_well = today_pre_screenings.any?(&:feeling_well) || nil
not_pregnant = today_pre_screenings.any?(&:not_pregnant) || nil
pre_screening_confirmed = patient.pre_screenings.today.exists?(programme:)

VaccinateForm.new(
patient_session:,
programme:,
feeling_well:,
not_pregnant:
)
VaccinateForm.new(patient_session:, programme:, pre_screening_confirmed:)
end
end
100 changes: 49 additions & 51 deletions app/components/app_vaccinate_form_component.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,69 +8,67 @@
<% content_for(:before_content) { f.govuk_error_summary } %>

<div class="nhsuk-card__content">
<h2 class="nhsuk-card__heading nhsuk-heading-m">
<%= patient.given_name %> has confirmed that they:
</h2>
<section>
<h2 class="nhsuk-card__heading nhsuk-heading-m">
Pre-screening checks
</h2>

<%= f.govuk_check_boxes_fieldset :feeling_well, multiple: false, legend: nil do %>
<%= f.govuk_check_box :feeling_well, true, multiple: false, link_errors: true %>
<% end %>
<p><%= patient.given_name %> has confirmed that they:</p>

<% if vaccinate_form.ask_not_pregnant? %>
<%= f.govuk_check_boxes_fieldset :not_pregnant, multiple: false, legend: nil do %>
<%= f.govuk_check_box :not_pregnant, true, multiple: false, link_errors: true %>
<% end %>
<% end %>
<ul class="nhsuk-list nhsuk-list--bullet">
<li>are not acutely unwell</li>
<% if vaccinate_form.ask_not_pregnant? %>
<li>are not pregnant</li>
<% end %>
<% if vaccinate_form.ask_not_taking_medication? %>
<li>are not taking any medication which prevents vaccination</li>
<% end %>
<li>have no allergies which would prevent vaccination</li>
<li>have not already had this vaccination</li>
<li>know what the vaccination is for, and are happy to have it</li>
</ul>

<% if vaccinate_form.ask_not_taking_medication? %>
<%= f.govuk_check_boxes_fieldset :not_taking_medication, multiple: false, legend: nil do %>
<%= f.govuk_check_box :not_taking_medication, true, multiple: false, link_errors: true %>
<%= f.govuk_check_boxes_fieldset :pre_screening_confirmed, multiple: false, legend: nil do %>
<%= f.govuk_check_box :pre_screening_confirmed, 1, 0, multiple: false, link_errors: true,
label: { text: "#{patient.given_name} has confirmed the above statements are true" } %>
<% end %>
<% end %>

<%= f.govuk_check_boxes_fieldset :no_allergies, multiple: false, legend: nil do %>
<%= f.govuk_check_box :no_allergies, true, multiple: false, link_errors: true %>
<% end %>

<%= f.govuk_check_boxes_fieldset :not_already_had, multiple: false, legend: nil do %>
<%= f.govuk_check_box :not_already_had, true, multiple: false, link_errors: true %>
<% end %>

<%= f.govuk_check_boxes_fieldset :knows_vaccination, multiple: false, legend: nil do %>
<%= f.govuk_check_box :knows_vaccination, true, multiple: false, link_errors: true %>
<% end %>

<%= f.govuk_text_area :pre_screening_notes, label: { text: "Pre-screening notes (optional)" } %>
<%= f.govuk_text_area :pre_screening_notes, label: { text: "Pre-screening notes (optional)" }, rows: 3 %>
</section>

<hr class="nhsuk-section-break nhsuk-section-break--visible nhsuk-section-break--l">

<h2 class="nhsuk-card__heading nhsuk-heading-m">
Is <%= patient.given_name %> ready for their <%= programme.name %> vaccination?
</h2>
<section>
<h2 class="nhsuk-card__heading nhsuk-heading-m">
Is <%= patient.given_name %> ready for their <%= programme.name %> vaccination?
</h2>

<% hint = "Pre-screening checks must be completed for vaccination to go ahead" %>

<%= f.govuk_radio_buttons_fieldset :administered, legend: nil do %>
<% if common_delivery_sites_options.length > 1 %>
<%= f.govuk_radio_button :administered, true, label: { text: "Yes" }, link_errors: true do %>
<%= f.govuk_collection_radio_buttons :delivery_site,
common_delivery_sites_options,
:value,
:label,
legend: {
text: "Where will the injection be given?",
size: "s",
} %>
<%= f.govuk_radio_buttons_fieldset :administered, legend: nil do %>
<% if common_delivery_sites_options.length > 1 %>
<%= f.govuk_radio_button :administered, true, label: { text: "Yes" }, hint: { text: hint }, link_errors: true do %>
<%= f.govuk_collection_radio_buttons :delivery_site,
common_delivery_sites_options,
:value,
:label,
legend: {
text: "Where will the injection be given?",
size: "s",
} %>
<% end %>
<% else %>
<%= f.govuk_radio_button :administered, true, label: { text: "Yes" }, hint: { text: hint }, link_errors: true %>
<%= f.hidden_field :delivery_site, value: common_delivery_sites_options.first.value %>
<% end %>
<% else %>
<%= f.govuk_radio_button :administered, true, label: { text: "Yes" }, link_errors: true %>
<%= f.hidden_field :delivery_site, value: common_delivery_sites_options.first.value %>
<%= f.govuk_radio_button :administered, false, label: { text: "No" } %>
<% end %>
<%= f.govuk_radio_button :administered, false, label: { text: "No" } %>
<% end %>

<%= f.hidden_field :delivery_method, value: delivery_method %>
<%= f.hidden_field :dose_sequence, value: dose_sequence %>
<%= f.hidden_field :programme_id, value: programme.id %>
<%= f.hidden_field :delivery_method, value: delivery_method %>
<%= f.hidden_field :dose_sequence, value: dose_sequence %>
<%= f.hidden_field :programme_id, value: programme.id %>

<%= f.govuk_submit "Continue" %>
<%= f.govuk_submit "Continue" %>
</section>
</div>
<% end %>
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,7 @@ def vaccinate_form_params
delivery_method
delivery_site
dose_sequence
feeling_well
knows_vaccination
no_allergies
not_already_had
not_pregnant
not_taking_medication
pre_screening_confirmed
pre_screening_notes
vaccine_id
]
Expand Down
35 changes: 3 additions & 32 deletions app/forms/vaccinate_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,7 @@ class VaccinateForm

attr_accessor :patient_session, :programme, :current_user, :todays_batch

attribute :knows_vaccination, :boolean
attribute :not_already_had, :boolean
attribute :feeling_well, :boolean
attribute :no_allergies, :boolean
attribute :not_taking_medication, :boolean
attribute :not_pregnant, :boolean
attribute :pre_screening_confirmed, :boolean
attribute :pre_screening_notes, :string

attribute :administered, :boolean
Expand All @@ -24,20 +19,7 @@ class VaccinateForm
validates :pre_screening_notes, length: { maximum: 1000 }

with_options if: :administered do
validates :knows_vaccination, presence: true
validates :not_already_had, presence: true
validates :no_allergies, presence: true
end

with_options if: -> { administered && ask_not_taking_medication? } do
validates :not_taking_medication, presence: true
end

with_options if: -> { administered && ask_not_pregnant? } do
validates :not_pregnant, presence: true
end

with_options if: :administered do
validates :pre_screening_confirmed, presence: true
validates :delivery_method, presence: true
validates :delivery_site, presence: true
end
Expand Down Expand Up @@ -81,20 +63,9 @@ def ask_not_pregnant? = programme.td_ipv?
def pre_screening
@pre_screening ||=
patient_session.pre_screenings.build(
feeling_well: feeling_well || false,
knows_vaccination: knows_vaccination || false,
no_allergies: no_allergies || false,
not_already_had: not_already_had || false,
not_pregnant: not_pregnant || false,
not_taking_medication: not_taking_medication || false,
notes: pre_screening_notes,
performed_by: current_user,
programme:,
session_date_id:
programme:
)
end

def session_date_id
patient_session.session.session_dates.today.first&.id
end
end
26 changes: 9 additions & 17 deletions app/models/pre_screening.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,47 +4,39 @@
#
# Table name: pre_screenings
#
# id :bigint not null, primary key
# feeling_well :boolean not null
# knows_vaccination :boolean not null
# no_allergies :boolean not null
# not_already_had :boolean not null
# not_pregnant :boolean not null
# not_taking_medication :boolean not null
# notes :text default(""), not null
# created_at :datetime not null
# updated_at :datetime not null
# patient_session_id :bigint not null
# performed_by_user_id :bigint not null
# programme_id :bigint not null
# session_date_id :bigint not null
# id :bigint not null, primary key
# notes :text default(""), not null
# created_at :datetime not null
# updated_at :datetime not null
# patient_session_id :bigint not null
# performed_by_user_id :bigint not null
# programme_id :bigint not null
#
# Indexes
#
# index_pre_screenings_on_patient_session_id (patient_session_id)
# index_pre_screenings_on_performed_by_user_id (performed_by_user_id)
# index_pre_screenings_on_programme_id (programme_id)
# index_pre_screenings_on_session_date_id (session_date_id)
#
# Foreign Keys
#
# fk_rails_... (patient_session_id => patient_sessions.id)
# fk_rails_... (performed_by_user_id => users.id)
# fk_rails_... (programme_id => programmes.id)
# fk_rails_... (session_date_id => session_dates.id)
#
class PreScreening < ApplicationRecord
audited associated_with: :patient_session

belongs_to :patient_session
belongs_to :session_date
belongs_to :programme
belongs_to :performed_by,
class_name: "User",
foreign_key: :performed_by_user_id

has_one :patient, through: :patient_session

scope :today, -> { where(created_at: Date.current.all_day) }

encrypts :notes

validates :notes, length: { maximum: 1000 }
Expand Down
1 change: 0 additions & 1 deletion app/models/session_date.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ class SessionDate < ApplicationRecord
belongs_to :session

has_many :session_attendances, dependent: :restrict_with_error
has_many :pre_screenings, dependent: :restrict_with_error

scope :for_session, -> { where("session_id = sessions.id") }

Expand Down
14 changes: 2 additions & 12 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -113,18 +113,8 @@ en:
inclusion: Choose if they are ready to vaccinate
delivery_site:
blank: Choose where the injection will be given
feeling_well:
blank: Confirm that they are feeling well
knows_vaccination:
blank: Confirm that they know what the vaccination is for, and are happy to have it
no_allergies:
blank: Confirm that they have no allergies which would prevent vaccination
not_already_had:
blank: Confirm that they have not already had the vaccination
not_pregnant:
blank: Confirm that they are not pregnant
not_taking_medication:
blank: Confirm that they are not taking any medication which prevents vaccination
pre_screening_confirmed:
blank: Select if the child has confirmed all pre-screening statements are true
pre_screening_notes:
too_long: Enter notes that are less than %{count} characters long
vaccination_report:
Expand Down
13 changes: 0 additions & 13 deletions config/locales/helpers.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,6 @@ en:
apply: Use duplicate record
discard: Keep previously uploaded record
keep_both: Keep both records
vaccinate_form:
knows_vaccination_options:
true: know what the vaccination is for, and are happy to have it
not_already_had_options:
true: have not already had the vaccination
feeling_well_options:
true: are feeling well
no_allergies_options:
true: have no allergies which would prevent vaccination
not_taking_medication_options:
true: are not taking any medication which prevents vaccination
not_pregnant_options:
true: are not pregnant
vaccination_report:
file_format_options:
careplus: CarePlus
Expand Down
15 changes: 15 additions & 0 deletions db/migrate/20250505193919_remove_from_pre_screenings.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

class RemoveFromPreScreenings < ActiveRecord::Migration[8.0]
def up
change_table :pre_screenings, bulk: true do |t|
t.remove :feeling_well,
:knows_vaccination,
:no_allergies,
:not_already_had,
:not_pregnant,
:not_taking_medication
t.remove_references :session_date
end
end
end
9 changes: 0 additions & 9 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -629,21 +629,13 @@
create_table "pre_screenings", force: :cascade do |t|
t.bigint "patient_session_id", null: false
t.bigint "performed_by_user_id", null: false
t.boolean "knows_vaccination", null: false
t.boolean "not_already_had", null: false
t.boolean "feeling_well", null: false
t.boolean "no_allergies", null: false
t.text "notes", default: "", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.bigint "programme_id", null: false
t.boolean "not_taking_medication", null: false
t.boolean "not_pregnant", null: false
t.bigint "session_date_id", null: false
t.index ["patient_session_id"], name: "index_pre_screenings_on_patient_session_id"
t.index ["performed_by_user_id"], name: "index_pre_screenings_on_performed_by_user_id"
t.index ["programme_id"], name: "index_pre_screenings_on_programme_id"
t.index ["session_date_id"], name: "index_pre_screenings_on_session_date_id"
end

create_table "programmes", force: :cascade do |t|
Expand Down Expand Up @@ -908,7 +900,6 @@
add_foreign_key "patients", "locations", column: "school_id"
add_foreign_key "pre_screenings", "patient_sessions"
add_foreign_key "pre_screenings", "programmes"
add_foreign_key "pre_screenings", "session_dates"
add_foreign_key "pre_screenings", "users", column: "performed_by_user_id"
add_foreign_key "school_move_log_entries", "locations", column: "school_id"
add_foreign_key "school_move_log_entries", "patients"
Expand Down
1 change: 0 additions & 1 deletion spec/components/app_activity_log_component_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,6 @@
before do
create(
:pre_screening,
:allows_vaccination,
performed_by: user,
patient_session:,
notes: "Some notes",
Expand Down
Loading