Skip to content

Conversation

MartinVanIJcken
Copy link
Contributor

@MartinVanIJcken MartinVanIJcken requested a review from a team as a code owner June 17, 2025 10:37
@MartinVanIJcken

This comment was marked as resolved.

@tvararu tvararu temporarily deployed to mavis-pr-3743 June 17, 2025 10:40 Inactive
@MartinVanIJcken MartinVanIJcken force-pushed the do-not-allow-vaccination-of-absent-children branch from a33d38a to 2269452 Compare June 17, 2025 10:46
@MartinVanIJcken MartinVanIJcken force-pushed the do-not-allow-vaccination-of-absent-children branch from 2269452 to cd02163 Compare June 17, 2025 10:50
@tvararu tvararu temporarily deployed to mavis-pr-3743 June 17, 2025 10:50 Inactive
@MartinVanIJcken MartinVanIJcken force-pushed the do-not-allow-vaccination-of-absent-children branch from cd02163 to 631deac Compare June 19, 2025 12:58
@MartinVanIJcken MartinVanIJcken force-pushed the do-not-allow-vaccination-of-absent-children branch from 631deac to e114b7b Compare June 19, 2025 13:28
@MartinVanIJcken MartinVanIJcken force-pushed the do-not-allow-vaccination-of-absent-children branch from e114b7b to 45d62dd Compare June 19, 2025 14:03
@MartinVanIJcken MartinVanIJcken force-pushed the do-not-allow-vaccination-of-absent-children branch from 45d62dd to 67f0b83 Compare June 19, 2025 14:08
@tvararu tvararu temporarily deployed to mavis-pr-3743 June 19, 2025 14:08 Inactive
Copy link

joins(:patient_session).where(patient_session: { patient:, session: })
end

scope :allows_recording_vaccination, -> { attending.or(completed) }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the same logic as:

.has_registration_status(%w[attending completed])

I wonder if there's a way we can refactor this so the same logic is used in both places, perhaps something like this:

STATUSES_FOR_RECORDING_VACCINATION = %w[attending completed]

scope :allows_recording_vaccination, -> { where(status: STATUSES_FOR_RECORDING_VACCINATION) }

.has_registration_status(STATUSES_FOR_RECORDING_VACCINATION)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did this refactor. There is a third place that used .has_registration_status(%w[attending completed]), namely the record controller, but in this case the purpose is to check that they are attending, not to check they can receive a vaccination. I have chosen for now to not replace that instance.

@MartinVanIJcken MartinVanIJcken force-pushed the do-not-allow-vaccination-of-absent-children branch from 67f0b83 to 6bbe91e Compare August 6, 2025 13:51
@MartinVanIJcken MartinVanIJcken requested a review from a team as a code owner August 6, 2025 13:51
@MartinVanIJcken MartinVanIJcken changed the base branch from main to next August 6, 2025 14:00
@MartinVanIJcken MartinVanIJcken force-pushed the do-not-allow-vaccination-of-absent-children branch 8 times, most recently from 317d83b to 380eb8b Compare August 11, 2025 12:44
In the next commit we will enforce that a child is registered as
attending. We therefore fix the tests so that the children are attending
when this is appropriate and required.
Ideally we would get the error message to be a direct link to the
child on the registration page, see
x-govuk/govuk-form-builder#566
for why this is not yet possible.

I could not find a way to test this feature with an e2e test as our
testing library uses a mocked browser that does not actually allow you
to open a second tab in which to modify the attendance while submitting
the vaccination.
@MartinVanIJcken MartinVanIJcken force-pushed the do-not-allow-vaccination-of-absent-children branch from 380eb8b to 775c80e Compare August 27, 2025 15:07
Copy link

Comment on lines +421 to +436
def attending?(session:)
patient_sessions
.includes(:registration_status)
.find_by(session:)
&.registration_status
&.attending?
end

def completed?(session:)
patient_sessions
.includes(:registration_status)
.find_by(session:)
&.registration_status
&.completed?
end

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't see where these methods are used.

.exists?
date = performed_at.to_date
errors.add(
:session_id,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if it makes sense for this error to be attached to :session_id, I wonder if :base is more appropriate (since it's more like a general validation error for the model rather than a specific attribute).

patient_full_name: patient.full_name,
display_date:
date.today? ? "Today (#{date.to_fs(:long)})" : date.to_fs(:long),
location_name:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

location_name is an optional value that's only set when recording a vaccination in a clinic session. I think you'll want to use the logic from the vaccination_record_location helper.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants